diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 28f4aef60..000000000 --- a/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.DS_Store -.vscode/* -site -secrets.py -__pycache__ -~$* -.venv -venv -src/kits/farm-animal-tracker/DesignSparkPCB_V11_0_1.exe diff --git a/docs/glossary.md b/.nojekyll similarity index 100% rename from docs/glossary.md rename to .nojekyll diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 682232c62..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "editor.fontSize": 10, - "cSpell.words": [ - "Adafruit", - "AGND", - "allowfullscreen", - "Autoshutdown", - "breadboarding", - "circuitpython", - "coderdojo", - "Cytron", - "Datasheet", - "ffprobe", - "framebuf", - "Framebuffers", - "localtime", - "maxtries", - "microcontroller", - "micropython", - "microsite", - "microswitch", - "microswitches", - "milliamp", - "milliamps", - "minicom", - "mkdocs", - "mpremote", - "NEOPIXEL", - "neopixels", - "OLED", - "ONESHOT", - "photosensor", - "Pinout", - "pydub", - "rshell", - "SMPS", - "solderless", - "SSID", - "Teachman", - "Thonny", - "timeset", - "timetries", - "tinyml", - "TTGO", - "urandom", - "urequests", - "usbmodem", - "utime", - "VBUS", - "VREF", - "VSYS", - "waveshare", - "WLAN" - ], - "markdown.experimental.validate.ignoreLinks": [ - "../img/pi-w.png" - ] -} \ No newline at end of file diff --git a/40-gpt-outliner.md b/40-gpt-outliner.md deleted file mode 100644 index 427241fb6..000000000 --- a/40-gpt-outliner.md +++ /dev/null @@ -1,25 +0,0 @@ -# GPT Outliner - -## GPT Promt -```txt -Create an outline for a course on microcontroller programming with Micropython for 9th-grade students. The students should have an interest in computers and be able to use a computer keyboard including copy/cut and paste commands. - -1. Introduction -2. Setting up your Python environment -3. Blink an LED -``` - -## GPT Response - -```txt -4. Reading analog inputs -4. Servos -5. LED strips -7. Buttons -8. Sound -9. Temperature sensors -10. Light sensing -11. Accelerometers -12. Motion sensors -13. Gesture sensors -``` \ No newline at end of file diff --git a/404.html b/404.html new file mode 100644 index 000000000..890744831 --- /dev/null +++ b/404.html @@ -0,0 +1,1261 @@ + + + + + + + + + + + + + + + + + + + + + + + MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + + + +
+
+ + + logo + + + +
+
+
+ + MicroPython for Kids + +
+
+ + + + + +
+
+
+ + + + + + + +
+ +
+
+ + +
+ + +
+ +
+
+
+
+
+ Initializing search +
+
    +
    +
    +
    +
    +
    + + +
    + +
    + + +
    +
    + GitHub Repo +
    +
    +
    + +
    + +
    + +
    + + + + + + +
    +
    + + + +
    +
    +
    + + + + +
    + + +
    + +
    + + +
    +
    + GitHub Repo +
    +
    +
    + +
      + + + + + + + +
    • + + + + + CoderDojo Mentor Resources + + + + +
    • + + + + + + + + + +
    • + + + + + MicroPython Home + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Introduction + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Getting Started + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Basic Examples + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Sensors + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Sound and Music + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Wireless + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Robots + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Project Kits + + + + + + + + + + +
    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    • + + + + + + + + + Sims + + + + + + + + + + +
    • + + + + + + + + + +
    • + + + + + Glossary + + + + +
    • + + + + + + + + + +
    • + + + + + References + + + + +
    • + + + + + + + + + +
    • + + + + + Contributing + + + + +
    • + + + + + + + + + +
    • + + + + + Contact + + + + +
    • + + + + + + + + + +
    • + + + + + Colophon + + + + +
    • + + + +
    +
    +
    +
    +
    + + + +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    + + + +
    +
    + +

    404 - Not found

    + +
    +
    + + + +
    + + + +
    + +
    + + + +
    +
    +
    + + + Made with + + Material for MkDocs + + +
    + +
    +
    +
    + +
    +
    +
    +
    + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 267ea541b..000000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# micropython - -This site is being decomissioned. - -The new site is here: - -https://dmccreary.github.io/learning-micropython/ - -Please update all your bookmarks. - -Sorry for the inconvience. -Dan McCreary diff --git a/advanced-labs/01-intro/index.html b/advanced-labs/01-intro/index.html new file mode 100644 index 000000000..acd3b2cdf --- /dev/null +++ b/advanced-labs/01-intro/index.html @@ -0,0 +1,1302 @@ + + + + + + + + + + + + + + + + + + + + + + + Advanced Labs - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + Skip to content + + +
    +
    + +
    + + + + + + +
    +
    + + + logo + + + +
    +
    +
    + + MicroPython for Kids + +
    +
    + + + Advanced Labs + + +
    +
    +
    + + + + + + + +
    + +
    +
    + + +
    + + +
    + +
    +
    +
    +
    +
    + Initializing search +
    +
      +
      +
      +
      +
      +
      + + +
      + +
      + + +
      +
      + GitHub Repo +
      +
      +
      + +
      + +
      + +
      + + + + + + +
      +
      + + + +
      +
      +
      + + + + +
      + + +
      + +
      + + +
      +
      + GitHub Repo +
      +
      +
      + +
        + + + + + + + +
      • + + + + + CoderDojo Mentor Resources + + + + +
      • + + + + + + + + + +
      • + + + + + MicroPython Home + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Introduction + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Getting Started + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Basic Examples + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Sensors + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Sound and Music + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Wireless + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Robots + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Project Kits + + + + + + + + + + +
      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      • + + + + + + + + + Sims + + + + + + + + + + +
      • + + + + + + + + + +
      • + + + + + Glossary + + + + +
      • + + + + + + + + + +
      • + + + + + References + + + + +
      • + + + + + + + + + +
      • + + + + + Contributing + + + + +
      • + + + + + + + + + +
      • + + + + + Contact + + + + +
      • + + + + + + + + + +
      • + + + + + Colophon + + + + +
      • + + + +
      +
      +
      +
      +
      + + + +
      +
      +
      + + +
      + + + + + + +
      +
      +
      +
      + + + +
      +
      + + + + + + + +

      Advanced Labs

      +

      This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects.

      +

      Topics include:

      +
        +
      1. Writing Interrupt Handlers
      2. +
      3. Monitoring the internal temperature of your RP2040 CPU
      4. +
      5. Timing the speed of functions for performance optimization
      6. +
      7. Setting up a Conda virtual Python development environment
      8. +
      9. Using operating system functions such as listing files on the file system
      10. +
      11. Scanning for I2C devices
      12. +
      13. Using a framebuffer
      14. +
      15. Using the minicom tool to move files to and from you PC from your microcontroller
      16. +
      17. Reading files from a SD card
      18. +
      19. Converting CircuitPython code and drivers to MicroPython
      20. +
      + + + + + + + + + + + + + + + +
      +
      + + + +
      + + + +
      + +
      + + + +
      +
      +
      + + + Made with + + Material for MkDocs + + +
      + +
      +
      +
      + +
      +
      +
      +
      + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/02-interrupt-handlers/index.html b/advanced-labs/02-interrupt-handlers/index.html new file mode 100644 index 000000000..250aee67d --- /dev/null +++ b/advanced-labs/02-interrupt-handlers/index.html @@ -0,0 +1,2275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Interrupt Handlers - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + Skip to content + + +
      +
      + +
      + + + + + + +
      +
      + + + logo + + + +
      +
      +
      + + MicroPython for Kids + +
      +
      + + + Interrupt Handlers + + +
      +
      +
      + + + + + + + +
      + +
      +
      + + +
      + + +
      + +
      +
      +
      +
      +
      + Initializing search +
      +
        +
        +
        +
        +
        +
        + + +
        + +
        + + +
        +
        + GitHub Repo +
        +
        +
        + +
        + +
        + +
        + + + + + + +
        +
        + + + +
        +
        +
        + + + + +
        + + +
        + +
        + + +
        +
        + GitHub Repo +
        +
        +
        + +
          + + + + + + + +
        • + + + + + CoderDojo Mentor Resources + + + + +
        • + + + + + + + + + +
        • + + + + + MicroPython Home + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Introduction + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Getting Started + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Basic Examples + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Sensors + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Sound and Music + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Wireless + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Robots + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + +
          + + + + + Advanced Labs + + + + + + + + +
          + +
          + +
            + + + + + + + + + +
          • + + + + + Internal Temperature + + + + +
          • + + + + + + + + + + + + +
          • + + + + + + + + + + + + + + Interrupt Handlers + + + + + + + +
            + + + + + + + +
              + +
            • + + + What is an Interrupt Handler? + + + +
            • + +
            • + + + Polling vs. Interrupt Handlers + + + +
            • + +
            • + + + Simple Button Press ISR Example + + + +
            • + +
            • + + + Debounced Version of a Button Press Detection + + + +
            • + +
            • + + + ISR with Deactivation + + + +
            • + +
            • + + + Debounce Without Disabling the IRQ + + + +
            • + +
            • + + + References + + + +
            • + +
            + +
            + +
          • + + + + + + + + + + +
          • + + + + + Timing Functions + + + + +
          • + + + + + + + + + + +
          • + + + + + Conda Environment Setup + + + + +
          • + + + + + + + + + + +
          • + + + + + OS Functions + + + + +
          • + + + + + + + + + + +
          • + + + + + I2C Scanner + + + + +
          • + + + + + + + + + + +
          • + + + + + Frame Buffer + + + + +
          • + + + + + + + + + + +
          • + + + + + Minicom + + + + +
          • + + + + + + + + + + +
          • + + + + + SD Card Reader + + + + +
          • + + + + + + + + + + +
          • + + + + + Converting CircuitPython + + + + +
          • + + + + + + + + + + +
          • + + + + + MicroPython Remote + + + + +
          • + + + + + + + + + + +
          • + + + + + Rshell + + + + +
          • + + + + + + + + + + +
          • + + + + + Timers + + + + +
          • + + + + + + + + + + +
          • + + + + + Memory Management + + + + +
          • + + + + + + + + + + +
          • + + + + + TinyML + + + + +
          • + + + + + + + + + + +
          • + + + + + String Formatting + + + + +
          • + + + + + + + + + + +
          • + + + + + Operating System + + + + +
          • + + + + + + + + + + +
          • + + + + + Measuring Battery Voltage + + + + +
          • + + + + + + + + + + +
          • + + + + + File System + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Debugging + + + + + + + + + + +
          • + + + + +
          +
          + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Project Kits + + + + + + + + + + +
        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        • + + + + + + + + + Sims + + + + + + + + + + +
        • + + + + + + + + + +
        • + + + + + Glossary + + + + +
        • + + + + + + + + + +
        • + + + + + References + + + + +
        • + + + + + + + + + +
        • + + + + + Contributing + + + + +
        • + + + + + + + + + +
        • + + + + + Contact + + + + +
        • + + + + + + + + + +
        • + + + + + Colophon + + + + +
        • + + + +
        +
        +
        +
        +
        + + + +
        +
        +
        + + +
        + + + + + + + +
          + +
        • + + + What is an Interrupt Handler? + + + +
        • + +
        • + + + Polling vs. Interrupt Handlers + + + +
        • + +
        • + + + Simple Button Press ISR Example + + + +
        • + +
        • + + + Debounced Version of a Button Press Detection + + + +
        • + +
        • + + + ISR with Deactivation + + + +
        • + +
        • + + + Debounce Without Disabling the IRQ + + + +
        • + +
        • + + + References + + + +
        • + +
        + +
        +
        +
        +
        + + + +
        +
        + + + + + + + +

        Interrupt Handlers in MicroPython

        +

        What is an Interrupt Handler?

        +

        An Interrupt Handler (also called an ISR for Interrupt Service Request) is a special Python function that is called when specific events occur such as a button being pressed. ISRs are the preferred way to detect external events, as opposed to polling methods that are inconsistent and inefficient. However, they are a bit tricky to setup and debug. So a good design should be as simple as possible and avoid using complex features unless you really know you need them.

        +

        Polling vs. Interrupt Handlers

        +

        So why are ISRs so important? Let's illustrate this is a story.

        +

        Imagine you have 10 friends each with a button at their home. In the polling method you would need to drive to each of their houses and ask them "Is the button get pressed"? You would have to do this frequently in case the button was pressed and released too quickly. This is a slow and painful process and takes a lot of CPU cycles.

        +

        An interrupt handler on the other hand has each friend tell you directly if their button has been pressed. The messages are quick and efficient. They don't use a lot of extra CPU power and the results get handled quickly.

        +

        However, there are specific rules about what we can and can't do within an ISR function. They need to be quick and efficient. We can't wonder off and do crazy things like printing debugging lines within a good ISR. Our job is typically update a global value and finish ASAP. A good ISR should be as efficient as possible.

        +

        Simple Button Press ISR Example

        +

        This is our first ISR example. It has several parts:

        +
          +
        1. import statements - (pretty standard but we have to add the import micropython)
        2. +
        3. global variables - we will update these to communicate the result of our ISR
        4. +
        5. the callback function - this is the function will be automatically called on a pin event
        6. +
        7. the button defintion - this is where we indicate what pin and the PULL_DOWN value
        8. +
        9. the irq handler - this is where we associate the event with the callback function
        10. +
        11. the main loop - here we only print the button press count if it has changed
        12. +
        +
         1
        + 2
        + 3
        + 4
        + 5
        + 6
        + 7
        + 8
        + 9
        +10
        +11
        +12
        +13
        +14
        +15
        +16
        +17
        +18
        +19
        +20
        +21
        +22
        +23
        +24
        # Use an interrupt function count the number of times a button has been pressed
        +from machine import Pin
        +import micropython
        +import time
        +
        +# global value
        +button_pressed_count = 0
        +
        +# Interrupt Service Routine for Button Pressed Events - with no debounce
        +def button1_pressed(change):
        +    global button_pressed_count
        +    button_pressed_count += 1
        +
        +# we define button1 as being connected to GP14 and to use the internal Pico PULL_DOWN resistor
        +button1 = Pin(14, Pin.IN, Pin.PULL_DOWN)
        +
        +# here is how we associate the falling value on the input pin with the callback function
        +button1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING)
        +
        +button_pressed_count_old = 0
        +while True:
        +    if button_pressed_count_old != button_pressed_count:
        +       print('Button 1 value:', button_pressed_count)
        +       button_pressed_count_old = button_pressed_count
        +
        +

        Now if you run this program, you will see that it prints to the Terminal each time the button is pressed and it also tells us how many times the button has been pressed.

        +

        example output:

        +
         1
        + 2
        + 3
        + 4
        + 5
        + 6
        + 7
        + 8
        + 9
        +10
        +11
        +12
        +13
        +14
        +15
        +16
        +17
        +18
        +19
        +20
        Button 1 value: 1
        +Button 1 value: 2
        +Button 1 value: 3
        +Button 1 value: 4
        +Button 1 value: 5
        +Button 1 value: 6
        +Button 1 value: 8
        +Button 1 value: 9
        +Button 1 value: 10
        +Button 1 value: 11
        +Button 1 value: 12
        +Button 1 value: 13
        +Button 1 value: 14
        +Button 1 value: 15
        +Button 1 value: 16
        +Button 1 value: 17
        +Button 1 value: 18
        +Button 1 value: 19
        +Button 1 value: 20
        +Button 1 value: 21
        +
        +

        But if you are careful, you will note something slightly unexpected might happen. I the example above, I actually only pressed the button about 10 times. But the button value is 21! What could be going on here? Could there be a bug in the code?

        +

        The answer is that buttons are not perfect on/off switches. They are essentially noisy on/off devices that may go through a transition of off/on/off/on each time we press the button.

        +

        As a switch goes from open to closed, it moves from a stable state, through an unstable transition state and then it finally arrives at a new stable state. This is illustrated in the drawing below.

        +

        Debounce Transition State

        +

        We can reduce this "noise" with a small capacitor next to the button. The capacitor will quickly absorb the energy of the button transition and it will "smooth" out the spikes. This will give us a more consistent readout of the number of button presses and avoid accidental "double presses" that were not intended.

        +

        However, we can also get a clean signal by using software. The key is when we first detect that a transition may be happening we "stop listening" for a short period of time until we are confident that the unstable transition state is over. This is typically around 20 milliseconds, but there may be a few stray signals left. Since we may not have to detect changes more frequently than 5 presses per second, we can go to sleep in our ISR for up to 200 milliseconds. This will give us a nice stable reading from the button.

        +

        These are general rules but for our breadboard mounted momentary switches, the values are appropriate.

        +

        Debounced Version of a Button Press Detection

        +

        Now let's show you the code that does the hard work of debouncing a signal from a button or switch.

        +

        In this example, our ISR is called button_pressed_handler(pin). As soon as it is called, it checks the number of milliseconds since it was last called. If the time difference is under 200 milliseconds we are good to go and we update the button_presses global variable. If we are under the 200 millisecond window, we might be in that transition state and we don't do anything.

        +
        1
        +2
        +3
        +4
        +5
        new_time = utime.ticks_ms()
        +# if it has been more that 1/5 of a second since the last event, we have a new event
        +    if (new_time - last_time) > 200: 
        +        button_presses +=1
        +        last_time = new_time
        +
        +

        The net effect is that the presses variable will ONLY be incremented once, and not multiple times during the transition. Here is the full code:

        +
         1
        + 2
        + 3
        + 4
        + 5
        + 6
        + 7
        + 8
        + 9
        +10
        +11
        +12
        +13
        +14
        +15
        +16
        +17
        +18
        +19
        +20
        +21
        +22
        +23
        +24
        +25
        +26
        +27
        +28
        +29
        +30
        +31
        +32
        import utime
        +from machine import Pin
        +
        +# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler
        +
        +button_presses = 0 # the count of times the button has been pressed
        +last_time = 0 # the last time we pressed the button
        +
        +builtin_led = machine.Pin(25, Pin.OUT)
        +# the lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail
        +button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
        +
        +# this function gets called every time the button is pressed
        +def button_pressed_handler(pin):
        +    global button_presses, last_time
        +    new_time = utime.ticks_ms()
        +    # if it has been more that 1/5 of a second since the last event, we have a new event
        +    if (new_time - last_time) > 200: 
        +        button_presses +=1
        +        last_time = new_time
        +
        +# now we register the handler function when the button is pressed
        +button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
        +
        +# This is for only printing when a new button press count value happens
        +old_presses = 0
        +while True:
        +    # only print on change in the button_presses value
        +    if button_presses != old_presses:
        +        print(button_presses)
        +        builtin_led.toggle()
        +        old_presses = button_presses
        +
        +

        ISR with Deactivation

        +

        Although there are benefits to the simplicity of the code above, some microcontrollers developers suggest that you simply deactivate the IRQ during the debounce sleep. This makes sense since there is two small calculation of the time differences (a subtraction and a compare operation) that do not need to be performed.

        +

        The key lines we add are a deactivate of the IRQ, a sleep for 200 milliseconds and a re-enable of the IRQ after the sleep. Both approaches have worked for me and I will let you decide the tradeoffs.

        +
         1
        + 2
        + 3
        + 4
        + 5
        + 6
        + 7
        + 8
        + 9
        +10
        +11
        +12
        +13
        +14
        +15
        +16
        +17
        +18
        +19
        +20
        +21
        +22
        +23
        +24
        +25
        +26
        +27
        import machine, utime
        +
        +# the lower right coner has a wire that goes throuh
        +count_input = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
        +presses = 0
        +
        +def count_handler(pin):
        +    global presses
        +    # disable the IRQ during our debounce check
        +    count_input.irq(handler=None)
        +    presses +=1
        +    # debounce time - we ignore any activity diring this period 
        +    utime.sleep_ms(200)
        +    # re-enable the IRQ
        +    count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler)
        +
        +count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler)
        +
        +old_presses = 0
        +while True:
        +    # only print on change
        +    if presses != old_presses:
        +        if presses > old_presses + 1:
        +            print('double counting in irq.  Fixing...')
        +            presses = old_presses + 1
        +        print(presses)
        +        old_presses = presses
        +
        +

        Debounce Without Disabling the IRQ

        +

        References

        +
          +
        1. MicroPython Documentation on Interrupt Handlers
        2. +
        3. A Guide to Debouncing by Jack G. Ganssle - this is an excellent reference if you want to know how long to set the debounce intervals for various types of switches. It has lots of transition plots and shows the incredible variation in transition states of switches. In the Summary of the final page, Jack suggest that most low-cost switch denouncers should use a debounce period of between 20 and 50 milliseconds if the users want a fast response.
        4. +
        + + + + + + + + + + + + + + + +
        +
        + + + +
        + + + +
        + +
        + + + +
        + + + +
        + + +
        +
        + + Previous + +
        + Internal Temperature +
        +
        +
        + + + + +
        + + Next + +
        + Timing Functions +
        +
        +
        + + +
        +
        + +
        + + +
        +
        +
        + + + Made with + + Material for MkDocs + + +
        + +
        +
        +
        + +
        +
        +
        +
        + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/03-internal-temperature/index.html b/advanced-labs/03-internal-temperature/index.html new file mode 100644 index 000000000..850d5fc02 --- /dev/null +++ b/advanced-labs/03-internal-temperature/index.html @@ -0,0 +1,1971 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Internal Temperature - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        + + + + Skip to content + + +
        +
        + +
        + + + + + + +
        +
        + + + logo + + + +
        +
        +
        + + MicroPython for Kids + +
        +
        + + + Internal Temperature + + +
        +
        +
        + + + + + + + +
        + +
        +
        + + +
        + + +
        + +
        +
        +
        +
        +
        + Initializing search +
        +
          +
          +
          +
          +
          +
          + + +
          + +
          + + +
          +
          + GitHub Repo +
          +
          +
          + +
          + +
          + +
          + + + + + + +
          +
          + + + +
          +
          +
          + + + + +
          + + +
          + +
          + + +
          +
          + GitHub Repo +
          +
          +
          + +
            + + + + + + + +
          • + + + + + CoderDojo Mentor Resources + + + + +
          • + + + + + + + + + +
          • + + + + + MicroPython Home + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Introduction + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Getting Started + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Basic Examples + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Sensors + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Sound and Music + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Wireless + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Robots + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + +
            + + + + + Advanced Labs + + + + + + + + +
            + +
            + +
              + + + + + + + + + + + +
            • + + + + + + + + + + + + + + Internal Temperature + + + + + + + +
              + + + + + + + +
                + +
              • + + + Reading the temperature + + + +
              • + +
              • + + + Logging the Temperature + + + +
              • + +
              + +
              + +
            • + + + + + + + + + + +
            • + + + + + Interrupt Handlers + + + + +
            • + + + + + + + + + + +
            • + + + + + Timing Functions + + + + +
            • + + + + + + + + + + +
            • + + + + + Conda Environment Setup + + + + +
            • + + + + + + + + + + +
            • + + + + + OS Functions + + + + +
            • + + + + + + + + + + +
            • + + + + + I2C Scanner + + + + +
            • + + + + + + + + + + +
            • + + + + + Frame Buffer + + + + +
            • + + + + + + + + + + +
            • + + + + + Minicom + + + + +
            • + + + + + + + + + + +
            • + + + + + SD Card Reader + + + + +
            • + + + + + + + + + + +
            • + + + + + Converting CircuitPython + + + + +
            • + + + + + + + + + + +
            • + + + + + MicroPython Remote + + + + +
            • + + + + + + + + + + +
            • + + + + + Rshell + + + + +
            • + + + + + + + + + + +
            • + + + + + Timers + + + + +
            • + + + + + + + + + + +
            • + + + + + Memory Management + + + + +
            • + + + + + + + + + + +
            • + + + + + TinyML + + + + +
            • + + + + + + + + + + +
            • + + + + + String Formatting + + + + +
            • + + + + + + + + + + +
            • + + + + + Operating System + + + + +
            • + + + + + + + + + + +
            • + + + + + Measuring Battery Voltage + + + + +
            • + + + + + + + + + + +
            • + + + + + File System + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Debugging + + + + + + + + + + +
            • + + + + +
            +
            + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Project Kits + + + + + + + + + + +
          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          • + + + + + + + + + Sims + + + + + + + + + + +
          • + + + + + + + + + +
          • + + + + + Glossary + + + + +
          • + + + + + + + + + +
          • + + + + + References + + + + +
          • + + + + + + + + + +
          • + + + + + Contributing + + + + +
          • + + + + + + + + + +
          • + + + + + Contact + + + + +
          • + + + + + + + + + +
          • + + + + + Colophon + + + + +
          • + + + +
          +
          +
          +
          +
          + + + +
          +
          +
          + + +
          + + + + + + + +
            + +
          • + + + Reading the temperature + + + +
          • + +
          • + + + Logging the Temperature + + + +
          • + +
          + +
          +
          +
          +
          + + + +
          +
          + + + + + + + +

          Using the Builtin Temperature Sensor

          +

          The Raspberry Pi Pico has an internal temperature sensor that can be access using machine.ADC(4). This might be useful to see if your RP2040 CPY is running "hot" and might benefit from a cooling fan.

          +

          Reading the temperature

          +
          1
          +2
          +3
          +4
          +5
          +6
          +7
          +8
          import machine
          +import utime
          +sensor_temp = machine.ADC(4)
          +while True:
          +   reading = sensor_temp.read_u16() * conversion_factor
          +   temperature = 27 - (reading - 0.706)/0.001721
          +   print(temperature)
          +   print('\n')
          +
          +

          Logging the Temperature

          +
           1
          + 2
          + 3
          + 4
          + 5
          + 6
          + 7
          + 8
          + 9
          +10
          +11
          import machine
          +import utime
          +sensor_temp = machine.ADC(machine.ADC.CORE_TEMP)
          +conversion_factor = 3.3 / (65535)
          +file = open("temps.txt", "w")
          +while True:
          +   reading = sensor_temp.read_u16() * conversion_factor
          +   temperature = 27 - (reading - 0.706)/0.001721
          +   file.write(str(temperature))
          +   file.flush()
          +   utime.sleep(10)
          +
          + + + + + + + + + + + + + + + +
          +
          + + + +
          + + + +
          + +
          + + + +
          + + + +
          + + +
          +
          + + Previous + +
          + Introduction +
          +
          +
          + + + + +
          + + Next + +
          + Interrupt Handlers +
          +
          +
          + + +
          +
          + +
          + + +
          +
          +
          + + + Made with + + Material for MkDocs + + +
          + +
          +
          +
          + +
          +
          +
          +
          + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/03-timing-functions/index.html b/advanced-labs/03-timing-functions/index.html new file mode 100644 index 000000000..9bbb566da --- /dev/null +++ b/advanced-labs/03-timing-functions/index.html @@ -0,0 +1,2013 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Timing Functions - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
          + + + + Skip to content + + +
          +
          + +
          + + + + + + +
          +
          + + + logo + + + +
          +
          +
          + + MicroPython for Kids + +
          +
          + + + Timing Functions + + +
          +
          +
          + + + + + + + +
          + +
          +
          + + +
          + + +
          + +
          +
          +
          +
          +
          + Initializing search +
          +
            +
            +
            +
            +
            +
            + + +
            + +
            + + +
            +
            + GitHub Repo +
            +
            +
            + +
            + +
            + +
            + + + + + + +
            +
            + + + +
            +
            +
            + + + + +
            + + +
            + +
            + + +
            +
            + GitHub Repo +
            +
            +
            + +
              + + + + + + + +
            • + + + + + CoderDojo Mentor Resources + + + + +
            • + + + + + + + + + +
            • + + + + + MicroPython Home + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Introduction + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Getting Started + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Basic Examples + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Sensors + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Sound and Music + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Wireless + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Robots + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + +
              + + + + + Advanced Labs + + + + + + + + +
              + +
              + +
                + + + + + + + + + +
              • + + + + + Internal Temperature + + + + +
              • + + + + + + + + + + +
              • + + + + + Interrupt Handlers + + + + +
              • + + + + + + + + + + + + +
              • + + + + + + + + + + + + + + Timing Functions + + + + + + + +
                + + + + + + + +
                  + +
                • + + + Microsecond Timer + + + +
                • + +
                • + + + Millisecond Timer + + + +
                • + +
                + +
                + +
              • + + + + + + + + + + +
              • + + + + + Conda Environment Setup + + + + +
              • + + + + + + + + + + +
              • + + + + + OS Functions + + + + +
              • + + + + + + + + + + +
              • + + + + + I2C Scanner + + + + +
              • + + + + + + + + + + +
              • + + + + + Frame Buffer + + + + +
              • + + + + + + + + + + +
              • + + + + + Minicom + + + + +
              • + + + + + + + + + + +
              • + + + + + SD Card Reader + + + + +
              • + + + + + + + + + + +
              • + + + + + Converting CircuitPython + + + + +
              • + + + + + + + + + + +
              • + + + + + MicroPython Remote + + + + +
              • + + + + + + + + + + +
              • + + + + + Rshell + + + + +
              • + + + + + + + + + + +
              • + + + + + Timers + + + + +
              • + + + + + + + + + + +
              • + + + + + Memory Management + + + + +
              • + + + + + + + + + + +
              • + + + + + TinyML + + + + +
              • + + + + + + + + + + +
              • + + + + + String Formatting + + + + +
              • + + + + + + + + + + +
              • + + + + + Operating System + + + + +
              • + + + + + + + + + + +
              • + + + + + Measuring Battery Voltage + + + + +
              • + + + + + + + + + + +
              • + + + + + File System + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Debugging + + + + + + + + + + +
              • + + + + +
              +
              + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Project Kits + + + + + + + + + + +
            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            • + + + + + + + + + Sims + + + + + + + + + + +
            • + + + + + + + + + +
            • + + + + + Glossary + + + + +
            • + + + + + + + + + +
            • + + + + + References + + + + +
            • + + + + + + + + + +
            • + + + + + Contributing + + + + +
            • + + + + + + + + + +
            • + + + + + Contact + + + + +
            • + + + + + + + + + +
            • + + + + + Colophon + + + + +
            • + + + +
            +
            +
            +
            +
            + + + +
            +
            +
            + + +
            + + + + + + + +
              + +
            • + + + Microsecond Timer + + + +
            • + +
            • + + + Millisecond Timer + + + +
            • + +
            + +
            +
            +
            +
            + + + +
            +
            + + + + + + + +

            Timing Functions

            +

            We often need to calculate how much time has elapsed since an event occurred. To to this we can use the ticks functions in the MicroPython utime library.

            +

            Microsecond Timer

            +

            There are one million microseconds in a single second. The utime library allows us to count the number of microseconds that have elapsed since the processor was powered up.

            +

            The following example times the sleep function and measures the difference in the number of clock ticks in microseconds between the two events.

            +
             1
            + 2
            + 3
            + 4
            + 5
            + 6
            + 7
            + 8
            + 9
            +10
            +11
            +12
            import machine, utime
            +
            +start_time = utime.ticks_us()
            +# sleep for 1 second
            +utime.sleep(1)
            +end_time = utime.ticks_us()
            +
            +while True:
            +    print("Start Time:", start_time)
            +    print("End Time:", end_time)
            +    print("Delta Time:", end_time - start_time)
            +    print("")
            +
            +

            results:

            +
            1
            +2
            +3
            +4
            +5
            +6
            +7
            Start Time: 403122147
            +End Time: 404122241
            +Delta Time: 1000094
            +
            +Start Time: 403122147
            +End Time: 404122241
            +Delta Time: 1000096
            +
            +

            You will note that the difference between the start and end time should be one million microseconds. However, the run-time libraries on the pico have some variability, so you will see the actual time vary by a few microseconds. Most of the time you can use milliseconds to compare time intervals.

            +

            Millisecond Timer

            +
             1
            + 2
            + 3
            + 4
            + 5
            + 6
            + 7
            + 8
            + 9
            +10
            +11
            import machine, utime
            +
            +start_time = utime.ticks_ms()
            +utime.sleep(1)
            +end_time = utime.ticks_ms()
            +
            +while True:
            +    print("Start Time:", start_time)
            +    print("End Time:", end_time)
            +    print("Delta Time:", end_time - start_time)
            +    print("")
            +
            +

            results:

            +
            1
            +2
            +3
            +4
            +5
            +6
            +7
            Start Time: 855845
            +End Time: 856845
            +Delta Time: 1000
            +
            +Start Time: 858031
            +End Time: 859032
            +Delta Time: 1001
            +
            +

            These results are almost always 1000 with an occasional 1001 value.

            + + + + + + + + + + + + + + + +
            +
            + + + +
            + + + +
            + +
            + + + +
            + + + +
            + + +
            +
            + + Previous + +
            + Interrupt Handlers +
            +
            +
            + + + + +
            + + Next + +
            + Conda Environment Setup +
            +
            +
            + + +
            +
            + +
            + + +
            +
            +
            + + + Made with + + Material for MkDocs + + +
            + +
            +
            +
            + +
            +
            +
            +
            + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/04-conda-env/index.html b/advanced-labs/04-conda-env/index.html new file mode 100644 index 000000000..b76f5f1b1 --- /dev/null +++ b/advanced-labs/04-conda-env/index.html @@ -0,0 +1,2019 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Conda Environment Setup - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
            + + + + Skip to content + + +
            +
            + +
            + + + + + + +
            +
            + + + logo + + + +
            +
            +
            + + MicroPython for Kids + +
            +
            + + + Conda Environment Setup + + +
            +
            +
            + + + + + + + +
            + +
            +
            + + +
            + + +
            + +
            +
            +
            +
            +
            + Initializing search +
            +
              +
              +
              +
              +
              +
              + + +
              + +
              + + +
              +
              + GitHub Repo +
              +
              +
              + +
              + +
              + +
              + + + + + + +
              +
              + + + +
              +
              +
              + + + + +
              + + +
              + +
              + + +
              +
              + GitHub Repo +
              +
              +
              + +
                + + + + + + + +
              • + + + + + CoderDojo Mentor Resources + + + + +
              • + + + + + + + + + +
              • + + + + + MicroPython Home + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Introduction + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Getting Started + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Basic Examples + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Sensors + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Sound and Music + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Wireless + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Robots + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + +
                + + + + + Advanced Labs + + + + + + + + +
                + +
                + +
                  + + + + + + + + + +
                • + + + + + Internal Temperature + + + + +
                • + + + + + + + + + + +
                • + + + + + Interrupt Handlers + + + + +
                • + + + + + + + + + + +
                • + + + + + Timing Functions + + + + +
                • + + + + + + + + + + + + +
                • + + + + + + + + + + + + + + Conda Environment Setup + + + + + + + +
                  + + + + + + + +
                    + +
                  • + + + Getting Started + + + +
                  • + +
                  • + + + Creating Your Conda Environment + + + +
                  • + +
                  • + + + References + + + +
                  • + +
                  • + + + Raspberry Pi Pico Forum on MicroPython Site + + + +
                    +
                      + +
                    • + + + MicroPython PyCopy (pycopy) + + + +
                    • + +
                    +
                    + +
                  • + +
                  + +
                  + +
                • + + + + + + + + + + +
                • + + + + + OS Functions + + + + +
                • + + + + + + + + + + +
                • + + + + + I2C Scanner + + + + +
                • + + + + + + + + + + +
                • + + + + + Frame Buffer + + + + +
                • + + + + + + + + + + +
                • + + + + + Minicom + + + + +
                • + + + + + + + + + + +
                • + + + + + SD Card Reader + + + + +
                • + + + + + + + + + + +
                • + + + + + Converting CircuitPython + + + + +
                • + + + + + + + + + + +
                • + + + + + MicroPython Remote + + + + +
                • + + + + + + + + + + +
                • + + + + + Rshell + + + + +
                • + + + + + + + + + + +
                • + + + + + Timers + + + + +
                • + + + + + + + + + + +
                • + + + + + Memory Management + + + + +
                • + + + + + + + + + + +
                • + + + + + TinyML + + + + +
                • + + + + + + + + + + +
                • + + + + + String Formatting + + + + +
                • + + + + + + + + + + +
                • + + + + + Operating System + + + + +
                • + + + + + + + + + + +
                • + + + + + Measuring Battery Voltage + + + + +
                • + + + + + + + + + + +
                • + + + + + File System + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Debugging + + + + + + + + + + +
                • + + + + +
                +
                + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Project Kits + + + + + + + + + + +
              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              • + + + + + + + + + Sims + + + + + + + + + + +
              • + + + + + + + + + +
              • + + + + + Glossary + + + + +
              • + + + + + + + + + +
              • + + + + + References + + + + +
              • + + + + + + + + + +
              • + + + + + Contributing + + + + +
              • + + + + + + + + + +
              • + + + + + Contact + + + + +
              • + + + + + + + + + +
              • + + + + + Colophon + + + + +
              • + + + +
              +
              +
              +
              +
              + + + +
              +
              +
              + + +
              + + + + + + + +
                + +
              • + + + Getting Started + + + +
              • + +
              • + + + Creating Your Conda Environment + + + +
              • + +
              • + + + References + + + +
              • + +
              • + + + Raspberry Pi Pico Forum on MicroPython Site + + + +
                +
                  + +
                • + + + MicroPython PyCopy (pycopy) + + + +
                • + +
                +
                + +
              • + +
              + +
              +
              +
              +
              + + + +
              +
              + + + + + + + +

              Creating a Conda Environment for MicroPython

              +

              Conda is a powerful tool for building consistent and stable Python environments. These environments include all the Python libraries that you need to be a productive MicroPython developer. Using Conda allows you to keep each of your Python projects cleanly separated. This may not be important on your 2nd or 3rd Python project, but as you do more Python projects you will benefit from isolated environments that each have their own versions of each Python libraries that will not conflict with each other.

              +

              One other important fact to remember is that if you use a conda virtual environment you should never need to use sudo (root) to install Python libraries. This means your installation scripts are more secure and less likely to introduce security problems and accidentally remove libraries that other projects depend on.

              +

              Getting Started

              +

              To get started, it is best to go directly to the Conda web site and follow the installation instructions for you specific version of your operating system. There are many variations of installation not just for Windows, Mac and Linux, but each version my had different steps required.

              +

              Once you can open a terminal and type in conda --version you have successfully installed Conda. For this document we have used conda:

              +
              1
              conda --version
              +
              +

              which returns:

              +
              1
              conda 4.10.1
              +
              +

              Creating Your Conda Environment

              +

              Our fist job is to create a desktop environment that allows us to run Python programs that support the MicroPython development process.

              +
              1
              conda create -n micropython python=3
              +
              +
              1
              conda activate micropython
              +
              +

              After this your prompt should now show that you are in the micropython environment.

              +

              This process may take about five minutes, since all the most current libraries must be downloaded onto your desktop. Once this process finsihes you must remember to deactivate your current conda environment (if you have one and then activate your new micropython environment.

              +

              References

              +

              Raspberry Pi Pico Forum on MicroPython Site

              +

              MicroPython Pico Forum

              +

              MicroPython PyCopy (pycopy)

              +

              MicroPython PyCopy

              + + + + + + + + + + + + + + + +
              +
              + + + +
              + + + +
              + +
              + + + +
              + + + +
              + + +
              +
              + + Previous + +
              + Timing Functions +
              +
              +
              + + + + +
              + + Next + +
              + OS Functions +
              +
              +
              + + +
              +
              + +
              + + +
              +
              +
              + + + Made with + + Material for MkDocs + + +
              + +
              +
              +
              + +
              +
              +
              +
              + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/05-os-functions/index.html b/advanced-labs/05-os-functions/index.html new file mode 100644 index 000000000..cf79c1045 --- /dev/null +++ b/advanced-labs/05-os-functions/index.html @@ -0,0 +1,2048 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OS Functions - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
              + + + + Skip to content + + +
              +
              + +
              + + + + + + +
              +
              + + + logo + + + +
              +
              +
              + + MicroPython for Kids + +
              +
              + + + OS Functions + + +
              +
              +
              + + + + + + + +
              + +
              +
              + + +
              + + +
              + +
              +
              +
              +
              +
              + Initializing search +
              +
                +
                +
                +
                +
                +
                + + +
                + +
                + + +
                +
                + GitHub Repo +
                +
                +
                + +
                + +
                + +
                + + + + + + +
                +
                + + + +
                +
                +
                + + + + +
                + + +
                + +
                + + +
                +
                + GitHub Repo +
                +
                +
                + +
                  + + + + + + + +
                • + + + + + CoderDojo Mentor Resources + + + + +
                • + + + + + + + + + +
                • + + + + + MicroPython Home + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Introduction + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Getting Started + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Sensors + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Wireless + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Robots + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + +
                  + + + + + Advanced Labs + + + + + + + + +
                  + +
                  + +
                    + + + + + + + + + +
                  • + + + + + Internal Temperature + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Interrupt Handlers + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Timing Functions + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Conda Environment Setup + + + + +
                  • + + + + + + + + + + + + +
                  • + + + + + + + + + + + + + + OS Functions + + + + + + + +
                    + + + + + + + +
                      + +
                    • + + + OS Functions + + + +
                    • + +
                    • + + + Real Time Clock + + + +
                    • + +
                    + +
                    + +
                  • + + + + + + + + + + +
                  • + + + + + I2C Scanner + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Frame Buffer + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Minicom + + + + +
                  • + + + + + + + + + + +
                  • + + + + + SD Card Reader + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Converting CircuitPython + + + + +
                  • + + + + + + + + + + +
                  • + + + + + MicroPython Remote + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Rshell + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Timers + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Memory Management + + + + +
                  • + + + + + + + + + + +
                  • + + + + + TinyML + + + + +
                  • + + + + + + + + + + +
                  • + + + + + String Formatting + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Operating System + + + + +
                  • + + + + + + + + + + +
                  • + + + + + Measuring Battery Voltage + + + + +
                  • + + + + + + + + + + +
                  • + + + + + File System + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Debugging + + + + + + + + + + +
                  • + + + + +
                  +
                  + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Project Kits + + + + + + + + + + +
                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                • + + + + + + + + + Sims + + + + + + + + + + +
                • + + + + + + + + + +
                • + + + + + Glossary + + + + +
                • + + + + + + + + + +
                • + + + + + References + + + + +
                • + + + + + + + + + +
                • + + + + + Contributing + + + + +
                • + + + + + + + + + +
                • + + + + + Contact + + + + +
                • + + + + + + + + + +
                • + + + + + Colophon + + + + +
                • + + + +
                +
                +
                +
                +
                + + + +
                +
                +
                + + +
                + + + + + + + +
                  + +
                • + + + OS Functions + + + +
                • + +
                • + + + Real Time Clock + + + +
                • + +
                + +
                +
                +
                +
                + + + +
                +
                + + + + + + + +

                Raspberry Pi Pico OS Functions

                +

                In the Thonny tool, open the Terminal. At the REPL prompt type:

                +

                help()

                +

                which returns

                +
                1
                help()
                +
                +

                returns

                +
                 1
                + 2
                + 3
                + 4
                + 5
                + 6
                + 7
                + 8
                + 9
                +10
                +11
                +12
                +13
                +14
                +15
                +16
                +17
                +18
                +19
                +20
                +21
                +22
                +23
                +24
                +25
                +26
                +27
                +28
                +29
                +30
                +31
                +32
                +33
                +34
                Welcome to MicroPython!
                +
                +For online help please visit https://micropython.org/help/.
                +
                +For access to the hardware use the 'machine' module.  RP2 specific commands
                +are in the 'rp2' module.
                +
                +Quick overview of some objects:
                +  machine.Pin(pin) -- get a pin, eg machine.Pin(0)
                +  machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
                +    methods: init(..), value([v]), high(), low(), irq(handler)
                +  machine.ADC(pin) -- make an analog object from a pin
                +    methods: read_u16()
                +  machine.PWM(pin) -- make a PWM object from a pin
                +    methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])
                +  machine.I2C(id) -- create an I2C object (id=0,1)
                +    methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)
                +             readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)
                +  machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)
                +    methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)
                +  machine.Timer(freq, callback) -- create a software timer object
                +    eg: machine.Timer(freq=1, callback=lambda t:print(t))
                +
                +Pins are numbered 0-29, and 26-29 have ADC capabilities
                +Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT
                +Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN
                +
                +Useful control commands:
                +  CTRL-C -- interrupt a running program
                +  CTRL-D -- on a blank line, do a soft reset of the board
                +  CTRL-E -- on a blank line, enter paste mode
                +
                +For further help on a specific object, type help(obj)
                +For a list of available modules, type help('modules')
                +
                +

                followed by

                +

                help(modules)

                +
                 1
                + 2
                + 3
                + 4
                + 5
                + 6
                + 7
                + 8
                + 9
                +10
                +11
                help('modules')
                +__main__          gc                uasyncio/funcs    uos
                +_boot             machine           uasyncio/lock     urandom
                +_onewire          math              uasyncio/stream   ure
                +_rp2              micropython       ubinascii         uselect
                +_thread           onewire           ucollections      ustruct
                +_uasyncio         rp2               uctypes           usys
                +builtins          uarray            uerrno            utime
                +cmath             uasyncio/__init__ uhashlib          uzlib
                +ds18x20           uasyncio/core     uio
                +framebuf          uasyncio/event    ujson
                +
                +

                OS Functions

                +
                1
                +2
                import os
                +print(dir(os))
                +
                +

                returns

                +
                1
                ['__class__', '__name__', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', 'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', 'umount', 'uname', 'urandom']
                +
                +

                Real Time Clock

                +
                1
                +2
                +3
                +4
                +5
                from machine import RTC
                +
                +rtc = RTC()
                +rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time
                +rtc.datetime() # get date and time
                +
                +

                See MicroPython Real Time Clock

                + + + + + + + + + + + + + + + +
                +
                + + + +
                + + + +
                + +
                + + + +
                + + + +
                + + +
                +
                + + Previous + +
                + Conda Environment Setup +
                +
                +
                + + + + +
                + + Next + +
                + I2C Scanner +
                +
                +
                + + +
                +
                + +
                + + +
                +
                +
                + + + Made with + + Material for MkDocs + + +
                + +
                +
                +
                + +
                +
                +
                +
                + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/06-i2c/index.html b/advanced-labs/06-i2c/index.html new file mode 100644 index 000000000..6d0c162d3 --- /dev/null +++ b/advanced-labs/06-i2c/index.html @@ -0,0 +1,2078 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + I2C Scanner - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                + + + + Skip to content + + +
                +
                + +
                + + + + + + +
                +
                + + + logo + + + +
                +
                +
                + + MicroPython for Kids + +
                +
                + + + I2C Scanner + + +
                +
                +
                + + + + + + + +
                + +
                +
                + + +
                + + +
                + +
                +
                +
                +
                +
                + Initializing search +
                +
                  +
                  +
                  +
                  +
                  +
                  + + +
                  + +
                  + + +
                  +
                  + GitHub Repo +
                  +
                  +
                  + +
                  + +
                  + +
                  + + + + + + +
                  +
                  + + + +
                  +
                  +
                  + + + + +
                  + + +
                  + +
                  + + +
                  +
                  + GitHub Repo +
                  +
                  +
                  + +
                    + + + + + + + +
                  • + + + + + CoderDojo Mentor Resources + + + + +
                  • + + + + + + + + + +
                  • + + + + + MicroPython Home + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Introduction + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Sensors + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Wireless + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Robots + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + +
                    + + + + + Advanced Labs + + + + + + + + +
                    + +
                    + +
                      + + + + + + + + + +
                    • + + + + + Internal Temperature + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Interrupt Handlers + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Timing Functions + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Conda Environment Setup + + + + +
                    • + + + + + + + + + + +
                    • + + + + + OS Functions + + + + +
                    • + + + + + + + + + + + + +
                    • + + + + + + + + + + + + + + I2C Scanner + + + + + + + +
                      + + + + + + + +
                        + +
                      • + + + I2C Scanner for I2C 0 + + + +
                      • + +
                      • + + + I2C Scanner for Both I2C 0 and 1 + + + +
                      • + +
                      • + + + References + + + +
                      • + +
                      + +
                      + +
                    • + + + + + + + + + + +
                    • + + + + + Frame Buffer + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Minicom + + + + +
                    • + + + + + + + + + + +
                    • + + + + + SD Card Reader + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Converting CircuitPython + + + + +
                    • + + + + + + + + + + +
                    • + + + + + MicroPython Remote + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Rshell + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Timers + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Memory Management + + + + +
                    • + + + + + + + + + + +
                    • + + + + + TinyML + + + + +
                    • + + + + + + + + + + +
                    • + + + + + String Formatting + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Operating System + + + + +
                    • + + + + + + + + + + +
                    • + + + + + Measuring Battery Voltage + + + + +
                    • + + + + + + + + + + +
                    • + + + + + File System + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Debugging + + + + + + + + + + +
                    • + + + + +
                    +
                    + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  • + + + + + + + + + Sims + + + + + + + + + + +
                  • + + + + + + + + + +
                  • + + + + + Glossary + + + + +
                  • + + + + + + + + + +
                  • + + + + + References + + + + +
                  • + + + + + + + + + +
                  • + + + + + Contributing + + + + +
                  • + + + + + + + + + +
                  • + + + + + Contact + + + + +
                  • + + + + + + + + + +
                  • + + + + + Colophon + + + + +
                  • + + + +
                  +
                  +
                  +
                  +
                  + + + +
                  +
                  +
                  + + +
                  + + + + + + + +
                    + +
                  • + + + I2C Scanner for I2C 0 + + + +
                  • + +
                  • + + + I2C Scanner for Both I2C 0 and 1 + + + +
                  • + +
                  • + + + References + + + +
                  • + +
                  + +
                  +
                  +
                  +
                  + + + +
                  +
                  + + + + + + + +

                  Raspberry Pi Pico I2C

                  +

                  The Pico has two I2C hardware controllers. Each controller can talk to multiple IIC devices as long as all the devices communicating on each controller have distinct addresses.

                  +
                    +
                  1. I2C0 SDA are on GPIOs 0, 4, 8, 12, 16 and 20
                  2. +
                  3. I2C0 SCL are on GPIOs 1, 5, 9, 13, 17 and 21
                  4. +
                  5. I2C1 SDA are on GPIOs 2, 6, 10, 14, 18 and 26
                  6. +
                  7. I2C1 SCL are on GPIOs 3, 7, 11, 15, 19 and 27
                  8. +
                  +

                  I2C Scanner for I2C 0

                  +
                   1
                  + 2
                  + 3
                  + 4
                  + 5
                  + 6
                  + 7
                  + 8
                  + 9
                  +10
                  +11
                  +12
                  +13
                  +14
                  +15
                  +16
                  +17
                  +18
                  import machine
                  +
                  +I2C_SDA_PIN = 0
                  +I2C_SCL_PIN = 1
                  +i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
                  +
                  +print('Scanning I2C bus.')
                  +devices = i2c.scan() # this returns a list of devices
                  +
                  +device_count = len(devices)
                  +
                  +if device_count == 0:
                  +    print('No i2c device found.')
                  +else:
                  +    print(device_count, 'devices found.')
                  +
                  +for device in devices:
                  +    print('Decimal address:', device, ", Hex address: ", hex(device))
                  +
                  +

                  I2C Scanner for Both I2C 0 and 1

                  +
                   1
                  + 2
                  + 3
                  + 4
                  + 5
                  + 6
                  + 7
                  + 8
                  + 9
                  +10
                  +11
                  +12
                  +13
                  +14
                  +15
                  +16
                  +17
                  +18
                  +19
                  +20
                  +21
                  +22
                  +23
                  +24
                  +25
                  +26
                  +27
                  +28
                  +29
                  +30
                  +31
                  +32
                  +33
                  +34
                  import machine
                  +
                  +I2C0_SDA_PIN = 0
                  +I2C0_SCL_PIN = 1
                  +I2C1_SDA_PIN = 2
                  +I2C1_SCL_PIN = 3
                  +i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000)
                  +i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000)
                  +
                  +print('Scanning I2C bus 0.')
                  +devices = i2c0.scan() # this returns a list of devices
                  +
                  +device_count = len(devices)
                  +
                  +if device_count == 0:
                  +    print('No i2c device found on bus 0.')
                  +else:
                  +    print(device_count, 'devices found.')
                  +
                  +for device in devices:
                  +    print('Decimal address:', device, ", Hex address: ", hex(device))
                  +
                  +print('Scanning I2C bus 1.')
                  +devices = i2c1.scan() # this returns a list of devices
                  +
                  +device_count = len(devices)
                  +
                  +if device_count == 0:
                  +    print('No i2c device found on bus 1.')
                  +else:
                  +    print(device_count, 'devices found.')
                  +
                  +for device in devices:
                  +    print('Decimal address:', device, ", Hex address: ", hex(device))
                  +
                  +

                  Results for both a OLED display on I2C 0 and a time-of-flight sensor on I2C 1

                  +
                  1
                  +2
                  +3
                  +4
                  +5
                  +6
                  Scanning I2C bus 0.
                  +1 devices found.
                  +Decimal address: 60 , Hex address:  0x3c
                  +Scanning I2C bus 1.
                  +1 devices found.
                  +Decimal address: 41 , Hex address:  0x29
                  +
                  +

                  References

                  +
                    +
                  1. Article on Hackster.io
                  2. +
                  + + + + + + + + + + + + + + + +
                  +
                  + + + +
                  + + + +
                  + +
                  + + + +
                  + + + +
                  + + +
                  +
                  + + Previous + +
                  + OS Functions +
                  +
                  +
                  + + + + +
                  + + Next + +
                  + Frame Buffer +
                  +
                  +
                  + + +
                  +
                  + +
                  + + +
                  +
                  +
                  + + + Made with + + Material for MkDocs + + +
                  + +
                  +
                  +
                  + +
                  +
                  +
                  +
                  + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/07-framebuffer/index.html b/advanced-labs/07-framebuffer/index.html new file mode 100644 index 000000000..5c58425a0 --- /dev/null +++ b/advanced-labs/07-framebuffer/index.html @@ -0,0 +1,1858 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Frame Buffer - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                  + + + + Skip to content + + +
                  +
                  + +
                  + + + + + + +
                  +
                  + + + logo + + + +
                  +
                  +
                  + + MicroPython for Kids + +
                  +
                  + + + Frame Buffer + + +
                  +
                  +
                  + + + + + + + +
                  + +
                  +
                  + + +
                  + + +
                  + +
                  +
                  +
                  +
                  +
                  + Initializing search +
                  +
                    +
                    +
                    +
                    +
                    +
                    + + +
                    + +
                    + + +
                    +
                    + GitHub Repo +
                    +
                    +
                    + +
                    + +
                    + +
                    + + + + + + +
                    +
                    + + + +
                    +
                    +
                    + + + + +
                    + + +
                    + +
                    + + +
                    +
                    + GitHub Repo +
                    +
                    +
                    + +
                      + + + + + + + +
                    • + + + + + CoderDojo Mentor Resources + + + + +
                    • + + + + + + + + + +
                    • + + + + + MicroPython Home + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Introduction + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Sensors + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Wireless + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Robots + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + +
                      + + + + + Advanced Labs + + + + + + + + +
                      + +
                      + +
                        + + + + + + + + + +
                      • + + + + + Internal Temperature + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Interrupt Handlers + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Timing Functions + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Conda Environment Setup + + + + +
                      • + + + + + + + + + + +
                      • + + + + + OS Functions + + + + +
                      • + + + + + + + + + + +
                      • + + + + + I2C Scanner + + + + +
                      • + + + + + + + + + + + + +
                      • + + + + + + + + + + + + Frame Buffer + + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Minicom + + + + +
                      • + + + + + + + + + + +
                      • + + + + + SD Card Reader + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Converting CircuitPython + + + + +
                      • + + + + + + + + + + +
                      • + + + + + MicroPython Remote + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Rshell + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Timers + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Memory Management + + + + +
                      • + + + + + + + + + + +
                      • + + + + + TinyML + + + + +
                      • + + + + + + + + + + +
                      • + + + + + String Formatting + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Operating System + + + + +
                      • + + + + + + + + + + +
                      • + + + + + Measuring Battery Voltage + + + + +
                      • + + + + + + + + + + +
                      • + + + + + File System + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Debugging + + + + + + + + + + +
                      • + + + + +
                      +
                      + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    • + + + + + + + + + Sims + + + + + + + + + + +
                    • + + + + + + + + + +
                    • + + + + + Glossary + + + + +
                    • + + + + + + + + + +
                    • + + + + + References + + + + +
                    • + + + + + + + + + +
                    • + + + + + Contributing + + + + +
                    • + + + + + + + + + +
                    • + + + + + Contact + + + + +
                    • + + + + + + + + + +
                    • + + + + + Colophon + + + + +
                    • + + + +
                    +
                    +
                    +
                    +
                    + + + +
                    +
                    +
                    + + +
                    + + + + + + +
                    +
                    +
                    +
                    + + + +
                    +
                    + + + + + + + +

                    Framebuffers in MicroPython

                    +

                    References

                    +

                    MicroPython.org docs on framebuf

                    + + + + + + + + + + + + + + + +
                    +
                    + + + +
                    + + + +
                    + +
                    + + + +
                    + + + +
                    + + +
                    +
                    + + Previous + +
                    + I2C Scanner +
                    +
                    +
                    + + + + +
                    + + Next + +
                    + Minicom +
                    +
                    +
                    + + +
                    +
                    + +
                    + + +
                    +
                    +
                    + + + Made with + + Material for MkDocs + + +
                    + +
                    +
                    +
                    + +
                    +
                    +
                    +
                    + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/08-minicom/index.html b/advanced-labs/08-minicom/index.html new file mode 100644 index 000000000..67687a4ab --- /dev/null +++ b/advanced-labs/08-minicom/index.html @@ -0,0 +1,2091 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Minicom - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                    + + + + Skip to content + + +
                    +
                    + +
                    + + + + + + +
                    +
                    + + + logo + + + +
                    +
                    +
                    + + MicroPython for Kids + +
                    +
                    + + + Minicom + + +
                    +
                    +
                    + + + + + + + +
                    + +
                    +
                    + + +
                    + + +
                    + +
                    +
                    +
                    +
                    +
                    + Initializing search +
                    +
                      +
                      +
                      +
                      +
                      +
                      + + +
                      + +
                      + + +
                      +
                      + GitHub Repo +
                      +
                      +
                      + +
                      + +
                      + +
                      + + + + + + +
                      +
                      + + + +
                      +
                      +
                      + + + + +
                      + + +
                      + +
                      + + +
                      +
                      + GitHub Repo +
                      +
                      +
                      + +
                        + + + + + + + +
                      • + + + + + CoderDojo Mentor Resources + + + + +
                      • + + + + + + + + + +
                      • + + + + + MicroPython Home + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Introduction + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Sensors + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Wireless + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Robots + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + +
                        + + + + + Advanced Labs + + + + + + + + +
                        + +
                        + +
                          + + + + + + + + + +
                        • + + + + + Internal Temperature + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Interrupt Handlers + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Timing Functions + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Conda Environment Setup + + + + +
                        • + + + + + + + + + + +
                        • + + + + + OS Functions + + + + +
                        • + + + + + + + + + + +
                        • + + + + + I2C Scanner + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Frame Buffer + + + + +
                        • + + + + + + + + + + + + +
                        • + + + + + + + + + + + + + + Minicom + + + + + + + +
                          + + + + + + + +
                            + +
                          • + + + Installation + + + +
                            +
                              + +
                            • + + + Installation on a Mac + + + +
                            • + +
                            • + + + Installation on Linux (Raspberry Pi OS) + + + +
                            • + +
                            +
                            + +
                          • + +
                          • + + + Verification of Installation + + + +
                          • + +
                          • + + + References + + + +
                          • + +
                          + +
                          + +
                        • + + + + + + + + + + +
                        • + + + + + SD Card Reader + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Converting CircuitPython + + + + +
                        • + + + + + + + + + + +
                        • + + + + + MicroPython Remote + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Rshell + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Timers + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Memory Management + + + + +
                        • + + + + + + + + + + +
                        • + + + + + TinyML + + + + +
                        • + + + + + + + + + + +
                        • + + + + + String Formatting + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Operating System + + + + +
                        • + + + + + + + + + + +
                        • + + + + + Measuring Battery Voltage + + + + +
                        • + + + + + + + + + + +
                        • + + + + + File System + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Debugging + + + + + + + + + + +
                        • + + + + +
                        +
                        + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      • + + + + + + + + + Sims + + + + + + + + + + +
                      • + + + + + + + + + +
                      • + + + + + Glossary + + + + +
                      • + + + + + + + + + +
                      • + + + + + References + + + + +
                      • + + + + + + + + + +
                      • + + + + + Contributing + + + + +
                      • + + + + + + + + + +
                      • + + + + + Contact + + + + +
                      • + + + + + + + + + +
                      • + + + + + Colophon + + + + +
                      • + + + +
                      +
                      +
                      +
                      +
                      + + + +
                      +
                      +
                      + + +
                      + + + + + + + +
                        + +
                      • + + + Installation + + + +
                        +
                          + +
                        • + + + Installation on a Mac + + + +
                        • + +
                        • + + + Installation on Linux (Raspberry Pi OS) + + + +
                        • + +
                        +
                        + +
                      • + +
                      • + + + Verification of Installation + + + +
                      • + +
                      • + + + References + + + +
                      • + +
                      + +
                      +
                      +
                      +
                      + + + +
                      +
                      + + + + + + + +

                      Minicom

                      +

                      Installation

                      +

                      Installation on a Mac

                      +
                      1
                      brew install minicom
                      +
                      +

                      Installation on Linux (Raspberry Pi OS)

                      +
                      1
                      sudo apt install minicom
                      +
                      +

                      Verification of Installation

                      +
                      1
                      which minicom
                      +
                      +
                      1
                      /usr/local/bin/minicom
                      +
                      +
                      1
                      minicom --version
                      +
                      +
                      1
                      minicom version 2.8 (compiled Jan  4 2021)
                      +
                      +
                      1
                      minicom --help
                      +
                      +

                      returns: +

                       1
                      + 2
                      + 3
                      + 4
                      + 5
                      + 6
                      + 7
                      + 8
                      + 9
                      +10
                      +11
                      +12
                      +13
                      +14
                      +15
                      +16
                      +17
                      +18
                      +19
                      +20
                      +21
                      +22
                      +23
                      +24
                      +25
                      +26
                      +27
                      +28
                      +29
                      +30
                      +31
                      +32
                      +33
                      +34
                      +35
                      +36
                      Usage: minicom [OPTION]... [configuration]
                      +A terminal program for Linux and other unix-like systems.
                      +
                      +  -b, --baudrate         : set baudrate (ignore the value from config)
                      +  -D, --device           : set device name (ignore the value from config)
                      +  -s, --setup            : enter setup mode
                      +  -o, --noinit           : do not initialize modem & lockfiles at startup
                      +  -m, --metakey          : use meta or alt key for commands
                      +  -M, --metakey8         : use 8bit meta key for commands
                      +  -l, --ansi             : literal; assume screen uses non IBM-PC character set
                      +  -L, --iso              : don't assume screen uses ISO8859
                      +  -w, --wrap             : Linewrap on
                      +  -H, --displayhex       : display output in hex
                      +  -z, --statline         : try to use terminal's status line
                      +  -7, --7bit             : force 7bit mode
                      +  -8, --8bit             : force 8bit mode
                      +  -c, --color=on/off     : ANSI style color usage on or off
                      +  -a, --attrib=on/off    : use reverse or highlight attributes on or off
                      +  -t, --term=TERM        : override TERM environment variable
                      +  -S, --script=SCRIPT    : run SCRIPT at startup
                      +  -d, --dial=ENTRY       : dial ENTRY from the dialing directory
                      +  -p, --ptty=TTYP        : connect to pseudo terminal
                      +  -C, --capturefile=FILE : start capturing to FILE
                      +  --capturefile-buffer-mode=MODE : set buffering mode of capture file
                      +  -F, --statlinefmt      : format of status line
                      +  -R, --remotecharset    : character set of communication partner
                      +  -v, --version          : output version information and exit
                      +  -h, --help             : show help
                      +  configuration          : configuration file to use
                      +
                      +These options can also be specified in the MINICOM environment variable.
                      +This variable is currently unset.
                      +The configuration directory for the access file and the configurations
                      +is compiled to /usr/local/Cellar/minicom/2.8/etc.
                      +
                      +Report bugs to <minicom-devel@lists.alioth.debian.org>.
                      +

                      +

                      References

                      +
                        +
                      1. +
                      + + + + + + + + + + + + + + + +
                      +
                      + + + +
                      + + + +
                      + +
                      + + + +
                      + + + +
                      + + +
                      +
                      + + Previous + +
                      + Frame Buffer +
                      +
                      +
                      + + + + +
                      + + Next + +
                      + SD Card Reader +
                      +
                      +
                      + + +
                      +
                      + +
                      + + +
                      +
                      +
                      + + + Made with + + Material for MkDocs + + +
                      + +
                      +
                      +
                      + +
                      +
                      +
                      +
                      + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/09-micro-sd-card-reader/index.html b/advanced-labs/09-micro-sd-card-reader/index.html new file mode 100644 index 000000000..8bcacf3f0 --- /dev/null +++ b/advanced-labs/09-micro-sd-card-reader/index.html @@ -0,0 +1,2150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + SD Card Reader - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                      + + + + Skip to content + + +
                      +
                      + +
                      + + + + + + +
                      +
                      + + + logo + + + +
                      +
                      +
                      + + MicroPython for Kids + +
                      +
                      + + + SD Card Reader + + +
                      +
                      +
                      + + + + + + + +
                      + +
                      +
                      + + +
                      + + +
                      + +
                      +
                      +
                      +
                      +
                      + Initializing search +
                      +
                        +
                        +
                        +
                        +
                        +
                        + + +
                        + +
                        + + +
                        +
                        + GitHub Repo +
                        +
                        +
                        + +
                        + +
                        + +
                        + + + + + + +
                        +
                        + + + +
                        +
                        +
                        + + + + +
                        + + +
                        + +
                        + + +
                        +
                        + GitHub Repo +
                        +
                        +
                        + +
                          + + + + + + + +
                        • + + + + + CoderDojo Mentor Resources + + + + +
                        • + + + + + + + + + +
                        • + + + + + MicroPython Home + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Introduction + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Sensors + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Wireless + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Robots + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + +
                          + + + + + Advanced Labs + + + + + + + + +
                          + +
                          + +
                            + + + + + + + + + +
                          • + + + + + Internal Temperature + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Interrupt Handlers + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Timing Functions + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Conda Environment Setup + + + + +
                          • + + + + + + + + + + +
                          • + + + + + OS Functions + + + + +
                          • + + + + + + + + + + +
                          • + + + + + I2C Scanner + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Frame Buffer + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Minicom + + + + +
                          • + + + + + + + + + + + + +
                          • + + + + + + + + + + + + + + SD Card Reader + + + + + + + +
                            + + + + + + + +
                              + +
                            • + + + Maker Pi Pico Connections + + + +
                            • + +
                            • + + + Maker Pi Pico Example Code + + + +
                              +
                                + +
                              • + + + Pin Definitions + + + +
                              • + +
                              • + + + Sample Code for SPI Mode + + + +
                              • + +
                              +
                              + +
                            • + +
                            • + + + References + + + +
                            • + +
                            + +
                            + +
                          • + + + + + + + + + + +
                          • + + + + + Converting CircuitPython + + + + +
                          • + + + + + + + + + + +
                          • + + + + + MicroPython Remote + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Rshell + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Timers + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Memory Management + + + + +
                          • + + + + + + + + + + +
                          • + + + + + TinyML + + + + +
                          • + + + + + + + + + + +
                          • + + + + + String Formatting + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Operating System + + + + +
                          • + + + + + + + + + + +
                          • + + + + + Measuring Battery Voltage + + + + +
                          • + + + + + + + + + + +
                          • + + + + + File System + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Debugging + + + + + + + + + + +
                          • + + + + +
                          +
                          + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        • + + + + + + + + + Sims + + + + + + + + + + +
                        • + + + + + + + + + +
                        • + + + + + Glossary + + + + +
                        • + + + + + + + + + +
                        • + + + + + References + + + + +
                        • + + + + + + + + + +
                        • + + + + + Contributing + + + + +
                        • + + + + + + + + + +
                        • + + + + + Contact + + + + +
                        • + + + + + + + + + +
                        • + + + + + Colophon + + + + +
                        • + + + +
                        +
                        +
                        +
                        +
                        + + + +
                        +
                        +
                        + + +
                        + + + + + + + +
                          + +
                        • + + + Maker Pi Pico Connections + + + +
                        • + +
                        • + + + Maker Pi Pico Example Code + + + +
                          +
                            + +
                          • + + + Pin Definitions + + + +
                          • + +
                          • + + + Sample Code for SPI Mode + + + +
                          • + +
                          +
                          + +
                        • + +
                        • + + + References + + + +
                        • + +
                        + +
                        +
                        +
                        +
                        + + + +
                        +
                        + + + + + + + +

                        Micro SD Card Reader

                        +

                        Secure Digital (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices.

                        +

                        On Microcontrollers SD cards are usually access through an SPI interface although there are also devices that use I2C interfaces.

                        +

                        Maker Pi Pico Connections

                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        GPIO PinSD ModeSPI Mode
                        GP10CLKSCK
                        GP11CMDSDI
                        GP12DAT0SD0
                        GP13DAT1X
                        GP14DAT2X
                        GP15CD/DAT3CSn
                        +

                        Maker Pi Pico Example Code

                        +

                        Pin Definitions

                        +
                         1
                        + 2
                        + 3
                        + 4
                        + 5
                        + 6
                        + 7
                        + 8
                        + 9
                        +10
                        +11
                        +12
                        +13
                        +14
                        +15
                        # SD Mode Definitions
                        +SDCARD_CLK = 10
                        +SDCARD_CMD = 11
                        +SDCARD_DAT0 = 12
                        +SDCARD_DAT1 = 13
                        +SDCARD_DAT2 = 14
                        +SDCARD_CD_DAT3 = 15
                        +
                        +# SPI Mode Definitions
                        +SDCARD_SCK = 10
                        +SDCARD_SDI = 11
                        +SDCARD_SD0 = 12
                        +SDCARD_X1 = 13
                        +SDCARD_X2 = 14
                        +SDCARD_CS = 15
                        +
                        +

                        Sample Code for SPI Mode

                        +
                         1
                        + 2
                        + 3
                        + 4
                        + 5
                        + 6
                        + 7
                        + 8
                        + 9
                        +10
                        +11
                        +12
                        +13
                        +14
                        +15
                        +16
                        +17
                        +18
                        +19
                        +20
                        +21
                        +22
                        +23
                        +24
                        +25
                        +26
                        +27
                        +28
                        +29
                        +30
                        +31
                        +32
                        import machine, os, sdcard
                        +
                        +# Assign chip select (CS) pin (and start it high)
                        +cs = machine.Pin(15, machine.Pin.OUT)
                        +# Intialize SPI peripheral (start with 1 MHz)
                        +spi = machine.SPI(1,
                        +                  baudrate=1000000,
                        +                  polarity=0,
                        +                  phase=0,
                        +                  bits=8,
                        +                  firstbit=machine.SPI.MSB,
                        +                  sck=machine.Pin(10),
                        +                  mosi=machine.Pin(11),
                        +                  miso=machine.Pin(12))
                        +# Initialize SD card
                        +sd = sdcard.SDCard(spi, cs)
                        +
                        +# OR this simpler initialization code should works on Maker Pi Pico too...
                        +#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
                        +
                        +os.mount(sd, '/sd')
                        +# check the content
                        +os.listdir('/sd')
                        +
                        +# try some standard file operations
                        +file = open('/sd/test.txt', 'w')
                        +file.write('Testing SD card on Maker Pi Pico')
                        +file.close()
                        +file = open('/sd/test.txt', 'r')
                        +data = file.read()
                        +print(data)
                        +file.close()
                        +
                        +

                        Results:

                        +
                        1
                        Testing SD card on Maker Pi Pico
                        +
                        +

                        References

                        +
                          +
                        1. MicroPython sdcard.py driver - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266
                        2. +
                        3. MicroPython.org Documentation
                        4. +
                        5. Raspberry Pi Pico Forum
                        6. +
                        7. YouTube Video by Shawn Hymel
                        8. +
                        9. Cytron Maker Pi Pico Datasheet
                        10. +
                        11. SparkFun microSD Transflash Breakout - $4.75 - pins are labeled CD, DO, GND, SCK, VCC, DI and CS
                        12. +
                        13. +
                        + + + + + + + + + + + + + + + +
                        +
                        + + + +
                        + + + +
                        + +
                        + + + +
                        + + + +
                        + + +
                        +
                        + + Previous + +
                        + Minicom +
                        +
                        +
                        + + + + +
                        + + Next + +
                        + Converting CircuitPython +
                        +
                        +
                        + + +
                        +
                        + +
                        + + +
                        +
                        +
                        + + + Made with + + Material for MkDocs + + +
                        + +
                        +
                        +
                        + +
                        +
                        +
                        +
                        + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/10-converting-circuitpython-to-micropython/index.html b/advanced-labs/10-converting-circuitpython-to-micropython/index.html new file mode 100644 index 000000000..90cc22ad5 --- /dev/null +++ b/advanced-labs/10-converting-circuitpython-to-micropython/index.html @@ -0,0 +1,2082 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Converting CircuitPython - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                        + + + + Skip to content + + +
                        +
                        + +
                        + + + + + + +
                        +
                        + + + logo + + + +
                        +
                        +
                        + + MicroPython for Kids + +
                        +
                        + + + Converting CircuitPython + + +
                        +
                        +
                        + + + + + + + +
                        + +
                        +
                        + + +
                        + + +
                        + +
                        +
                        +
                        +
                        +
                        + Initializing search +
                        +
                          +
                          +
                          +
                          +
                          +
                          + + +
                          + +
                          + + +
                          +
                          + GitHub Repo +
                          +
                          +
                          + +
                          + +
                          + +
                          + + + + + + +
                          +
                          + + + +
                          +
                          +
                          + + + + +
                          + + +
                          + +
                          + + +
                          +
                          + GitHub Repo +
                          +
                          +
                          + +
                            + + + + + + + +
                          • + + + + + CoderDojo Mentor Resources + + + + +
                          • + + + + + + + + + +
                          • + + + + + MicroPython Home + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Introduction + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Sensors + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Wireless + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Robots + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + +
                            + + + + + Advanced Labs + + + + + + + + +
                            + +
                            + +
                              + + + + + + + + + +
                            • + + + + + Internal Temperature + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Interrupt Handlers + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Timing Functions + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Conda Environment Setup + + + + +
                            • + + + + + + + + + + +
                            • + + + + + OS Functions + + + + +
                            • + + + + + + + + + + +
                            • + + + + + I2C Scanner + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Frame Buffer + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Minicom + + + + +
                            • + + + + + + + + + + +
                            • + + + + + SD Card Reader + + + + +
                            • + + + + + + + + + + + + +
                            • + + + + + + + + + + + + + + Converting CircuitPython + + + + + + + +
                              + + + + + + + +
                                + +
                              • + + + Setting up a CircuitPython Virtual Environment + + + +
                                +
                                  + +
                                • + + + Installing the SSD1306 CircuitPython Library + + + +
                                • + +
                                +
                                + +
                              • + +
                              • + + + Using ChatGPT to convert CircuitPython to MicroPython + + + +
                              • + +
                              • + + + Trend analysis + + + +
                              • + +
                              + +
                              + +
                            • + + + + + + + + + + +
                            • + + + + + MicroPython Remote + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Rshell + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Timers + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Memory Management + + + + +
                            • + + + + + + + + + + +
                            • + + + + + TinyML + + + + +
                            • + + + + + + + + + + +
                            • + + + + + String Formatting + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Operating System + + + + +
                            • + + + + + + + + + + +
                            • + + + + + Measuring Battery Voltage + + + + +
                            • + + + + + + + + + + +
                            • + + + + + File System + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Debugging + + + + + + + + + + +
                            • + + + + +
                            +
                            + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          • + + + + + + + + + Sims + + + + + + + + + + +
                          • + + + + + + + + + +
                          • + + + + + Glossary + + + + +
                          • + + + + + + + + + +
                          • + + + + + References + + + + +
                          • + + + + + + + + + +
                          • + + + + + Contributing + + + + +
                          • + + + + + + + + + +
                          • + + + + + Contact + + + + +
                          • + + + + + + + + + +
                          • + + + + + Colophon + + + + +
                          • + + + +
                          +
                          +
                          +
                          +
                          + + + +
                          +
                          +
                          + + +
                          + + + + + + + +
                            + +
                          • + + + Setting up a CircuitPython Virtual Environment + + + +
                            +
                              + +
                            • + + + Installing the SSD1306 CircuitPython Library + + + +
                            • + +
                            +
                            + +
                          • + +
                          • + + + Using ChatGPT to convert CircuitPython to MicroPython + + + +
                          • + +
                          • + + + Trend analysis + + + +
                          • + +
                          + +
                          +
                          +
                          +
                          + + + +
                          +
                          + + + + + + + +

                          Converting CircuitPython to MicroPython

                          +

                          MicroPython was created in by Australian programmer Damian George in May of 2014. Although Adafruit originally supported MicroPython, in July 2017 Adafruit created a fork of MicroPython and called it CircuitPython. We can only speculate why this decisive action was taken, but the result is it divided the community into two incompatible branches and it doubled the amount of work needed to be done to introduce a new device to the Python community. Unfortunately, the consequence is that many programs written in CircuitPython are difficult to port to MicroPython.

                          +

                          Today, according to Google Trends, MicroPython is still four more popular than CircuitPython when we look at worldwide web search comparisons. However, in the US, the popularity is more equal. Although the claim was that CircuitPython was done for "simplicity" there is little evidence that CircuitPython programs are smaller or easier to maintain than MicroPython.

                          +

                          The one thing is clear, CircuitPython has lots of drivers for unusual hardware devices. If you find a driver you need in MicroPython you will need to convert it to MicroPython. This is usually done manually on a line-by-line basis.

                          +

                          Setting up a CircuitPython Virtual Environment

                          +

                          Because MicroPython and CircuitPython are incompatible, it is important that you don't intermix your Python libraries.

                          +

                          Here is how we setup a virtual environment for CircuitPython using Conda.

                          +
                          1
                          +2
                          conda create -n circuitpython python=3
                          +conda activate circuitpython
                          +
                          +

                          Installing the SSD1306 CircuitPython Library

                          +

                          Per Directions Here

                          +
                          1
                          pip3 install adafruit-circuitpython-ssd1306
                          +
                          +
                          1
                          pip3 install adafruit-circuitpython-displayio-ssd1306
                          +
                          +
                          +

                          Note

                          +

                          ERROR: Could not find a version that satisfies the requirement adafruit-circuitpython-displayio-ssd1306 +ERROR: No matching distribution found for adafruit-circuitpython-displayio-ssd1306

                          +
                          +
                          1
                          Successfully installed Adafruit-Blinka-6.3.2 Adafruit-PlatformDetect-3.2.0 Adafruit-PureIO-1.1.8 adafruit-circuitpython-busdevice-5.0.6 adafruit-circuitpython-framebuf-1.4.6 adafruit-circuitpython-ssd1306-2.11.1 pyftdi-0.52.9 pyserial-3.5 pyusb-1.1.1
                          +
                          +
                           1
                          + 2
                          + 3
                          + 4
                          + 5
                          + 6
                          + 7
                          + 8
                          + 9
                          +10
                          +11
                          +12
                          +13
                          +14
                          +15
                          +16
                          +17
                          +18
                          +19
                          +20
                          +21
                          +22
                          +23
                          +24
                          +25
                          +26
                          +27
                          +28
                          +29
                          +30
                          +31
                          +32
                          +33
                          +34
                          +35
                          +36
                          # Basic example of clearing and drawing pixels on a SSD1306 OLED display.
                          +# This example and library is meant to work with Adafruit CircuitPython API.
                          +# Author: Tony DiCola
                          +# License: Public Domain
                          +
                          +# Import all board pins.
                          +from board import SCL, SDA
                          +import busio
                          +
                          +# Import the SSD1306 module.
                          +import adafruit_ssd1306
                          +
                          +
                          +# Create the I2C interface.
                          +i2c = busio.I2C(SCL, SDA)
                          +
                          +# Create the SSD1306 OLED class.
                          +# The first two parameters are the pixel width and pixel height.  Change these
                          +# to the right size for your display!
                          +display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
                          +# Alternatively you can change the I2C address of the device with an addr parameter:
                          +#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31)
                          +
                          +# Clear the display.  Always call show after changing pixels to make the display
                          +# update visible!
                          +display.fill(0)
                          +
                          +display.show()
                          +
                          +# Set a pixel in the origin 0,0 position.
                          +display.pixel(0, 0, 1)
                          +# Set a pixel in the middle 64, 16 position.
                          +display.pixel(64, 16, 1)
                          +# Set a pixel in the opposite 127, 31 position.
                          +display.pixel(127, 31, 1)
                          +display.show()
                          +
                          +

                          Using ChatGPT to convert CircuitPython to MicroPython

                          +

                          ChatGPT does a good job of automatically converting CircuitPython to MicroPython. In your prompt you just add the following instruction:

                          +
                          1
                          Convert the following CircuitPython code to MicroPython:
                          +
                          +

                          An example of this working with the basic blink example is shown below:

                          +

                          +

                          Trend analysis

                          +

                          As of March 2021, MicroPython is about two to four times more popular than CircuitPython.

                          +

                          Google Worldwide Search Trends

                          + + + + + + + + + + + + + + + +
                          +
                          + + + +
                          + + + +
                          + +
                          + + + +
                          + + + +
                          + + +
                          +
                          + + Previous + +
                          + SD Card Reader +
                          +
                          +
                          + + + + +
                          + + Next + +
                          + MicroPython Remote +
                          +
                          +
                          + + +
                          +
                          + +
                          + + +
                          +
                          +
                          + + + Made with + + Material for MkDocs + + +
                          + +
                          +
                          +
                          + +
                          +
                          +
                          +
                          + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/11-mpremote/index.html b/advanced-labs/11-mpremote/index.html new file mode 100644 index 000000000..adf49a189 --- /dev/null +++ b/advanced-labs/11-mpremote/index.html @@ -0,0 +1,2301 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroPython Remote - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                          + + + + Skip to content + + +
                          +
                          + +
                          + + + + + + +
                          +
                          + + + logo + + + +
                          +
                          +
                          + + MicroPython for Kids + +
                          +
                          + + + MicroPython Remote + + +
                          +
                          +
                          + + + + + + + +
                          + +
                          +
                          + + +
                          + + +
                          + +
                          +
                          +
                          +
                          +
                          + Initializing search +
                          +
                            +
                            +
                            +
                            +
                            +
                            + + +
                            + +
                            + + +
                            +
                            + GitHub Repo +
                            +
                            +
                            + +
                            + +
                            + +
                            + + + + + + +
                            +
                            + + + +
                            +
                            +
                            + + + + +
                            + + +
                            + +
                            + + +
                            +
                            + GitHub Repo +
                            +
                            +
                            + +
                              + + + + + + + +
                            • + + + + + CoderDojo Mentor Resources + + + + +
                            • + + + + + + + + + +
                            • + + + + + MicroPython Home + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Introduction + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Sensors + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Wireless + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Robots + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + +
                              + + + + + Advanced Labs + + + + + + + + +
                              + +
                              + +
                                + + + + + + + + + +
                              • + + + + + Internal Temperature + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Interrupt Handlers + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Timing Functions + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Conda Environment Setup + + + + +
                              • + + + + + + + + + + +
                              • + + + + + OS Functions + + + + +
                              • + + + + + + + + + + +
                              • + + + + + I2C Scanner + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Frame Buffer + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Minicom + + + + +
                              • + + + + + + + + + + +
                              • + + + + + SD Card Reader + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Converting CircuitPython + + + + +
                              • + + + + + + + + + + + + +
                              • + + + + + + + + + + + + + + MicroPython Remote + + + + + + + +
                                + + + + + + + +
                                  + +
                                • + + + Why Use MicroPython Remote + + + +
                                • + +
                                • + + + List of Commands + + + +
                                • + +
                                • + + + Installing + + + +
                                  +
                                    + +
                                  • + + + Install Log + + + +
                                  • + +
                                  +
                                  + +
                                • + +
                                • + + + Testing the Version + + + +
                                • + +
                                • + + + Getting Help + + + +
                                  +
                                    + +
                                  • + + + Help Results + + + +
                                  • + +
                                  +
                                  + +
                                • + +
                                • + + + Examples of File System Commands + + + +
                                  +
                                    + +
                                  • + + + Setting Up a UNIX Alias + + + +
                                  • + +
                                  +
                                  + +
                                • + +
                                • + + + Creating Deployment Scripts + + + +
                                • + +
                                + +
                                + +
                              • + + + + + + + + + + +
                              • + + + + + Rshell + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Timers + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Memory Management + + + + +
                              • + + + + + + + + + + +
                              • + + + + + TinyML + + + + +
                              • + + + + + + + + + + +
                              • + + + + + String Formatting + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Operating System + + + + +
                              • + + + + + + + + + + +
                              • + + + + + Measuring Battery Voltage + + + + +
                              • + + + + + + + + + + +
                              • + + + + + File System + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Debugging + + + + + + + + + + +
                              • + + + + +
                              +
                              + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            • + + + + + + + + + Sims + + + + + + + + + + +
                            • + + + + + + + + + +
                            • + + + + + Glossary + + + + +
                            • + + + + + + + + + +
                            • + + + + + References + + + + +
                            • + + + + + + + + + +
                            • + + + + + Contributing + + + + +
                            • + + + + + + + + + +
                            • + + + + + Contact + + + + +
                            • + + + + + + + + + +
                            • + + + + + Colophon + + + + +
                            • + + + +
                            +
                            +
                            +
                            +
                            + + + +
                            +
                            +
                            + + +
                            + + + + + + + +
                              + +
                            • + + + Why Use MicroPython Remote + + + +
                            • + +
                            • + + + List of Commands + + + +
                            • + +
                            • + + + Installing + + + +
                              +
                                + +
                              • + + + Install Log + + + +
                              • + +
                              +
                              + +
                            • + +
                            • + + + Testing the Version + + + +
                            • + +
                            • + + + Getting Help + + + +
                              +
                                + +
                              • + + + Help Results + + + +
                              • + +
                              +
                              + +
                            • + +
                            • + + + Examples of File System Commands + + + +
                              +
                                + +
                              • + + + Setting Up a UNIX Alias + + + +
                              • + +
                              +
                              + +
                            • + +
                            • + + + Creating Deployment Scripts + + + +
                            • + +
                            + +
                            +
                            +
                            +
                            + + + +
                            +
                            + + + + + + + +

                            MicroPython Remote

                            +

                            MicroPython now has a standard format for all remote access. The program +is called mpremote. There is +ample documentation on the site, and there is a higher chance it will include the latest features.

                            +

                            Why Use MicroPython Remote

                            +

                            There are three main reasons to use mpremote:

                            +
                              +
                            1. Setting up a new device with many device drivers, data files and code.
                            2. +
                            3. Automatically updating software to get new versions and fix bugs such as security patches.
                            4. +
                            5. Moving data back and forth from your Pico to and from your host computer or a cloud server on the internet,
                            6. +
                            +

                            List of Commands

                            +

                            A partial list of the most frequently used commands are:

                            +
                              +
                            1. connect - connect to a remote device
                            2. +
                            3. disconnect - disconnect from a remote device
                            4. +
                            5. resume - maintain existing interpreter state for subsequent commands. Useful for multiple REPL commands without soft resets between the commands.
                            6. +
                            7. soft_reset - perform a soft-reset of the device which will clear out the Python heap and restart the interpreter.
                            8. +
                            9. repl - enter the line-at-time REPL Python interpreter loop on the connected device.
                            10. +
                            11. eval - evaluate a string you give as a parameter on the pico using the MicroPython interpreter.
                            12. +
                            13. exec - execute a string and potentially run it in the background.
                            14. +
                            15. run - run a script from the local filesystem on the Pico
                            16. +
                            17. fs - file system commands like copy, move, rename. Examples below.
                            18. +
                            19. df - print size/used/free statistics for teach of the device filesystems
                            20. +
                            21. edit - edit a file locally. This will copy the file to your local file systems, launch your $EDITOR program and then copy the file back to the Pico.
                            22. +
                            23. mip - intaller. Like pip but it runs on the pico. It install packages from micropython-lib (or GitHub) using the mip tool. This can be useful if you want to automatically upgrade your software and restart the device. If you have a wireless Pico "W" you can get new software directly from the Internet without ever needing a hardline to the Pico.
                            24. +
                            25. mount - mount the local directory on your PC onto the remote device (the Pico). This will allow you to use local files directly from your MicroPython code.
                            26. +
                            27. unmount - unmount a local directory. This happens automatically when mpremote terminates.
                            28. +
                            29. rtc - get or set the real-time clock - useful if you want to keep clocks in sync
                            30. +
                            31. sleep - (delay) n seconds before executing the next command
                            32. +
                            33. reset - hard reset the device. It will then rerun the main.py if it finds it.
                            34. +
                            35. bootloader - This will make the device enter its bootloader mode so it can get an new uf2 file. Useful if you need to upgrade to a new version of MicroPython.
                            36. +
                            +

                            Note that you can only be connected to one remote device at a time to use many commands.

                            +

                            Installing

                            +

                            The first time:

                            +
                            1
                            pip install --user mpremote
                            +
                            +
                            1
                            pip install --upgrade --user mpremote
                            +
                            +

                            Install Log

                            +

                            I use conda and you can see that it found the mpremote package version 1.20.0

                            +
                            1
                            +2
                            +3
                            +4
                            +5
                            Requirement already satisfied: mpremote in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (1.20.0)
                            +Requirement already satisfied: pyserial>=3.3 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (3.5)
                            +Requirement already satisfied: importlib-metadata>=1.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (4.8.3)
                            +Requirement already satisfied: zipp>=0.5 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.4.0)
                            +Requirement already satisfied: typing-extensions>=3.6.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.7.4.3)
                            +
                            +

                            Testing the Version

                            +

                            The version of mpremote is not yet working, but eventually, it will be used like this:

                            +
                            1
                            $ mpremote --version
                            +
                            +
                            1
                            mpremote 0.0.0-unknown
                            +
                            +

                            Getting Help

                            +
                            1
                            $ mpremote --help
                            +
                            +

                            Help Results

                            +
                             1
                            + 2
                            + 3
                            + 4
                            + 5
                            + 6
                            + 7
                            + 8
                            + 9
                            +10
                            +11
                            +12
                            +13
                            +14
                            +15
                            +16
                            +17
                            +18
                            +19
                            +20
                            +21
                            +22
                            +23
                            +24
                            +25
                            +26
                            +27
                            +28
                            +29
                            +30
                            +31
                            +32
                            +33
                            +34
                            +35
                            +36
                            +37
                            +38
                            +39
                            +40
                            +41
                            +42
                            +43
                            +44
                            +45
                            +46
                            +47
                            mpremote -- MicroPython remote control
                            +See https://docs.micropython.org/en/latest/reference/mpremote.html
                            +
                            +List of commands:
                            +  connect     connect to given device
                            +  disconnect  disconnect current device
                            +  edit        edit files on the device
                            +  eval        evaluate and print the string
                            +  exec        execute the string
                            +  fs          execute filesystem commands on the device
                            +  help        print help and exit
                            +  mip         install packages from micropython-lib or third-party sources
                            +  mount       mount local directory on device
                            +  repl        connect to given device
                            +  resume      resume a previous mpremote session (will not auto soft-reset)
                            +  run         run the given local script
                            +  soft-reset  perform a soft-reset of the device
                            +  umount      unmount the local directory
                            +  version     print version and exit
                            +
                            +List of shortcuts:
                            +  --help      
                            +  --version   
                            +  a0          connect to serial port "/dev/ttyACM0"
                            +  a1          connect to serial port "/dev/ttyACM1"
                            +  a2          connect to serial port "/dev/ttyACM2"
                            +  a3          connect to serial port "/dev/ttyACM3"
                            +  bootloader  make the device enter its bootloader
                            +  c0          connect to serial port "COM0"
                            +  c1          connect to serial port "COM1"
                            +  c2          connect to serial port "COM2"
                            +  c3          connect to serial port "COM3"
                            +  cat         
                            +  cp          
                            +  devs        list available serial ports
                            +  df          
                            +  ls          
                            +  mkdir       
                            +  reset       reset the device after delay
                            +  rm          
                            +  rmdir       
                            +  setrtc      
                            +  touch       
                            +  u0          connect to serial port "/dev/ttyUSB0"
                            +  u1          connect to serial port "/dev/ttyUSB1"
                            +  u2          connect to serial port "/dev/ttyUSB2"
                            +  u3          connect to serial port "/dev/ttyUSB3"```
                            +
                            +

                            Examples of File System Commands

                            +

                            Here is the syntax of the copy file command:

                            +
                            1
                            mpremote fs cp main.py :main.py
                            +
                            +

                            This copies the local file "main.py" to your pico. The colon ":" is the root of the pico.

                            +

                            Setting Up a UNIX Alias

                            +

                            If you get tired of typing "mpremote fs cp" you can create an command-line alias called "pcp" for Pico Copy:

                            +
                            1
                            alias pcp='mpremote fs cp'
                            +
                            +

                            The copy command the becomes simply:

                            +
                            1
                            pcp main.py :main.py
                            +
                            +

                            If you place this line in your .bashrc or similar shell startup it saves you a lot of typing.

                            +

                            File systems examples include:

                            +
                              +
                            1. cat <file..> to show the contents of a file or files on the device
                            2. +
                            3. ls to list the current directory
                            4. +
                            5. ls <dirs...> to list the given directories
                            6. +
                            7. cp [-r] <src...> <dest> to copy files
                            8. +
                            9. rm <src...> to remove files on the device
                            10. +
                            11. mkdir <dirs...> to create directories on the device
                            12. +
                            13. rmdir <dirs...> to remove directories on the device
                            14. +
                            15. touch <file..> to create the files (if they don’t already exist)
                            16. +
                            +

                            Creating Deployment Scripts

                            +

                            For large classrooms that teach MicroPython using kits, we recommend that you arrange +all the mkdir and copy (cp) file shell commands in a single UNIX shell script for consistency.

                            +

                            Here are the steps:

                            +
                              +
                            1. Update the Pico with a new image
                            2. +
                            3. Make a /lib directory using the mkdir
                            4. +
                            5. Copy all the drivers for your projects to /lib directory. The drivers you use will be dependent on the hardware you use. For example if your kit has a display you might need to load the ssd1306.py display driver into the /lib directory.
                            6. +
                            7. Copy the default startup program to the /main.py
                            8. +
                            9. Have a sequence of "labs" that start with numbers such as 01_blink.py, 02_button.py etc.
                            10. +
                            +

                            If you follow these steps, then when the students connect to the Pico using Thonny they will see all the labs in the right order from simple to the most complex.

                            + + + + + + + + + + + + + + + +
                            +
                            + + + +
                            + + + +
                            + +
                            + + + +
                            + + + +
                            + + +
                            +
                            + + Previous + +
                            + Converting CircuitPython +
                            +
                            +
                            + + + + +
                            + + Next + +
                            + Rshell +
                            +
                            +
                            + + +
                            +
                            + +
                            + + +
                            +
                            +
                            + + + Made with + + Material for MkDocs + + +
                            + +
                            +
                            +
                            + +
                            +
                            +
                            +
                            + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/11-os/index.html b/advanced-labs/11-os/index.html new file mode 100644 index 000000000..2e81c597a --- /dev/null +++ b/advanced-labs/11-os/index.html @@ -0,0 +1,2093 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Operating System - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                            + + + + Skip to content + + +
                            +
                            + +
                            + + + + + + +
                            +
                            + + + logo + + + +
                            +
                            +
                            + + MicroPython for Kids + +
                            +
                            + + + Operating System + + +
                            +
                            +
                            + + + + + + + +
                            + +
                            +
                            + + +
                            + + +
                            + +
                            +
                            +
                            +
                            +
                            + Initializing search +
                            +
                              +
                              +
                              +
                              +
                              +
                              + + +
                              + +
                              + + +
                              +
                              + GitHub Repo +
                              +
                              +
                              + +
                              + +
                              + +
                              + + + + + + +
                              +
                              + + + +
                              +
                              +
                              + + + + +
                              + + +
                              + +
                              + + +
                              +
                              + GitHub Repo +
                              +
                              +
                              + +
                                + + + + + + + +
                              • + + + + + CoderDojo Mentor Resources + + + + +
                              • + + + + + + + + + +
                              • + + + + + MicroPython Home + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Introduction + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Sensors + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Wireless + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Robots + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + +
                                + + + + + Advanced Labs + + + + + + + + +
                                + +
                                + +
                                  + + + + + + + + + +
                                • + + + + + Internal Temperature + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Interrupt Handlers + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Timing Functions + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Conda Environment Setup + + + + +
                                • + + + + + + + + + + +
                                • + + + + + OS Functions + + + + +
                                • + + + + + + + + + + +
                                • + + + + + I2C Scanner + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Frame Buffer + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Minicom + + + + +
                                • + + + + + + + + + + +
                                • + + + + + SD Card Reader + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Converting CircuitPython + + + + +
                                • + + + + + + + + + + +
                                • + + + + + MicroPython Remote + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Rshell + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Timers + + + + +
                                • + + + + + + + + + + +
                                • + + + + + Memory Management + + + + +
                                • + + + + + + + + + + +
                                • + + + + + TinyML + + + + +
                                • + + + + + + + + + + +
                                • + + + + + String Formatting + + + + +
                                • + + + + + + + + + + + + +
                                • + + + + + + + + + + + + + + Operating System + + + + + + + +
                                  + + + + + + + +
                                    + +
                                  • + + + UName: Getting System Information + + + +
                                  • + +
                                  • + + + Percent Storage Full and Free RAM + + + +
                                  • + +
                                  • + + + Machine Clock frequency + + + +
                                  • + +
                                  • + + + References + + + +
                                  • + +
                                  + +
                                  + +
                                • + + + + + + + + + + +
                                • + + + + + Measuring Battery Voltage + + + + +
                                • + + + + + + + + + + +
                                • + + + + + File System + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Debugging + + + + + + + + + + +
                                • + + + + +
                                +
                                + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              • + + + + + + + + + Sims + + + + + + + + + + +
                              • + + + + + + + + + +
                              • + + + + + Glossary + + + + +
                              • + + + + + + + + + +
                              • + + + + + References + + + + +
                              • + + + + + + + + + +
                              • + + + + + Contributing + + + + +
                              • + + + + + + + + + +
                              • + + + + + Contact + + + + +
                              • + + + + + + + + + +
                              • + + + + + Colophon + + + + +
                              • + + + +
                              +
                              +
                              +
                              +
                              + + + +
                              +
                              +
                              + + +
                              + + + + + + + +
                                + +
                              • + + + UName: Getting System Information + + + +
                              • + +
                              • + + + Percent Storage Full and Free RAM + + + +
                              • + +
                              • + + + Machine Clock frequency + + + +
                              • + +
                              • + + + References + + + +
                              • + +
                              + +
                              +
                              +
                              +
                              + + + +
                              +
                              + + + + + + + +

                              Sample MicroPython OS functions

                              +

                              MicroPython provides a small list of os functions that allow you to manipulate files on the local filesystem of a MicroController.

                              +

                              These functions for filesystem access, and mounting, terminal redirection and duplication, and the uname and urandom functions.

                              +

                              These commands include:

                              +
                                +
                              • uname - get system information such as the release of the runtime and machine type
                              • +
                              • listdir - list directory
                              • +
                              • ilistdir - list all files including low-level i-node statistics
                              • +
                              • getcwd - get current working directory
                              • +
                              • chdir - change directory
                              • +
                              • mkdir -
                              • +
                              • mount/umount - mount or unmount a remote directory as a local file system
                              • +
                              • remove - remove a file
                              • +
                              • stat - get statistics about a file or directory
                              • +
                              • rmdir - remove a directory
                              • +
                              +

                              UName: Getting System Information

                              +
                              1
                              +2
                              +3
                              import os
                              +uname = os.uname()
                              +print(uname)
                              +
                              +

                              Returns:

                              +
                              1
                              +2
                              +3
                              +4
                              +5
                              +6
                              +7
                              (
                              +   sysname='rp2',
                              +   nodename='rp2',
                              +   release='1.19.1',
                              +   version='v1.19.1-88-g74e33e714 on 2022-06-30 (GNU 11.2.0 MinSizeRel)',
                              +   machine='Raspberry Pi Pico W with RP2040'
                              +)
                              +
                              +

                              Thonny does not easily allow you to delete files. To do this you will need to use the "os" functions.

                              +
                              1
                              +2
                              +3
                              +4
                              import os
                              +os.listdir()
                              +os.remove('myfile')
                              +os.listdir()
                              +
                              +

                              To find out all the os functions use:

                              +

                              1
                              +2
                              +3
                              +4
                              +5
                              import os
                              +print(dir(os))
                              +``
                              +
                              +Returns
                              +
                              +['class', 'name', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', +'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', +'umount', 'uname', 'urandom']`

                              +

                              Percent Storage Full and Free RAM

                              +
                               1
                              + 2
                              + 3
                              + 4
                              + 5
                              + 6
                              + 7
                              + 8
                              + 9
                              +10
                              +11
                              +12
                              +13
                              +14
                              +15
                              +16
                              +17
                              +18
                              +19
                              +20
                              +21
                              +22
                              +23
                              +24
                              +25
                              +26
                              +27
                              +28
                              +29
                              import gc
                              +import os
                              +
                              +def df():
                              +  s = os.statvfs('//')
                              +  return ('{0} MB'.format((s[0]*s[3])/1048576))
                              +
                              +def free(full=False):
                              +  F = gc.mem_free()
                              +  A = gc.mem_alloc()
                              +  T = F+A
                              +  P = '{0:.2f}%'.format(F/T*100)
                              +  if not full: return P
                              +  else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))
                              +
                              +def free-gc(full=False):
                              +  gc.collect()
                              +  F = gc.mem_free()
                              +  A = gc.mem_alloc()
                              +  T = F+A
                              +  P = '{0:.2f}%'.format(F/T*100)
                              +  if not full: return P
                              +  else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))
                              +
                              +print(df())
                              +
                              +print(free())
                              +
                              +print(free-gc())
                              +
                              +

                              Machine Clock frequency

                              +
                              1
                              print('Machine Clock Frequency:', '{:,} MHz'.format(machine.freq()/1000000))
                              +
                              +

                              returns:

                              +
                              1
                              Machine Clock Frequency: 125 MHz
                              +
                              +

                              References

                              +

                              https://www.youtube.com/watch?v=jnSX8ZMmHZ4

                              + + + + + + + + + + + + + + + +
                              +
                              + + + +
                              + + + +
                              + +
                              + + + +
                              + + + +
                              + + +
                              +
                              + + Previous + +
                              + String Formatting +
                              +
                              +
                              + + + + +
                              + + Next + +
                              + Measuring Battery Voltage +
                              +
                              +
                              + + +
                              +
                              + +
                              + + +
                              +
                              +
                              + + + Made with + + Material for MkDocs + + +
                              + +
                              +
                              +
                              + +
                              +
                              +
                              +
                              + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/11-rshell/index.html b/advanced-labs/11-rshell/index.html new file mode 100644 index 000000000..1e6b5f673 --- /dev/null +++ b/advanced-labs/11-rshell/index.html @@ -0,0 +1,2228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Rshell - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                              + + + + Skip to content + + +
                              +
                              + +
                              + + + + + + +
                              +
                              + + + logo + + + +
                              +
                              +
                              + + MicroPython for Kids + +
                              +
                              + + + Rshell + + +
                              +
                              +
                              + + + + + + + +
                              + +
                              +
                              + + +
                              + + +
                              + +
                              +
                              +
                              +
                              +
                              + Initializing search +
                              +
                                +
                                +
                                +
                                +
                                +
                                + + +
                                + +
                                + + +
                                +
                                + GitHub Repo +
                                +
                                +
                                + +
                                + +
                                + +
                                + + + + + + +
                                +
                                + + + +
                                +
                                +
                                + + + + +
                                + + +
                                + +
                                + + +
                                +
                                + GitHub Repo +
                                +
                                +
                                + +
                                  + + + + + + + +
                                • + + + + + CoderDojo Mentor Resources + + + + +
                                • + + + + + + + + + +
                                • + + + + + MicroPython Home + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Robots + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + +
                                  + + + + + Advanced Labs + + + + + + + + +
                                  + +
                                  + +
                                    + + + + + + + + + +
                                  • + + + + + Internal Temperature + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Interrupt Handlers + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Timing Functions + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Conda Environment Setup + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + OS Functions + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + I2C Scanner + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Frame Buffer + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Minicom + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + SD Card Reader + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Converting CircuitPython + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + MicroPython Remote + + + + +
                                  • + + + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + Rshell + + + + + + + +
                                    + + + + + + + +
                                      + +
                                    • + + + Conda Setup + + + +
                                    • + +
                                    • + + + Install rshell in your pico environment + + + +
                                    • + +
                                    • + + + Running shell + + + +
                                    • + +
                                    • + + + Boards + + + +
                                    • + +
                                    • + + + Listing Files + + + +
                                    • + +
                                    • + + + Giving Your Board a Name + + + +
                                    • + +
                                    • + + + Entering REPL + + + +
                                    • + +
                                    • + + + Getting Help on rshell commands + + + +
                                    • + +
                                    • + + + Running Backup + + + +
                                    • + +
                                    • + + + Installing files + + + +
                                    • + +
                                    • + + + Direct Command Execution + + + +
                                    • + +
                                    + +
                                    + +
                                  • + + + + + + + + + + +
                                  • + + + + + Timers + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Memory Management + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + TinyML + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + String Formatting + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Operating System + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + Measuring Battery Voltage + + + + +
                                  • + + + + + + + + + + +
                                  • + + + + + File System + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Debugging + + + + + + + + + + +
                                  • + + + + +
                                  +
                                  + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                • + + + + + + + + + Sims + + + + + + + + + + +
                                • + + + + + + + + + +
                                • + + + + + Glossary + + + + +
                                • + + + + + + + + + +
                                • + + + + + References + + + + +
                                • + + + + + + + + + +
                                • + + + + + Contributing + + + + +
                                • + + + + + + + + + +
                                • + + + + + Contact + + + + +
                                • + + + + + + + + + +
                                • + + + + + Colophon + + + + +
                                • + + + +
                                +
                                +
                                +
                                +
                                + + + +
                                +
                                +
                                + + +
                                + + + + + + + +
                                  + +
                                • + + + Conda Setup + + + +
                                • + +
                                • + + + Install rshell in your pico environment + + + +
                                • + +
                                • + + + Running shell + + + +
                                • + +
                                • + + + Boards + + + +
                                • + +
                                • + + + Listing Files + + + +
                                • + +
                                • + + + Giving Your Board a Name + + + +
                                • + +
                                • + + + Entering REPL + + + +
                                • + +
                                • + + + Getting Help on rshell commands + + + +
                                • + +
                                • + + + Running Backup + + + +
                                • + +
                                • + + + Installing files + + + +
                                • + +
                                • + + + Direct Command Execution + + + +
                                • + +
                                + +
                                +
                                +
                                +
                                + + + +
                                +
                                + + + + + + + +

                                Using rshell on the Raspberry Pi Pico

                                +
                                +

                                Note

                                +

                                MicroPython now has standardized file transfers with the new "MicroPython Remote" or mpremote commands. +See the mpremote docs for details. +We will be updating all our documentation to use this standard. +This page is mostly for older systems.

                                +
                                +

                                Using an IDE such as Thonny you can copy many files at a time to the Raspberry Pi Pico by using the GUI.

                                +

                                However, this process becomes error prone if you want to copy a large number of files. To do this we will use the "remote shell" program from the command line. In our classes we often want to copy a dozen or more files to a new robot for student to try out.

                                +

                                Rshell was written by David Hyland. The source code and installations are documented on Dave's GitHub repository here: https://github.com/dhylands/rshell. Dave added support for the Raspberry Pi Pico in release 0.0.30 in March of 2021.

                                +

                                Rshell's primary use is to to get filesystem information on the pico (ls), and to copy files to and from MicroPython's filesystem. It can also be used as a terminal to run interactive REPL commands.

                                +

                                Conda Setup

                                +

                                If you are new to Python and you don't have any previous virtual environments set up you can skip this step. Experienced Python developers have many different environments that they want to keep separated due to library incompatibility issues. Here is how to create a new Python Conda environment that keeps your rshell libraries separated.

                                +
                                1
                                +2
                                +3
                                conda create -n pico python=3
                                +conda deactivate
                                +conda activate pico
                                +
                                +

                                Your prompt should now indicate you are in the pico environment.

                                +

                                Install rshell in your pico environment

                                +

                                We will now use the standard pip installer tool to install the rshell command.

                                +
                                1
                                python -m pip install rshell
                                +
                                +

                                You can check that rshell has been correctly installed in your command PATH by running the UNIX which command.

                                +
                                1
                                which rshell
                                +
                                +

                                Running shell

                                +

                                Rshell communicates with the Pico through the USB port. When you plug in the Pico you should see a new file created in the UNIX /dev directory. It typically begins with the letters /dev/cu.modem. One way to test this is to unlpug the pico and run the following command:

                                +

                                1
                                ls /dev/cu.usbmodem*
                                +
                                +With the pico unplugged, there should be no files that match the ls wildcard pattern. However, after you plug in the pico the following should be returned:

                                +
                                1
                                /dev/cu.usbmodem14101
                                +
                                +

                                This is the port you will use to connect to the pico. We will use the -p for port option to startup rshell.

                                +
                                1
                                rshell -p /dev/cu.usbmodem14101
                                +
                                +
                                 1
                                + 2
                                + 3
                                + 4
                                + 5
                                + 6
                                + 7
                                + 8
                                + 9
                                +10
                                Using buffer-size of 128
                                +Connecting to /dev/cu.usbmodem14101 (buffer-size 128)...
                                +Trying to connect to REPL  connected
                                +Retrieving sysname ... rp2
                                +Testing if ubinascii.unhexlify exists ... Y
                                +Retrieving root directories ... /LCD_SPI.py/ /lcd-spi-test.py/ /lcd-test.py/ /lcd.py/
                                +Setting time ... Oct 28, 2021 20:30:56
                                +Evaluating board_name ... pyboard
                                +Retrieving time epoch ... Jan 01, 1970
                                +Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
                                +
                                +

                                Boards

                                +

                                The boards command will list the boards rshell is connected to:

                                +

                                boards +pyboard @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pyboard/hello.py /pyboard/main.py

                                +

                                Listing Files

                                +

                                We can see that the board is called "pyboard" and you can use that as a path to list the files on the board.

                                +
                                1
                                +2
                                ls /pyboard
                                +hello.py      main.py
                                +
                                +

                                Giving Your Board a Name

                                +

                                rshell will look for a program called board.py when it connects to the board. If this file contains a board name it will use that as the board name the next time it connects to the board. You can use the "echo" command to generate the file. In the example below, we will call our board "pico"

                                +
                                1
                                echo 'name="pico"' > /pyboard/board.py
                                +
                                +

                                After you use the CONTROL-C and reconnect you will see the following:

                                +
                                1
                                pico @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pico/hello.py /pico/main.py
                                +
                                +

                                Remember you must disconnect from rshell and reconnect before the boards.py function is used.

                                +

                                For the remainder of this lesson we will assume you have renamed your board "pico".

                                +

                                You can then type cd /pico followed by a ls to see the files on your pico.

                                +

                                Entering REPL

                                +

                                You can enter the REPL loop using the repl command and use the same commands that you used in the Thonny shell.

                                +
                                1
                                +2
                                repl
                                +print('Hello World!')
                                +
                                +

                                returns

                                +
                                1
                                Hello World!
                                +
                                +

                                Getting Help on rshell commands

                                +

                                You can type the help command to see all the rshell commands:

                                +
                                1
                                +2
                                +3
                                +4
                                +5
                                +6
                                +7
                                +8
                                help
                                +
                                +Documented commands (type help <topic>):
                                +========================================
                                +args    cat  connect  date  edit  filesize  help  mkdir  rm     shell
                                +boards  cd   cp       echo  exit  filetype  ls    repl   rsync
                                +
                                +Use Control-D (or the exit command) to exit rshell.
                                +
                                +

                                Running Backup

                                +

                                If you want to copy all the python files from the pico to a backup directory you can use the following command:

                                +
                                1
                                +2
                                cd /pico
                                +cp *.py /Users/dan/backup
                                +
                                +

                                You will need to create the /Users/dan/backup directory before you do this. You can also use the tilde ~ character to stand in for your home directory like this:

                                +
                                1
                                cp *.py /Users/dan/backup
                                +
                                +

                                Copying '/pico/hello.py' to '/Users/dan/backup/hello.py' ... +Copying '/pico/main.py' to '/Users/dan/backup/main.py' ...

                                +

                                Installing files

                                +

                                If you have a directory called ~/build that contains many files you want to install on the pico file system you can use the following command:

                                +
                                1
                                cp ~/build/* /pico
                                +
                                +

                                If you have done a clone to the CoderDojoTC micropython repository and put it in your home directory under ~/micropython then following command will copy the python files from the Maker Pi RP2040 kit to your pico:

                                +
                                1
                                +2
                                +3
                                +4
                                mkdir /pico/lib
                                +cp ~/micropython/src/drivers/*.py /pico/lib
                                +cp ~/micropython/src/kits/maker-pi-rp2040/*.py /pico
                                +cp ~Documents/ws/micropython/src/kits/maker-pi-rp2040-robots/*.py /pico/lib
                                +
                                +

                                Note that the drivers will be placed in the /lob directory.

                                +

                                Direct Command Execution

                                +

                                You do not need to use an interactive session to run a command with rshell. You can just add the command you would like to run to the end of the rshell command like this:

                                +
                                1
                                rshell -p /dev/cu.usbmodem14101 ls /pico
                                +
                                +

                                returns:

                                +
                                1
                                hello.py      main.py
                                +
                                + + + + + + + + + + + + + + + +
                                +
                                + + + +
                                + + + +
                                + +
                                + + + +
                                + + + +
                                + + +
                                +
                                + + Previous + +
                                + MicroPython Remote +
                                +
                                +
                                + + + + +
                                + + Next + +
                                + Timers +
                                +
                                +
                                + + +
                                +
                                + +
                                + + +
                                +
                                +
                                + + + Made with + + Material for MkDocs + + +
                                + +
                                +
                                +
                                + +
                                +
                                +
                                +
                                + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/12-string-formatting/index.html b/advanced-labs/12-string-formatting/index.html new file mode 100644 index 000000000..b5ebc8d1d --- /dev/null +++ b/advanced-labs/12-string-formatting/index.html @@ -0,0 +1,1929 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + String Formatting - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                + + + + Skip to content + + +
                                +
                                + +
                                + + + + + + +
                                +
                                + + + logo + + + +
                                +
                                +
                                + + MicroPython for Kids + +
                                +
                                + + + String Formatting + + +
                                +
                                +
                                + + + + + + + +
                                + +
                                +
                                + + +
                                + + +
                                + +
                                +
                                +
                                +
                                +
                                + Initializing search +
                                +
                                  +
                                  +
                                  +
                                  +
                                  +
                                  + + +
                                  + +
                                  + + +
                                  +
                                  + GitHub Repo +
                                  +
                                  +
                                  + +
                                  + +
                                  + +
                                  + + + + + + +
                                  +
                                  + + + +
                                  +
                                  +
                                  + + + + +
                                  + + +
                                  + +
                                  + + +
                                  +
                                  + GitHub Repo +
                                  +
                                  +
                                  + +
                                    + + + + + + + +
                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + MicroPython Home + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + +
                                    + + + + + Advanced Labs + + + + + + + + +
                                    + +
                                    + +
                                      + + + + + + + + + +
                                    • + + + + + Internal Temperature + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Interrupt Handlers + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Timing Functions + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Conda Environment Setup + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + OS Functions + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + I2C Scanner + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Frame Buffer + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Minicom + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + SD Card Reader + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Converting CircuitPython + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + MicroPython Remote + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Rshell + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Timers + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Memory Management + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + TinyML + + + + +
                                    • + + + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + String Formatting + + + + + + + +
                                      + + + + + + + +
                                        + +
                                      • + + + Padding Example + + + +
                                      • + +
                                      + +
                                      + +
                                    • + + + + + + + + + + +
                                    • + + + + + Operating System + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + Measuring Battery Voltage + + + + +
                                    • + + + + + + + + + + +
                                    • + + + + + File System + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Debugging + + + + + + + + + + +
                                    • + + + + +
                                    +
                                    + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + Glossary + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + References + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + Contributing + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + Contact + + + + +
                                  • + + + + + + + + + +
                                  • + + + + + Colophon + + + + +
                                  • + + + +
                                  +
                                  +
                                  +
                                  +
                                  + + + +
                                  +
                                  +
                                  + + +
                                  + + + + + + + +
                                    + +
                                  • + + + Padding Example + + + +
                                  • + +
                                  + +
                                  +
                                  +
                                  +
                                  + + + +
                                  +
                                  + + + + + + + +

                                  MicroPython String Formatting

                                  +

                                  The normal Python has advanced string formatting functions using "%" and .format methods documented at the PyFormat website.

                                  +

                                  Although most of these functions work, there are some exceptions when using date formats.

                                  +

                                  The following % formats do not work under MicroPython:

                                  +
                                    +
                                  1. %Y - year
                                  2. +
                                  3. %m - month
                                  4. +
                                  5. %d - day of month
                                  6. +
                                  7. %H - hour of day
                                  8. +
                                  9. %M - minute
                                  10. +
                                  +

                                  Padding Example

                                  +

                                  The following example prints a floating point number with two decimals of precision in a field of six characters with leading zeros.

                                  +
                                  1
                                  print('{:06.2f}'.format(3.141592653589793))
                                  +
                                  +

                                  returns:

                                  +
                                  1
                                  003.14
                                  +
                                  + + + + + + + + + + + + + + + +
                                  +
                                  + + + +
                                  + + + +
                                  + +
                                  + + + +
                                  + + + +
                                  + + +
                                  +
                                  + + Previous + +
                                  + TinyML +
                                  +
                                  +
                                  + + + + +
                                  + + Next + +
                                  + Operating System +
                                  +
                                  +
                                  + + +
                                  +
                                  + +
                                  + + +
                                  +
                                  +
                                  + + + Made with + + Material for MkDocs + + +
                                  + +
                                  +
                                  +
                                  + +
                                  +
                                  +
                                  +
                                  + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/13-timers/index.html b/advanced-labs/13-timers/index.html new file mode 100644 index 000000000..42d2c1f1c --- /dev/null +++ b/advanced-labs/13-timers/index.html @@ -0,0 +1,2272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Timers - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                  + + + + Skip to content + + +
                                  +
                                  + +
                                  + + + + + + +
                                  +
                                  + + + logo + + + +
                                  +
                                  +
                                  + + MicroPython for Kids + +
                                  +
                                  + + + Timers + + +
                                  +
                                  +
                                  + + + + + + + +
                                  + +
                                  +
                                  + + +
                                  + + +
                                  + +
                                  +
                                  +
                                  +
                                  +
                                  + Initializing search +
                                  +
                                    +
                                    +
                                    +
                                    +
                                    +
                                    + + +
                                    + +
                                    + + +
                                    +
                                    + GitHub Repo +
                                    +
                                    +
                                    + +
                                    + +
                                    + +
                                    + + + + + + +
                                    +
                                    + + + +
                                    +
                                    +
                                    + + + + +
                                    + + +
                                    + +
                                    + + +
                                    +
                                    + GitHub Repo +
                                    +
                                    +
                                    + +
                                      + + + + + + + +
                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + MicroPython Home + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + +
                                      + + + + + Advanced Labs + + + + + + + + +
                                      + +
                                      + +
                                        + + + + + + + + + +
                                      • + + + + + Internal Temperature + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Interrupt Handlers + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Timing Functions + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Conda Environment Setup + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + OS Functions + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + I2C Scanner + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Frame Buffer + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Minicom + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + SD Card Reader + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Converting CircuitPython + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + MicroPython Remote + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Rshell + + + + +
                                      • + + + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + Timers + + + + + + + +
                                        + + + + + + + +
                                          + +
                                        • + + + Types of Timers + + + +
                                        • + +
                                        • + + + Using Frequency on Periodic Timers + + + +
                                        • + +
                                        • + + + Hardware vs. Virtual Software Timers + + + +
                                        • + +
                                        • + + + Sample Timer Program + + + +
                                        • + +
                                        • + + + Sample Code to Toggle the Builtin LED + + + +
                                        • + +
                                        • + + + Sample Code to Animate an LED Strip With a Timer + + + +
                                        • + +
                                        • + + + Removing a Timer + + + +
                                        • + +
                                        • + + + Limits on the Number of Timers + + + +
                                        • + +
                                        • + + + Drawbacks of Timers and ISRs + + + +
                                        • + +
                                        • + + + Exercises + + + +
                                        • + +
                                        • + + + References + + + +
                                        • + +
                                        + +
                                        + +
                                      • + + + + + + + + + + +
                                      • + + + + + Memory Management + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + TinyML + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + String Formatting + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Operating System + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + Measuring Battery Voltage + + + + +
                                      • + + + + + + + + + + +
                                      • + + + + + File System + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Debugging + + + + + + + + + + +
                                      • + + + + +
                                      +
                                      + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + Glossary + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + References + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + Contributing + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + Contact + + + + +
                                    • + + + + + + + + + +
                                    • + + + + + Colophon + + + + +
                                    • + + + +
                                    +
                                    +
                                    +
                                    +
                                    + + + +
                                    +
                                    +
                                    + + +
                                    + + + + + + + +
                                      + +
                                    • + + + Types of Timers + + + +
                                    • + +
                                    • + + + Using Frequency on Periodic Timers + + + +
                                    • + +
                                    • + + + Hardware vs. Virtual Software Timers + + + +
                                    • + +
                                    • + + + Sample Timer Program + + + +
                                    • + +
                                    • + + + Sample Code to Toggle the Builtin LED + + + +
                                    • + +
                                    • + + + Sample Code to Animate an LED Strip With a Timer + + + +
                                    • + +
                                    • + + + Removing a Timer + + + +
                                    • + +
                                    • + + + Limits on the Number of Timers + + + +
                                    • + +
                                    • + + + Drawbacks of Timers and ISRs + + + +
                                    • + +
                                    • + + + Exercises + + + +
                                    • + +
                                    • + + + References + + + +
                                    • + +
                                    + +
                                    +
                                    +
                                    +
                                    + + + +
                                    +
                                    + + + + + + + +

                                    Timers in MicroPython

                                    +

                                    Timer Tutorial Banner +When clocks are used to trigger future events, they are called timers. Timers are used to efficiently use CPU resources. In microcontrollers, the work of keeping track of timers is frequently delegated to hardware outside of the main CPU loop. This makes your microcontroller more efficient, more reliable, and makes your code easier to read.

                                    +

                                    Timers work independently of the main CPU's clock. As a result, they are called asynchronous objects. Using timers can be both efficient and reliable, but they can be complex to debug. Errors within Timers and interrupts can be difficult to get information on.

                                    +

                                    Types of Timers

                                    +

                                    Timers are used to schedule events in the future. There are two types:

                                    +
                                      +
                                    1. A PERIODIC timer will continually fire events in the future at periodic intervals.
                                    2. +
                                    3. A ONE_SHOT timer will fire an event once and then stop.
                                    4. +
                                    +

                                    Both of these timer objects need a callback function to be specified when they are initialized. These callback functions are also called interrupt service routines (ISRs). This is the function that will be executed when the timer gets triggered. So we must define an ISR function before timers are properly initialized.

                                    +

                                    Periodic timers are usually initialized with a period parameter. This is the amount of time in milliseconds between each event. They are useful for doing like checking if new data is available on a network connection or checking if a sensor is still working.

                                    +

                                    One-shot timers are also initialized with a period parameter often called a "timeout" period. This is the amount of time in milliseconds before the timer will fire. One-shot timers are used if you want to do something in the future but don't want to deal with it now. You can think of this as a reminder service.

                                    +

                                    Here is how both Periodic and one-shot timers are setup:

                                    +
                                    1
                                    +2
                                    +3
                                    +4
                                    +5
                                    +6
                                    +7
                                    myOneShotTimer = Timer()
                                    +# call once in 10 seconds from now
                                    +myOneShotTimer.init(mode=Timer.ONE_SHOT, callback=myCallbackFunction, period=10000)
                                    +
                                    +# call every two seconds until the timer is deactivated
                                    +myPeriodicTimer = Timer()
                                    +myPeriodicTimer.init(mode=Timer.PERIODIC, callback=myCallbackFunction, period=2000) 
                                    +
                                    +

                                    Using Frequency on Periodic Timers

                                    +

                                    A Periodic timer can be configured to use either a period or a frequency as a parameter. The frequency is the number of times the timer will fire per second. The period is the amount of time in milliseconds between each event. The frequency is used to calculate the period. The following are equivalent:

                                    +
                                    1
                                    +2
                                    +3
                                    +4
                                    # 50ms between events
                                    +myTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel) 
                                    +# 20 events per second
                                    +myTimer.init(freq=20, mode=Timer.PERIODIC, callback=move_pixel) 
                                    +
                                    +

                                    You can always convert between the two by taking the inverse and multiplying by 1000.

                                    +
                                    1
                                    +2
                                    frequency = 1 / period * 1000
                                    +period = 1 / frequency * 1000
                                    +
                                    +

                                    Hardware vs. Virtual Software Timers

                                    +

                                    Older microcontrollers have fixed hardware associated with each timer. These are call "hardware timers". When you initialize a hardware timer, you specify what set of hardware to use using a fixed ID (0,1,2,3 etc.). On the Raspberry Pi Pico all timers are "virtual" and are implemented in software. All virtual timers have an ID of -1 and the timer ID does not need to be specified.

                                    +

                                    Sample Timer Program

                                    +

                                    In the following program we will create timer that will toggle the built-in LED on the Raspberry Pi Pico every second. We will create a new function called toggle_led() that will toggle the builtin LED on and off each time it is called. There are three key lines in this program.

                                    +
                                      +
                                    1. line 1 imports the Timer library
                                    2. +
                                    3. line 7 creates the uninitialized timer object
                                    4. +
                                    5. line 16 initialize the timer object to indicate how often to trigger the timer, the mode (periodic) and the callback function (toggle_led)
                                    6. +
                                    +

                                    Sample Code to Toggle the Builtin LED

                                    +

                                    Here is a sample code to toggle the builtin LED on the Raspberry Pi Pico and off.

                                    +
                                     1
                                    + 2
                                    + 3
                                    + 4
                                    + 5
                                    + 6
                                    + 7
                                    + 8
                                    + 9
                                    +10
                                    +11
                                    +12
                                    +13
                                    +14
                                    +15
                                    +16
                                    +17
                                    +18
                                    +19
                                    +20
                                    from machine import Pin, Timer
                                    +from utime import sleep
                                    +
                                    +# create an LED object using the onboard LED
                                    +myLED = machine.Pin("LED", machine.Pin.OUT)
                                    +
                                    +# create an uninitialized timer object
                                    +myTimer = Timer()
                                    +
                                    +# create a function to be called when the timer goes off
                                    +# this function just toggles the onboard LED
                                    +def toggle_led(timer):
                                    +    myLED.toggle()
                                    +
                                    +# initialize the timer object to tick every second (1,000 milliseconds)
                                    +myTimer.init(period=1000, mode=Timer.PERIODIC, callback=toggle_led)
                                    +
                                    +while True:
                                    +    sleep(10)
                                    +    print('just sleeping here')
                                    +
                                    +

                                    Sample Code to Animate an LED Strip With a Timer

                                    +

                                    Many times you want to animate an LED strip but not complicate up your main event loop with this code. For example, you might want to light up the entire strip with a pattern of motion on the LED strip. You can do this by creating a new function that will conditionally turn one pixel to a color and increment a global variable that keeps track of which pixel to turn on. This function will be called every time the timer goes off.

                                    +
                                     1
                                    + 2
                                    + 3
                                    + 4
                                    + 5
                                    + 6
                                    + 7
                                    + 8
                                    + 9
                                    +10
                                    +11
                                    +12
                                    +13
                                    +14
                                    +15
                                    +16
                                    +17
                                    +18
                                    +19
                                    +20
                                    +21
                                    +22
                                    +23
                                    +24
                                    +25
                                    +26
                                    +27
                                    +28
                                    +29
                                    +30
                                    +31
                                    from machine import Pin, Timer
                                    +from utime import sleep
                                    +from neopixel import NeoPixel
                                    +
                                    +NEOPIXEL_PIN = 0
                                    +NUMBER_PIXELS = 8
                                    +strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                    +
                                    +# create an uninitialized timer object
                                    +myTimer = Timer()
                                    +
                                    +counter = 0
                                    +# a callback function.  Use this with a timer that triggers 20 times a second
                                    +def move_pixel(myTimer):
                                    +    global counter
                                    +    for i in range(0, NUMBER_PIXELS):
                                    +        if i == counter:
                                    +            strip[i] = (10,0,0)
                                    +        else:
                                    +            strip[i] = (0,0,10)
                                    +        strip.write()
                                    +    counter += 1
                                    +    if counter > NUMBER_PIXELS:
                                    +        counter = 0
                                    +
                                    +# initialize the timer object to tick 20 times per second (50 milliseconds)
                                    +myTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel)
                                    +
                                    +while True:
                                    +    print('Just sleeping here.  The timer is doing all the work flashing the LED...', counter)
                                    +    sleep(5) # sleep for five seconds
                                    +
                                    +

                                    For example, if a robot has a set of "modes" like driving forward, turning left, turning right, backing up etc. You can use a timer to flash the LED strip in different colors with different patterns to indicate the robot is in different modes.

                                    +

                                    Removing a Timer

                                    +

                                    The Timer.deinit() can be used to remove a timer from the system. This is useful if you want to stop a timer that is currently running. If you have many timers that are each using memory, it is a good practice to remove them when you are done with them.

                                    +

                                    Limits on the Number of Timers

                                    +

                                    In MicroPython on the RP2040, there are no limits placed on the number of timers other than you must have enough memory available. Because there are no specific hardware limits, these are often referred to as "virtual" timers. The number of virtual timers is limited by the amount of memory available to the microcontroller.

                                    +

                                    Other implementations of MicroPython on different hardware have stricter limits placed on the number of timers. The ESP32 MicroPython port currently only has four hardware timers and a numeric ID of 0 to 3 must be used when you setup these timers. For the pyboard has a limit of 14 timers. Be aware of these limits if you are interested in creating portable MicroPython code.

                                    +

                                    Drawbacks of Timers and ISRs

                                    +

                                    Unfortunately, different hardware implementations of MicroPython have different ways to setup and use timers. Some hardware requires timers to each have an ID tied to a specific resource. Because of this, be cautious about using timers in your code if you require portability between hardware.

                                    +

                                    As we mentioned, timers need callback functions are a type of function called interrupt service requests (ISRs). In multi-core systems like the RP2040 these interrupts can only be called from the core that executed the timer. This means that if you are using a timer to trigger an interrupt, you must make sure that the interrupt is only called from the core that is executing the timer.

                                    +

                                    There are special limitations on what can and can't be done within interrupts in most systems. For example, you are not allowed to allocate dynamic memory within an interrupt. Your interrupt handler should be a short function that performs the minimum work to change external variables. This is because the interrupt handler is called in a separate thread and can't allocate memory.

                                    +

                                    In general, doing complex logic within timers and interrupts is not a good idea. If you are interested in doing complex logic, you should use a different method that is easy to debug. This will make your code easier to understand and maintain.

                                    +

                                    Exercises

                                    +
                                      +
                                    1. Can you change the frequency of the times in the sample code above?
                                    2. +
                                    3. How much memory do you think a timer will use? How many timers can be used on a RP2040 with 264K of memory?
                                    4. +
                                    5. What if you wanted a timer to check in on the health of your program? Could it reboot the Raspberry Pi using machine.reset() if it gets stuck? Hint: See Watchdog Timers
                                    6. +
                                    +

                                    References

                                    +
                                      +
                                    1. MicroPython Timers
                                    2. +
                                    3. MicroPython Documentation on Timers on the RP2040
                                    4. +
                                    5. Engineers Garage on Time and Timers in MicroPython
                                    6. +
                                    + + + + + + + + + + + + + + + +
                                    +
                                    + + + +
                                    + + + +
                                    + +
                                    + + + +
                                    + + + +
                                    + + +
                                    +
                                    + + Previous + +
                                    + Rshell +
                                    +
                                    +
                                    + + + + +
                                    + + Next + +
                                    + Memory Management +
                                    +
                                    +
                                    + + +
                                    +
                                    + +
                                    + + +
                                    +
                                    +
                                    + + + Made with + + Material for MkDocs + + +
                                    + +
                                    +
                                    +
                                    + +
                                    +
                                    +
                                    +
                                    + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/14-memory-management/index.html b/advanced-labs/14-memory-management/index.html new file mode 100644 index 000000000..8ce01189f --- /dev/null +++ b/advanced-labs/14-memory-management/index.html @@ -0,0 +1,2166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Memory Management - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                    + + + + Skip to content + + +
                                    +
                                    + +
                                    + + + + + + +
                                    +
                                    + + + logo + + + +
                                    +
                                    +
                                    + + MicroPython for Kids + +
                                    +
                                    + + + Memory Management + + +
                                    +
                                    +
                                    + + + + + + + +
                                    + +
                                    +
                                    + + +
                                    + + +
                                    + +
                                    +
                                    +
                                    +
                                    +
                                    + Initializing search +
                                    +
                                      +
                                      +
                                      +
                                      +
                                      +
                                      + + +
                                      + +
                                      + + +
                                      +
                                      + GitHub Repo +
                                      +
                                      +
                                      + +
                                      + +
                                      + +
                                      + + + + + + +
                                      +
                                      + + + +
                                      +
                                      +
                                      + + + + +
                                      + + +
                                      + +
                                      + + +
                                      +
                                      + GitHub Repo +
                                      +
                                      +
                                      + +
                                        + + + + + + + +
                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + MicroPython Home + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + +
                                        + + + + + Advanced Labs + + + + + + + + +
                                        + +
                                        + +
                                          + + + + + + + + + +
                                        • + + + + + Internal Temperature + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Interrupt Handlers + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Timing Functions + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Conda Environment Setup + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + OS Functions + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + I2C Scanner + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Frame Buffer + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Minicom + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + SD Card Reader + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Converting CircuitPython + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + MicroPython Remote + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Rshell + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Timers + + + + +
                                        • + + + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + Memory Management + + + + + + + +
                                          + + + + + + + +
                                            + +
                                          • + + + Memory Management Concepts + + + +
                                          • + +
                                          • + + + Functions to show free and used memory + + + +
                                            +
                                              + +
                                            • + + + Viewing Memory Layout + + + +
                                            • + +
                                            +
                                            + +
                                          • + +
                                          • + + + Functions to manually allocate and free memory + + + +
                                          • + +
                                          • + + + Image Size + + + +
                                          • + +
                                          • + + + References + + + +
                                          • + +
                                          + +
                                          + +
                                        • + + + + + + + + + + +
                                        • + + + + + TinyML + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + String Formatting + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Operating System + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + Measuring Battery Voltage + + + + +
                                        • + + + + + + + + + + +
                                        • + + + + + File System + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Debugging + + + + + + + + + + +
                                        • + + + + +
                                        +
                                        + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + Glossary + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + References + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + Contributing + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + Contact + + + + +
                                      • + + + + + + + + + +
                                      • + + + + + Colophon + + + + +
                                      • + + + +
                                      +
                                      +
                                      +
                                      +
                                      + + + +
                                      +
                                      +
                                      + + +
                                      + + + + + + + +
                                        + +
                                      • + + + Memory Management Concepts + + + +
                                      • + +
                                      • + + + Functions to show free and used memory + + + +
                                        +
                                          + +
                                        • + + + Viewing Memory Layout + + + +
                                        • + +
                                        +
                                        + +
                                      • + +
                                      • + + + Functions to manually allocate and free memory + + + +
                                      • + +
                                      • + + + Image Size + + + +
                                      • + +
                                      • + + + References + + + +
                                      • + +
                                      + +
                                      +
                                      +
                                      +
                                      + + + +
                                      +
                                      + + + + + + + +

                                      Memory Management in MicroPython

                                      +

                                      In the recent past, memory management has been a challenge for embedded systems. Before 2020 microcontrollers like the Arduino usually only came with a few kilobytes of RAM, and careful attention needed to be paid to each byte using clever memory management trickery. The memory management system in recent years has become much easier. Even a low-cost $4 Raspberry Pi Pico now comes with 264K RAM! This is an almost 100-fold increase over the older Arduino Uno which only had 2K of RAM. That being said, there are always developers that push their hardware to the limit, and knowing the basics of memory management is important to understand how embedded systems work.

                                      +

                                      MicroPython is very clever about how memory is allocated. It is very stingy about memory use and will only allocate memory for what is needed. This is very different from the standard Python that allocates memory for everything that is needed up-front assuming that most laptops, desktops and servers have gigabytes of RAM and virtual memory support. This is an important difference, and it is important to understand if you want to push the limits of your microcontroller.

                                      +

                                      This lab will cover the basics of memory management, and how to use the memory management system in MicroPython. +We will cover the following topics:

                                      +
                                        +
                                      1. Memory Management Concepts: The Heap, Stack, and Garbage Collection
                                      2. +
                                      3. Functions to show the amount of free and used memory and current memory usage
                                      4. +
                                      5. Functions to manually allocate and free memory
                                      6. +
                                      7. Functions to debug memory allocation
                                      8. +
                                      +

                                      Memory Management Concepts

                                      +

                                      Memory Heap Stack

                                      +

                                      The memory management system is responsible for allocating and freeing memory. The memory management system must allocate memory for data variables, and for freeing this memory when a variable is no longer needed. The system is also responsible for allocating memory for the parameters used by functions, and for freeing memory when a function is no longer needed. You can read more about memory management on the MicroPython Memory Management Docs website.

                                      +

                                      The heap is the area of memory that is used to store general data. In MicroPython the heap is located in the lower memory and it grows upwards in memory address space. The exception is memory used as parameters to functions, which is stored in the stack.

                                      +

                                      The stack is the area of memory that is used to store all the parameters to function calls. In MicroPython the stack is located in the upper memory and it grows downwards in memory address space. If you are calling highly recursive functions, the stack will get a lot of use.

                                      +

                                      The garbage collector is a process to reuse memory that is no longer in use. The garbage collector is automatically run when the heap is full, but you can also run it manually to reclaim unused memory to get finer-grain control over memory usage and to avoid memory fragmentation.

                                      +

                                      In MicroPython most of these operations are done automatically for you. You don't really need to worry about how memory works unless you are reaching the limits of what your microcontroller can do.

                                      +

                                      One other key concept is continuous memory. If you are allocating a large amount of memory in an array or a long string, we need to allocate all this memory in one large chunk. As programs run for a long time memory becomes fragmented (many small free sections) and can't be used for storing large arrays.

                                      +

                                      You can read more about how MicroPython is clever about memory usage by reading the MicroPython Optimizations Docs website.

                                      +

                                      Functions to show free and used memory

                                      +

                                      We will be using the "gc" module to show the amount of free and used memory. "gc" orignally stood for "garbage collection", but the model has been generalized to perform other memory management tasks.

                                      +

                                      Here are the key functions to show the amount of free and used memory and current memory usage on a Raspberry Pi Pico with an RP2040 microcontroller: gc.mem_free() and gc.mem_alloc():

                                      +
                                      1
                                      +2
                                      +3
                                      +4
                                      +5
                                      import gc
                                      +import micropython
                                      +
                                      +print('Memory Free:', "{:,}".format(gc.mem_free()), 'bytes')
                                      +print('Memory Allocated:', "{:,}".format(gc.mem_alloc()), 'bytes')
                                      +
                                      +

                                      results for RP2040:

                                      +
                                      1
                                      +2
                                      Memory Free: 187,232 bytes
                                      +Memory Allocated: 4,864 bytes
                                      +
                                      +

                                      You can see that although the RP2040 chip has a specification of 264K of RAM, it only has 187,232 bytes of RAM available for program use. The other RAM us used to store the MicroPython interpreter software. You can also see that the heap is currently using 4,864 bytes of RAM. This is typical of the additional overhead that MicroPython requires to run a program.

                                      +

                                      Viewing Memory Layout

                                      +

                                      You can use the micropython.mem_info(1) function to view the memory layout of the MicroPython interpreter. This function returns a list of tuples, each tuple containing the address, size and type of each memory block. The address on the left of each row is the memory address of the start of the block within the heap. In MicroPython, memory blocks are each typically 16 bytes.

                                      +
                                      1
                                      +2
                                      +3
                                      ```python
                                      +import micropython
                                      +print(micropython.mem_info(1))
                                      +
                                      +

                                      results: +

                                       1
                                      + 2
                                      + 3
                                      + 4
                                      + 5
                                      + 6
                                      + 7
                                      + 8
                                      + 9
                                      +10
                                      +11
                                      +12
                                      +13
                                      stack: 532 out of 7936
                                      +GC: total: 192064, used: 4896, free: 187168
                                      + No. of 1-blocks: 52, 2-blocks: 13, max blk sz: 64, max free sz: 11650
                                      +GC memory layout; from 200084a0:
                                      +00000: h=MhhhBDhhBTTBDhTBDBBBh===DBDh====B=BBBBBBTB=BTB=BBBTB=TBTB=Bh==
                                      +00400: =BB=h===========TB=h=h===================h=====h==h=============
                                      +00800: ====h===========================================================
                                      +00c00: ====h===========================================================
                                      +01000: ====h=hBhh=ShhS..h=.........Sh=.................................
                                      +01400: ....Shh=======h========h====h=====..............................
                                      +       (181 lines all free)
                                      +2ec00: ....................................
                                      +None
                                      +

                                      +

                                      This shows that the garbage collector is responsible for managing a total of 192,064 bytes of memory. The other numbers give you an indication of how fragmented you heap is.

                                      +
                                        +
                                      • The number of 1-blocks is 52
                                      • +
                                      • The number of 2-block spaces is 13
                                      • +
                                      • The maximum block size is 64
                                      • +
                                      • The maximum free size is 11,650
                                      • +
                                      • The heap starts at memory location: 2000 84a0
                                      • +
                                      +

                                      Each of the letters represents the type of memory at that position on the heap:

                                      +

                                      | Letter | Description | +||| +|.|Free memory| +|h|head of a block of memory| +|=|tail of a block of memory| +|T|Tuple| +|L|List| +|D|Dictionary| +|S|String| +|A|Array or Byte Array| +|F|Float| +|B|Function BC| +|M|Module|

                                      +

                                      If the heap is 192,064 bytes and each block is 16 bytes then there should be 12,004 blocks on the heap. If each row in the report displays 62 characters then there are 12,004/62=193 rows in the report. To keep the report short, the function will only show the rows that are not free. The report indicates that there are 181 lines all free blocks, so it will only show the non-free lines which in the example above is about six non-free rows in lower heap memory.

                                      +

                                      Functions to manually allocate and free memory

                                      +

                                      You can manually run the garbage collector using the gc.collect() functions. This function is used to force garbage collection exactly when you want to, not when the heap is full. This may occur at a time that is inconvenient for the program when it must be sending data at a specific speed.

                                      +
                                      +

                                      Note

                                      +

                                      Still under development.

                                      +
                                      +
                                       1
                                      + 2
                                      + 3
                                      + 4
                                      + 5
                                      + 6
                                      + 7
                                      + 8
                                      + 9
                                      +10
                                      +11
                                      +12
                                      +13
                                      +14
                                      +15
                                      +16
                                      import gc
                                      +import micropython
                                      +
                                      +def show_memory():
                                      +    print('Memory Free:', "{:,}".format(gc.mem_free()), 'bytes')
                                      +    print('Memory Allocated:', "{:,}".format(gc.mem_alloc()), 'bytes')
                                      +
                                      +show_memory()
                                      +# allocate a block of memory
                                      +print('Allocating a block of memory')
                                      +myBigBlockOfMemory = matrix[100][100]
                                      +show_memory()
                                      +print('Freeing the block of memory')
                                      +# free the block of memory
                                      +gc.mem_free(ptr)
                                      +show_memory()
                                      +
                                      +

                                      Image Size

                                      +

                                      You can determine how much space we have available on the Pico flash after programming an ELF or UF2 file. For example, if we have an ELF file that's 1 MB and we were to program via openocd, then where should we offset my user data in flash? (i.e. XIP_BASE + OFFSET)

                                      +

                                      With an elf or uf2 file, using picotool info -a on it will show the start and end of the binary (the start is usually 0x10000000 unless you did something to change it).

                                      +

                                      Inside your code, you can use the symbols defined by the linker script __flash_binary_start (defined here) and __flash_binary_end (defined here) like this:

                                      +
                                      1
                                      +2
                                      +3
                                      +4
                                      +5
                                      extern char __flash_binary_start;  // defined in linker script
                                      +extern char __flash_binary_end;    // defined in linker script
                                      +uintptr_t start = (uintptr_t) &__flash_binary_start;
                                      +uintptr_t end = (uintptr_t) &__flash_binary_end;
                                      +printf("Binary starts at %08x and ends at %08x, size is %08x\n", start, end, end-start);
                                      +
                                      +

                                      References

                                      +
                                        +
                                      • Code that Prints Memory Block Types
                                      • +
                                      + + + + + + + + + + + + + + + +
                                      +
                                      + + + +
                                      + + + +
                                      + +
                                      + + + +
                                      + + + +
                                      + + +
                                      +
                                      + + Previous + +
                                      + Timers +
                                      +
                                      +
                                      + + + + +
                                      + + Next + +
                                      + TinyML +
                                      +
                                      +
                                      + + +
                                      +
                                      + +
                                      + + +
                                      +
                                      +
                                      + + + Made with + + Material for MkDocs + + +
                                      + +
                                      +
                                      +
                                      + +
                                      +
                                      +
                                      +
                                      + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/15-measuring-vsys/index.html b/advanced-labs/15-measuring-vsys/index.html new file mode 100644 index 000000000..5767fd90e --- /dev/null +++ b/advanced-labs/15-measuring-vsys/index.html @@ -0,0 +1,1878 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Measuring Battery Voltage - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                      + + + + Skip to content + + +
                                      +
                                      + +
                                      + + + + + + +
                                      +
                                      + + + logo + + + +
                                      +
                                      +
                                      + + MicroPython for Kids + +
                                      +
                                      + + + Measuring Battery Voltage + + +
                                      +
                                      +
                                      + + + + + + + +
                                      + +
                                      +
                                      + + +
                                      + + +
                                      + +
                                      +
                                      +
                                      +
                                      +
                                      + Initializing search +
                                      +
                                        +
                                        +
                                        +
                                        +
                                        +
                                        + + +
                                        + +
                                        + + +
                                        +
                                        + GitHub Repo +
                                        +
                                        +
                                        + +
                                        + +
                                        + +
                                        + + + + + + +
                                        +
                                        + + + +
                                        +
                                        +
                                        + + + + +
                                        + + +
                                        + +
                                        + + +
                                        +
                                        + GitHub Repo +
                                        +
                                        +
                                        + +
                                          + + + + + + + +
                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + MicroPython Home + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + +
                                          + + + + + Advanced Labs + + + + + + + + +
                                          + +
                                          + +
                                            + + + + + + + + + +
                                          • + + + + + Internal Temperature + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Interrupt Handlers + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Timing Functions + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Conda Environment Setup + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + OS Functions + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + I2C Scanner + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Frame Buffer + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Minicom + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + SD Card Reader + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Converting CircuitPython + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + MicroPython Remote + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Rshell + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Timers + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Memory Management + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + TinyML + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + String Formatting + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + Operating System + + + + +
                                          • + + + + + + + + + + + + +
                                          • + + + + + + + + + + + + Measuring Battery Voltage + + + + + +
                                          • + + + + + + + + + + +
                                          • + + + + + File System + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Debugging + + + + + + + + + + +
                                          • + + + + +
                                          +
                                          + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + Glossary + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + References + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + Contributing + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + Contact + + + + +
                                        • + + + + + + + + + +
                                        • + + + + + Colophon + + + + +
                                        • + + + +
                                        +
                                        +
                                        +
                                        +
                                        + + + +
                                        +
                                        +
                                        + + +
                                        + + + + + + +
                                        +
                                        +
                                        +
                                        + + + +
                                        +
                                        + + + + + + + +

                                        Measuring VSys

                                        +

                                        You need to set GP25 to output and set it high and also set GP29 to input with no pull resistors before reading. +And don't forget that the input from VSYS to ADC is divided by 3, so you have to multiply your result to get real value. +When I do that I get around 4.7 V when powered from USB, so it definitely works.

                                        +

                                        https://forums.raspberrypi.com/viewtopic.php?t=301152

                                        +
                                        1
                                        +2
                                        +3
                                        +4
                                        +5
                                        +6
                                        +7
                                        +8
                                        +9
                                        import machine
                                        +
                                        +# Vsys = machine.ADC(3)
                                        +Vsys = machine.ADC(29)
                                        +conversion_factor = (3.3 / (65535)) * 3
                                        +
                                        +reading = Vsys.read_u16() * conversion_factor
                                        +
                                        +print(reading)
                                        +
                                        + + + + + + + + + + + + + + + +
                                        +
                                        + + + +
                                        + + + +
                                        + +
                                        + + + +
                                        + + + +
                                        + + +
                                        +
                                        + + Previous + +
                                        + Operating System +
                                        +
                                        +
                                        + + + + +
                                        + + Next + +
                                        + File System +
                                        +
                                        +
                                        + + +
                                        +
                                        + +
                                        + + +
                                        +
                                        +
                                        + + + Made with + + Material for MkDocs + + +
                                        + +
                                        +
                                        +
                                        + +
                                        +
                                        +
                                        +
                                        + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/16-dual-core/index.html b/advanced-labs/16-dual-core/index.html new file mode 100644 index 000000000..eb73dcebe --- /dev/null +++ b/advanced-labs/16-dual-core/index.html @@ -0,0 +1,1286 @@ + + + + + + + + + + + + + + + + + + + + + + + 16 dual core - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                        + +
                                        +
                                        + +
                                        + + + + + + +
                                        +
                                        + + + logo + + + +
                                        +
                                        +
                                        + + MicroPython for Kids + +
                                        +
                                        + + + 16 dual core + + +
                                        +
                                        +
                                        + + + + + + + +
                                        + +
                                        +
                                        + + +
                                        + + +
                                        + +
                                        +
                                        +
                                        +
                                        +
                                        + Initializing search +
                                        +
                                          +
                                          +
                                          +
                                          +
                                          +
                                          + + +
                                          + +
                                          + + +
                                          +
                                          + GitHub Repo +
                                          +
                                          +
                                          + +
                                          + +
                                          + +
                                          + + + + + + +
                                          +
                                          + + + +
                                          +
                                          +
                                          + + + + +
                                          + + +
                                          + +
                                          + + +
                                          +
                                          + GitHub Repo +
                                          +
                                          +
                                          + +
                                            + + + + + + + +
                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + MicroPython Home + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + Glossary + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + References + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + Contributing + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + Contact + + + + +
                                          • + + + + + + + + + +
                                          • + + + + + Colophon + + + + +
                                          • + + + +
                                          +
                                          +
                                          +
                                          +
                                          + + + +
                                          +
                                          +
                                          + + +
                                          + + + + +
                                          +
                                          +
                                          +
                                          + + + +
                                          +
                                          + + + + + + + +

                                          16 dual core

                                          + + + + + + + + + + + + + + + + + + + + +
                                          +
                                          + + + +
                                          + + + +
                                          + +
                                          + + + +
                                          +
                                          +
                                          + + + Made with + + Material for MkDocs + + +
                                          + +
                                          +
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/17-file-system/index.html b/advanced-labs/17-file-system/index.html new file mode 100644 index 000000000..199ca9f2d --- /dev/null +++ b/advanced-labs/17-file-system/index.html @@ -0,0 +1,2057 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + File System - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                          + + + + Skip to content + + +
                                          +
                                          + +
                                          + + + + + + +
                                          +
                                          + + + logo + + + +
                                          +
                                          +
                                          + + MicroPython for Kids + +
                                          +
                                          + + + File System + + +
                                          +
                                          +
                                          + + + + + + + +
                                          + +
                                          +
                                          + + +
                                          + + +
                                          + +
                                          +
                                          +
                                          +
                                          +
                                          + Initializing search +
                                          +
                                            +
                                            +
                                            +
                                            +
                                            +
                                            + + +
                                            + +
                                            + + +
                                            +
                                            + GitHub Repo +
                                            +
                                            +
                                            + +
                                            + +
                                            + +
                                            + + + + + + +
                                            +
                                            + + + +
                                            +
                                            +
                                            + + + + +
                                            + + +
                                            + +
                                            + + +
                                            +
                                            + GitHub Repo +
                                            +
                                            +
                                            + +
                                              + + + + + + + +
                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + MicroPython Home + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + +
                                              + + + + + Advanced Labs + + + + + + + + +
                                              + +
                                              + +
                                                + + + + + + + + + +
                                              • + + + + + Internal Temperature + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Interrupt Handlers + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Timing Functions + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Conda Environment Setup + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + OS Functions + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + I2C Scanner + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Frame Buffer + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Minicom + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + SD Card Reader + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Converting CircuitPython + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + MicroPython Remote + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Rshell + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Timers + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Memory Management + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + TinyML + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + String Formatting + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Operating System + + + + +
                                              • + + + + + + + + + + +
                                              • + + + + + Measuring Battery Voltage + + + + +
                                              • + + + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + File System + + + + + + + +
                                                + + + + + + + +
                                                  + +
                                                • + + + Blocks and Fragments + + + +
                                                • + +
                                                • + + + File Systems Statistics + + + +
                                                • + +
                                                • + + + Using Statvfs + + + +
                                                • + +
                                                + +
                                                + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Debugging + + + + + + + + + + +
                                              • + + + + +
                                              +
                                              + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + Glossary + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + References + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + Contributing + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + Contact + + + + +
                                            • + + + + + + + + + +
                                            • + + + + + Colophon + + + + +
                                            • + + + +
                                            +
                                            +
                                            +
                                            +
                                            + + + +
                                            +
                                            +
                                            + + +
                                            + + + + + + + +
                                              + +
                                            • + + + Blocks and Fragments + + + +
                                            • + +
                                            • + + + File Systems Statistics + + + +
                                            • + +
                                            • + + + Using Statvfs + + + +
                                            • + +
                                            + +
                                            +
                                            +
                                            +
                                            + + + +
                                            +
                                            + + + + + + + +

                                            MicroPython File Systems

                                            +

                                            Unlike older Arduino systems, MicroPython has full support for a "virtual file system" (VFS) that we use to store and retrieve programs and data. The way we access the file systems in MicroPython +is similar to the way we access files in standard Python.

                                            +

                                            Blocks and Fragments

                                            +

                                            First, we need to define two key terms: blocks and fragments.

                                            +

                                            The block size refers to the size of the fundamental unit of storage on the file system. All files and directories occupy an integral number of blocks, with the size of each file and directory being a multiple of the block size. The block size is typically a power of 2, and can vary depending on the file system and the size of the storage medium.

                                            +

                                            The fragment size, on the other hand, refers to the smallest unit of space that can be allocated for a file or directory. Files and directories may occupy a number of fragments that is not necessarily an integer multiple of the fragment size. Fragmentation occurs when the file system is unable to allocate a contiguous block of storage for a file or directory, resulting in the file or directory being spread out over multiple fragments. The fragment size is typically smaller than the block size, and may also vary depending on the file system and the size of the storage medium.

                                            +

                                            File Systems Statistics

                                            +

                                            In MicroPython, the os.statvfs('/') function provides information about the root file system. Among the information it provides is the block size and fragment size of the file system.

                                            +

                                            In the os.statvfs('/') function, the block size and fragment size are reported as the first and second elements of the tuple returned by the function, respectively. Specifically, stats[0] contains the block size, and stats[1] contains the fragment size. These values can be used to calculate various file system statistics, such as the total size of the file system, the total number of blocks and fragments, and the amount of free space available.

                                            +

                                            You can also mount file systems on other flash drives. You can get the stats of these file systems by using the new mount point with the os.statvfs() function.

                                            +

                                            Using Statvfs

                                            +
                                             1
                                            + 2
                                            + 3
                                            + 4
                                            + 5
                                            + 6
                                            + 7
                                            + 8
                                            + 9
                                            +10
                                            +11
                                            +12
                                            +13
                                            +14
                                            +15
                                            +16
                                            +17
                                            +18
                                            +19
                                            +20
                                            +21
                                            +22
                                            +23
                                            +24
                                            +25
                                            +26
                                            +27
                                            +28
                                            +29
                                            +30
                                            +31
                                            +32
                                            +33
                                            +34
                                            +35
                                            +36
                                            +37
                                            +38
                                            +39
                                            +40
                                            +41
                                            +42
                                            +43
                                            +44
                                            +45
                                            +46
                                            +47
                                            +48
                                            +49
                                            """
                                            +Print the statistics from the virtual file system (vfs)
                                            +
                                            +https://docs.micropython.org/en/latest/library/os.html?highlight=os#os.statvfs
                                            +
                                            +0 f_bsize – file system block size
                                            +1 f_frsize – fragment size
                                            +2 f_blocks – size of fs in f_frsize units
                                            +3 f_bfree – number of free blocks
                                            +4 f_bavail – number of free blocks for unprivileged users
                                            +5 f_files – number of inodes
                                            +6 f_ffree – number of free inodes
                                            +7 f_favail – number of free inodes for unprivileged users
                                            +8 f_flag – mount flags
                                            +9 f_namemax – maximum filename length
                                            +"""
                                            +
                                            +import os
                                            +
                                            +stats = os.statvfs("/")
                                            +print(stats)
                                            +
                                            +block_size = stats[0]
                                            +fragment_size = stats[1]
                                            +total_blocks = stats[2]
                                            +
                                            +free_blocks = stats[3]
                                            +available_blocks = stats[4]
                                            +
                                            +mount_flags = stats[8]
                                            +max_filename_length = stats[9]
                                            +
                                            +# byte calculations
                                            +total_bytes = total_blocks * fragment_size
                                            +free_bytes = free_blocks * fragment_size
                                            +available_bytes = available_blocks * fragment_size
                                            +
                                            +print("File system block size: {:,} bytes".format(block_size))
                                            +print("Fragement size: {:,} bytes".format(fragment_size))
                                            +print("Size of entire file system in fragement blocks: {:,}".format(total_blocks))
                                            +print("Size of entire file system in bytes: {:,}".format(total_bytes))
                                            +
                                            +print("Total free blocks for system and users: {:,}".format(free_blocks))
                                            +print("Number of free blocks for unprivileged users: {:,} bytes".format(available_blocks))
                                            +
                                            +print("Free size for system and users: {:,} bytes".format(free_bytes))
                                            +print("Free size for users: {:,} bytes".format(available_bytes))
                                            +print("Mount flags: {:,}".format(mount_flags))
                                            +print("Max filename length: {:,}".format(max_filename_length))
                                            +
                                            + + + + + + + + + + + + + + + +
                                            +
                                            + + + +
                                            + + + +
                                            + +
                                            + + + +
                                            + + + +
                                            + + +
                                            +
                                            + + Previous + +
                                            + Measuring Battery Voltage +
                                            +
                                            +
                                            + + + + +
                                            + + Next + +
                                            + Introduction +
                                            +
                                            +
                                            + + +
                                            +
                                            + +
                                            + + +
                                            +
                                            +
                                            + + + Made with + + Material for MkDocs + + +
                                            + +
                                            +
                                            +
                                            + +
                                            +
                                            +
                                            +
                                            + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/20-tinyml/index.html b/advanced-labs/20-tinyml/index.html new file mode 100644 index 000000000..c07546cbc --- /dev/null +++ b/advanced-labs/20-tinyml/index.html @@ -0,0 +1,1920 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + TinyML - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                            + + + + Skip to content + + +
                                            +
                                            + +
                                            + + + + + + +
                                            +
                                            + + + logo + + + +
                                            +
                                            +
                                            + + MicroPython for Kids + +
                                            +
                                            + + + TinyML + + +
                                            +
                                            +
                                            + + + + + + + +
                                            + +
                                            +
                                            + + +
                                            + + +
                                            + +
                                            +
                                            +
                                            +
                                            +
                                            + Initializing search +
                                            +
                                              +
                                              +
                                              +
                                              +
                                              +
                                              + + +
                                              + +
                                              + + +
                                              +
                                              + GitHub Repo +
                                              +
                                              +
                                              + +
                                              + +
                                              + +
                                              + + + + + + +
                                              +
                                              + + + +
                                              +
                                              +
                                              + + + + +
                                              + + +
                                              + +
                                              + + +
                                              +
                                              + GitHub Repo +
                                              +
                                              +
                                              + +
                                                + + + + + + + +
                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + MicroPython Home + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + +
                                                + + + + + Advanced Labs + + + + + + + + +
                                                + +
                                                + +
                                                  + + + + + + + + + +
                                                • + + + + + Internal Temperature + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Interrupt Handlers + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Timing Functions + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Conda Environment Setup + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + OS Functions + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + I2C Scanner + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Frame Buffer + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Minicom + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + SD Card Reader + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Converting CircuitPython + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + MicroPython Remote + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Rshell + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Timers + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Memory Management + + + + +
                                                • + + + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + TinyML + + + + + + + +
                                                  + + + + + + + +
                                                    + +
                                                  • + + + References + + + +
                                                  • + +
                                                  + +
                                                  + +
                                                • + + + + + + + + + + +
                                                • + + + + + String Formatting + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Operating System + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + Measuring Battery Voltage + + + + +
                                                • + + + + + + + + + + +
                                                • + + + + + File System + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Debugging + + + + + + + + + + +
                                                • + + + + +
                                                +
                                                + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + Glossary + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + References + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + Contributing + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + Contact + + + + +
                                              • + + + + + + + + + +
                                              • + + + + + Colophon + + + + +
                                              • + + + +
                                              +
                                              +
                                              +
                                              +
                                              + + + +
                                              +
                                              +
                                              + + +
                                              + + + + + + + +
                                                + +
                                              • + + + References + + + +
                                              • + +
                                              + +
                                              +
                                              +
                                              +
                                              + + + +
                                              +
                                              + + + + + + + +

                                              TinyML

                                              +

                                              TinyML is designed to help you do machine learning and embedded systems. Once you have trained a deep learning model, you can use TinyML perform data analysis (inference) on a microcontroller or a cell phone.

                                              +

                                              References

                                              +
                                                +
                                              • UCTRONICS RP2040 Dev Board for TinyMLd - $50.00 US
                                              • +
                                              • Harvard Fundamentals of TinyML Course - free without certificate.
                                              • +
                                              • EMLearn GitHub Repo for Machine Learning
                                              • +
                                              • EMLearn YouTube Video
                                              • +
                                              + + + + + + + + + + + + + + + +
                                              +
                                              + + + +
                                              + + + +
                                              + +
                                              + + + +
                                              + + + +
                                              + + +
                                              +
                                              + + Previous + +
                                              + Memory Management +
                                              +
                                              +
                                              + + + + +
                                              + + Next + +
                                              + String Formatting +
                                              +
                                              +
                                              + + +
                                              +
                                              + +
                                              + + +
                                              +
                                              +
                                              + + + Made with + + Material for MkDocs + + +
                                              + +
                                              +
                                              +
                                              + +
                                              +
                                              +
                                              +
                                              + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/21-botton-callback/index.html b/advanced-labs/21-botton-callback/index.html new file mode 100644 index 000000000..2df43e7e4 --- /dev/null +++ b/advanced-labs/21-botton-callback/index.html @@ -0,0 +1,1321 @@ + + + + + + + + + + + + + + + + + + + + + + + Button Callback - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                              + + + + Skip to content + + +
                                              +
                                              + +
                                              + + + + + + +
                                              +
                                              + + + logo + + + +
                                              +
                                              +
                                              + + MicroPython for Kids + +
                                              +
                                              + + + Button Callback + + +
                                              +
                                              +
                                              + + + + + + + +
                                              + +
                                              +
                                              + + +
                                              + + +
                                              + +
                                              +
                                              +
                                              +
                                              +
                                              + Initializing search +
                                              +
                                                +
                                                +
                                                +
                                                +
                                                +
                                                + + +
                                                + +
                                                + + +
                                                +
                                                + GitHub Repo +
                                                +
                                                +
                                                + +
                                                + +
                                                + +
                                                + + + + + + +
                                                +
                                                + + + +
                                                +
                                                +
                                                + + + + +
                                                + + +
                                                + +
                                                + + +
                                                +
                                                + GitHub Repo +
                                                +
                                                +
                                                + +
                                                  + + + + + + + +
                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + MicroPython Home + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + Glossary + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + References + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + Contributing + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + Contact + + + + +
                                                • + + + + + + + + + +
                                                • + + + + + Colophon + + + + +
                                                • + + + +
                                                +
                                                +
                                                +
                                                +
                                                + + + +
                                                +
                                                +
                                                + + +
                                                + + + + + + +
                                                +
                                                +
                                                +
                                                + + + +
                                                +
                                                + + + + + + + +

                                                Button Callback

                                                +
                                                 1
                                                + 2
                                                + 3
                                                + 4
                                                + 5
                                                + 6
                                                + 7
                                                + 8
                                                + 9
                                                +10
                                                +11
                                                +12
                                                +13
                                                +14
                                                +15
                                                +16
                                                import re
                                                +
                                                +def extract_gpio_pin(input_string):
                                                +    # Use a regular expression to find the GPIO number
                                                +    match = re.search(r"GPIO(\d+)", input_string)
                                                +    if match:
                                                +        # Convert the extracted number to an integer to remove leading zeros
                                                +        return int(match.group(1))
                                                +    else:
                                                +        # Return None if no match is found (or raise an exception if that's preferable)
                                                +        return None
                                                +
                                                +# Test the function with examples
                                                +print(extract_gpio_pin("Pin(GPIO15, mode=IN, pull=PULL_UP)"))  # Output: 15
                                                +print(extract_gpio_pin("Pin(GPIO7, mode=IN, pull=PULL_UP)"))   # Output: 7
                                                +print(extract_gpio_pin("Pin(GPIO03, mode=IN, pull=PULL_UP)"))  # Output: 3
                                                +
                                                +

                                                https://chat.openai.com/share/6e6d8123-ed4d-4dc6-a915-030fe2245dfe

                                                + + + + + + + + + + + + + + + +
                                                +
                                                + + + +
                                                + + + +
                                                + +
                                                + + + +
                                                +
                                                +
                                                + + + Made with + + Material for MkDocs + + +
                                                + +
                                                +
                                                +
                                                + +
                                                +
                                                +
                                                +
                                                + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/index.html b/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/index.html new file mode 100644 index 000000000..16d7a2abb --- /dev/null +++ b/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/index.html @@ -0,0 +1,2152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Test Incomming - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                + + + + Skip to content + + +
                                                +
                                                + +
                                                + + + + + + +
                                                +
                                                + + + logo + + + +
                                                +
                                                +
                                                + + MicroPython for Kids + +
                                                +
                                                + + + Test Incomming + + +
                                                +
                                                +
                                                + + + + + + + +
                                                + +
                                                +
                                                + + +
                                                + + +
                                                + +
                                                +
                                                +
                                                +
                                                +
                                                + Initializing search +
                                                +
                                                  +
                                                  +
                                                  +
                                                  +
                                                  +
                                                  + + +
                                                  + +
                                                  + + +
                                                  +
                                                  + GitHub Repo +
                                                  +
                                                  +
                                                  + +
                                                  + +
                                                  + +
                                                  + + + + + + +
                                                  +
                                                  + + + +
                                                  +
                                                  +
                                                  + + + + +
                                                  + + +
                                                  + +
                                                  + + +
                                                  +
                                                  + GitHub Repo +
                                                  +
                                                  +
                                                  + +
                                                    + + + + + + + +
                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + MicroPython Home + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + +
                                                    + + + + + Advanced Labs + + + + + + + + +
                                                    + +
                                                    + +
                                                      + + + + + + + + + +
                                                    • + + + + + Internal Temperature + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Interrupt Handlers + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Timing Functions + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Conda Environment Setup + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + OS Functions + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + I2C Scanner + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Frame Buffer + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Minicom + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + SD Card Reader + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Converting CircuitPython + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + MicroPython Remote + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Rshell + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Timers + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Memory Management + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + TinyML + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + String Formatting + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Operating System + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + Measuring Battery Voltage + + + + +
                                                    • + + + + + + + + + + +
                                                    • + + + + + File System + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + +
                                                      + + + + + Spectrum Analyzer + + + + + + + + +
                                                      + +
                                                      + +
                                                        + + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + Test Incomming + + + + + + + +
                                                        + + + + + + + +
                                                          + +
                                                        • + + + Prompt + + + +
                                                        • + +
                                                        • + + + GPT-4 Reponse + + + +
                                                        • + +
                                                        + +
                                                        + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Gain Pot + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Display Scroll + + + + +
                                                      • + + + + +
                                                      +
                                                      + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Debugging + + + + + + + + + + +
                                                    • + + + + +
                                                    +
                                                    + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + Glossary + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + References + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + Contributing + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + Contact + + + + +
                                                  • + + + + + + + + + +
                                                  • + + + + + Colophon + + + + +
                                                  • + + + +
                                                  +
                                                  +
                                                  +
                                                  +
                                                  + + + +
                                                  +
                                                  +
                                                  + + +
                                                  + + + + + + + +
                                                    + +
                                                  • + + + Prompt + + + +
                                                  • + +
                                                  • + + + GPT-4 Reponse + + + +
                                                  • + +
                                                  + +
                                                  +
                                                  +
                                                  +
                                                  + + + +
                                                  +
                                                  + + + + + + + +

                                                  Test Incoming Sound

                                                  +

                                                  Prompt

                                                  +
                                                  OK, I now have a Raspberry Pi Pico and the OLED display hooked up.  I also have a microphone hooked up to ADC0 on port GPIO26.  How can I test that the signal is coming into the ADC?  Can you write a MicroPython program that displays the audio signal on the OLED?
                                                  +
                                                  +I am using a ssd1306 and I use the following MicroPython:
                                                  +
                                                  +
                                                   1
                                                  + 2
                                                  + 3
                                                  + 4
                                                  + 5
                                                  + 6
                                                  + 7
                                                  + 8
                                                  + 9
                                                  +10
                                                  +11
                                                  +12
                                                  +13
                                                  +14
                                                  +15
                                                  +16
                                                  +17
                                                  +18
                                                  from machine import Pin
                                                  +import ssd1306
                                                  +
                                                  +WIDTH = 128
                                                  +HEIGHT = 64
                                                  +
                                                  +clock=Pin(2) #SCL
                                                  +data=Pin(3) #SDA
                                                  +RES = machine.Pin(4)
                                                  +DC = machine.Pin(5)
                                                  +CS = machine.Pin(6)
                                                  +
                                                  +spi=machine.SPI(0, sck=clock, mosi=data)
                                                  +display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                  +# clear the display
                                                  +display.fill(0)
                                                  +# draw a diagonal line
                                                  +display.line(0, 0, WIDTH, HEIGHT, 1)
                                                  +
                                                  +

                                                  GPT-4 Reponse

                                                  +

                                                  To test that the signal is coming into the ADC (Analog-to-Digital Converter) on the Raspberry Pi Pico via GPIO26, and to display the audio signal on your SSD1306 OLED, you can use the following MicroPython script. This script will read the analog values from the microphone connected to GPIO26 and plot these values in real-time on the OLED display, creating a simple waveform visualization.

                                                  +

                                                  Note: Before running this script, ensure you have properly initialized and connected your microphone to GPIO26 (ADC0), and the OLED display is correctly wired for SPI communication as per your provided initialization.

                                                  +
                                                   1
                                                  + 2
                                                  + 3
                                                  + 4
                                                  + 5
                                                  + 6
                                                  + 7
                                                  + 8
                                                  + 9
                                                  +10
                                                  +11
                                                  +12
                                                  +13
                                                  +14
                                                  +15
                                                  +16
                                                  +17
                                                  +18
                                                  +19
                                                  +20
                                                  +21
                                                  +22
                                                  +23
                                                  +24
                                                  +25
                                                  +26
                                                  +27
                                                  +28
                                                  +29
                                                  +30
                                                  +31
                                                  +32
                                                  +33
                                                  +34
                                                  +35
                                                  +36
                                                  +37
                                                  +38
                                                  +39
                                                  +40
                                                  +41
                                                  +42
                                                  +43
                                                  +44
                                                  +45
                                                  import machine
                                                  +import utime
                                                  +from machine import Pin, ADC, SPI
                                                  +import ssd1306
                                                  +
                                                  +# OLED display width and height
                                                  +WIDTH = 128
                                                  +HEIGHT = 64
                                                  +
                                                  +# SPI pins for OLED
                                                  +clock = Pin(2) # SCL
                                                  +data = Pin(3) # SDA
                                                  +RES = Pin(4)
                                                  +DC = Pin(5)
                                                  +CS = Pin(6)
                                                  +
                                                  +# Initialize SPI and OLED Display
                                                  +spi = SPI(0, sck=clock, mosi=data)
                                                  +display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                  +
                                                  +# Initialize ADC for GPIO26 (ADC0)
                                                  +adc = ADC(Pin(26))
                                                  +
                                                  +def plot_signal():
                                                  +    display.fill(0) # Clear the display
                                                  +    old_x = 0
                                                  +    old_y = HEIGHT // 2
                                                  +
                                                  +    # For simplicity, we're plotting every other pixel
                                                  +    for x in range(0, WIDTH, 2):
                                                  +        # Read from ADC (values will be from 0 to 4095)
                                                  +        val = adc.read_u16()
                                                  +        # Scale the ADC value to fit the OLED height
                                                  +        y = int((val / 65535) * HEIGHT)
                                                  +        # Invert y to plot correctly on the OLED
                                                  +        y = HEIGHT - y
                                                  +        # Draw a line from the last point to the new point
                                                  +        display.line(old_x, old_y, x, y, 1)
                                                  +        old_x, old_y = x, y
                                                  +
                                                  +    display.show() # Update the display with the new data
                                                  +
                                                  +while True:
                                                  +    plot_signal()
                                                  +    utime.sleep(0.1) # Small delay to reduce flickering
                                                  +
                                                  +

                                                  This script continuously reads the analog signal from the microphone and plots a simplified version of the waveform across the OLED display. Here's a breakdown of the plotting part:

                                                  +
                                                    +
                                                  • The screen is cleared at the beginning of each frame with display.fill(0).
                                                  • +
                                                  • We read a value from the ADC and scale it to fit the OLED's screen height.
                                                  • +
                                                  • We draw a line from the previous point to the current point to create a continuous waveform.
                                                  • +
                                                  • The display is updated with display.show() to visualize the waveform.
                                                  • +
                                                  +

                                                  This example provides a basic way to visualize audio signals. The resolution and quality of the visualization can be further enhanced or adjusted according to your requirements.

                                                  + + + + + + + + + + + + + + + +
                                                  +
                                                  + + + +
                                                  + + + +
                                                  + +
                                                  + + + +
                                                  + + + +
                                                  + + +
                                                  +
                                                  + + Previous + +
                                                  + Introduction +
                                                  +
                                                  +
                                                  + + + + +
                                                  + + Next + +
                                                  + Gain Pot +
                                                  +
                                                  +
                                                  + + +
                                                  +
                                                  + +
                                                  + + +
                                                  +
                                                  +
                                                  + + + Made with + + Material for MkDocs + + +
                                                  + +
                                                  +
                                                  +
                                                  + +
                                                  +
                                                  +
                                                  +
                                                  + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/30-spectrum-analyzer/02-gain-pot/index.html b/advanced-labs/30-spectrum-analyzer/02-gain-pot/index.html new file mode 100644 index 000000000..35acb01f5 --- /dev/null +++ b/advanced-labs/30-spectrum-analyzer/02-gain-pot/index.html @@ -0,0 +1,2122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Gain Pot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                  + + + + Skip to content + + +
                                                  +
                                                  + +
                                                  + + + + + + +
                                                  +
                                                  + + + logo + + + +
                                                  +
                                                  +
                                                  + + MicroPython for Kids + +
                                                  +
                                                  + + + Gain Pot + + +
                                                  +
                                                  +
                                                  + + + + + + + +
                                                  + +
                                                  +
                                                  + + +
                                                  + + +
                                                  + +
                                                  +
                                                  +
                                                  +
                                                  +
                                                  + Initializing search +
                                                  +
                                                    +
                                                    +
                                                    +
                                                    +
                                                    +
                                                    + + +
                                                    + +
                                                    + + +
                                                    +
                                                    + GitHub Repo +
                                                    +
                                                    +
                                                    + +
                                                    + +
                                                    + +
                                                    + + + + + + +
                                                    +
                                                    + + + +
                                                    +
                                                    +
                                                    + + + + +
                                                    + + +
                                                    + +
                                                    + + +
                                                    +
                                                    + GitHub Repo +
                                                    +
                                                    +
                                                    + +
                                                      + + + + + + + +
                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + MicroPython Home + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + +
                                                      + + + + + Advanced Labs + + + + + + + + +
                                                      + +
                                                      + +
                                                        + + + + + + + + + +
                                                      • + + + + + Internal Temperature + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Interrupt Handlers + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Timing Functions + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Conda Environment Setup + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + OS Functions + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + I2C Scanner + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Frame Buffer + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Minicom + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + SD Card Reader + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Converting CircuitPython + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + MicroPython Remote + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Rshell + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Timers + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Memory Management + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + TinyML + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + String Formatting + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Operating System + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + Measuring Battery Voltage + + + + +
                                                      • + + + + + + + + + + +
                                                      • + + + + + File System + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + +
                                                        + + + + + Spectrum Analyzer + + + + + + + + +
                                                        + +
                                                        + +
                                                          + + + + + + + + + +
                                                        • + + + + + Test Incomming + + + + +
                                                        • + + + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + Gain Pot + + + + + + + +
                                                          + + + + + + + +
                                                            + +
                                                          • + + + Prompt + + + +
                                                          • + +
                                                          • + + + ChatGPT- + + + +
                                                          • + +
                                                          + +
                                                          + +
                                                        • + + + + + + + + + + +
                                                        • + + + + + Display Scroll + + + + +
                                                        • + + + + +
                                                        +
                                                        + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Debugging + + + + + + + + + + +
                                                      • + + + + +
                                                      +
                                                      + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + Glossary + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + References + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + Contributing + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + Contact + + + + +
                                                    • + + + + + + + + + +
                                                    • + + + + + Colophon + + + + +
                                                    • + + + +
                                                    +
                                                    +
                                                    +
                                                    +
                                                    + + + +
                                                    +
                                                    +
                                                    + + +
                                                    + + + + + + + +
                                                      + +
                                                    • + + + Prompt + + + +
                                                    • + +
                                                    • + + + ChatGPT- + + + +
                                                    • + +
                                                    + +
                                                    +
                                                    +
                                                    +
                                                    + + + +
                                                    +
                                                    + + + + + + + +

                                                    Adding A Gain Potentiometer.

                                                    +

                                                    Prompt

                                                    +

                                                    The signal is very low on the display. I have added a Potentiometer on ADC1 which is on GPIO PIN 27. Can you please regenerate the entire program with sound on ADC0 and gain on ADC1. sound = ADC(Pin(26)) gain = ADC(Pin(27))

                                                    +

                                                    ChatGPT-

                                                    +

                                                    Certainly! To adjust the signal's amplitude on the display based on the gain from a potentiometer connected to ADC1 (GPIO PIN 27), you can modify the program as follows. This updated script will use the value from the potentiometer to scale the audio signal from the microphone, making the waveform larger or smaller on the OLED display according to the potentiometer's position.

                                                    +
                                                     1
                                                    + 2
                                                    + 3
                                                    + 4
                                                    + 5
                                                    + 6
                                                    + 7
                                                    + 8
                                                    + 9
                                                    +10
                                                    +11
                                                    +12
                                                    +13
                                                    +14
                                                    +15
                                                    +16
                                                    +17
                                                    +18
                                                    +19
                                                    +20
                                                    +21
                                                    +22
                                                    +23
                                                    +24
                                                    +25
                                                    +26
                                                    +27
                                                    +28
                                                    +29
                                                    +30
                                                    +31
                                                    +32
                                                    +33
                                                    +34
                                                    +35
                                                    +36
                                                    +37
                                                    +38
                                                    +39
                                                    +40
                                                    +41
                                                    +42
                                                    +43
                                                    +44
                                                    +45
                                                    +46
                                                    +47
                                                    +48
                                                    +49
                                                    +50
                                                    +51
                                                    +52
                                                    +53
                                                    import machine
                                                    +import utime
                                                    +from machine import Pin, ADC, SPI
                                                    +import ssd1306
                                                    +
                                                    +# OLED display width and height
                                                    +WIDTH = 128
                                                    +HEIGHT = 64
                                                    +
                                                    +# SPI pins for OLED
                                                    +clock = Pin(2)  # SCL
                                                    +data = Pin(3)  # SDA
                                                    +RES = Pin(4)
                                                    +DC = Pin(5)
                                                    +CS = Pin(6)
                                                    +
                                                    +# Initialize SPI and OLED Display
                                                    +spi = SPI(0, sck=clock, mosi=data)
                                                    +display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                    +
                                                    +# Initialize ADC for sound input (GPIO26) and gain control (GPIO27)
                                                    +sound = ADC(Pin(26))
                                                    +gain = ADC(Pin(27))
                                                    +
                                                    +def plot_signal_with_gain():
                                                    +    display.fill(0)  # Clear the display
                                                    +    old_x = 0
                                                    +    old_y = HEIGHT // 2
                                                    +
                                                    +    # Read gain control (potentiometer) value
                                                    +    gain_value = gain.read_u16() + 1  # Adding 1 to avoid division by zero
                                                    +
                                                    +    for x in range(0, WIDTH, 2):
                                                    +        # Read from ADC (sound input)
                                                    +        val = sound.read_u16()
                                                    +
                                                    +        # Adjust the sound value based on the gain
                                                    +        # Note: This scaling might need adjustment depending on your specific potentiometer and desired sensitivity
                                                    +        adjusted_val = min(((val * gain_value) >> 16), 65535)  # Ensure the adjusted value does not exceed ADC's max value
                                                    +
                                                    +        # Scale the adjusted value to fit the OLED height
                                                    +        y = int((adjusted_val / 65535) * HEIGHT)
                                                    +        # Invert y to plot correctly on the OLED
                                                    +        y = HEIGHT - y
                                                    +        # Draw a line from the last point to the new point
                                                    +        display.line(old_x, old_y, x, y, 1)
                                                    +        old_x, old_y = x, y
                                                    +
                                                    +    display.show()  # Update the display with the new data
                                                    +
                                                    +while True:
                                                    +    plot_signal_with_gain()
                                                    +    utime.sleep(0.1)  # Small delay to reduce flickering
                                                    +
                                                    +

                                                    In this script, the gain control (potentiometer) reading is used to adjust the amplitude of the sound signal before plotting it. The gain_value is read from ADC1 and is used to scale the audio signal from the microphone connected to ADC0. The line adjusted_val = min(((val * gain_value) >> 16), 65535) scales the microphone input based on the potentiometer's position, and the bit shift >> 16 is used to keep the value within the 16-bit range of the ADC's output.

                                                    +

                                                    This method should help make the displayed signal more responsive to the potentiometer's adjustments, allowing you to visually enhance or reduce the waveform amplitude on the OLED display.

                                                    + + + + + + + + + + + + + + + +
                                                    +
                                                    + + + +
                                                    + + + +
                                                    + +
                                                    + + + +
                                                    + + + +
                                                    + + +
                                                    +
                                                    + + Previous + +
                                                    + Test Incomming +
                                                    +
                                                    +
                                                    + + + + +
                                                    + + Next + +
                                                    + Debugging Python +
                                                    +
                                                    +
                                                    + + +
                                                    +
                                                    + +
                                                    + + +
                                                    +
                                                    +
                                                    + + + Made with + + Material for MkDocs + + +
                                                    + +
                                                    +
                                                    +
                                                    + +
                                                    +
                                                    +
                                                    +
                                                    + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/30-spectrum-analyzer/03-display-scroll/index.html b/advanced-labs/30-spectrum-analyzer/03-display-scroll/index.html new file mode 100644 index 000000000..b7fe64f42 --- /dev/null +++ b/advanced-labs/30-spectrum-analyzer/03-display-scroll/index.html @@ -0,0 +1,1383 @@ + + + + + + + + + + + + + + + + + + + + + + + Display Scroll - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                    + + + + Skip to content + + +
                                                    +
                                                    + +
                                                    + + + + + + +
                                                    +
                                                    + + + logo + + + +
                                                    +
                                                    +
                                                    + + MicroPython for Kids + +
                                                    +
                                                    + + + Display Scroll + + +
                                                    +
                                                    +
                                                    + + + + + + + +
                                                    + +
                                                    +
                                                    + + +
                                                    + + +
                                                    + +
                                                    +
                                                    +
                                                    +
                                                    +
                                                    + Initializing search +
                                                    +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + + +
                                                      + +
                                                      + + +
                                                      +
                                                      + GitHub Repo +
                                                      +
                                                      +
                                                      + +
                                                      + +
                                                      + +
                                                      + + + + + + +
                                                      +
                                                      + + + +
                                                      +
                                                      +
                                                      + + + + +
                                                      + + +
                                                      + +
                                                      + + +
                                                      +
                                                      + GitHub Repo +
                                                      +
                                                      +
                                                      + +
                                                        + + + + + + + +
                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + MicroPython Home + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + Glossary + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + References + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + Contributing + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + Contact + + + + +
                                                      • + + + + + + + + + +
                                                      • + + + + + Colophon + + + + +
                                                      • + + + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + + + +
                                                      +
                                                      +
                                                      + + +
                                                      + + + + + + + +
                                                        + +
                                                      • + + + Prompt + + + +
                                                        +
                                                          + +
                                                        • + + + ChatGPT GPT-4 Response + + + +
                                                        • + +
                                                        +
                                                        + +
                                                      • + +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      + + + +
                                                      +
                                                      + + + + + + + +

                                                      Display Scroll

                                                      +

                                                      Prompt

                                                      +
                                                      The display is a bit slow. Can you rewrite the plot\_signal\_with\_gain function so that the scroll() function is used to move the display to the left by one pixel?
                                                      +
                                                      +

                                                      ChatGPT GPT-4 Response

                                                      +

                                                      To make the display update faster and to create a scrolling effect that moves the waveform to the left by one pixel, you can modify the plot_signal_with_gain function to use the scroll() method of the SSD1306 library. This will shift the entire display content to the left by one pixel, and then you can plot the new data point at the right edge of the display. Here's how you can implement this:

                                                      +
                                                       1
                                                      + 2
                                                      + 3
                                                      + 4
                                                      + 5
                                                      + 6
                                                      + 7
                                                      + 8
                                                      + 9
                                                      +10
                                                      +11
                                                      +12
                                                      +13
                                                      +14
                                                      +15
                                                      +16
                                                      +17
                                                      +18
                                                      +19
                                                      +20
                                                      +21
                                                      +22
                                                      +23
                                                      +24
                                                      +25
                                                      +26
                                                      +27
                                                      +28
                                                      def plot_signal_with_gain():
                                                      +    # Scroll the display content to the left by one pixel
                                                      +    display.scroll(-1, 0)
                                                      +
                                                      +    # Read gain control (potentiometer) value
                                                      +    gain_value = gain.read_u16() + 1  # Adding 1 to avoid division by zero
                                                      +
                                                      +    # Read from ADC (sound input)
                                                      +    val = sound.read_u16()
                                                      +
                                                      +    # Adjust the sound value based on the gain
                                                      +    adjusted_val = min(((val * gain_value) >> 16), 65535)  # Ensure the adjusted value does not exceed ADC's max value
                                                      +
                                                      +    # Scale the adjusted value to fit the OLED height
                                                      +    y = int((adjusted_val / 65535) * HEIGHT)
                                                      +    # Invert y to plot correctly on the OLED
                                                      +    y = HEIGHT - y
                                                      +
                                                      +    # Since we've scrolled, we only need to update the last column (x = WIDTH - 1)
                                                      +    # Clear the last column first (optional, depending on the desired visual effect)
                                                      +    for clear_y in range(HEIGHT):
                                                      +        display.pixel(WIDTH - 1, clear_y, 0)
                                                      +
                                                      +    # Draw the new data point at the right edge of the display
                                                      +    display.pixel(WIDTH - 1, y, 1)
                                                      +
                                                      +    # Update the display with the new data
                                                      +    display.show()
                                                      +
                                                      +

                                                      In this updated function, the display is scrolled left by one pixel at the beginning of each update cycle using display.scroll(-1, 0). This creates room to draw the new data point at the far right edge (WIDTH - 1) of the display. The loop that clears the last column before drawing the new point is optional and can be adjusted or removed depending on the visual effect you're aiming for.

                                                      +

                                                      Remember, while scroll() improves the visual fluidity by creating a continuous scrolling effect, the update rate can still be limited by the display's physical refresh rate and the speed at which your MicroPython script can run. Experiment with the utime.sleep(0.1) delay at the end of the main loop to find a balance between smoothness and speed that works for your specific application.

                                                      + + + + + + + + + + + + + + + +
                                                      +
                                                      + + + +
                                                      + + + +
                                                      + +
                                                      + + + +
                                                      +
                                                      +
                                                      + + + Made with + + Material for MkDocs + + +
                                                      + +
                                                      +
                                                      +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/30-spectrum-analyzer/index.html b/advanced-labs/30-spectrum-analyzer/index.html new file mode 100644 index 000000000..b659f6569 --- /dev/null +++ b/advanced-labs/30-spectrum-analyzer/index.html @@ -0,0 +1,2069 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                      + + + + Skip to content + + +
                                                      +
                                                      + +
                                                      + + + + + + +
                                                      +
                                                      + + + logo + + + +
                                                      +
                                                      +
                                                      + + MicroPython for Kids + +
                                                      +
                                                      + + + Introduction + + +
                                                      +
                                                      +
                                                      + + + + + + + +
                                                      + +
                                                      +
                                                      + + +
                                                      + + +
                                                      + +
                                                      +
                                                      +
                                                      +
                                                      +
                                                      + Initializing search +
                                                      +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        + + +
                                                        + +
                                                        + + +
                                                        +
                                                        + GitHub Repo +
                                                        +
                                                        +
                                                        + +
                                                        + +
                                                        + +
                                                        + + + + + + +
                                                        +
                                                        + + + +
                                                        +
                                                        +
                                                        + + + + +
                                                        + + +
                                                        + +
                                                        + + +
                                                        +
                                                        + GitHub Repo +
                                                        +
                                                        +
                                                        + +
                                                          + + + + + + + +
                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + MicroPython Home + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + +
                                                          + + + + + Advanced Labs + + + + + + + + +
                                                          + +
                                                          + +
                                                            + + + + + + + + + +
                                                          • + + + + + Internal Temperature + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Interrupt Handlers + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Timing Functions + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Conda Environment Setup + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + OS Functions + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + I2C Scanner + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Frame Buffer + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Minicom + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + SD Card Reader + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Converting CircuitPython + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + MicroPython Remote + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Rshell + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Timers + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Memory Management + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + TinyML + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + String Formatting + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Operating System + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + Measuring Battery Voltage + + + + +
                                                          • + + + + + + + + + + +
                                                          • + + + + + File System + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + +
                                                            + + + + + Spectrum Analyzer + + + + + + + + +
                                                            + +
                                                            + +
                                                              + + + + + + + + + +
                                                            • + + + + + Test Incomming + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Gain Pot + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Display Scroll + + + + +
                                                            • + + + + +
                                                            +
                                                            + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Debugging + + + + + + + + + + +
                                                          • + + + + +
                                                          +
                                                          + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + Glossary + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + References + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + Contributing + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + Contact + + + + +
                                                        • + + + + + + + + + +
                                                        • + + + + + Colophon + + + + +
                                                        • + + + +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        + + + +
                                                        +
                                                        +
                                                        + + +
                                                        + + + + + + + +
                                                          + +
                                                        • + + + ChatGPT Prompt + + + +
                                                        • + +
                                                        • + + + ChatGPT GPT-4 Response + + + +
                                                          +
                                                            + +
                                                          • + + + Step 1: Gather the Components + + + +
                                                          • + +
                                                          • + + + Step 2: Set Up the Raspberry Pi Pico + + + +
                                                          • + +
                                                          • + + + Step 3: Connect the Hardware + + + +
                                                          • + +
                                                          • + + + Step 4: Write the Software + + + +
                                                          • + +
                                                          • + + + Step 5: Testing and Troubleshooting + + + +
                                                          • + +
                                                          • + + + Step 6: Refinement and Expansion + + + +
                                                          • + +
                                                          • + + + Resources + + + +
                                                          • + +
                                                          +
                                                          + +
                                                        • + +
                                                        + +
                                                        +
                                                        +
                                                        +
                                                        + + + +
                                                        +
                                                        + + + + + + + +

                                                        Spectrum Analyzer

                                                        +

                                                        ChatGPT Prompt

                                                        +
                                                        I would like to create an audio spectrum analyzer using a Raspberry Pi Pico and a 128x64 OLED display using MicroPython. How would you suggest I go about this project. Break it down step-by-step.
                                                        +
                                                        +

                                                        ChatGPT GPT-4 Response

                                                        +

                                                        Creating an audio spectrum analyzer with a Raspberry Pi Pico and a 128x64 OLED display using MicroPython is a fascinating project that combines hardware interfacing with digital signal processing. Below is a step-by-step guide to help you get started on this project.

                                                        +

                                                        Step 1: Gather the Components

                                                        +
                                                          +
                                                        1. Raspberry Pi Pico: A microcontroller board based on the RP2040 microcontroller chip.
                                                        2. +
                                                        3. 128x64 OLED Display: This will be used for visualizing the audio spectrum. Ensure it's compatible with the Pi Pico, ideally one that communicates over I2C or SPI.
                                                        4. +
                                                        5. Electret Microphone Amplifier: This captures the audio signals. A module like the MAX4466 or a similar one would be suitable.
                                                        6. +
                                                        7. Jump Wires: For connecting the components.
                                                        8. +
                                                        9. Breadboard: Useful for prototyping without soldering.
                                                        10. +
                                                        11. USB Cable: For programming the Raspberry Pi Pico.
                                                        12. +
                                                        +

                                                        Step 2: Set Up the Raspberry Pi Pico

                                                        +
                                                          +
                                                        1. Install MicroPython: Download and flash MicroPython onto the Raspberry Pi Pico. The Raspberry Pi Pico documentation provides clear instructions for this process.
                                                        2. +
                                                        3. Prepare Your Development Environment: Install any necessary drivers and a code editor that supports MicroPython, such as Thonny or Visual Studio Code with the appropriate extensions.
                                                        4. +
                                                        +

                                                        Step 3: Connect the Hardware

                                                        +
                                                          +
                                                        1. Microphone to Pi Pico: Connect the output of the electret microphone amplifier to one of the analog input pins of the Pi Pico. Also, connect the ground and Vcc pins accordingly.
                                                        2. +
                                                        3. OLED Display to Pi Pico: Connect the OLED display to the Pi Pico using I2C or SPI, depending on your display module. For I2C, you'll need to connect SDA, SCL, Vcc, and GND. For SPI, the connections will include SCK, MOSI, RES, DC, CS, Vcc, and GND.
                                                        4. +
                                                        +

                                                        Step 4: Write the Software

                                                        +
                                                          +
                                                        1. Initialize the OLED Display: Write or adapt a MicroPython script to initialize the OLED display using the appropriate library. There are libraries available for both I2C and SPI OLED displays in MicroPython.
                                                        2. +
                                                        3. Capture Audio Data: Write a script to capture audio data from the microphone using the ADC (Analog to Digital Converter) of the Pi Pico. The data capture should be done in real-time, and you may need to experiment with sampling rates.
                                                        4. +
                                                        5. Process Audio Data: Implement a Fast Fourier Transform (FFT) algorithm to convert the time-domain audio signals into the frequency domain. This step is crucial for creating the spectrum analysis.
                                                        6. +
                                                        7. Visualize the Spectrum: Map the frequency domain data to the OLED display. You will likely need to scale the data to fit nicely on the 128x64 display, representing different frequencies and their intensities.
                                                        8. +
                                                        +

                                                        Step 5: Testing and Troubleshooting

                                                        +
                                                          +
                                                        1. Run Your Script: Test the entire system by running your script. You may need to adjust the audio capture settings or the way the data is visualized on the OLED display.
                                                        2. +
                                                        3. Troubleshoot: If you encounter issues, use serial print statements to debug and understand where things might be going wrong.
                                                        4. +
                                                        +

                                                        Step 6: Refinement and Expansion

                                                        +
                                                          +
                                                        1. Refine the Display: You can refine how the audio spectrum is displayed, perhaps by adjusting the resolution, colors (if your OLED supports it), or adding additional visual elements like peak hold.
                                                        2. +
                                                        3. Experiment with Features: Consider adding features such as different modes for the spectrum analyzer, audio input from different sources, or even a GUI for interacting with the device.
                                                        4. +
                                                        +

                                                        Resources

                                                        +
                                                          +
                                                        • MicroPython Documentation: Essential for understanding how to program the Raspberry Pi Pico.
                                                        • +
                                                        • FFT Libraries: Look for MicroPython libraries or examples of FFT implementations suitable for the Raspberry Pi Pico.
                                                        • +
                                                        • OLED Libraries: Find libraries specific to your OLED display model for easier programming.
                                                        • +
                                                        +

                                                        This project involves a mix of hardware setup, digital signal processing, and real-time data visualization. Take it step by step, and don't hesitate to seek out community forums and resources if you encounter challenges.

                                                        + + + + + + + + + + + + + + + +
                                                        +
                                                        + + + +
                                                        + + + +
                                                        + +
                                                        + + + +
                                                        + + + +
                                                        + + +
                                                        +
                                                        + + Previous + +
                                                        + File System +
                                                        +
                                                        +
                                                        + + + + +
                                                        + + Next + +
                                                        + Test Incomming +
                                                        +
                                                        +
                                                        + + +
                                                        +
                                                        + +
                                                        + + +
                                                        +
                                                        +
                                                        + + + Made with + + Material for MkDocs + + +
                                                        + +
                                                        +
                                                        +
                                                        + +
                                                        +
                                                        +
                                                        +
                                                        + + + + + + + + + + \ No newline at end of file diff --git a/advanced-labs/index.html b/advanced-labs/index.html new file mode 100644 index 000000000..e2125cfcc --- /dev/null +++ b/advanced-labs/index.html @@ -0,0 +1,1879 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                        + + + + Skip to content + + +
                                                        +
                                                        + +
                                                        + + + + + + +
                                                        +
                                                        + + + logo + + + +
                                                        +
                                                        +
                                                        + + MicroPython for Kids + +
                                                        +
                                                        + + + Introduction + + +
                                                        +
                                                        +
                                                        + + + + + + + +
                                                        + +
                                                        +
                                                        + + +
                                                        + + +
                                                        + +
                                                        +
                                                        +
                                                        +
                                                        +
                                                        + Initializing search +
                                                        +
                                                          +
                                                          +
                                                          +
                                                          +
                                                          +
                                                          + + +
                                                          + +
                                                          + + +
                                                          +
                                                          + GitHub Repo +
                                                          +
                                                          +
                                                          + +
                                                          + +
                                                          + +
                                                          + + + + + + +
                                                          +
                                                          + + + +
                                                          +
                                                          +
                                                          + + + + +
                                                          + + +
                                                          + +
                                                          + + +
                                                          +
                                                          + GitHub Repo +
                                                          +
                                                          +
                                                          + +
                                                            + + + + + + + +
                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + MicroPython Home + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + +
                                                            + + + + + Advanced Labs + + + + + + + + +
                                                            + +
                                                            + +
                                                              + + + + + + + + + +
                                                            • + + + + + Internal Temperature + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Interrupt Handlers + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Timing Functions + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Conda Environment Setup + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + OS Functions + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + I2C Scanner + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Frame Buffer + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Minicom + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + SD Card Reader + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Converting CircuitPython + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + MicroPython Remote + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Rshell + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Timers + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Memory Management + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + TinyML + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + String Formatting + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Operating System + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + Measuring Battery Voltage + + + + +
                                                            • + + + + + + + + + + +
                                                            • + + + + + File System + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Debugging + + + + + + + + + + +
                                                            • + + + + +
                                                            +
                                                            + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + Glossary + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + References + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + Contributing + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + Contact + + + + +
                                                          • + + + + + + + + + +
                                                          • + + + + + Colophon + + + + +
                                                          • + + + +
                                                          +
                                                          +
                                                          +
                                                          +
                                                          + + + +
                                                          +
                                                          +
                                                          + + +
                                                          + + + + + + + +
                                                            + +
                                                          • + + + References + + + +
                                                          • + +
                                                          + +
                                                          +
                                                          +
                                                          +
                                                          + + + +
                                                          +
                                                          + + + + + + + +

                                                          Advanced Labs

                                                          +

                                                          This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects.

                                                          +

                                                          Topics include:

                                                          +
                                                            +
                                                          1. Writing Interrupt Handlers
                                                          2. +
                                                          3. Monitoring the internal temperature of your RP2040 CPU
                                                          4. +
                                                          5. Timing the speed of functions for performance optimization
                                                          6. +
                                                          7. Setting up a Conda virtual Python development environment
                                                          8. +
                                                          9. Using operating system functions such as listing files on the file system
                                                          10. +
                                                          11. Scanning for I2C devices
                                                          12. +
                                                          13. Using a framebuffer
                                                          14. +
                                                          15. Using the minicom tool to move files to and from you PC from your microcontroller
                                                          16. +
                                                          17. Reading files from a SD card
                                                          18. +
                                                          19. Converting CircuitPython code and drivers to MicroPython
                                                          20. +
                                                          +

                                                          References

                                                          +

                                                          Wokwi ESP32 Simulator for the Raspberry Pi Pico

                                                          + + + + + + + + + + + + + + + +
                                                          +
                                                          + + + +
                                                          + + + +
                                                          + +
                                                          + + + +
                                                          + + + +
                                                          + + +
                                                          +
                                                          + + Previous + +
                                                          + FAQs +
                                                          +
                                                          +
                                                          + + + + +
                                                          + + Next + +
                                                          + Internal Temperature +
                                                          +
                                                          +
                                                          + + +
                                                          +
                                                          + +
                                                          + + +
                                                          +
                                                          +
                                                          + + + Made with + + Material for MkDocs + + +
                                                          + +
                                                          +
                                                          +
                                                          + +
                                                          +
                                                          +
                                                          +
                                                          + + + + + + + + + + \ No newline at end of file diff --git a/assets/images/favicon.png b/assets/images/favicon.png new file mode 100644 index 000000000..1cf13b9f9 Binary files /dev/null and b/assets/images/favicon.png differ diff --git a/assets/javascripts/bundle.83f73b43.min.js b/assets/javascripts/bundle.83f73b43.min.js new file mode 100644 index 000000000..43d8b70f6 --- /dev/null +++ b/assets/javascripts/bundle.83f73b43.min.js @@ -0,0 +1,16 @@ +"use strict";(()=>{var Wi=Object.create;var gr=Object.defineProperty;var Di=Object.getOwnPropertyDescriptor;var Vi=Object.getOwnPropertyNames,Vt=Object.getOwnPropertySymbols,Ni=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty,ao=Object.prototype.propertyIsEnumerable;var io=(e,t,r)=>t in e?gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$=(e,t)=>{for(var r in t||(t={}))yr.call(t,r)&&io(e,r,t[r]);if(Vt)for(var r of Vt(t))ao.call(t,r)&&io(e,r,t[r]);return e};var so=(e,t)=>{var r={};for(var o in e)yr.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&Vt)for(var o of Vt(e))t.indexOf(o)<0&&ao.call(e,o)&&(r[o]=e[o]);return r};var xr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var zi=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Vi(t))!yr.call(e,n)&&n!==r&&gr(e,n,{get:()=>t[n],enumerable:!(o=Di(t,n))||o.enumerable});return e};var Mt=(e,t,r)=>(r=e!=null?Wi(Ni(e)):{},zi(t||!e||!e.__esModule?gr(r,"default",{value:e,enumerable:!0}):r,e));var co=(e,t,r)=>new Promise((o,n)=>{var i=p=>{try{s(r.next(p))}catch(c){n(c)}},a=p=>{try{s(r.throw(p))}catch(c){n(c)}},s=p=>p.done?o(p.value):Promise.resolve(p.value).then(i,a);s((r=r.apply(e,t)).next())});var lo=xr((Er,po)=>{(function(e,t){typeof Er=="object"&&typeof po!="undefined"?t():typeof define=="function"&&define.amd?define(t):t()})(Er,function(){"use strict";function e(r){var o=!0,n=!1,i=null,a={text:!0,search:!0,url:!0,tel:!0,email:!0,password:!0,number:!0,date:!0,month:!0,week:!0,time:!0,datetime:!0,"datetime-local":!0};function s(k){return!!(k&&k!==document&&k.nodeName!=="HTML"&&k.nodeName!=="BODY"&&"classList"in k&&"contains"in k.classList)}function p(k){var ft=k.type,qe=k.tagName;return!!(qe==="INPUT"&&a[ft]&&!k.readOnly||qe==="TEXTAREA"&&!k.readOnly||k.isContentEditable)}function c(k){k.classList.contains("focus-visible")||(k.classList.add("focus-visible"),k.setAttribute("data-focus-visible-added",""))}function l(k){k.hasAttribute("data-focus-visible-added")&&(k.classList.remove("focus-visible"),k.removeAttribute("data-focus-visible-added"))}function f(k){k.metaKey||k.altKey||k.ctrlKey||(s(r.activeElement)&&c(r.activeElement),o=!0)}function u(k){o=!1}function d(k){s(k.target)&&(o||p(k.target))&&c(k.target)}function y(k){s(k.target)&&(k.target.classList.contains("focus-visible")||k.target.hasAttribute("data-focus-visible-added"))&&(n=!0,window.clearTimeout(i),i=window.setTimeout(function(){n=!1},100),l(k.target))}function L(k){document.visibilityState==="hidden"&&(n&&(o=!0),X())}function X(){document.addEventListener("mousemove",J),document.addEventListener("mousedown",J),document.addEventListener("mouseup",J),document.addEventListener("pointermove",J),document.addEventListener("pointerdown",J),document.addEventListener("pointerup",J),document.addEventListener("touchmove",J),document.addEventListener("touchstart",J),document.addEventListener("touchend",J)}function te(){document.removeEventListener("mousemove",J),document.removeEventListener("mousedown",J),document.removeEventListener("mouseup",J),document.removeEventListener("pointermove",J),document.removeEventListener("pointerdown",J),document.removeEventListener("pointerup",J),document.removeEventListener("touchmove",J),document.removeEventListener("touchstart",J),document.removeEventListener("touchend",J)}function J(k){k.target.nodeName&&k.target.nodeName.toLowerCase()==="html"||(o=!1,te())}document.addEventListener("keydown",f,!0),document.addEventListener("mousedown",u,!0),document.addEventListener("pointerdown",u,!0),document.addEventListener("touchstart",u,!0),document.addEventListener("visibilitychange",L,!0),X(),r.addEventListener("focus",d,!0),r.addEventListener("blur",y,!0),r.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&r.host?r.host.setAttribute("data-js-focus-visible",""):r.nodeType===Node.DOCUMENT_NODE&&(document.documentElement.classList.add("js-focus-visible"),document.documentElement.setAttribute("data-js-focus-visible",""))}if(typeof window!="undefined"&&typeof document!="undefined"){window.applyFocusVisiblePolyfill=e;var t;try{t=new CustomEvent("focus-visible-polyfill-ready")}catch(r){t=document.createEvent("CustomEvent"),t.initCustomEvent("focus-visible-polyfill-ready",!1,!1,{})}window.dispatchEvent(t)}typeof document!="undefined"&&e(document)})});var qr=xr((hy,On)=>{"use strict";/*! + * escape-html + * Copyright(c) 2012-2013 TJ Holowaychuk + * Copyright(c) 2015 Andreas Lubbe + * Copyright(c) 2015 Tiancheng "Timothy" Gu + * MIT Licensed + */var $a=/["'&<>]/;On.exports=Pa;function Pa(e){var t=""+e,r=$a.exec(t);if(!r)return t;var o,n="",i=0,a=0;for(i=r.index;i{/*! + * clipboard.js v2.0.11 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */(function(t,r){typeof It=="object"&&typeof Yr=="object"?Yr.exports=r():typeof define=="function"&&define.amd?define([],r):typeof It=="object"?It.ClipboardJS=r():t.ClipboardJS=r()})(It,function(){return function(){var e={686:function(o,n,i){"use strict";i.d(n,{default:function(){return Ui}});var a=i(279),s=i.n(a),p=i(370),c=i.n(p),l=i(817),f=i.n(l);function u(V){try{return document.execCommand(V)}catch(A){return!1}}var d=function(A){var M=f()(A);return u("cut"),M},y=d;function L(V){var A=document.documentElement.getAttribute("dir")==="rtl",M=document.createElement("textarea");M.style.fontSize="12pt",M.style.border="0",M.style.padding="0",M.style.margin="0",M.style.position="absolute",M.style[A?"right":"left"]="-9999px";var F=window.pageYOffset||document.documentElement.scrollTop;return M.style.top="".concat(F,"px"),M.setAttribute("readonly",""),M.value=V,M}var X=function(A,M){var F=L(A);M.container.appendChild(F);var D=f()(F);return u("copy"),F.remove(),D},te=function(A){var M=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},F="";return typeof A=="string"?F=X(A,M):A instanceof HTMLInputElement&&!["text","search","url","tel","password"].includes(A==null?void 0:A.type)?F=X(A.value,M):(F=f()(A),u("copy")),F},J=te;function k(V){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?k=function(M){return typeof M}:k=function(M){return M&&typeof Symbol=="function"&&M.constructor===Symbol&&M!==Symbol.prototype?"symbol":typeof M},k(V)}var ft=function(){var A=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},M=A.action,F=M===void 0?"copy":M,D=A.container,Y=A.target,$e=A.text;if(F!=="copy"&&F!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(Y!==void 0)if(Y&&k(Y)==="object"&&Y.nodeType===1){if(F==="copy"&&Y.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(F==="cut"&&(Y.hasAttribute("readonly")||Y.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if($e)return J($e,{container:D});if(Y)return F==="cut"?y(Y):J(Y,{container:D})},qe=ft;function Fe(V){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Fe=function(M){return typeof M}:Fe=function(M){return M&&typeof Symbol=="function"&&M.constructor===Symbol&&M!==Symbol.prototype?"symbol":typeof M},Fe(V)}function ki(V,A){if(!(V instanceof A))throw new TypeError("Cannot call a class as a function")}function no(V,A){for(var M=0;M0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof D.action=="function"?D.action:this.defaultAction,this.target=typeof D.target=="function"?D.target:this.defaultTarget,this.text=typeof D.text=="function"?D.text:this.defaultText,this.container=Fe(D.container)==="object"?D.container:document.body}},{key:"listenClick",value:function(D){var Y=this;this.listener=c()(D,"click",function($e){return Y.onClick($e)})}},{key:"onClick",value:function(D){var Y=D.delegateTarget||D.currentTarget,$e=this.action(Y)||"copy",Dt=qe({action:$e,container:this.container,target:this.target(Y),text:this.text(Y)});this.emit(Dt?"success":"error",{action:$e,text:Dt,trigger:Y,clearSelection:function(){Y&&Y.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(D){return vr("action",D)}},{key:"defaultTarget",value:function(D){var Y=vr("target",D);if(Y)return document.querySelector(Y)}},{key:"defaultText",value:function(D){return vr("text",D)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(D){var Y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return J(D,Y)}},{key:"cut",value:function(D){return y(D)}},{key:"isSupported",value:function(){var D=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],Y=typeof D=="string"?[D]:D,$e=!!document.queryCommandSupported;return Y.forEach(function(Dt){$e=$e&&!!document.queryCommandSupported(Dt)}),$e}}]),M}(s()),Ui=Fi},828:function(o){var n=9;if(typeof Element!="undefined"&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}function a(s,p){for(;s&&s.nodeType!==n;){if(typeof s.matches=="function"&&s.matches(p))return s;s=s.parentNode}}o.exports=a},438:function(o,n,i){var a=i(828);function s(l,f,u,d,y){var L=c.apply(this,arguments);return l.addEventListener(u,L,y),{destroy:function(){l.removeEventListener(u,L,y)}}}function p(l,f,u,d,y){return typeof l.addEventListener=="function"?s.apply(null,arguments):typeof u=="function"?s.bind(null,document).apply(null,arguments):(typeof l=="string"&&(l=document.querySelectorAll(l)),Array.prototype.map.call(l,function(L){return s(L,f,u,d,y)}))}function c(l,f,u,d){return function(y){y.delegateTarget=a(y.target,f),y.delegateTarget&&d.call(l,y)}}o.exports=p},879:function(o,n){n.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},n.nodeList=function(i){var a=Object.prototype.toString.call(i);return i!==void 0&&(a==="[object NodeList]"||a==="[object HTMLCollection]")&&"length"in i&&(i.length===0||n.node(i[0]))},n.string=function(i){return typeof i=="string"||i instanceof String},n.fn=function(i){var a=Object.prototype.toString.call(i);return a==="[object Function]"}},370:function(o,n,i){var a=i(879),s=i(438);function p(u,d,y){if(!u&&!d&&!y)throw new Error("Missing required arguments");if(!a.string(d))throw new TypeError("Second argument must be a String");if(!a.fn(y))throw new TypeError("Third argument must be a Function");if(a.node(u))return c(u,d,y);if(a.nodeList(u))return l(u,d,y);if(a.string(u))return f(u,d,y);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function c(u,d,y){return u.addEventListener(d,y),{destroy:function(){u.removeEventListener(d,y)}}}function l(u,d,y){return Array.prototype.forEach.call(u,function(L){L.addEventListener(d,y)}),{destroy:function(){Array.prototype.forEach.call(u,function(L){L.removeEventListener(d,y)})}}}function f(u,d,y){return s(document.body,u,d,y)}o.exports=p},817:function(o){function n(i){var a;if(i.nodeName==="SELECT")i.focus(),a=i.value;else if(i.nodeName==="INPUT"||i.nodeName==="TEXTAREA"){var s=i.hasAttribute("readonly");s||i.setAttribute("readonly",""),i.select(),i.setSelectionRange(0,i.value.length),s||i.removeAttribute("readonly"),a=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var p=window.getSelection(),c=document.createRange();c.selectNodeContents(i),p.removeAllRanges(),p.addRange(c),a=p.toString()}return a}o.exports=n},279:function(o){function n(){}n.prototype={on:function(i,a,s){var p=this.e||(this.e={});return(p[i]||(p[i]=[])).push({fn:a,ctx:s}),this},once:function(i,a,s){var p=this;function c(){p.off(i,c),a.apply(s,arguments)}return c._=a,this.on(i,c,s)},emit:function(i){var a=[].slice.call(arguments,1),s=((this.e||(this.e={}))[i]||[]).slice(),p=0,c=s.length;for(p;p0&&i[i.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function N(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var o=r.call(e),n,i=[],a;try{for(;(t===void 0||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(s){a={error:s}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(a)throw a.error}}return i}function q(e,t,r){if(r||arguments.length===2)for(var o=0,n=t.length,i;o1||p(d,L)})},y&&(n[d]=y(n[d])))}function p(d,y){try{c(o[d](y))}catch(L){u(i[0][3],L)}}function c(d){d.value instanceof nt?Promise.resolve(d.value.v).then(l,f):u(i[0][2],d)}function l(d){p("next",d)}function f(d){p("throw",d)}function u(d,y){d(y),i.shift(),i.length&&p(i[0][0],i[0][1])}}function uo(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof he=="function"?he(e):e[Symbol.iterator](),r={},o("next"),o("throw"),o("return"),r[Symbol.asyncIterator]=function(){return this},r);function o(i){r[i]=e[i]&&function(a){return new Promise(function(s,p){a=e[i](a),n(s,p,a.done,a.value)})}}function n(i,a,s,p){Promise.resolve(p).then(function(c){i({value:c,done:s})},a)}}function H(e){return typeof e=="function"}function ut(e){var t=function(o){Error.call(o),o.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var zt=ut(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: +`+r.map(function(o,n){return n+1+") "+o.toString()}).join(` + `):"",this.name="UnsubscriptionError",this.errors=r}});function Qe(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Ue=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,o,n,i;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var s=he(a),p=s.next();!p.done;p=s.next()){var c=p.value;c.remove(this)}}catch(L){t={error:L}}finally{try{p&&!p.done&&(r=s.return)&&r.call(s)}finally{if(t)throw t.error}}else a.remove(this);var l=this.initialTeardown;if(H(l))try{l()}catch(L){i=L instanceof zt?L.errors:[L]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var u=he(f),d=u.next();!d.done;d=u.next()){var y=d.value;try{ho(y)}catch(L){i=i!=null?i:[],L instanceof zt?i=q(q([],N(i)),N(L.errors)):i.push(L)}}}catch(L){o={error:L}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(o)throw o.error}}}if(i)throw new zt(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ho(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&Qe(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&Qe(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();var Tr=Ue.EMPTY;function qt(e){return e instanceof Ue||e&&"closed"in e&&H(e.remove)&&H(e.add)&&H(e.unsubscribe)}function ho(e){H(e)?e():e.unsubscribe()}var Pe={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var dt={setTimeout:function(e,t){for(var r=[],o=2;o0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var o=this,n=this,i=n.hasError,a=n.isStopped,s=n.observers;return i||a?Tr:(this.currentObservers=null,s.push(r),new Ue(function(){o.currentObservers=null,Qe(s,r)}))},t.prototype._checkFinalizedStatuses=function(r){var o=this,n=o.hasError,i=o.thrownError,a=o.isStopped;n?r.error(i):a&&r.complete()},t.prototype.asObservable=function(){var r=new j;return r.source=this,r},t.create=function(r,o){return new To(r,o)},t}(j);var To=function(e){oe(t,e);function t(r,o){var n=e.call(this)||this;return n.destination=r,n.source=o,n}return t.prototype.next=function(r){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,r)},t.prototype.error=function(r){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,r)},t.prototype.complete=function(){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||o===void 0||o.call(r)},t.prototype._subscribe=function(r){var o,n;return(n=(o=this.source)===null||o===void 0?void 0:o.subscribe(r))!==null&&n!==void 0?n:Tr},t}(g);var _r=function(e){oe(t,e);function t(r){var o=e.call(this)||this;return o._value=r,o}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(r){var o=e.prototype._subscribe.call(this,r);return!o.closed&&r.next(this._value),o},t.prototype.getValue=function(){var r=this,o=r.hasError,n=r.thrownError,i=r._value;if(o)throw n;return this._throwIfClosed(),i},t.prototype.next=function(r){e.prototype.next.call(this,this._value=r)},t}(g);var At={now:function(){return(At.delegate||Date).now()},delegate:void 0};var Ct=function(e){oe(t,e);function t(r,o,n){r===void 0&&(r=1/0),o===void 0&&(o=1/0),n===void 0&&(n=At);var i=e.call(this)||this;return i._bufferSize=r,i._windowTime=o,i._timestampProvider=n,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=o===1/0,i._bufferSize=Math.max(1,r),i._windowTime=Math.max(1,o),i}return t.prototype.next=function(r){var o=this,n=o.isStopped,i=o._buffer,a=o._infiniteTimeWindow,s=o._timestampProvider,p=o._windowTime;n||(i.push(r),!a&&i.push(s.now()+p)),this._trimBuffer(),e.prototype.next.call(this,r)},t.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var o=this._innerSubscribe(r),n=this,i=n._infiniteTimeWindow,a=n._buffer,s=a.slice(),p=0;p0?e.prototype.schedule.call(this,r,o):(this.delay=o,this.state=r,this.scheduler.flush(this),this)},t.prototype.execute=function(r,o){return o>0||this.closed?e.prototype.execute.call(this,r,o):this._execute(r,o)},t.prototype.requestAsyncId=function(r,o,n){return n===void 0&&(n=0),n!=null&&n>0||n==null&&this.delay>0?e.prototype.requestAsyncId.call(this,r,o,n):(r.flush(this),0)},t}(gt);var Lo=function(e){oe(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t}(yt);var kr=new Lo(Oo);var Mo=function(e){oe(t,e);function t(r,o){var n=e.call(this,r,o)||this;return n.scheduler=r,n.work=o,n}return t.prototype.requestAsyncId=function(r,o,n){return n===void 0&&(n=0),n!==null&&n>0?e.prototype.requestAsyncId.call(this,r,o,n):(r.actions.push(this),r._scheduled||(r._scheduled=vt.requestAnimationFrame(function(){return r.flush(void 0)})))},t.prototype.recycleAsyncId=function(r,o,n){var i;if(n===void 0&&(n=0),n!=null?n>0:this.delay>0)return e.prototype.recycleAsyncId.call(this,r,o,n);var a=r.actions;o!=null&&((i=a[a.length-1])===null||i===void 0?void 0:i.id)!==o&&(vt.cancelAnimationFrame(o),r._scheduled=void 0)},t}(gt);var _o=function(e){oe(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.flush=function(r){this._active=!0;var o=this._scheduled;this._scheduled=void 0;var n=this.actions,i;r=r||n.shift();do if(i=r.execute(r.state,r.delay))break;while((r=n[0])&&r.id===o&&n.shift());if(this._active=!1,i){for(;(r=n[0])&&r.id===o&&n.shift();)r.unsubscribe();throw i}},t}(yt);var me=new _o(Mo);var S=new j(function(e){return e.complete()});function Yt(e){return e&&H(e.schedule)}function Hr(e){return e[e.length-1]}function Xe(e){return H(Hr(e))?e.pop():void 0}function ke(e){return Yt(Hr(e))?e.pop():void 0}function Bt(e,t){return typeof Hr(e)=="number"?e.pop():t}var xt=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function Gt(e){return H(e==null?void 0:e.then)}function Jt(e){return H(e[bt])}function Xt(e){return Symbol.asyncIterator&&H(e==null?void 0:e[Symbol.asyncIterator])}function Zt(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Zi(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var er=Zi();function tr(e){return H(e==null?void 0:e[er])}function rr(e){return fo(this,arguments,function(){var r,o,n,i;return Nt(this,function(a){switch(a.label){case 0:r=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,nt(r.read())];case 3:return o=a.sent(),n=o.value,i=o.done,i?[4,nt(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,nt(n)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function or(e){return H(e==null?void 0:e.getReader)}function U(e){if(e instanceof j)return e;if(e!=null){if(Jt(e))return ea(e);if(xt(e))return ta(e);if(Gt(e))return ra(e);if(Xt(e))return Ao(e);if(tr(e))return oa(e);if(or(e))return na(e)}throw Zt(e)}function ea(e){return new j(function(t){var r=e[bt]();if(H(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function ta(e){return new j(function(t){for(var r=0;r=2;return function(o){return o.pipe(e?b(function(n,i){return e(n,i,o)}):le,Te(1),r?De(t):Qo(function(){return new ir}))}}function jr(e){return e<=0?function(){return S}:E(function(t,r){var o=[];t.subscribe(T(r,function(n){o.push(n),e=2,!0))}function pe(e){e===void 0&&(e={});var t=e.connector,r=t===void 0?function(){return new g}:t,o=e.resetOnError,n=o===void 0?!0:o,i=e.resetOnComplete,a=i===void 0?!0:i,s=e.resetOnRefCountZero,p=s===void 0?!0:s;return function(c){var l,f,u,d=0,y=!1,L=!1,X=function(){f==null||f.unsubscribe(),f=void 0},te=function(){X(),l=u=void 0,y=L=!1},J=function(){var k=l;te(),k==null||k.unsubscribe()};return E(function(k,ft){d++,!L&&!y&&X();var qe=u=u!=null?u:r();ft.add(function(){d--,d===0&&!L&&!y&&(f=Ur(J,p))}),qe.subscribe(ft),!l&&d>0&&(l=new at({next:function(Fe){return qe.next(Fe)},error:function(Fe){L=!0,X(),f=Ur(te,n,Fe),qe.error(Fe)},complete:function(){y=!0,X(),f=Ur(te,a),qe.complete()}}),U(k).subscribe(l))})(c)}}function Ur(e,t){for(var r=[],o=2;oe.next(document)),e}function P(e,t=document){return Array.from(t.querySelectorAll(e))}function R(e,t=document){let r=fe(e,t);if(typeof r=="undefined")throw new ReferenceError(`Missing element: expected "${e}" to be present`);return r}function fe(e,t=document){return t.querySelector(e)||void 0}function Ie(){var e,t,r,o;return(o=(r=(t=(e=document.activeElement)==null?void 0:e.shadowRoot)==null?void 0:t.activeElement)!=null?r:document.activeElement)!=null?o:void 0}var wa=O(h(document.body,"focusin"),h(document.body,"focusout")).pipe(_e(1),Q(void 0),m(()=>Ie()||document.body),G(1));function et(e){return wa.pipe(m(t=>e.contains(t)),K())}function $t(e,t){return C(()=>O(h(e,"mouseenter").pipe(m(()=>!0)),h(e,"mouseleave").pipe(m(()=>!1))).pipe(t?Ht(r=>Le(+!r*t)):le,Q(e.matches(":hover"))))}function Jo(e,t){if(typeof t=="string"||typeof t=="number")e.innerHTML+=t.toString();else if(t instanceof Node)e.appendChild(t);else if(Array.isArray(t))for(let r of t)Jo(e,r)}function x(e,t,...r){let o=document.createElement(e);if(t)for(let n of Object.keys(t))typeof t[n]!="undefined"&&(typeof t[n]!="boolean"?o.setAttribute(n,t[n]):o.setAttribute(n,""));for(let n of r)Jo(o,n);return o}function sr(e){if(e>999){let t=+((e-950)%1e3>99);return`${((e+1e-6)/1e3).toFixed(t)}k`}else return e.toString()}function Tt(e){let t=x("script",{src:e});return C(()=>(document.head.appendChild(t),O(h(t,"load"),h(t,"error").pipe(v(()=>$r(()=>new ReferenceError(`Invalid script: ${e}`))))).pipe(m(()=>{}),_(()=>document.head.removeChild(t)),Te(1))))}var Xo=new g,Ta=C(()=>typeof ResizeObserver=="undefined"?Tt("https://unpkg.com/resize-observer-polyfill"):I(void 0)).pipe(m(()=>new ResizeObserver(e=>e.forEach(t=>Xo.next(t)))),v(e=>O(Ye,I(e)).pipe(_(()=>e.disconnect()))),G(1));function ce(e){return{width:e.offsetWidth,height:e.offsetHeight}}function ge(e){let t=e;for(;t.clientWidth===0&&t.parentElement;)t=t.parentElement;return Ta.pipe(w(r=>r.observe(t)),v(r=>Xo.pipe(b(o=>o.target===t),_(()=>r.unobserve(t)))),m(()=>ce(e)),Q(ce(e)))}function St(e){return{width:e.scrollWidth,height:e.scrollHeight}}function cr(e){let t=e.parentElement;for(;t&&(e.scrollWidth<=t.scrollWidth&&e.scrollHeight<=t.scrollHeight);)t=(e=t).parentElement;return t?e:void 0}function Zo(e){let t=[],r=e.parentElement;for(;r;)(e.clientWidth>r.clientWidth||e.clientHeight>r.clientHeight)&&t.push(r),r=(e=r).parentElement;return t.length===0&&t.push(document.documentElement),t}function Ve(e){return{x:e.offsetLeft,y:e.offsetTop}}function en(e){let t=e.getBoundingClientRect();return{x:t.x+window.scrollX,y:t.y+window.scrollY}}function tn(e){return O(h(window,"load"),h(window,"resize")).pipe(Me(0,me),m(()=>Ve(e)),Q(Ve(e)))}function pr(e){return{x:e.scrollLeft,y:e.scrollTop}}function Ne(e){return O(h(e,"scroll"),h(window,"scroll"),h(window,"resize")).pipe(Me(0,me),m(()=>pr(e)),Q(pr(e)))}var rn=new g,Sa=C(()=>I(new IntersectionObserver(e=>{for(let t of e)rn.next(t)},{threshold:0}))).pipe(v(e=>O(Ye,I(e)).pipe(_(()=>e.disconnect()))),G(1));function tt(e){return Sa.pipe(w(t=>t.observe(e)),v(t=>rn.pipe(b(({target:r})=>r===e),_(()=>t.unobserve(e)),m(({isIntersecting:r})=>r))))}function on(e,t=16){return Ne(e).pipe(m(({y:r})=>{let o=ce(e),n=St(e);return r>=n.height-o.height-t}),K())}var lr={drawer:R("[data-md-toggle=drawer]"),search:R("[data-md-toggle=search]")};function nn(e){return lr[e].checked}function Je(e,t){lr[e].checked!==t&&lr[e].click()}function ze(e){let t=lr[e];return h(t,"change").pipe(m(()=>t.checked),Q(t.checked))}function Oa(e,t){switch(e.constructor){case HTMLInputElement:return e.type==="radio"?/^Arrow/.test(t):!0;case HTMLSelectElement:case HTMLTextAreaElement:return!0;default:return e.isContentEditable}}function La(){return O(h(window,"compositionstart").pipe(m(()=>!0)),h(window,"compositionend").pipe(m(()=>!1))).pipe(Q(!1))}function an(){let e=h(window,"keydown").pipe(b(t=>!(t.metaKey||t.ctrlKey)),m(t=>({mode:nn("search")?"search":"global",type:t.key,claim(){t.preventDefault(),t.stopPropagation()}})),b(({mode:t,type:r})=>{if(t==="global"){let o=Ie();if(typeof o!="undefined")return!Oa(o,r)}return!0}),pe());return La().pipe(v(t=>t?S:e))}function ye(){return new URL(location.href)}function lt(e,t=!1){if(B("navigation.instant")&&!t){let r=x("a",{href:e.href});document.body.appendChild(r),r.click(),r.remove()}else location.href=e.href}function sn(){return new g}function cn(){return location.hash.slice(1)}function pn(e){let t=x("a",{href:e});t.addEventListener("click",r=>r.stopPropagation()),t.click()}function Ma(e){return O(h(window,"hashchange"),e).pipe(m(cn),Q(cn()),b(t=>t.length>0),G(1))}function ln(e){return Ma(e).pipe(m(t=>fe(`[id="${t}"]`)),b(t=>typeof t!="undefined"))}function Pt(e){let t=matchMedia(e);return ar(r=>t.addListener(()=>r(t.matches))).pipe(Q(t.matches))}function mn(){let e=matchMedia("print");return O(h(window,"beforeprint").pipe(m(()=>!0)),h(window,"afterprint").pipe(m(()=>!1))).pipe(Q(e.matches))}function Nr(e,t){return e.pipe(v(r=>r?t():S))}function zr(e,t){return new j(r=>{let o=new XMLHttpRequest;return o.open("GET",`${e}`),o.responseType="blob",o.addEventListener("load",()=>{o.status>=200&&o.status<300?(r.next(o.response),r.complete()):r.error(new Error(o.statusText))}),o.addEventListener("error",()=>{r.error(new Error("Network error"))}),o.addEventListener("abort",()=>{r.complete()}),typeof(t==null?void 0:t.progress$)!="undefined"&&(o.addEventListener("progress",n=>{var i;if(n.lengthComputable)t.progress$.next(n.loaded/n.total*100);else{let a=(i=o.getResponseHeader("Content-Length"))!=null?i:0;t.progress$.next(n.loaded/+a*100)}}),t.progress$.next(5)),o.send(),()=>o.abort()})}function je(e,t){return zr(e,t).pipe(v(r=>r.text()),m(r=>JSON.parse(r)),G(1))}function fn(e,t){let r=new DOMParser;return zr(e,t).pipe(v(o=>o.text()),m(o=>r.parseFromString(o,"text/html")),G(1))}function un(e,t){let r=new DOMParser;return zr(e,t).pipe(v(o=>o.text()),m(o=>r.parseFromString(o,"text/xml")),G(1))}function dn(){return{x:Math.max(0,scrollX),y:Math.max(0,scrollY)}}function hn(){return O(h(window,"scroll",{passive:!0}),h(window,"resize",{passive:!0})).pipe(m(dn),Q(dn()))}function bn(){return{width:innerWidth,height:innerHeight}}function vn(){return h(window,"resize",{passive:!0}).pipe(m(bn),Q(bn()))}function gn(){return z([hn(),vn()]).pipe(m(([e,t])=>({offset:e,size:t})),G(1))}function mr(e,{viewport$:t,header$:r}){let o=t.pipe(ee("size")),n=z([o,r]).pipe(m(()=>Ve(e)));return z([r,t,n]).pipe(m(([{height:i},{offset:a,size:s},{x:p,y:c}])=>({offset:{x:a.x-p,y:a.y-c+i},size:s})))}function _a(e){return h(e,"message",t=>t.data)}function Aa(e){let t=new g;return t.subscribe(r=>e.postMessage(r)),t}function yn(e,t=new Worker(e)){let r=_a(t),o=Aa(t),n=new g;n.subscribe(o);let i=o.pipe(Z(),ie(!0));return n.pipe(Z(),Re(r.pipe(W(i))),pe())}var Ca=R("#__config"),Ot=JSON.parse(Ca.textContent);Ot.base=`${new URL(Ot.base,ye())}`;function xe(){return Ot}function B(e){return Ot.features.includes(e)}function Ee(e,t){return typeof t!="undefined"?Ot.translations[e].replace("#",t.toString()):Ot.translations[e]}function Se(e,t=document){return R(`[data-md-component=${e}]`,t)}function ae(e,t=document){return P(`[data-md-component=${e}]`,t)}function ka(e){let t=R(".md-typeset > :first-child",e);return h(t,"click",{once:!0}).pipe(m(()=>R(".md-typeset",e)),m(r=>({hash:__md_hash(r.innerHTML)})))}function xn(e){if(!B("announce.dismiss")||!e.childElementCount)return S;if(!e.hidden){let t=R(".md-typeset",e);__md_hash(t.innerHTML)===__md_get("__announce")&&(e.hidden=!0)}return C(()=>{let t=new g;return t.subscribe(({hash:r})=>{e.hidden=!0,__md_set("__announce",r)}),ka(e).pipe(w(r=>t.next(r)),_(()=>t.complete()),m(r=>$({ref:e},r)))})}function Ha(e,{target$:t}){return t.pipe(m(r=>({hidden:r!==e})))}function En(e,t){let r=new g;return r.subscribe(({hidden:o})=>{e.hidden=o}),Ha(e,t).pipe(w(o=>r.next(o)),_(()=>r.complete()),m(o=>$({ref:e},o)))}function Rt(e,t){return t==="inline"?x("div",{class:"md-tooltip md-tooltip--inline",id:e,role:"tooltip"},x("div",{class:"md-tooltip__inner md-typeset"})):x("div",{class:"md-tooltip",id:e,role:"tooltip"},x("div",{class:"md-tooltip__inner md-typeset"}))}function wn(...e){return x("div",{class:"md-tooltip2",role:"tooltip"},x("div",{class:"md-tooltip2__inner md-typeset"},e))}function Tn(e,t){if(t=t?`${t}_annotation_${e}`:void 0,t){let r=t?`#${t}`:void 0;return x("aside",{class:"md-annotation",tabIndex:0},Rt(t),x("a",{href:r,class:"md-annotation__index",tabIndex:-1},x("span",{"data-md-annotation-id":e})))}else return x("aside",{class:"md-annotation",tabIndex:0},Rt(t),x("span",{class:"md-annotation__index",tabIndex:-1},x("span",{"data-md-annotation-id":e})))}function Sn(e){return x("button",{class:"md-clipboard md-icon",title:Ee("clipboard.copy"),"data-clipboard-target":`#${e} > code`})}var Ln=Mt(qr());function Qr(e,t){let r=t&2,o=t&1,n=Object.keys(e.terms).filter(p=>!e.terms[p]).reduce((p,c)=>[...p,x("del",null,(0,Ln.default)(c))," "],[]).slice(0,-1),i=xe(),a=new URL(e.location,i.base);B("search.highlight")&&a.searchParams.set("h",Object.entries(e.terms).filter(([,p])=>p).reduce((p,[c])=>`${p} ${c}`.trim(),""));let{tags:s}=xe();return x("a",{href:`${a}`,class:"md-search-result__link",tabIndex:-1},x("article",{class:"md-search-result__article md-typeset","data-md-score":e.score.toFixed(2)},r>0&&x("div",{class:"md-search-result__icon md-icon"}),r>0&&x("h1",null,e.title),r<=0&&x("h2",null,e.title),o>0&&e.text.length>0&&e.text,e.tags&&x("nav",{class:"md-tags"},e.tags.map(p=>{let c=s?p in s?`md-tag-icon md-tag--${s[p]}`:"md-tag-icon":"";return x("span",{class:`md-tag ${c}`},p)})),o>0&&n.length>0&&x("p",{class:"md-search-result__terms"},Ee("search.result.term.missing"),": ",...n)))}function Mn(e){let t=e[0].score,r=[...e],o=xe(),n=r.findIndex(l=>!`${new URL(l.location,o.base)}`.includes("#")),[i]=r.splice(n,1),a=r.findIndex(l=>l.scoreQr(l,1)),...p.length?[x("details",{class:"md-search-result__more"},x("summary",{tabIndex:-1},x("div",null,p.length>0&&p.length===1?Ee("search.result.more.one"):Ee("search.result.more.other",p.length))),...p.map(l=>Qr(l,1)))]:[]];return x("li",{class:"md-search-result__item"},c)}function _n(e){return x("ul",{class:"md-source__facts"},Object.entries(e).map(([t,r])=>x("li",{class:`md-source__fact md-source__fact--${t}`},typeof r=="number"?sr(r):r)))}function Kr(e){let t=`tabbed-control tabbed-control--${e}`;return x("div",{class:t,hidden:!0},x("button",{class:"tabbed-button",tabIndex:-1,"aria-hidden":"true"}))}function An(e){return x("div",{class:"md-typeset__scrollwrap"},x("div",{class:"md-typeset__table"},e))}function Ra(e){var o;let t=xe(),r=new URL(`../${e.version}/`,t.base);return x("li",{class:"md-version__item"},x("a",{href:`${r}`,class:"md-version__link"},e.title,((o=t.version)==null?void 0:o.alias)&&e.aliases.length>0&&x("span",{class:"md-version__alias"},e.aliases[0])))}function Cn(e,t){var o;let r=xe();return e=e.filter(n=>{var i;return!((i=n.properties)!=null&&i.hidden)}),x("div",{class:"md-version"},x("button",{class:"md-version__current","aria-label":Ee("select.version")},t.title,((o=r.version)==null?void 0:o.alias)&&t.aliases.length>0&&x("span",{class:"md-version__alias"},t.aliases[0])),x("ul",{class:"md-version__list"},e.map(Ra)))}var Ia=0;function ja(e){let t=z([et(e),$t(e)]).pipe(m(([o,n])=>o||n),K()),r=C(()=>Zo(e)).pipe(ne(Ne),pt(1),He(t),m(()=>en(e)));return t.pipe(Ae(o=>o),v(()=>z([t,r])),m(([o,n])=>({active:o,offset:n})),pe())}function Fa(e,t){let{content$:r,viewport$:o}=t,n=`__tooltip2_${Ia++}`;return C(()=>{let i=new g,a=new _r(!1);i.pipe(Z(),ie(!1)).subscribe(a);let s=a.pipe(Ht(c=>Le(+!c*250,kr)),K(),v(c=>c?r:S),w(c=>c.id=n),pe());z([i.pipe(m(({active:c})=>c)),s.pipe(v(c=>$t(c,250)),Q(!1))]).pipe(m(c=>c.some(l=>l))).subscribe(a);let p=a.pipe(b(c=>c),re(s,o),m(([c,l,{size:f}])=>{let u=e.getBoundingClientRect(),d=u.width/2;if(l.role==="tooltip")return{x:d,y:8+u.height};if(u.y>=f.height/2){let{height:y}=ce(l);return{x:d,y:-16-y}}else return{x:d,y:16+u.height}}));return z([s,i,p]).subscribe(([c,{offset:l},f])=>{c.style.setProperty("--md-tooltip-host-x",`${l.x}px`),c.style.setProperty("--md-tooltip-host-y",`${l.y}px`),c.style.setProperty("--md-tooltip-x",`${f.x}px`),c.style.setProperty("--md-tooltip-y",`${f.y}px`),c.classList.toggle("md-tooltip2--top",f.y<0),c.classList.toggle("md-tooltip2--bottom",f.y>=0)}),a.pipe(b(c=>c),re(s,(c,l)=>l),b(c=>c.role==="tooltip")).subscribe(c=>{let l=ce(R(":scope > *",c));c.style.setProperty("--md-tooltip-width",`${l.width}px`),c.style.setProperty("--md-tooltip-tail","0px")}),a.pipe(K(),ve(me),re(s)).subscribe(([c,l])=>{l.classList.toggle("md-tooltip2--active",c)}),z([a.pipe(b(c=>c)),s]).subscribe(([c,l])=>{l.role==="dialog"?(e.setAttribute("aria-controls",n),e.setAttribute("aria-haspopup","dialog")):e.setAttribute("aria-describedby",n)}),a.pipe(b(c=>!c)).subscribe(()=>{e.removeAttribute("aria-controls"),e.removeAttribute("aria-describedby"),e.removeAttribute("aria-haspopup")}),ja(e).pipe(w(c=>i.next(c)),_(()=>i.complete()),m(c=>$({ref:e},c)))})}function mt(e,{viewport$:t},r=document.body){return Fa(e,{content$:new j(o=>{let n=e.title,i=wn(n);return o.next(i),e.removeAttribute("title"),r.append(i),()=>{i.remove(),e.setAttribute("title",n)}}),viewport$:t})}function Ua(e,t){let r=C(()=>z([tn(e),Ne(t)])).pipe(m(([{x:o,y:n},i])=>{let{width:a,height:s}=ce(e);return{x:o-i.x+a/2,y:n-i.y+s/2}}));return et(e).pipe(v(o=>r.pipe(m(n=>({active:o,offset:n})),Te(+!o||1/0))))}function kn(e,t,{target$:r}){let[o,n]=Array.from(e.children);return C(()=>{let i=new g,a=i.pipe(Z(),ie(!0));return i.subscribe({next({offset:s}){e.style.setProperty("--md-tooltip-x",`${s.x}px`),e.style.setProperty("--md-tooltip-y",`${s.y}px`)},complete(){e.style.removeProperty("--md-tooltip-x"),e.style.removeProperty("--md-tooltip-y")}}),tt(e).pipe(W(a)).subscribe(s=>{e.toggleAttribute("data-md-visible",s)}),O(i.pipe(b(({active:s})=>s)),i.pipe(_e(250),b(({active:s})=>!s))).subscribe({next({active:s}){s?e.prepend(o):o.remove()},complete(){e.prepend(o)}}),i.pipe(Me(16,me)).subscribe(({active:s})=>{o.classList.toggle("md-tooltip--active",s)}),i.pipe(pt(125,me),b(()=>!!e.offsetParent),m(()=>e.offsetParent.getBoundingClientRect()),m(({x:s})=>s)).subscribe({next(s){s?e.style.setProperty("--md-tooltip-0",`${-s}px`):e.style.removeProperty("--md-tooltip-0")},complete(){e.style.removeProperty("--md-tooltip-0")}}),h(n,"click").pipe(W(a),b(s=>!(s.metaKey||s.ctrlKey))).subscribe(s=>{s.stopPropagation(),s.preventDefault()}),h(n,"mousedown").pipe(W(a),re(i)).subscribe(([s,{active:p}])=>{var c;if(s.button!==0||s.metaKey||s.ctrlKey)s.preventDefault();else if(p){s.preventDefault();let l=e.parentElement.closest(".md-annotation");l instanceof HTMLElement?l.focus():(c=Ie())==null||c.blur()}}),r.pipe(W(a),b(s=>s===o),Ge(125)).subscribe(()=>e.focus()),Ua(e,t).pipe(w(s=>i.next(s)),_(()=>i.complete()),m(s=>$({ref:e},s)))})}function Wa(e){return e.tagName==="CODE"?P(".c, .c1, .cm",e):[e]}function Da(e){let t=[];for(let r of Wa(e)){let o=[],n=document.createNodeIterator(r,NodeFilter.SHOW_TEXT);for(let i=n.nextNode();i;i=n.nextNode())o.push(i);for(let i of o){let a;for(;a=/(\(\d+\))(!)?/.exec(i.textContent);){let[,s,p]=a;if(typeof p=="undefined"){let c=i.splitText(a.index);i=c.splitText(s.length),t.push(c)}else{i.textContent=s,t.push(i);break}}}}return t}function Hn(e,t){t.append(...Array.from(e.childNodes))}function fr(e,t,{target$:r,print$:o}){let n=t.closest("[id]"),i=n==null?void 0:n.id,a=new Map;for(let s of Da(t)){let[,p]=s.textContent.match(/\((\d+)\)/);fe(`:scope > li:nth-child(${p})`,e)&&(a.set(p,Tn(p,i)),s.replaceWith(a.get(p)))}return a.size===0?S:C(()=>{let s=new g,p=s.pipe(Z(),ie(!0)),c=[];for(let[l,f]of a)c.push([R(".md-typeset",f),R(`:scope > li:nth-child(${l})`,e)]);return o.pipe(W(p)).subscribe(l=>{e.hidden=!l,e.classList.toggle("md-annotation-list",l);for(let[f,u]of c)l?Hn(f,u):Hn(u,f)}),O(...[...a].map(([,l])=>kn(l,t,{target$:r}))).pipe(_(()=>s.complete()),pe())})}function $n(e){if(e.nextElementSibling){let t=e.nextElementSibling;if(t.tagName==="OL")return t;if(t.tagName==="P"&&!t.children.length)return $n(t)}}function Pn(e,t){return C(()=>{let r=$n(e);return typeof r!="undefined"?fr(r,e,t):S})}var Rn=Mt(Br());var Va=0;function In(e){if(e.nextElementSibling){let t=e.nextElementSibling;if(t.tagName==="OL")return t;if(t.tagName==="P"&&!t.children.length)return In(t)}}function Na(e){return ge(e).pipe(m(({width:t})=>({scrollable:St(e).width>t})),ee("scrollable"))}function jn(e,t){let{matches:r}=matchMedia("(hover)"),o=C(()=>{let n=new g,i=n.pipe(jr(1));n.subscribe(({scrollable:c})=>{c&&r?e.setAttribute("tabindex","0"):e.removeAttribute("tabindex")});let a=[];if(Rn.default.isSupported()&&(e.closest(".copy")||B("content.code.copy")&&!e.closest(".no-copy"))){let c=e.closest("pre");c.id=`__code_${Va++}`;let l=Sn(c.id);c.insertBefore(l,e),B("content.tooltips")&&a.push(mt(l,{viewport$}))}let s=e.closest(".highlight");if(s instanceof HTMLElement){let c=In(s);if(typeof c!="undefined"&&(s.classList.contains("annotate")||B("content.code.annotate"))){let l=fr(c,e,t);a.push(ge(s).pipe(W(i),m(({width:f,height:u})=>f&&u),K(),v(f=>f?l:S)))}}return P(":scope > span[id]",e).length&&e.classList.add("md-code__content"),Na(e).pipe(w(c=>n.next(c)),_(()=>n.complete()),m(c=>$({ref:e},c)),Re(...a))});return B("content.lazy")?tt(e).pipe(b(n=>n),Te(1),v(()=>o)):o}function za(e,{target$:t,print$:r}){let o=!0;return O(t.pipe(m(n=>n.closest("details:not([open])")),b(n=>e===n),m(()=>({action:"open",reveal:!0}))),r.pipe(b(n=>n||!o),w(()=>o=e.open),m(n=>({action:n?"open":"close"}))))}function Fn(e,t){return C(()=>{let r=new g;return r.subscribe(({action:o,reveal:n})=>{e.toggleAttribute("open",o==="open"),n&&e.scrollIntoView()}),za(e,t).pipe(w(o=>r.next(o)),_(()=>r.complete()),m(o=>$({ref:e},o)))})}var Un=".node circle,.node ellipse,.node path,.node polygon,.node rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}marker{fill:var(--md-mermaid-edge-color)!important}.edgeLabel .label rect{fill:#0000}.label{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.label foreignObject{line-height:normal;overflow:visible}.label div .edgeLabel{color:var(--md-mermaid-label-fg-color)}.edgeLabel,.edgeLabel p,.label div .edgeLabel{background-color:var(--md-mermaid-label-bg-color)}.edgeLabel,.edgeLabel p{fill:var(--md-mermaid-label-bg-color);color:var(--md-mermaid-edge-color)}.edgePath .path,.flowchart-link{stroke:var(--md-mermaid-edge-color);stroke-width:.05rem}.edgePath .arrowheadPath{fill:var(--md-mermaid-edge-color);stroke:none}.cluster rect{fill:var(--md-default-fg-color--lightest);stroke:var(--md-default-fg-color--lighter)}.cluster span{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}g #flowchart-circleEnd,g #flowchart-circleStart,g #flowchart-crossEnd,g #flowchart-crossStart,g #flowchart-pointEnd,g #flowchart-pointStart{stroke:none}g.classGroup line,g.classGroup rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}g.classGroup text{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.classLabel .box{fill:var(--md-mermaid-label-bg-color);background-color:var(--md-mermaid-label-bg-color);opacity:1}.classLabel .label{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.node .divider{stroke:var(--md-mermaid-node-fg-color)}.relation{stroke:var(--md-mermaid-edge-color)}.cardinality{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.cardinality text{fill:inherit!important}defs #classDiagram-compositionEnd,defs #classDiagram-compositionStart,defs #classDiagram-dependencyEnd,defs #classDiagram-dependencyStart,defs #classDiagram-extensionEnd,defs #classDiagram-extensionStart{fill:var(--md-mermaid-edge-color)!important;stroke:var(--md-mermaid-edge-color)!important}defs #classDiagram-aggregationEnd,defs #classDiagram-aggregationStart{fill:var(--md-mermaid-label-bg-color)!important;stroke:var(--md-mermaid-edge-color)!important}g.stateGroup rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}g.stateGroup .state-title{fill:var(--md-mermaid-label-fg-color)!important;font-family:var(--md-mermaid-font-family)}g.stateGroup .composit{fill:var(--md-mermaid-label-bg-color)}.nodeLabel,.nodeLabel p{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}a .nodeLabel{text-decoration:underline}.node circle.state-end,.node circle.state-start,.start-state{fill:var(--md-mermaid-edge-color);stroke:none}.end-state-inner,.end-state-outer{fill:var(--md-mermaid-edge-color)}.end-state-inner,.node circle.state-end{stroke:var(--md-mermaid-label-bg-color)}.transition{stroke:var(--md-mermaid-edge-color)}[id^=state-fork] rect,[id^=state-join] rect{fill:var(--md-mermaid-edge-color)!important;stroke:none!important}.statediagram-cluster.statediagram-cluster .inner{fill:var(--md-default-bg-color)}.statediagram-cluster rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}.statediagram-state rect.divider{fill:var(--md-default-fg-color--lightest);stroke:var(--md-default-fg-color--lighter)}defs #statediagram-barbEnd{stroke:var(--md-mermaid-edge-color)}.attributeBoxEven,.attributeBoxOdd{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}.entityBox{fill:var(--md-mermaid-label-bg-color);stroke:var(--md-mermaid-node-fg-color)}.entityLabel{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.relationshipLabelBox{fill:var(--md-mermaid-label-bg-color);fill-opacity:1;background-color:var(--md-mermaid-label-bg-color);opacity:1}.relationshipLabel{fill:var(--md-mermaid-label-fg-color)}.relationshipLine{stroke:var(--md-mermaid-edge-color)}defs #ONE_OR_MORE_END *,defs #ONE_OR_MORE_START *,defs #ONLY_ONE_END *,defs #ONLY_ONE_START *,defs #ZERO_OR_MORE_END *,defs #ZERO_OR_MORE_START *,defs #ZERO_OR_ONE_END *,defs #ZERO_OR_ONE_START *{stroke:var(--md-mermaid-edge-color)!important}defs #ZERO_OR_MORE_END circle,defs #ZERO_OR_MORE_START circle{fill:var(--md-mermaid-label-bg-color)}.actor{fill:var(--md-mermaid-sequence-actor-bg-color);stroke:var(--md-mermaid-sequence-actor-border-color)}text.actor>tspan{fill:var(--md-mermaid-sequence-actor-fg-color);font-family:var(--md-mermaid-font-family)}line{stroke:var(--md-mermaid-sequence-actor-line-color)}.actor-man circle,.actor-man line{fill:var(--md-mermaid-sequence-actorman-bg-color);stroke:var(--md-mermaid-sequence-actorman-line-color)}.messageLine0,.messageLine1{stroke:var(--md-mermaid-sequence-message-line-color)}.note{fill:var(--md-mermaid-sequence-note-bg-color);stroke:var(--md-mermaid-sequence-note-border-color)}.loopText,.loopText>tspan,.messageText,.noteText>tspan{stroke:none;font-family:var(--md-mermaid-font-family)!important}.messageText{fill:var(--md-mermaid-sequence-message-fg-color)}.loopText,.loopText>tspan{fill:var(--md-mermaid-sequence-loop-fg-color)}.noteText>tspan{fill:var(--md-mermaid-sequence-note-fg-color)}#arrowhead path{fill:var(--md-mermaid-sequence-message-line-color);stroke:none}.loopLine{fill:var(--md-mermaid-sequence-loop-bg-color);stroke:var(--md-mermaid-sequence-loop-border-color)}.labelBox{fill:var(--md-mermaid-sequence-label-bg-color);stroke:none}.labelText,.labelText>span{fill:var(--md-mermaid-sequence-label-fg-color);font-family:var(--md-mermaid-font-family)}.sequenceNumber{fill:var(--md-mermaid-sequence-number-fg-color)}rect.rect{fill:var(--md-mermaid-sequence-box-bg-color);stroke:none}rect.rect+text.text{fill:var(--md-mermaid-sequence-box-fg-color)}defs #sequencenumber{fill:var(--md-mermaid-sequence-number-bg-color)!important}";var Gr,Qa=0;function Ka(){return typeof mermaid=="undefined"||mermaid instanceof Element?Tt("https://unpkg.com/mermaid@11/dist/mermaid.min.js"):I(void 0)}function Wn(e){return e.classList.remove("mermaid"),Gr||(Gr=Ka().pipe(w(()=>mermaid.initialize({startOnLoad:!1,themeCSS:Un,sequence:{actorFontSize:"16px",messageFontSize:"16px",noteFontSize:"16px"}})),m(()=>{}),G(1))),Gr.subscribe(()=>co(this,null,function*(){e.classList.add("mermaid");let t=`__mermaid_${Qa++}`,r=x("div",{class:"mermaid"}),o=e.textContent,{svg:n,fn:i}=yield mermaid.render(t,o),a=r.attachShadow({mode:"closed"});a.innerHTML=n,e.replaceWith(r),i==null||i(a)})),Gr.pipe(m(()=>({ref:e})))}var Dn=x("table");function Vn(e){return e.replaceWith(Dn),Dn.replaceWith(An(e)),I({ref:e})}function Ya(e){let t=e.find(r=>r.checked)||e[0];return O(...e.map(r=>h(r,"change").pipe(m(()=>R(`label[for="${r.id}"]`))))).pipe(Q(R(`label[for="${t.id}"]`)),m(r=>({active:r})))}function Nn(e,{viewport$:t,target$:r}){let o=R(".tabbed-labels",e),n=P(":scope > input",e),i=Kr("prev");e.append(i);let a=Kr("next");return e.append(a),C(()=>{let s=new g,p=s.pipe(Z(),ie(!0));z([s,ge(e),tt(e)]).pipe(W(p),Me(1,me)).subscribe({next([{active:c},l]){let f=Ve(c),{width:u}=ce(c);e.style.setProperty("--md-indicator-x",`${f.x}px`),e.style.setProperty("--md-indicator-width",`${u}px`);let d=pr(o);(f.xd.x+l.width)&&o.scrollTo({left:Math.max(0,f.x-16),behavior:"smooth"})},complete(){e.style.removeProperty("--md-indicator-x"),e.style.removeProperty("--md-indicator-width")}}),z([Ne(o),ge(o)]).pipe(W(p)).subscribe(([c,l])=>{let f=St(o);i.hidden=c.x<16,a.hidden=c.x>f.width-l.width-16}),O(h(i,"click").pipe(m(()=>-1)),h(a,"click").pipe(m(()=>1))).pipe(W(p)).subscribe(c=>{let{width:l}=ce(o);o.scrollBy({left:l*c,behavior:"smooth"})}),r.pipe(W(p),b(c=>n.includes(c))).subscribe(c=>c.click()),o.classList.add("tabbed-labels--linked");for(let c of n){let l=R(`label[for="${c.id}"]`);l.replaceChildren(x("a",{href:`#${l.htmlFor}`,tabIndex:-1},...Array.from(l.childNodes))),h(l.firstElementChild,"click").pipe(W(p),b(f=>!(f.metaKey||f.ctrlKey)),w(f=>{f.preventDefault(),f.stopPropagation()})).subscribe(()=>{history.replaceState({},"",`#${l.htmlFor}`),l.click()})}return B("content.tabs.link")&&s.pipe(Ce(1),re(t)).subscribe(([{active:c},{offset:l}])=>{let f=c.innerText.trim();if(c.hasAttribute("data-md-switching"))c.removeAttribute("data-md-switching");else{let u=e.offsetTop-l.y;for(let y of P("[data-tabs]"))for(let L of P(":scope > input",y)){let X=R(`label[for="${L.id}"]`);if(X!==c&&X.innerText.trim()===f){X.setAttribute("data-md-switching",""),L.click();break}}window.scrollTo({top:e.offsetTop-u});let d=__md_get("__tabs")||[];__md_set("__tabs",[...new Set([f,...d])])}}),s.pipe(W(p)).subscribe(()=>{for(let c of P("audio, video",e))c.pause()}),Ya(n).pipe(w(c=>s.next(c)),_(()=>s.complete()),m(c=>$({ref:e},c)))}).pipe(Ke(se))}function zn(e,{viewport$:t,target$:r,print$:o}){return O(...P(".annotate:not(.highlight)",e).map(n=>Pn(n,{target$:r,print$:o})),...P("pre:not(.mermaid) > code",e).map(n=>jn(n,{target$:r,print$:o})),...P("pre.mermaid",e).map(n=>Wn(n)),...P("table:not([class])",e).map(n=>Vn(n)),...P("details",e).map(n=>Fn(n,{target$:r,print$:o})),...P("[data-tabs]",e).map(n=>Nn(n,{viewport$:t,target$:r})),...P("[title]",e).filter(()=>B("content.tooltips")).map(n=>mt(n,{viewport$:t})))}function Ba(e,{alert$:t}){return t.pipe(v(r=>O(I(!0),I(!1).pipe(Ge(2e3))).pipe(m(o=>({message:r,active:o})))))}function qn(e,t){let r=R(".md-typeset",e);return C(()=>{let o=new g;return o.subscribe(({message:n,active:i})=>{e.classList.toggle("md-dialog--active",i),r.textContent=n}),Ba(e,t).pipe(w(n=>o.next(n)),_(()=>o.complete()),m(n=>$({ref:e},n)))})}var Ga=0;function Ja(e,t){document.body.append(e);let{width:r}=ce(e);e.style.setProperty("--md-tooltip-width",`${r}px`),e.remove();let o=cr(t),n=typeof o!="undefined"?Ne(o):I({x:0,y:0}),i=O(et(t),$t(t)).pipe(K());return z([i,n]).pipe(m(([a,s])=>{let{x:p,y:c}=Ve(t),l=ce(t),f=t.closest("table");return f&&t.parentElement&&(p+=f.offsetLeft+t.parentElement.offsetLeft,c+=f.offsetTop+t.parentElement.offsetTop),{active:a,offset:{x:p-s.x+l.width/2-r/2,y:c-s.y+l.height+8}}}))}function Qn(e){let t=e.title;if(!t.length)return S;let r=`__tooltip_${Ga++}`,o=Rt(r,"inline"),n=R(".md-typeset",o);return n.innerHTML=t,C(()=>{let i=new g;return i.subscribe({next({offset:a}){o.style.setProperty("--md-tooltip-x",`${a.x}px`),o.style.setProperty("--md-tooltip-y",`${a.y}px`)},complete(){o.style.removeProperty("--md-tooltip-x"),o.style.removeProperty("--md-tooltip-y")}}),O(i.pipe(b(({active:a})=>a)),i.pipe(_e(250),b(({active:a})=>!a))).subscribe({next({active:a}){a?(e.insertAdjacentElement("afterend",o),e.setAttribute("aria-describedby",r),e.removeAttribute("title")):(o.remove(),e.removeAttribute("aria-describedby"),e.setAttribute("title",t))},complete(){o.remove(),e.removeAttribute("aria-describedby"),e.setAttribute("title",t)}}),i.pipe(Me(16,me)).subscribe(({active:a})=>{o.classList.toggle("md-tooltip--active",a)}),i.pipe(pt(125,me),b(()=>!!e.offsetParent),m(()=>e.offsetParent.getBoundingClientRect()),m(({x:a})=>a)).subscribe({next(a){a?o.style.setProperty("--md-tooltip-0",`${-a}px`):o.style.removeProperty("--md-tooltip-0")},complete(){o.style.removeProperty("--md-tooltip-0")}}),Ja(o,e).pipe(w(a=>i.next(a)),_(()=>i.complete()),m(a=>$({ref:e},a)))}).pipe(Ke(se))}function Xa({viewport$:e}){if(!B("header.autohide"))return I(!1);let t=e.pipe(m(({offset:{y:n}})=>n),Be(2,1),m(([n,i])=>[nMath.abs(i-n.y)>100),m(([,[n]])=>n),K()),o=ze("search");return z([e,o]).pipe(m(([{offset:n},i])=>n.y>400&&!i),K(),v(n=>n?r:I(!1)),Q(!1))}function Kn(e,t){return C(()=>z([ge(e),Xa(t)])).pipe(m(([{height:r},o])=>({height:r,hidden:o})),K((r,o)=>r.height===o.height&&r.hidden===o.hidden),G(1))}function Yn(e,{header$:t,main$:r}){return C(()=>{let o=new g,n=o.pipe(Z(),ie(!0));o.pipe(ee("active"),He(t)).subscribe(([{active:a},{hidden:s}])=>{e.classList.toggle("md-header--shadow",a&&!s),e.hidden=s});let i=ue(P("[title]",e)).pipe(b(()=>B("content.tooltips")),ne(a=>Qn(a)));return r.subscribe(o),t.pipe(W(n),m(a=>$({ref:e},a)),Re(i.pipe(W(n))))})}function Za(e,{viewport$:t,header$:r}){return mr(e,{viewport$:t,header$:r}).pipe(m(({offset:{y:o}})=>{let{height:n}=ce(e);return{active:o>=n}}),ee("active"))}function Bn(e,t){return C(()=>{let r=new g;r.subscribe({next({active:n}){e.classList.toggle("md-header__title--active",n)},complete(){e.classList.remove("md-header__title--active")}});let o=fe(".md-content h1");return typeof o=="undefined"?S:Za(o,t).pipe(w(n=>r.next(n)),_(()=>r.complete()),m(n=>$({ref:e},n)))})}function Gn(e,{viewport$:t,header$:r}){let o=r.pipe(m(({height:i})=>i),K()),n=o.pipe(v(()=>ge(e).pipe(m(({height:i})=>({top:e.offsetTop,bottom:e.offsetTop+i})),ee("bottom"))));return z([o,n,t]).pipe(m(([i,{top:a,bottom:s},{offset:{y:p},size:{height:c}}])=>(c=Math.max(0,c-Math.max(0,a-p,i)-Math.max(0,c+p-s)),{offset:a-i,height:c,active:a-i<=p})),K((i,a)=>i.offset===a.offset&&i.height===a.height&&i.active===a.active))}function es(e){let t=__md_get("__palette")||{index:e.findIndex(o=>matchMedia(o.getAttribute("data-md-color-media")).matches)},r=Math.max(0,Math.min(t.index,e.length-1));return I(...e).pipe(ne(o=>h(o,"change").pipe(m(()=>o))),Q(e[r]),m(o=>({index:e.indexOf(o),color:{media:o.getAttribute("data-md-color-media"),scheme:o.getAttribute("data-md-color-scheme"),primary:o.getAttribute("data-md-color-primary"),accent:o.getAttribute("data-md-color-accent")}})),G(1))}function Jn(e){let t=P("input",e),r=x("meta",{name:"theme-color"});document.head.appendChild(r);let o=x("meta",{name:"color-scheme"});document.head.appendChild(o);let n=Pt("(prefers-color-scheme: light)");return C(()=>{let i=new g;return i.subscribe(a=>{if(document.body.setAttribute("data-md-color-switching",""),a.color.media==="(prefers-color-scheme)"){let s=matchMedia("(prefers-color-scheme: light)"),p=document.querySelector(s.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");a.color.scheme=p.getAttribute("data-md-color-scheme"),a.color.primary=p.getAttribute("data-md-color-primary"),a.color.accent=p.getAttribute("data-md-color-accent")}for(let[s,p]of Object.entries(a.color))document.body.setAttribute(`data-md-color-${s}`,p);for(let s=0;sa.key==="Enter"),re(i,(a,s)=>s)).subscribe(({index:a})=>{a=(a+1)%t.length,t[a].click(),t[a].focus()}),i.pipe(m(()=>{let a=Se("header"),s=window.getComputedStyle(a);return o.content=s.colorScheme,s.backgroundColor.match(/\d+/g).map(p=>(+p).toString(16).padStart(2,"0")).join("")})).subscribe(a=>r.content=`#${a}`),i.pipe(ve(se)).subscribe(()=>{document.body.removeAttribute("data-md-color-switching")}),es(t).pipe(W(n.pipe(Ce(1))),ct(),w(a=>i.next(a)),_(()=>i.complete()),m(a=>$({ref:e},a)))})}function Xn(e,{progress$:t}){return C(()=>{let r=new g;return r.subscribe(({value:o})=>{e.style.setProperty("--md-progress-value",`${o}`)}),t.pipe(w(o=>r.next({value:o})),_(()=>r.complete()),m(o=>({ref:e,value:o})))})}var Jr=Mt(Br());function ts(e){e.setAttribute("data-md-copying","");let t=e.closest("[data-copy]"),r=t?t.getAttribute("data-copy"):e.innerText;return e.removeAttribute("data-md-copying"),r.trimEnd()}function Zn({alert$:e}){Jr.default.isSupported()&&new j(t=>{new Jr.default("[data-clipboard-target], [data-clipboard-text]",{text:r=>r.getAttribute("data-clipboard-text")||ts(R(r.getAttribute("data-clipboard-target")))}).on("success",r=>t.next(r))}).pipe(w(t=>{t.trigger.focus()}),m(()=>Ee("clipboard.copied"))).subscribe(e)}function ei(e,t){return e.protocol=t.protocol,e.hostname=t.hostname,e}function rs(e,t){let r=new Map;for(let o of P("url",e)){let n=R("loc",o),i=[ei(new URL(n.textContent),t)];r.set(`${i[0]}`,i);for(let a of P("[rel=alternate]",o)){let s=a.getAttribute("href");s!=null&&i.push(ei(new URL(s),t))}}return r}function ur(e){return un(new URL("sitemap.xml",e)).pipe(m(t=>rs(t,new URL(e))),de(()=>I(new Map)))}function os(e,t){if(!(e.target instanceof Element))return S;let r=e.target.closest("a");if(r===null)return S;if(r.target||e.metaKey||e.ctrlKey)return S;let o=new URL(r.href);return o.search=o.hash="",t.has(`${o}`)?(e.preventDefault(),I(new URL(r.href))):S}function ti(e){let t=new Map;for(let r of P(":scope > *",e.head))t.set(r.outerHTML,r);return t}function ri(e){for(let t of P("[href], [src]",e))for(let r of["href","src"]){let o=t.getAttribute(r);if(o&&!/^(?:[a-z]+:)?\/\//i.test(o)){t[r]=t[r];break}}return I(e)}function ns(e){for(let o of["[data-md-component=announce]","[data-md-component=container]","[data-md-component=header-topic]","[data-md-component=outdated]","[data-md-component=logo]","[data-md-component=skip]",...B("navigation.tabs.sticky")?["[data-md-component=tabs]"]:[]]){let n=fe(o),i=fe(o,e);typeof n!="undefined"&&typeof i!="undefined"&&n.replaceWith(i)}let t=ti(document);for(let[o,n]of ti(e))t.has(o)?t.delete(o):document.head.appendChild(n);for(let o of t.values()){let n=o.getAttribute("name");n!=="theme-color"&&n!=="color-scheme"&&o.remove()}let r=Se("container");return We(P("script",r)).pipe(v(o=>{let n=e.createElement("script");if(o.src){for(let i of o.getAttributeNames())n.setAttribute(i,o.getAttribute(i));return o.replaceWith(n),new j(i=>{n.onload=()=>i.complete()})}else return n.textContent=o.textContent,o.replaceWith(n),S}),Z(),ie(document))}function oi({location$:e,viewport$:t,progress$:r}){let o=xe();if(location.protocol==="file:")return S;let n=ur(o.base);I(document).subscribe(ri);let i=h(document.body,"click").pipe(He(n),v(([p,c])=>os(p,c)),pe()),a=h(window,"popstate").pipe(m(ye),pe());i.pipe(re(t)).subscribe(([p,{offset:c}])=>{history.replaceState(c,""),history.pushState(null,"",p)}),O(i,a).subscribe(e);let s=e.pipe(ee("pathname"),v(p=>fn(p,{progress$:r}).pipe(de(()=>(lt(p,!0),S)))),v(ri),v(ns),pe());return O(s.pipe(re(e,(p,c)=>c)),s.pipe(v(()=>e),ee("pathname"),v(()=>e),ee("hash")),e.pipe(K((p,c)=>p.pathname===c.pathname&&p.hash===c.hash),v(()=>i),w(()=>history.back()))).subscribe(p=>{var c,l;history.state!==null||!p.hash?window.scrollTo(0,(l=(c=history.state)==null?void 0:c.y)!=null?l:0):(history.scrollRestoration="auto",pn(p.hash),history.scrollRestoration="manual")}),e.subscribe(()=>{history.scrollRestoration="manual"}),h(window,"beforeunload").subscribe(()=>{history.scrollRestoration="auto"}),t.pipe(ee("offset"),_e(100)).subscribe(({offset:p})=>{history.replaceState(p,"")}),s}var ni=Mt(qr());function ii(e){let t=e.separator.split("|").map(n=>n.replace(/(\(\?[!=<][^)]+\))/g,"").length===0?"\uFFFD":n).join("|"),r=new RegExp(t,"img"),o=(n,i,a)=>`${i}${a}`;return n=>{n=n.replace(/[\s*+\-:~^]+/g," ").trim();let i=new RegExp(`(^|${e.separator}|)(${n.replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&").replace(r,"|")})`,"img");return a=>(0,ni.default)(a).replace(i,o).replace(/<\/mark>(\s+)]*>/img,"$1")}}function jt(e){return e.type===1}function dr(e){return e.type===3}function ai(e,t){let r=yn(e);return O(I(location.protocol!=="file:"),ze("search")).pipe(Ae(o=>o),v(()=>t)).subscribe(({config:o,docs:n})=>r.next({type:0,data:{config:o,docs:n,options:{suggest:B("search.suggest")}}})),r}function si(e){var l;let{selectedVersionSitemap:t,selectedVersionBaseURL:r,currentLocation:o,currentBaseURL:n}=e,i=(l=Xr(n))==null?void 0:l.pathname;if(i===void 0)return;let a=ss(o.pathname,i);if(a===void 0)return;let s=ps(t.keys());if(!t.has(s))return;let p=Xr(a,s);if(!p||!t.has(p.href))return;let c=Xr(a,r);if(c)return c.hash=o.hash,c.search=o.search,c}function Xr(e,t){try{return new URL(e,t)}catch(r){return}}function ss(e,t){if(e.startsWith(t))return e.slice(t.length)}function cs(e,t){let r=Math.min(e.length,t.length),o;for(o=0;oS)),o=r.pipe(m(n=>{let[,i]=t.base.match(/([^/]+)\/?$/);return n.find(({version:a,aliases:s})=>a===i||s.includes(i))||n[0]}));r.pipe(m(n=>new Map(n.map(i=>[`${new URL(`../${i.version}/`,t.base)}`,i]))),v(n=>h(document.body,"click").pipe(b(i=>!i.metaKey&&!i.ctrlKey),re(o),v(([i,a])=>{if(i.target instanceof Element){let s=i.target.closest("a");if(s&&!s.target&&n.has(s.href)){let p=s.href;return!i.target.closest(".md-version")&&n.get(p)===a?S:(i.preventDefault(),I(new URL(p)))}}return S}),v(i=>ur(i).pipe(m(a=>{var s;return(s=si({selectedVersionSitemap:a,selectedVersionBaseURL:i,currentLocation:ye(),currentBaseURL:t.base}))!=null?s:i})))))).subscribe(n=>lt(n,!0)),z([r,o]).subscribe(([n,i])=>{R(".md-header__topic").appendChild(Cn(n,i))}),e.pipe(v(()=>o)).subscribe(n=>{var a;let i=__md_get("__outdated",sessionStorage);if(i===null){i=!0;let s=((a=t.version)==null?void 0:a.default)||"latest";Array.isArray(s)||(s=[s]);e:for(let p of s)for(let c of n.aliases.concat(n.version))if(new RegExp(p,"i").test(c)){i=!1;break e}__md_set("__outdated",i,sessionStorage)}if(i)for(let s of ae("outdated"))s.hidden=!1})}function ls(e,{worker$:t}){let{searchParams:r}=ye();r.has("q")&&(Je("search",!0),e.value=r.get("q"),e.focus(),ze("search").pipe(Ae(i=>!i)).subscribe(()=>{let i=ye();i.searchParams.delete("q"),history.replaceState({},"",`${i}`)}));let o=et(e),n=O(t.pipe(Ae(jt)),h(e,"keyup"),o).pipe(m(()=>e.value),K());return z([n,o]).pipe(m(([i,a])=>({value:i,focus:a})),G(1))}function pi(e,{worker$:t}){let r=new g,o=r.pipe(Z(),ie(!0));z([t.pipe(Ae(jt)),r],(i,a)=>a).pipe(ee("value")).subscribe(({value:i})=>t.next({type:2,data:i})),r.pipe(ee("focus")).subscribe(({focus:i})=>{i&&Je("search",i)}),h(e.form,"reset").pipe(W(o)).subscribe(()=>e.focus());let n=R("header [for=__search]");return h(n,"click").subscribe(()=>e.focus()),ls(e,{worker$:t}).pipe(w(i=>r.next(i)),_(()=>r.complete()),m(i=>$({ref:e},i)),G(1))}function li(e,{worker$:t,query$:r}){let o=new g,n=on(e.parentElement).pipe(b(Boolean)),i=e.parentElement,a=R(":scope > :first-child",e),s=R(":scope > :last-child",e);ze("search").subscribe(l=>s.setAttribute("role",l?"list":"presentation")),o.pipe(re(r),Wr(t.pipe(Ae(jt)))).subscribe(([{items:l},{value:f}])=>{switch(l.length){case 0:a.textContent=f.length?Ee("search.result.none"):Ee("search.result.placeholder");break;case 1:a.textContent=Ee("search.result.one");break;default:let u=sr(l.length);a.textContent=Ee("search.result.other",u)}});let p=o.pipe(w(()=>s.innerHTML=""),v(({items:l})=>O(I(...l.slice(0,10)),I(...l.slice(10)).pipe(Be(4),Vr(n),v(([f])=>f)))),m(Mn),pe());return p.subscribe(l=>s.appendChild(l)),p.pipe(ne(l=>{let f=fe("details",l);return typeof f=="undefined"?S:h(f,"toggle").pipe(W(o),m(()=>f))})).subscribe(l=>{l.open===!1&&l.offsetTop<=i.scrollTop&&i.scrollTo({top:l.offsetTop})}),t.pipe(b(dr),m(({data:l})=>l)).pipe(w(l=>o.next(l)),_(()=>o.complete()),m(l=>$({ref:e},l)))}function ms(e,{query$:t}){return t.pipe(m(({value:r})=>{let o=ye();return o.hash="",r=r.replace(/\s+/g,"+").replace(/&/g,"%26").replace(/=/g,"%3D"),o.search=`q=${r}`,{url:o}}))}function mi(e,t){let r=new g,o=r.pipe(Z(),ie(!0));return r.subscribe(({url:n})=>{e.setAttribute("data-clipboard-text",e.href),e.href=`${n}`}),h(e,"click").pipe(W(o)).subscribe(n=>n.preventDefault()),ms(e,t).pipe(w(n=>r.next(n)),_(()=>r.complete()),m(n=>$({ref:e},n)))}function fi(e,{worker$:t,keyboard$:r}){let o=new g,n=Se("search-query"),i=O(h(n,"keydown"),h(n,"focus")).pipe(ve(se),m(()=>n.value),K());return o.pipe(He(i),m(([{suggest:s},p])=>{let c=p.split(/([\s-]+)/);if(s!=null&&s.length&&c[c.length-1]){let l=s[s.length-1];l.startsWith(c[c.length-1])&&(c[c.length-1]=l)}else c.length=0;return c})).subscribe(s=>e.innerHTML=s.join("").replace(/\s/g," ")),r.pipe(b(({mode:s})=>s==="search")).subscribe(s=>{switch(s.type){case"ArrowRight":e.innerText.length&&n.selectionStart===n.value.length&&(n.value=e.innerText);break}}),t.pipe(b(dr),m(({data:s})=>s)).pipe(w(s=>o.next(s)),_(()=>o.complete()),m(()=>({ref:e})))}function ui(e,{index$:t,keyboard$:r}){let o=xe();try{let n=ai(o.search,t),i=Se("search-query",e),a=Se("search-result",e);h(e,"click").pipe(b(({target:p})=>p instanceof Element&&!!p.closest("a"))).subscribe(()=>Je("search",!1)),r.pipe(b(({mode:p})=>p==="search")).subscribe(p=>{let c=Ie();switch(p.type){case"Enter":if(c===i){let l=new Map;for(let f of P(":first-child [href]",a)){let u=f.firstElementChild;l.set(f,parseFloat(u.getAttribute("data-md-score")))}if(l.size){let[[f]]=[...l].sort(([,u],[,d])=>d-u);f.click()}p.claim()}break;case"Escape":case"Tab":Je("search",!1),i.blur();break;case"ArrowUp":case"ArrowDown":if(typeof c=="undefined")i.focus();else{let l=[i,...P(":not(details) > [href], summary, details[open] [href]",a)],f=Math.max(0,(Math.max(0,l.indexOf(c))+l.length+(p.type==="ArrowUp"?-1:1))%l.length);l[f].focus()}p.claim();break;default:i!==Ie()&&i.focus()}}),r.pipe(b(({mode:p})=>p==="global")).subscribe(p=>{switch(p.type){case"f":case"s":case"/":i.focus(),i.select(),p.claim();break}});let s=pi(i,{worker$:n});return O(s,li(a,{worker$:n,query$:s})).pipe(Re(...ae("search-share",e).map(p=>mi(p,{query$:s})),...ae("search-suggest",e).map(p=>fi(p,{worker$:n,keyboard$:r}))))}catch(n){return e.hidden=!0,Ye}}function di(e,{index$:t,location$:r}){return z([t,r.pipe(Q(ye()),b(o=>!!o.searchParams.get("h")))]).pipe(m(([o,n])=>ii(o.config)(n.searchParams.get("h"))),m(o=>{var a;let n=new Map,i=document.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let s=i.nextNode();s;s=i.nextNode())if((a=s.parentElement)!=null&&a.offsetHeight){let p=s.textContent,c=o(p);c.length>p.length&&n.set(s,c)}for(let[s,p]of n){let{childNodes:c}=x("span",null,p);s.replaceWith(...Array.from(c))}return{ref:e,nodes:n}}))}function fs(e,{viewport$:t,main$:r}){let o=e.closest(".md-grid"),n=o.offsetTop-o.parentElement.offsetTop;return z([r,t]).pipe(m(([{offset:i,height:a},{offset:{y:s}}])=>(a=a+Math.min(n,Math.max(0,s-i))-n,{height:a,locked:s>=i+n})),K((i,a)=>i.height===a.height&&i.locked===a.locked))}function Zr(e,o){var n=o,{header$:t}=n,r=so(n,["header$"]);let i=R(".md-sidebar__scrollwrap",e),{y:a}=Ve(i);return C(()=>{let s=new g,p=s.pipe(Z(),ie(!0)),c=s.pipe(Me(0,me));return c.pipe(re(t)).subscribe({next([{height:l},{height:f}]){i.style.height=`${l-2*a}px`,e.style.top=`${f}px`},complete(){i.style.height="",e.style.top=""}}),c.pipe(Ae()).subscribe(()=>{for(let l of P(".md-nav__link--active[href]",e)){if(!l.clientHeight)continue;let f=l.closest(".md-sidebar__scrollwrap");if(typeof f!="undefined"){let u=l.offsetTop-f.offsetTop,{height:d}=ce(f);f.scrollTo({top:u-d/2})}}}),ue(P("label[tabindex]",e)).pipe(ne(l=>h(l,"click").pipe(ve(se),m(()=>l),W(p)))).subscribe(l=>{let f=R(`[id="${l.htmlFor}"]`);R(`[aria-labelledby="${l.id}"]`).setAttribute("aria-expanded",`${f.checked}`)}),fs(e,r).pipe(w(l=>s.next(l)),_(()=>s.complete()),m(l=>$({ref:e},l)))})}function hi(e,t){if(typeof t!="undefined"){let r=`https://api.github.com/repos/${e}/${t}`;return st(je(`${r}/releases/latest`).pipe(de(()=>S),m(o=>({version:o.tag_name})),De({})),je(r).pipe(de(()=>S),m(o=>({stars:o.stargazers_count,forks:o.forks_count})),De({}))).pipe(m(([o,n])=>$($({},o),n)))}else{let r=`https://api.github.com/users/${e}`;return je(r).pipe(m(o=>({repositories:o.public_repos})),De({}))}}function bi(e,t){let r=`https://${e}/api/v4/projects/${encodeURIComponent(t)}`;return st(je(`${r}/releases/permalink/latest`).pipe(de(()=>S),m(({tag_name:o})=>({version:o})),De({})),je(r).pipe(de(()=>S),m(({star_count:o,forks_count:n})=>({stars:o,forks:n})),De({}))).pipe(m(([o,n])=>$($({},o),n)))}function vi(e){let t=e.match(/^.+github\.com\/([^/]+)\/?([^/]+)?/i);if(t){let[,r,o]=t;return hi(r,o)}if(t=e.match(/^.+?([^/]*gitlab[^/]+)\/(.+?)\/?$/i),t){let[,r,o]=t;return bi(r,o)}return S}var us;function ds(e){return us||(us=C(()=>{let t=__md_get("__source",sessionStorage);if(t)return I(t);if(ae("consent").length){let o=__md_get("__consent");if(!(o&&o.github))return S}return vi(e.href).pipe(w(o=>__md_set("__source",o,sessionStorage)))}).pipe(de(()=>S),b(t=>Object.keys(t).length>0),m(t=>({facts:t})),G(1)))}function gi(e){let t=R(":scope > :last-child",e);return C(()=>{let r=new g;return r.subscribe(({facts:o})=>{t.appendChild(_n(o)),t.classList.add("md-source__repository--active")}),ds(e).pipe(w(o=>r.next(o)),_(()=>r.complete()),m(o=>$({ref:e},o)))})}function hs(e,{viewport$:t,header$:r}){return ge(document.body).pipe(v(()=>mr(e,{header$:r,viewport$:t})),m(({offset:{y:o}})=>({hidden:o>=10})),ee("hidden"))}function yi(e,t){return C(()=>{let r=new g;return r.subscribe({next({hidden:o}){e.hidden=o},complete(){e.hidden=!1}}),(B("navigation.tabs.sticky")?I({hidden:!1}):hs(e,t)).pipe(w(o=>r.next(o)),_(()=>r.complete()),m(o=>$({ref:e},o)))})}function bs(e,{viewport$:t,header$:r}){let o=new Map,n=P(".md-nav__link",e);for(let s of n){let p=decodeURIComponent(s.hash.substring(1)),c=fe(`[id="${p}"]`);typeof c!="undefined"&&o.set(s,c)}let i=r.pipe(ee("height"),m(({height:s})=>{let p=Se("main"),c=R(":scope > :first-child",p);return s+.8*(c.offsetTop-p.offsetTop)}),pe());return ge(document.body).pipe(ee("height"),v(s=>C(()=>{let p=[];return I([...o].reduce((c,[l,f])=>{for(;p.length&&o.get(p[p.length-1]).tagName>=f.tagName;)p.pop();let u=f.offsetTop;for(;!u&&f.parentElement;)f=f.parentElement,u=f.offsetTop;let d=f.offsetParent;for(;d;d=d.offsetParent)u+=d.offsetTop;return c.set([...p=[...p,l]].reverse(),u)},new Map))}).pipe(m(p=>new Map([...p].sort(([,c],[,l])=>c-l))),He(i),v(([p,c])=>t.pipe(Fr(([l,f],{offset:{y:u},size:d})=>{let y=u+d.height>=Math.floor(s.height);for(;f.length;){let[,L]=f[0];if(L-c=u&&!y)f=[l.pop(),...f];else break}return[l,f]},[[],[...p]]),K((l,f)=>l[0]===f[0]&&l[1]===f[1])))))).pipe(m(([s,p])=>({prev:s.map(([c])=>c),next:p.map(([c])=>c)})),Q({prev:[],next:[]}),Be(2,1),m(([s,p])=>s.prev.length{let i=new g,a=i.pipe(Z(),ie(!0));if(i.subscribe(({prev:s,next:p})=>{for(let[c]of p)c.classList.remove("md-nav__link--passed"),c.classList.remove("md-nav__link--active");for(let[c,[l]]of s.entries())l.classList.add("md-nav__link--passed"),l.classList.toggle("md-nav__link--active",c===s.length-1)}),B("toc.follow")){let s=O(t.pipe(_e(1),m(()=>{})),t.pipe(_e(250),m(()=>"smooth")));i.pipe(b(({prev:p})=>p.length>0),He(o.pipe(ve(se))),re(s)).subscribe(([[{prev:p}],c])=>{let[l]=p[p.length-1];if(l.offsetHeight){let f=cr(l);if(typeof f!="undefined"){let u=l.offsetTop-f.offsetTop,{height:d}=ce(f);f.scrollTo({top:u-d/2,behavior:c})}}})}return B("navigation.tracking")&&t.pipe(W(a),ee("offset"),_e(250),Ce(1),W(n.pipe(Ce(1))),ct({delay:250}),re(i)).subscribe(([,{prev:s}])=>{let p=ye(),c=s[s.length-1];if(c&&c.length){let[l]=c,{hash:f}=new URL(l.href);p.hash!==f&&(p.hash=f,history.replaceState({},"",`${p}`))}else p.hash="",history.replaceState({},"",`${p}`)}),bs(e,{viewport$:t,header$:r}).pipe(w(s=>i.next(s)),_(()=>i.complete()),m(s=>$({ref:e},s)))})}function vs(e,{viewport$:t,main$:r,target$:o}){let n=t.pipe(m(({offset:{y:a}})=>a),Be(2,1),m(([a,s])=>a>s&&s>0),K()),i=r.pipe(m(({active:a})=>a));return z([i,n]).pipe(m(([a,s])=>!(a&&s)),K(),W(o.pipe(Ce(1))),ie(!0),ct({delay:250}),m(a=>({hidden:a})))}function Ei(e,{viewport$:t,header$:r,main$:o,target$:n}){let i=new g,a=i.pipe(Z(),ie(!0));return i.subscribe({next({hidden:s}){e.hidden=s,s?(e.setAttribute("tabindex","-1"),e.blur()):e.removeAttribute("tabindex")},complete(){e.style.top="",e.hidden=!0,e.removeAttribute("tabindex")}}),r.pipe(W(a),ee("height")).subscribe(({height:s})=>{e.style.top=`${s+16}px`}),h(e,"click").subscribe(s=>{s.preventDefault(),window.scrollTo({top:0})}),vs(e,{viewport$:t,main$:o,target$:n}).pipe(w(s=>i.next(s)),_(()=>i.complete()),m(s=>$({ref:e},s)))}function wi({document$:e,viewport$:t}){e.pipe(v(()=>P(".md-ellipsis")),ne(r=>tt(r).pipe(W(e.pipe(Ce(1))),b(o=>o),m(()=>r),Te(1))),b(r=>r.offsetWidth{let o=r.innerText,n=r.closest("a")||r;return n.title=o,B("content.tooltips")?mt(n,{viewport$:t}).pipe(W(e.pipe(Ce(1))),_(()=>n.removeAttribute("title"))):S})).subscribe(),B("content.tooltips")&&e.pipe(v(()=>P(".md-status")),ne(r=>mt(r,{viewport$:t}))).subscribe()}function Ti({document$:e,tablet$:t}){e.pipe(v(()=>P(".md-toggle--indeterminate")),w(r=>{r.indeterminate=!0,r.checked=!1}),ne(r=>h(r,"change").pipe(Dr(()=>r.classList.contains("md-toggle--indeterminate")),m(()=>r))),re(t)).subscribe(([r,o])=>{r.classList.remove("md-toggle--indeterminate"),o&&(r.checked=!1)})}function gs(){return/(iPad|iPhone|iPod)/.test(navigator.userAgent)}function Si({document$:e}){e.pipe(v(()=>P("[data-md-scrollfix]")),w(t=>t.removeAttribute("data-md-scrollfix")),b(gs),ne(t=>h(t,"touchstart").pipe(m(()=>t)))).subscribe(t=>{let r=t.scrollTop;r===0?t.scrollTop=1:r+t.offsetHeight===t.scrollHeight&&(t.scrollTop=r-1)})}function Oi({viewport$:e,tablet$:t}){z([ze("search"),t]).pipe(m(([r,o])=>r&&!o),v(r=>I(r).pipe(Ge(r?400:100))),re(e)).subscribe(([r,{offset:{y:o}}])=>{if(r)document.body.setAttribute("data-md-scrolllock",""),document.body.style.top=`-${o}px`;else{let n=-1*parseInt(document.body.style.top,10);document.body.removeAttribute("data-md-scrolllock"),document.body.style.top="",n&&window.scrollTo(0,n)}})}Object.entries||(Object.entries=function(e){let t=[];for(let r of Object.keys(e))t.push([r,e[r]]);return t});Object.values||(Object.values=function(e){let t=[];for(let r of Object.keys(e))t.push(e[r]);return t});typeof Element!="undefined"&&(Element.prototype.scrollTo||(Element.prototype.scrollTo=function(e,t){typeof e=="object"?(this.scrollLeft=e.left,this.scrollTop=e.top):(this.scrollLeft=e,this.scrollTop=t)}),Element.prototype.replaceWith||(Element.prototype.replaceWith=function(...e){let t=this.parentNode;if(t){e.length===0&&t.removeChild(this);for(let r=e.length-1;r>=0;r--){let o=e[r];typeof o=="string"?o=document.createTextNode(o):o.parentNode&&o.parentNode.removeChild(o),r?t.insertBefore(this.previousSibling,o):t.replaceChild(o,this)}}}));function ys(){return location.protocol==="file:"?Tt(`${new URL("search/search_index.js",eo.base)}`).pipe(m(()=>__index),G(1)):je(new URL("search/search_index.json",eo.base))}document.documentElement.classList.remove("no-js");document.documentElement.classList.add("js");var ot=Go(),Ut=sn(),Lt=ln(Ut),to=an(),Oe=gn(),hr=Pt("(min-width: 960px)"),Mi=Pt("(min-width: 1220px)"),_i=mn(),eo=xe(),Ai=document.forms.namedItem("search")?ys():Ye,ro=new g;Zn({alert$:ro});var oo=new g;B("navigation.instant")&&oi({location$:Ut,viewport$:Oe,progress$:oo}).subscribe(ot);var Li;((Li=eo.version)==null?void 0:Li.provider)==="mike"&&ci({document$:ot});O(Ut,Lt).pipe(Ge(125)).subscribe(()=>{Je("drawer",!1),Je("search",!1)});to.pipe(b(({mode:e})=>e==="global")).subscribe(e=>{switch(e.type){case"p":case",":let t=fe("link[rel=prev]");typeof t!="undefined"&<(t);break;case"n":case".":let r=fe("link[rel=next]");typeof r!="undefined"&<(r);break;case"Enter":let o=Ie();o instanceof HTMLLabelElement&&o.click()}});wi({viewport$:Oe,document$:ot});Ti({document$:ot,tablet$:hr});Si({document$:ot});Oi({viewport$:Oe,tablet$:hr});var rt=Kn(Se("header"),{viewport$:Oe}),Ft=ot.pipe(m(()=>Se("main")),v(e=>Gn(e,{viewport$:Oe,header$:rt})),G(1)),xs=O(...ae("consent").map(e=>En(e,{target$:Lt})),...ae("dialog").map(e=>qn(e,{alert$:ro})),...ae("palette").map(e=>Jn(e)),...ae("progress").map(e=>Xn(e,{progress$:oo})),...ae("search").map(e=>ui(e,{index$:Ai,keyboard$:to})),...ae("source").map(e=>gi(e))),Es=C(()=>O(...ae("announce").map(e=>xn(e)),...ae("content").map(e=>zn(e,{viewport$:Oe,target$:Lt,print$:_i})),...ae("content").map(e=>B("search.highlight")?di(e,{index$:Ai,location$:Ut}):S),...ae("header").map(e=>Yn(e,{viewport$:Oe,header$:rt,main$:Ft})),...ae("header-title").map(e=>Bn(e,{viewport$:Oe,header$:rt})),...ae("sidebar").map(e=>e.getAttribute("data-md-type")==="navigation"?Nr(Mi,()=>Zr(e,{viewport$:Oe,header$:rt,main$:Ft})):Nr(hr,()=>Zr(e,{viewport$:Oe,header$:rt,main$:Ft}))),...ae("tabs").map(e=>yi(e,{viewport$:Oe,header$:rt})),...ae("toc").map(e=>xi(e,{viewport$:Oe,header$:rt,main$:Ft,target$:Lt})),...ae("top").map(e=>Ei(e,{viewport$:Oe,header$:rt,main$:Ft,target$:Lt})))),Ci=ot.pipe(v(()=>Es),Re(xs),G(1));Ci.subscribe();window.document$=ot;window.location$=Ut;window.target$=Lt;window.keyboard$=to;window.viewport$=Oe;window.tablet$=hr;window.screen$=Mi;window.print$=_i;window.alert$=ro;window.progress$=oo;window.component$=Ci;})(); +//# sourceMappingURL=bundle.83f73b43.min.js.map + diff --git a/assets/javascripts/bundle.83f73b43.min.js.map b/assets/javascripts/bundle.83f73b43.min.js.map new file mode 100644 index 000000000..fe920b7d6 --- /dev/null +++ b/assets/javascripts/bundle.83f73b43.min.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["node_modules/focus-visible/dist/focus-visible.js", "node_modules/escape-html/index.js", "node_modules/clipboard/dist/clipboard.js", "src/templates/assets/javascripts/bundle.ts", "node_modules/tslib/tslib.es6.mjs", "node_modules/rxjs/src/internal/util/isFunction.ts", "node_modules/rxjs/src/internal/util/createErrorClass.ts", "node_modules/rxjs/src/internal/util/UnsubscriptionError.ts", "node_modules/rxjs/src/internal/util/arrRemove.ts", "node_modules/rxjs/src/internal/Subscription.ts", "node_modules/rxjs/src/internal/config.ts", "node_modules/rxjs/src/internal/scheduler/timeoutProvider.ts", "node_modules/rxjs/src/internal/util/reportUnhandledError.ts", "node_modules/rxjs/src/internal/util/noop.ts", "node_modules/rxjs/src/internal/NotificationFactories.ts", "node_modules/rxjs/src/internal/util/errorContext.ts", "node_modules/rxjs/src/internal/Subscriber.ts", "node_modules/rxjs/src/internal/symbol/observable.ts", "node_modules/rxjs/src/internal/util/identity.ts", "node_modules/rxjs/src/internal/util/pipe.ts", "node_modules/rxjs/src/internal/Observable.ts", "node_modules/rxjs/src/internal/util/lift.ts", "node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts", "node_modules/rxjs/src/internal/scheduler/animationFrameProvider.ts", "node_modules/rxjs/src/internal/util/ObjectUnsubscribedError.ts", "node_modules/rxjs/src/internal/Subject.ts", "node_modules/rxjs/src/internal/BehaviorSubject.ts", "node_modules/rxjs/src/internal/scheduler/dateTimestampProvider.ts", "node_modules/rxjs/src/internal/ReplaySubject.ts", "node_modules/rxjs/src/internal/scheduler/Action.ts", "node_modules/rxjs/src/internal/scheduler/intervalProvider.ts", "node_modules/rxjs/src/internal/scheduler/AsyncAction.ts", "node_modules/rxjs/src/internal/Scheduler.ts", "node_modules/rxjs/src/internal/scheduler/AsyncScheduler.ts", "node_modules/rxjs/src/internal/scheduler/async.ts", "node_modules/rxjs/src/internal/scheduler/QueueAction.ts", "node_modules/rxjs/src/internal/scheduler/QueueScheduler.ts", "node_modules/rxjs/src/internal/scheduler/queue.ts", "node_modules/rxjs/src/internal/scheduler/AnimationFrameAction.ts", "node_modules/rxjs/src/internal/scheduler/AnimationFrameScheduler.ts", "node_modules/rxjs/src/internal/scheduler/animationFrame.ts", "node_modules/rxjs/src/internal/observable/empty.ts", "node_modules/rxjs/src/internal/util/isScheduler.ts", "node_modules/rxjs/src/internal/util/args.ts", "node_modules/rxjs/src/internal/util/isArrayLike.ts", "node_modules/rxjs/src/internal/util/isPromise.ts", "node_modules/rxjs/src/internal/util/isInteropObservable.ts", "node_modules/rxjs/src/internal/util/isAsyncIterable.ts", "node_modules/rxjs/src/internal/util/throwUnobservableError.ts", "node_modules/rxjs/src/internal/symbol/iterator.ts", "node_modules/rxjs/src/internal/util/isIterable.ts", "node_modules/rxjs/src/internal/util/isReadableStreamLike.ts", "node_modules/rxjs/src/internal/observable/innerFrom.ts", "node_modules/rxjs/src/internal/util/executeSchedule.ts", "node_modules/rxjs/src/internal/operators/observeOn.ts", "node_modules/rxjs/src/internal/operators/subscribeOn.ts", "node_modules/rxjs/src/internal/scheduled/scheduleObservable.ts", "node_modules/rxjs/src/internal/scheduled/schedulePromise.ts", "node_modules/rxjs/src/internal/scheduled/scheduleArray.ts", "node_modules/rxjs/src/internal/scheduled/scheduleIterable.ts", "node_modules/rxjs/src/internal/scheduled/scheduleAsyncIterable.ts", "node_modules/rxjs/src/internal/scheduled/scheduleReadableStreamLike.ts", "node_modules/rxjs/src/internal/scheduled/scheduled.ts", "node_modules/rxjs/src/internal/observable/from.ts", "node_modules/rxjs/src/internal/observable/of.ts", "node_modules/rxjs/src/internal/observable/throwError.ts", "node_modules/rxjs/src/internal/util/EmptyError.ts", "node_modules/rxjs/src/internal/util/isDate.ts", "node_modules/rxjs/src/internal/operators/map.ts", "node_modules/rxjs/src/internal/util/mapOneOrManyArgs.ts", "node_modules/rxjs/src/internal/util/argsArgArrayOrObject.ts", "node_modules/rxjs/src/internal/util/createObject.ts", "node_modules/rxjs/src/internal/observable/combineLatest.ts", "node_modules/rxjs/src/internal/operators/mergeInternals.ts", "node_modules/rxjs/src/internal/operators/mergeMap.ts", "node_modules/rxjs/src/internal/operators/mergeAll.ts", "node_modules/rxjs/src/internal/operators/concatAll.ts", "node_modules/rxjs/src/internal/observable/concat.ts", "node_modules/rxjs/src/internal/observable/defer.ts", "node_modules/rxjs/src/internal/observable/fromEvent.ts", "node_modules/rxjs/src/internal/observable/fromEventPattern.ts", "node_modules/rxjs/src/internal/observable/timer.ts", "node_modules/rxjs/src/internal/observable/merge.ts", "node_modules/rxjs/src/internal/observable/never.ts", "node_modules/rxjs/src/internal/util/argsOrArgArray.ts", "node_modules/rxjs/src/internal/operators/filter.ts", "node_modules/rxjs/src/internal/observable/zip.ts", "node_modules/rxjs/src/internal/operators/audit.ts", "node_modules/rxjs/src/internal/operators/auditTime.ts", "node_modules/rxjs/src/internal/operators/bufferCount.ts", "node_modules/rxjs/src/internal/operators/catchError.ts", "node_modules/rxjs/src/internal/operators/scanInternals.ts", "node_modules/rxjs/src/internal/operators/combineLatest.ts", "node_modules/rxjs/src/internal/operators/combineLatestWith.ts", "node_modules/rxjs/src/internal/operators/debounce.ts", "node_modules/rxjs/src/internal/operators/debounceTime.ts", "node_modules/rxjs/src/internal/operators/defaultIfEmpty.ts", "node_modules/rxjs/src/internal/operators/take.ts", "node_modules/rxjs/src/internal/operators/ignoreElements.ts", "node_modules/rxjs/src/internal/operators/mapTo.ts", "node_modules/rxjs/src/internal/operators/delayWhen.ts", "node_modules/rxjs/src/internal/operators/delay.ts", "node_modules/rxjs/src/internal/operators/distinctUntilChanged.ts", "node_modules/rxjs/src/internal/operators/distinctUntilKeyChanged.ts", "node_modules/rxjs/src/internal/operators/throwIfEmpty.ts", "node_modules/rxjs/src/internal/operators/endWith.ts", "node_modules/rxjs/src/internal/operators/finalize.ts", "node_modules/rxjs/src/internal/operators/first.ts", "node_modules/rxjs/src/internal/operators/takeLast.ts", "node_modules/rxjs/src/internal/operators/merge.ts", "node_modules/rxjs/src/internal/operators/mergeWith.ts", "node_modules/rxjs/src/internal/operators/repeat.ts", "node_modules/rxjs/src/internal/operators/scan.ts", "node_modules/rxjs/src/internal/operators/share.ts", "node_modules/rxjs/src/internal/operators/shareReplay.ts", "node_modules/rxjs/src/internal/operators/skip.ts", "node_modules/rxjs/src/internal/operators/skipUntil.ts", "node_modules/rxjs/src/internal/operators/startWith.ts", "node_modules/rxjs/src/internal/operators/switchMap.ts", "node_modules/rxjs/src/internal/operators/takeUntil.ts", "node_modules/rxjs/src/internal/operators/takeWhile.ts", "node_modules/rxjs/src/internal/operators/tap.ts", "node_modules/rxjs/src/internal/operators/throttle.ts", "node_modules/rxjs/src/internal/operators/throttleTime.ts", "node_modules/rxjs/src/internal/operators/withLatestFrom.ts", "node_modules/rxjs/src/internal/operators/zip.ts", "node_modules/rxjs/src/internal/operators/zipWith.ts", "src/templates/assets/javascripts/browser/document/index.ts", "src/templates/assets/javascripts/browser/element/_/index.ts", "src/templates/assets/javascripts/browser/element/focus/index.ts", "src/templates/assets/javascripts/browser/element/hover/index.ts", "src/templates/assets/javascripts/utilities/h/index.ts", "src/templates/assets/javascripts/utilities/round/index.ts", "src/templates/assets/javascripts/browser/script/index.ts", "src/templates/assets/javascripts/browser/element/size/_/index.ts", "src/templates/assets/javascripts/browser/element/size/content/index.ts", "src/templates/assets/javascripts/browser/element/offset/_/index.ts", "src/templates/assets/javascripts/browser/element/offset/content/index.ts", "src/templates/assets/javascripts/browser/element/visibility/index.ts", "src/templates/assets/javascripts/browser/toggle/index.ts", "src/templates/assets/javascripts/browser/keyboard/index.ts", "src/templates/assets/javascripts/browser/location/_/index.ts", "src/templates/assets/javascripts/browser/location/hash/index.ts", "src/templates/assets/javascripts/browser/media/index.ts", "src/templates/assets/javascripts/browser/request/index.ts", "src/templates/assets/javascripts/browser/viewport/offset/index.ts", "src/templates/assets/javascripts/browser/viewport/size/index.ts", "src/templates/assets/javascripts/browser/viewport/_/index.ts", "src/templates/assets/javascripts/browser/viewport/at/index.ts", "src/templates/assets/javascripts/browser/worker/index.ts", "src/templates/assets/javascripts/_/index.ts", "src/templates/assets/javascripts/components/_/index.ts", "src/templates/assets/javascripts/components/announce/index.ts", "src/templates/assets/javascripts/components/consent/index.ts", "src/templates/assets/javascripts/templates/tooltip/index.tsx", "src/templates/assets/javascripts/templates/annotation/index.tsx", "src/templates/assets/javascripts/templates/clipboard/index.tsx", "src/templates/assets/javascripts/templates/search/index.tsx", "src/templates/assets/javascripts/templates/source/index.tsx", "src/templates/assets/javascripts/templates/tabbed/index.tsx", "src/templates/assets/javascripts/templates/table/index.tsx", "src/templates/assets/javascripts/templates/version/index.tsx", "src/templates/assets/javascripts/components/tooltip2/index.ts", "src/templates/assets/javascripts/components/content/annotation/_/index.ts", "src/templates/assets/javascripts/components/content/annotation/list/index.ts", "src/templates/assets/javascripts/components/content/annotation/block/index.ts", "src/templates/assets/javascripts/components/content/code/_/index.ts", "src/templates/assets/javascripts/components/content/details/index.ts", "src/templates/assets/javascripts/components/content/mermaid/index.css", "src/templates/assets/javascripts/components/content/mermaid/index.ts", "src/templates/assets/javascripts/components/content/table/index.ts", "src/templates/assets/javascripts/components/content/tabs/index.ts", "src/templates/assets/javascripts/components/content/_/index.ts", "src/templates/assets/javascripts/components/dialog/index.ts", "src/templates/assets/javascripts/components/tooltip/index.ts", "src/templates/assets/javascripts/components/header/_/index.ts", "src/templates/assets/javascripts/components/header/title/index.ts", "src/templates/assets/javascripts/components/main/index.ts", "src/templates/assets/javascripts/components/palette/index.ts", "src/templates/assets/javascripts/components/progress/index.ts", "src/templates/assets/javascripts/integrations/clipboard/index.ts", "src/templates/assets/javascripts/integrations/sitemap/index.ts", "src/templates/assets/javascripts/integrations/instant/index.ts", "src/templates/assets/javascripts/integrations/search/highlighter/index.ts", "src/templates/assets/javascripts/integrations/search/worker/message/index.ts", "src/templates/assets/javascripts/integrations/search/worker/_/index.ts", "src/templates/assets/javascripts/integrations/version/findurl/index.ts", "src/templates/assets/javascripts/integrations/version/index.ts", "src/templates/assets/javascripts/components/search/query/index.ts", "src/templates/assets/javascripts/components/search/result/index.ts", "src/templates/assets/javascripts/components/search/share/index.ts", "src/templates/assets/javascripts/components/search/suggest/index.ts", "src/templates/assets/javascripts/components/search/_/index.ts", "src/templates/assets/javascripts/components/search/highlight/index.ts", "src/templates/assets/javascripts/components/sidebar/index.ts", "src/templates/assets/javascripts/components/source/facts/github/index.ts", "src/templates/assets/javascripts/components/source/facts/gitlab/index.ts", "src/templates/assets/javascripts/components/source/facts/_/index.ts", "src/templates/assets/javascripts/components/source/_/index.ts", "src/templates/assets/javascripts/components/tabs/index.ts", "src/templates/assets/javascripts/components/toc/index.ts", "src/templates/assets/javascripts/components/top/index.ts", "src/templates/assets/javascripts/patches/ellipsis/index.ts", "src/templates/assets/javascripts/patches/indeterminate/index.ts", "src/templates/assets/javascripts/patches/scrollfix/index.ts", "src/templates/assets/javascripts/patches/scrolllock/index.ts", "src/templates/assets/javascripts/polyfills/index.ts"], + "sourcesContent": ["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (factory());\n}(this, (function () { 'use strict';\n\n /**\n * Applies the :focus-visible polyfill at the given scope.\n * A scope in this case is either the top-level Document or a Shadow Root.\n *\n * @param {(Document|ShadowRoot)} scope\n * @see https://github.com/WICG/focus-visible\n */\n function applyFocusVisiblePolyfill(scope) {\n var hadKeyboardEvent = true;\n var hadFocusVisibleRecently = false;\n var hadFocusVisibleRecentlyTimeout = null;\n\n var inputTypesAllowlist = {\n text: true,\n search: true,\n url: true,\n tel: true,\n email: true,\n password: true,\n number: true,\n date: true,\n month: true,\n week: true,\n time: true,\n datetime: true,\n 'datetime-local': true\n };\n\n /**\n * Helper function for legacy browsers and iframes which sometimes focus\n * elements like document, body, and non-interactive SVG.\n * @param {Element} el\n */\n function isValidFocusTarget(el) {\n if (\n el &&\n el !== document &&\n el.nodeName !== 'HTML' &&\n el.nodeName !== 'BODY' &&\n 'classList' in el &&\n 'contains' in el.classList\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Computes whether the given element should automatically trigger the\n * `focus-visible` class being added, i.e. whether it should always match\n * `:focus-visible` when focused.\n * @param {Element} el\n * @return {boolean}\n */\n function focusTriggersKeyboardModality(el) {\n var type = el.type;\n var tagName = el.tagName;\n\n if (tagName === 'INPUT' && inputTypesAllowlist[type] && !el.readOnly) {\n return true;\n }\n\n if (tagName === 'TEXTAREA' && !el.readOnly) {\n return true;\n }\n\n if (el.isContentEditable) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Add the `focus-visible` class to the given element if it was not added by\n * the author.\n * @param {Element} el\n */\n function addFocusVisibleClass(el) {\n if (el.classList.contains('focus-visible')) {\n return;\n }\n el.classList.add('focus-visible');\n el.setAttribute('data-focus-visible-added', '');\n }\n\n /**\n * Remove the `focus-visible` class from the given element if it was not\n * originally added by the author.\n * @param {Element} el\n */\n function removeFocusVisibleClass(el) {\n if (!el.hasAttribute('data-focus-visible-added')) {\n return;\n }\n el.classList.remove('focus-visible');\n el.removeAttribute('data-focus-visible-added');\n }\n\n /**\n * If the most recent user interaction was via the keyboard;\n * and the key press did not include a meta, alt/option, or control key;\n * then the modality is keyboard. Otherwise, the modality is not keyboard.\n * Apply `focus-visible` to any current active element and keep track\n * of our keyboard modality state with `hadKeyboardEvent`.\n * @param {KeyboardEvent} e\n */\n function onKeyDown(e) {\n if (e.metaKey || e.altKey || e.ctrlKey) {\n return;\n }\n\n if (isValidFocusTarget(scope.activeElement)) {\n addFocusVisibleClass(scope.activeElement);\n }\n\n hadKeyboardEvent = true;\n }\n\n /**\n * If at any point a user clicks with a pointing device, ensure that we change\n * the modality away from keyboard.\n * This avoids the situation where a user presses a key on an already focused\n * element, and then clicks on a different element, focusing it with a\n * pointing device, while we still think we're in keyboard modality.\n * @param {Event} e\n */\n function onPointerDown(e) {\n hadKeyboardEvent = false;\n }\n\n /**\n * On `focus`, add the `focus-visible` class to the target if:\n * - the target received focus as a result of keyboard navigation, or\n * - the event target is an element that will likely require interaction\n * via the keyboard (e.g. a text box)\n * @param {Event} e\n */\n function onFocus(e) {\n // Prevent IE from focusing the document or HTML element.\n if (!isValidFocusTarget(e.target)) {\n return;\n }\n\n if (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {\n addFocusVisibleClass(e.target);\n }\n }\n\n /**\n * On `blur`, remove the `focus-visible` class from the target.\n * @param {Event} e\n */\n function onBlur(e) {\n if (!isValidFocusTarget(e.target)) {\n return;\n }\n\n if (\n e.target.classList.contains('focus-visible') ||\n e.target.hasAttribute('data-focus-visible-added')\n ) {\n // To detect a tab/window switch, we look for a blur event followed\n // rapidly by a visibility change.\n // If we don't see a visibility change within 100ms, it's probably a\n // regular focus change.\n hadFocusVisibleRecently = true;\n window.clearTimeout(hadFocusVisibleRecentlyTimeout);\n hadFocusVisibleRecentlyTimeout = window.setTimeout(function() {\n hadFocusVisibleRecently = false;\n }, 100);\n removeFocusVisibleClass(e.target);\n }\n }\n\n /**\n * If the user changes tabs, keep track of whether or not the previously\n * focused element had .focus-visible.\n * @param {Event} e\n */\n function onVisibilityChange(e) {\n if (document.visibilityState === 'hidden') {\n // If the tab becomes active again, the browser will handle calling focus\n // on the element (Safari actually calls it twice).\n // If this tab change caused a blur on an element with focus-visible,\n // re-apply the class when the user switches back to the tab.\n if (hadFocusVisibleRecently) {\n hadKeyboardEvent = true;\n }\n addInitialPointerMoveListeners();\n }\n }\n\n /**\n * Add a group of listeners to detect usage of any pointing devices.\n * These listeners will be added when the polyfill first loads, and anytime\n * the window is blurred, so that they are active when the window regains\n * focus.\n */\n function addInitialPointerMoveListeners() {\n document.addEventListener('mousemove', onInitialPointerMove);\n document.addEventListener('mousedown', onInitialPointerMove);\n document.addEventListener('mouseup', onInitialPointerMove);\n document.addEventListener('pointermove', onInitialPointerMove);\n document.addEventListener('pointerdown', onInitialPointerMove);\n document.addEventListener('pointerup', onInitialPointerMove);\n document.addEventListener('touchmove', onInitialPointerMove);\n document.addEventListener('touchstart', onInitialPointerMove);\n document.addEventListener('touchend', onInitialPointerMove);\n }\n\n function removeInitialPointerMoveListeners() {\n document.removeEventListener('mousemove', onInitialPointerMove);\n document.removeEventListener('mousedown', onInitialPointerMove);\n document.removeEventListener('mouseup', onInitialPointerMove);\n document.removeEventListener('pointermove', onInitialPointerMove);\n document.removeEventListener('pointerdown', onInitialPointerMove);\n document.removeEventListener('pointerup', onInitialPointerMove);\n document.removeEventListener('touchmove', onInitialPointerMove);\n document.removeEventListener('touchstart', onInitialPointerMove);\n document.removeEventListener('touchend', onInitialPointerMove);\n }\n\n /**\n * When the polfyill first loads, assume the user is in keyboard modality.\n * If any event is received from a pointing device (e.g. mouse, pointer,\n * touch), turn off keyboard modality.\n * This accounts for situations where focus enters the page from the URL bar.\n * @param {Event} e\n */\n function onInitialPointerMove(e) {\n // Work around a Safari quirk that fires a mousemove on whenever the\n // window blurs, even if you're tabbing out of the page. \u00AF\\_(\u30C4)_/\u00AF\n if (e.target.nodeName && e.target.nodeName.toLowerCase() === 'html') {\n return;\n }\n\n hadKeyboardEvent = false;\n removeInitialPointerMoveListeners();\n }\n\n // For some kinds of state, we are interested in changes at the global scope\n // only. For example, global pointer input, global key presses and global\n // visibility change should affect the state at every scope:\n document.addEventListener('keydown', onKeyDown, true);\n document.addEventListener('mousedown', onPointerDown, true);\n document.addEventListener('pointerdown', onPointerDown, true);\n document.addEventListener('touchstart', onPointerDown, true);\n document.addEventListener('visibilitychange', onVisibilityChange, true);\n\n addInitialPointerMoveListeners();\n\n // For focus and blur, we specifically care about state changes in the local\n // scope. This is because focus / blur events that originate from within a\n // shadow root are not re-dispatched from the host element if it was already\n // the active element in its own scope:\n scope.addEventListener('focus', onFocus, true);\n scope.addEventListener('blur', onBlur, true);\n\n // We detect that a node is a ShadowRoot by ensuring that it is a\n // DocumentFragment and also has a host property. This check covers native\n // implementation and polyfill implementation transparently. If we only cared\n // about the native implementation, we could just check if the scope was\n // an instance of a ShadowRoot.\n if (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {\n // Since a ShadowRoot is a special kind of DocumentFragment, it does not\n // have a root element to add a class to. So, we add this attribute to the\n // host element instead:\n scope.host.setAttribute('data-js-focus-visible', '');\n } else if (scope.nodeType === Node.DOCUMENT_NODE) {\n document.documentElement.classList.add('js-focus-visible');\n document.documentElement.setAttribute('data-js-focus-visible', '');\n }\n }\n\n // It is important to wrap all references to global window and document in\n // these checks to support server-side rendering use cases\n // @see https://github.com/WICG/focus-visible/issues/199\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n // Make the polyfill helper globally available. This can be used as a signal\n // to interested libraries that wish to coordinate with the polyfill for e.g.,\n // applying the polyfill to a shadow root:\n window.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;\n\n // Notify interested libraries of the polyfill's presence, in case the\n // polyfill was loaded lazily:\n var event;\n\n try {\n event = new CustomEvent('focus-visible-polyfill-ready');\n } catch (error) {\n // IE11 does not support using CustomEvent as a constructor directly:\n event = document.createEvent('CustomEvent');\n event.initCustomEvent('focus-visible-polyfill-ready', false, false, {});\n }\n\n window.dispatchEvent(event);\n }\n\n if (typeof document !== 'undefined') {\n // Apply the polyfill to the global document, so that no JavaScript\n // coordination is required to use the polyfill in the top-level document:\n applyFocusVisiblePolyfill(document);\n }\n\n})));\n", "/*!\n * escape-html\n * Copyright(c) 2012-2013 TJ Holowaychuk\n * Copyright(c) 2015 Andreas Lubbe\n * Copyright(c) 2015 Tiancheng \"Timothy\" Gu\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module variables.\n * @private\n */\n\nvar matchHtmlRegExp = /[\"'&<>]/;\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = escapeHtml;\n\n/**\n * Escape special characters in the given string of html.\n *\n * @param {string} string The string to escape for inserting into HTML\n * @return {string}\n * @public\n */\n\nfunction escapeHtml(string) {\n var str = '' + string;\n var match = matchHtmlRegExp.exec(str);\n\n if (!match) {\n return str;\n }\n\n var escape;\n var html = '';\n var index = 0;\n var lastIndex = 0;\n\n for (index = match.index; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"';\n break;\n case 38: // &\n escape = '&';\n break;\n case 39: // '\n escape = ''';\n break;\n case 60: // <\n escape = '<';\n break;\n case 62: // >\n escape = '>';\n break;\n default:\n continue;\n }\n\n if (lastIndex !== index) {\n html += str.substring(lastIndex, index);\n }\n\n lastIndex = index + 1;\n html += escape;\n }\n\n return lastIndex !== index\n ? html + str.substring(lastIndex, index)\n : html;\n}\n", "/*!\n * clipboard.js v2.0.11\n * https://clipboardjs.com/\n *\n * Licensed MIT \u00A9 Zeno Rocha\n */\n(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ClipboardJS\"] = factory();\n\telse\n\t\troot[\"ClipboardJS\"] = factory();\n})(this, function() {\nreturn /******/ (function() { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 686:\n/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n\n// EXPORTS\n__webpack_require__.d(__webpack_exports__, {\n \"default\": function() { return /* binding */ clipboard; }\n});\n\n// EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js\nvar tiny_emitter = __webpack_require__(279);\nvar tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter);\n// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js\nvar listen = __webpack_require__(370);\nvar listen_default = /*#__PURE__*/__webpack_require__.n(listen);\n// EXTERNAL MODULE: ./node_modules/select/src/select.js\nvar src_select = __webpack_require__(817);\nvar select_default = /*#__PURE__*/__webpack_require__.n(src_select);\n;// CONCATENATED MODULE: ./src/common/command.js\n/**\n * Executes a given operation type.\n * @param {String} type\n * @return {Boolean}\n */\nfunction command(type) {\n try {\n return document.execCommand(type);\n } catch (err) {\n return false;\n }\n}\n;// CONCATENATED MODULE: ./src/actions/cut.js\n\n\n/**\n * Cut action wrapper.\n * @param {String|HTMLElement} target\n * @return {String}\n */\n\nvar ClipboardActionCut = function ClipboardActionCut(target) {\n var selectedText = select_default()(target);\n command('cut');\n return selectedText;\n};\n\n/* harmony default export */ var actions_cut = (ClipboardActionCut);\n;// CONCATENATED MODULE: ./src/common/create-fake-element.js\n/**\n * Creates a fake textarea element with a value.\n * @param {String} value\n * @return {HTMLElement}\n */\nfunction createFakeElement(value) {\n var isRTL = document.documentElement.getAttribute('dir') === 'rtl';\n var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS\n\n fakeElement.style.fontSize = '12pt'; // Reset box model\n\n fakeElement.style.border = '0';\n fakeElement.style.padding = '0';\n fakeElement.style.margin = '0'; // Move element out of screen horizontally\n\n fakeElement.style.position = 'absolute';\n fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically\n\n var yPosition = window.pageYOffset || document.documentElement.scrollTop;\n fakeElement.style.top = \"\".concat(yPosition, \"px\");\n fakeElement.setAttribute('readonly', '');\n fakeElement.value = value;\n return fakeElement;\n}\n;// CONCATENATED MODULE: ./src/actions/copy.js\n\n\n\n/**\n * Create fake copy action wrapper using a fake element.\n * @param {String} target\n * @param {Object} options\n * @return {String}\n */\n\nvar fakeCopyAction = function fakeCopyAction(value, options) {\n var fakeElement = createFakeElement(value);\n options.container.appendChild(fakeElement);\n var selectedText = select_default()(fakeElement);\n command('copy');\n fakeElement.remove();\n return selectedText;\n};\n/**\n * Copy action wrapper.\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @return {String}\n */\n\n\nvar ClipboardActionCopy = function ClipboardActionCopy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n var selectedText = '';\n\n if (typeof target === 'string') {\n selectedText = fakeCopyAction(target, options);\n } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {\n // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n selectedText = fakeCopyAction(target.value, options);\n } else {\n selectedText = select_default()(target);\n command('copy');\n }\n\n return selectedText;\n};\n\n/* harmony default export */ var actions_copy = (ClipboardActionCopy);\n;// CONCATENATED MODULE: ./src/actions/default.js\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n\n\n/**\n * Inner function which performs selection from either `text` or `target`\n * properties and then executes copy or cut operations.\n * @param {Object} options\n */\n\nvar ClipboardActionDefault = function ClipboardActionDefault() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n // Defines base properties passed from constructor.\n var _options$action = options.action,\n action = _options$action === void 0 ? 'copy' : _options$action,\n container = options.container,\n target = options.target,\n text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.\n\n if (action !== 'copy' && action !== 'cut') {\n throw new Error('Invalid \"action\" value, use either \"copy\" or \"cut\"');\n } // Sets the `target` property using an element that will be have its content copied.\n\n\n if (target !== undefined) {\n if (target && _typeof(target) === 'object' && target.nodeType === 1) {\n if (action === 'copy' && target.hasAttribute('disabled')) {\n throw new Error('Invalid \"target\" attribute. Please use \"readonly\" instead of \"disabled\" attribute');\n }\n\n if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {\n throw new Error('Invalid \"target\" attribute. You can\\'t cut text from elements with \"readonly\" or \"disabled\" attributes');\n }\n } else {\n throw new Error('Invalid \"target\" value, use a valid Element');\n }\n } // Define selection strategy based on `text` property.\n\n\n if (text) {\n return actions_copy(text, {\n container: container\n });\n } // Defines which selection strategy based on `target` property.\n\n\n if (target) {\n return action === 'cut' ? actions_cut(target) : actions_copy(target, {\n container: container\n });\n }\n};\n\n/* harmony default export */ var actions_default = (ClipboardActionDefault);\n;// CONCATENATED MODULE: ./src/clipboard.js\nfunction clipboard_typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return clipboard_typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\n\n/**\n * Helper function to retrieve attribute value.\n * @param {String} suffix\n * @param {Element} element\n */\n\nfunction getAttributeValue(suffix, element) {\n var attribute = \"data-clipboard-\".concat(suffix);\n\n if (!element.hasAttribute(attribute)) {\n return;\n }\n\n return element.getAttribute(attribute);\n}\n/**\n * Base class which takes one or more elements, adds event listeners to them,\n * and instantiates a new `ClipboardAction` on each click.\n */\n\n\nvar Clipboard = /*#__PURE__*/function (_Emitter) {\n _inherits(Clipboard, _Emitter);\n\n var _super = _createSuper(Clipboard);\n\n /**\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n * @param {Object} options\n */\n function Clipboard(trigger, options) {\n var _this;\n\n _classCallCheck(this, Clipboard);\n\n _this = _super.call(this);\n\n _this.resolveOptions(options);\n\n _this.listenClick(trigger);\n\n return _this;\n }\n /**\n * Defines if attributes would be resolved using internal setter functions\n * or custom functions that were passed in the constructor.\n * @param {Object} options\n */\n\n\n _createClass(Clipboard, [{\n key: \"resolveOptions\",\n value: function resolveOptions() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n this.action = typeof options.action === 'function' ? options.action : this.defaultAction;\n this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;\n this.text = typeof options.text === 'function' ? options.text : this.defaultText;\n this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;\n }\n /**\n * Adds a click event listener to the passed trigger.\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n */\n\n }, {\n key: \"listenClick\",\n value: function listenClick(trigger) {\n var _this2 = this;\n\n this.listener = listen_default()(trigger, 'click', function (e) {\n return _this2.onClick(e);\n });\n }\n /**\n * Defines a new `ClipboardAction` on each click event.\n * @param {Event} e\n */\n\n }, {\n key: \"onClick\",\n value: function onClick(e) {\n var trigger = e.delegateTarget || e.currentTarget;\n var action = this.action(trigger) || 'copy';\n var text = actions_default({\n action: action,\n container: this.container,\n target: this.target(trigger),\n text: this.text(trigger)\n }); // Fires an event based on the copy operation result.\n\n this.emit(text ? 'success' : 'error', {\n action: action,\n text: text,\n trigger: trigger,\n clearSelection: function clearSelection() {\n if (trigger) {\n trigger.focus();\n }\n\n window.getSelection().removeAllRanges();\n }\n });\n }\n /**\n * Default `action` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultAction\",\n value: function defaultAction(trigger) {\n return getAttributeValue('action', trigger);\n }\n /**\n * Default `target` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultTarget\",\n value: function defaultTarget(trigger) {\n var selector = getAttributeValue('target', trigger);\n\n if (selector) {\n return document.querySelector(selector);\n }\n }\n /**\n * Allow fire programmatically a copy action\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @returns Text copied.\n */\n\n }, {\n key: \"defaultText\",\n\n /**\n * Default `text` lookup function.\n * @param {Element} trigger\n */\n value: function defaultText(trigger) {\n return getAttributeValue('text', trigger);\n }\n /**\n * Destroy lifecycle.\n */\n\n }, {\n key: \"destroy\",\n value: function destroy() {\n this.listener.destroy();\n }\n }], [{\n key: \"copy\",\n value: function copy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n return actions_copy(target, options);\n }\n /**\n * Allow fire programmatically a cut action\n * @param {String|HTMLElement} target\n * @returns Text cutted.\n */\n\n }, {\n key: \"cut\",\n value: function cut(target) {\n return actions_cut(target);\n }\n /**\n * Returns the support of the given action, or all actions if no action is\n * given.\n * @param {String} [action]\n */\n\n }, {\n key: \"isSupported\",\n value: function isSupported() {\n var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];\n var actions = typeof action === 'string' ? [action] : action;\n var support = !!document.queryCommandSupported;\n actions.forEach(function (action) {\n support = support && !!document.queryCommandSupported(action);\n });\n return support;\n }\n }]);\n\n return Clipboard;\n}((tiny_emitter_default()));\n\n/* harmony default export */ var clipboard = (Clipboard);\n\n/***/ }),\n\n/***/ 828:\n/***/ (function(module) {\n\nvar DOCUMENT_NODE_TYPE = 9;\n\n/**\n * A polyfill for Element.matches()\n */\nif (typeof Element !== 'undefined' && !Element.prototype.matches) {\n var proto = Element.prototype;\n\n proto.matches = proto.matchesSelector ||\n proto.mozMatchesSelector ||\n proto.msMatchesSelector ||\n proto.oMatchesSelector ||\n proto.webkitMatchesSelector;\n}\n\n/**\n * Finds the closest parent that matches a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @return {Function}\n */\nfunction closest (element, selector) {\n while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {\n if (typeof element.matches === 'function' &&\n element.matches(selector)) {\n return element;\n }\n element = element.parentNode;\n }\n}\n\nmodule.exports = closest;\n\n\n/***/ }),\n\n/***/ 438:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar closest = __webpack_require__(828);\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction _delegate(element, selector, type, callback, useCapture) {\n var listenerFn = listener.apply(this, arguments);\n\n element.addEventListener(type, listenerFn, useCapture);\n\n return {\n destroy: function() {\n element.removeEventListener(type, listenerFn, useCapture);\n }\n }\n}\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element|String|Array} [elements]\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction delegate(elements, selector, type, callback, useCapture) {\n // Handle the regular Element usage\n if (typeof elements.addEventListener === 'function') {\n return _delegate.apply(null, arguments);\n }\n\n // Handle Element-less usage, it defaults to global delegation\n if (typeof type === 'function') {\n // Use `document` as the first parameter, then apply arguments\n // This is a short way to .unshift `arguments` without running into deoptimizations\n return _delegate.bind(null, document).apply(null, arguments);\n }\n\n // Handle Selector-based usage\n if (typeof elements === 'string') {\n elements = document.querySelectorAll(elements);\n }\n\n // Handle Array-like based usage\n return Array.prototype.map.call(elements, function (element) {\n return _delegate(element, selector, type, callback, useCapture);\n });\n}\n\n/**\n * Finds closest match and invokes callback.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Function}\n */\nfunction listener(element, selector, type, callback) {\n return function(e) {\n e.delegateTarget = closest(e.target, selector);\n\n if (e.delegateTarget) {\n callback.call(element, e);\n }\n }\n}\n\nmodule.exports = delegate;\n\n\n/***/ }),\n\n/***/ 879:\n/***/ (function(__unused_webpack_module, exports) {\n\n/**\n * Check if argument is a HTML element.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.node = function(value) {\n return value !== undefined\n && value instanceof HTMLElement\n && value.nodeType === 1;\n};\n\n/**\n * Check if argument is a list of HTML elements.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.nodeList = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return value !== undefined\n && (type === '[object NodeList]' || type === '[object HTMLCollection]')\n && ('length' in value)\n && (value.length === 0 || exports.node(value[0]));\n};\n\n/**\n * Check if argument is a string.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.string = function(value) {\n return typeof value === 'string'\n || value instanceof String;\n};\n\n/**\n * Check if argument is a function.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.fn = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return type === '[object Function]';\n};\n\n\n/***/ }),\n\n/***/ 370:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar is = __webpack_require__(879);\nvar delegate = __webpack_require__(438);\n\n/**\n * Validates all params and calls the right\n * listener function based on its target type.\n *\n * @param {String|HTMLElement|HTMLCollection|NodeList} target\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listen(target, type, callback) {\n if (!target && !type && !callback) {\n throw new Error('Missing required arguments');\n }\n\n if (!is.string(type)) {\n throw new TypeError('Second argument must be a String');\n }\n\n if (!is.fn(callback)) {\n throw new TypeError('Third argument must be a Function');\n }\n\n if (is.node(target)) {\n return listenNode(target, type, callback);\n }\n else if (is.nodeList(target)) {\n return listenNodeList(target, type, callback);\n }\n else if (is.string(target)) {\n return listenSelector(target, type, callback);\n }\n else {\n throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');\n }\n}\n\n/**\n * Adds an event listener to a HTML element\n * and returns a remove listener function.\n *\n * @param {HTMLElement} node\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNode(node, type, callback) {\n node.addEventListener(type, callback);\n\n return {\n destroy: function() {\n node.removeEventListener(type, callback);\n }\n }\n}\n\n/**\n * Add an event listener to a list of HTML elements\n * and returns a remove listener function.\n *\n * @param {NodeList|HTMLCollection} nodeList\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNodeList(nodeList, type, callback) {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.addEventListener(type, callback);\n });\n\n return {\n destroy: function() {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.removeEventListener(type, callback);\n });\n }\n }\n}\n\n/**\n * Add an event listener to a selector\n * and returns a remove listener function.\n *\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenSelector(selector, type, callback) {\n return delegate(document.body, selector, type, callback);\n}\n\nmodule.exports = listen;\n\n\n/***/ }),\n\n/***/ 817:\n/***/ (function(module) {\n\nfunction select(element) {\n var selectedText;\n\n if (element.nodeName === 'SELECT') {\n element.focus();\n\n selectedText = element.value;\n }\n else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {\n var isReadOnly = element.hasAttribute('readonly');\n\n if (!isReadOnly) {\n element.setAttribute('readonly', '');\n }\n\n element.select();\n element.setSelectionRange(0, element.value.length);\n\n if (!isReadOnly) {\n element.removeAttribute('readonly');\n }\n\n selectedText = element.value;\n }\n else {\n if (element.hasAttribute('contenteditable')) {\n element.focus();\n }\n\n var selection = window.getSelection();\n var range = document.createRange();\n\n range.selectNodeContents(element);\n selection.removeAllRanges();\n selection.addRange(range);\n\n selectedText = selection.toString();\n }\n\n return selectedText;\n}\n\nmodule.exports = select;\n\n\n/***/ }),\n\n/***/ 279:\n/***/ (function(module) {\n\nfunction E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = this;\n function listener () {\n self.off(name, listener);\n callback.apply(ctx, arguments);\n };\n\n listener._ = callback\n return this.on(name, listener, ctx);\n },\n\n emit: function (name) {\n var data = [].slice.call(arguments, 1);\n var evtArr = ((this.e || (this.e = {}))[name] || []).slice();\n var i = 0;\n var len = evtArr.length;\n\n for (i; i < len; i++) {\n evtArr[i].fn.apply(evtArr[i].ctx, data);\n }\n\n return this;\n },\n\n off: function (name, callback) {\n var e = this.e || (this.e = {});\n var evts = e[name];\n var liveEvents = [];\n\n if (evts && callback) {\n for (var i = 0, len = evts.length; i < len; i++) {\n if (evts[i].fn !== callback && evts[i].fn._ !== callback)\n liveEvents.push(evts[i]);\n }\n }\n\n // Remove event from queue to prevent memory leak\n // Suggested by https://github.com/lazd\n // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910\n\n (liveEvents.length)\n ? e[name] = liveEvents\n : delete e[name];\n\n return this;\n }\n};\n\nmodule.exports = E;\nmodule.exports.TinyEmitter = E;\n\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(__webpack_module_cache__[moduleId]) {\n/******/ \t\t\treturn __webpack_module_cache__[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t!function() {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = function(module) {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\tfunction() { return module['default']; } :\n/******/ \t\t\t\tfunction() { return module; };\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t!function() {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = function(exports, definition) {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t!function() {\n/******/ \t\t__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }\n/******/ \t}();\n/******/ \t\n/************************************************************************/\n/******/ \t// module exports must be returned from runtime so entry inlining is disabled\n/******/ \t// startup\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(686);\n/******/ })()\n.default;\n});", "/*\n * Copyright (c) 2016-2024 Martin Donath \n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\nimport \"focus-visible\"\n\nimport {\n EMPTY,\n NEVER,\n Observable,\n Subject,\n defer,\n delay,\n filter,\n map,\n merge,\n mergeWith,\n shareReplay,\n switchMap\n} from \"rxjs\"\n\nimport { configuration, feature } from \"./_\"\nimport {\n at,\n getActiveElement,\n getOptionalElement,\n requestJSON,\n setLocation,\n setToggle,\n watchDocument,\n watchKeyboard,\n watchLocation,\n watchLocationTarget,\n watchMedia,\n watchPrint,\n watchScript,\n watchViewport\n} from \"./browser\"\nimport {\n getComponentElement,\n getComponentElements,\n mountAnnounce,\n mountBackToTop,\n mountConsent,\n mountContent,\n mountDialog,\n mountHeader,\n mountHeaderTitle,\n mountPalette,\n mountProgress,\n mountSearch,\n mountSearchHiglight,\n mountSidebar,\n mountSource,\n mountTableOfContents,\n mountTabs,\n watchHeader,\n watchMain\n} from \"./components\"\nimport {\n SearchIndex,\n setupClipboardJS,\n setupInstantNavigation,\n setupVersionSelector\n} from \"./integrations\"\nimport {\n patchEllipsis,\n patchIndeterminate,\n patchScrollfix,\n patchScrolllock\n} from \"./patches\"\nimport \"./polyfills\"\n\n/* ----------------------------------------------------------------------------\n * Functions - @todo refactor\n * ------------------------------------------------------------------------- */\n\n/**\n * Fetch search index\n *\n * @returns Search index observable\n */\nfunction fetchSearchIndex(): Observable {\n if (location.protocol === \"file:\") {\n return watchScript(\n `${new URL(\"search/search_index.js\", config.base)}`\n )\n .pipe(\n // @ts-ignore - @todo fix typings\n map(() => __index),\n shareReplay(1)\n )\n } else {\n return requestJSON(\n new URL(\"search/search_index.json\", config.base)\n )\n }\n}\n\n/* ----------------------------------------------------------------------------\n * Application\n * ------------------------------------------------------------------------- */\n\n/* Yay, JavaScript is available */\ndocument.documentElement.classList.remove(\"no-js\")\ndocument.documentElement.classList.add(\"js\")\n\n/* Set up navigation observables and subjects */\nconst document$ = watchDocument()\nconst location$ = watchLocation()\nconst target$ = watchLocationTarget(location$)\nconst keyboard$ = watchKeyboard()\n\n/* Set up media observables */\nconst viewport$ = watchViewport()\nconst tablet$ = watchMedia(\"(min-width: 960px)\")\nconst screen$ = watchMedia(\"(min-width: 1220px)\")\nconst print$ = watchPrint()\n\n/* Retrieve search index, if search is enabled */\nconst config = configuration()\nconst index$ = document.forms.namedItem(\"search\")\n ? fetchSearchIndex()\n : NEVER\n\n/* Set up Clipboard.js integration */\nconst alert$ = new Subject()\nsetupClipboardJS({ alert$ })\n\n/* Set up progress indicator */\nconst progress$ = new Subject()\n\n/* Set up instant navigation, if enabled */\nif (feature(\"navigation.instant\"))\n setupInstantNavigation({ location$, viewport$, progress$ })\n .subscribe(document$)\n\n/* Set up version selector */\nif (config.version?.provider === \"mike\")\n setupVersionSelector({ document$ })\n\n/* Always close drawer and search on navigation */\nmerge(location$, target$)\n .pipe(\n delay(125)\n )\n .subscribe(() => {\n setToggle(\"drawer\", false)\n setToggle(\"search\", false)\n })\n\n/* Set up global keyboard handlers */\nkeyboard$\n .pipe(\n filter(({ mode }) => mode === \"global\")\n )\n .subscribe(key => {\n switch (key.type) {\n\n /* Go to previous page */\n case \"p\":\n case \",\":\n const prev = getOptionalElement(\"link[rel=prev]\")\n if (typeof prev !== \"undefined\")\n setLocation(prev)\n break\n\n /* Go to next page */\n case \"n\":\n case \".\":\n const next = getOptionalElement(\"link[rel=next]\")\n if (typeof next !== \"undefined\")\n setLocation(next)\n break\n\n /* Expand navigation, see https://bit.ly/3ZjG5io */\n case \"Enter\":\n const active = getActiveElement()\n if (active instanceof HTMLLabelElement)\n active.click()\n }\n })\n\n/* Set up patches */\npatchEllipsis({ viewport$, document$ })\npatchIndeterminate({ document$, tablet$ })\npatchScrollfix({ document$ })\npatchScrolllock({ viewport$, tablet$ })\n\n/* Set up header and main area observable */\nconst header$ = watchHeader(getComponentElement(\"header\"), { viewport$ })\nconst main$ = document$\n .pipe(\n map(() => getComponentElement(\"main\")),\n switchMap(el => watchMain(el, { viewport$, header$ })),\n shareReplay(1)\n )\n\n/* Set up control component observables */\nconst control$ = merge(\n\n /* Consent */\n ...getComponentElements(\"consent\")\n .map(el => mountConsent(el, { target$ })),\n\n /* Dialog */\n ...getComponentElements(\"dialog\")\n .map(el => mountDialog(el, { alert$ })),\n\n /* Color palette */\n ...getComponentElements(\"palette\")\n .map(el => mountPalette(el)),\n\n /* Progress bar */\n ...getComponentElements(\"progress\")\n .map(el => mountProgress(el, { progress$ })),\n\n /* Search */\n ...getComponentElements(\"search\")\n .map(el => mountSearch(el, { index$, keyboard$ })),\n\n /* Repository information */\n ...getComponentElements(\"source\")\n .map(el => mountSource(el))\n)\n\n/* Set up content component observables */\nconst content$ = defer(() => merge(\n\n /* Announcement bar */\n ...getComponentElements(\"announce\")\n .map(el => mountAnnounce(el)),\n\n /* Content */\n ...getComponentElements(\"content\")\n .map(el => mountContent(el, { viewport$, target$, print$ })),\n\n /* Search highlighting */\n ...getComponentElements(\"content\")\n .map(el => feature(\"search.highlight\")\n ? mountSearchHiglight(el, { index$, location$ })\n : EMPTY\n ),\n\n /* Header */\n ...getComponentElements(\"header\")\n .map(el => mountHeader(el, { viewport$, header$, main$ })),\n\n /* Header title */\n ...getComponentElements(\"header-title\")\n .map(el => mountHeaderTitle(el, { viewport$, header$ })),\n\n /* Sidebar */\n ...getComponentElements(\"sidebar\")\n .map(el => el.getAttribute(\"data-md-type\") === \"navigation\"\n ? at(screen$, () => mountSidebar(el, { viewport$, header$, main$ }))\n : at(tablet$, () => mountSidebar(el, { viewport$, header$, main$ }))\n ),\n\n /* Navigation tabs */\n ...getComponentElements(\"tabs\")\n .map(el => mountTabs(el, { viewport$, header$ })),\n\n /* Table of contents */\n ...getComponentElements(\"toc\")\n .map(el => mountTableOfContents(el, {\n viewport$, header$, main$, target$\n })),\n\n /* Back-to-top button */\n ...getComponentElements(\"top\")\n .map(el => mountBackToTop(el, { viewport$, header$, main$, target$ }))\n))\n\n/* Set up component observables */\nconst component$ = document$\n .pipe(\n switchMap(() => content$),\n mergeWith(control$),\n shareReplay(1)\n )\n\n/* Subscribe to all components */\ncomponent$.subscribe()\n\n/* ----------------------------------------------------------------------------\n * Exports\n * ------------------------------------------------------------------------- */\n\nwindow.document$ = document$ /* Document observable */\nwindow.location$ = location$ /* Location subject */\nwindow.target$ = target$ /* Location target observable */\nwindow.keyboard$ = keyboard$ /* Keyboard observable */\nwindow.viewport$ = viewport$ /* Viewport observable */\nwindow.tablet$ = tablet$ /* Media tablet observable */\nwindow.screen$ = screen$ /* Media screen observable */\nwindow.print$ = print$ /* Media print observable */\nwindow.alert$ = alert$ /* Alert subject */\nwindow.progress$ = progress$ /* Progress indicator subject */\nwindow.component$ = component$ /* Component observable */\n", "/******************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\n/* global Reflect, Promise, SuppressedError, Symbol, Iterator */\n\nvar extendStatics = function(d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n};\n\nexport function __extends(d, b) {\n if (typeof b !== \"function\" && b !== null)\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n}\n\nexport var __assign = function() {\n __assign = Object.assign || function __assign(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\n }\n return t;\n }\n return __assign.apply(this, arguments);\n}\n\nexport function __rest(s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n}\n\nexport function __decorate(decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n}\n\nexport function __param(paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n}\n\nexport function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {\n function accept(f) { if (f !== void 0 && typeof f !== \"function\") throw new TypeError(\"Function expected\"); return f; }\n var kind = contextIn.kind, key = kind === \"getter\" ? \"get\" : kind === \"setter\" ? \"set\" : \"value\";\n var target = !descriptorIn && ctor ? contextIn[\"static\"] ? ctor : ctor.prototype : null;\n var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});\n var _, done = false;\n for (var i = decorators.length - 1; i >= 0; i--) {\n var context = {};\n for (var p in contextIn) context[p] = p === \"access\" ? {} : contextIn[p];\n for (var p in contextIn.access) context.access[p] = contextIn.access[p];\n context.addInitializer = function (f) { if (done) throw new TypeError(\"Cannot add initializers after decoration has completed\"); extraInitializers.push(accept(f || null)); };\n var result = (0, decorators[i])(kind === \"accessor\" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);\n if (kind === \"accessor\") {\n if (result === void 0) continue;\n if (result === null || typeof result !== \"object\") throw new TypeError(\"Object expected\");\n if (_ = accept(result.get)) descriptor.get = _;\n if (_ = accept(result.set)) descriptor.set = _;\n if (_ = accept(result.init)) initializers.unshift(_);\n }\n else if (_ = accept(result)) {\n if (kind === \"field\") initializers.unshift(_);\n else descriptor[key] = _;\n }\n }\n if (target) Object.defineProperty(target, contextIn.name, descriptor);\n done = true;\n};\n\nexport function __runInitializers(thisArg, initializers, value) {\n var useValue = arguments.length > 2;\n for (var i = 0; i < initializers.length; i++) {\n value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);\n }\n return useValue ? value : void 0;\n};\n\nexport function __propKey(x) {\n return typeof x === \"symbol\" ? x : \"\".concat(x);\n};\n\nexport function __setFunctionName(f, name, prefix) {\n if (typeof name === \"symbol\") name = name.description ? \"[\".concat(name.description, \"]\") : \"\";\n return Object.defineProperty(f, \"name\", { configurable: true, value: prefix ? \"\".concat(prefix, \" \", name) : name });\n};\n\nexport function __metadata(metadataKey, metadataValue) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\n}\n\nexport function __awaiter(thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n}\n\nexport function __generator(thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === \"function\" ? Iterator : Object).prototype);\n return g.next = verb(0), g[\"throw\"] = verb(1), g[\"return\"] = verb(2), typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n}\n\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n});\n\nexport function __exportStar(m, o) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\n}\n\nexport function __values(o) {\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\n if (m) return m.call(o);\n if (o && typeof o.length === \"number\") return {\n next: function () {\n if (o && i >= o.length) o = void 0;\n return { value: o && o[i++], done: !o };\n }\n };\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\n}\n\nexport function __read(o, n) {\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\n if (!m) return o;\n var i = m.call(o), r, ar = [], e;\n try {\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\n }\n catch (error) { e = { error: error }; }\n finally {\n try {\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\n }\n finally { if (e) throw e.error; }\n }\n return ar;\n}\n\n/** @deprecated */\nexport function __spread() {\n for (var ar = [], i = 0; i < arguments.length; i++)\n ar = ar.concat(__read(arguments[i]));\n return ar;\n}\n\n/** @deprecated */\nexport function __spreadArrays() {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n}\n\nexport function __spreadArray(to, from, pack) {\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\n if (ar || !(i in from)) {\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\n ar[i] = from[i];\n }\n }\n return to.concat(ar || Array.prototype.slice.call(from));\n}\n\nexport function __await(v) {\n return this instanceof __await ? (this.v = v, this) : new __await(v);\n}\n\nexport function __asyncGenerator(thisArg, _arguments, generator) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\n return i = Object.create((typeof AsyncIterator === \"function\" ? AsyncIterator : Object).prototype), verb(\"next\"), verb(\"throw\"), verb(\"return\", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;\n function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }\n function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\n function fulfill(value) { resume(\"next\", value); }\n function reject(value) { resume(\"throw\", value); }\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\n}\n\nexport function __asyncDelegator(o) {\n var i, p;\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }\n}\n\nexport function __asyncValues(o) {\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\n var m = o[Symbol.asyncIterator], i;\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\n}\n\nexport function __makeTemplateObject(cooked, raw) {\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\n return cooked;\n};\n\nvar __setModuleDefault = Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n};\n\nexport function __importStar(mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n}\n\nexport function __importDefault(mod) {\n return (mod && mod.__esModule) ? mod : { default: mod };\n}\n\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\n}\n\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\n}\n\nexport function __classPrivateFieldIn(state, receiver) {\n if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\n return typeof state === \"function\" ? receiver === state : state.has(receiver);\n}\n\nexport function __addDisposableResource(env, value, async) {\n if (value !== null && value !== void 0) {\n if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\n var dispose, inner;\n if (async) {\n if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\n dispose = value[Symbol.asyncDispose];\n }\n if (dispose === void 0) {\n if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\n dispose = value[Symbol.dispose];\n if (async) inner = dispose;\n }\n if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\n if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\n env.stack.push({ value: value, dispose: dispose, async: async });\n }\n else if (async) {\n env.stack.push({ async: true });\n }\n return value;\n}\n\nvar _SuppressedError = typeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\n var e = new Error(message);\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\n};\n\nexport function __disposeResources(env) {\n function fail(e) {\n env.error = env.hasError ? new _SuppressedError(e, env.error, \"An error was suppressed during disposal.\") : e;\n env.hasError = true;\n }\n var r, s = 0;\n function next() {\n while (r = env.stack.pop()) {\n try {\n if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);\n if (r.dispose) {\n var result = r.dispose.call(r.value);\n if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });\n }\n else s |= 1;\n }\n catch (e) {\n fail(e);\n }\n }\n if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();\n if (env.hasError) throw env.error;\n }\n return next();\n}\n\nexport default {\n __extends,\n __assign,\n __rest,\n __decorate,\n __param,\n __metadata,\n __awaiter,\n __generator,\n __createBinding,\n __exportStar,\n __values,\n __read,\n __spread,\n __spreadArrays,\n __spreadArray,\n __await,\n __asyncGenerator,\n __asyncDelegator,\n __asyncValues,\n __makeTemplateObject,\n __importStar,\n __importDefault,\n __classPrivateFieldGet,\n __classPrivateFieldSet,\n __classPrivateFieldIn,\n __addDisposableResource,\n __disposeResources,\n};\n", "/**\n * Returns true if the object is a function.\n * @param value The value to check\n */\nexport function isFunction(value: any): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n", "/**\n * Used to create Error subclasses until the community moves away from ES5.\n *\n * This is because compiling from TypeScript down to ES5 has issues with subclassing Errors\n * as well as other built-in types: https://github.com/Microsoft/TypeScript/issues/12123\n *\n * @param createImpl A factory function to create the actual constructor implementation. The returned\n * function should be a named function that calls `_super` internally.\n */\nexport function createErrorClass(createImpl: (_super: any) => any): T {\n const _super = (instance: any) => {\n Error.call(instance);\n instance.stack = new Error().stack;\n };\n\n const ctorFunc = createImpl(_super);\n ctorFunc.prototype = Object.create(Error.prototype);\n ctorFunc.prototype.constructor = ctorFunc;\n return ctorFunc;\n}\n", "import { createErrorClass } from './createErrorClass';\n\nexport interface UnsubscriptionError extends Error {\n readonly errors: any[];\n}\n\nexport interface UnsubscriptionErrorCtor {\n /**\n * @deprecated Internal implementation detail. Do not construct error instances.\n * Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269\n */\n new (errors: any[]): UnsubscriptionError;\n}\n\n/**\n * An error thrown when one or more errors have occurred during the\n * `unsubscribe` of a {@link Subscription}.\n */\nexport const UnsubscriptionError: UnsubscriptionErrorCtor = createErrorClass(\n (_super) =>\n function UnsubscriptionErrorImpl(this: any, errors: (Error | string)[]) {\n _super(this);\n this.message = errors\n ? `${errors.length} errors occurred during unsubscription:\n${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\\n ')}`\n : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n }\n);\n", "/**\n * Removes an item from an array, mutating it.\n * @param arr The array to remove the item from\n * @param item The item to remove\n */\nexport function arrRemove(arr: T[] | undefined | null, item: T) {\n if (arr) {\n const index = arr.indexOf(item);\n 0 <= index && arr.splice(index, 1);\n }\n}\n", "import { isFunction } from './util/isFunction';\nimport { UnsubscriptionError } from './util/UnsubscriptionError';\nimport { SubscriptionLike, TeardownLogic, Unsubscribable } from './types';\nimport { arrRemove } from './util/arrRemove';\n\n/**\n * Represents a disposable resource, such as the execution of an Observable. A\n * Subscription has one important method, `unsubscribe`, that takes no argument\n * and just disposes the resource held by the subscription.\n *\n * Additionally, subscriptions may be grouped together through the `add()`\n * method, which will attach a child Subscription to the current Subscription.\n * When a Subscription is unsubscribed, all its children (and its grandchildren)\n * will be unsubscribed as well.\n *\n * @class Subscription\n */\nexport class Subscription implements SubscriptionLike {\n /** @nocollapse */\n public static EMPTY = (() => {\n const empty = new Subscription();\n empty.closed = true;\n return empty;\n })();\n\n /**\n * A flag to indicate whether this Subscription has already been unsubscribed.\n */\n public closed = false;\n\n private _parentage: Subscription[] | Subscription | null = null;\n\n /**\n * The list of registered finalizers to execute upon unsubscription. Adding and removing from this\n * list occurs in the {@link #add} and {@link #remove} methods.\n */\n private _finalizers: Exclude[] | null = null;\n\n /**\n * @param initialTeardown A function executed first as part of the finalization\n * process that is kicked off when {@link #unsubscribe} is called.\n */\n constructor(private initialTeardown?: () => void) {}\n\n /**\n * Disposes the resources held by the subscription. May, for instance, cancel\n * an ongoing Observable execution or cancel any other type of work that\n * started when the Subscription was created.\n * @return {void}\n */\n unsubscribe(): void {\n let errors: any[] | undefined;\n\n if (!this.closed) {\n this.closed = true;\n\n // Remove this from it's parents.\n const { _parentage } = this;\n if (_parentage) {\n this._parentage = null;\n if (Array.isArray(_parentage)) {\n for (const parent of _parentage) {\n parent.remove(this);\n }\n } else {\n _parentage.remove(this);\n }\n }\n\n const { initialTeardown: initialFinalizer } = this;\n if (isFunction(initialFinalizer)) {\n try {\n initialFinalizer();\n } catch (e) {\n errors = e instanceof UnsubscriptionError ? e.errors : [e];\n }\n }\n\n const { _finalizers } = this;\n if (_finalizers) {\n this._finalizers = null;\n for (const finalizer of _finalizers) {\n try {\n execFinalizer(finalizer);\n } catch (err) {\n errors = errors ?? [];\n if (err instanceof UnsubscriptionError) {\n errors = [...errors, ...err.errors];\n } else {\n errors.push(err);\n }\n }\n }\n }\n\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n }\n }\n\n /**\n * Adds a finalizer to this subscription, so that finalization will be unsubscribed/called\n * when this subscription is unsubscribed. If this subscription is already {@link #closed},\n * because it has already been unsubscribed, then whatever finalizer is passed to it\n * will automatically be executed (unless the finalizer itself is also a closed subscription).\n *\n * Closed Subscriptions cannot be added as finalizers to any subscription. Adding a closed\n * subscription to a any subscription will result in no operation. (A noop).\n *\n * Adding a subscription to itself, or adding `null` or `undefined` will not perform any\n * operation at all. (A noop).\n *\n * `Subscription` instances that are added to this instance will automatically remove themselves\n * if they are unsubscribed. Functions and {@link Unsubscribable} objects that you wish to remove\n * will need to be removed manually with {@link #remove}\n *\n * @param teardown The finalization logic to add to this subscription.\n */\n add(teardown: TeardownLogic): void {\n // Only add the finalizer if it's not undefined\n // and don't add a subscription to itself.\n if (teardown && teardown !== this) {\n if (this.closed) {\n // If this subscription is already closed,\n // execute whatever finalizer is handed to it automatically.\n execFinalizer(teardown);\n } else {\n if (teardown instanceof Subscription) {\n // We don't add closed subscriptions, and we don't add the same subscription\n // twice. Subscription unsubscribe is idempotent.\n if (teardown.closed || teardown._hasParent(this)) {\n return;\n }\n teardown._addParent(this);\n }\n (this._finalizers = this._finalizers ?? []).push(teardown);\n }\n }\n }\n\n /**\n * Checks to see if a this subscription already has a particular parent.\n * This will signal that this subscription has already been added to the parent in question.\n * @param parent the parent to check for\n */\n private _hasParent(parent: Subscription) {\n const { _parentage } = this;\n return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));\n }\n\n /**\n * Adds a parent to this subscription so it can be removed from the parent if it\n * unsubscribes on it's own.\n *\n * NOTE: THIS ASSUMES THAT {@link _hasParent} HAS ALREADY BEEN CHECKED.\n * @param parent The parent subscription to add\n */\n private _addParent(parent: Subscription) {\n const { _parentage } = this;\n this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;\n }\n\n /**\n * Called on a child when it is removed via {@link #remove}.\n * @param parent The parent to remove\n */\n private _removeParent(parent: Subscription) {\n const { _parentage } = this;\n if (_parentage === parent) {\n this._parentage = null;\n } else if (Array.isArray(_parentage)) {\n arrRemove(_parentage, parent);\n }\n }\n\n /**\n * Removes a finalizer from this subscription that was previously added with the {@link #add} method.\n *\n * Note that `Subscription` instances, when unsubscribed, will automatically remove themselves\n * from every other `Subscription` they have been added to. This means that using the `remove` method\n * is not a common thing and should be used thoughtfully.\n *\n * If you add the same finalizer instance of a function or an unsubscribable object to a `Subscription` instance\n * more than once, you will need to call `remove` the same number of times to remove all instances.\n *\n * All finalizer instances are removed to free up memory upon unsubscription.\n *\n * @param teardown The finalizer to remove from this subscription\n */\n remove(teardown: Exclude): void {\n const { _finalizers } = this;\n _finalizers && arrRemove(_finalizers, teardown);\n\n if (teardown instanceof Subscription) {\n teardown._removeParent(this);\n }\n }\n}\n\nexport const EMPTY_SUBSCRIPTION = Subscription.EMPTY;\n\nexport function isSubscription(value: any): value is Subscription {\n return (\n value instanceof Subscription ||\n (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe))\n );\n}\n\nfunction execFinalizer(finalizer: Unsubscribable | (() => void)) {\n if (isFunction(finalizer)) {\n finalizer();\n } else {\n finalizer.unsubscribe();\n }\n}\n", "import { Subscriber } from './Subscriber';\nimport { ObservableNotification } from './types';\n\n/**\n * The {@link GlobalConfig} object for RxJS. It is used to configure things\n * like how to react on unhandled errors.\n */\nexport const config: GlobalConfig = {\n onUnhandledError: null,\n onStoppedNotification: null,\n Promise: undefined,\n useDeprecatedSynchronousErrorHandling: false,\n useDeprecatedNextContext: false,\n};\n\n/**\n * The global configuration object for RxJS, used to configure things\n * like how to react on unhandled errors. Accessible via {@link config}\n * object.\n */\nexport interface GlobalConfig {\n /**\n * A registration point for unhandled errors from RxJS. These are errors that\n * cannot were not handled by consuming code in the usual subscription path. For\n * example, if you have this configured, and you subscribe to an observable without\n * providing an error handler, errors from that subscription will end up here. This\n * will _always_ be called asynchronously on another job in the runtime. This is because\n * we do not want errors thrown in this user-configured handler to interfere with the\n * behavior of the library.\n */\n onUnhandledError: ((err: any) => void) | null;\n\n /**\n * A registration point for notifications that cannot be sent to subscribers because they\n * have completed, errored or have been explicitly unsubscribed. By default, next, complete\n * and error notifications sent to stopped subscribers are noops. However, sometimes callers\n * might want a different behavior. For example, with sources that attempt to report errors\n * to stopped subscribers, a caller can configure RxJS to throw an unhandled error instead.\n * This will _always_ be called asynchronously on another job in the runtime. This is because\n * we do not want errors thrown in this user-configured handler to interfere with the\n * behavior of the library.\n */\n onStoppedNotification: ((notification: ObservableNotification, subscriber: Subscriber) => void) | null;\n\n /**\n * The promise constructor used by default for {@link Observable#toPromise toPromise} and {@link Observable#forEach forEach}\n * methods.\n *\n * @deprecated As of version 8, RxJS will no longer support this sort of injection of a\n * Promise constructor. If you need a Promise implementation other than native promises,\n * please polyfill/patch Promise as you see appropriate. Will be removed in v8.\n */\n Promise?: PromiseConstructorLike;\n\n /**\n * If true, turns on synchronous error rethrowing, which is a deprecated behavior\n * in v6 and higher. This behavior enables bad patterns like wrapping a subscribe\n * call in a try/catch block. It also enables producer interference, a nasty bug\n * where a multicast can be broken for all observers by a downstream consumer with\n * an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BUY TIME\n * FOR MIGRATION REASONS.\n *\n * @deprecated As of version 8, RxJS will no longer support synchronous throwing\n * of unhandled errors. All errors will be thrown on a separate call stack to prevent bad\n * behaviors described above. Will be removed in v8.\n */\n useDeprecatedSynchronousErrorHandling: boolean;\n\n /**\n * If true, enables an as-of-yet undocumented feature from v5: The ability to access\n * `unsubscribe()` via `this` context in `next` functions created in observers passed\n * to `subscribe`.\n *\n * This is being removed because the performance was severely problematic, and it could also cause\n * issues when types other than POJOs are passed to subscribe as subscribers, as they will likely have\n * their `this` context overwritten.\n *\n * @deprecated As of version 8, RxJS will no longer support altering the\n * context of next functions provided as part of an observer to Subscribe. Instead,\n * you will have access to a subscription or a signal or token that will allow you to do things like\n * unsubscribe and test closed status. Will be removed in v8.\n */\n useDeprecatedNextContext: boolean;\n}\n", "import type { TimerHandle } from './timerHandle';\ntype SetTimeoutFunction = (handler: () => void, timeout?: number, ...args: any[]) => TimerHandle;\ntype ClearTimeoutFunction = (handle: TimerHandle) => void;\n\ninterface TimeoutProvider {\n setTimeout: SetTimeoutFunction;\n clearTimeout: ClearTimeoutFunction;\n delegate:\n | {\n setTimeout: SetTimeoutFunction;\n clearTimeout: ClearTimeoutFunction;\n }\n | undefined;\n}\n\nexport const timeoutProvider: TimeoutProvider = {\n // When accessing the delegate, use the variable rather than `this` so that\n // the functions can be called without being bound to the provider.\n setTimeout(handler: () => void, timeout?: number, ...args) {\n const { delegate } = timeoutProvider;\n if (delegate?.setTimeout) {\n return delegate.setTimeout(handler, timeout, ...args);\n }\n return setTimeout(handler, timeout, ...args);\n },\n clearTimeout(handle) {\n const { delegate } = timeoutProvider;\n return (delegate?.clearTimeout || clearTimeout)(handle as any);\n },\n delegate: undefined,\n};\n", "import { config } from '../config';\nimport { timeoutProvider } from '../scheduler/timeoutProvider';\n\n/**\n * Handles an error on another job either with the user-configured {@link onUnhandledError},\n * or by throwing it on that new job so it can be picked up by `window.onerror`, `process.on('error')`, etc.\n *\n * This should be called whenever there is an error that is out-of-band with the subscription\n * or when an error hits a terminal boundary of the subscription and no error handler was provided.\n *\n * @param err the error to report\n */\nexport function reportUnhandledError(err: any) {\n timeoutProvider.setTimeout(() => {\n const { onUnhandledError } = config;\n if (onUnhandledError) {\n // Execute the user-configured error handler.\n onUnhandledError(err);\n } else {\n // Throw so it is picked up by the runtime's uncaught error mechanism.\n throw err;\n }\n });\n}\n", "/* tslint:disable:no-empty */\nexport function noop() { }\n", "import { CompleteNotification, NextNotification, ErrorNotification } from './types';\n\n/**\n * A completion object optimized for memory use and created to be the\n * same \"shape\" as other notifications in v8.\n * @internal\n */\nexport const COMPLETE_NOTIFICATION = (() => createNotification('C', undefined, undefined) as CompleteNotification)();\n\n/**\n * Internal use only. Creates an optimized error notification that is the same \"shape\"\n * as other notifications.\n * @internal\n */\nexport function errorNotification(error: any): ErrorNotification {\n return createNotification('E', undefined, error) as any;\n}\n\n/**\n * Internal use only. Creates an optimized next notification that is the same \"shape\"\n * as other notifications.\n * @internal\n */\nexport function nextNotification(value: T) {\n return createNotification('N', value, undefined) as NextNotification;\n}\n\n/**\n * Ensures that all notifications created internally have the same \"shape\" in v8.\n *\n * TODO: This is only exported to support a crazy legacy test in `groupBy`.\n * @internal\n */\nexport function createNotification(kind: 'N' | 'E' | 'C', value: any, error: any) {\n return {\n kind,\n value,\n error,\n };\n}\n", "import { config } from '../config';\n\nlet context: { errorThrown: boolean; error: any } | null = null;\n\n/**\n * Handles dealing with errors for super-gross mode. Creates a context, in which\n * any synchronously thrown errors will be passed to {@link captureError}. Which\n * will record the error such that it will be rethrown after the call back is complete.\n * TODO: Remove in v8\n * @param cb An immediately executed function.\n */\nexport function errorContext(cb: () => void) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n const isRoot = !context;\n if (isRoot) {\n context = { errorThrown: false, error: null };\n }\n cb();\n if (isRoot) {\n const { errorThrown, error } = context!;\n context = null;\n if (errorThrown) {\n throw error;\n }\n }\n } else {\n // This is the general non-deprecated path for everyone that\n // isn't crazy enough to use super-gross mode (useDeprecatedSynchronousErrorHandling)\n cb();\n }\n}\n\n/**\n * Captures errors only in super-gross mode.\n * @param err the error to capture\n */\nexport function captureError(err: any) {\n if (config.useDeprecatedSynchronousErrorHandling && context) {\n context.errorThrown = true;\n context.error = err;\n }\n}\n", "import { isFunction } from './util/isFunction';\nimport { Observer, ObservableNotification } from './types';\nimport { isSubscription, Subscription } from './Subscription';\nimport { config } from './config';\nimport { reportUnhandledError } from './util/reportUnhandledError';\nimport { noop } from './util/noop';\nimport { nextNotification, errorNotification, COMPLETE_NOTIFICATION } from './NotificationFactories';\nimport { timeoutProvider } from './scheduler/timeoutProvider';\nimport { captureError } from './util/errorContext';\n\n/**\n * Implements the {@link Observer} interface and extends the\n * {@link Subscription} class. While the {@link Observer} is the public API for\n * consuming the values of an {@link Observable}, all Observers get converted to\n * a Subscriber, in order to provide Subscription-like capabilities such as\n * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for\n * implementing operators, but it is rarely used as a public API.\n *\n * @class Subscriber\n */\nexport class Subscriber extends Subscription implements Observer {\n /**\n * A static factory for a Subscriber, given a (potentially partial) definition\n * of an Observer.\n * @param next The `next` callback of an Observer.\n * @param error The `error` callback of an\n * Observer.\n * @param complete The `complete` callback of an\n * Observer.\n * @return A Subscriber wrapping the (partially defined)\n * Observer represented by the given arguments.\n * @nocollapse\n * @deprecated Do not use. Will be removed in v8. There is no replacement for this\n * method, and there is no reason to be creating instances of `Subscriber` directly.\n * If you have a specific use case, please file an issue.\n */\n static create(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber {\n return new SafeSubscriber(next, error, complete);\n }\n\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n protected isStopped: boolean = false;\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n protected destination: Subscriber | Observer; // this `any` is the escape hatch to erase extra type param (e.g. R)\n\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n * There is no reason to directly create an instance of Subscriber. This type is exported for typings reasons.\n */\n constructor(destination?: Subscriber | Observer) {\n super();\n if (destination) {\n this.destination = destination;\n // Automatically chain subscriptions together here.\n // if destination is a Subscription, then it is a Subscriber.\n if (isSubscription(destination)) {\n destination.add(this);\n }\n } else {\n this.destination = EMPTY_OBSERVER;\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `next` from\n * the Observable, with a value. The Observable may call this method 0 or more\n * times.\n * @param {T} [value] The `next` value.\n * @return {void}\n */\n next(value?: T): void {\n if (this.isStopped) {\n handleStoppedNotification(nextNotification(value), this);\n } else {\n this._next(value!);\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `error` from\n * the Observable, with an attached `Error`. Notifies the Observer that\n * the Observable has experienced an error condition.\n * @param {any} [err] The `error` exception.\n * @return {void}\n */\n error(err?: any): void {\n if (this.isStopped) {\n handleStoppedNotification(errorNotification(err), this);\n } else {\n this.isStopped = true;\n this._error(err);\n }\n }\n\n /**\n * The {@link Observer} callback to receive a valueless notification of type\n * `complete` from the Observable. Notifies the Observer that the Observable\n * has finished sending push-based notifications.\n * @return {void}\n */\n complete(): void {\n if (this.isStopped) {\n handleStoppedNotification(COMPLETE_NOTIFICATION, this);\n } else {\n this.isStopped = true;\n this._complete();\n }\n }\n\n unsubscribe(): void {\n if (!this.closed) {\n this.isStopped = true;\n super.unsubscribe();\n this.destination = null!;\n }\n }\n\n protected _next(value: T): void {\n this.destination.next(value);\n }\n\n protected _error(err: any): void {\n try {\n this.destination.error(err);\n } finally {\n this.unsubscribe();\n }\n }\n\n protected _complete(): void {\n try {\n this.destination.complete();\n } finally {\n this.unsubscribe();\n }\n }\n}\n\n/**\n * This bind is captured here because we want to be able to have\n * compatibility with monoid libraries that tend to use a method named\n * `bind`. In particular, a library called Monio requires this.\n */\nconst _bind = Function.prototype.bind;\n\nfunction bind any>(fn: Fn, thisArg: any): Fn {\n return _bind.call(fn, thisArg);\n}\n\n/**\n * Internal optimization only, DO NOT EXPOSE.\n * @internal\n */\nclass ConsumerObserver implements Observer {\n constructor(private partialObserver: Partial>) {}\n\n next(value: T): void {\n const { partialObserver } = this;\n if (partialObserver.next) {\n try {\n partialObserver.next(value);\n } catch (error) {\n handleUnhandledError(error);\n }\n }\n }\n\n error(err: any): void {\n const { partialObserver } = this;\n if (partialObserver.error) {\n try {\n partialObserver.error(err);\n } catch (error) {\n handleUnhandledError(error);\n }\n } else {\n handleUnhandledError(err);\n }\n }\n\n complete(): void {\n const { partialObserver } = this;\n if (partialObserver.complete) {\n try {\n partialObserver.complete();\n } catch (error) {\n handleUnhandledError(error);\n }\n }\n }\n}\n\nexport class SafeSubscriber extends Subscriber {\n constructor(\n observerOrNext?: Partial> | ((value: T) => void) | null,\n error?: ((e?: any) => void) | null,\n complete?: (() => void) | null\n ) {\n super();\n\n let partialObserver: Partial>;\n if (isFunction(observerOrNext) || !observerOrNext) {\n // The first argument is a function, not an observer. The next\n // two arguments *could* be observers, or they could be empty.\n partialObserver = {\n next: (observerOrNext ?? undefined) as (((value: T) => void) | undefined),\n error: error ?? undefined,\n complete: complete ?? undefined,\n };\n } else {\n // The first argument is a partial observer.\n let context: any;\n if (this && config.useDeprecatedNextContext) {\n // This is a deprecated path that made `this.unsubscribe()` available in\n // next handler functions passed to subscribe. This only exists behind a flag\n // now, as it is *very* slow.\n context = Object.create(observerOrNext);\n context.unsubscribe = () => this.unsubscribe();\n partialObserver = {\n next: observerOrNext.next && bind(observerOrNext.next, context),\n error: observerOrNext.error && bind(observerOrNext.error, context),\n complete: observerOrNext.complete && bind(observerOrNext.complete, context),\n };\n } else {\n // The \"normal\" path. Just use the partial observer directly.\n partialObserver = observerOrNext;\n }\n }\n\n // Wrap the partial observer to ensure it's a full observer, and\n // make sure proper error handling is accounted for.\n this.destination = new ConsumerObserver(partialObserver);\n }\n}\n\nfunction handleUnhandledError(error: any) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n captureError(error);\n } else {\n // Ideal path, we report this as an unhandled error,\n // which is thrown on a new call stack.\n reportUnhandledError(error);\n }\n}\n\n/**\n * An error handler used when no error handler was supplied\n * to the SafeSubscriber -- meaning no error handler was supplied\n * do the `subscribe` call on our observable.\n * @param err The error to handle\n */\nfunction defaultErrorHandler(err: any) {\n throw err;\n}\n\n/**\n * A handler for notifications that cannot be sent to a stopped subscriber.\n * @param notification The notification being sent\n * @param subscriber The stopped subscriber\n */\nfunction handleStoppedNotification(notification: ObservableNotification, subscriber: Subscriber) {\n const { onStoppedNotification } = config;\n onStoppedNotification && timeoutProvider.setTimeout(() => onStoppedNotification(notification, subscriber));\n}\n\n/**\n * The observer used as a stub for subscriptions where the user did not\n * pass any arguments to `subscribe`. Comes with the default error handling\n * behavior.\n */\nexport const EMPTY_OBSERVER: Readonly> & { closed: true } = {\n closed: true,\n next: noop,\n error: defaultErrorHandler,\n complete: noop,\n};\n", "/**\n * Symbol.observable or a string \"@@observable\". Used for interop\n *\n * @deprecated We will no longer be exporting this symbol in upcoming versions of RxJS.\n * Instead polyfill and use Symbol.observable directly *or* use https://www.npmjs.com/package/symbol-observable\n */\nexport const observable: string | symbol = (() => (typeof Symbol === 'function' && Symbol.observable) || '@@observable')();\n", "/**\n * This function takes one parameter and just returns it. Simply put,\n * this is like `(x: T): T => x`.\n *\n * ## Examples\n *\n * This is useful in some cases when using things like `mergeMap`\n *\n * ```ts\n * import { interval, take, map, range, mergeMap, identity } from 'rxjs';\n *\n * const source$ = interval(1000).pipe(take(5));\n *\n * const result$ = source$.pipe(\n * map(i => range(i)),\n * mergeMap(identity) // same as mergeMap(x => x)\n * );\n *\n * result$.subscribe({\n * next: console.log\n * });\n * ```\n *\n * Or when you want to selectively apply an operator\n *\n * ```ts\n * import { interval, take, identity } from 'rxjs';\n *\n * const shouldLimit = () => Math.random() < 0.5;\n *\n * const source$ = interval(1000);\n *\n * const result$ = source$.pipe(shouldLimit() ? take(5) : identity);\n *\n * result$.subscribe({\n * next: console.log\n * });\n * ```\n *\n * @param x Any value that is returned by this function\n * @returns The value passed as the first parameter to this function\n */\nexport function identity(x: T): T {\n return x;\n}\n", "import { identity } from './identity';\nimport { UnaryFunction } from '../types';\n\nexport function pipe(): typeof identity;\nexport function pipe(fn1: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction,\n fn9: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction,\n fn9: UnaryFunction,\n ...fns: UnaryFunction[]\n): UnaryFunction;\n\n/**\n * pipe() can be called on one or more functions, each of which can take one argument (\"UnaryFunction\")\n * and uses it to return a value.\n * It returns a function that takes one argument, passes it to the first UnaryFunction, and then\n * passes the result to the next one, passes that result to the next one, and so on. \n */\nexport function pipe(...fns: Array>): UnaryFunction {\n return pipeFromArray(fns);\n}\n\n/** @internal */\nexport function pipeFromArray(fns: Array>): UnaryFunction {\n if (fns.length === 0) {\n return identity as UnaryFunction;\n }\n\n if (fns.length === 1) {\n return fns[0];\n }\n\n return function piped(input: T): R {\n return fns.reduce((prev: any, fn: UnaryFunction) => fn(prev), input as any);\n };\n}\n", "import { Operator } from './Operator';\nimport { SafeSubscriber, Subscriber } from './Subscriber';\nimport { isSubscription, Subscription } from './Subscription';\nimport { TeardownLogic, OperatorFunction, Subscribable, Observer } from './types';\nimport { observable as Symbol_observable } from './symbol/observable';\nimport { pipeFromArray } from './util/pipe';\nimport { config } from './config';\nimport { isFunction } from './util/isFunction';\nimport { errorContext } from './util/errorContext';\n\n/**\n * A representation of any set of values over any amount of time. This is the most basic building block\n * of RxJS.\n *\n * @class Observable\n */\nexport class Observable implements Subscribable {\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n */\n source: Observable | undefined;\n\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n */\n operator: Operator | undefined;\n\n /**\n * @constructor\n * @param {Function} subscribe the function that is called when the Observable is\n * initially subscribed to. This function is given a Subscriber, to which new values\n * can be `next`ed, or an `error` method can be called to raise an error, or\n * `complete` can be called to notify of a successful completion.\n */\n constructor(subscribe?: (this: Observable, subscriber: Subscriber) => TeardownLogic) {\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n\n // HACK: Since TypeScript inherits static properties too, we have to\n // fight against TypeScript here so Subject can have a different static create signature\n /**\n * Creates a new Observable by calling the Observable constructor\n * @owner Observable\n * @method create\n * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor\n * @return {Observable} a new observable\n * @nocollapse\n * @deprecated Use `new Observable()` instead. Will be removed in v8.\n */\n static create: (...args: any[]) => any = (subscribe?: (subscriber: Subscriber) => TeardownLogic) => {\n return new Observable(subscribe);\n };\n\n /**\n * Creates a new Observable, with this Observable instance as the source, and the passed\n * operator defined as the new observable's operator.\n * @method lift\n * @param operator the operator defining the operation to take on the observable\n * @return a new observable with the Operator applied\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n * If you have implemented an operator using `lift`, it is recommended that you create an\n * operator by simply returning `new Observable()` directly. See \"Creating new operators from\n * scratch\" section here: https://rxjs.dev/guide/operators\n */\n lift(operator?: Operator): Observable {\n const observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n }\n\n subscribe(observerOrNext?: Partial> | ((value: T) => void)): Subscription;\n /** @deprecated Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments */\n subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;\n /**\n * Invokes an execution of an Observable and registers Observer handlers for notifications it will emit.\n *\n * Use it when you have all these Observables, but still nothing is happening.\n *\n * `subscribe` is not a regular operator, but a method that calls Observable's internal `subscribe` function. It\n * might be for example a function that you passed to Observable's constructor, but most of the time it is\n * a library implementation, which defines what will be emitted by an Observable, and when it be will emitted. This means\n * that calling `subscribe` is actually the moment when Observable starts its work, not when it is created, as it is often\n * the thought.\n *\n * Apart from starting the execution of an Observable, this method allows you to listen for values\n * that an Observable emits, as well as for when it completes or errors. You can achieve this in two\n * of the following ways.\n *\n * The first way is creating an object that implements {@link Observer} interface. It should have methods\n * defined by that interface, but note that it should be just a regular JavaScript object, which you can create\n * yourself in any way you want (ES6 class, classic function constructor, object literal etc.). In particular, do\n * not attempt to use any RxJS implementation details to create Observers - you don't need them. Remember also\n * that your object does not have to implement all methods. If you find yourself creating a method that doesn't\n * do anything, you can simply omit it. Note however, if the `error` method is not provided and an error happens,\n * it will be thrown asynchronously. Errors thrown asynchronously cannot be caught using `try`/`catch`. Instead,\n * use the {@link onUnhandledError} configuration option or use a runtime handler (like `window.onerror` or\n * `process.on('error)`) to be notified of unhandled errors. Because of this, it's recommended that you provide\n * an `error` method to avoid missing thrown errors.\n *\n * The second way is to give up on Observer object altogether and simply provide callback functions in place of its methods.\n * This means you can provide three functions as arguments to `subscribe`, where the first function is equivalent\n * of a `next` method, the second of an `error` method and the third of a `complete` method. Just as in case of an Observer,\n * if you do not need to listen for something, you can omit a function by passing `undefined` or `null`,\n * since `subscribe` recognizes these functions by where they were placed in function call. When it comes\n * to the `error` function, as with an Observer, if not provided, errors emitted by an Observable will be thrown asynchronously.\n *\n * You can, however, subscribe with no parameters at all. This may be the case where you're not interested in terminal events\n * and you also handled emissions internally by using operators (e.g. using `tap`).\n *\n * Whichever style of calling `subscribe` you use, in both cases it returns a Subscription object.\n * This object allows you to call `unsubscribe` on it, which in turn will stop the work that an Observable does and will clean\n * up all resources that an Observable used. Note that cancelling a subscription will not call `complete` callback\n * provided to `subscribe` function, which is reserved for a regular completion signal that comes from an Observable.\n *\n * Remember that callbacks provided to `subscribe` are not guaranteed to be called asynchronously.\n * It is an Observable itself that decides when these functions will be called. For example {@link of}\n * by default emits all its values synchronously. Always check documentation for how given Observable\n * will behave when subscribed and if its default behavior can be modified with a `scheduler`.\n *\n * #### Examples\n *\n * Subscribe with an {@link guide/observer Observer}\n *\n * ```ts\n * import { of } from 'rxjs';\n *\n * const sumObserver = {\n * sum: 0,\n * next(value) {\n * console.log('Adding: ' + value);\n * this.sum = this.sum + value;\n * },\n * error() {\n * // We actually could just remove this method,\n * // since we do not really care about errors right now.\n * },\n * complete() {\n * console.log('Sum equals: ' + this.sum);\n * }\n * };\n *\n * of(1, 2, 3) // Synchronously emits 1, 2, 3 and then completes.\n * .subscribe(sumObserver);\n *\n * // Logs:\n * // 'Adding: 1'\n * // 'Adding: 2'\n * // 'Adding: 3'\n * // 'Sum equals: 6'\n * ```\n *\n * Subscribe with functions ({@link deprecations/subscribe-arguments deprecated})\n *\n * ```ts\n * import { of } from 'rxjs'\n *\n * let sum = 0;\n *\n * of(1, 2, 3).subscribe(\n * value => {\n * console.log('Adding: ' + value);\n * sum = sum + value;\n * },\n * undefined,\n * () => console.log('Sum equals: ' + sum)\n * );\n *\n * // Logs:\n * // 'Adding: 1'\n * // 'Adding: 2'\n * // 'Adding: 3'\n * // 'Sum equals: 6'\n * ```\n *\n * Cancel a subscription\n *\n * ```ts\n * import { interval } from 'rxjs';\n *\n * const subscription = interval(1000).subscribe({\n * next(num) {\n * console.log(num)\n * },\n * complete() {\n * // Will not be called, even when cancelling subscription.\n * console.log('completed!');\n * }\n * });\n *\n * setTimeout(() => {\n * subscription.unsubscribe();\n * console.log('unsubscribed!');\n * }, 2500);\n *\n * // Logs:\n * // 0 after 1s\n * // 1 after 2s\n * // 'unsubscribed!' after 2.5s\n * ```\n *\n * @param {Observer|Function} observerOrNext (optional) Either an observer with methods to be called,\n * or the first of three possible handlers, which is the handler for each value emitted from the subscribed\n * Observable.\n * @param {Function} error (optional) A handler for a terminal event resulting from an error. If no error handler is provided,\n * the error will be thrown asynchronously as unhandled.\n * @param {Function} complete (optional) A handler for a terminal event resulting from successful completion.\n * @return {Subscription} a subscription reference to the registered handlers\n * @method subscribe\n */\n subscribe(\n observerOrNext?: Partial> | ((value: T) => void) | null,\n error?: ((error: any) => void) | null,\n complete?: (() => void) | null\n ): Subscription {\n const subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);\n\n errorContext(() => {\n const { operator, source } = this;\n subscriber.add(\n operator\n ? // We're dealing with a subscription in the\n // operator chain to one of our lifted operators.\n operator.call(subscriber, source)\n : source\n ? // If `source` has a value, but `operator` does not, something that\n // had intimate knowledge of our API, like our `Subject`, must have\n // set it. We're going to just call `_subscribe` directly.\n this._subscribe(subscriber)\n : // In all other cases, we're likely wrapping a user-provided initializer\n // function, so we need to catch errors and handle them appropriately.\n this._trySubscribe(subscriber)\n );\n });\n\n return subscriber;\n }\n\n /** @internal */\n protected _trySubscribe(sink: Subscriber): TeardownLogic {\n try {\n return this._subscribe(sink);\n } catch (err) {\n // We don't need to return anything in this case,\n // because it's just going to try to `add()` to a subscription\n // above.\n sink.error(err);\n }\n }\n\n /**\n * Used as a NON-CANCELLABLE means of subscribing to an observable, for use with\n * APIs that expect promises, like `async/await`. You cannot unsubscribe from this.\n *\n * **WARNING**: Only use this with observables you *know* will complete. If the source\n * observable does not complete, you will end up with a promise that is hung up, and\n * potentially all of the state of an async function hanging out in memory. To avoid\n * this situation, look into adding something like {@link timeout}, {@link take},\n * {@link takeWhile}, or {@link takeUntil} amongst others.\n *\n * #### Example\n *\n * ```ts\n * import { interval, take } from 'rxjs';\n *\n * const source$ = interval(1000).pipe(take(4));\n *\n * async function getTotal() {\n * let total = 0;\n *\n * await source$.forEach(value => {\n * total += value;\n * console.log('observable -> ' + value);\n * });\n *\n * return total;\n * }\n *\n * getTotal().then(\n * total => console.log('Total: ' + total)\n * );\n *\n * // Expected:\n * // 'observable -> 0'\n * // 'observable -> 1'\n * // 'observable -> 2'\n * // 'observable -> 3'\n * // 'Total: 6'\n * ```\n *\n * @param next a handler for each value emitted by the observable\n * @return a promise that either resolves on observable completion or\n * rejects with the handled error\n */\n forEach(next: (value: T) => void): Promise;\n\n /**\n * @param next a handler for each value emitted by the observable\n * @param promiseCtor a constructor function used to instantiate the Promise\n * @return a promise that either resolves on observable completion or\n * rejects with the handled error\n * @deprecated Passing a Promise constructor will no longer be available\n * in upcoming versions of RxJS. This is because it adds weight to the library, for very\n * little benefit. If you need this functionality, it is recommended that you either\n * polyfill Promise, or you create an adapter to convert the returned native promise\n * to whatever promise implementation you wanted. Will be removed in v8.\n */\n forEach(next: (value: T) => void, promiseCtor: PromiseConstructorLike): Promise;\n\n forEach(next: (value: T) => void, promiseCtor?: PromiseConstructorLike): Promise {\n promiseCtor = getPromiseCtor(promiseCtor);\n\n return new promiseCtor((resolve, reject) => {\n const subscriber = new SafeSubscriber({\n next: (value) => {\n try {\n next(value);\n } catch (err) {\n reject(err);\n subscriber.unsubscribe();\n }\n },\n error: reject,\n complete: resolve,\n });\n this.subscribe(subscriber);\n }) as Promise;\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): TeardownLogic {\n return this.source?.subscribe(subscriber);\n }\n\n /**\n * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable\n * @method Symbol.observable\n * @return {Observable} this instance of the observable\n */\n [Symbol_observable]() {\n return this;\n }\n\n /* tslint:disable:max-line-length */\n pipe(): Observable;\n pipe(op1: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction,\n op6: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction,\n op6: OperatorFunction,\n op7: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction,\n op6: OperatorFunction,\n op7: OperatorFunction,\n op8: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction,\n op6: OperatorFunction,\n op7: OperatorFunction,\n op8: OperatorFunction,\n op9: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction,\n op6: OperatorFunction,\n op7: OperatorFunction,\n op8: OperatorFunction,\n op9: OperatorFunction,\n ...operations: OperatorFunction[]\n ): Observable;\n /* tslint:enable:max-line-length */\n\n /**\n * Used to stitch together functional operators into a chain.\n * @method pipe\n * @return {Observable} the Observable result of all of the operators having\n * been called in the order they were passed in.\n *\n * ## Example\n *\n * ```ts\n * import { interval, filter, map, scan } from 'rxjs';\n *\n * interval(1000)\n * .pipe(\n * filter(x => x % 2 === 0),\n * map(x => x + x),\n * scan((acc, x) => acc + x)\n * )\n * .subscribe(x => console.log(x));\n * ```\n */\n pipe(...operations: OperatorFunction[]): Observable {\n return pipeFromArray(operations)(this);\n }\n\n /* tslint:disable:max-line-length */\n /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */\n toPromise(): Promise;\n /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */\n toPromise(PromiseCtor: typeof Promise): Promise;\n /** @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise */\n toPromise(PromiseCtor: PromiseConstructorLike): Promise;\n /* tslint:enable:max-line-length */\n\n /**\n * Subscribe to this Observable and get a Promise resolving on\n * `complete` with the last emission (if any).\n *\n * **WARNING**: Only use this with observables you *know* will complete. If the source\n * observable does not complete, you will end up with a promise that is hung up, and\n * potentially all of the state of an async function hanging out in memory. To avoid\n * this situation, look into adding something like {@link timeout}, {@link take},\n * {@link takeWhile}, or {@link takeUntil} amongst others.\n *\n * @method toPromise\n * @param [promiseCtor] a constructor function used to instantiate\n * the Promise\n * @return A Promise that resolves with the last value emit, or\n * rejects on an error. If there were no emissions, Promise\n * resolves with undefined.\n * @deprecated Replaced with {@link firstValueFrom} and {@link lastValueFrom}. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise\n */\n toPromise(promiseCtor?: PromiseConstructorLike): Promise {\n promiseCtor = getPromiseCtor(promiseCtor);\n\n return new promiseCtor((resolve, reject) => {\n let value: T | undefined;\n this.subscribe(\n (x: T) => (value = x),\n (err: any) => reject(err),\n () => resolve(value)\n );\n }) as Promise;\n }\n}\n\n/**\n * Decides between a passed promise constructor from consuming code,\n * A default configured promise constructor, and the native promise\n * constructor and returns it. If nothing can be found, it will throw\n * an error.\n * @param promiseCtor The optional promise constructor to passed by consuming code\n */\nfunction getPromiseCtor(promiseCtor: PromiseConstructorLike | undefined) {\n return promiseCtor ?? config.Promise ?? Promise;\n}\n\nfunction isObserver(value: any): value is Observer {\n return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);\n}\n\nfunction isSubscriber(value: any): value is Subscriber {\n return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));\n}\n", "import { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { OperatorFunction } from '../types';\nimport { isFunction } from './isFunction';\n\n/**\n * Used to determine if an object is an Observable with a lift function.\n */\nexport function hasLift(source: any): source is { lift: InstanceType['lift'] } {\n return isFunction(source?.lift);\n}\n\n/**\n * Creates an `OperatorFunction`. Used to define operators throughout the library in a concise way.\n * @param init The logic to connect the liftedSource to the subscriber at the moment of subscription.\n */\nexport function operate(\n init: (liftedSource: Observable, subscriber: Subscriber) => (() => void) | void\n): OperatorFunction {\n return (source: Observable) => {\n if (hasLift(source)) {\n return source.lift(function (this: Subscriber, liftedSource: Observable) {\n try {\n return init(liftedSource, this);\n } catch (err) {\n this.error(err);\n }\n });\n }\n throw new TypeError('Unable to lift unknown Observable type');\n };\n}\n", "import { Subscriber } from '../Subscriber';\n\n/**\n * Creates an instance of an `OperatorSubscriber`.\n * @param destination The downstream subscriber.\n * @param onNext Handles next values, only called if this subscriber is not stopped or closed. Any\n * error that occurs in this function is caught and sent to the `error` method of this subscriber.\n * @param onError Handles errors from the subscription, any errors that occur in this handler are caught\n * and send to the `destination` error handler.\n * @param onComplete Handles completion notification from the subscription. Any errors that occur in\n * this handler are sent to the `destination` error handler.\n * @param onFinalize Additional teardown logic here. This will only be called on teardown if the\n * subscriber itself is not already closed. This is called after all other teardown logic is executed.\n */\nexport function createOperatorSubscriber(\n destination: Subscriber,\n onNext?: (value: T) => void,\n onComplete?: () => void,\n onError?: (err: any) => void,\n onFinalize?: () => void\n): Subscriber {\n return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);\n}\n\n/**\n * A generic helper for allowing operators to be created with a Subscriber and\n * use closures to capture necessary state from the operator function itself.\n */\nexport class OperatorSubscriber extends Subscriber {\n /**\n * Creates an instance of an `OperatorSubscriber`.\n * @param destination The downstream subscriber.\n * @param onNext Handles next values, only called if this subscriber is not stopped or closed. Any\n * error that occurs in this function is caught and sent to the `error` method of this subscriber.\n * @param onError Handles errors from the subscription, any errors that occur in this handler are caught\n * and send to the `destination` error handler.\n * @param onComplete Handles completion notification from the subscription. Any errors that occur in\n * this handler are sent to the `destination` error handler.\n * @param onFinalize Additional finalization logic here. This will only be called on finalization if the\n * subscriber itself is not already closed. This is called after all other finalization logic is executed.\n * @param shouldUnsubscribe An optional check to see if an unsubscribe call should truly unsubscribe.\n * NOTE: This currently **ONLY** exists to support the strange behavior of {@link groupBy}, where unsubscription\n * to the resulting observable does not actually disconnect from the source if there are active subscriptions\n * to any grouped observable. (DO NOT EXPOSE OR USE EXTERNALLY!!!)\n */\n constructor(\n destination: Subscriber,\n onNext?: (value: T) => void,\n onComplete?: () => void,\n onError?: (err: any) => void,\n private onFinalize?: () => void,\n private shouldUnsubscribe?: () => boolean\n ) {\n // It's important - for performance reasons - that all of this class's\n // members are initialized and that they are always initialized in the same\n // order. This will ensure that all OperatorSubscriber instances have the\n // same hidden class in V8. This, in turn, will help keep the number of\n // hidden classes involved in property accesses within the base class as\n // low as possible. If the number of hidden classes involved exceeds four,\n // the property accesses will become megamorphic and performance penalties\n // will be incurred - i.e. inline caches won't be used.\n //\n // The reasons for ensuring all instances have the same hidden class are\n // further discussed in this blog post from Benedikt Meurer:\n // https://benediktmeurer.de/2018/03/23/impact-of-polymorphism-on-component-based-frameworks-like-react/\n super(destination);\n this._next = onNext\n ? function (this: OperatorSubscriber, value: T) {\n try {\n onNext(value);\n } catch (err) {\n destination.error(err);\n }\n }\n : super._next;\n this._error = onError\n ? function (this: OperatorSubscriber, err: any) {\n try {\n onError(err);\n } catch (err) {\n // Send any errors that occur down stream.\n destination.error(err);\n } finally {\n // Ensure finalization.\n this.unsubscribe();\n }\n }\n : super._error;\n this._complete = onComplete\n ? function (this: OperatorSubscriber) {\n try {\n onComplete();\n } catch (err) {\n // Send any errors that occur down stream.\n destination.error(err);\n } finally {\n // Ensure finalization.\n this.unsubscribe();\n }\n }\n : super._complete;\n }\n\n unsubscribe() {\n if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {\n const { closed } = this;\n super.unsubscribe();\n // Execute additional teardown if we have any and we didn't already do so.\n !closed && this.onFinalize?.();\n }\n }\n}\n", "import { Subscription } from '../Subscription';\n\ninterface AnimationFrameProvider {\n schedule(callback: FrameRequestCallback): Subscription;\n requestAnimationFrame: typeof requestAnimationFrame;\n cancelAnimationFrame: typeof cancelAnimationFrame;\n delegate:\n | {\n requestAnimationFrame: typeof requestAnimationFrame;\n cancelAnimationFrame: typeof cancelAnimationFrame;\n }\n | undefined;\n}\n\nexport const animationFrameProvider: AnimationFrameProvider = {\n // When accessing the delegate, use the variable rather than `this` so that\n // the functions can be called without being bound to the provider.\n schedule(callback) {\n let request = requestAnimationFrame;\n let cancel: typeof cancelAnimationFrame | undefined = cancelAnimationFrame;\n const { delegate } = animationFrameProvider;\n if (delegate) {\n request = delegate.requestAnimationFrame;\n cancel = delegate.cancelAnimationFrame;\n }\n const handle = request((timestamp) => {\n // Clear the cancel function. The request has been fulfilled, so\n // attempting to cancel the request upon unsubscription would be\n // pointless.\n cancel = undefined;\n callback(timestamp);\n });\n return new Subscription(() => cancel?.(handle));\n },\n requestAnimationFrame(...args) {\n const { delegate } = animationFrameProvider;\n return (delegate?.requestAnimationFrame || requestAnimationFrame)(...args);\n },\n cancelAnimationFrame(...args) {\n const { delegate } = animationFrameProvider;\n return (delegate?.cancelAnimationFrame || cancelAnimationFrame)(...args);\n },\n delegate: undefined,\n};\n", "import { createErrorClass } from './createErrorClass';\n\nexport interface ObjectUnsubscribedError extends Error {}\n\nexport interface ObjectUnsubscribedErrorCtor {\n /**\n * @deprecated Internal implementation detail. Do not construct error instances.\n * Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269\n */\n new (): ObjectUnsubscribedError;\n}\n\n/**\n * An error thrown when an action is invalid because the object has been\n * unsubscribed.\n *\n * @see {@link Subject}\n * @see {@link BehaviorSubject}\n *\n * @class ObjectUnsubscribedError\n */\nexport const ObjectUnsubscribedError: ObjectUnsubscribedErrorCtor = createErrorClass(\n (_super) =>\n function ObjectUnsubscribedErrorImpl(this: any) {\n _super(this);\n this.name = 'ObjectUnsubscribedError';\n this.message = 'object unsubscribed';\n }\n);\n", "import { Operator } from './Operator';\nimport { Observable } from './Observable';\nimport { Subscriber } from './Subscriber';\nimport { Subscription, EMPTY_SUBSCRIPTION } from './Subscription';\nimport { Observer, SubscriptionLike, TeardownLogic } from './types';\nimport { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError';\nimport { arrRemove } from './util/arrRemove';\nimport { errorContext } from './util/errorContext';\n\n/**\n * A Subject is a special type of Observable that allows values to be\n * multicasted to many Observers. Subjects are like EventEmitters.\n *\n * Every Subject is an Observable and an Observer. You can subscribe to a\n * Subject, and you can call next to feed values as well as error and complete.\n */\nexport class Subject extends Observable implements SubscriptionLike {\n closed = false;\n\n private currentObservers: Observer[] | null = null;\n\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n observers: Observer[] = [];\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n isStopped = false;\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n hasError = false;\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n thrownError: any = null;\n\n /**\n * Creates a \"subject\" by basically gluing an observer to an observable.\n *\n * @nocollapse\n * @deprecated Recommended you do not use. Will be removed at some point in the future. Plans for replacement still under discussion.\n */\n static create: (...args: any[]) => any = (destination: Observer, source: Observable): AnonymousSubject => {\n return new AnonymousSubject(destination, source);\n };\n\n constructor() {\n // NOTE: This must be here to obscure Observable's constructor.\n super();\n }\n\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n lift(operator: Operator): Observable {\n const subject = new AnonymousSubject(this, this);\n subject.operator = operator as any;\n return subject as any;\n }\n\n /** @internal */\n protected _throwIfClosed() {\n if (this.closed) {\n throw new ObjectUnsubscribedError();\n }\n }\n\n next(value: T) {\n errorContext(() => {\n this._throwIfClosed();\n if (!this.isStopped) {\n if (!this.currentObservers) {\n this.currentObservers = Array.from(this.observers);\n }\n for (const observer of this.currentObservers) {\n observer.next(value);\n }\n }\n });\n }\n\n error(err: any) {\n errorContext(() => {\n this._throwIfClosed();\n if (!this.isStopped) {\n this.hasError = this.isStopped = true;\n this.thrownError = err;\n const { observers } = this;\n while (observers.length) {\n observers.shift()!.error(err);\n }\n }\n });\n }\n\n complete() {\n errorContext(() => {\n this._throwIfClosed();\n if (!this.isStopped) {\n this.isStopped = true;\n const { observers } = this;\n while (observers.length) {\n observers.shift()!.complete();\n }\n }\n });\n }\n\n unsubscribe() {\n this.isStopped = this.closed = true;\n this.observers = this.currentObservers = null!;\n }\n\n get observed() {\n return this.observers?.length > 0;\n }\n\n /** @internal */\n protected _trySubscribe(subscriber: Subscriber): TeardownLogic {\n this._throwIfClosed();\n return super._trySubscribe(subscriber);\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): Subscription {\n this._throwIfClosed();\n this._checkFinalizedStatuses(subscriber);\n return this._innerSubscribe(subscriber);\n }\n\n /** @internal */\n protected _innerSubscribe(subscriber: Subscriber) {\n const { hasError, isStopped, observers } = this;\n if (hasError || isStopped) {\n return EMPTY_SUBSCRIPTION;\n }\n this.currentObservers = null;\n observers.push(subscriber);\n return new Subscription(() => {\n this.currentObservers = null;\n arrRemove(observers, subscriber);\n });\n }\n\n /** @internal */\n protected _checkFinalizedStatuses(subscriber: Subscriber) {\n const { hasError, thrownError, isStopped } = this;\n if (hasError) {\n subscriber.error(thrownError);\n } else if (isStopped) {\n subscriber.complete();\n }\n }\n\n /**\n * Creates a new Observable with this Subject as the source. You can do this\n * to create custom Observer-side logic of the Subject and conceal it from\n * code that uses the Observable.\n * @return {Observable} Observable that the Subject casts to\n */\n asObservable(): Observable {\n const observable: any = new Observable();\n observable.source = this;\n return observable;\n }\n}\n\n/**\n * @class AnonymousSubject\n */\nexport class AnonymousSubject extends Subject {\n constructor(\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n public destination?: Observer,\n source?: Observable\n ) {\n super();\n this.source = source;\n }\n\n next(value: T) {\n this.destination?.next?.(value);\n }\n\n error(err: any) {\n this.destination?.error?.(err);\n }\n\n complete() {\n this.destination?.complete?.();\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): Subscription {\n return this.source?.subscribe(subscriber) ?? EMPTY_SUBSCRIPTION;\n }\n}\n", "import { Subject } from './Subject';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\n\n/**\n * A variant of Subject that requires an initial value and emits its current\n * value whenever it is subscribed to.\n *\n * @class BehaviorSubject\n */\nexport class BehaviorSubject extends Subject {\n constructor(private _value: T) {\n super();\n }\n\n get value(): T {\n return this.getValue();\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): Subscription {\n const subscription = super._subscribe(subscriber);\n !subscription.closed && subscriber.next(this._value);\n return subscription;\n }\n\n getValue(): T {\n const { hasError, thrownError, _value } = this;\n if (hasError) {\n throw thrownError;\n }\n this._throwIfClosed();\n return _value;\n }\n\n next(value: T): void {\n super.next((this._value = value));\n }\n}\n", "import { TimestampProvider } from '../types';\n\ninterface DateTimestampProvider extends TimestampProvider {\n delegate: TimestampProvider | undefined;\n}\n\nexport const dateTimestampProvider: DateTimestampProvider = {\n now() {\n // Use the variable rather than `this` so that the function can be called\n // without being bound to the provider.\n return (dateTimestampProvider.delegate || Date).now();\n },\n delegate: undefined,\n};\n", "import { Subject } from './Subject';\nimport { TimestampProvider } from './types';\nimport { Subscriber } from './Subscriber';\nimport { Subscription } from './Subscription';\nimport { dateTimestampProvider } from './scheduler/dateTimestampProvider';\n\n/**\n * A variant of {@link Subject} that \"replays\" old values to new subscribers by emitting them when they first subscribe.\n *\n * `ReplaySubject` has an internal buffer that will store a specified number of values that it has observed. Like `Subject`,\n * `ReplaySubject` \"observes\" values by having them passed to its `next` method. When it observes a value, it will store that\n * value for a time determined by the configuration of the `ReplaySubject`, as passed to its constructor.\n *\n * When a new subscriber subscribes to the `ReplaySubject` instance, it will synchronously emit all values in its buffer in\n * a First-In-First-Out (FIFO) manner. The `ReplaySubject` will also complete, if it has observed completion; and it will\n * error if it has observed an error.\n *\n * There are two main configuration items to be concerned with:\n *\n * 1. `bufferSize` - This will determine how many items are stored in the buffer, defaults to infinite.\n * 2. `windowTime` - The amount of time to hold a value in the buffer before removing it from the buffer.\n *\n * Both configurations may exist simultaneously. So if you would like to buffer a maximum of 3 values, as long as the values\n * are less than 2 seconds old, you could do so with a `new ReplaySubject(3, 2000)`.\n *\n * ### Differences with BehaviorSubject\n *\n * `BehaviorSubject` is similar to `new ReplaySubject(1)`, with a couple of exceptions:\n *\n * 1. `BehaviorSubject` comes \"primed\" with a single value upon construction.\n * 2. `ReplaySubject` will replay values, even after observing an error, where `BehaviorSubject` will not.\n *\n * @see {@link Subject}\n * @see {@link BehaviorSubject}\n * @see {@link shareReplay}\n */\nexport class ReplaySubject extends Subject {\n private _buffer: (T | number)[] = [];\n private _infiniteTimeWindow = true;\n\n /**\n * @param bufferSize The size of the buffer to replay on subscription\n * @param windowTime The amount of time the buffered items will stay buffered\n * @param timestampProvider An object with a `now()` method that provides the current timestamp. This is used to\n * calculate the amount of time something has been buffered.\n */\n constructor(\n private _bufferSize = Infinity,\n private _windowTime = Infinity,\n private _timestampProvider: TimestampProvider = dateTimestampProvider\n ) {\n super();\n this._infiniteTimeWindow = _windowTime === Infinity;\n this._bufferSize = Math.max(1, _bufferSize);\n this._windowTime = Math.max(1, _windowTime);\n }\n\n next(value: T): void {\n const { isStopped, _buffer, _infiniteTimeWindow, _timestampProvider, _windowTime } = this;\n if (!isStopped) {\n _buffer.push(value);\n !_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime);\n }\n this._trimBuffer();\n super.next(value);\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): Subscription {\n this._throwIfClosed();\n this._trimBuffer();\n\n const subscription = this._innerSubscribe(subscriber);\n\n const { _infiniteTimeWindow, _buffer } = this;\n // We use a copy here, so reentrant code does not mutate our array while we're\n // emitting it to a new subscriber.\n const copy = _buffer.slice();\n for (let i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) {\n subscriber.next(copy[i] as T);\n }\n\n this._checkFinalizedStatuses(subscriber);\n\n return subscription;\n }\n\n private _trimBuffer() {\n const { _bufferSize, _timestampProvider, _buffer, _infiniteTimeWindow } = this;\n // If we don't have an infinite buffer size, and we're over the length,\n // use splice to truncate the old buffer values off. Note that we have to\n // double the size for instances where we're not using an infinite time window\n // because we're storing the values and the timestamps in the same array.\n const adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize;\n _bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize);\n\n // Now, if we're not in an infinite time window, remove all values where the time is\n // older than what is allowed.\n if (!_infiniteTimeWindow) {\n const now = _timestampProvider.now();\n let last = 0;\n // Search the array for the first timestamp that isn't expired and\n // truncate the buffer up to that point.\n for (let i = 1; i < _buffer.length && (_buffer[i] as number) <= now; i += 2) {\n last = i;\n }\n last && _buffer.splice(0, last + 1);\n }\n }\n}\n", "import { Scheduler } from '../Scheduler';\nimport { Subscription } from '../Subscription';\nimport { SchedulerAction } from '../types';\n\n/**\n * A unit of work to be executed in a `scheduler`. An action is typically\n * created from within a {@link SchedulerLike} and an RxJS user does not need to concern\n * themselves about creating and manipulating an Action.\n *\n * ```ts\n * class Action extends Subscription {\n * new (scheduler: Scheduler, work: (state?: T) => void);\n * schedule(state?: T, delay: number = 0): Subscription;\n * }\n * ```\n *\n * @class Action\n */\nexport class Action extends Subscription {\n constructor(scheduler: Scheduler, work: (this: SchedulerAction, state?: T) => void) {\n super();\n }\n /**\n * Schedules this action on its parent {@link SchedulerLike} for execution. May be passed\n * some context object, `state`. May happen at some point in the future,\n * according to the `delay` parameter, if specified.\n * @param {T} [state] Some contextual data that the `work` function uses when\n * called by the Scheduler.\n * @param {number} [delay] Time to wait before executing the work, where the\n * time unit is implicit and defined by the Scheduler.\n * @return {void}\n */\n public schedule(state?: T, delay: number = 0): Subscription {\n return this;\n }\n}\n", "import type { TimerHandle } from './timerHandle';\ntype SetIntervalFunction = (handler: () => void, timeout?: number, ...args: any[]) => TimerHandle;\ntype ClearIntervalFunction = (handle: TimerHandle) => void;\n\ninterface IntervalProvider {\n setInterval: SetIntervalFunction;\n clearInterval: ClearIntervalFunction;\n delegate:\n | {\n setInterval: SetIntervalFunction;\n clearInterval: ClearIntervalFunction;\n }\n | undefined;\n}\n\nexport const intervalProvider: IntervalProvider = {\n // When accessing the delegate, use the variable rather than `this` so that\n // the functions can be called without being bound to the provider.\n setInterval(handler: () => void, timeout?: number, ...args) {\n const { delegate } = intervalProvider;\n if (delegate?.setInterval) {\n return delegate.setInterval(handler, timeout, ...args);\n }\n return setInterval(handler, timeout, ...args);\n },\n clearInterval(handle) {\n const { delegate } = intervalProvider;\n return (delegate?.clearInterval || clearInterval)(handle as any);\n },\n delegate: undefined,\n};\n", "import { Action } from './Action';\nimport { SchedulerAction } from '../types';\nimport { Subscription } from '../Subscription';\nimport { AsyncScheduler } from './AsyncScheduler';\nimport { intervalProvider } from './intervalProvider';\nimport { arrRemove } from '../util/arrRemove';\nimport { TimerHandle } from './timerHandle';\n\nexport class AsyncAction extends Action {\n public id: TimerHandle | undefined;\n public state?: T;\n // @ts-ignore: Property has no initializer and is not definitely assigned\n public delay: number;\n protected pending: boolean = false;\n\n constructor(protected scheduler: AsyncScheduler, protected work: (this: SchedulerAction, state?: T) => void) {\n super(scheduler, work);\n }\n\n public schedule(state?: T, delay: number = 0): Subscription {\n if (this.closed) {\n return this;\n }\n\n // Always replace the current state with the new state.\n this.state = state;\n\n const id = this.id;\n const scheduler = this.scheduler;\n\n //\n // Important implementation note:\n //\n // Actions only execute once by default, unless rescheduled from within the\n // scheduled callback. This allows us to implement single and repeat\n // actions via the same code path, without adding API surface area, as well\n // as mimic traditional recursion but across asynchronous boundaries.\n //\n // However, JS runtimes and timers distinguish between intervals achieved by\n // serial `setTimeout` calls vs. a single `setInterval` call. An interval of\n // serial `setTimeout` calls can be individually delayed, which delays\n // scheduling the next `setTimeout`, and so on. `setInterval` attempts to\n // guarantee the interval callback will be invoked more precisely to the\n // interval period, regardless of load.\n //\n // Therefore, we use `setInterval` to schedule single and repeat actions.\n // If the action reschedules itself with the same delay, the interval is not\n // canceled. If the action doesn't reschedule, or reschedules with a\n // different delay, the interval will be canceled after scheduled callback\n // execution.\n //\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, delay);\n }\n\n // Set the pending flag indicating that this action has been scheduled, or\n // has recursively rescheduled itself.\n this.pending = true;\n\n this.delay = delay;\n // If this action has already an async Id, don't request a new one.\n this.id = this.id ?? this.requestAsyncId(scheduler, this.id, delay);\n\n return this;\n }\n\n protected requestAsyncId(scheduler: AsyncScheduler, _id?: TimerHandle, delay: number = 0): TimerHandle {\n return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);\n }\n\n protected recycleAsyncId(_scheduler: AsyncScheduler, id?: TimerHandle, delay: number | null = 0): TimerHandle | undefined {\n // If this action is rescheduled with the same delay time, don't clear the interval id.\n if (delay != null && this.delay === delay && this.pending === false) {\n return id;\n }\n // Otherwise, if the action's delay time is different from the current delay,\n // or the action has been rescheduled before it's executed, clear the interval id\n if (id != null) {\n intervalProvider.clearInterval(id);\n }\n\n return undefined;\n }\n\n /**\n * Immediately executes this action and the `work` it contains.\n * @return {any}\n */\n public execute(state: T, delay: number): any {\n if (this.closed) {\n return new Error('executing a cancelled action');\n }\n\n this.pending = false;\n const error = this._execute(state, delay);\n if (error) {\n return error;\n } else if (this.pending === false && this.id != null) {\n // Dequeue if the action didn't reschedule itself. Don't call\n // unsubscribe(), because the action could reschedule later.\n // For example:\n // ```\n // scheduler.schedule(function doWork(counter) {\n // /* ... I'm a busy worker bee ... */\n // var originalAction = this;\n // /* wait 100ms before rescheduling the action */\n // setTimeout(function () {\n // originalAction.schedule(counter + 1);\n // }, 100);\n // }, 1000);\n // ```\n this.id = this.recycleAsyncId(this.scheduler, this.id, null);\n }\n }\n\n protected _execute(state: T, _delay: number): any {\n let errored: boolean = false;\n let errorValue: any;\n try {\n this.work(state);\n } catch (e) {\n errored = true;\n // HACK: Since code elsewhere is relying on the \"truthiness\" of the\n // return here, we can't have it return \"\" or 0 or false.\n // TODO: Clean this up when we refactor schedulers mid-version-8 or so.\n errorValue = e ? e : new Error('Scheduled action threw falsy error');\n }\n if (errored) {\n this.unsubscribe();\n return errorValue;\n }\n }\n\n unsubscribe() {\n if (!this.closed) {\n const { id, scheduler } = this;\n const { actions } = scheduler;\n\n this.work = this.state = this.scheduler = null!;\n this.pending = false;\n\n arrRemove(actions, this);\n if (id != null) {\n this.id = this.recycleAsyncId(scheduler, id, null);\n }\n\n this.delay = null!;\n super.unsubscribe();\n }\n }\n}\n", "import { Action } from './scheduler/Action';\nimport { Subscription } from './Subscription';\nimport { SchedulerLike, SchedulerAction } from './types';\nimport { dateTimestampProvider } from './scheduler/dateTimestampProvider';\n\n/**\n * An execution context and a data structure to order tasks and schedule their\n * execution. Provides a notion of (potentially virtual) time, through the\n * `now()` getter method.\n *\n * Each unit of work in a Scheduler is called an `Action`.\n *\n * ```ts\n * class Scheduler {\n * now(): number;\n * schedule(work, delay?, state?): Subscription;\n * }\n * ```\n *\n * @class Scheduler\n * @deprecated Scheduler is an internal implementation detail of RxJS, and\n * should not be used directly. Rather, create your own class and implement\n * {@link SchedulerLike}. Will be made internal in v8.\n */\nexport class Scheduler implements SchedulerLike {\n public static now: () => number = dateTimestampProvider.now;\n\n constructor(private schedulerActionCtor: typeof Action, now: () => number = Scheduler.now) {\n this.now = now;\n }\n\n /**\n * A getter method that returns a number representing the current time\n * (at the time this function was called) according to the scheduler's own\n * internal clock.\n * @return {number} A number that represents the current time. May or may not\n * have a relation to wall-clock time. May or may not refer to a time unit\n * (e.g. milliseconds).\n */\n public now: () => number;\n\n /**\n * Schedules a function, `work`, for execution. May happen at some point in\n * the future, according to the `delay` parameter, if specified. May be passed\n * some context object, `state`, which will be passed to the `work` function.\n *\n * The given arguments will be processed an stored as an Action object in a\n * queue of actions.\n *\n * @param {function(state: ?T): ?Subscription} work A function representing a\n * task, or some unit of work to be executed by the Scheduler.\n * @param {number} [delay] Time to wait before executing the work, where the\n * time unit is implicit and defined by the Scheduler itself.\n * @param {T} [state] Some contextual data that the `work` function uses when\n * called by the Scheduler.\n * @return {Subscription} A subscription in order to be able to unsubscribe\n * the scheduled work.\n */\n public schedule(work: (this: SchedulerAction, state?: T) => void, delay: number = 0, state?: T): Subscription {\n return new this.schedulerActionCtor(this, work).schedule(state, delay);\n }\n}\n", "import { Scheduler } from '../Scheduler';\nimport { Action } from './Action';\nimport { AsyncAction } from './AsyncAction';\nimport { TimerHandle } from './timerHandle';\n\nexport class AsyncScheduler extends Scheduler {\n public actions: Array> = [];\n /**\n * A flag to indicate whether the Scheduler is currently executing a batch of\n * queued actions.\n * @type {boolean}\n * @internal\n */\n public _active: boolean = false;\n /**\n * An internal ID used to track the latest asynchronous task such as those\n * coming from `setTimeout`, `setInterval`, `requestAnimationFrame`, and\n * others.\n * @type {any}\n * @internal\n */\n public _scheduled: TimerHandle | undefined;\n\n constructor(SchedulerAction: typeof Action, now: () => number = Scheduler.now) {\n super(SchedulerAction, now);\n }\n\n public flush(action: AsyncAction): void {\n const { actions } = this;\n\n if (this._active) {\n actions.push(action);\n return;\n }\n\n let error: any;\n this._active = true;\n\n do {\n if ((error = action.execute(action.state, action.delay))) {\n break;\n }\n } while ((action = actions.shift()!)); // exhaust the scheduler queue\n\n this._active = false;\n\n if (error) {\n while ((action = actions.shift()!)) {\n action.unsubscribe();\n }\n throw error;\n }\n }\n}\n", "import { AsyncAction } from './AsyncAction';\nimport { AsyncScheduler } from './AsyncScheduler';\n\n/**\n *\n * Async Scheduler\n *\n * Schedule task as if you used setTimeout(task, duration)\n *\n * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript\n * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating\n * in intervals.\n *\n * If you just want to \"defer\" task, that is to perform it right after currently\n * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),\n * better choice will be the {@link asapScheduler} scheduler.\n *\n * ## Examples\n * Use async scheduler to delay task\n * ```ts\n * import { asyncScheduler } from 'rxjs';\n *\n * const task = () => console.log('it works!');\n *\n * asyncScheduler.schedule(task, 2000);\n *\n * // After 2 seconds logs:\n * // \"it works!\"\n * ```\n *\n * Use async scheduler to repeat task in intervals\n * ```ts\n * import { asyncScheduler } from 'rxjs';\n *\n * function task(state) {\n * console.log(state);\n * this.schedule(state + 1, 1000); // `this` references currently executing Action,\n * // which we reschedule with new state and delay\n * }\n *\n * asyncScheduler.schedule(task, 3000, 0);\n *\n * // Logs:\n * // 0 after 3s\n * // 1 after 4s\n * // 2 after 5s\n * // 3 after 6s\n * ```\n */\n\nexport const asyncScheduler = new AsyncScheduler(AsyncAction);\n\n/**\n * @deprecated Renamed to {@link asyncScheduler}. Will be removed in v8.\n */\nexport const async = asyncScheduler;\n", "import { AsyncAction } from './AsyncAction';\nimport { Subscription } from '../Subscription';\nimport { QueueScheduler } from './QueueScheduler';\nimport { SchedulerAction } from '../types';\nimport { TimerHandle } from './timerHandle';\n\nexport class QueueAction extends AsyncAction {\n constructor(protected scheduler: QueueScheduler, protected work: (this: SchedulerAction, state?: T) => void) {\n super(scheduler, work);\n }\n\n public schedule(state?: T, delay: number = 0): Subscription {\n if (delay > 0) {\n return super.schedule(state, delay);\n }\n this.delay = delay;\n this.state = state;\n this.scheduler.flush(this);\n return this;\n }\n\n public execute(state: T, delay: number): any {\n return delay > 0 || this.closed ? super.execute(state, delay) : this._execute(state, delay);\n }\n\n protected requestAsyncId(scheduler: QueueScheduler, id?: TimerHandle, delay: number = 0): TimerHandle {\n // If delay exists and is greater than 0, or if the delay is null (the\n // action wasn't rescheduled) but was originally scheduled as an async\n // action, then recycle as an async action.\n\n if ((delay != null && delay > 0) || (delay == null && this.delay > 0)) {\n return super.requestAsyncId(scheduler, id, delay);\n }\n\n // Otherwise flush the scheduler starting with this action.\n scheduler.flush(this);\n\n // HACK: In the past, this was returning `void`. However, `void` isn't a valid\n // `TimerHandle`, and generally the return value here isn't really used. So the\n // compromise is to return `0` which is both \"falsy\" and a valid `TimerHandle`,\n // as opposed to refactoring every other instanceo of `requestAsyncId`.\n return 0;\n }\n}\n", "import { AsyncScheduler } from './AsyncScheduler';\n\nexport class QueueScheduler extends AsyncScheduler {\n}\n", "import { QueueAction } from './QueueAction';\nimport { QueueScheduler } from './QueueScheduler';\n\n/**\n *\n * Queue Scheduler\n *\n * Put every next task on a queue, instead of executing it immediately\n *\n * `queue` scheduler, when used with delay, behaves the same as {@link asyncScheduler} scheduler.\n *\n * When used without delay, it schedules given task synchronously - executes it right when\n * it is scheduled. However when called recursively, that is when inside the scheduled task,\n * another task is scheduled with queue scheduler, instead of executing immediately as well,\n * that task will be put on a queue and wait for current one to finish.\n *\n * This means that when you execute task with `queue` scheduler, you are sure it will end\n * before any other task scheduled with that scheduler will start.\n *\n * ## Examples\n * Schedule recursively first, then do something\n * ```ts\n * import { queueScheduler } from 'rxjs';\n *\n * queueScheduler.schedule(() => {\n * queueScheduler.schedule(() => console.log('second')); // will not happen now, but will be put on a queue\n *\n * console.log('first');\n * });\n *\n * // Logs:\n * // \"first\"\n * // \"second\"\n * ```\n *\n * Reschedule itself recursively\n * ```ts\n * import { queueScheduler } from 'rxjs';\n *\n * queueScheduler.schedule(function(state) {\n * if (state !== 0) {\n * console.log('before', state);\n * this.schedule(state - 1); // `this` references currently executing Action,\n * // which we reschedule with new state\n * console.log('after', state);\n * }\n * }, 0, 3);\n *\n * // In scheduler that runs recursively, you would expect:\n * // \"before\", 3\n * // \"before\", 2\n * // \"before\", 1\n * // \"after\", 1\n * // \"after\", 2\n * // \"after\", 3\n *\n * // But with queue it logs:\n * // \"before\", 3\n * // \"after\", 3\n * // \"before\", 2\n * // \"after\", 2\n * // \"before\", 1\n * // \"after\", 1\n * ```\n */\n\nexport const queueScheduler = new QueueScheduler(QueueAction);\n\n/**\n * @deprecated Renamed to {@link queueScheduler}. Will be removed in v8.\n */\nexport const queue = queueScheduler;\n", "import { AsyncAction } from './AsyncAction';\nimport { AnimationFrameScheduler } from './AnimationFrameScheduler';\nimport { SchedulerAction } from '../types';\nimport { animationFrameProvider } from './animationFrameProvider';\nimport { TimerHandle } from './timerHandle';\n\nexport class AnimationFrameAction extends AsyncAction {\n constructor(protected scheduler: AnimationFrameScheduler, protected work: (this: SchedulerAction, state?: T) => void) {\n super(scheduler, work);\n }\n\n protected requestAsyncId(scheduler: AnimationFrameScheduler, id?: TimerHandle, delay: number = 0): TimerHandle {\n // If delay is greater than 0, request as an async action.\n if (delay !== null && delay > 0) {\n return super.requestAsyncId(scheduler, id, delay);\n }\n // Push the action to the end of the scheduler queue.\n scheduler.actions.push(this);\n // If an animation frame has already been requested, don't request another\n // one. If an animation frame hasn't been requested yet, request one. Return\n // the current animation frame request id.\n return scheduler._scheduled || (scheduler._scheduled = animationFrameProvider.requestAnimationFrame(() => scheduler.flush(undefined)));\n }\n\n protected recycleAsyncId(scheduler: AnimationFrameScheduler, id?: TimerHandle, delay: number = 0): TimerHandle | undefined {\n // If delay exists and is greater than 0, or if the delay is null (the\n // action wasn't rescheduled) but was originally scheduled as an async\n // action, then recycle as an async action.\n if (delay != null ? delay > 0 : this.delay > 0) {\n return super.recycleAsyncId(scheduler, id, delay);\n }\n // If the scheduler queue has no remaining actions with the same async id,\n // cancel the requested animation frame and set the scheduled flag to\n // undefined so the next AnimationFrameAction will request its own.\n const { actions } = scheduler;\n if (id != null && actions[actions.length - 1]?.id !== id) {\n animationFrameProvider.cancelAnimationFrame(id as number);\n scheduler._scheduled = undefined;\n }\n // Return undefined so the action knows to request a new async id if it's rescheduled.\n return undefined;\n }\n}\n", "import { AsyncAction } from './AsyncAction';\nimport { AsyncScheduler } from './AsyncScheduler';\n\nexport class AnimationFrameScheduler extends AsyncScheduler {\n public flush(action?: AsyncAction): void {\n this._active = true;\n // The async id that effects a call to flush is stored in _scheduled.\n // Before executing an action, it's necessary to check the action's async\n // id to determine whether it's supposed to be executed in the current\n // flush.\n // Previous implementations of this method used a count to determine this,\n // but that was unsound, as actions that are unsubscribed - i.e. cancelled -\n // are removed from the actions array and that can shift actions that are\n // scheduled to be executed in a subsequent flush into positions at which\n // they are executed within the current flush.\n const flushId = this._scheduled;\n this._scheduled = undefined;\n\n const { actions } = this;\n let error: any;\n action = action || actions.shift()!;\n\n do {\n if ((error = action.execute(action.state, action.delay))) {\n break;\n }\n } while ((action = actions[0]) && action.id === flushId && actions.shift());\n\n this._active = false;\n\n if (error) {\n while ((action = actions[0]) && action.id === flushId && actions.shift()) {\n action.unsubscribe();\n }\n throw error;\n }\n }\n}\n", "import { AnimationFrameAction } from './AnimationFrameAction';\nimport { AnimationFrameScheduler } from './AnimationFrameScheduler';\n\n/**\n *\n * Animation Frame Scheduler\n *\n * Perform task when `window.requestAnimationFrame` would fire\n *\n * When `animationFrame` scheduler is used with delay, it will fall back to {@link asyncScheduler} scheduler\n * behaviour.\n *\n * Without delay, `animationFrame` scheduler can be used to create smooth browser animations.\n * It makes sure scheduled task will happen just before next browser content repaint,\n * thus performing animations as efficiently as possible.\n *\n * ## Example\n * Schedule div height animation\n * ```ts\n * // html:
                                                          \n * import { animationFrameScheduler } from 'rxjs';\n *\n * const div = document.querySelector('div');\n *\n * animationFrameScheduler.schedule(function(height) {\n * div.style.height = height + \"px\";\n *\n * this.schedule(height + 1); // `this` references currently executing Action,\n * // which we reschedule with new state\n * }, 0, 0);\n *\n * // You will see a div element growing in height\n * ```\n */\n\nexport const animationFrameScheduler = new AnimationFrameScheduler(AnimationFrameAction);\n\n/**\n * @deprecated Renamed to {@link animationFrameScheduler}. Will be removed in v8.\n */\nexport const animationFrame = animationFrameScheduler;\n", "import { Observable } from '../Observable';\nimport { SchedulerLike } from '../types';\n\n/**\n * A simple Observable that emits no items to the Observer and immediately\n * emits a complete notification.\n *\n * Just emits 'complete', and nothing else.\n *\n * ![](empty.png)\n *\n * A simple Observable that only emits the complete notification. It can be used\n * for composing with other Observables, such as in a {@link mergeMap}.\n *\n * ## Examples\n *\n * Log complete notification\n *\n * ```ts\n * import { EMPTY } from 'rxjs';\n *\n * EMPTY.subscribe({\n * next: () => console.log('Next'),\n * complete: () => console.log('Complete!')\n * });\n *\n * // Outputs\n * // Complete!\n * ```\n *\n * Emit the number 7, then complete\n *\n * ```ts\n * import { EMPTY, startWith } from 'rxjs';\n *\n * const result = EMPTY.pipe(startWith(7));\n * result.subscribe(x => console.log(x));\n *\n * // Outputs\n * // 7\n * ```\n *\n * Map and flatten only odd numbers to the sequence `'a'`, `'b'`, `'c'`\n *\n * ```ts\n * import { interval, mergeMap, of, EMPTY } from 'rxjs';\n *\n * const interval$ = interval(1000);\n * const result = interval$.pipe(\n * mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : EMPTY),\n * );\n * result.subscribe(x => console.log(x));\n *\n * // Results in the following to the console:\n * // x is equal to the count on the interval, e.g. (0, 1, 2, 3, ...)\n * // x will occur every 1000ms\n * // if x % 2 is equal to 1, print a, b, c (each on its own)\n * // if x % 2 is not equal to 1, nothing will be output\n * ```\n *\n * @see {@link Observable}\n * @see {@link NEVER}\n * @see {@link of}\n * @see {@link throwError}\n */\nexport const EMPTY = new Observable((subscriber) => subscriber.complete());\n\n/**\n * @param scheduler A {@link SchedulerLike} to use for scheduling\n * the emission of the complete notification.\n * @deprecated Replaced with the {@link EMPTY} constant or {@link scheduled} (e.g. `scheduled([], scheduler)`). Will be removed in v8.\n */\nexport function empty(scheduler?: SchedulerLike) {\n return scheduler ? emptyScheduled(scheduler) : EMPTY;\n}\n\nfunction emptyScheduled(scheduler: SchedulerLike) {\n return new Observable((subscriber) => scheduler.schedule(() => subscriber.complete()));\n}\n", "import { SchedulerLike } from '../types';\nimport { isFunction } from './isFunction';\n\nexport function isScheduler(value: any): value is SchedulerLike {\n return value && isFunction(value.schedule);\n}\n", "import { SchedulerLike } from '../types';\nimport { isFunction } from './isFunction';\nimport { isScheduler } from './isScheduler';\n\nfunction last(arr: T[]): T | undefined {\n return arr[arr.length - 1];\n}\n\nexport function popResultSelector(args: any[]): ((...args: unknown[]) => unknown) | undefined {\n return isFunction(last(args)) ? args.pop() : undefined;\n}\n\nexport function popScheduler(args: any[]): SchedulerLike | undefined {\n return isScheduler(last(args)) ? args.pop() : undefined;\n}\n\nexport function popNumber(args: any[], defaultValue: number): number {\n return typeof last(args) === 'number' ? args.pop()! : defaultValue;\n}\n", "export const isArrayLike = ((x: any): x is ArrayLike => x && typeof x.length === 'number' && typeof x !== 'function');", "import { isFunction } from \"./isFunction\";\n\n/**\n * Tests to see if the object is \"thennable\".\n * @param value the object to test\n */\nexport function isPromise(value: any): value is PromiseLike {\n return isFunction(value?.then);\n}\n", "import { InteropObservable } from '../types';\nimport { observable as Symbol_observable } from '../symbol/observable';\nimport { isFunction } from './isFunction';\n\n/** Identifies an input as being Observable (but not necessary an Rx Observable) */\nexport function isInteropObservable(input: any): input is InteropObservable {\n return isFunction(input[Symbol_observable]);\n}\n", "import { isFunction } from './isFunction';\n\nexport function isAsyncIterable(obj: any): obj is AsyncIterable {\n return Symbol.asyncIterator && isFunction(obj?.[Symbol.asyncIterator]);\n}\n", "/**\n * Creates the TypeError to throw if an invalid object is passed to `from` or `scheduled`.\n * @param input The object that was passed.\n */\nexport function createInvalidObservableTypeError(input: any) {\n // TODO: We should create error codes that can be looked up, so this can be less verbose.\n return new TypeError(\n `You provided ${\n input !== null && typeof input === 'object' ? 'an invalid object' : `'${input}'`\n } where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.`\n );\n}\n", "export function getSymbolIterator(): symbol {\n if (typeof Symbol !== 'function' || !Symbol.iterator) {\n return '@@iterator' as any;\n }\n\n return Symbol.iterator;\n}\n\nexport const iterator = getSymbolIterator();\n", "import { iterator as Symbol_iterator } from '../symbol/iterator';\nimport { isFunction } from './isFunction';\n\n/** Identifies an input as being an Iterable */\nexport function isIterable(input: any): input is Iterable {\n return isFunction(input?.[Symbol_iterator]);\n}\n", "import { ReadableStreamLike } from '../types';\nimport { isFunction } from './isFunction';\n\nexport async function* readableStreamLikeToAsyncGenerator(readableStream: ReadableStreamLike): AsyncGenerator {\n const reader = readableStream.getReader();\n try {\n while (true) {\n const { value, done } = await reader.read();\n if (done) {\n return;\n }\n yield value!;\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nexport function isReadableStreamLike(obj: any): obj is ReadableStreamLike {\n // We don't want to use instanceof checks because they would return\n // false for instances from another Realm, like an + +

                                                          Changing the Brightness of the Building LED

                                                          +

                                                          We can change the brightness of the builtin LED by using the POT value to change the PWM duty cycle.

                                                          +

                                                          Here is a sample progam that does this:

                                                          +
                                                           1
                                                          + 2
                                                          + 3
                                                          + 4
                                                          + 5
                                                          + 6
                                                          + 7
                                                          + 8
                                                          + 9
                                                          +10
                                                          +11
                                                          +12
                                                          +13
                                                          +14
                                                          +15
                                                          +16
                                                          +17
                                                          +18
                                                          +19
                                                          +20
                                                          from machine import ADC, Pin, PWM
                                                          +from utime import sleep
                                                          +
                                                          +# Pins Used
                                                          +BUILT_IN_LED_PIN = 25
                                                          +POT_PIN = 26
                                                          +
                                                          +pot = ADC(POT_PIN)
                                                          +
                                                          +builtin_pwm = PWM(Pin(BUILT_IN_LED_PIN))
                                                          +builtin_pwm.freq(1000) # 1K Hz
                                                          +
                                                          +POLL_DELAY = .1 # poll the pot after this delay in seconds
                                                          +
                                                          +# repeat forever
                                                          +while True:
                                                          +    pot_value = pot.read_u16() # read the value from the pot
                                                          +    print("pot value:", pot_value)
                                                          +    builtin_pwm.duty_u16(pot_value)
                                                          +    sleep(POLL_DELAY)
                                                          +
                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          + + +
                                                          +
                                                          +
                                                          + + + + + + + + + + \ No newline at end of file diff --git a/basics/04-fade-in-and-out/index.html b/basics/04-fade-in-and-out/index.html new file mode 100644 index 000000000..789f8c438 --- /dev/null +++ b/basics/04-fade-in-and-out/index.html @@ -0,0 +1,1752 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Fade In and Out - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                          + + + + Skip to content + + +
                                                          +
                                                          + +
                                                          + + + + + + +
                                                          +
                                                          + + + logo + + + +
                                                          +
                                                          +
                                                          + + MicroPython for Kids + +
                                                          +
                                                          + + + Fade In and Out + + +
                                                          +
                                                          +
                                                          + + + + + + + +
                                                          + +
                                                          +
                                                          + + +
                                                          + + +
                                                          + +
                                                          +
                                                          +
                                                          +
                                                          +
                                                          + Initializing search +
                                                          +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + + +
                                                            + +
                                                            + + +
                                                            +
                                                            + GitHub Repo +
                                                            +
                                                            +
                                                            + +
                                                            + +
                                                            + +
                                                            + + + + + + +
                                                            +
                                                            + + + +
                                                            +
                                                            +
                                                            + + + + +
                                                            + + +
                                                            + +
                                                            + + +
                                                            +
                                                            + GitHub Repo +
                                                            +
                                                            +
                                                            + +
                                                              + + + + + + + +
                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + MicroPython Home + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + +
                                                              + +
                                                                + + + + + + + +
                                                              • + + + + + Introduction + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Blink + + + + +
                                                              • + + + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + Fade In and Out + + + + + + + +
                                                                + + + + + + + +
                                                                  + +
                                                                • + + + Welcome to Pulse Width Modulation + + + +
                                                                • + +
                                                                • + + + PWM Functions + + + +
                                                                • + +
                                                                • + + + Suggested Exercises + + + +
                                                                • + +
                                                                • + + + References + + + +
                                                                  +
                                                                    + +
                                                                  • + + + Pulse With Modulation + + + +
                                                                  • + +
                                                                  +
                                                                  + +
                                                                • + +
                                                                + +
                                                                + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Buttons + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Potentiometer + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Motor + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Servo + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + NeoPixel + + + + +
                                                              • + + + + + + + + + + +
                                                              • + + + + + Wireless + + + + +
                                                              • + + + + +
                                                              +
                                                              + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + Glossary + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + References + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + Contributing + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + Contact + + + + +
                                                            • + + + + + + + + + +
                                                            • + + + + + Colophon + + + + +
                                                            • + + + +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + + + +
                                                            +
                                                            +
                                                            + + +
                                                            + + + + + + + +
                                                              + +
                                                            • + + + Welcome to Pulse Width Modulation + + + +
                                                            • + +
                                                            • + + + PWM Functions + + + +
                                                            • + +
                                                            • + + + Suggested Exercises + + + +
                                                            • + +
                                                            • + + + References + + + +
                                                              +
                                                                + +
                                                              • + + + Pulse With Modulation + + + +
                                                              • + +
                                                              +
                                                              + +
                                                            • + +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            + + + +
                                                            +
                                                            + + + + + + + +

                                                            Fade an LED in and Out

                                                            +

                                                            In the prior Blink lab, we turned an LED on an off at different speeds. But what if we want to slowly turn on our LED on and off? In this lab we will show you how to dim your LED to any brightness level you want.

                                                            +

                                                            Welcome to Pulse Width Modulation

                                                            +

                                                            PWM Duty Cycle

                                                            +

                                                            Although digital computers are good at quickly turning signals on and off, they don't really allow us to easily set an output to a given voltage level without complex circuits. But there is an easier way to adjust the brightness of an LED! We can quickly turn the signal to the LED on and off. We can do this so quickly that you can't even see it flicker. Controlling the amount of time a signal is on is all about controlling the width of the ON pulse. That is why this is called Pulse Width Modulation or PWM for short.

                                                            +

                                                            With a PWM design there are two things we need to tell the microcontroller:

                                                            +
                                                              +
                                                            1. How often do you want a square wave to go on and off?
                                                            2. +
                                                            3. How wide should the on part of the pulse be (relative to the total width). This is called the duty cycle.
                                                            4. +
                                                            +

                                                            The rate of change of the pulse is call the frequency. You can set the frequency to be 1,000 changes per second, which is much faster than the human eye can detect. This is done using the following line:

                                                            +
                                                            1
                                                            pwm.freq(1000)
                                                            +
                                                            +

                                                            Note that we can slow the frequency way down and the dimming effect will still work. As an experiment you can change the PWM frequency to around 20 and you will see a distinct flicker as the LED turns on.

                                                            +

                                                            Here is the sample program that will slowly dim the builtin LED that is on pin 25:

                                                            +
                                                             1
                                                            + 2
                                                            + 3
                                                            + 4
                                                            + 5
                                                            + 6
                                                            + 7
                                                            + 8
                                                            + 9
                                                            +10
                                                            +11
                                                            +12
                                                            +13
                                                            +14
                                                            from machine import Pin, PWM
                                                            +from time import sleep
                                                            +
                                                            +pwm = PWM(Pin(25))
                                                            +
                                                            +pwm.freq(1000)
                                                            +
                                                            +while True:
                                                            +    for duty in range(65025):
                                                            +        pwm.duty_u16(duty)
                                                            +        sleep(0.0001)
                                                            +    for duty in range(65025, 0, -1):
                                                            +        pwm.duty_u16(duty)
                                                            +        sleep(0.0001)
                                                            +
                                                            +

                                                            Note that the duty cycle starts at 0 (always off) and moves slowly up to 65,025 (always on). It then does the reverse and slowly dims the LED and then repeats. There is only a 1/10,000 of a delay between these changes so the LED will completely turn on in about six seconds before it starts to dim again.

                                                            +

                                                            PWM Functions

                                                            +

                                                            Here is a list of the PWM functions.

                                                            +
                                                            1
                                                            +2
                                                            +3
                                                            +4
                                                            +5
                                                            +6
                                                            +7
                                                            +8
                                                            from machine import Pin, PWM
                                                            +
                                                            +pwm0 = PWM(Pin(0))      # create PWM object from a pin
                                                            +pwm0.freq()             # get current frequency
                                                            +pwm0.freq(1000)         # set frequency (1000 cycles per minute)
                                                            +pwm0.duty_u16()         # get current duty cycle, range 0-65535
                                                            +pwm0.duty_u16(200)      # set duty cycle, range 0-65535
                                                            +pwm0.deinit()           # turn off PWM on the pin
                                                            +
                                                            +

                                                            Make sure you deinit() to de-initialize the PWM controller after you are done. You may have to trap the stop to do this. For example if a PWM is driving motors, your Stop must send deinit() to each motor controller. See the Interrupt Handlers for details.

                                                            +

                                                            Suggested Exercises

                                                            +
                                                              +
                                                            1. Change the frequency from 1,000 to 500, 100, 50, 40, 30, 25, 20, and 10. When can you just barley see it flicker? What does this tell you about the human eye?
                                                            2. +
                                                            3. Can you add a delay so that the LED stays on at full brightness for one second before it starts to dim again?
                                                            4. +
                                                            5. Can you add a delay so that the LED is completely off for five seconds and then goes to full brightness and off in one second?
                                                            6. +
                                                            7. What lights in your home would you like to see slowly dim on and off? How could you modify a light (safely) so that it slowly dimmed on and off. Would PWM work with all lightbulb types such as tungsten filament bulbs that take a long time to heat up and cool down?
                                                            8. +
                                                            9. Can you hook up a set of red, green and blue LEDs program them to fade in and out to display all the colors of the rainbow (red, orange, yellow, green, blue, indigo and violet)?
                                                            10. +
                                                            11. When you stop the program does the LED stop changing brightness? Does it retain the value that it had when you pressed the Stop function? What does that tell you about how main CPU and the role of PWM? Note that we will cover up doing "cleanup" events that stop all PWM activity in our Interrupt Handlers Lab
                                                            12. +
                                                            +

                                                            References

                                                            +

                                                            Pulse With Modulation

                                                            +
                                                              +
                                                            1. Wikipedia Article on Pulse With Modulation
                                                            2. +
                                                            + + + + + + + + + + + + + + + +
                                                            +
                                                            + + + +
                                                            + + + +
                                                            + +
                                                            + + + +
                                                            + + + +
                                                            + + +
                                                            +
                                                            + + Previous + +
                                                            + Blink +
                                                            +
                                                            +
                                                            + + + + +
                                                            + + Next + +
                                                            + Buttons +
                                                            +
                                                            +
                                                            + + +
                                                            +
                                                            + +
                                                            + + +
                                                            +
                                                            +
                                                            + + + Made with + + Material for MkDocs + + +
                                                            + +
                                                            +
                                                            +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            + + + + + + + + + + \ No newline at end of file diff --git a/basics/04-motor/index.html b/basics/04-motor/index.html new file mode 100644 index 000000000..119303f9f --- /dev/null +++ b/basics/04-motor/index.html @@ -0,0 +1,1714 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Motor - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                            + + + + Skip to content + + +
                                                            +
                                                            + +
                                                            + + + + + + +
                                                            +
                                                            + + + logo + + + +
                                                            +
                                                            +
                                                            + + MicroPython for Kids + +
                                                            +
                                                            + + + Motor + + +
                                                            +
                                                            +
                                                            + + + + + + + +
                                                            + +
                                                            +
                                                            + + +
                                                            + + +
                                                            + +
                                                            +
                                                            +
                                                            +
                                                            +
                                                            + Initializing search +
                                                            +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + + +
                                                              + +
                                                              + + +
                                                              +
                                                              + GitHub Repo +
                                                              +
                                                              +
                                                              + +
                                                              + +
                                                              + +
                                                              + + + + + + +
                                                              +
                                                              + + + +
                                                              +
                                                              +
                                                              + + + + +
                                                              + + +
                                                              + +
                                                              + + +
                                                              +
                                                              + GitHub Repo +
                                                              +
                                                              +
                                                              + +
                                                                + + + + + + + +
                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + MicroPython Home + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + +
                                                                + +
                                                                  + + + + + + + +
                                                                • + + + + + Introduction + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Blink + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Fade In and Out + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Buttons + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Potentiometer + + + + +
                                                                • + + + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + Motor + + + + + + + +
                                                                  + + + + + + + +
                                                                    + +
                                                                  • + + + Basic Transistor Circuit + + + +
                                                                  • + +
                                                                  • + + + PWM Control + + + +
                                                                    +
                                                                      + +
                                                                    • + + + PWM Frequency + + + +
                                                                    • + +
                                                                    +
                                                                    + +
                                                                  • + +
                                                                  • + + + Sample Coder + + + +
                                                                  • + +
                                                                  • + + + References + + + +
                                                                  • + +
                                                                  + +
                                                                  + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Servo + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + NeoPixel + + + + +
                                                                • + + + + + + + + + + +
                                                                • + + + + + Wireless + + + + +
                                                                • + + + + +
                                                                +
                                                                + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + Glossary + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + References + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + Contributing + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + Contact + + + + +
                                                              • + + + + + + + + + +
                                                              • + + + + + Colophon + + + + +
                                                              • + + + +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + + + +
                                                              +
                                                              +
                                                              + + +
                                                              + + + + + + + +
                                                                + +
                                                              • + + + Basic Transistor Circuit + + + +
                                                              • + +
                                                              • + + + PWM Control + + + +
                                                                +
                                                                  + +
                                                                • + + + PWM Frequency + + + +
                                                                • + +
                                                                +
                                                                + +
                                                              • + +
                                                              • + + + Sample Coder + + + +
                                                              • + +
                                                              • + + + References + + + +
                                                              • + +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              + + + +
                                                              +
                                                              + + + + + + + +

                                                              Driving a Motor with the Pico

                                                              +

                                                              The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the Raspberry Pi Pico Datasheet Table 5. 17 milliamps is fine for lighting up an LED. However, motors require much more power. 17 milliamps is not enough current to drive even small motors. Even our small DC hobby motors we use with our robots require around 200 milliamps.

                                                              +

                                                              But don't worry! We have two ways around this problem.

                                                              +
                                                                +
                                                              1. The first option is to use a simple transistor as a "switch" that will use our low-power digital signal to control its on-and-off settings.
                                                              2. +
                                                              3. The second option is to use a full motor driver chip such as an L293D chip. This chip takes the same PWM signal we learned about in our Fade In and Out Lab.
                                                              4. +
                                                              +

                                                              Basic Transistor Circuit

                                                              +
                                                                +
                                                              1. Transistor NPN 2222A
                                                              2. +
                                                              3. Diode: 1N1448
                                                              4. +
                                                              5. Motor: 3-6 volt hobby motor
                                                              6. +
                                                              +

                                                              Motor Circuit

                                                              +

                                                              PWM Control

                                                              +

                                                              PWM Frequency

                                                              +

                                                              Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms)

                                                              +

                                                              Sample Coder

                                                              +
                                                              1
                                                              +2
                                                              +3
                                                              +4
                                                              +5
                                                              +6
                                                              +7
                                                              +8
                                                              import machine
                                                              +
                                                              +# set the 7th from the bottom on right as our motor pin
                                                              +motor_pin = machine.Pin(21, machine.Pin.OUT)
                                                              +# allocate a PWM object for controlling the motor speed
                                                              +motor_pwm = machine.PWM(motor_pin)
                                                              +motor_pwm.freq(50) # 50 hertz
                                                              +motor_pwm.duty(51)
                                                              +
                                                              +

                                                              References

                                                              +
                                                                +
                                                              1. Sparkfun Motor Lab from SIK Kit
                                                              2. +
                                                              3. Nick Zoic MicroPython Motor Control Tutorial
                                                              4. +
                                                              + + + + + + + + + + + + + + + +
                                                              +
                                                              + + + +
                                                              + + + +
                                                              + +
                                                              + + + +
                                                              + + + +
                                                              + + +
                                                              +
                                                              + + Previous + +
                                                              + Potentiometer +
                                                              +
                                                              +
                                                              + + + + +
                                                              + + Next + +
                                                              + Servo +
                                                              +
                                                              +
                                                              + + +
                                                              +
                                                              + +
                                                              + + +
                                                              +
                                                              +
                                                              + + + Made with + + Material for MkDocs + + +
                                                              + +
                                                              +
                                                              +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              + + + + + + + + + + \ No newline at end of file diff --git a/basics/04-read-pot/index.html b/basics/04-read-pot/index.html new file mode 100644 index 000000000..81fa67a78 --- /dev/null +++ b/basics/04-read-pot/index.html @@ -0,0 +1,1329 @@ + + + + + + + + + + + + + + + + + + + + + + + Using MicroPython to Read a Potentiometer - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                              + + + + Skip to content + + +
                                                              +
                                                              + +
                                                              + + + + + + +
                                                              +
                                                              + + + logo + + + +
                                                              +
                                                              +
                                                              + + MicroPython for Kids + +
                                                              +
                                                              + + + Using MicroPython to Read a Potentiometer + + +
                                                              +
                                                              +
                                                              + + + + + + + +
                                                              + +
                                                              +
                                                              + + +
                                                              + + +
                                                              + +
                                                              +
                                                              +
                                                              +
                                                              +
                                                              + Initializing search +
                                                              +
                                                                +
                                                                +
                                                                +
                                                                +
                                                                +
                                                                + + +
                                                                + +
                                                                + + +
                                                                +
                                                                + GitHub Repo +
                                                                +
                                                                +
                                                                + +
                                                                + +
                                                                + +
                                                                + + + + + + +
                                                                +
                                                                + + + +
                                                                +
                                                                +
                                                                + + + + +
                                                                + + +
                                                                + +
                                                                + + +
                                                                +
                                                                + GitHub Repo +
                                                                +
                                                                +
                                                                + +
                                                                  + + + + + + + +
                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + MicroPython Home + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + Glossary + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + References + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + Contributing + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + Contact + + + + +
                                                                • + + + + + + + + + +
                                                                • + + + + + Colophon + + + + +
                                                                • + + + +
                                                                +
                                                                +
                                                                +
                                                                +
                                                                + + + +
                                                                +
                                                                +
                                                                + + +
                                                                + + + + + + +
                                                                +
                                                                +
                                                                +
                                                                + + + +
                                                                +
                                                                + + + + + + + +

                                                                Using MicroPython to Read a Potentiometer

                                                                +

                                                                Reading a Potentiometer

                                                                +

                                                                ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This +pin can be used with an external reference if better ADC performance is required. +AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and +terminating at this pin.

                                                                +
                                                                1
                                                                +2
                                                                +3
                                                                +4
                                                                +5
                                                                +6
                                                                +7
                                                                graph LR
                                                                +p[Pico]-->|ADC_VREF 36 row=6| pos(Positive)
                                                                +p[Pico]-->|AGND 33 row=8| neg(Negative)
                                                                +p[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)
                                                                +    pos(Positive) --- pot(Potentiometer)
                                                                +    neg(Negative) --- pot(Potentiometer)
                                                                +    tap(Center Tap) --- pot(Potentiometer)
                                                                +
                                                                +

                                                                Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.

                                                                +

                                                                Sampling data

                                                                +

                                                                Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values.

                                                                +

                                                                Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples.

                                                                +
                                                                1
                                                                +2
                                                                +3
                                                                +4
                                                                +5
                                                                +6
                                                                def sample_pot(pin, count):
                                                                +    total = 0
                                                                +    for i in range(count):
                                                                +        total += int(pin.read_u16())
                                                                +        utime.sleep_ms(5)
                                                                +    return int(total / count)
                                                                +
                                                                +
                                                                1
                                                                +2
                                                                +3
                                                                pot_pin_1 = machine.ADC(26)
                                                                +# return a value after sampling 10 times
                                                                +sample_pot(pot_pin_1, 10)
                                                                +
                                                                + + + + + + + + + + + + + + + +
                                                                +
                                                                + + + +
                                                                + + + +
                                                                + +
                                                                + + + +
                                                                +
                                                                +
                                                                + + + Made with + + Material for MkDocs + + +
                                                                + +
                                                                +
                                                                +
                                                                + +
                                                                +
                                                                +
                                                                +
                                                                + + + + + + + + + + \ No newline at end of file diff --git a/basics/04-servo/index.html b/basics/04-servo/index.html new file mode 100644 index 000000000..0cd1bdbe4 --- /dev/null +++ b/basics/04-servo/index.html @@ -0,0 +1,1551 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Servo - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                + + + + Skip to content + + +
                                                                +
                                                                + +
                                                                + + + + + + +
                                                                +
                                                                + + + logo + + + +
                                                                +
                                                                +
                                                                + + MicroPython for Kids + +
                                                                +
                                                                + + + Servo + + +
                                                                +
                                                                +
                                                                + + + + + + + +
                                                                + +
                                                                +
                                                                + + +
                                                                + + +
                                                                + +
                                                                +
                                                                +
                                                                +
                                                                +
                                                                + Initializing search +
                                                                +
                                                                  +
                                                                  +
                                                                  +
                                                                  +
                                                                  +
                                                                  + + +
                                                                  + +
                                                                  + + +
                                                                  +
                                                                  + GitHub Repo +
                                                                  +
                                                                  +
                                                                  + +
                                                                  + +
                                                                  + +
                                                                  + + + + + + +
                                                                  +
                                                                  + + + +
                                                                  +
                                                                  +
                                                                  + + + + +
                                                                  + + +
                                                                  + +
                                                                  + + +
                                                                  +
                                                                  + GitHub Repo +
                                                                  +
                                                                  +
                                                                  + +
                                                                    + + + + + + + +
                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + MicroPython Home + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + +
                                                                    + +
                                                                      + + + + + + + +
                                                                    • + + + + + Introduction + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Blink + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Fade In and Out + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Buttons + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Potentiometer + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Motor + + + + +
                                                                    • + + + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + Servo + + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + NeoPixel + + + + +
                                                                    • + + + + + + + + + + +
                                                                    • + + + + + Wireless + + + + +
                                                                    • + + + + +
                                                                    +
                                                                    + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + Glossary + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + References + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + Contributing + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + Contact + + + + +
                                                                  • + + + + + + + + + +
                                                                  • + + + + + Colophon + + + + +
                                                                  • + + + +
                                                                  +
                                                                  +
                                                                  +
                                                                  +
                                                                  + + + +
                                                                  +
                                                                  +
                                                                  + + +
                                                                  + + + + + + +
                                                                  +
                                                                  +
                                                                  +
                                                                  + + + +
                                                                  +
                                                                  + + + + + + + +

                                                                  Micropython Servo Lab

                                                                  +

                                                                  TBD

                                                                  +
                                                                  1
                                                                  +2
                                                                  +3
                                                                  +4
                                                                  +5
                                                                  +6
                                                                  +7
                                                                  import machine
                                                                  +import pyb
                                                                  +
                                                                  +# The pyboard has four simple servo connections
                                                                  +servo = pyb.Servo(1)
                                                                  +
                                                                  +servo.angle(90, 5000)
                                                                  +
                                                                  + + + + + + + + + + + + + + + +
                                                                  +
                                                                  + + + +
                                                                  + + + +
                                                                  + +
                                                                  + + + +
                                                                  + + + +
                                                                  + + +
                                                                  +
                                                                  + + Previous + +
                                                                  + Motor +
                                                                  +
                                                                  +
                                                                  + + + + +
                                                                  + + Next + +
                                                                  + NeoPixel +
                                                                  +
                                                                  +
                                                                  + + +
                                                                  +
                                                                  + +
                                                                  + + +
                                                                  +
                                                                  +
                                                                  + + + Made with + + Material for MkDocs + + +
                                                                  + +
                                                                  +
                                                                  +
                                                                  + +
                                                                  +
                                                                  +
                                                                  +
                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/basics/05-neopixel/index.html b/basics/05-neopixel/index.html new file mode 100644 index 000000000..22cfa558e --- /dev/null +++ b/basics/05-neopixel/index.html @@ -0,0 +1,2235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + NeoPixel - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                  + + + + Skip to content + + +
                                                                  +
                                                                  + +
                                                                  + + + + + + +
                                                                  +
                                                                  + + + logo + + + +
                                                                  +
                                                                  +
                                                                  + + MicroPython for Kids + +
                                                                  +
                                                                  + + + NeoPixel + + +
                                                                  +
                                                                  +
                                                                  + + + + + + + +
                                                                  + +
                                                                  +
                                                                  + + +
                                                                  + + +
                                                                  + +
                                                                  +
                                                                  +
                                                                  +
                                                                  +
                                                                  + Initializing search +
                                                                  +
                                                                    +
                                                                    +
                                                                    +
                                                                    +
                                                                    +
                                                                    + + +
                                                                    + +
                                                                    + + +
                                                                    +
                                                                    + GitHub Repo +
                                                                    +
                                                                    +
                                                                    + +
                                                                    + +
                                                                    + +
                                                                    + + + + + + +
                                                                    +
                                                                    + + + +
                                                                    +
                                                                    +
                                                                    + + + + +
                                                                    + + +
                                                                    + +
                                                                    + + +
                                                                    +
                                                                    + GitHub Repo +
                                                                    +
                                                                    +
                                                                    + +
                                                                      + + + + + + + +
                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + MicroPython Home + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + +
                                                                      + +
                                                                        + + + + + + + +
                                                                      • + + + + + Introduction + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Blink + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Fade In and Out + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Buttons + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Potentiometer + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Motor + + + + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Servo + + + + +
                                                                      • + + + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + NeoPixel + + + + + + + +
                                                                        + + + + + + + +
                                                                          + +
                                                                        • + + + Different Types of NeoPixels + + + +
                                                                        • + +
                                                                        • + + + Circuit connections + + + +
                                                                        • + +
                                                                        • + + + Setup Parameters + + + +
                                                                          +
                                                                            + +
                                                                          • + + + Import Statements + + + +
                                                                          • + +
                                                                          • + + + Static Initialization Parameters + + + +
                                                                          • + +
                                                                          • + + + Initialize the Strip Object + + + +
                                                                          • + +
                                                                          +
                                                                          + +
                                                                        • + +
                                                                        • + + + Sample Programs + + + +
                                                                          +
                                                                            + +
                                                                          • + + + Move Red Pixel Across Strip + + + +
                                                                          • + +
                                                                          • + + + Fade in and Out + + + +
                                                                          • + +
                                                                          • + + + Heartbeat Lab + + + +
                                                                          • + +
                                                                          • + + + Move Red, Green and Blue + + + +
                                                                          • + +
                                                                          • + + + Rainbow Cycle + + + +
                                                                          • + +
                                                                          +
                                                                          + +
                                                                        • + +
                                                                        • + + + References + + + +
                                                                        • + +
                                                                        + +
                                                                        + +
                                                                      • + + + + + + + + + + +
                                                                      • + + + + + Wireless + + + + +
                                                                      • + + + + +
                                                                      +
                                                                      + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + Glossary + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + References + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + Contributing + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + Contact + + + + +
                                                                    • + + + + + + + + + +
                                                                    • + + + + + Colophon + + + + +
                                                                    • + + + +
                                                                    +
                                                                    +
                                                                    +
                                                                    +
                                                                    + + + +
                                                                    +
                                                                    +
                                                                    + + +
                                                                    + + + + + + + +
                                                                      + +
                                                                    • + + + Different Types of NeoPixels + + + +
                                                                    • + +
                                                                    • + + + Circuit connections + + + +
                                                                    • + +
                                                                    • + + + Setup Parameters + + + +
                                                                      +
                                                                        + +
                                                                      • + + + Import Statements + + + +
                                                                      • + +
                                                                      • + + + Static Initialization Parameters + + + +
                                                                      • + +
                                                                      • + + + Initialize the Strip Object + + + +
                                                                      • + +
                                                                      +
                                                                      + +
                                                                    • + +
                                                                    • + + + Sample Programs + + + +
                                                                      +
                                                                        + +
                                                                      • + + + Move Red Pixel Across Strip + + + +
                                                                      • + +
                                                                      • + + + Fade in and Out + + + +
                                                                      • + +
                                                                      • + + + Heartbeat Lab + + + +
                                                                      • + +
                                                                      • + + + Move Red, Green and Blue + + + +
                                                                      • + +
                                                                      • + + + Rainbow Cycle + + + +
                                                                      • + +
                                                                      +
                                                                      + +
                                                                    • + +
                                                                    • + + + References + + + +
                                                                    • + +
                                                                    + +
                                                                    +
                                                                    +
                                                                    +
                                                                    + + + +
                                                                    +
                                                                    + + + + + + + +

                                                                    NeoPixels

                                                                    +

                                                                    NeoPixel Demo

                                                                    +

                                                                    NeoPixels are Red-Green-Blue LEDs that are designed to makes them easy to control with three wires: GND, +5V and a single serial data line. They are very popular with our students because they are powerful, easy to program and full of bling.

                                                                    +
                                                                    +

                                                                    Note

                                                                    +

                                                                    As of March of 2022 there is now built-in support for NeoPixels in the MicroPython 1.18 runtime for the Raspberry Pi RP2040 microcontroller. Although you can still use custom libraries, this tutorial assumes you are using +version 1.18 or later.

                                                                    +
                                                                    +

                                                                    Controlling NeoPixels is challenging since the timing of data being sent must be very precise. Python alone is not fast enough to send bits out of a serial port. So a small function that uses assembly code is used. This code can be called directly from a neopixel driver file so that the user's don't need to see this code.

                                                                    +

                                                                    MicroPython Example Code on ESP8266

                                                                    +

                                                                    Different Types of NeoPixels

                                                                    +

                                                                    There are many different types of NeoPixels. They come in many forms such as strips, rings and matrices.

                                                                    +

                                                                    NeoPixel Types

                                                                    +

                                                                    The most common type of NeoPixels are strips. The strips come in a variety of densities and waterproofing. The most common and easiest to use are the 60 pixels-per-meter type.

                                                                    +

                                                                    Circuit connections

                                                                    +

                                                                    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    LED StripPico NamePico PinDescription
                                                                    GNDGND3Ground
                                                                    5vVBUS40Voltage from the USB bus. Top right with USB on top
                                                                    DataGP2222Row 12 on the right side
                                                                    +

                                                                    Note that you can also power most of the LED strips using the 3.3 volts available on Grove connectors. The only difference is the brightness might not be quite as high, but for most applications this will not be a problem.

                                                                    +

                                                                    Setup Parameters

                                                                    +

                                                                    Our Python code will have four parts:

                                                                    +
                                                                      +
                                                                    1. Declaration of the imports from the RP2 MicroPython runtime. We also import the sleep function from the utime module and some samples will also need the random library. All our programs have been tested on version 1.18 of the MicroPython RP2 library or later.
                                                                    2. +
                                                                    3. Initialization of the fixed static parameters. This is done once and the parameters are usually at the top of the file to make them easy to find and change for each application. Make sure you adjust the pin number and the number of pixels in your setup in this area.
                                                                    4. +
                                                                    5. Initialization of the NeoPixel object using these static parameters. This is also done just once.
                                                                    6. +
                                                                    7. Sending the drawing commands to the device through the data port. This is usually done within a main loop.
                                                                    8. +
                                                                    +

                                                                    Import Statements

                                                                    +

                                                                    Here are the import statements we use:

                                                                    +
                                                                    1
                                                                    +2
                                                                    +3
                                                                    from machine import Pin
                                                                    +from utime import sleep
                                                                    +from neopixel import NeoPixel
                                                                    +
                                                                    +

                                                                    Static Initialization Parameters

                                                                    +

                                                                    There are only two values. The number of pixels in the LED strip or LED ring and the pin number the data pin is connected to.

                                                                    +
                                                                    1
                                                                    +2
                                                                    NUMBER_PIXELS = 8
                                                                    +LED_PIN = 22
                                                                    +
                                                                    +

                                                                    Initialize the Strip Object

                                                                    +

                                                                    To setup the NeoPixel object we just pass it the two parameters like this:

                                                                    +
                                                                    1
                                                                    strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +

                                                                    Here is the full initialization code:

                                                                    +
                                                                    1
                                                                    +2
                                                                    +3
                                                                    +4
                                                                    +5
                                                                    +6
                                                                    +7
                                                                    from machine import Pin
                                                                    +from utime import sleep
                                                                    +from neopixel import NeoPixel
                                                                    +
                                                                    +NUMBER_PIXELS = 8
                                                                    +LED_PIN = 22
                                                                    +strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +

                                                                    Sample Programs

                                                                    +

                                                                    Now we are ready to write our first small test program!

                                                                    +

                                                                    Move Red Pixel Across Strip

                                                                    +

                                                                    Move LED Up Strip

                                                                    +
                                                                     1
                                                                    + 2
                                                                    + 3
                                                                    + 4
                                                                    + 5
                                                                    + 6
                                                                    + 7
                                                                    + 8
                                                                    + 9
                                                                    +10
                                                                    +11
                                                                    +12
                                                                    +13
                                                                    +14
                                                                    +15
                                                                    from machine import Pin
                                                                    +from time import sleep
                                                                    +from neopixel import NeoPixel
                                                                    +
                                                                    +NUMBER_PIXELS = 60
                                                                    +LED_PIN = 0
                                                                    +
                                                                    +strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +while True:
                                                                    +    for i in range(0, NUMBER_PIXELS):
                                                                    +        strip[i] = (255,0,0) # red=255, green and blue are 0
                                                                    +        strip.write() # send the data from RAM down the wire
                                                                    +        sleep(.1) # keep on 1/10 of a second
                                                                    +        strip[i] = (0,0,0) # change the RAM back but don't resend the data
                                                                    +
                                                                    +

                                                                    Fade in and Out

                                                                    +

                                                                    Make the first pixel fade the red color in and out. We do this by slowly turning up the color level of the red on strip[0].

                                                                    +
                                                                    1
                                                                    +2
                                                                    +3
                                                                    +4
                                                                    +5
                                                                    Off: strip[0] = (0,0,0)
                                                                    +Red Very Dim: strip[0] = (1,0,0)
                                                                    +Dim Red: strip[0] = (10,0,0)
                                                                    +Red Half Brightness: strip[0] = (128,0,0)
                                                                    +Red Full Brightness: strip[0] = (255,0,0)
                                                                    +
                                                                    +

                                                                    We start a 0 and go up to 255. Then we go back from 255 back down to zero. We delay about 5 milliseconds between each of the 255 brightness levels.

                                                                    +
                                                                     1
                                                                    + 2
                                                                    + 3
                                                                    + 4
                                                                    + 5
                                                                    + 6
                                                                    + 7
                                                                    + 8
                                                                    + 9
                                                                    +10
                                                                    +11
                                                                    +12
                                                                    +13
                                                                    +14
                                                                    +15
                                                                    +16
                                                                    +17
                                                                    +18
                                                                    +19
                                                                    +20
                                                                    +21
                                                                    from machine import Pin
                                                                    +from time import sleep
                                                                    +from neopixel import NeoPixel
                                                                    +
                                                                    +
                                                                    +NUMBER_PIXELS = 60
                                                                    +LED_PIN = 0
                                                                    +
                                                                    +strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +delay = .005
                                                                    +
                                                                    +while True:
                                                                    +    for i in range(0, 255):
                                                                    +        strip[0] = (i,0,0) # red=255, green and blue are 0
                                                                    +        strip.write() # send the data from RAM down the wire
                                                                    +        sleep(delay)
                                                                    +    for i in range(255, 0, -1):
                                                                    +        strip[0] = (i,0,0)
                                                                    +        strip.write()
                                                                    +        sleep(delay)
                                                                    +
                                                                    +

                                                                    Heartbeat Lab

                                                                    +

                                                                    What if you were building a robot and you wanted to flash the LED to look like a human heartbeat? Instead of slowing fading in and out, you would want the brightness to follow the electrical signals coming from the heart. This is called an electro cardiogram (EKG) and it look like this:

                                                                    +

                                                                    EKG Sample

                                                                    +

                                                                    Notice that the signal is low for about one second and then it spikes up to maximum brightness and then comes back down. When we are moving the brightness up and down, we don't have to pause between each of the 256 brightness values. The eye can't usually see the intermediate brightness values if the brightness is changing quickly. To make our code efficient we can skip over 9 out of 10 of the brightness gradations between 0 and 255. We call this the skip_interval in our code below.

                                                                    +

                                                                    The following code emulates this heart beat pattern:

                                                                    +
                                                                     1
                                                                    + 2
                                                                    + 3
                                                                    + 4
                                                                    + 5
                                                                    + 6
                                                                    + 7
                                                                    + 8
                                                                    + 9
                                                                    +10
                                                                    +11
                                                                    +12
                                                                    +13
                                                                    +14
                                                                    +15
                                                                    +16
                                                                    +17
                                                                    +18
                                                                    +19
                                                                    +20
                                                                    +21
                                                                    +22
                                                                    +23
                                                                    +24
                                                                    +25
                                                                    +26
                                                                    +27
                                                                    +28
                                                                    +29
                                                                    +30
                                                                    +31
                                                                    from machine import Pin
                                                                    +from time import sleep
                                                                    +from neopixel import NeoPixel
                                                                    +
                                                                    +# Most people have a heart rate of around 60-70 beats per minute
                                                                    +# If we add a once second delay between "beats" you can make and LED
                                                                    +# look like a beating heart.
                                                                    +
                                                                    +NUMBER_PIXELS = 1
                                                                    +LED_PIN = 0
                                                                    +
                                                                    +strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +ramp_delay = .001
                                                                    +beat_delay = 1
                                                                    +skip_interval = 10
                                                                    +
                                                                    +while True:
                                                                    +    # ramp brightness up using the ramp_delay
                                                                    +    for i in range(0, 255, skip_interval):
                                                                    +        strip[0] = (i,0,0)
                                                                    +        strip.write()
                                                                    +        sleep(ramp_delay)
                                                                    +    # ramp brightness down using the same delay
                                                                    +    for i in range(255, 0, -skip_interval):
                                                                    +        strip[0] = (i,0,0)
                                                                    +        strip.write()
                                                                    +        sleep(ramp_delay)
                                                                    +    strip[0] = (0,0,0)
                                                                    +    strip.write()
                                                                    +    sleep(beat_delay)
                                                                    +
                                                                    +

                                                                    Move Red, Green and Blue

                                                                    +

                                                                    neopixel-red-green-blue

                                                                    +

                                                                    The following program will just take the block of code in the for loop above and duplicate it three times, one for red, one for blue and one for green.

                                                                    +
                                                                     1
                                                                    + 2
                                                                    + 3
                                                                    + 4
                                                                    + 5
                                                                    + 6
                                                                    + 7
                                                                    + 8
                                                                    + 9
                                                                    +10
                                                                    +11
                                                                    +12
                                                                    +13
                                                                    +14
                                                                    +15
                                                                    +16
                                                                    +17
                                                                    +18
                                                                    +19
                                                                    +20
                                                                    +21
                                                                    +22
                                                                    +23
                                                                    +24
                                                                    +25
                                                                    +26
                                                                    +27
                                                                    +28
                                                                    +29
                                                                    +30
                                                                    +31
                                                                    +32
                                                                    +33
                                                                    +34
                                                                    +35
                                                                    from machine import Pin
                                                                    +from neopixel import NeoPixel
                                                                    +from time import sleep
                                                                    +
                                                                    +NUMBER_PIXELS = 8
                                                                    +LED_PIN = 0
                                                                    +
                                                                    +strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +# we use the same brightness for each color
                                                                    +brightness = 25
                                                                    +delay = .1
                                                                    +# here we define variables for each color
                                                                    +red = (brightness, 0, 0)
                                                                    +green = (0, brightness, 0)
                                                                    +blue = (0, 0, brightness)
                                                                    +while True:
                                                                    +    # draw red up the strip
                                                                    +    for i in range(0, NUMBER_PIXELS):
                                                                    +        strip[i] = red
                                                                    +        strip.write()
                                                                    +        sleep(delay)
                                                                    +        strip[i] = (0,0,0)
                                                                    +    # draw blue up the strip
                                                                    +    for i in range(0, NUMBER_PIXELS):
                                                                    +        strip[i] =  green
                                                                    +        strip.write()
                                                                    +        sleep(delay)
                                                                    +        strip[i] = (0,0,0)
                                                                    +    # draw green up the strip
                                                                    +    for i in range(0, NUMBER_PIXELS):
                                                                    +        strip[i] =  blue
                                                                    +        strip.write()
                                                                    +        sleep(delay)
                                                                    +        strip[i] = (0,0,0)
                                                                    +
                                                                    +

                                                                    Rainbow Cycle

                                                                    +

                                                                    The program cycles each pixel through all the colors in a rainbow. It uses two functions:

                                                                    +
                                                                      +
                                                                    1. wheel(pos) this function takes a position parameter from 0 to 255 and returns a triple of numbers for the red, green and blue values as the position moves around the color wheel. This is a handy program anytime you want to cycle through all the colors of the rainbow!
                                                                    2. +
                                                                    3. rainbow_cycle(wait) will cycle each of the pixels in a strip through the color wheel. It gives the appearance that colors are moving across the strip. The wait is the delay time between updating the colors. A typical value for wait is .05 seconds or 50 milliseconds.
                                                                    4. +
                                                                    +
                                                                     1
                                                                    + 2
                                                                    + 3
                                                                    + 4
                                                                    + 5
                                                                    + 6
                                                                    + 7
                                                                    + 8
                                                                    + 9
                                                                    +10
                                                                    +11
                                                                    +12
                                                                    +13
                                                                    +14
                                                                    +15
                                                                    +16
                                                                    +17
                                                                    +18
                                                                    +19
                                                                    +20
                                                                    +21
                                                                    +22
                                                                    +23
                                                                    +24
                                                                    +25
                                                                    +26
                                                                    +27
                                                                    +28
                                                                    +29
                                                                    +30
                                                                    +31
                                                                    +32
                                                                    +33
                                                                    +34
                                                                    +35
                                                                    +36
                                                                    +37
                                                                    from machine import Pin
                                                                    +from neopixel import NeoPixel
                                                                    +from utime import sleep
                                                                    +
                                                                    +NEOPIXEL_PIN = 22
                                                                    +NUMBER_PIXELS = 8
                                                                    +strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                    +
                                                                    +def wheel(pos):
                                                                    +    # Input a value 0 to 255 to get a color value.
                                                                    +    # The colors are a transition r - g - b - back to r.
                                                                    +    if pos < 0 or pos > 255:
                                                                    +        return (0, 0, 0)
                                                                    +    if pos < 85:
                                                                    +        return (255 - pos * 3, pos * 3, 0)
                                                                    +    if pos < 170:
                                                                    +        pos -= 85
                                                                    +        return (0, 255 - pos * 3, pos * 3)
                                                                    +    pos -= 170
                                                                    +    return (pos * 3, 0, 255 - pos * 3)
                                                                    +
                                                                    +def rainbow_cycle(wait):
                                                                    +    global NUMBER_PIXELS, strip
                                                                    +    for j in range(255):
                                                                    +        for i in range(NUMBER_PIXELS):
                                                                    +            rc_index = (i * 256 // NUMBER_PIXELS) + j
                                                                    +            # print(rc_index)
                                                                    +            strip[i] = wheel(rc_index & 255)
                                                                    +        strip.write()
                                                                    +    sleep(wait)
                                                                    +
                                                                    +counter = 0
                                                                    +offset = 0
                                                                    +while True:
                                                                    +    print('Running cycle', counter)
                                                                    +    rainbow_cycle(.05)
                                                                    +    counter += 1
                                                                    +
                                                                    +

                                                                    References

                                                                    +
                                                                      +
                                                                    • MicroPython RP2 Reference for NeoPixel Driver
                                                                    • +
                                                                    • Core Electronics: How to use WS2812B RGB LEDs with Raspberry Pi Pico - HTML page, sample code and video
                                                                    • +
                                                                    • MicroPython Library for NeoPixel (used before version 1.18 of the MicroPython RP2 Runtime) - note the lack of support for the RP2040 microcontroller.
                                                                    • +
                                                                    • rp2 port no module named array
                                                                    • +
                                                                    + + + + + + + + + + + + + + + +
                                                                    +
                                                                    + + + +
                                                                    + + + +
                                                                    + +
                                                                    + + + +
                                                                    + + + +
                                                                    + + +
                                                                    +
                                                                    + + Previous + +
                                                                    + Servo +
                                                                    +
                                                                    +
                                                                    + + + + +
                                                                    + + Next + +
                                                                    + Wireless +
                                                                    +
                                                                    +
                                                                    + + +
                                                                    +
                                                                    + +
                                                                    + + +
                                                                    +
                                                                    +
                                                                    + + + Made with + + Material for MkDocs + + +
                                                                    + +
                                                                    +
                                                                    +
                                                                    + +
                                                                    +
                                                                    +
                                                                    +
                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/basics/06-wireless/index.html b/basics/06-wireless/index.html new file mode 100644 index 000000000..046f40f5e --- /dev/null +++ b/basics/06-wireless/index.html @@ -0,0 +1,2578 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Wireless - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                    + + + + Skip to content + + +
                                                                    +
                                                                    + +
                                                                    + + + + + + +
                                                                    +
                                                                    + + + logo + + + +
                                                                    +
                                                                    +
                                                                    + + MicroPython for Kids + +
                                                                    +
                                                                    + + + Wireless + + +
                                                                    +
                                                                    +
                                                                    + + + + + + + +
                                                                    + +
                                                                    +
                                                                    + + +
                                                                    + + +
                                                                    + +
                                                                    +
                                                                    +
                                                                    +
                                                                    +
                                                                    + Initializing search +
                                                                    +
                                                                      +
                                                                      +
                                                                      +
                                                                      +
                                                                      +
                                                                      + + +
                                                                      + +
                                                                      + + +
                                                                      +
                                                                      + GitHub Repo +
                                                                      +
                                                                      +
                                                                      + +
                                                                      + +
                                                                      + +
                                                                      + + + + + + +
                                                                      +
                                                                      + + + +
                                                                      +
                                                                      +
                                                                      + + + + +
                                                                      + + +
                                                                      + +
                                                                      + + +
                                                                      +
                                                                      + GitHub Repo +
                                                                      +
                                                                      +
                                                                      + +
                                                                        + + + + + + + +
                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + MicroPython Home + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + +
                                                                        + +
                                                                          + + + + + + + +
                                                                        • + + + + + Introduction + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Blink + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Fade In and Out + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Buttons + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Potentiometer + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Motor + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + Servo + + + + +
                                                                        • + + + + + + + + + + +
                                                                        • + + + + + NeoPixel + + + + +
                                                                        • + + + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + Wireless + + + + + + + +
                                                                          + + + + + + + +
                                                                            + +
                                                                          • + + + Compatibility with Prior Code + + + +
                                                                          • + +
                                                                          • + + + Getting the New Pico W Image + + + +
                                                                          • + +
                                                                          • + + + Beginner WiFi Programs + + + +
                                                                            +
                                                                              + +
                                                                            • + + + Setting Up Your WIFI secrets.py + + + +
                                                                            • + +
                                                                            • + + + Testing Your WiFi Access Point Connection + + + +
                                                                            • + +
                                                                            • + + + Waiting for a Valid Access Point Connection + + + +
                                                                            • + +
                                                                            • + + + Error Handling + + + +
                                                                            • + +
                                                                            • + + + Testing HTTP GET + + + +
                                                                            • + +
                                                                            +
                                                                            + +
                                                                          • + +
                                                                          • + + + Listing the Functions in Your Network Library + + + +
                                                                            +
                                                                              + +
                                                                            • + + + Network Help + + + +
                                                                            • + +
                                                                            • + + + Network dir() Function + + + +
                                                                            • + +
                                                                            • + + + Urequest + + + +
                                                                            • + +
                                                                            +
                                                                            + +
                                                                          • + +
                                                                          • + + + Getting the MAC/Ethernet Access + + + +
                                                                          • + +
                                                                          • + + + Advanced WiFi Programs + + + +
                                                                            +
                                                                              + +
                                                                            • + + + Using the Pico W as a Web Server + + + +
                                                                            • + +
                                                                            • + + + SHTTP Support + + + +
                                                                            • + +
                                                                            • + + + Sending Notifications + + + +
                                                                            • + +
                                                                            +
                                                                            + +
                                                                          • + +
                                                                          + +
                                                                          + +
                                                                        • + + + + +
                                                                        +
                                                                        + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + Glossary + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + References + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + Contributing + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + Contact + + + + +
                                                                      • + + + + + + + + + +
                                                                      • + + + + + Colophon + + + + +
                                                                      • + + + +
                                                                      +
                                                                      +
                                                                      +
                                                                      +
                                                                      + + + +
                                                                      +
                                                                      +
                                                                      + + +
                                                                      + + + + + + + +
                                                                        + +
                                                                      • + + + Compatibility with Prior Code + + + +
                                                                      • + +
                                                                      • + + + Getting the New Pico W Image + + + +
                                                                      • + +
                                                                      • + + + Beginner WiFi Programs + + + +
                                                                        +
                                                                          + +
                                                                        • + + + Setting Up Your WIFI secrets.py + + + +
                                                                        • + +
                                                                        • + + + Testing Your WiFi Access Point Connection + + + +
                                                                        • + +
                                                                        • + + + Waiting for a Valid Access Point Connection + + + +
                                                                        • + +
                                                                        • + + + Error Handling + + + +
                                                                        • + +
                                                                        • + + + Testing HTTP GET + + + +
                                                                        • + +
                                                                        +
                                                                        + +
                                                                      • + +
                                                                      • + + + Listing the Functions in Your Network Library + + + +
                                                                        +
                                                                          + +
                                                                        • + + + Network Help + + + +
                                                                        • + +
                                                                        • + + + Network dir() Function + + + +
                                                                        • + +
                                                                        • + + + Urequest + + + +
                                                                        • + +
                                                                        +
                                                                        + +
                                                                      • + +
                                                                      • + + + Getting the MAC/Ethernet Access + + + +
                                                                      • + +
                                                                      • + + + Advanced WiFi Programs + + + +
                                                                        +
                                                                          + +
                                                                        • + + + Using the Pico W as a Web Server + + + +
                                                                        • + +
                                                                        • + + + SHTTP Support + + + +
                                                                        • + +
                                                                        • + + + Sending Notifications + + + +
                                                                        • + +
                                                                        +
                                                                        + +
                                                                      • + +
                                                                      + +
                                                                      +
                                                                      +
                                                                      +
                                                                      + + + +
                                                                      +
                                                                      + + + + + + + +

                                                                      MicroPython Pico W Wireless Examples

                                                                      +

                                                                      Raspberry Pi Pico W

                                                                      +

                                                                      One June 30th, 2022 the Raspberry Pi Foundation announced the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth.

                                                                      +

                                                                      The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the lwip TCP/IP stack. This stack is accessible using the MicroPython network functions.

                                                                      +

                                                                      The WiFi chip used is the Infineon CYW43439 chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication.

                                                                      +

                                                                      Wireless Block Architecture

                                                                      +

                                                                      You can read more about the capabilities of the WiFi/Bluetooth chip by reading the Infineon CYW43439 Datasheet. I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains!

                                                                      +

                                                                      Compatibility with Prior Code

                                                                      +

                                                                      The Pico W code is very similar to prior versions of the Pico with a few small exceptions. One of these is the fact that we must now use a symbolic label called an alias such as Pin("LED") instead of Pin(25) to access the LED pin, not a hardwired PIN number. This allows us to keep our code more portable as the underlying hardware changes.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      from machine import Pin, Timer
                                                                      +
                                                                      +# was Pin(25)
                                                                      +led = Pin("LED", Pin.OUT)
                                                                      +tim = Timer()
                                                                      +def tick(timer):
                                                                      +    global led
                                                                      +    led.toggle()
                                                                      +
                                                                      +tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)
                                                                      +
                                                                      +

                                                                      See the new Sample Blink code on the Raspberry Pi Examples site.

                                                                      +

                                                                      Getting the New Pico W Image

                                                                      +

                                                                      I had to download a brand new image for the Pico W runtime from the Raspberry Pi Foundation Software Site

                                                                      +

                                                                      After I downloaded the new image and ran a Stop/Reset on Thonny I got the following prompt:

                                                                      +
                                                                      1
                                                                      +2
                                                                      +3
                                                                      MicroPython v1.19.1-88-g74e33e714 on 2022-06-30; Raspberry Pi Pico W with RP2040
                                                                      +Type "help()" for more information.
                                                                      +>>> 
                                                                      +
                                                                      +

                                                                      Note that the "Pico W" is listed in the prompt. If you do not see the "W" then the network code will not work.

                                                                      +

                                                                      Beginner WiFi Programs

                                                                      +

                                                                      We will store the name of our local WiFi network we wish to connect to and the password for that name in a file called secrets.py. This is called you WiFi "access point" and the variable name to store the name is called the `SSID. We will need to make sure we never save this file into a public GitHub repo by adding this file to our .gitignore file.

                                                                      +

                                                                      Setting Up Your WIFI secrets.py

                                                                      +

                                                                      By convention, we put both our SSID and password in a python file called "secrets.py". This file should never be checked into a public source code repository. We can add secrets.py to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone.

                                                                      +
                                                                      1
                                                                      +2
                                                                      SSID = "MY_WIFI_NETWORK_NAME"
                                                                      +PASSWORD = "MY_WIFI_PASSWORD"
                                                                      +
                                                                      +

                                                                      By importing the secrets.py file you can then reference your network name like this:

                                                                      +
                                                                      1
                                                                      print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                      +
                                                                      +

                                                                      Testing Your WiFi Access Point Connection

                                                                      +

                                                                      Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      import network
                                                                      +import secrets
                                                                      +from utime import sleep
                                                                      +
                                                                      +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True) # power up the WiFi chip
                                                                      +print('Waiting for wifi chip to power up...')
                                                                      +sleep(3) # wait three seconds for the chip to power up and initialize
                                                                      +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                      +print('Waiting for access point to log us in.')
                                                                      +sleep(2)
                                                                      +if wlan.isconnected():
                                                                      +  print('Success! We have connected to your access point!')
                                                                      +  print('Try to ping the device at', wlan.ifconfig()[0])
                                                                      +else:
                                                                      +  print('Failure! We have not connected to your access point!  Check your secrets.py file for errors.')
                                                                      +
                                                                      +

                                                                      Returns:

                                                                      +
                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      +5
                                                                      Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME
                                                                      +Waiting for wifi chip to power up...
                                                                      +Waiting for access point to log us in...
                                                                      +Success! We have connected to your access point!
                                                                      +Try to ping the device at 10.0.0.70
                                                                      +
                                                                      +

                                                                      If the result is a Failure you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing.

                                                                      +

                                                                      Note that we are using the sleep() function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly.

                                                                      +

                                                                      Waiting for a Valid Access Point Connection

                                                                      +

                                                                      Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      +18
                                                                      +19
                                                                      +20
                                                                      +21
                                                                      +22
                                                                      import network
                                                                      +import secrets
                                                                      +from utime import sleep, ticks_ms, ticks_diff
                                                                      +
                                                                      +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True)
                                                                      +
                                                                      +start = ticks_ms() # start a millisecond counter
                                                                      +
                                                                      +if not wlan.isconnected():
                                                                      +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                      +    print("Waiting for connection...")
                                                                      +    counter = 0
                                                                      +    while not wlan.isconnected():
                                                                      +        sleep(1)
                                                                      +        print(counter, '.', sep='', end='', )
                                                                      +        counter += 1
                                                                      +
                                                                      +delta = ticks_diff(ticks_ms(), start)
                                                                      +print("Connect Time:", delta, 'milliseconds')
                                                                      +print('IP Address:', wlan.ifconfig()[0])
                                                                      +
                                                                      +

                                                                      This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds.

                                                                      +

                                                                      First run upon power on might take several seconds: +

                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      +5
                                                                      >>> %Run -c $EDITOR_CONTENT
                                                                      +Connecting to WiFi Network Name: MY_NETWORK_NAME
                                                                      +Waiting for connection...
                                                                      +0.1.2.3.Connect Time: 4640
                                                                      +IP Address: 10.0.0.70
                                                                      +

                                                                      +

                                                                      The second and consecutive runs will use a cached connection.

                                                                      +
                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      +5
                                                                      >>> %Run -c $EDITOR_CONTENT
                                                                      +Connecting to WiFi Network Name: MY_NETWORK_NAME
                                                                      +Connect Time: 0 milliseconds
                                                                      +IP Address: 10.0.0.70
                                                                      +>>>
                                                                      +
                                                                      +

                                                                      Error Handling

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      +18
                                                                      +19
                                                                      +20
                                                                      lan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True)
                                                                      +wlan.connect(ssid, password)
                                                                      +
                                                                      +# Wait for connect or fail
                                                                      +max_wait = 10
                                                                      +while max_wait > 0:
                                                                      +  if wlan.status() < 0 or wlan.status() >= 3:
                                                                      +    break
                                                                      +  max_wait -= 1
                                                                      +  print('waiting for connection...')
                                                                      +  time.sleep(1)
                                                                      +
                                                                      +# Handle connection error
                                                                      +if wlan.status() != 3:
                                                                      +   raise RuntimeError('network connection failed')
                                                                      +else:
                                                                      +  print('connected')
                                                                      +  status = wlan.ifconfig()
                                                                      +  print( 'ip = ' + status[0] )
                                                                      +
                                                                      +

                                                                      The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above.

                                                                      +

                                                                      Testing HTTP GET

                                                                      +

                                                                      The following example was taken from Tom's Hardware

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      +18
                                                                      +19
                                                                      +20
                                                                      +21
                                                                      import network
                                                                      +import secrets
                                                                      +from utime import sleep, ticks_ms, ticks_diff
                                                                      +import urequests
                                                                      +
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True)
                                                                      +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                      +
                                                                      +start = ticks_ms() # start a millisecond counter
                                                                      +
                                                                      +astronauts = urequests.get("http://api.open-notify.org/astros.json").json()
                                                                      +
                                                                      +delta = ticks_diff(ticks_ms(), start)
                                                                      +
                                                                      +number = astronauts['number']
                                                                      +print('There are', number, 'astronauts in space.')
                                                                      +for i in range(number):
                                                                      +    print(i+1, astronauts['people'][i]['name'])
                                                                      +
                                                                      +print("HTTP GET Time in milliseconds:", delta)
                                                                      +
                                                                      +

                                                                      Returns:

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      There are 10 astronauts in space.
                                                                      +1 Oleg Artemyev
                                                                      +2 Denis Matveev
                                                                      +3 Sergey Korsakov
                                                                      +4 Kjell Lindgren
                                                                      +5 Bob Hines
                                                                      +6 Samantha Cristoforetti
                                                                      +7 Jessica Watkins
                                                                      +8 Cai Xuzhe
                                                                      +9 Chen Dong
                                                                      +10 Liu Yang
                                                                      +HTTP GET Time in milliseconds: 786
                                                                      +
                                                                      +

                                                                      Listing the Functions in Your Network Library

                                                                      +

                                                                      The network library provided by the Raspberry Pi Foundation for the Pico W is new an may change as new functions are added. To get the list of functions in your network library you can use the Python help(network) at the prompt or use the dir() function.

                                                                      +

                                                                      Network Help

                                                                      +

                                                                      You can also get a list of the network functions by typing help(network) at the Python REPL prompt.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      help(network)
                                                                      +object <module 'network'> is of type module
                                                                      +  __name__ -- network
                                                                      +  route -- <function>
                                                                      +  WLAN -- <class 'CYW43'>
                                                                      +  STAT_IDLE -- 0
                                                                      +  STAT_CONNECTING -- 1
                                                                      +  STAT_WRONG_PASSWORD -- -3
                                                                      +  STAT_NO_AP_FOUND -- -2
                                                                      +  STAT_CONNECT_FAIL -- -1
                                                                      +  STAT_GOT_IP -- 3
                                                                      +  STA_IF -- 0
                                                                      +  AP_IF -- 1
                                                                      +
                                                                      +

                                                                      Network dir() Function

                                                                      +
                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      +5
                                                                      import network
                                                                      +function_list = dir(network)
                                                                      +
                                                                      +for function in function_list:
                                                                      +    print(function)
                                                                      +
                                                                      +

                                                                      Returns:

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      __class__
                                                                      +__name__
                                                                      +AP_IF
                                                                      +STAT_CONNECTING
                                                                      +STAT_CONNECT_FAIL
                                                                      +STAT_GOT_IP
                                                                      +STAT_IDLE
                                                                      +STAT_NO_AP_FOUND
                                                                      +STAT_WRONG_PASSWORD
                                                                      +STA_IF
                                                                      +WLAN
                                                                      +route
                                                                      +
                                                                      +

                                                                      Urequest

                                                                      +

                                                                      It is easy to communicate with non-SSL protected HTTP protocols sites using the WLAN `urequest function. It supports the standard GET, POST, PUT and DELETE functions.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      help(urequests)
                                                                      +object <module 'urequests' from 'urequests.py'> is of type module
                                                                      +  head -- <function head at 0x2000b740>
                                                                      +  post -- <function post at 0x2000ba80>
                                                                      +  delete -- <function delete at 0x2000bbb0>
                                                                      +  get -- <function get at 0x2000b750>
                                                                      +  __file__ -- urequests.py
                                                                      +  Response -- <class 'Response'>
                                                                      +  patch -- <function patch at 0x2000baf0>
                                                                      +  put -- <function put at 0x2000ba90>
                                                                      +  usocket -- <module 'lwip'>
                                                                      +  __name__ -- urequests
                                                                      +  request -- <function request at 0x2000bb80>
                                                                      +
                                                                      +

                                                                      Getting the MAC/Ethernet Access

                                                                      +

                                                                      You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function.

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      +18
                                                                      +19
                                                                      +20
                                                                      +21
                                                                      +22
                                                                      +23
                                                                      import network
                                                                      +from utime import sleep, ticks_us, ticks_diff
                                                                      +
                                                                      +print('Getting MAC/Ethernet Address for this device.')
                                                                      +
                                                                      +start = ticks_us() # start a millisecond counter
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True) # this line powers up the chip - it takes about 2.5 seconds
                                                                      +
                                                                      +# This returns a byte array of hex numbers
                                                                      +mac_addess = wlan.config('mac')
                                                                      +print('Time in microseconds:', ticks_diff(ticks_us(), start))
                                                                      +# each MAC address is 6 bytes or 48 bits
                                                                      +print("Hex byte array:", mac_addess, 'length:', len(mac_addess))
                                                                      +
                                                                      +# This should be in hex per the Notational Conventions
                                                                      +# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions
                                                                      +# b'(\xcd\xc1\x015X'
                                                                      +# 28:cd:c1:1:35:58
                                                                      +# format in MAC Notational Convention
                                                                      +for digit in range(0,5):
                                                                      +    print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '')
                                                                      +print(str(hex(mac_addess[5]))[2:4] )
                                                                      +
                                                                      +

                                                                      First Time After Power On Results: +

                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      Getting MAC/Ethernet Address for this device.
                                                                      +Time in microseconds: 2584424
                                                                      +Hex byte array: b'(\xcd\xc1\x015X' length: 6
                                                                      +28:cd:c1:1:35:58
                                                                      +

                                                                      +

                                                                      Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address.

                                                                      +

                                                                      Subsequent Times +

                                                                      1
                                                                      +2
                                                                      +3
                                                                      +4
                                                                      Getting MAC/Ethernet Address for this device.
                                                                      +Time in microseconds: 211
                                                                      +Hex byte array: b'(\xcd\xc1\x015X' length: 6
                                                                      +28:cd:c1:1:35:58
                                                                      +

                                                                      +
                                                                      +

                                                                      Note

                                                                      +

                                                                      We must add the wlan.active(True) line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros.

                                                                      +
                                                                      +

                                                                      The MAC address is six bytes or "octets". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the Wikipedia Page on MAC Address for more information. If you run this on your Pico W the first octets should be similar.

                                                                      +

                                                                      Here are the two MAC addresses for two different Pico W devices:

                                                                      +
                                                                      1
                                                                      +2
                                                                      28:cd:c1:1:35:54
                                                                      +28:cd:c1:1:35:58
                                                                      +
                                                                      +

                                                                      Because they were purchased together, their MAC address are very similar.

                                                                      +

                                                                      I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking.

                                                                      +

                                                                      Advanced WiFi Programs

                                                                      +

                                                                      Once we have mastered the basics of connecting to a local access point and returning our IP address, we are no ready to build some sample Internet of Things applications.

                                                                      +

                                                                      Using the Pico W as a Web Server

                                                                      +

                                                                      This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off.

                                                                      +

                                                                      Screen image of Pico W Web Server: +

                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      +11
                                                                      +12
                                                                      +13
                                                                      +14
                                                                      +15
                                                                      +16
                                                                      +17
                                                                      +18
                                                                      +19
                                                                      +20
                                                                      +21
                                                                      +22
                                                                      +23
                                                                      +24
                                                                      +25
                                                                      +26
                                                                      +27
                                                                      +28
                                                                      +29
                                                                      +30
                                                                      +31
                                                                      +32
                                                                      +33
                                                                      +34
                                                                      +35
                                                                      +36
                                                                      +37
                                                                      +38
                                                                      +39
                                                                      +40
                                                                      +41
                                                                      +42
                                                                      +43
                                                                      +44
                                                                      +45
                                                                      +46
                                                                      +47
                                                                      +48
                                                                      +49
                                                                      +50
                                                                      +51
                                                                      +52
                                                                      +53
                                                                      +54
                                                                      +55
                                                                      +56
                                                                      +57
                                                                      +58
                                                                      +59
                                                                      +60
                                                                      +61
                                                                      +62
                                                                      +63
                                                                      +64
                                                                      +65
                                                                      +66
                                                                      +67
                                                                      +68
                                                                      +69
                                                                      +70
                                                                      +71
                                                                      +72
                                                                      +73
                                                                      +74
                                                                      +75
                                                                      +76
                                                                      +77
                                                                      +78
                                                                      +79
                                                                      +80
                                                                      +81
                                                                      +82
                                                                      +83
                                                                      +84
                                                                      +85
                                                                      +86
                                                                      +87
                                                                      +88
                                                                      # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/
                                                                      +import network
                                                                      +import socket
                                                                      +import time
                                                                      +import secrets
                                                                      +
                                                                      +from machine import Pin
                                                                      +
                                                                      +# Select the onboard LED
                                                                      +led = machine.Pin("LED", machine.Pin.OUT)
                                                                      +
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True)
                                                                      +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                      +stateis = "LED is OFF"
                                                                      +
                                                                      +html = """<!DOCTYPE html>
                                                                      +<html>
                                                                      +   <head>
                                                                      +     <title>Web Server On Pico W </title>
                                                                      +   </head>
                                                                      +  <body>
                                                                      +      <h1>Pico Wireless Web Server</h1>
                                                                      +      <p>%s</p>
                                                                      +      <a href="/light/on">Turn On</a>
                                                                      +      <a href="/light/off">Turn Off</a>
                                                                      +  </body>
                                                                      +</html>
                                                                      +"""
                                                                      +
                                                                      +# Wait for connect or fail
                                                                      +max_wait = 10
                                                                      +while max_wait > 0:
                                                                      +  if wlan.status() < 0 or wlan.status() >= 3:
                                                                      +    break
                                                                      +  max_wait -= 1
                                                                      +  print('waiting for connection...')
                                                                      +  time.sleep(1)
                                                                      +
                                                                      +# Handle connection error
                                                                      +if wlan.status() != 3:
                                                                      +  raise RuntimeError('network connection failed')
                                                                      +else:
                                                                      +  print('We are connected to WiFI access point:', secrets.SSID)
                                                                      +  status = wlan.ifconfig()
                                                                      +  print( 'The IP address of the pico W is:', status[0] )
                                                                      +
                                                                      +# Open socket
                                                                      +addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
                                                                      +print('addr:', addr)
                                                                      +s = socket.socket()
                                                                      +#if not addr:
                                                                      +s.bind(addr)
                                                                      +s.listen(1)
                                                                      +
                                                                      +print('listening on', addr)
                                                                      +
                                                                      +# Listen for connections
                                                                      +while True:
                                                                      +  try:
                                                                      +    cl, addr = s.accept()
                                                                      +    print('client connected from', addr)
                                                                      +    request = cl.recv(1024)
                                                                      +    print(request)
                                                                      +    request = str(request)
                                                                      +    led_on = request.find('/light/on')
                                                                      +    led_off = request.find('/light/off')
                                                                      +    print( 'led on = ' + str(led_on))
                                                                      +    print( 'led off = ' + str(led_off))
                                                                      +
                                                                      +    if led_on == 6:
                                                                      +      print("led on")
                                                                      +      led.value(1)
                                                                      +      stateis = "LED is ON"
                                                                      +
                                                                      +    if led_off == 6:
                                                                      +      print("led off")
                                                                      +      led.value(0)
                                                                      +      stateis = "LED is OFF"
                                                                      +    # generate the we page with the stateis as a parameter
                                                                      +    response = html % stateis
                                                                      +    cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
                                                                      +    cl.send(response)
                                                                      +    cl.close()
                                                                      +
                                                                      +  except OSError as e:
                                                                      +    cl.close()
                                                                      +    print('connection closed')
                                                                      +
                                                                      +

                                                                      SHTTP Support

                                                                      +
                                                                      +

                                                                      Warning

                                                                      +

                                                                      This code is not working. I believe we need to get a SSL certificate for SSL to work. To do this I think we need to use a command line tool to generate a certificate for the device and store it in RAM.

                                                                      +
                                                                      +
                                                                       1
                                                                      + 2
                                                                      + 3
                                                                      + 4
                                                                      + 5
                                                                      + 6
                                                                      + 7
                                                                      + 8
                                                                      + 9
                                                                      +10
                                                                      import network
                                                                      +import secrets
                                                                      +import time
                                                                      +import urequests
                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                      +wlan.active(True)
                                                                      +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                      +print(wlan.isconnected())
                                                                      +my_ip = urequests.get("https://api.myip.com/").json()
                                                                      +print(im_pi)
                                                                      +
                                                                      +

                                                                      Sending Notifications

                                                                      +

                                                                      We can connect to a remote server to send text and e-mail notifications if specific events occur on our devices. To do this you must have credentials on some system that response to messages such as IFTTT or an MQTT server.

                                                                      +

                                                                      TBD

                                                                      + + + + + + + + + + + + + + + +
                                                                      +
                                                                      + + + +
                                                                      + + + +
                                                                      + +
                                                                      + + + +
                                                                      + + + +
                                                                      + + +
                                                                      +
                                                                      + + Previous + +
                                                                      + NeoPixel +
                                                                      +
                                                                      +
                                                                      + + + + +
                                                                      + + Next + +
                                                                      + Introduction +
                                                                      +
                                                                      +
                                                                      + + +
                                                                      +
                                                                      + +
                                                                      + + +
                                                                      +
                                                                      +
                                                                      + + + Made with + + Material for MkDocs + + +
                                                                      + +
                                                                      +
                                                                      +
                                                                      + +
                                                                      +
                                                                      +
                                                                      +
                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/carls-rfi-board.png b/carls-rfi-board.png deleted file mode 100644 index d7460e0a5..000000000 Binary files a/carls-rfi-board.png and /dev/null differ diff --git a/concept-card-scripts/print.css b/concept-card-scripts/print.css deleted file mode 100644 index b064259f5..000000000 --- a/concept-card-scripts/print.css +++ /dev/null @@ -1,49 +0,0 @@ -body { - background: white; - color: black; - } - - @page { - margin-left: .25ins; - margin-right: 25ins; - margin-top: 25ins; - margin-bottom: 25ins; - } - - /* insert URLs */ - a[href]:after { - content: " (" attr(href) ")"; - font-size: 90%; - color: #333; - } - - /* avoid splitting tables on page breaks */ - table { page-break-inside: avoid; } - - h1 { - color: blue; - font-size: 16pt; - } - - @code { - font-family: "Courier New", monospace; - } - - @concept-card-title { - color: purple; - font-weight: bold; - border: 1px solid purple; - } - - @beginner-border { - background: green; - color: white; - font-weight: bold; - border: 1px solid black; - } - - @concept-card-body{ - background: white; - color: black; - border: 1px solid orange; - } \ No newline at end of file diff --git a/concept-card-scripts/sample-template.html b/concept-card-scripts/sample-template.html deleted file mode 100644 index 85f5c49d0..000000000 --- a/concept-card-scripts/sample-template.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - - - -
                                                                      -
                                                                      CoderDojo MicroPython Beginning Concept Card
                                                                      -
                                                                      -
                                                                      Blink Lab
                                                                      -
                                                                      How to blink an LED on and off.
                                                                      -
                                                                      How to blink an LED
                                                                      -
                                                                      - In this lab we will make an LED go on and off. -
                                                                      -
                                                                      -from machine import Pin # get the Pin function from the machine module
                                                                      -from time import sleep # get the sleep library from the time module
                                                                      -# this is the built-in green LED on the Pico
                                                                      -led = machine.Pin(25, machine.Pin.OUT)
                                                                      -
                                                                      -# repeat forever
                                                                      -while True:
                                                                      -    led.high() # turn on the LED
                                                                      -    sleep(0.5) # leave it on for 1/2 second
                                                                      -    led.low() # Turn off the LED
                                                                      -    sleep(0.5) # leave it off for 1/2 second
                                                                      -                
                                                                      -
                                                                      - - - - - diff --git a/concept-card-scripts/screen.css b/concept-card-scripts/screen.css deleted file mode 100644 index 69653d8b8..000000000 --- a/concept-card-scripts/screen.css +++ /dev/null @@ -1,4 +0,0 @@ -@code { - font-family: "Courier New", "Courier", monospace; - border: 1px solid red; -} \ No newline at end of file diff --git a/concept-cards/01-intro/index.html b/concept-cards/01-intro/index.html new file mode 100644 index 000000000..63fba294d --- /dev/null +++ b/concept-cards/01-intro/index.html @@ -0,0 +1,1532 @@ + + + + + + + + + + + + + + + + + + + + + + + MicroPython Concept Cards - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                      + + + + Skip to content + + +
                                                                      +
                                                                      + +
                                                                      + + + + + + +
                                                                      +
                                                                      + + + logo + + + +
                                                                      +
                                                                      +
                                                                      + + MicroPython for Kids + +
                                                                      +
                                                                      + + + MicroPython Concept Cards + + +
                                                                      +
                                                                      +
                                                                      + + + + + + + +
                                                                      + +
                                                                      +
                                                                      + + +
                                                                      + + +
                                                                      + +
                                                                      +
                                                                      +
                                                                      +
                                                                      +
                                                                      + Initializing search +
                                                                      +
                                                                        +
                                                                        +
                                                                        +
                                                                        +
                                                                        +
                                                                        + + +
                                                                        + +
                                                                        + + +
                                                                        +
                                                                        + GitHub Repo +
                                                                        +
                                                                        +
                                                                        + +
                                                                        + +
                                                                        + +
                                                                        + + + + + + +
                                                                        +
                                                                        + + + +
                                                                        +
                                                                        +
                                                                        + + + + +
                                                                        + + +
                                                                        + +
                                                                        + + +
                                                                        +
                                                                        + GitHub Repo +
                                                                        +
                                                                        +
                                                                        + +
                                                                          + + + + + + + +
                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + MicroPython Home + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + Glossary + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + References + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + Contributing + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + Contact + + + + +
                                                                        • + + + + + + + + + +
                                                                        • + + + + + Colophon + + + + +
                                                                        • + + + +
                                                                        +
                                                                        +
                                                                        +
                                                                        +
                                                                        + + + +
                                                                        +
                                                                        +
                                                                        + + +
                                                                        + + + + + + + +
                                                                          + +
                                                                        • + + + Beginning concepts + + + +
                                                                          +
                                                                            + +
                                                                          • + + + Physical Computing + + + +
                                                                          • + +
                                                                          • + + + Sensors + + + +
                                                                          • + +
                                                                          • + + + Switches and Buttons + + + +
                                                                          • + +
                                                                          • + + + Sensing Light + + + +
                                                                          • + +
                                                                          • + + + [Sensing Distance] + + + +
                                                                            +
                                                                              + +
                                                                            • + + + Ping Distance Sensors + + + +
                                                                            • + +
                                                                            • + + + Time of Flight Distance Sensors + + + +
                                                                            • + +
                                                                            +
                                                                            + +
                                                                          • + +
                                                                          • + + + Motors + + + +
                                                                          • + +
                                                                          • + + + DC Motors + + + +
                                                                          • + +
                                                                          • + + + Servos + + + +
                                                                          • + +
                                                                          • + + + Stepper Motors + + + +
                                                                          • + +
                                                                          • + + + Batteries and Power + + + +
                                                                            +
                                                                              + +
                                                                            • + + + AA Batteries + + + +
                                                                            • + +
                                                                            • + + + LiPo Batteries + + + +
                                                                            • + +
                                                                            +
                                                                            + +
                                                                          • + +
                                                                          +
                                                                          + +
                                                                        • + +
                                                                        • + + + Intermediate Concepts + + + +
                                                                          +
                                                                            + +
                                                                          • + + + Interrupts + + + +
                                                                          • + +
                                                                          +
                                                                          + +
                                                                        • + +
                                                                        • + + + Advanced Concepts + + + +
                                                                          +
                                                                            + +
                                                                          • + + + MultiCore Programming + + + +
                                                                          • + +
                                                                          +
                                                                          + +
                                                                        • + +
                                                                        • + + + References + + + +
                                                                        • + +
                                                                        + +
                                                                        +
                                                                        +
                                                                        +
                                                                        + + + +
                                                                        +
                                                                        + + + + + + + +

                                                                        MicroPython Concept Cards

                                                                        +

                                                                        This is a list of concept cards that are related to MicroPython. Our goal is to print these concept cards on 1/2 sheet laminated paper and have them available at the center of the tables in our CoderDojo Classrooms.

                                                                        +

                                                                        Please let me know if you are willing to volunteer.

                                                                        +

                                                                        Each concept card will have the content stored in a MarkDown file. A Python script will convert the MarkDown into HTML with a CSS file that paginates the output.

                                                                        +

                                                                        Concept Cards

                                                                        +

                                                                        Beginning concepts

                                                                        +

                                                                        Physical Computing

                                                                        +

                                                                        Sensors

                                                                        +

                                                                        Switches and Buttons

                                                                        +

                                                                        Sensing Light

                                                                        +

                                                                        [Sensing Distance]

                                                                        +

                                                                        Ping Distance Sensors

                                                                        +

                                                                        Time of Flight Distance Sensors

                                                                        +

                                                                        Motors

                                                                        +

                                                                        DC Motors

                                                                        +

                                                                        Servos

                                                                        +

                                                                        Stepper Motors

                                                                        +

                                                                        Batteries and Power

                                                                        +

                                                                        AA Batteries

                                                                        +

                                                                        LiPo Batteries

                                                                        +

                                                                        Intermediate Concepts

                                                                        +

                                                                        Interrupts

                                                                        +

                                                                        Advanced Concepts

                                                                        +

                                                                        MultiCore Programming

                                                                        +

                                                                        References

                                                                        +

                                                                        https://www.sitepoint.com/css-printer-friendly-pages/

                                                                        +

                                                                        https://www.jotform.com/blog/css-perfect-print-stylesheet-98272/

                                                                        + + + + + + + + + + + + + + + +
                                                                        +
                                                                        + + + +
                                                                        + + + +
                                                                        + +
                                                                        + + + +
                                                                        +
                                                                        +
                                                                        + + + Made with + + Material for MkDocs + + +
                                                                        + +
                                                                        +
                                                                        +
                                                                        + +
                                                                        +
                                                                        +
                                                                        +
                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/docs/css/extra.css b/css/extra.css similarity index 100% rename from docs/css/extra.css rename to css/extra.css diff --git a/debugging/28-debugging-python/index.html b/debugging/28-debugging-python/index.html new file mode 100644 index 000000000..87411789b --- /dev/null +++ b/debugging/28-debugging-python/index.html @@ -0,0 +1,2026 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Debugging Python - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                        + + + + Skip to content + + +
                                                                        +
                                                                        + +
                                                                        + + + + + + +
                                                                        +
                                                                        + + + logo + + + +
                                                                        +
                                                                        +
                                                                        + + MicroPython for Kids + +
                                                                        +
                                                                        + + + Debugging Python + + +
                                                                        +
                                                                        +
                                                                        + + + + + + + +
                                                                        + +
                                                                        +
                                                                        + + +
                                                                        + + +
                                                                        + +
                                                                        +
                                                                        +
                                                                        +
                                                                        +
                                                                        + Initializing search +
                                                                        +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + +
                                                                          + +
                                                                          + + +
                                                                          +
                                                                          + GitHub Repo +
                                                                          +
                                                                          +
                                                                          + +
                                                                          + +
                                                                          + +
                                                                          + + + + + + +
                                                                          +
                                                                          + + + +
                                                                          +
                                                                          +
                                                                          + + + + +
                                                                          + + +
                                                                          + +
                                                                          + + +
                                                                          +
                                                                          + GitHub Repo +
                                                                          +
                                                                          +
                                                                          + +
                                                                            + + + + + + + +
                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + MicroPython Home + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + +
                                                                            + + + + + Advanced Labs + + + + + + + + +
                                                                            + +
                                                                            + +
                                                                              + + + + + + + + + +
                                                                            • + + + + + Internal Temperature + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Interrupt Handlers + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Timing Functions + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Conda Environment Setup + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + OS Functions + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + I2C Scanner + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Frame Buffer + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Minicom + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + SD Card Reader + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Converting CircuitPython + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + MicroPython Remote + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Rshell + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Timers + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Memory Management + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + TinyML + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + String Formatting + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Operating System + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + Measuring Battery Voltage + + + + +
                                                                            • + + + + + + + + + + +
                                                                            • + + + + + File System + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + +
                                                                              + +
                                                                                + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + Debugging Python + + + + + + + +
                                                                                + + + + + + + +
                                                                                  + +
                                                                                • + + + Listing the Modules + + + +
                                                                                • + +
                                                                                • + + + Micropython issues + + + +
                                                                                • + +
                                                                                + +
                                                                                + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Debugging I2C + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Debugging SPI + + + + +
                                                                              • + + + + +
                                                                              +
                                                                              + +
                                                                            • + + + + +
                                                                            +
                                                                            + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + Glossary + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + References + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + Contributing + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + Contact + + + + +
                                                                          • + + + + + + + + + +
                                                                          • + + + + + Colophon + + + + +
                                                                          • + + + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + + +
                                                                          +
                                                                          +
                                                                          + + +
                                                                          + + + + + + + +
                                                                            + +
                                                                          • + + + Listing the Modules + + + +
                                                                          • + +
                                                                          • + + + Micropython issues + + + +
                                                                          • + +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + + +
                                                                          +
                                                                          + + + + + + + +

                                                                          How to Debug Micropython

                                                                          +

                                                                          Listing the Modules

                                                                          +
                                                                          1
                                                                          help('modules')
                                                                          +
                                                                          +

                                                                          Result:

                                                                          +
                                                                           1
                                                                          + 2
                                                                          + 3
                                                                          + 4
                                                                          + 5
                                                                          + 6
                                                                          + 7
                                                                          + 8
                                                                          + 9
                                                                          +10
                                                                          __main__          gc                uasyncio/funcs    uos
                                                                          +_boot             machine           uasyncio/lock     urandom
                                                                          +_onewire          math              uasyncio/stream   ure
                                                                          +_rp2              micropython       ubinascii         uselect
                                                                          +_thread           onewire           ucollections      ustruct
                                                                          +_uasyncio         rp2               uctypes           usys
                                                                          +builtins          uasyncio/__init__ uhashlib          utime
                                                                          +ds18x20           uasyncio/core     uio               uzlib
                                                                          +framebuf          uasyncio/event    ujson
                                                                          +Plus any modules on the filesystem
                                                                          +
                                                                          +

                                                                          Micropython issues

                                                                          +

                                                                          https://github.com/micropython/micropython/issues

                                                                          + + + + + + + + + + + + + + + +
                                                                          +
                                                                          + + + +
                                                                          + + + +
                                                                          + +
                                                                          + + + +
                                                                          + + + +
                                                                          + + +
                                                                          +
                                                                          + + Previous + +
                                                                          + Gain Pot +
                                                                          +
                                                                          +
                                                                          + + + + +
                                                                          + + Next + +
                                                                          + Debugging I2C +
                                                                          +
                                                                          +
                                                                          + + +
                                                                          +
                                                                          + +
                                                                          + + +
                                                                          +
                                                                          +
                                                                          + + + Made with + + Material for MkDocs + + +
                                                                          + +
                                                                          +
                                                                          +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/debugging/29-debugging-spi/index.html b/debugging/29-debugging-spi/index.html new file mode 100644 index 000000000..1308e9a4a --- /dev/null +++ b/debugging/29-debugging-spi/index.html @@ -0,0 +1,2192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Debugging SPI - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                          + + + + Skip to content + + +
                                                                          +
                                                                          + +
                                                                          + + + + + + +
                                                                          +
                                                                          + + + logo + + + +
                                                                          +
                                                                          +
                                                                          + + MicroPython for Kids + +
                                                                          +
                                                                          + + + Debugging SPI + + +
                                                                          +
                                                                          +
                                                                          + + + + + + + +
                                                                          + +
                                                                          +
                                                                          + + +
                                                                          + + +
                                                                          + +
                                                                          +
                                                                          +
                                                                          +
                                                                          +
                                                                          + Initializing search +
                                                                          +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            + + +
                                                                            + +
                                                                            + + +
                                                                            +
                                                                            + GitHub Repo +
                                                                            +
                                                                            +
                                                                            + +
                                                                            + +
                                                                            + +
                                                                            + + + + + + +
                                                                            +
                                                                            + + + +
                                                                            +
                                                                            +
                                                                            + + + + +
                                                                            + + +
                                                                            + +
                                                                            + + +
                                                                            +
                                                                            + GitHub Repo +
                                                                            +
                                                                            +
                                                                            + +
                                                                              + + + + + + + +
                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + MicroPython Home + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + +
                                                                              + + + + + Advanced Labs + + + + + + + + +
                                                                              + +
                                                                              + +
                                                                                + + + + + + + + + +
                                                                              • + + + + + Internal Temperature + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Interrupt Handlers + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Timing Functions + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Conda Environment Setup + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + OS Functions + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + I2C Scanner + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Frame Buffer + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Minicom + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + SD Card Reader + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Converting CircuitPython + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + MicroPython Remote + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Rshell + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Timers + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Memory Management + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + TinyML + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + String Formatting + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Operating System + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + Measuring Battery Voltage + + + + +
                                                                              • + + + + + + + + + + +
                                                                              • + + + + + File System + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + +
                                                                                + +
                                                                                  + + + + + + + +
                                                                                • + + + + + Debugging Python + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Debugging I2C + + + + +
                                                                                • + + + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + Debugging SPI + + + + + + + +
                                                                                  + + + + + + + +
                                                                                    + +
                                                                                  • + + + The SSD1306 SPI OLED Timing Diagram + + + +
                                                                                  • + +
                                                                                  • + + + OLED SPI settings + + + +
                                                                                  • + +
                                                                                  • + + + Setting up a Logic Analyzer + + + +
                                                                                    +
                                                                                      + +
                                                                                    • + + + Setup SPI Analyser + + + +
                                                                                    • + +
                                                                                    • + + + Configure SPI Channel Settings + + + +
                                                                                    • + +
                                                                                    +
                                                                                    + +
                                                                                  • + +
                                                                                  • + + + Check a Working Device + + + +
                                                                                  • + +
                                                                                  • + + + Viewing Data Clock and RES + + + +
                                                                                    +
                                                                                      + +
                                                                                    • + + + Clock Period + + + +
                                                                                    • + +
                                                                                    +
                                                                                    + +
                                                                                  • + +
                                                                                  • + + + References + + + +
                                                                                  • + +
                                                                                  + +
                                                                                  + +
                                                                                • + + + + +
                                                                                +
                                                                                + +
                                                                              • + + + + +
                                                                              +
                                                                              + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + Glossary + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + References + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + Contributing + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + Contact + + + + +
                                                                            • + + + + + + + + + +
                                                                            • + + + + + Colophon + + + + +
                                                                            • + + + +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            + + + +
                                                                            +
                                                                            +
                                                                            + + +
                                                                            + + + + + + + +
                                                                              + +
                                                                            • + + + The SSD1306 SPI OLED Timing Diagram + + + +
                                                                            • + +
                                                                            • + + + OLED SPI settings + + + +
                                                                            • + +
                                                                            • + + + Setting up a Logic Analyzer + + + +
                                                                              +
                                                                                + +
                                                                              • + + + Setup SPI Analyser + + + +
                                                                              • + +
                                                                              • + + + Configure SPI Channel Settings + + + +
                                                                              • + +
                                                                              +
                                                                              + +
                                                                            • + +
                                                                            • + + + Check a Working Device + + + +
                                                                            • + +
                                                                            • + + + Viewing Data Clock and RES + + + +
                                                                              +
                                                                                + +
                                                                              • + + + Clock Period + + + +
                                                                              • + +
                                                                              +
                                                                              + +
                                                                            • + +
                                                                            • + + + References + + + +
                                                                            • + +
                                                                            + +
                                                                            +
                                                                            +
                                                                            +
                                                                            + + + +
                                                                            +
                                                                            + + + + + + + +

                                                                            Debugging SPI

                                                                            +

                                                                            In this lab we use a logic analyzer to debug the SPI protocol being used to drive a sample OLED device. We will be using the the 8 port Saleae Logic Analyser. The retail cost is about $399.00 although there are lower cost logic analyzer available.

                                                                            +

                                                                            The SSD1306 SPI OLED Timing Diagram

                                                                            +

                                                                            The OLED display is a read-only interface. It does not send any data back to the microcontroller, so there is no MOSI connection. The data is transmitted on the SDK line when the SCL line goes high. The CS line must be low for the OLED to be active.

                                                                            +

                                                                            For details, see section 8.1.3 MCU Serial Interface on page 21 of the SSD1305 132 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller.

                                                                            +

                                                                            SSD1306 Timing Diagram

                                                                            +

                                                                            OLED SPI settings

                                                                            +

                                                                            Our OLED device has seven wires. In addition to power and ground there a five data connections we will be observing on our logic analyzer.

                                                                            +

                                                                            SPI OLED Connections

                                                                            +
                                                                              +
                                                                            1. CS - Chip Select pin 4
                                                                            2. +
                                                                            3. DC - Data/Command - pin 5
                                                                            4. +
                                                                            5. RES - Reset - pin 6
                                                                            6. +
                                                                            7. SDA - Data - SPIO TX GP7 pin 10 (Data from the )
                                                                            8. +
                                                                            9. SCL - Clock - Connect to SPIO SCK GP6 pin 9
                                                                            10. +
                                                                            11. VCC - Connect to the 3.3V Out pin 36
                                                                            12. +
                                                                            13. GND - pin 38 or 3 any other GND pin
                                                                            14. +
                                                                            +

                                                                            Setting up a Logic Analyzer

                                                                            +

                                                                            Setup SPI Analyser

                                                                            +

                                                                            SPI Logic Analyser Analysis Option

                                                                            +

                                                                            Configure SPI Channel Settings

                                                                            +

                                                                            SPI Logic Analyser Settings
                                                                            +Saleae Logic Analyser SPI Logic Analyser Settings

                                                                            +

                                                                            Check a Working Device

                                                                            +

                                                                            The first thing we want to see is what the signals to a working SPI OLED should be. There are plenty of working drivers for the Arduino, so I hooked one up to the Logic analizer to see what they were.

                                                                            +

                                                                            Viewing Data Clock and RES

                                                                            +

                                                                            SPI Clock

                                                                            +

                                                                            SPI Clock FUll
                                                                            +All five signals

                                                                            +

                                                                            SPI Logic Analyser
                                                                            +DC and CS signals have a larger period.

                                                                            +

                                                                            +
                                                                              +
                                                                            1. DC on was 3.668 milliseconds
                                                                            2. +
                                                                            +

                                                                            Clock Period

                                                                            +

                                                                            Our Clock (SCL) has 8 positive pulses with a width of .4167 microseconds. This means that the positve/negative combined width has a period of 2 * .4167 = .8333 microseconds. This can be converted into a frequency of 1.2 megahertz.

                                                                            +

                                                                            +

                                                                            +

                                                                            References

                                                                            +

                                                                            Video on how to use the Saleae Logic Analyzer

                                                                            +

                                                                            https://www.youtube.com/watch?v=Ak9R4yxQPhs

                                                                            + + + + + + + + + + + + + + + +
                                                                            +
                                                                            + + + +
                                                                            + + + +
                                                                            + +
                                                                            + + + +
                                                                            + + + +
                                                                            + + +
                                                                            +
                                                                            + + Previous + +
                                                                            + Debugging I2C +
                                                                            +
                                                                            +
                                                                            + + + + +
                                                                            + + Next + +
                                                                            + Introduction +
                                                                            +
                                                                            +
                                                                            + + +
                                                                            +
                                                                            + +
                                                                            + + +
                                                                            +
                                                                            +
                                                                            + + + Made with + + Material for MkDocs + + +
                                                                            + +
                                                                            +
                                                                            +
                                                                            + +
                                                                            +
                                                                            +
                                                                            +
                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/debugging/29a-debugging-i2c/index.html b/debugging/29a-debugging-i2c/index.html new file mode 100644 index 000000000..c1205db41 --- /dev/null +++ b/debugging/29a-debugging-i2c/index.html @@ -0,0 +1,1927 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Debugging I2C - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                            + + + + Skip to content + + +
                                                                            +
                                                                            + +
                                                                            + + + + + + +
                                                                            +
                                                                            + + + logo + + + +
                                                                            +
                                                                            +
                                                                            + + MicroPython for Kids + +
                                                                            +
                                                                            + + + Debugging I2C + + +
                                                                            +
                                                                            +
                                                                            + + + + + + + +
                                                                            + +
                                                                            +
                                                                            + + +
                                                                            + + +
                                                                            + +
                                                                            +
                                                                            +
                                                                            +
                                                                            +
                                                                            + Initializing search +
                                                                            +
                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              + + +
                                                                              + +
                                                                              + + +
                                                                              +
                                                                              + GitHub Repo +
                                                                              +
                                                                              +
                                                                              + +
                                                                              + +
                                                                              + +
                                                                              + + + + + + +
                                                                              +
                                                                              + + + +
                                                                              +
                                                                              +
                                                                              + + + + +
                                                                              + + +
                                                                              + +
                                                                              + + +
                                                                              +
                                                                              + GitHub Repo +
                                                                              +
                                                                              +
                                                                              + +
                                                                                + + + + + + + +
                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + MicroPython Home + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + +
                                                                                + + + + + Advanced Labs + + + + + + + + +
                                                                                + +
                                                                                + +
                                                                                  + + + + + + + + + +
                                                                                • + + + + + Internal Temperature + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Interrupt Handlers + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Timing Functions + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Conda Environment Setup + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + OS Functions + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + I2C Scanner + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Frame Buffer + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Minicom + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + SD Card Reader + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Converting CircuitPython + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + MicroPython Remote + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Rshell + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Timers + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Memory Management + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + TinyML + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + String Formatting + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Operating System + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + Measuring Battery Voltage + + + + +
                                                                                • + + + + + + + + + + +
                                                                                • + + + + + File System + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Spectrum Analyzer + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + +
                                                                                  + +
                                                                                    + + + + + + + +
                                                                                  • + + + + + Debugging Python + + + + +
                                                                                  • + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + Debugging I2C + + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Debugging SPI + + + + +
                                                                                  • + + + + +
                                                                                  +
                                                                                  + +
                                                                                • + + + + +
                                                                                +
                                                                                + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + Glossary + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + References + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + Contributing + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + Contact + + + + +
                                                                              • + + + + + + + + + +
                                                                              • + + + + + Colophon + + + + +
                                                                              • + + + +
                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              + + + +
                                                                              +
                                                                              +
                                                                              + + +
                                                                              + + + + + + +
                                                                              +
                                                                              +
                                                                              +
                                                                              + + + +
                                                                              +
                                                                              + + + + + + + +

                                                                              Debugging I2C Bus

                                                                              +

                                                                              + + + + + + + + + + + + + + + +
                                                                              +
                                                                              + + + +
                                                                              + + + +
                                                                              + +
                                                                              + + + +
                                                                              + + + +
                                                                              + + +
                                                                              +
                                                                              + + Previous + +
                                                                              + Debugging Python +
                                                                              +
                                                                              +
                                                                              + + + + +
                                                                              + + Next + +
                                                                              + Debugging SPI +
                                                                              +
                                                                              +
                                                                              + + +
                                                                              +
                                                                              + +
                                                                              + + +
                                                                              +
                                                                              +
                                                                              + + + Made with + + Material for MkDocs + + +
                                                                              + +
                                                                              +
                                                                              +
                                                                              + +
                                                                              +
                                                                              +
                                                                              +
                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/01-intro/index.html b/displays/graph/01-intro/index.html new file mode 100644 index 000000000..10dcbdbb1 --- /dev/null +++ b/displays/graph/01-intro/index.html @@ -0,0 +1,2006 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                              + + + + Skip to content + + +
                                                                              +
                                                                              + +
                                                                              + + + + + + +
                                                                              +
                                                                              + + + logo + + + +
                                                                              +
                                                                              +
                                                                              + + MicroPython for Kids + +
                                                                              +
                                                                              + + + Introduction + + +
                                                                              +
                                                                              +
                                                                              + + + + + + + +
                                                                              + +
                                                                              +
                                                                              + + +
                                                                              + + +
                                                                              + +
                                                                              +
                                                                              +
                                                                              +
                                                                              +
                                                                              + Initializing search +
                                                                              +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + + +
                                                                                + +
                                                                                + + +
                                                                                +
                                                                                + GitHub Repo +
                                                                                +
                                                                                +
                                                                                + +
                                                                                + +
                                                                                + +
                                                                                + + + + + + +
                                                                                +
                                                                                + + + +
                                                                                +
                                                                                +
                                                                                + + + + +
                                                                                + + +
                                                                                + +
                                                                                + + +
                                                                                +
                                                                                + GitHub Repo +
                                                                                +
                                                                                +
                                                                                + +
                                                                                  + + + + + + + +
                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + MicroPython Home + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + +
                                                                                  + +
                                                                                    + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                    + + + + + + + +
                                                                                      + +
                                                                                    • + + + I2C Scanner + + + +
                                                                                    • + +
                                                                                    • + + + References + + + +
                                                                                    • + +
                                                                                    + +
                                                                                    + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Wiring Harness + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Graphic LCD + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Basic Drawing + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Drawing with Bitmaps + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Custom Drawing Functions + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Color LCD ST7789V + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Timing Draw Speed + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + TFT ILI9341 + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + LCD Waveshare + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + E-Paper + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Setup + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED SSD1306 I2C + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED SSD 1352 + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Bounce + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Pot + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Ping + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Pong + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Pixel Draw + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED Patterns + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + Random Hearts + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + NeoPixel Matrix + + + + +
                                                                                  • + + + + + + + + + + +
                                                                                  • + + + + + OLED References + + + + +
                                                                                  • + + + + +
                                                                                  +
                                                                                  + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + Glossary + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + References + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + Contributing + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + Contact + + + + +
                                                                                • + + + + + + + + + +
                                                                                • + + + + + Colophon + + + + +
                                                                                • + + + +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + + + +
                                                                                +
                                                                                +
                                                                                + + +
                                                                                + + + + + + + +
                                                                                  + +
                                                                                • + + + I2C Scanner + + + +
                                                                                • + +
                                                                                • + + + References + + + +
                                                                                • + +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                + + + +
                                                                                +
                                                                                + + + + + + + +

                                                                                Introduction to OLED Displays

                                                                                +


                                                                                +Four colors of 2.44" OLED displays from DIY More. We can purchase them on EBay for around $18 each.

                                                                                +

                                                                                We use small OLED displays in many of our labs because:

                                                                                +
                                                                                  +
                                                                                1. They are inexpensive (around $4).
                                                                                2. +
                                                                                3. They are easy to connect** via I2C and SPI. Just four wires for I2C and seven wires for SPI.
                                                                                4. +
                                                                                5. They have a large area to display feedback. Most of them are 128X64 pixels.
                                                                                6. +
                                                                                7. Once you get the drivers installed (not always easy) they are easy to program. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions.
                                                                                8. +
                                                                                9. OLEDs, unlike LCDs, have high contrast over a large range of input voltages. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast.
                                                                                10. +
                                                                                11. There is plenty of sample code and tutorials available.
                                                                                12. +
                                                                                13. You can program them with Python (our student's favorite language)
                                                                                14. +
                                                                                15. They are crazy fun!
                                                                                16. +
                                                                                +

                                                                                The first step is to find out what type of display graphics chip is used in your OLED.

                                                                                +

                                                                                In these lessons we will assume you have a 128X64 or similar OLED display. Many of these displays can be purchased for around $4 on eBay. Many of these displays use the popular SSD1306 chip to drive the displays. There are also to communication options:

                                                                                +
                                                                                  +
                                                                                1. I2C - simple 2 wire connection (not including power and ground)
                                                                                2. +
                                                                                3. SPI - five wires but also faster screen refresh rates
                                                                                4. +
                                                                                +

                                                                                Updating a 128X64 display using I2C takes around 37ms. When using the SPI interface, updating the display can be reduced to around 2.79ms.

                                                                                +

                                                                                These labs will assume these parameters, but you can modify the labs to use different sizes and display driver chips by only modifying a few lines of code.

                                                                                +

                                                                                I2C Scanner

                                                                                +

                                                                                Because your microcontroller might have multiple displays on it, their must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function.

                                                                                +
                                                                                1
                                                                                +2
                                                                                +3
                                                                                +4
                                                                                +5
                                                                                import machine
                                                                                +sda=machine.Pin(0) # row one on our standard Pico breadboard
                                                                                +scl=machine.Pin(1) # row two on our standard Pico breadboard
                                                                                +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                +print("Device found at decimal", i2c.scan())
                                                                                +
                                                                                +

                                                                                If you don't see a return value of "60" or similar, then you need to check your wiring and make sure that you have an I2C (not an SPI) device.

                                                                                +

                                                                                References

                                                                                +
                                                                                  +
                                                                                • Wokwi web-based simulator of OLED display
                                                                                • +
                                                                                • Mike Causer's Awesome MicroPython Display Drivers
                                                                                • +
                                                                                + + + + + + + + + + + + + + + +
                                                                                +
                                                                                + + + +
                                                                                + + + +
                                                                                + +
                                                                                + + + +
                                                                                + + + +
                                                                                + + +
                                                                                +
                                                                                + + Previous + +
                                                                                + 4 Digit LED +
                                                                                +
                                                                                +
                                                                                + + + + +
                                                                                + + Next + +
                                                                                + Wiring Harness +
                                                                                +
                                                                                +
                                                                                + + +
                                                                                +
                                                                                + +
                                                                                + + +
                                                                                +
                                                                                +
                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                + +
                                                                                +
                                                                                +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/02-oled-setup/index.html b/displays/graph/02-oled-setup/index.html new file mode 100644 index 000000000..197d5ed8a --- /dev/null +++ b/displays/graph/02-oled-setup/index.html @@ -0,0 +1,2126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Setup - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                + + + + Skip to content + + +
                                                                                +
                                                                                + +
                                                                                + + + + + + +
                                                                                +
                                                                                + + + logo + + + +
                                                                                +
                                                                                +
                                                                                + + MicroPython for Kids + +
                                                                                +
                                                                                + + + OLED Setup + + +
                                                                                +
                                                                                +
                                                                                + + + + + + + +
                                                                                + +
                                                                                +
                                                                                + + +
                                                                                + + +
                                                                                + +
                                                                                +
                                                                                +
                                                                                +
                                                                                +
                                                                                + Initializing search +
                                                                                +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + + +
                                                                                  + +
                                                                                  + + +
                                                                                  +
                                                                                  + GitHub Repo +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  + +
                                                                                  + +
                                                                                  + + + + + + +
                                                                                  +
                                                                                  + + + +
                                                                                  +
                                                                                  +
                                                                                  + + + + +
                                                                                  + + +
                                                                                  + +
                                                                                  + + +
                                                                                  +
                                                                                  + GitHub Repo +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                    + + + + + + + +
                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + +
                                                                                    + +
                                                                                      + + + + + + + +
                                                                                    • + + + + + Introduction + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Wiring Harness + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Graphic LCD + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Basic Drawing + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Drawing with Bitmaps + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Custom Drawing Functions + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Color LCD ST7789V + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Timing Draw Speed + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + TFT ILI9341 + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + LCD Waveshare + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + E-Paper + + + + +
                                                                                    • + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + OLED Setup + + + + + + + +
                                                                                      + + + + + + + +
                                                                                        + +
                                                                                      • + + + I2C Scanner + + + +
                                                                                      • + +
                                                                                      • + + + SSD1306 Examples + + + +
                                                                                        +
                                                                                          + +
                                                                                        • + + + SSD1306 I2C Setup + + + +
                                                                                        • + +
                                                                                        • + + + SSD1306 SPI Setup + + + +
                                                                                        • + +
                                                                                        +
                                                                                        + +
                                                                                      • + +
                                                                                      • + + + SSH1106 I2C Setup + + + +
                                                                                      • + +
                                                                                      • + + + References + + + +
                                                                                      • + +
                                                                                      + +
                                                                                      + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED SSD1306 I2C + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED SSD 1352 + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Bounce + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Pot + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Ping + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Pong + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Pixel Draw + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED Patterns + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + Random Hearts + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + NeoPixel Matrix + + + + +
                                                                                    • + + + + + + + + + + +
                                                                                    • + + + + + OLED References + + + + +
                                                                                    • + + + + +
                                                                                    +
                                                                                    + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + Glossary + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + References + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + Contributing + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + Contact + + + + +
                                                                                  • + + + + + + + + + +
                                                                                  • + + + + + Colophon + + + + +
                                                                                  • + + + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + + + +
                                                                                  +
                                                                                  +
                                                                                  + + +
                                                                                  + + + + + + + +
                                                                                    + +
                                                                                  • + + + I2C Scanner + + + +
                                                                                  • + +
                                                                                  • + + + SSD1306 Examples + + + +
                                                                                    +
                                                                                      + +
                                                                                    • + + + SSD1306 I2C Setup + + + +
                                                                                    • + +
                                                                                    • + + + SSD1306 SPI Setup + + + +
                                                                                    • + +
                                                                                    +
                                                                                    + +
                                                                                  • + +
                                                                                  • + + + SSH1106 I2C Setup + + + +
                                                                                  • + +
                                                                                  • + + + References + + + +
                                                                                  • + +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + + + +
                                                                                  +
                                                                                  + + + + + + + +

                                                                                  OLED Setup

                                                                                  +

                                                                                  At the beginning of of your Python programs there is usually a few lines of setup instruction to tell the system which libraries to use, what pins to assign and what devices to initialize.

                                                                                  +

                                                                                  We will first look at the simple I2C setup. Then we will look at the SPI setup.

                                                                                  +

                                                                                  I2C Scanner

                                                                                  +

                                                                                  Because your microcontroller might have multiple I2C devices and displays on it, there must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function.

                                                                                  +
                                                                                  1
                                                                                  +2
                                                                                  +3
                                                                                  +4
                                                                                  +5
                                                                                  import machine
                                                                                  +sda=machine.Pin(0)
                                                                                  +scl=machine.Pin(1)
                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                  +print("Device found at decimal", i2c.scan())
                                                                                  +
                                                                                  +

                                                                                  returns: [60]

                                                                                  +

                                                                                  returns: [60]

                                                                                  +

                                                                                  SSD1306 Examples

                                                                                  +

                                                                                  SSD1306 I2C Setup

                                                                                  +
                                                                                  1
                                                                                  +2
                                                                                  +3
                                                                                  +4
                                                                                  from ssd1306 import SSD1306_I2C
                                                                                  +oled = SSD1306_I2C(128, 64, i2c)
                                                                                  +oled.text('Hello World!', 0, 0, 1)
                                                                                  +oled.show()
                                                                                  +
                                                                                  +

                                                                                  SSD1306 SPI Setup

                                                                                  +

                                                                                  Back connections: +OLED Back Connections

                                                                                  +

                                                                                  Front labels on OLED with SPI: +OLED SPI Connection

                                                                                  +

                                                                                  Here is the connection diagram:

                                                                                  +

                                                                                  SPI Connection

                                                                                  +

                                                                                  Here is the code:

                                                                                  +
                                                                                   1
                                                                                  + 2
                                                                                  + 3
                                                                                  + 4
                                                                                  + 5
                                                                                  + 6
                                                                                  + 7
                                                                                  + 8
                                                                                  + 9
                                                                                  +10
                                                                                  import machine import ssd1306
                                                                                  +spi_sck=machine.Pin(2)
                                                                                  +spi_tx=machine.Pin(3)
                                                                                  +spi=machine.SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx)
                                                                                  +CS = machine.Pin(1)
                                                                                  +DC = machine.Pin(4)
                                                                                  +RES = machine.Pin(5)
                                                                                  +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                  +oled.text('Hello World!', 0, 0, 1)
                                                                                  +oled.show()
                                                                                  +
                                                                                  +

                                                                                  SSH1106 I2C Setup

                                                                                  +
                                                                                  1
                                                                                  +2
                                                                                  +3
                                                                                  +4
                                                                                  +5
                                                                                  +6
                                                                                  +7
                                                                                  +8
                                                                                  +9
                                                                                  from machine import Pin, I2C
                                                                                  +import sh1106
                                                                                  +
                                                                                  +sda=machine.Pin(0)
                                                                                  +scl=machine.Pin(1)
                                                                                  +i2c = I2C(0, scl=scl, sda=sda, freq=400000)
                                                                                  +oled = SH1106_I2C(128, 64, i2c)
                                                                                  +oled.text('Hello World!', 0, 0, 1)
                                                                                  +oled.show()
                                                                                  +
                                                                                  +

                                                                                  References

                                                                                  +

                                                                                  Micropython SSD1306 Driver on GitHub

                                                                                  + + + + + + + + + + + + + + + +
                                                                                  +
                                                                                  + + + +
                                                                                  + + + +
                                                                                  + +
                                                                                  + + + +
                                                                                  + + + +
                                                                                  + + +
                                                                                  +
                                                                                  + + Previous + +
                                                                                  + E-Paper +
                                                                                  +
                                                                                  +
                                                                                  + + + + +
                                                                                  + + Next + +
                                                                                  + OLED SSD1306 I2C +
                                                                                  +
                                                                                  +
                                                                                  + + +
                                                                                  +
                                                                                  + +
                                                                                  + + +
                                                                                  +
                                                                                  +
                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/03-basic-drawing/index.html b/displays/graph/03-basic-drawing/index.html new file mode 100644 index 000000000..5c5df4522 --- /dev/null +++ b/displays/graph/03-basic-drawing/index.html @@ -0,0 +1,2327 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Basic Drawing - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                  + + + + Skip to content + + +
                                                                                  +
                                                                                  + +
                                                                                  + + + + + + +
                                                                                  +
                                                                                  + + + logo + + + +
                                                                                  +
                                                                                  +
                                                                                  + + MicroPython for Kids + +
                                                                                  +
                                                                                  + + + Basic Drawing + + +
                                                                                  +
                                                                                  +
                                                                                  + + + + + + + +
                                                                                  + +
                                                                                  +
                                                                                  + + +
                                                                                  + + +
                                                                                  + +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  +
                                                                                  + Initializing search +
                                                                                  +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    + + +
                                                                                    + +
                                                                                    + + +
                                                                                    +
                                                                                    + GitHub Repo +
                                                                                    +
                                                                                    +
                                                                                    + +
                                                                                    + +
                                                                                    + +
                                                                                    + + + + + + +
                                                                                    +
                                                                                    + + + +
                                                                                    +
                                                                                    +
                                                                                    + + + + +
                                                                                    + + +
                                                                                    + +
                                                                                    + + +
                                                                                    +
                                                                                    + GitHub Repo +
                                                                                    +
                                                                                    +
                                                                                    + +
                                                                                      + + + + + + + +
                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + +
                                                                                      + +
                                                                                        + + + + + + + +
                                                                                      • + + + + + Introduction + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Wiring Harness + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Graphic LCD + + + + +
                                                                                      • + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + Basic Drawing + + + + + + + +
                                                                                        + + + + + +
                                                                                          + +
                                                                                        • + + + Basic Draw Functions + + + +
                                                                                        • + +
                                                                                        • + + + Initializing the Framebuffer + + + +
                                                                                        • + +
                                                                                        • + + + Full list of Drawing Functions + + + +
                                                                                        • + +
                                                                                        • + + + Pixel Drawing Example + + + +
                                                                                        • + +
                                                                                        • + + + Drawing Tutorial and Primitives + + + +
                                                                                        • + +
                                                                                        • + + + Working with the framebuf + + + +
                                                                                        • + +
                                                                                        • + + + References + + + +
                                                                                        • + +
                                                                                        + +
                                                                                        + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Drawing with Bitmaps + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Custom Drawing Functions + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Color LCD ST7789V + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Timing Draw Speed + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + TFT ILI9341 + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + LCD Waveshare + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + E-Paper + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Setup + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED SSD1306 I2C + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED SSD 1352 + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Bounce + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Pot + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Ping + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Pong + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Pixel Draw + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED Patterns + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + Random Hearts + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + NeoPixel Matrix + + + + +
                                                                                      • + + + + + + + + + + +
                                                                                      • + + + + + OLED References + + + + +
                                                                                      • + + + + +
                                                                                      +
                                                                                      + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + Glossary + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + References + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + Contributing + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + Contact + + + + +
                                                                                    • + + + + + + + + + +
                                                                                    • + + + + + Colophon + + + + +
                                                                                    • + + + +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    + + + +
                                                                                    +
                                                                                    +
                                                                                    + + +
                                                                                    + + + + + +
                                                                                      + +
                                                                                    • + + + Basic Draw Functions + + + +
                                                                                    • + +
                                                                                    • + + + Initializing the Framebuffer + + + +
                                                                                    • + +
                                                                                    • + + + Full list of Drawing Functions + + + +
                                                                                    • + +
                                                                                    • + + + Pixel Drawing Example + + + +
                                                                                    • + +
                                                                                    • + + + Drawing Tutorial and Primitives + + + +
                                                                                    • + +
                                                                                    • + + + Working with the framebuf + + + +
                                                                                    • + +
                                                                                    • + + + References + + + +
                                                                                    • + +
                                                                                    + +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    + + + +
                                                                                    +
                                                                                    + + + + + + + +

                                                                                    Basic Drawing

                                                                                    + +

                                                                                    Basic Draw Functions

                                                                                    +

                                                                                    For our beginning labs we will just do some basic drawing. We will start out with just four functions:

                                                                                    +
                                                                                      +
                                                                                    1. Initialize the display framebuffer memory with the right object class initialization
                                                                                    2. +
                                                                                    3. Fill the framebuffer will zeros which are black pixels with the oled.fill(0)
                                                                                    4. +
                                                                                    5. Draw white text in the framebuffer memory with the oled.text("Hello World!", 40, 10)
                                                                                    6. +
                                                                                    7. Send the entire framebuffer to the display over the bus with the oled.show() function.
                                                                                    8. +
                                                                                    +

                                                                                    Initializing the Framebuffer

                                                                                    +

                                                                                    Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled "oled" using the following line:

                                                                                    +
                                                                                    1
                                                                                    +2
                                                                                    from ssd1306 import SSD1306_I2C
                                                                                    +oled = SSD1306_I2C(128, 64, i2c)
                                                                                    +
                                                                                    + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    FunctionDescriptionParameters
                                                                                    oled.fill(0)Fill the display with white or black0=black and 1=white
                                                                                    oled.text("Hello",Draw textString, x (horizontal from left edge) and y (vertical from the top)Example: Draw "Hello World" 40 over and 10 down. oled.text("Hello World!", 40, 10)
                                                                                    showShow the displaySend the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.
                                                                                    +

                                                                                    The full program would look like this:

                                                                                    +
                                                                                    1
                                                                                    +2
                                                                                    +3
                                                                                    +4
                                                                                    +5
                                                                                    from ssd1306 import SSD1306_I2C
                                                                                    +oled = SSD1306_I2C(128, 64, i2c)
                                                                                    +oled.fill(0)
                                                                                    +oled.text("Hello World!", 0, 0)
                                                                                    +oled.show()
                                                                                    +
                                                                                    +

                                                                                    This would display the following:

                                                                                    +

                                                                                    OLED SPI Hello World

                                                                                    +

                                                                                    Full list of Drawing Functions

                                                                                    +

                                                                                    Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class.

                                                                                    +

                                                                                    1
                                                                                    +2
                                                                                    from ssd1306 import SSD1306_I2C
                                                                                    +print(dir(SSD1306_I2C))
                                                                                    +
                                                                                    +This returns the following list:

                                                                                    +

                                                                                    1
                                                                                    +2
                                                                                    +3
                                                                                    +4
                                                                                    +5
                                                                                    ['__class__', '__init__', '__module__', '__name__', '__qualname__',
                                                                                    +'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline',
                                                                                    +'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline',
                                                                                    +'init_display', 'write_cmd', 'show', 'poweroff', 'poweron',
                                                                                    +'contrast', 'write_data']
                                                                                    +
                                                                                    +Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions.

                                                                                    +

                                                                                    The following are relevant for the SSD1306_I2C display.

                                                                                    +

                                                                                    The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state or color is 0=off (black) and 1=on (white).

                                                                                    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    FunctionDescriptionExample
                                                                                    blit(fbuf, x, y, color)Bit Level Transferblit(fbuf, 1, 1)
                                                                                    fill(state)FillFill with black (0) or white(1)
                                                                                    fill_rectFill a rectangle
                                                                                    hline(x, x, length, state)Draw a horizontal lineDraw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1)
                                                                                    invert()invert the displayFilp the orientation of the display
                                                                                    line(x1,y1,x2,y2)draw a line at any angleHorizontal oled.line(0,0, 127, 63, 1)
                                                                                    pixel(x,y, color)Draw a single point on the screen
                                                                                    rect(x, y, width, height)Draw an empty rectangle
                                                                                    scroll(x,y)Scroll the display
                                                                                    text(x,y,color)Write text at a point
                                                                                    vline(x,y,length, color)Draw a Vertical Lineoled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                    init_display()Initialize the display
                                                                                    write_cmdWrite a command to the display
                                                                                    show()Update the display from the frame buffer
                                                                                    poweroff()
                                                                                    poweron()
                                                                                    contrast()
                                                                                    write_data()
                                                                                    +

                                                                                    Pixel Drawing Example

                                                                                    +
                                                                                     1
                                                                                    + 2
                                                                                    + 3
                                                                                    + 4
                                                                                    + 5
                                                                                    + 6
                                                                                    + 7
                                                                                    + 8
                                                                                    + 9
                                                                                    +10
                                                                                    +11
                                                                                    +12
                                                                                    +13
                                                                                    +14
                                                                                    +15
                                                                                    +16
                                                                                    +17
                                                                                    +18
                                                                                    ICON = [
                                                                                    +    [ 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                                                                    +    [ 0, 1, 1, 0, 0, 0, 1, 1, 0],
                                                                                    +    [ 1, 1, 1, 1, 0, 1, 1, 1, 1],
                                                                                    +    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                                                                    +    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                                                                    +    [ 0, 1, 1, 1, 1, 1, 1, 1, 0],
                                                                                    +    [ 0, 0, 1, 1, 1, 1, 1, 0, 0],
                                                                                    +    [ 0, 0, 0, 1, 1, 1, 0, 0, 0],
                                                                                    +    [ 0, 0, 0, 0, 1, 0, 0, 0, 0],
                                                                                    +]
                                                                                    +
                                                                                    +display.fill(0) # Clear the display
                                                                                    +for y, row in enumerate(ICON):
                                                                                    +    for x, c in enumerate(row):
                                                                                    +        display.pixel(x, y, c)    
                                                                                    +
                                                                                    +display.show()
                                                                                    +
                                                                                    +

                                                                                    Drawing Tutorial and Primitives

                                                                                    +

                                                                                    Taken from the MicroPython site: Using a SSD1306 OLED display - although the path name imply the ESP8266, these functions also run on the Raspberry Pi Pico.

                                                                                    +
                                                                                    1
                                                                                    +2
                                                                                    +3
                                                                                    +4
                                                                                    +5
                                                                                    +6
                                                                                    +7
                                                                                    +8
                                                                                    +9
                                                                                    display.poweroff()     # power off the display, pixels persist in memory
                                                                                    +display.poweron()      # power on the display, pixels redrawn
                                                                                    +display.contrast(0)    # dim
                                                                                    +display.contrast(255)  # bright
                                                                                    +display.invert(1)      # display inverted
                                                                                    +display.invert(0)      # display normal
                                                                                    +display.rotate(True)   # rotate 180 degrees
                                                                                    +display.rotate(False)  # rotate 0 degrees
                                                                                    +display.show()         # write the contents of the FrameBuffer to display memory
                                                                                    +
                                                                                    +
                                                                                     1
                                                                                    + 2
                                                                                    + 3
                                                                                    + 4
                                                                                    + 5
                                                                                    + 6
                                                                                    + 7
                                                                                    + 8
                                                                                    + 9
                                                                                    +10
                                                                                    display.fill(0)                         # fill entire screen with colour=0
                                                                                    +display.pixel(0, 10)                    # get pixel at x=0, y=10
                                                                                    +display.pixel(0, 10, 1)                 # set pixel at x=0, y=10 to colour=1
                                                                                    +display.hline(0, 8, 4, 1)               # draw horizontal line x=0, y=8, width=4, colour=1
                                                                                    +display.vline(0, 8, 4, 1)               # draw vertical line x=0, y=8, height=4, colour=1
                                                                                    +display.line(0, 0, 127, 63, 1)          # draw a line from 0,0 to 127,63
                                                                                    +display.rect(10, 10, 107, 43, 1)        # draw a rectangle outline 10,10 to 107,43, colour=1
                                                                                    +display.fill_rect(10, 10, 107, 43, 1)   # draw a solid rectangle 10,10 to 107,43, colour=1
                                                                                    +display.text('Hello World', 0, 0, 1)    # draw some text at x=0, y=0, colour=1
                                                                                    +display.scroll(20, 0)                   # scroll 20 pixels to the right
                                                                                    +
                                                                                    +

                                                                                    Working with the framebuf

                                                                                    +

                                                                                    A frame buffer is a region of RAM that holds an exact image of what is on the display. The data can be copied from the framebuffer memory with the blit() (BLock Transfer) operation that copies a rectangular area of one framebuffer to another framebuffer.

                                                                                    +

                                                                                    Here is an example of the blit() function:

                                                                                    +
                                                                                    1
                                                                                    oled.blit(my_frame_buf, 10, 10, 0)
                                                                                    +
                                                                                    +
                                                                                    1
                                                                                    +2
                                                                                    +3
                                                                                    +4
                                                                                    +5
                                                                                    +6
                                                                                    # draw another FrameBuffer on top of the current one at the given coordinates
                                                                                    +import framebuf
                                                                                    +fbuf = framebuf.FrameBuffer(bytearray(8 * 8 * 1), 8, 8, framebuf.MONO_VLSB)
                                                                                    +fbuf.line(0, 0, 7, 7, 1)
                                                                                    +display.blit(fbuf, 10, 10, 0)           # draw on top at x=10, y=10, key=0
                                                                                    +display.show()
                                                                                    +
                                                                                    +

                                                                                    References

                                                                                    +
                                                                                      +
                                                                                    • MicroPython Documentation on FrameBuffer
                                                                                    • +
                                                                                    • Drawing Primitive Shapes
                                                                                    • +
                                                                                    • Driving I2C OLED displays with MicroPython - by Martin Fitzpatrick
                                                                                    • +
                                                                                    • ST7735 Micropython Driver by Anthony Norman
                                                                                    • +
                                                                                    + + + + + + + + + + + + + + + +
                                                                                    +
                                                                                    + + + +
                                                                                    + + + +
                                                                                    + +
                                                                                    + + + +
                                                                                    + + + +
                                                                                    + + +
                                                                                    +
                                                                                    + + Previous + +
                                                                                    + Graphic LCD +
                                                                                    +
                                                                                    +
                                                                                    + + + + +
                                                                                    + + Next + +
                                                                                    + Drawing with Bitmaps +
                                                                                    +
                                                                                    +
                                                                                    + + +
                                                                                    +
                                                                                    + +
                                                                                    + + +
                                                                                    +
                                                                                    +
                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                    + +
                                                                                    +
                                                                                    +
                                                                                    + +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/03-bitmaps/index.html b/displays/graph/03-bitmaps/index.html new file mode 100644 index 000000000..e5d2fa60c --- /dev/null +++ b/displays/graph/03-bitmaps/index.html @@ -0,0 +1,2152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Drawing with Bitmaps - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                    + + + + Skip to content + + +
                                                                                    +
                                                                                    + +
                                                                                    + + + + + + +
                                                                                    +
                                                                                    + + + logo + + + +
                                                                                    +
                                                                                    +
                                                                                    + + MicroPython for Kids + +
                                                                                    +
                                                                                    + + + Drawing with Bitmaps + + +
                                                                                    +
                                                                                    +
                                                                                    + + + + + + + +
                                                                                    + +
                                                                                    +
                                                                                    + + +
                                                                                    + + +
                                                                                    + +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    +
                                                                                    + Initializing search +
                                                                                    +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      + + +
                                                                                      + +
                                                                                      + + +
                                                                                      +
                                                                                      + GitHub Repo +
                                                                                      +
                                                                                      +
                                                                                      + +
                                                                                      + +
                                                                                      + +
                                                                                      + + + + + + +
                                                                                      +
                                                                                      + + + +
                                                                                      +
                                                                                      +
                                                                                      + + + + +
                                                                                      + + +
                                                                                      + +
                                                                                      + + +
                                                                                      +
                                                                                      + GitHub Repo +
                                                                                      +
                                                                                      +
                                                                                      + +
                                                                                        + + + + + + + +
                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + +
                                                                                        + +
                                                                                          + + + + + + + +
                                                                                        • + + + + + Introduction + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Wiring Harness + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Graphic LCD + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Basic Drawing + + + + +
                                                                                        • + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + Drawing with Bitmaps + + + + + + + +
                                                                                          + + + + + + + +
                                                                                            + +
                                                                                          • + + + Framebuffers + + + +
                                                                                          • + +
                                                                                          • + + + Block Image Transfers (blit) + + + +
                                                                                          • + +
                                                                                          • + + + Blit Functions Are Efficient + + + +
                                                                                          • + +
                                                                                          • + + + Working with ByteArrays + + + +
                                                                                          • + +
                                                                                          • + + + Creating a Solid Block of Pixels + + + +
                                                                                          • + +
                                                                                          • + + + Image Encoding Options + + + +
                                                                                            +
                                                                                              + +
                                                                                            • + + + Vertical Least Significant Bit Layout + + + +
                                                                                            • + +
                                                                                            • + + + Horizontal + + + +
                                                                                            • + +
                                                                                            +
                                                                                            + +
                                                                                          • + +
                                                                                          • + + + References + + + +
                                                                                          • + +
                                                                                          + +
                                                                                          + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Custom Drawing Functions + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Color LCD ST7789V + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Timing Draw Speed + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + TFT ILI9341 + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + LCD Waveshare + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + E-Paper + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Setup + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED SSD1306 I2C + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED SSD 1352 + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Bounce + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Pot + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Ping + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Pong + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Pixel Draw + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED Patterns + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + Random Hearts + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + NeoPixel Matrix + + + + +
                                                                                        • + + + + + + + + + + +
                                                                                        • + + + + + OLED References + + + + +
                                                                                        • + + + + +
                                                                                        +
                                                                                        + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + Glossary + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + References + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + Contributing + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + Contact + + + + +
                                                                                      • + + + + + + + + + +
                                                                                      • + + + + + Colophon + + + + +
                                                                                      • + + + +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      + + + +
                                                                                      +
                                                                                      +
                                                                                      + + +
                                                                                      + + + + + + + +
                                                                                        + +
                                                                                      • + + + Framebuffers + + + +
                                                                                      • + +
                                                                                      • + + + Block Image Transfers (blit) + + + +
                                                                                      • + +
                                                                                      • + + + Blit Functions Are Efficient + + + +
                                                                                      • + +
                                                                                      • + + + Working with ByteArrays + + + +
                                                                                      • + +
                                                                                      • + + + Creating a Solid Block of Pixels + + + +
                                                                                      • + +
                                                                                      • + + + Image Encoding Options + + + +
                                                                                        +
                                                                                          + +
                                                                                        • + + + Vertical Least Significant Bit Layout + + + +
                                                                                        • + +
                                                                                        • + + + Horizontal + + + +
                                                                                        • + +
                                                                                        +
                                                                                        + +
                                                                                      • + +
                                                                                      • + + + References + + + +
                                                                                      • + +
                                                                                      + +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      + + + +
                                                                                      +
                                                                                      + + + + + + + +

                                                                                      Drawing Bitmaps with MicroPython

                                                                                      +

                                                                                      Framebuffers

                                                                                      +

                                                                                      A Framebuffer is the core data structure we use when drawing bitmaps.

                                                                                      +

                                                                                      Block Image Transfers (blit)

                                                                                      +

                                                                                      The basic function we use to draw a rectangular region of the screen is called the blit() function:

                                                                                      +
                                                                                      1
                                                                                      display.blit(frame_buffer, x, y)
                                                                                      +
                                                                                      +

                                                                                      This function moves all the data within any frame buffer to the given (x,y) position of the display. The function will check the dimensions of the frame buffer to know how much data to move to the display. You just need to tell the function where to start drawing.

                                                                                      +

                                                                                      Blit Functions Are Efficient

                                                                                      +

                                                                                      Blit operations can be much more efficient then the display.show() function when you are just updating a small region of the screen. This is because the display.show() function transfers the entire screen image each time it is called. Using blit functions can be written to only update the area of the screen that changes.

                                                                                      +

                                                                                      For example, if you are writing a video game that has a ball moving across the screen, you only need to update the pixels around the ball, not the entire screen image. The exact performance difference between show() and blit() operations will depend on the size of the screen, the size of the blit update and the speed of the transfer of data from the framebuffer to the display device.

                                                                                      +

                                                                                      The key disadvantage of using blit() functions is that you must consider what other artifacts there are on the screen that you might overwrite. Keeping track of the differences requires more computation by the microcontroller. The more powerful your microcontroller is relative to the communication speed, the more difference computations you can do.

                                                                                      +

                                                                                      Not all display drivers will let you write directly from the microcontroller resident image directly to a region of the display. Sometimes you must follow your blit() operations with a show() to transfer the entire framebuffer to the display.

                                                                                      +

                                                                                      Working with ByteArrays

                                                                                      +

                                                                                      MicroPython blit operations use a data representation format for images called a ByteArray. These are sequences of the bytes that will be sent in a blit operation. They are coded using the following notation:

                                                                                      +
                                                                                      1
                                                                                      my_bytearray = (b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD")
                                                                                      +
                                                                                      +

                                                                                      Note that the letter b begins the parameter to show the Python interpreter that the all the characters between the double quotes are byte array values. The characters \x indicate that there are hexadecimals useds to encode the bit values.

                                                                                      +

                                                                                      Creating a Solid Block of Pixels

                                                                                      +

                                                                                      Sometimes you want to update an entire region of the screen with a block of pixels that are all on or off. You can do this with the following steps

                                                                                      +
                                                                                      1
                                                                                      +2
                                                                                      +3
                                                                                      +4
                                                                                      +5
                                                                                      +6
                                                                                      +7
                                                                                      +8
                                                                                      +9
                                                                                      # create a 10x10 matrix of on pixels
                                                                                      +# allocate an array of 20 bytes = 
                                                                                      +on_buffer = bytearray(20)
                                                                                      +# put all 1's in that buffer
                                                                                      +on_buffer[:] = b'\xff' * 20
                                                                                      +# create a frame buffer using monochrome 
                                                                                      +on_square = framebuf.FrameBuffer(on_buffer, 10, 10, framebuf.MONO_HLSB)
                                                                                      +
                                                                                      +oled.blit(logo, i, 0)
                                                                                      +
                                                                                      +

                                                                                      Image Encoding Options

                                                                                      +

                                                                                      There are several alternate methods to encode the bits of an image into a byte array. The bits can be coded left to right or top to bottom. You can also put the bits in most-significant bit first or least-significant bit first. All these options and controlled when you interface with a framebuffer.

                                                                                      +

                                                                                      Vertical Least Significant Bit Layout

                                                                                      +

                                                                                      framebuf.MONO_VLSB +Monochrome (1-bit) color format This defines a mapping where the bits in a byte are vertically mapped with bit 0 being nearest the top of the screen. Consequently each byte occupies 8 vertical pixels. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached. Further bytes are rendered at locations starting at the leftmost edge, 8 pixels lower.

                                                                                      +

                                                                                      Horizontal

                                                                                      +

                                                                                      MONO_HLSB. Monochrome (1-bit) color format This defines a mapping where the bits in a byte are horizontally mapped. Each byte occupies 8 horizontal pixels with bit 7 being the leftmost. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached.

                                                                                      +

                                                                                      References

                                                                                      +

                                                                                      MicroPython Bitmap Tool Video - this video created by Lucky Resistor +is a good overview of the image formats used by MicroPython.

                                                                                      + + + + + + + + + + + + + + + +
                                                                                      +
                                                                                      + + + +
                                                                                      + + + +
                                                                                      + +
                                                                                      + + + +
                                                                                      + + + +
                                                                                      + + +
                                                                                      +
                                                                                      + + Previous + +
                                                                                      + Basic Drawing +
                                                                                      +
                                                                                      +
                                                                                      + + + + +
                                                                                      + + Next + +
                                                                                      + Custom Drawing Functions +
                                                                                      +
                                                                                      +
                                                                                      + + +
                                                                                      +
                                                                                      + +
                                                                                      + + +
                                                                                      +
                                                                                      +
                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                      + +
                                                                                      +
                                                                                      +
                                                                                      + +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/04-extended-drawing-functions/index.html b/displays/graph/04-extended-drawing-functions/index.html new file mode 100644 index 000000000..273dafca8 --- /dev/null +++ b/displays/graph/04-extended-drawing-functions/index.html @@ -0,0 +1,2112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Custom Drawing Functions - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                      + + + + Skip to content + + +
                                                                                      +
                                                                                      + +
                                                                                      + + + + + + +
                                                                                      +
                                                                                      + + + logo + + + +
                                                                                      +
                                                                                      +
                                                                                      + + MicroPython for Kids + +
                                                                                      +
                                                                                      + + + Custom Drawing Functions + + +
                                                                                      +
                                                                                      +
                                                                                      + + + + + + + +
                                                                                      + +
                                                                                      +
                                                                                      + + +
                                                                                      + + +
                                                                                      + +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      +
                                                                                      + Initializing search +
                                                                                      +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + + +
                                                                                        + +
                                                                                        + + +
                                                                                        +
                                                                                        + GitHub Repo +
                                                                                        +
                                                                                        +
                                                                                        + +
                                                                                        + +
                                                                                        + +
                                                                                        + + + + + + +
                                                                                        +
                                                                                        + + + +
                                                                                        +
                                                                                        +
                                                                                        + + + + +
                                                                                        + + +
                                                                                        + +
                                                                                        + + +
                                                                                        +
                                                                                        + GitHub Repo +
                                                                                        +
                                                                                        +
                                                                                        + +
                                                                                          + + + + + + + +
                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + +
                                                                                          + +
                                                                                            + + + + + + + +
                                                                                          • + + + + + Introduction + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Wiring Harness + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Graphic LCD + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Basic Drawing + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Drawing with Bitmaps + + + + +
                                                                                          • + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + Custom Drawing Functions + + + + + + + +
                                                                                            + + + + + + + +
                                                                                              + +
                                                                                            • + + + Circle + + + +
                                                                                            • + +
                                                                                            • + + + Testing Circle Drawing + + + +
                                                                                            • + +
                                                                                            • + + + Drawing a Face + + + +
                                                                                            • + +
                                                                                            + +
                                                                                            + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Color LCD ST7789V + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Timing Draw Speed + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + TFT ILI9341 + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + LCD Waveshare + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + E-Paper + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Setup + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED SSD1306 I2C + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED SSD 1352 + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Bounce + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Pot + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Ping + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Pong + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Pixel Draw + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED Patterns + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + Random Hearts + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + NeoPixel Matrix + + + + +
                                                                                          • + + + + + + + + + + +
                                                                                          • + + + + + OLED References + + + + +
                                                                                          • + + + + +
                                                                                          +
                                                                                          + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + Glossary + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + References + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + Contributing + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + Contact + + + + +
                                                                                        • + + + + + + + + + +
                                                                                        • + + + + + Colophon + + + + +
                                                                                        • + + + +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + + + +
                                                                                        +
                                                                                        +
                                                                                        + + +
                                                                                        + + + + + + + +
                                                                                          + +
                                                                                        • + + + Circle + + + +
                                                                                        • + +
                                                                                        • + + + Testing Circle Drawing + + + +
                                                                                        • + +
                                                                                        • + + + Drawing a Face + + + +
                                                                                        • + +
                                                                                        + +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + + + +
                                                                                        +
                                                                                        + + + + + + + +

                                                                                        Extending Drawing Functions

                                                                                        +

                                                                                        Although there are several drawing functions available in most of the standard graphics libraries, most of them lack some basic shapes such as a circle. To draw circles on your display, you will need to add new Python functions. Here are some examples of these custom drawing functions.

                                                                                        +

                                                                                        Circle

                                                                                        +

                                                                                        Here is a function to draw a circle at a given (x,y) point with a radius of r and fill indicator.

                                                                                        +

                                                                                        Here are the parameters for circle functions

                                                                                        +
                                                                                          +
                                                                                        1. X position of the circle center
                                                                                        2. +
                                                                                        3. Y position of the circle center
                                                                                        4. +
                                                                                        5. The radius of the circle in pixels
                                                                                        6. +
                                                                                        7. The color of the circle (1 for on and 0 for off.
                                                                                        8. +
                                                                                        +
                                                                                         1
                                                                                        + 2
                                                                                        + 3
                                                                                        + 4
                                                                                        + 5
                                                                                        + 6
                                                                                        + 7
                                                                                        + 8
                                                                                        + 9
                                                                                        +10
                                                                                        +11
                                                                                        +12
                                                                                        +13
                                                                                        from math import sqrt
                                                                                        +
                                                                                        +def draw_circle(cx, cy, r, color):
                                                                                        +    diameter = r*2
                                                                                        +    upper_left_x = cx - r
                                                                                        +    upper_left_y = cy - r 
                                                                                        +    # scan through all pixels and only turn on pixels within r of the center
                                                                                        +    for i in range(upper_left_x, upper_left_x + diameter):
                                                                                        +        for j in range(upper_left_y, upper_left_y + diameter):
                                                                                        +            # distance of the current point (i, j) from the center (cx, cy)
                                                                                        +            d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 )
                                                                                        +            if d < r:
                                                                                        +                oled.pixel(i, j, color)
                                                                                        +
                                                                                        +

                                                                                        Testing Circle Drawing

                                                                                        +
                                                                                         1
                                                                                        + 2
                                                                                        + 3
                                                                                        + 4
                                                                                        + 5
                                                                                        + 6
                                                                                        + 7
                                                                                        + 8
                                                                                        + 9
                                                                                        +10
                                                                                        +11
                                                                                        +12
                                                                                        +13
                                                                                        +14
                                                                                        +15
                                                                                        +16
                                                                                        +17
                                                                                        +18
                                                                                        +19
                                                                                        +20
                                                                                        +21
                                                                                        +22
                                                                                        +23
                                                                                        +24
                                                                                        +25
                                                                                        +26
                                                                                        +27
                                                                                        +28
                                                                                        +29
                                                                                        +30
                                                                                        +31
                                                                                        +32
                                                                                        +33
                                                                                        +34
                                                                                        +35
                                                                                        +36
                                                                                        +37
                                                                                        +38
                                                                                        +39
                                                                                        +40
                                                                                        +41
                                                                                        +42
                                                                                        +43
                                                                                        from machine import Pin
                                                                                        +from utime import sleep
                                                                                        +from math import sqrt
                                                                                        +import ssd1306
                                                                                        +
                                                                                        +WIDTH = 128
                                                                                        +HEIGHT = 64
                                                                                        +clock=Pin(2) # SCL
                                                                                        +data=Pin(3) # SDA
                                                                                        +RES = machine.Pin(4)
                                                                                        +DC = machine.Pin(5)
                                                                                        +CS = machine.Pin(6)
                                                                                        +
                                                                                        +spi=machine.SPI(0, sck=clock, mosi=data)
                                                                                        +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                        +
                                                                                        +def circle(cx, cy, r, color):
                                                                                        +    diameter = r*2
                                                                                        +    upper_left_x = cx - r
                                                                                        +    upper_left_y = cy - r 
                                                                                        +    # scan through all pixels and only turn on pixels within r of the center
                                                                                        +    for i in range(upper_left_x, upper_left_x + diameter):
                                                                                        +        for j in range(upper_left_y, upper_left_y + diameter):
                                                                                        +            # distance of the current point (i, j) from the center (cx, cy)
                                                                                        +            d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 )
                                                                                        +            if d < r:
                                                                                        +                oled.pixel(i, j, color)
                                                                                        +
                                                                                        +HALF_WIDTH = int(WIDTH/2)
                                                                                        +HALF_HEIGHT = int(HEIGHT/2)
                                                                                        +while True:
                                                                                        +    for rad in range(1,HALF_HEIGHT+2):
                                                                                        +        draw_circle(HALF_WIDTH, HALF_HEIGHT, rad, 1)
                                                                                        +        oled.show()
                                                                                        +        sleep(.1)
                                                                                        +    sleep(3)
                                                                                        +    oled.fill(1)
                                                                                        +    for rad in range(1,HALF_HEIGHT+2):
                                                                                        +        circle(HALF_WIDTH, HALF_HEIGHT, rad, 0)
                                                                                        +        oled.show()
                                                                                        +        sleep(.1)
                                                                                        +    oled.fill(0)
                                                                                        +    sleep(3)
                                                                                        +
                                                                                        +

                                                                                        Drawing a Face

                                                                                        +

                                                                                        If we assume we have a 64x128 display we can call two circle functions to draw eyes

                                                                                        +

                                                                                        display.fill(0) # Clear the display. +display.circle(32, 32, 10, 1) # draw the left eye

                                                                                        + + + + + + + + + + + + + + + +
                                                                                        +
                                                                                        + + + +
                                                                                        + + + +
                                                                                        + +
                                                                                        + + + +
                                                                                        + + + +
                                                                                        + + +
                                                                                        +
                                                                                        + + Previous + +
                                                                                        + Drawing with Bitmaps +
                                                                                        +
                                                                                        +
                                                                                        + + + + +
                                                                                        + + Next + +
                                                                                        + Color LCD ST7789V +
                                                                                        +
                                                                                        +
                                                                                        + + +
                                                                                        +
                                                                                        + +
                                                                                        + + +
                                                                                        +
                                                                                        +
                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                        + +
                                                                                        +
                                                                                        +
                                                                                        + +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/05-timing-draw-speed/index.html b/displays/graph/05-timing-draw-speed/index.html new file mode 100644 index 000000000..8ea2b03e3 --- /dev/null +++ b/displays/graph/05-timing-draw-speed/index.html @@ -0,0 +1,2134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Timing Draw Speed - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                        + + + + Skip to content + + +
                                                                                        +
                                                                                        + +
                                                                                        + + + + + + +
                                                                                        +
                                                                                        + + + logo + + + +
                                                                                        +
                                                                                        +
                                                                                        + + MicroPython for Kids + +
                                                                                        +
                                                                                        + + + Timing Draw Speed + + +
                                                                                        +
                                                                                        +
                                                                                        + + + + + + + +
                                                                                        + +
                                                                                        +
                                                                                        + + +
                                                                                        + + +
                                                                                        + +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        +
                                                                                        + Initializing search +
                                                                                        +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + + +
                                                                                          + +
                                                                                          + + +
                                                                                          +
                                                                                          + GitHub Repo +
                                                                                          +
                                                                                          +
                                                                                          + +
                                                                                          + +
                                                                                          + +
                                                                                          + + + + + + +
                                                                                          +
                                                                                          + + + +
                                                                                          +
                                                                                          +
                                                                                          + + + + +
                                                                                          + + +
                                                                                          + +
                                                                                          + + +
                                                                                          +
                                                                                          + GitHub Repo +
                                                                                          +
                                                                                          +
                                                                                          + +
                                                                                            + + + + + + + +
                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + +
                                                                                            + +
                                                                                              + + + + + + + +
                                                                                            • + + + + + Introduction + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Wiring Harness + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Graphic LCD + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Basic Drawing + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Drawing with Bitmaps + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Custom Drawing Functions + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Color LCD ST7789V + + + + +
                                                                                            • + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + Timing Draw Speed + + + + + + + +
                                                                                              + + + + + + + +
                                                                                                + +
                                                                                              • + + + Sample Function Timer Code + + + +
                                                                                              • + +
                                                                                              • + + + Sample Function Code + + + +
                                                                                              • + +
                                                                                              • + + + Comparing Two Circle Drawing Algorithms + + + +
                                                                                              • + +
                                                                                              + +
                                                                                              + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + TFT ILI9341 + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + LCD Waveshare + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + E-Paper + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Setup + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED SSD1306 I2C + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED SSD 1352 + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Bounce + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Pot + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Ping + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Pong + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Pixel Draw + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED Patterns + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + Random Hearts + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + NeoPixel Matrix + + + + +
                                                                                            • + + + + + + + + + + +
                                                                                            • + + + + + OLED References + + + + +
                                                                                            • + + + + +
                                                                                            +
                                                                                            + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + Glossary + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + References + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + Contributing + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + Contact + + + + +
                                                                                          • + + + + + + + + + +
                                                                                          • + + + + + Colophon + + + + +
                                                                                          • + + + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + + + +
                                                                                          +
                                                                                          +
                                                                                          + + +
                                                                                          + + + + + + + +
                                                                                            + +
                                                                                          • + + + Sample Function Timer Code + + + +
                                                                                          • + +
                                                                                          • + + + Sample Function Code + + + +
                                                                                          • + +
                                                                                          • + + + Comparing Two Circle Drawing Algorithms + + + +
                                                                                          • + +
                                                                                          + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + + + +
                                                                                          +
                                                                                          + + + + + + + +

                                                                                          Timing Drawing Speed

                                                                                          +

                                                                                          If you are writing a video game and want fast drawing times for objects on the screen, there are several different algorithms you can try. You can use the MicroPython time_us function to +record the time before and after you call a drawing function and return the difference +to get an idea of the time saved in different versions of your drawing functions.

                                                                                          +

                                                                                          Sample Function Timer Code

                                                                                          +

                                                                                          Sample Function Code

                                                                                          +
                                                                                          1
                                                                                          +2
                                                                                          +3
                                                                                          +4
                                                                                          +5
                                                                                          +6
                                                                                          from utime import ticks_us
                                                                                          +
                                                                                          +start = ticks_us()
                                                                                          +my_function()
                                                                                          +end = ticks_us()
                                                                                          +print('Execution time in microseconds:', end - start)
                                                                                          +
                                                                                          +

                                                                                          MicroPython also supports the ticks_cpu() function which could return a smaller granularity +for precise time measurements. However, on the Raspberry Pi implementation, the results are exactly +the same as the ticks_us() function.

                                                                                          +

                                                                                          Comparing Two Circle Drawing Algorithms

                                                                                          +

                                                                                          In the following code, we compare two circle drawing algorithms.

                                                                                          +
                                                                                            +
                                                                                          1. Row Scanner Method - this method scans each pixel in the square around the circle and turns it on if the pixel is within a distance range. It must calculate the distance of each pixel and compare
                                                                                          2. +
                                                                                          3. that distance to both the inside and outside distances. The time-consuming operations are to calculate the squares of the x and y distances.
                                                                                          4. +
                                                                                          5. Point Draw Method - this method walks around the circle and for each degree, it draws a single pixel at the edge of the circle. Each point uses the sine() and cosine() functions to calculate the x and y distance from the center of the circle to that point.
                                                                                          6. +
                                                                                          +

                                                                                          For small circles, it is very inefficient to calculate all 360 points. Scanning all the points in a 5X5 grid only takes 25 calculations. However, the larger the circle becomes, the more points there are to calculate in the row scanner method. A 20X20 circle will need to run the distance calculation 400 times.

                                                                                          +
                                                                                           1
                                                                                          + 2
                                                                                          + 3
                                                                                          + 4
                                                                                          + 5
                                                                                          + 6
                                                                                          + 7
                                                                                          + 8
                                                                                          + 9
                                                                                          +10
                                                                                          +11
                                                                                          +12
                                                                                          +13
                                                                                          +14
                                                                                          +15
                                                                                          +16
                                                                                          +17
                                                                                          +18
                                                                                          +19
                                                                                          +20
                                                                                          +21
                                                                                          +22
                                                                                          +23
                                                                                          +24
                                                                                          +25
                                                                                          +26
                                                                                          +27
                                                                                          +28
                                                                                          +29
                                                                                          +30
                                                                                          +31
                                                                                          +32
                                                                                          +33
                                                                                          +34
                                                                                          +35
                                                                                          +36
                                                                                          +37
                                                                                          +38
                                                                                          +39
                                                                                          +40
                                                                                          +41
                                                                                          +42
                                                                                          +43
                                                                                          +44
                                                                                          +45
                                                                                          +46
                                                                                          +47
                                                                                          +48
                                                                                          +49
                                                                                          +50
                                                                                          +51
                                                                                          +52
                                                                                          +53
                                                                                          +54
                                                                                          +55
                                                                                          +56
                                                                                          from utime import sleep, ticks_cpu, ticks_us
                                                                                          +import math
                                                                                          +import ssd1306
                                                                                          +
                                                                                          +# this is the built-in LED on the Pico
                                                                                          +led = Pin('LED', Pin.OUT)
                                                                                          +
                                                                                          +WIDTH = 128
                                                                                          +HEIGHT = 64
                                                                                          +clock=Pin(2)
                                                                                          +data=Pin(3)
                                                                                          +RES = machine.Pin(4)
                                                                                          +DC = machine.Pin(5)
                                                                                          +CS = machine.Pin(6)
                                                                                          +
                                                                                          +spi=machine.SPI(0, sck=clock, mosi=data)
                                                                                          +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                          +
                                                                                          +# 
                                                                                          +def fast_circle(x, y, r, color):
                                                                                          +    # draw points around a circle skiping every 4th one
                                                                                          +    for theta in range(0, 360, 2):
                                                                                          +        # we can save 5% of the time by only doing this once
                                                                                          +        radians = math.radians(theta)
                                                                                          +        x_pos = int(x + r * math.cos(radians))
                                                                                          +        y_pos = int(y + r * math.sin(radians))
                                                                                          +        # check if we are within range
                                                                                          +        #if 0 <= x_pos < 128 and 0 <= y_pos < 64:
                                                                                          +        # we can cut another 5% by not doing these checks
                                                                                          +        oled.pixel(x_pos, y_pos, color)
                                                                                          +
                                                                                          +def circle(x, y, r, color):
                                                                                          +    diameter1 = (r - 0.5) ** 2
                                                                                          +    diameter2 = (r + 0.5) ** 2
                                                                                          +    x_min = max(0, int(x - r))
                                                                                          +    x_max = min(128, int(x + r + 1))
                                                                                          +    y_min = max(0, int(y - r))
                                                                                          +    y_max = min(64, int(y + r + 1))
                                                                                          +
                                                                                          +    for y_pos in range(y_min, y_max):
                                                                                          +        for x_pos in range(x_min, x_max):
                                                                                          +            if ((x_pos - x) ** 2 + (y_pos - y) ** 2 >= diameter1) and ((x_pos - x) ** 2 + (y_pos - y) ** 2 <= diameter2):
                                                                                          +                oled.pixel(x_pos, y_pos, color)
                                                                                          +
                                                                                          +
                                                                                          +start = ticks_us()
                                                                                          +circle(32, 32, 10, 1)
                                                                                          +end = ticks_us()
                                                                                          +print('Standard scanner circle draw time in cpu ticks', end - start)
                                                                                          +oled.show()
                                                                                          +sleep(1)
                                                                                          +start = ticks_us()
                                                                                          +fast_circle(96, 32, 10, 1)
                                                                                          +end = ticks_us()
                                                                                          +print('Fast draw time in cpu ticks', end - start)
                                                                                          +oled.show()
                                                                                          +
                                                                                          +
                                                                                          +

                                                                                          Challenge

                                                                                          +
                                                                                            +
                                                                                          1. Write a program that compares drawing speed for various sizes of circles.
                                                                                          2. +
                                                                                          3. Modify the circle function to use the most efficient algorithm
                                                                                          4. +
                                                                                          5. If you have a small circle, how many points do you need to not make the circle appear broken? Try changing the number of points calculated in the line `for theta in range(0, 360, 2):. Can you dynamically change the number of points skipped as the circle becomes smaller?
                                                                                          6. +
                                                                                          7. Can you add a parameter to the circle function that only draws every 3rd point?
                                                                                          8. +
                                                                                          +
                                                                                          + + + + + + + + + + + + + + + +
                                                                                          +
                                                                                          + + + +
                                                                                          + + + +
                                                                                          + +
                                                                                          + + + +
                                                                                          + + + +
                                                                                          + + +
                                                                                          +
                                                                                          + + Previous + +
                                                                                          + Color LCD ST7789V +
                                                                                          +
                                                                                          +
                                                                                          + + + + +
                                                                                          + + Next + +
                                                                                          + TFT ILI9341 +
                                                                                          +
                                                                                          +
                                                                                          + + +
                                                                                          +
                                                                                          + +
                                                                                          + + +
                                                                                          +
                                                                                          +
                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                          + +
                                                                                          +
                                                                                          +
                                                                                          + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/10-oled-bounce/index.html b/displays/graph/10-oled-bounce/index.html new file mode 100644 index 000000000..c267bbb99 --- /dev/null +++ b/displays/graph/10-oled-bounce/index.html @@ -0,0 +1,2132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Bounce - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                          + + + + Skip to content + + +
                                                                                          +
                                                                                          + +
                                                                                          + + + + + + +
                                                                                          +
                                                                                          + + + logo + + + +
                                                                                          +
                                                                                          +
                                                                                          + + MicroPython for Kids + +
                                                                                          +
                                                                                          + + + OLED Bounce + + +
                                                                                          +
                                                                                          +
                                                                                          + + + + + + + +
                                                                                          + +
                                                                                          +
                                                                                          + + +
                                                                                          + + +
                                                                                          + +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          +
                                                                                          + Initializing search +
                                                                                          +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            + + +
                                                                                            + +
                                                                                            + + +
                                                                                            +
                                                                                            + GitHub Repo +
                                                                                            +
                                                                                            +
                                                                                            + +
                                                                                            + +
                                                                                            + +
                                                                                            + + + + + + +
                                                                                            +
                                                                                            + + + +
                                                                                            +
                                                                                            +
                                                                                            + + + + +
                                                                                            + + +
                                                                                            + +
                                                                                            + + +
                                                                                            +
                                                                                            + GitHub Repo +
                                                                                            +
                                                                                            +
                                                                                            + +
                                                                                              + + + + + + + +
                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + +
                                                                                              + +
                                                                                                + + + + + + + +
                                                                                              • + + + + + Introduction + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Wiring Harness + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Graphic LCD + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Basic Drawing + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Drawing with Bitmaps + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Custom Drawing Functions + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Color LCD ST7789V + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Timing Draw Speed + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + TFT ILI9341 + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + LCD Waveshare + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + E-Paper + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Setup + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED SSD1306 I2C + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED SSD 1352 + + + + +
                                                                                              • + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + OLED Bounce + + + + + + + +
                                                                                                + + + + + + + +
                                                                                                  + +
                                                                                                • + + + Draw a border + + + +
                                                                                                • + +
                                                                                                • + + + Make a Ball Bounce Around Inside the Wall + + + +
                                                                                                • + +
                                                                                                + +
                                                                                                + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Pot + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Ping + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Pong + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Pixel Draw + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED Patterns + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + Random Hearts + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + NeoPixel Matrix + + + + +
                                                                                              • + + + + + + + + + + +
                                                                                              • + + + + + OLED References + + + + +
                                                                                              • + + + + +
                                                                                              +
                                                                                              + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + Glossary + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + References + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + Contributing + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + Contact + + + + +
                                                                                            • + + + + + + + + + +
                                                                                            • + + + + + Colophon + + + + +
                                                                                            • + + + +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            + + + +
                                                                                            +
                                                                                            +
                                                                                            + + +
                                                                                            + + + + + + + +
                                                                                              + +
                                                                                            • + + + Draw a border + + + +
                                                                                            • + +
                                                                                            • + + + Make a Ball Bounce Around Inside the Wall + + + +
                                                                                            • + +
                                                                                            + +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            + + + +
                                                                                            +
                                                                                            + + + + + + + +

                                                                                            OLED Bounce

                                                                                            +

                                                                                            In this lesson, we will draw a box around the edge of the display using the commands that draw horizontal and vertical lines: hline and vline. Then we will draw a ball that bounces off these edges.

                                                                                            +

                                                                                            Draw a border

                                                                                            +
                                                                                             1
                                                                                            + 2
                                                                                            + 3
                                                                                            + 4
                                                                                            + 5
                                                                                            + 6
                                                                                            + 7
                                                                                            + 8
                                                                                            + 9
                                                                                            +10
                                                                                            +11
                                                                                            +12
                                                                                            +13
                                                                                            +14
                                                                                            +15
                                                                                            +16
                                                                                            +17
                                                                                            import machine
                                                                                            +import utime
                                                                                            +from ssd1306 import SSD1306_I2C
                                                                                            +
                                                                                            +sda=machine.Pin(0)
                                                                                            +scl=machine.Pin(1)
                                                                                            +i2c=machine.I2C(0,sda=sda, scl=scl)
                                                                                            +# Screen size
                                                                                            +width=128
                                                                                            +height=64
                                                                                            +oled = SSD1306_I2C(width, height, i2c)
                                                                                            +
                                                                                            +oled.hline(0, 0, width - 1, 1) # top edge
                                                                                            +oled.hline(0, height - 1, width - 1, 1) # bottom edge
                                                                                            +oled.vline(0, 0, height - 1, 1) # left edge
                                                                                            +oled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                            +oled.show()
                                                                                            +
                                                                                            +

                                                                                            Make a Ball Bounce Around Inside the Wall

                                                                                            +
                                                                                             1
                                                                                            + 2
                                                                                            + 3
                                                                                            + 4
                                                                                            + 5
                                                                                            + 6
                                                                                            + 7
                                                                                            + 8
                                                                                            + 9
                                                                                            +10
                                                                                            +11
                                                                                            +12
                                                                                            +13
                                                                                            +14
                                                                                            +15
                                                                                            +16
                                                                                            +17
                                                                                            +18
                                                                                            +19
                                                                                            +20
                                                                                            +21
                                                                                            +22
                                                                                            +23
                                                                                            +24
                                                                                            +25
                                                                                            +26
                                                                                            +27
                                                                                            +28
                                                                                            +29
                                                                                            +30
                                                                                            +31
                                                                                            +32
                                                                                            +33
                                                                                            +34
                                                                                            +35
                                                                                            +36
                                                                                            +37
                                                                                            +38
                                                                                            +39
                                                                                            +40
                                                                                            +41
                                                                                            +42
                                                                                            +43
                                                                                            +44
                                                                                            +45
                                                                                            +46
                                                                                            +47
                                                                                            +48
                                                                                            +49
                                                                                            +50
                                                                                            +51
                                                                                            +52
                                                                                            +53
                                                                                            +54
                                                                                            +55
                                                                                            +56
                                                                                            +57
                                                                                            +58
                                                                                            +59
                                                                                            +60
                                                                                            +61
                                                                                            +62
                                                                                            +63
                                                                                            +64
                                                                                            import machine
                                                                                            +import utime
                                                                                            +from ssd1306 import SSD1306_I2C
                                                                                            +
                                                                                            +sda=machine.Pin(0)
                                                                                            +scl=machine.Pin(1)
                                                                                            +i2c=machine.I2C(0,sda=sda, scl=scl)
                                                                                            +# Screen size
                                                                                            +width=128
                                                                                            +height=64
                                                                                            +oled = SSD1306_I2C(width, height, i2c)
                                                                                            +
                                                                                            +oled.fill(0) # clear to black
                                                                                            +
                                                                                            +# note that OLEDs have problems with screen burn it - don't leave this on too long!
                                                                                            +def border(width, height):
                                                                                            +    oled.hline(0, 0, width - 1, 1) # top edge
                                                                                            +    oled.hline(0, height - 1, width - 1, 1) # bottom edge
                                                                                            +    oled.vline(0, 0, height - 1, 1) # left edge
                                                                                            +    oled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                            +
                                                                                            +# ok, not really a circle - just a square for now
                                                                                            +def draw_ball(x,y, size, state):
                                                                                            +    if size == 1:
                                                                                            +        oled.pixel(x, y, state) # draw a single pixel
                                                                                            +    else:
                                                                                            +        for i in range(0,size): # draw a box of pixels of the right size
                                                                                            +            for j in range(0,size):
                                                                                            +                oled.pixel(x + i, y + j, state)
                                                                                            +    # TODO: for size above 4 round the corners
                                                                                            +
                                                                                            +border(width, height)
                                                                                            +
                                                                                            +ball_size = 2
                                                                                            +# start in the middle of the screen
                                                                                            +current_x = int(width / 2)
                                                                                            +current_y = int(height / 2)
                                                                                            +# start going down to the right
                                                                                            +direction_x = 1
                                                                                            +direction_y = -1
                                                                                            +# delay_time = .0001
                                                                                            +
                                                                                            +# Bounce forever
                                                                                            +while True:
                                                                                            +    draw_ball(current_x,current_y, ball_size,1)
                                                                                            +    oled.show()
                                                                                            +    # utime.sleep(delay_time)
                                                                                            +    draw_ball(current_x,current_y,ball_size,0)
                                                                                            +    # reverse at the edges
                                                                                            +    # left edge test
                                                                                            +    if current_x < 2:
                                                                                            +        direction_x = 1
                                                                                            +    # right edge test
                                                                                            +    if current_x > width - ball_size -2:
                                                                                            +        direction_x = -1
                                                                                            +    # top edge test
                                                                                            +    if current_y < 2:
                                                                                            +        direction_y = 1
                                                                                            +    # bottom edge test
                                                                                            +    if current_y > height - ball_size - 2:
                                                                                            +        direction_y = -1
                                                                                            +    # update the ball
                                                                                            +    current_x = current_x + direction_x
                                                                                            +    current_y = current_y + direction_y
                                                                                            +
                                                                                            + + + + + + + + + + + + + + + +
                                                                                            +
                                                                                            + + + +
                                                                                            + + + +
                                                                                            + +
                                                                                            + + + +
                                                                                            + + + +
                                                                                            + + +
                                                                                            +
                                                                                            + + Previous + +
                                                                                            + OLED SSD 1352 +
                                                                                            +
                                                                                            +
                                                                                            + + + + +
                                                                                            + + Next + +
                                                                                            + OLED Pot +
                                                                                            +
                                                                                            +
                                                                                            + + +
                                                                                            +
                                                                                            + +
                                                                                            + + +
                                                                                            +
                                                                                            +
                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                            + +
                                                                                            +
                                                                                            +
                                                                                            + +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-lcd-waveshare/index.html b/displays/graph/11-lcd-waveshare/index.html new file mode 100644 index 000000000..64880a23a --- /dev/null +++ b/displays/graph/11-lcd-waveshare/index.html @@ -0,0 +1,1986 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + LCD Waveshare - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                            + + + + Skip to content + + +
                                                                                            +
                                                                                            + +
                                                                                            + + + + + + +
                                                                                            +
                                                                                            + + + logo + + + +
                                                                                            +
                                                                                            +
                                                                                            + + MicroPython for Kids + +
                                                                                            +
                                                                                            + + + LCD Waveshare + + +
                                                                                            +
                                                                                            +
                                                                                            + + + + + + + +
                                                                                            + +
                                                                                            +
                                                                                            + + +
                                                                                            + + +
                                                                                            + +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            +
                                                                                            + Initializing search +
                                                                                            +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + + +
                                                                                              + +
                                                                                              + + +
                                                                                              +
                                                                                              + GitHub Repo +
                                                                                              +
                                                                                              +
                                                                                              + +
                                                                                              + +
                                                                                              + +
                                                                                              + + + + + + +
                                                                                              +
                                                                                              + + + +
                                                                                              +
                                                                                              +
                                                                                              + + + + +
                                                                                              + + +
                                                                                              + +
                                                                                              + + +
                                                                                              +
                                                                                              + GitHub Repo +
                                                                                              +
                                                                                              +
                                                                                              + +
                                                                                                + + + + + + + +
                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + +
                                                                                                + +
                                                                                                  + + + + + + + +
                                                                                                • + + + + + Introduction + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Wiring Harness + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Graphic LCD + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Basic Drawing + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Drawing with Bitmaps + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Custom Drawing Functions + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Color LCD ST7789V + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Timing Draw Speed + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + TFT ILI9341 + + + + +
                                                                                                • + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + LCD Waveshare + + + + + + + +
                                                                                                  + + + + + + + +
                                                                                                    + +
                                                                                                  • + + + Specification + + + +
                                                                                                  • + +
                                                                                                  • + + + References + + + +
                                                                                                  • + +
                                                                                                  + +
                                                                                                  + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + E-Paper + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Setup + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED SSD 1352 + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Bounce + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Pot + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Ping + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Pong + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Pixel Draw + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED Patterns + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + Random Hearts + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + NeoPixel Matrix + + + + +
                                                                                                • + + + + + + + + + + +
                                                                                                • + + + + + OLED References + + + + +
                                                                                                • + + + + +
                                                                                                +
                                                                                                + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + Glossary + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + References + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + Contributing + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + Contact + + + + +
                                                                                              • + + + + + + + + + +
                                                                                              • + + + + + Colophon + + + + +
                                                                                              • + + + +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + + + +
                                                                                              +
                                                                                              +
                                                                                              + + +
                                                                                              + + + + + + + +
                                                                                                + +
                                                                                              • + + + Specification + + + +
                                                                                              • + +
                                                                                              • + + + References + + + +
                                                                                              • + +
                                                                                              + +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + + + +
                                                                                              +
                                                                                              + + + + + + + +

                                                                                              Waveshare LCD

                                                                                              +

                                                                                              Specification

                                                                                              +
                                                                                                +
                                                                                              1. Description: 1.8 inch TFT LCD Display Module For Raspberry Pi Pico
                                                                                              2. +
                                                                                              3. List price: $10 US + shipping
                                                                                              4. +
                                                                                              5. 65K RGB Colors
                                                                                              6. +
                                                                                              7. Resolution: 160×128 Pixels
                                                                                              8. +
                                                                                              9. Interface: SPI
                                                                                              10. +
                                                                                              11. Driver: ST7735S Driver
                                                                                              12. +
                                                                                              13. Onboard Female Pin Header For Direct Attaching To Raspberry Pi Pico
                                                                                              14. +
                                                                                              15. Pixel size: 0.219 × 0.219 mm
                                                                                              16. +
                                                                                              17. Dimensions 52.0 × 34.5 mm
                                                                                              18. +
                                                                                              19. Operating voltage: 2.6~5.5V
                                                                                              20. +
                                                                                              21. 18 bits per pixel (6 bits per color)
                                                                                              22. +
                                                                                              +

                                                                                              References

                                                                                              +

                                                                                              Waveshare spec +Waveshare wiki +Demo Code +ST7735S Datasheet

                                                                                              + + + + + + + + + + + + + + + +
                                                                                              +
                                                                                              + + + +
                                                                                              + + + +
                                                                                              + +
                                                                                              + + + +
                                                                                              + + + +
                                                                                              + + +
                                                                                              +
                                                                                              + + Previous + +
                                                                                              + TFT ILI9341 +
                                                                                              +
                                                                                              +
                                                                                              + + + + +
                                                                                              + + Next + +
                                                                                              + E-Paper +
                                                                                              +
                                                                                              +
                                                                                              + + +
                                                                                              +
                                                                                              + +
                                                                                              + + +
                                                                                              +
                                                                                              +
                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                              + +
                                                                                              +
                                                                                              +
                                                                                              + +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-oled-ping/index.html b/displays/graph/11-oled-ping/index.html new file mode 100644 index 000000000..2ecdb632b --- /dev/null +++ b/displays/graph/11-oled-ping/index.html @@ -0,0 +1,2082 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Ping - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                              + + + + Skip to content + + +
                                                                                              +
                                                                                              + +
                                                                                              + + + + + + +
                                                                                              +
                                                                                              + + + logo + + + +
                                                                                              +
                                                                                              +
                                                                                              + + MicroPython for Kids + +
                                                                                              +
                                                                                              + + + OLED Ping + + +
                                                                                              +
                                                                                              +
                                                                                              + + + + + + + +
                                                                                              + +
                                                                                              +
                                                                                              + + +
                                                                                              + + +
                                                                                              + +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              +
                                                                                              + Initializing search +
                                                                                              +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + + +
                                                                                                + +
                                                                                                + + +
                                                                                                +
                                                                                                + GitHub Repo +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                + +
                                                                                                + +
                                                                                                + + + + + + +
                                                                                                +
                                                                                                + + + +
                                                                                                +
                                                                                                +
                                                                                                + + + + +
                                                                                                + + +
                                                                                                + +
                                                                                                + + +
                                                                                                +
                                                                                                + GitHub Repo +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                  + + + + + + + +
                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + +
                                                                                                  + +
                                                                                                    + + + + + + + +
                                                                                                  • + + + + + Introduction + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Wiring Harness + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Graphic LCD + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Basic Drawing + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Drawing with Bitmaps + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Custom Drawing Functions + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Color LCD ST7789V + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Timing Draw Speed + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + TFT ILI9341 + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + LCD Waveshare + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + E-Paper + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Setup + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED SSD 1352 + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Bounce + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Pot + + + + +
                                                                                                  • + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + OLED Ping + + + + + + + +
                                                                                                    + + + + + + + +
                                                                                                      + +
                                                                                                    • + + + Circuit + + + +
                                                                                                    • + +
                                                                                                    • + + + Coder + + + +
                                                                                                    • + +
                                                                                                    + +
                                                                                                    + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Pong + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Pixel Draw + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED Patterns + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + Random Hearts + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + NeoPixel Matrix + + + + +
                                                                                                  • + + + + + + + + + + +
                                                                                                  • + + + + + OLED References + + + + +
                                                                                                  • + + + + +
                                                                                                  +
                                                                                                  + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + Glossary + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + References + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + Contributing + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + Contact + + + + +
                                                                                                • + + + + + + + + + +
                                                                                                • + + + + + Colophon + + + + +
                                                                                                • + + + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + + + +
                                                                                                +
                                                                                                +
                                                                                                + + +
                                                                                                + + + + + + + +
                                                                                                  + +
                                                                                                • + + + Circuit + + + +
                                                                                                • + +
                                                                                                • + + + Coder + + + +
                                                                                                • + +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + + + +
                                                                                                +
                                                                                                + + + + + + + +

                                                                                                OLED PING

                                                                                                +

                                                                                                Circuit

                                                                                                +

                                                                                                +

                                                                                                Coder

                                                                                                +
                                                                                                 1
                                                                                                + 2
                                                                                                + 3
                                                                                                + 4
                                                                                                + 5
                                                                                                + 6
                                                                                                + 7
                                                                                                + 8
                                                                                                + 9
                                                                                                +10
                                                                                                +11
                                                                                                +12
                                                                                                +13
                                                                                                +14
                                                                                                +15
                                                                                                +16
                                                                                                +17
                                                                                                +18
                                                                                                +19
                                                                                                +20
                                                                                                +21
                                                                                                +22
                                                                                                +23
                                                                                                +24
                                                                                                +25
                                                                                                +26
                                                                                                +27
                                                                                                +28
                                                                                                +29
                                                                                                +30
                                                                                                +31
                                                                                                +32
                                                                                                +33
                                                                                                +34
                                                                                                +35
                                                                                                +36
                                                                                                +37
                                                                                                +38
                                                                                                +39
                                                                                                +40
                                                                                                +41
                                                                                                +42
                                                                                                +43
                                                                                                +44
                                                                                                +45
                                                                                                +46
                                                                                                +47
                                                                                                +48
                                                                                                +49
                                                                                                +50
                                                                                                +51
                                                                                                +52
                                                                                                +53
                                                                                                +54
                                                                                                +55
                                                                                                +56
                                                                                                from machine import Pin, I2C, Timer
                                                                                                +from ssd1306 import SSD1306_I2C
                                                                                                +import utime
                                                                                                +
                                                                                                +
                                                                                                +# global toggle button variable
                                                                                                +measure_on = False
                                                                                                +
                                                                                                +# debounce for button
                                                                                                +def debounce(pin):
                                                                                                +    timer.init(mode=Timer.ONE_SHOT, period=200, callback=on_pressed)
                                                                                                +
                                                                                                +# if button pressed, toggle measure_on
                                                                                                +def on_pressed(timer):
                                                                                                +    global measure_on
                                                                                                +    measure_on = not measure_on
                                                                                                +
                                                                                                +# Init button
                                                                                                +button = Pin(16, Pin.IN, Pin.PULL_DOWN)
                                                                                                +timer = Timer()
                                                                                                +button.irq(debounce, Pin.IRQ_RISING)
                                                                                                +
                                                                                                +# Init Display
                                                                                                +i2c = I2C(0,sda=Pin(0),scl=Pin(1),freq=40000)
                                                                                                +oled = SSD1306_I2C(128,64,i2c)
                                                                                                +
                                                                                                +# Init HC-SR04 pins
                                                                                                +trigger = Pin(14, Pin.OUT)
                                                                                                +echo = Pin(13, Pin.IN)
                                                                                                +
                                                                                                +
                                                                                                +def ultra():
                                                                                                +    trigger.low()
                                                                                                +    utime.sleep_us(2)
                                                                                                +    trigger.high()
                                                                                                +    utime.sleep_us(5)
                                                                                                +    trigger.low()
                                                                                                +    while echo.value() == 0:
                                                                                                +        signaloff = utime.ticks_us()
                                                                                                +    while echo.value() == 1:
                                                                                                +        signalon = utime.ticks_us()
                                                                                                +    timepassed = signalon - signaloff
                                                                                                +    distance = (timepassed * 0.0343) / 2
                                                                                                +    return distance
                                                                                                +
                                                                                                +try:
                                                                                                +    while True:
                                                                                                +        oled.fill(0)
                                                                                                +        if measure_on:
                                                                                                +            result = ultra()
                                                                                                +            oled.text("Distance:",0,0)
                                                                                                +            oled.text(str(result) + " cm",0,10)
                                                                                                +        oled.show()
                                                                                                +        utime.sleep(1)            
                                                                                                +except KeyboardInterrupt:
                                                                                                +    pass
                                                                                                +
                                                                                                + + + + + + + + + + + + + + + +
                                                                                                +
                                                                                                + + + +
                                                                                                + + + +
                                                                                                + +
                                                                                                + + + +
                                                                                                + + + +
                                                                                                + + +
                                                                                                +
                                                                                                + + Previous + +
                                                                                                + OLED Pot +
                                                                                                +
                                                                                                +
                                                                                                + + + + +
                                                                                                + + Next + +
                                                                                                + OLED Pong +
                                                                                                +
                                                                                                +
                                                                                                + + +
                                                                                                +
                                                                                                + +
                                                                                                + + +
                                                                                                +
                                                                                                +
                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-oled-sh1106-i2c/index.html b/displays/graph/11-oled-sh1106-i2c/index.html new file mode 100644 index 000000000..147554c30 --- /dev/null +++ b/displays/graph/11-oled-sh1106-i2c/index.html @@ -0,0 +1,2308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED SH1106 I2C Example - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                + + + + Skip to content + + +
                                                                                                +
                                                                                                + +
                                                                                                + + + + + + +
                                                                                                +
                                                                                                + + + logo + + + +
                                                                                                +
                                                                                                +
                                                                                                + + MicroPython for Kids + +
                                                                                                +
                                                                                                + + + OLED SH1106 I2C Example + + +
                                                                                                +
                                                                                                +
                                                                                                + + + + + + + +
                                                                                                + +
                                                                                                +
                                                                                                + + +
                                                                                                + + +
                                                                                                + +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                +
                                                                                                + Initializing search +
                                                                                                +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + +
                                                                                                  + +
                                                                                                  + + +
                                                                                                  +
                                                                                                  + GitHub Repo +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  + +
                                                                                                  + +
                                                                                                  + + + + + + +
                                                                                                  +
                                                                                                  + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + + +
                                                                                                  + + +
                                                                                                  + +
                                                                                                  + + +
                                                                                                  +
                                                                                                  + GitHub Repo +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                    + + + + + + + +
                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + +
                                                                                                    + +
                                                                                                      + + + + + + + +
                                                                                                    • + + + + + Introduction + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Wiring Harness + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Graphic LCD + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Basic Drawing + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Drawing with Bitmaps + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Custom Drawing Functions + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Color LCD ST7789V + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Timing Draw Speed + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + TFT ILI9341 + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + LCD Waveshare + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + E-Paper + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Setup + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                    • + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + OLED SH1106 I2C Example + + + + + + + +
                                                                                                      + + + + + + + +
                                                                                                        + +
                                                                                                      • + + + SH1106 Example + + + +
                                                                                                      • + +
                                                                                                      • + + + Counter Example + + + +
                                                                                                      • + +
                                                                                                      • + + + Animated Box + + + +
                                                                                                      • + +
                                                                                                      • + + + Bounce on the SH1106 Display using I2C + + + +
                                                                                                      • + +
                                                                                                      • + + + SH1106 References + + + +
                                                                                                      • + +
                                                                                                      + +
                                                                                                      + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED SSD 1352 + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Bounce + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Pot + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Ping + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Pong + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Pixel Draw + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED Patterns + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + Random Hearts + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + NeoPixel Matrix + + + + +
                                                                                                    • + + + + + + + + + + +
                                                                                                    • + + + + + OLED References + + + + +
                                                                                                    • + + + + +
                                                                                                    +
                                                                                                    + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + Glossary + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + References + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + Contributing + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + Contact + + + + +
                                                                                                  • + + + + + + + + + +
                                                                                                  • + + + + + Colophon + + + + +
                                                                                                  • + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  + + +
                                                                                                  + + + + + + + +
                                                                                                    + +
                                                                                                  • + + + SH1106 Example + + + +
                                                                                                  • + +
                                                                                                  • + + + Counter Example + + + +
                                                                                                  • + +
                                                                                                  • + + + Animated Box + + + +
                                                                                                  • + +
                                                                                                  • + + + Bounce on the SH1106 Display using I2C + + + +
                                                                                                  • + +
                                                                                                  • + + + SH1106 References + + + +
                                                                                                  • + +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + +
                                                                                                  +
                                                                                                  + + + + + + + +

                                                                                                  OLED SSD1306 I2C Examples

                                                                                                  +

                                                                                                  We use small OLED displays in many of our labs because:

                                                                                                  +
                                                                                                    +
                                                                                                  1. They are inexpensive (around $4).
                                                                                                  2. +
                                                                                                  3. They are easy to connect via SPI. Just four wires: GND, VCC, Clock and Data.
                                                                                                  4. +
                                                                                                  5. They have a large area to display feedback. Most of them are 128X64 pixels.
                                                                                                  6. +
                                                                                                  7. Once you get the drivers installed (not always easy) they are easy to program. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions.
                                                                                                  8. +
                                                                                                  9. OLEDs, unlike LCDs, have high contrast over a large range of input voltages. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast.
                                                                                                  10. +
                                                                                                  11. There is plenty of sample code and tutorials available.
                                                                                                  12. +
                                                                                                  +

                                                                                                  The first step is to find out what type of display graphics chip is used in your OLED.

                                                                                                  +

                                                                                                  SH1106 Example

                                                                                                  +
                                                                                                   1
                                                                                                  + 2
                                                                                                  + 3
                                                                                                  + 4
                                                                                                  + 5
                                                                                                  + 6
                                                                                                  + 7
                                                                                                  + 8
                                                                                                  + 9
                                                                                                  +10
                                                                                                  +11
                                                                                                  +12
                                                                                                  +13
                                                                                                  +14
                                                                                                  +15
                                                                                                  from machine import Pin, I2C
                                                                                                  +import sh1106
                                                                                                  +
                                                                                                  +sda=machine.Pin(0)
                                                                                                  +scl=machine.Pin(1)
                                                                                                  +i2c = I2C(0, scl=scl, sda=sda, freq=400000)
                                                                                                  +
                                                                                                  +display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)
                                                                                                  +display.sleep(False)
                                                                                                  +
                                                                                                  +display.fill(0)
                                                                                                  +display.text('CoderDojo', 0, 0, 1)
                                                                                                  +display.show()
                                                                                                  +
                                                                                                  +print('done')
                                                                                                  +
                                                                                                  +

                                                                                                  Counter Example

                                                                                                  +

                                                                                                  In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50.

                                                                                                  +
                                                                                                   1
                                                                                                  + 2
                                                                                                  + 3
                                                                                                  + 4
                                                                                                  + 5
                                                                                                  + 6
                                                                                                  + 7
                                                                                                  + 8
                                                                                                  + 9
                                                                                                  +10
                                                                                                  +11
                                                                                                  +12
                                                                                                  +13
                                                                                                  +14
                                                                                                  +15
                                                                                                  +16
                                                                                                  +17
                                                                                                  import machine
                                                                                                  +import utime
                                                                                                  +from ssd1306 import SSD1306_I2C
                                                                                                  +
                                                                                                  +sda=machine.Pin(0)
                                                                                                  +scl=machine.Pin(1)
                                                                                                  +i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
                                                                                                  +oled = SSD1306_I2C(128, 64, i2c)
                                                                                                  +
                                                                                                  +for i in range(1, 51): # count 1 to 50
                                                                                                  +    oled.fill(0) # clear to black
                                                                                                  +    oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black
                                                                                                  +    oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top
                                                                                                  +    oled.show() # update display
                                                                                                  +    utime.sleep(0.1) #wait 1/10th of a second
                                                                                                  +
                                                                                                  +print('done')
                                                                                                  +
                                                                                                  +

                                                                                                  Animated Box

                                                                                                  +

                                                                                                  This draws a title and four lines around a drawing area. It then draws boxes that move to the right.

                                                                                                  +
                                                                                                   1
                                                                                                  + 2
                                                                                                  + 3
                                                                                                  + 4
                                                                                                  + 5
                                                                                                  + 6
                                                                                                  + 7
                                                                                                  + 8
                                                                                                  + 9
                                                                                                  +10
                                                                                                  +11
                                                                                                  +12
                                                                                                  +13
                                                                                                  +14
                                                                                                  +15
                                                                                                  +16
                                                                                                  +17
                                                                                                  +18
                                                                                                  +19
                                                                                                  +20
                                                                                                  +21
                                                                                                  +22
                                                                                                  +23
                                                                                                  +24
                                                                                                  +25
                                                                                                  +26
                                                                                                  +27
                                                                                                  +28
                                                                                                  +29
                                                                                                  +30
                                                                                                  +31
                                                                                                  +32
                                                                                                  +33
                                                                                                  from machine import Pin, I2C
                                                                                                  +import sh1106
                                                                                                  +import utime
                                                                                                  +
                                                                                                  +sda=machine.Pin(0)
                                                                                                  +scl=machine.Pin(1)
                                                                                                  +i2c = I2C(0, scl=scl, sda=sda, freq=400000)
                                                                                                  +
                                                                                                  +## note that we can only draw from 0 to 62
                                                                                                  +display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)
                                                                                                  +display.sleep(False)
                                                                                                  +
                                                                                                  +display.fill(0) # clear to black
                                                                                                  +display.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black
                                                                                                  +# line under title
                                                                                                  +display.hline(0, 9, 127, 1)
                                                                                                  +# bottom of display
                                                                                                  +display.hline(0, 30, 127, 1)
                                                                                                  +# left edge
                                                                                                  +display.vline(0, 10, 32, 1)
                                                                                                  +# right edge
                                                                                                  +display.vline(127, 10, 32, 1)
                                                                                                  +
                                                                                                  +for i in range(0, 118):
                                                                                                  +    # box x0, y0, width, height, on
                                                                                                  +    display.fill_rect(i,10, 10, 10, 1)
                                                                                                  +    # draw black behind number
                                                                                                  +    display.fill_rect(10, 21, 30, 8, 0)
                                                                                                  +    display.text(str(i), 10, 21, 1)
                                                                                                  +    display.show() # update display
                                                                                                  +    # utime.sleep(0.001)
                                                                                                  +
                                                                                                  +print('done')
                                                                                                  +
                                                                                                  +

                                                                                                  Bounce on the SH1106 Display using I2C

                                                                                                  +

                                                                                                  This example is a ball that bounces around the inside of a border rectangle. Is similar to other bounce examples with the exception that you can't draw on the last row of pixels.

                                                                                                  +
                                                                                                   1
                                                                                                  + 2
                                                                                                  + 3
                                                                                                  + 4
                                                                                                  + 5
                                                                                                  + 6
                                                                                                  + 7
                                                                                                  + 8
                                                                                                  + 9
                                                                                                  +10
                                                                                                  +11
                                                                                                  +12
                                                                                                  +13
                                                                                                  +14
                                                                                                  +15
                                                                                                  +16
                                                                                                  +17
                                                                                                  +18
                                                                                                  +19
                                                                                                  +20
                                                                                                  +21
                                                                                                  +22
                                                                                                  +23
                                                                                                  +24
                                                                                                  +25
                                                                                                  +26
                                                                                                  +27
                                                                                                  +28
                                                                                                  +29
                                                                                                  +30
                                                                                                  +31
                                                                                                  +32
                                                                                                  +33
                                                                                                  +34
                                                                                                  +35
                                                                                                  +36
                                                                                                  +37
                                                                                                  +38
                                                                                                  +39
                                                                                                  +40
                                                                                                  +41
                                                                                                  +42
                                                                                                  +43
                                                                                                  +44
                                                                                                  +45
                                                                                                  +46
                                                                                                  +47
                                                                                                  +48
                                                                                                  +49
                                                                                                  +50
                                                                                                  +51
                                                                                                  +52
                                                                                                  +53
                                                                                                  +54
                                                                                                  +55
                                                                                                  +56
                                                                                                  +57
                                                                                                  +58
                                                                                                  +59
                                                                                                  +60
                                                                                                  +61
                                                                                                  +62
                                                                                                  +63
                                                                                                  +64
                                                                                                  +65
                                                                                                  +66
                                                                                                  +67
                                                                                                  +68
                                                                                                  import machine
                                                                                                  +import utime
                                                                                                  +# from ssd1306 import SSD1306_I2C
                                                                                                  +import sh1106
                                                                                                  +
                                                                                                  +sda=machine.Pin(0)
                                                                                                  +scl=machine.Pin(1)
                                                                                                  +i2c=machine.I2C(0,sda=sda, scl=scl)
                                                                                                  +# Screen size
                                                                                                  +width=128
                                                                                                  +height=64 # we could make this be 63 but the init method should use the full value
                                                                                                  +# oled = SSD1306_I2C(width, height, i2c)
                                                                                                  +oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c)
                                                                                                  +
                                                                                                  +oled.fill(0) # clear to black
                                                                                                  +
                                                                                                  +# note that OLEDs have problems with screen burn it - don't leave this on too long!
                                                                                                  +def border(width, height):
                                                                                                  +    oled.hline(0, 0, width - 1, 1) # top edge
                                                                                                  +    oled.hline(0, height - 2, width - 1, 1) # bottom edge
                                                                                                  +    oled.vline(0, 0, height - 1, 1) # left edge
                                                                                                  +    oled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                                  +
                                                                                                  +# ok, not really a circle - just a square for now
                                                                                                  +def draw_ball(x,y, size, state):
                                                                                                  +    if size == 1:
                                                                                                  +        oled.pixel(x, y, state) # draw a single pixel
                                                                                                  +    else:
                                                                                                  +        for i in range(0,size): # draw a box of pixels of the right size
                                                                                                  +            for j in range(0,size):
                                                                                                  +                oled.pixel(x + i, y + j, state)
                                                                                                  +    # TODO: for size above 4 round the corners
                                                                                                  +
                                                                                                  +border(width, height)
                                                                                                  +
                                                                                                  +ball_size = 5
                                                                                                  +current_x = int(width / 2)
                                                                                                  +current_y = int(height / 2)
                                                                                                  +direction_x = 1
                                                                                                  +direction_y = -1
                                                                                                  +# delay_time = .0001
                                                                                                  +
                                                                                                  +# oled.line(0, height-2, width-1, height-2, 1)
                                                                                                  +
                                                                                                  +# Bounce forever
                                                                                                  +while True:
                                                                                                  +    draw_ball(current_x,current_y, ball_size,1)
                                                                                                  +    oled.show()
                                                                                                  +    # utime.sleep(delay_time)
                                                                                                  +    draw_ball(current_x,current_y,ball_size,0)
                                                                                                  +    # reverse at the edges
                                                                                                  +    # left edge test
                                                                                                  +    if current_x < 2:
                                                                                                  +        direction_x = 1
                                                                                                  +    # right edge test
                                                                                                  +    if current_x > width - ball_size -2:
                                                                                                  +        direction_x = -1
                                                                                                  +    # top edge test
                                                                                                  +    if current_y < 2:
                                                                                                  +        direction_y = 1
                                                                                                  +    # bottom edge test
                                                                                                  +    if current_y > height - ball_size - 3:
                                                                                                  +        direction_y = -1
                                                                                                  +    # update the ball
                                                                                                  +    current_x = current_x + direction_x
                                                                                                  +    current_y = current_y + direction_y
                                                                                                  +
                                                                                                  +print('done')
                                                                                                  +
                                                                                                  +

                                                                                                  SH1106 References

                                                                                                  +
                                                                                                    +
                                                                                                  1. Robert HH SH1106 Driver GitHub
                                                                                                  2. +
                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                  +
                                                                                                  + + + +
                                                                                                  + + + +
                                                                                                  + +
                                                                                                  + + + +
                                                                                                  + + + +
                                                                                                  + + +
                                                                                                  +
                                                                                                  + + Previous + +
                                                                                                  + OLED SSD1306 SPI V2 +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + + +
                                                                                                  + + Next + +
                                                                                                  + OLED SSD 1352 +
                                                                                                  +
                                                                                                  +
                                                                                                  + + +
                                                                                                  +
                                                                                                  + +
                                                                                                  + + +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-oled-ssd1306-i2c/index.html b/displays/graph/11-oled-ssd1306-i2c/index.html new file mode 100644 index 000000000..905d0b37a --- /dev/null +++ b/displays/graph/11-oled-ssd1306-i2c/index.html @@ -0,0 +1,2552 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED SSD1306 I2C - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                  + + + + Skip to content + + +
                                                                                                  +
                                                                                                  + +
                                                                                                  + + + + + + +
                                                                                                  +
                                                                                                  + + + logo + + + +
                                                                                                  +
                                                                                                  +
                                                                                                  + + MicroPython for Kids + +
                                                                                                  +
                                                                                                  + + + OLED SSD1306 I2C + + +
                                                                                                  +
                                                                                                  +
                                                                                                  + + + + + + + +
                                                                                                  + +
                                                                                                  +
                                                                                                  + + +
                                                                                                  + + +
                                                                                                  + +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  +
                                                                                                  + Initializing search +
                                                                                                  +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    + + +
                                                                                                    + +
                                                                                                    + + +
                                                                                                    +
                                                                                                    + GitHub Repo +
                                                                                                    +
                                                                                                    +
                                                                                                    + +
                                                                                                    + +
                                                                                                    + +
                                                                                                    + + + + + + +
                                                                                                    +
                                                                                                    + + + +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + + +
                                                                                                    + + +
                                                                                                    + +
                                                                                                    + + +
                                                                                                    +
                                                                                                    + GitHub Repo +
                                                                                                    +
                                                                                                    +
                                                                                                    + +
                                                                                                      + + + + + + + +
                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + +
                                                                                                      + +
                                                                                                        + + + + + + + +
                                                                                                      • + + + + + Introduction + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Wiring Harness + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Graphic LCD + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Basic Drawing + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Drawing with Bitmaps + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Custom Drawing Functions + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Color LCD ST7789V + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Timing Draw Speed + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + TFT ILI9341 + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + LCD Waveshare + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + E-Paper + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Setup + + + + +
                                                                                                      • + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + OLED SSD1306 I2C + + + + + + + +
                                                                                                        + + + + + + + +
                                                                                                          + +
                                                                                                        • + + + Using the SSD1306 with I2C Interfaces + + + +
                                                                                                          +
                                                                                                            + +
                                                                                                          • + + + Add the ssd1306 Python Module + + + +
                                                                                                          • + +
                                                                                                          +
                                                                                                          + +
                                                                                                        • + +
                                                                                                        • + + + I2C Hello World + + + +
                                                                                                        • + +
                                                                                                        • + + + SH1106 Example + + + +
                                                                                                        • + +
                                                                                                        • + + + Counter Example + + + +
                                                                                                        • + +
                                                                                                        • + + + Animated Box + + + +
                                                                                                        • + +
                                                                                                        • + + + Install SSD1306 Module + + + +
                                                                                                        • + +
                                                                                                        • + + + ssd1306 module + + + +
                                                                                                        • + +
                                                                                                        • + + + SSD1306 vs. SH1106 + + + +
                                                                                                        • + +
                                                                                                        • + + + The SPI interface + + + +
                                                                                                          +
                                                                                                            + +
                                                                                                          • + + + SPI Baudrate + + + +
                                                                                                          • + +
                                                                                                          • + + + Pico Pins + + + +
                                                                                                          • + +
                                                                                                          • + + + SPI Terms + + + +
                                                                                                          • + +
                                                                                                          +
                                                                                                          + +
                                                                                                        • + +
                                                                                                        • + + + Sample Nonworking SPI Code + + + +
                                                                                                        • + +
                                                                                                        • + + + References + + + +
                                                                                                        • + +
                                                                                                        + +
                                                                                                        + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED SSD 1352 + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Bounce + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Pot + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Ping + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Pong + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Pixel Draw + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED Patterns + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + Random Hearts + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + NeoPixel Matrix + + + + +
                                                                                                      • + + + + + + + + + + +
                                                                                                      • + + + + + OLED References + + + + +
                                                                                                      • + + + + +
                                                                                                      +
                                                                                                      + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + Glossary + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + References + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + Contributing + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + Contact + + + + +
                                                                                                    • + + + + + + + + + +
                                                                                                    • + + + + + Colophon + + + + +
                                                                                                    • + + + +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + +
                                                                                                    +
                                                                                                    +
                                                                                                    + + +
                                                                                                    + + + + + + + +
                                                                                                      + +
                                                                                                    • + + + Using the SSD1306 with I2C Interfaces + + + +
                                                                                                      +
                                                                                                        + +
                                                                                                      • + + + Add the ssd1306 Python Module + + + +
                                                                                                      • + +
                                                                                                      +
                                                                                                      + +
                                                                                                    • + +
                                                                                                    • + + + I2C Hello World + + + +
                                                                                                    • + +
                                                                                                    • + + + SH1106 Example + + + +
                                                                                                    • + +
                                                                                                    • + + + Counter Example + + + +
                                                                                                    • + +
                                                                                                    • + + + Animated Box + + + +
                                                                                                    • + +
                                                                                                    • + + + Install SSD1306 Module + + + +
                                                                                                    • + +
                                                                                                    • + + + ssd1306 module + + + +
                                                                                                    • + +
                                                                                                    • + + + SSD1306 vs. SH1106 + + + +
                                                                                                    • + +
                                                                                                    • + + + The SPI interface + + + +
                                                                                                      +
                                                                                                        + +
                                                                                                      • + + + SPI Baudrate + + + +
                                                                                                      • + +
                                                                                                      • + + + Pico Pins + + + +
                                                                                                      • + +
                                                                                                      • + + + SPI Terms + + + +
                                                                                                      • + +
                                                                                                      +
                                                                                                      + +
                                                                                                    • + +
                                                                                                    • + + + Sample Nonworking SPI Code + + + +
                                                                                                    • + +
                                                                                                    • + + + References + + + +
                                                                                                    • + +
                                                                                                    + +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + +
                                                                                                    +
                                                                                                    + + + + + + + +

                                                                                                    OLED SSD1306 Examples

                                                                                                    +

                                                                                                    Using the SSD1306 with I2C Interfaces

                                                                                                    +

                                                                                                    Add the ssd1306 Python Module

                                                                                                    +

                                                                                                    You can now use the Thonny "Tools -> Manage Packages..." menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use.

                                                                                                    +

                                                                                                    +

                                                                                                    If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command.

                                                                                                    +

                                                                                                    I2C Hello World

                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    +11
                                                                                                    import machine
                                                                                                    +from ssd1306 import SSD1306_I2C
                                                                                                    +
                                                                                                    +sda=machine.Pin(0)
                                                                                                    +scl=machine.Pin(1)
                                                                                                    +i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
                                                                                                    +oled = SSD1306_I2C(128, 64, i2c)
                                                                                                    +oled.fill(0)
                                                                                                    +oled.text("Hello World!", 0, 0)
                                                                                                    +oled.show()
                                                                                                    +print('Done')
                                                                                                    +
                                                                                                    +

                                                                                                    After this program runs you should see the text on your OLED display. +

                                                                                                    +

                                                                                                    SH1106 Example

                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    +11
                                                                                                    +12
                                                                                                    +13
                                                                                                    +14
                                                                                                    +15
                                                                                                    from machine import Pin, I2C
                                                                                                    +import sh1106
                                                                                                    +
                                                                                                    +sda=machine.Pin(0)
                                                                                                    +scl=machine.Pin(1)
                                                                                                    +i2c = I2C(0, scl=scl, sda=sda, freq=400000)
                                                                                                    +
                                                                                                    +display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)
                                                                                                    +display.sleep(False)
                                                                                                    +
                                                                                                    +display.fill(0)
                                                                                                    +display.text('CoderDojo', 0, 0, 1)
                                                                                                    +display.show()
                                                                                                    +
                                                                                                    +print('done')
                                                                                                    +
                                                                                                    +

                                                                                                    Counter Example

                                                                                                    +

                                                                                                    In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50.

                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    +11
                                                                                                    +12
                                                                                                    +13
                                                                                                    +14
                                                                                                    +15
                                                                                                    +16
                                                                                                    +17
                                                                                                    import machine
                                                                                                    +import utime
                                                                                                    +from ssd1306 import SSD1306_I2C
                                                                                                    +
                                                                                                    +sda=machine.Pin(0)
                                                                                                    +scl=machine.Pin(1)
                                                                                                    +i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
                                                                                                    +oled = SSD1306_I2C(128, 64, i2c)
                                                                                                    +
                                                                                                    +for i in range(1, 51): # count 1 to 50
                                                                                                    +    oled.fill(0) # clear to black
                                                                                                    +    oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black
                                                                                                    +    oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top
                                                                                                    +    oled.show() # update display
                                                                                                    +    utime.sleep(0.1) #wait 1/10th of a second
                                                                                                    +
                                                                                                    +print('done')
                                                                                                    +
                                                                                                    +

                                                                                                    Animated Box

                                                                                                    +

                                                                                                    This draws a title and four lines around a drawing area. It then draws boxes that move to the right.

                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    +11
                                                                                                    +12
                                                                                                    +13
                                                                                                    +14
                                                                                                    +15
                                                                                                    +16
                                                                                                    +17
                                                                                                    +18
                                                                                                    +19
                                                                                                    +20
                                                                                                    +21
                                                                                                    +22
                                                                                                    +23
                                                                                                    +24
                                                                                                    +25
                                                                                                    +26
                                                                                                    +27
                                                                                                    +28
                                                                                                    +29
                                                                                                    +30
                                                                                                    +31
                                                                                                    +32
                                                                                                    from machine import Pin, I2C
                                                                                                    +import sh1106
                                                                                                    +import utime
                                                                                                    +
                                                                                                    +sda=machine.Pin(0)
                                                                                                    +scl=machine.Pin(1)
                                                                                                    +i2c = I2C(0, scl=scl, sda=sda, freq=400000)
                                                                                                    +
                                                                                                    +display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)
                                                                                                    +display.sleep(False)
                                                                                                    +
                                                                                                    +display.fill(0) # clear to black
                                                                                                    +display.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black
                                                                                                    +# line under title
                                                                                                    +display.hline(0, 9, 127, 1)
                                                                                                    +# bottom of display
                                                                                                    +display.hline(0, 30, 127, 1)
                                                                                                    +# left edge
                                                                                                    +display.vline(0, 10, 32, 1)
                                                                                                    +# right edge
                                                                                                    +display.vline(127, 10, 32, 1)
                                                                                                    +
                                                                                                    +for i in range(0, 118):
                                                                                                    +    # box x0, y0, width, height, on
                                                                                                    +    display.fill_rect(i,10, 10, 10, 1)
                                                                                                    +    # draw black behind number
                                                                                                    +    display.fill_rect(10, 21, 30, 8, 0)
                                                                                                    +    display.text(str(i), 10, 21, 1)
                                                                                                    +    display.show() # update display
                                                                                                    +    # utime.sleep(0.001)
                                                                                                    +
                                                                                                    +print('done')
                                                                                                    +
                                                                                                    +

                                                                                                    Install SSD1306 Module

                                                                                                    +

                                                                                                    +

                                                                                                    ssd1306 module

                                                                                                    +

                                                                                                    SSD1306 Library - click the RAW button and then right click to do a "Save As"

                                                                                                    +

                                                                                                    SSD1306 vs. SH1106

                                                                                                    +

                                                                                                    There is only one small difference between SSD1306 and SH1106: The SH1106 controller has an internal RAM of 132x64 pixel. The SSD1306 only has 128x64 pixel.

                                                                                                    +

                                                                                                    The SPI interface

                                                                                                    +

                                                                                                    The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy.

                                                                                                    +

                                                                                                    SPI Baudrate

                                                                                                    +

                                                                                                    https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c

                                                                                                    +

                                                                                                    The seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display:

                                                                                                    +

                                                                                                    +
                                                                                                      +
                                                                                                    1. CS - Chip Select - pin 4
                                                                                                    2. +
                                                                                                    3. DC - Data/Command - pin 5
                                                                                                    4. +
                                                                                                    5. RES - Reset - pin 6
                                                                                                    6. +
                                                                                                    7. SDA - Data - SPIO TX GP7 pin 10
                                                                                                    8. +
                                                                                                    9. SCL - Clock - Connect to SPIO SCK GP6 pin 9
                                                                                                    10. +
                                                                                                    11. VCC - Connect to the 3.3V Out pin 36
                                                                                                    12. +
                                                                                                    13. GND - pin 38 or 3 any other GND pin
                                                                                                    14. +
                                                                                                    +

                                                                                                    Pico Pins

                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    # Sample code sections
                                                                                                    + 28 # ------------ SPI ------------------
                                                                                                    + 29 # Pin Map SPI
                                                                                                    + 30 # - 3v - xxxxxx - Vcc
                                                                                                    + 31 # - G - xxxxxx - Gnd
                                                                                                    + 32 # - D7 - GPIO 13 - Din / MOSI fixed
                                                                                                    + 33 # - D5 - GPIO 14 - Clk / Sck fixed
                                                                                                    + 34 # - D8 - GPIO 4 - CS (optional, if the only connected device)
                                                                                                    + 35 # - D2 - GPIO 5 - D/C
                                                                                                    + 36 # - D1 - GPIO 2 - Res
                                                                                                    +
                                                                                                    +

                                                                                                    SCK is the clock - hook this to the oled SCL +MOSI is the line taking data from your Pico to the peripheral device. Hook this to SDA

                                                                                                    +

                                                                                                    From the SDK: +https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf +Section 3.7

                                                                                                    +
                                                                                                      +
                                                                                                    1. SPI0_SCK - pin 6
                                                                                                    2. +
                                                                                                    3. SPI0_MOSI - pin 7
                                                                                                    4. +
                                                                                                    5. SPI0_MISO - pin 8
                                                                                                    6. +
                                                                                                    +

                                                                                                    This contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO

                                                                                                    +
                                                                                                    1
                                                                                                    +2
                                                                                                    +3
                                                                                                    spi_sck=machine.Pin(2)
                                                                                                    +spi_tx=machine.Pin(3)
                                                                                                    +spi_rx=machine.Pin(4)
                                                                                                    +
                                                                                                    +

                                                                                                    SPI Terms

                                                                                                    +

                                                                                                    Master Out Slave In (MOSI)

                                                                                                    +

                                                                                                    We send the data to the SPI RX (Receive) port on the Pico. These are pin 1 (GP0) or pin 6 (GP4)

                                                                                                    +

                                                                                                    Sample Nonworking SPI Code

                                                                                                    +

                                                                                                    From the documentation:

                                                                                                    +
                                                                                                    +

                                                                                                    From

                                                                                                    +

                                                                                                    spi is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used.

                                                                                                    +

                                                                                                    dc is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver.

                                                                                                    +

                                                                                                    res is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.

                                                                                                    +

                                                                                                    cs is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.

                                                                                                    +
                                                                                                    +
                                                                                                     1
                                                                                                    + 2
                                                                                                    + 3
                                                                                                    + 4
                                                                                                    + 5
                                                                                                    + 6
                                                                                                    + 7
                                                                                                    + 8
                                                                                                    + 9
                                                                                                    +10
                                                                                                    +11
                                                                                                    +12
                                                                                                    +13
                                                                                                    +14
                                                                                                    +15
                                                                                                    +16
                                                                                                    +17
                                                                                                    +18
                                                                                                    +19
                                                                                                    +20
                                                                                                    +21
                                                                                                    +22
                                                                                                    +23
                                                                                                    +24
                                                                                                    +25
                                                                                                    +26
                                                                                                    +27
                                                                                                    +28
                                                                                                    +29
                                                                                                    +30
                                                                                                    +31
                                                                                                    +32
                                                                                                    +33
                                                                                                    +34
                                                                                                    +35
                                                                                                    +36
                                                                                                    +37
                                                                                                    import machine
                                                                                                    +import machine
                                                                                                    +import utime
                                                                                                    +import ssd1306
                                                                                                    +led = machine.Pin(25, machine.Pin.OUT)
                                                                                                    +
                                                                                                    +# From: https://github.com/robert-hh/SH1106
                                                                                                    +# display = sh1106.SH1106_SPI(width, height, spi, dc, res, cs)
                                                                                                    +#MOSI=machine.Pin(7)
                                                                                                    +#SCK=machine.Pin(6)
                                                                                                    +#spi = machine.SPI(0, baudrate=400000, sck=SCK, mosi=MOSI)
                                                                                                    +spi_sck=machine.Pin(6)
                                                                                                    +spi_tx=machine.Pin(7)
                                                                                                    +# spi_rx=machine.Pin(4)
                                                                                                    +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                    +
                                                                                                    +CS = machine.Pin(8)
                                                                                                    +DC = machine.Pin(9)
                                                                                                    +RES = machine.Pin(10)
                                                                                                    +
                                                                                                    +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                                    +
                                                                                                    +# flash all pixels on
                                                                                                    +oled.fill(1)
                                                                                                    +oled.show()
                                                                                                    +utime.sleep(0.5)
                                                                                                    +
                                                                                                    +oled.fill(0)
                                                                                                    +oled.text('CoderDojo Rocks!', 0, 0, 1)
                                                                                                    +oled.show()
                                                                                                    +
                                                                                                    +# flash the LED to show end
                                                                                                    +led.high()
                                                                                                    +utime.sleep(0.5)
                                                                                                    +led.low()
                                                                                                    +
                                                                                                    +print('Done')
                                                                                                    +
                                                                                                    +

                                                                                                    References

                                                                                                    +
                                                                                                      +
                                                                                                    1. +

                                                                                                      MicroPython Tutorial on the SSD1306

                                                                                                      +
                                                                                                    2. +
                                                                                                    3. +

                                                                                                      robert-hh's SH1106 Driver

                                                                                                      +
                                                                                                    4. +
                                                                                                    5. +

                                                                                                      M Fitzp OLED Display i2c Article

                                                                                                      +
                                                                                                    6. +
                                                                                                    7. +

                                                                                                      Adafruit Stats

                                                                                                      +
                                                                                                    8. +
                                                                                                    +

                                                                                                    DIY More OLED Product Description

                                                                                                    +
                                                                                                      +
                                                                                                    1. Using I2C Defaults
                                                                                                    2. +
                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                    +
                                                                                                    + + + +
                                                                                                    + + + +
                                                                                                    + +
                                                                                                    + + + +
                                                                                                    + + + +
                                                                                                    + + +
                                                                                                    +
                                                                                                    + + Previous + +
                                                                                                    + OLED Setup +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + + +
                                                                                                    + + Next + +
                                                                                                    + OLED SSD1306 SPI V1 +
                                                                                                    +
                                                                                                    +
                                                                                                    + + +
                                                                                                    +
                                                                                                    + +
                                                                                                    + + +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                    + +
                                                                                                    +
                                                                                                    +
                                                                                                    + +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-oled-ssd1306-spi/index.html b/displays/graph/11-oled-ssd1306-spi/index.html new file mode 100644 index 000000000..ea399234d --- /dev/null +++ b/displays/graph/11-oled-ssd1306-spi/index.html @@ -0,0 +1,2250 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED SSD1306 SPI V2 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                    + + + + Skip to content + + +
                                                                                                    +
                                                                                                    + +
                                                                                                    + + + + + + +
                                                                                                    +
                                                                                                    + + + logo + + + +
                                                                                                    +
                                                                                                    +
                                                                                                    + + MicroPython for Kids + +
                                                                                                    +
                                                                                                    + + + OLED SSD1306 SPI V2 + + +
                                                                                                    +
                                                                                                    +
                                                                                                    + + + + + + + +
                                                                                                    + +
                                                                                                    +
                                                                                                    + + +
                                                                                                    + + +
                                                                                                    + +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    +
                                                                                                    + Initializing search +
                                                                                                    +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      + + +
                                                                                                      + +
                                                                                                      + + +
                                                                                                      +
                                                                                                      + GitHub Repo +
                                                                                                      +
                                                                                                      +
                                                                                                      + +
                                                                                                      + +
                                                                                                      + +
                                                                                                      + + + + + + +
                                                                                                      +
                                                                                                      + + + +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + + +
                                                                                                      + + +
                                                                                                      + +
                                                                                                      + + +
                                                                                                      +
                                                                                                      + GitHub Repo +
                                                                                                      +
                                                                                                      +
                                                                                                      + +
                                                                                                        + + + + + + + +
                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + +
                                                                                                        + +
                                                                                                          + + + + + + + +
                                                                                                        • + + + + + Introduction + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Wiring Harness + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Graphic LCD + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Basic Drawing + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Drawing with Bitmaps + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Custom Drawing Functions + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Color LCD ST7789V + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Timing Draw Speed + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + TFT ILI9341 + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + LCD Waveshare + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + E-Paper + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Setup + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                        • + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + OLED SSD1306 SPI V2 + + + + + + + +
                                                                                                          + + + + + + + +
                                                                                                            + +
                                                                                                          • + + + Using the SSD1306 with SPI Interfaces + + + +
                                                                                                            +
                                                                                                              + +
                                                                                                            • + + + Add the ssd1306 Python Module + + + +
                                                                                                            • + +
                                                                                                            +
                                                                                                            + +
                                                                                                          • + +
                                                                                                          • + + + Install SSD1306 Module + + + +
                                                                                                          • + +
                                                                                                          • + + + ssd1306 module + + + +
                                                                                                          • + +
                                                                                                          • + + + The SPI interface + + + +
                                                                                                          • + +
                                                                                                          • + + + Displaying SPI Defaults + + + +
                                                                                                          • + +
                                                                                                          + +
                                                                                                          + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED SSD 1352 + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Bounce + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Pot + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Ping + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Pong + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Pixel Draw + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED Patterns + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + Random Hearts + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + NeoPixel Matrix + + + + +
                                                                                                        • + + + + + + + + + + +
                                                                                                        • + + + + + OLED References + + + + +
                                                                                                        • + + + + +
                                                                                                        +
                                                                                                        + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + Glossary + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + References + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + Contributing + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + Contact + + + + +
                                                                                                      • + + + + + + + + + +
                                                                                                      • + + + + + Colophon + + + + +
                                                                                                      • + + + +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + +
                                                                                                      +
                                                                                                      +
                                                                                                      + + +
                                                                                                      + + + + + + + +
                                                                                                        + +
                                                                                                      • + + + Using the SSD1306 with SPI Interfaces + + + +
                                                                                                        +
                                                                                                          + +
                                                                                                        • + + + Add the ssd1306 Python Module + + + +
                                                                                                        • + +
                                                                                                        +
                                                                                                        + +
                                                                                                      • + +
                                                                                                      • + + + Install SSD1306 Module + + + +
                                                                                                      • + +
                                                                                                      • + + + ssd1306 module + + + +
                                                                                                      • + +
                                                                                                      • + + + The SPI interface + + + +
                                                                                                      • + +
                                                                                                      • + + + Displaying SPI Defaults + + + +
                                                                                                      • + +
                                                                                                      + +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + +
                                                                                                      +
                                                                                                      + + + + + + + +

                                                                                                      OLED SSD1306 SPI Examples

                                                                                                      +

                                                                                                      Using the SSD1306 with SPI Interfaces

                                                                                                      +

                                                                                                      Add the ssd1306 Python Module

                                                                                                      +

                                                                                                      You can now use the Thonny "Tools -> Manage Packages..." menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use.

                                                                                                      +

                                                                                                      +

                                                                                                      If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command.

                                                                                                      +

                                                                                                      Install SSD1306 Module

                                                                                                      +

                                                                                                      +

                                                                                                      ssd1306 module

                                                                                                      +

                                                                                                      SSD1306 Library - click the RAW button and then right click to do a "Save As"

                                                                                                      +

                                                                                                      SSD1306 Library Searchable

                                                                                                      +

                                                                                                      The SPI interface

                                                                                                      +

                                                                                                      The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy.

                                                                                                      +

                                                                                                      Displaying SPI Defaults

                                                                                                      +
                                                                                                       1
                                                                                                      + 2
                                                                                                      + 3
                                                                                                      + 4
                                                                                                      + 5
                                                                                                      + 6
                                                                                                      + 7
                                                                                                      + 8
                                                                                                      + 9
                                                                                                      +10
                                                                                                      +11
                                                                                                      +12
                                                                                                      +13
                                                                                                      +14
                                                                                                      +15
                                                                                                      +16
                                                                                                      +17
                                                                                                      +18
                                                                                                      +19
                                                                                                      +20
                                                                                                      +21
                                                                                                      +22
                                                                                                      from machine import Pin
                                                                                                      +from ssd1306 import SSD1306_SPI
                                                                                                      +# default is data (MOSI) on GP7 and clock (sck) on GP6
                                                                                                      +spi=machine.SPI(0)
                                                                                                      +print(spi)
                                                                                                      +SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=6, mosi=7, miso=4)
                                                                                                      +### SPI Baudrate
                                                                                                      +https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c
                                                                                                      +
                                                                                                      +The seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display:
                                                                                                      +
                                                                                                      +![](../../img/oled-back-connections.png)
                                                                                                      +
                                                                                                      +1. CS - Chip Select - pin 4
                                                                                                      +2. DC - Data/Command - pin 5
                                                                                                      +3. RES - Reset - pin 6
                                                                                                      +4. SDA - Data - SPIO TX GP7 pin 10
                                                                                                      +5. SCL - Clock - Connect to SPIO SCK GP6 pin 9
                                                                                                      +6. VCC - Connect to the 3.3V Out pin 36
                                                                                                      +7. GND - pin 38 or 3 any other GND pin
                                                                                                      +
                                                                                                      +### Pico Pins
                                                                                                      +
                                                                                                      +

                                                                                                      Sample code sections

                                                                                                      +

                                                                                                      28 # ------------ SPI ------------------ + 29 # Pin Map SPI + 30 # - 3v - xxxxxx - Vcc + 31 # - G - xxxxxx - Gnd + 32 # - D7 - GPIO 13 - Din / MOSI fixed + 33 # - D5 - GPIO 14 - Clk / Sck fixed + 34 # - D8 - GPIO 4 - CS (optional, if the only connected device) + 35 # - D2 - GPIO 5 - D/C + 36 # - D1 - GPIO 2 - Res +

                                                                                                       1
                                                                                                      + 2
                                                                                                      + 3
                                                                                                      + 4
                                                                                                      + 5
                                                                                                      + 6
                                                                                                      + 7
                                                                                                      + 8
                                                                                                      + 9
                                                                                                      +10
                                                                                                      +11
                                                                                                      +12
                                                                                                      * SCK is the clock - hook this to the oled SCL
                                                                                                      +* MOSI is the line taking data from your Pico to the peripheral device.  Hook this to SDA
                                                                                                      +
                                                                                                      +From the SDK:
                                                                                                      +https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf
                                                                                                      +Section 3.7
                                                                                                      +
                                                                                                      +1. SPI0_SCK - pin 6
                                                                                                      +2. SPI0_MOSI - pin 7
                                                                                                      +3. SPI0_MISO - pin 8
                                                                                                      +
                                                                                                      +This contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO
                                                                                                      +
                                                                                                      +spi_sck=machine.Pin(2) +spi_tx=machine.Pin(3) +spi_rx=machine.Pin(4) +
                                                                                                       1
                                                                                                      + 2
                                                                                                      + 3
                                                                                                      + 4
                                                                                                      + 5
                                                                                                      + 6
                                                                                                      + 7
                                                                                                      + 8
                                                                                                      + 9
                                                                                                      +10
                                                                                                      +11
                                                                                                      +12
                                                                                                      +13
                                                                                                      +14
                                                                                                      +15
                                                                                                      +16
                                                                                                      +17
                                                                                                      +18
                                                                                                      +19
                                                                                                      +20
                                                                                                      +21
                                                                                                      +22
                                                                                                      +23
                                                                                                      +24
                                                                                                      +25
                                                                                                      +26
                                                                                                      +27
                                                                                                      +28
                                                                                                      +29
                                                                                                      +30
                                                                                                      +31
                                                                                                      +32
                                                                                                      +33
                                                                                                      +34
                                                                                                      +35
                                                                                                      +36
                                                                                                      +37
                                                                                                      +38
                                                                                                      +39
                                                                                                      +40
                                                                                                      +41
                                                                                                      +42
                                                                                                      +43
                                                                                                      +44
                                                                                                      +45
                                                                                                      +46
                                                                                                      +47
                                                                                                      We send the data to the SPI RX (Receive) port on the Pico.  These are pin 1 (GP0) or pin 6 (GP4)
                                                                                                      +
                                                                                                      +## Sample Nonworking SPI Code
                                                                                                      +
                                                                                                      +From the documentation:
                                                                                                      +
                                                                                                      +!!! From Raspberry Pi Pico Documentation
                                                                                                      +    **spi** is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used.
                                                                                                      +
                                                                                                      +    **dc** is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver.
                                                                                                      +
                                                                                                      +    **res** is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.
                                                                                                      +
                                                                                                      +    **cs** is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.
                                                                                                      +
                                                                                                      +```py
                                                                                                      +import machine
                                                                                                      +import utime
                                                                                                      +import ssd1306
                                                                                                      +led = machine.Pin(25, machine.Pin.OUT)
                                                                                                      +
                                                                                                      +spi_sck=machine.Pin(6)
                                                                                                      +spi_tx=machine.Pin(7)
                                                                                                      +# spi_rx=machine.Pin(4)
                                                                                                      +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                      +
                                                                                                      +CS = machine.Pin(8)
                                                                                                      +DC = machine.Pin(9)
                                                                                                      +RES = machine.Pin(10)
                                                                                                      +
                                                                                                      +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                                      +
                                                                                                      +# flash all pixels on
                                                                                                      +oled.fill(1)
                                                                                                      +oled.show()
                                                                                                      +utime.sleep(0.5)
                                                                                                      +
                                                                                                      +oled.fill(0)
                                                                                                      +oled.text('CoderDojo Rocks!', 0, 0, 1)
                                                                                                      +oled.show()
                                                                                                      +
                                                                                                      +# flash the LED to show end
                                                                                                      +led.high()
                                                                                                      +utime.sleep(0.5)
                                                                                                      +led.low()
                                                                                                      +
                                                                                                      +print('Done')
                                                                                                      +

                                                                                                      +

                                                                                                      References

                                                                                                      +

                                                                                                      robert-hh's SH1106 Driver

                                                                                                      +

                                                                                                      MicroPython SSD1306 Class

                                                                                                      +

                                                                                                      https://www.mfitzp.com/article/oled-displays-i2c-micropython/

                                                                                                      +

                                                                                                      https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/master/examples/ssd1306_stats.py

                                                                                                      +

                                                                                                      https://github.com/robert-hh/SH1106/blob/master/sh1106.py

                                                                                                      +

                                                                                                      DIY More OLED Product Description

                                                                                                      +

                                                                                                      SSD1306

                                                                                                      +

                                                                                                      https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1306/

                                                                                                      +

                                                                                                      SSD1307

                                                                                                      +

                                                                                                      https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1307/

                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                      +
                                                                                                      + + + +
                                                                                                      + + + +
                                                                                                      + +
                                                                                                      + + + +
                                                                                                      + + + +
                                                                                                      + + +
                                                                                                      +
                                                                                                      + + Previous + +
                                                                                                      + OLED SSD1306 SPI V1 +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + + +
                                                                                                      + + Next + +
                                                                                                      + OLED SH1106 I2C Example +
                                                                                                      +
                                                                                                      +
                                                                                                      + + +
                                                                                                      +
                                                                                                      + +
                                                                                                      + + +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                      + +
                                                                                                      +
                                                                                                      +
                                                                                                      + +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/11-pong/index.html b/displays/graph/11-pong/index.html new file mode 100644 index 000000000..5d71860f7 --- /dev/null +++ b/displays/graph/11-pong/index.html @@ -0,0 +1,2488 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Pong - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                      + + + + Skip to content + + +
                                                                                                      +
                                                                                                      + +
                                                                                                      + + + + + + +
                                                                                                      +
                                                                                                      + + + logo + + + +
                                                                                                      +
                                                                                                      +
                                                                                                      + + MicroPython for Kids + +
                                                                                                      +
                                                                                                      + + + OLED Pong + + +
                                                                                                      +
                                                                                                      +
                                                                                                      + + + + + + + +
                                                                                                      + +
                                                                                                      +
                                                                                                      + + +
                                                                                                      + + +
                                                                                                      + +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      +
                                                                                                      + Initializing search +
                                                                                                      +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + + +
                                                                                                        + +
                                                                                                        + + +
                                                                                                        +
                                                                                                        + GitHub Repo +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + +
                                                                                                        + + + + + + +
                                                                                                        +
                                                                                                        + + + +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + + +
                                                                                                        + + +
                                                                                                        + +
                                                                                                        + + +
                                                                                                        +
                                                                                                        + GitHub Repo +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                          + + + + + + + +
                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + +
                                                                                                          + +
                                                                                                            + + + + + + + +
                                                                                                          • + + + + + Introduction + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Wiring Harness + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Graphic LCD + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Basic Drawing + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Drawing with Bitmaps + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Custom Drawing Functions + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Color LCD ST7789V + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Timing Draw Speed + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + TFT ILI9341 + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + LCD Waveshare + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + E-Paper + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Setup + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED SSD 1352 + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Bounce + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Pot + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Ping + + + + +
                                                                                                          • + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + OLED Pong + + + + + + + +
                                                                                                            + + + + + + + +
                                                                                                              + +
                                                                                                            • + + + Part list + + + +
                                                                                                            • + +
                                                                                                            • + + + Connections + + + +
                                                                                                            • + +
                                                                                                            • + + + Getting the Right Python Libraries + + + +
                                                                                                            • + +
                                                                                                            • + + + Testing the OLED + + + +
                                                                                                            • + +
                                                                                                            • + + + Drawing the Border + + + +
                                                                                                            • + +
                                                                                                            • + + + Full Program + + + +
                                                                                                            • + +
                                                                                                            + +
                                                                                                            + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Pixel Draw + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED Patterns + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + Random Hearts + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + NeoPixel Matrix + + + + +
                                                                                                          • + + + + + + + + + + +
                                                                                                          • + + + + + OLED References + + + + +
                                                                                                          • + + + + +
                                                                                                          +
                                                                                                          + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + Glossary + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + References + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + Contributing + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + Contact + + + + +
                                                                                                        • + + + + + + + + + +
                                                                                                        • + + + + + Colophon + + + + +
                                                                                                        • + + + +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + +
                                                                                                        +
                                                                                                        +
                                                                                                        + + +
                                                                                                        + + + + + + + +
                                                                                                          + +
                                                                                                        • + + + Part list + + + +
                                                                                                        • + +
                                                                                                        • + + + Connections + + + +
                                                                                                        • + +
                                                                                                        • + + + Getting the Right Python Libraries + + + +
                                                                                                        • + +
                                                                                                        • + + + Testing the OLED + + + +
                                                                                                        • + +
                                                                                                        • + + + Drawing the Border + + + +
                                                                                                        • + +
                                                                                                        • + + + Full Program + + + +
                                                                                                        • + +
                                                                                                        + +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + +
                                                                                                        +
                                                                                                        + + + + + + + +

                                                                                                        Pong

                                                                                                        +

                                                                                                        Using a low-cost OLED device you can write a pong game. If you use a small 128X64 OLED the price can be around $12.

                                                                                                        +

                                                                                                        Part list

                                                                                                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        Part NamePriceLinkDescription
                                                                                                        Raspberry Pi Pico$4MicrocenterWith 264K RAM it has plenty of room for storing the framebuffer
                                                                                                        1/2 Size Solderless Breadboard$2link400 tie breadboard
                                                                                                        128X64 OLED$5eBayYou can also get larger 2.42" displays for around $20
                                                                                                        2 10K Potentiometers$1.5 eacheBayYou can purchase these in QTY 10 for less. Use the part number B10K to narrow your search.
                                                                                                        Clear Plastic Box$4The Container StoreShallow Narrow Stackable Rectangle Clear with Lids 8-1/4" x 3-1/2" x 1-7/8" h. The link is to the white lids.
                                                                                                        +

                                                                                                        +

                                                                                                        Raspberry Pi Pico for $4.

                                                                                                        +

                                                                                                        +

                                                                                                        OLED with I2C Interface. Note the pins are VCC, GND, SCL (clock), SDA (data).

                                                                                                        +

                                                                                                        +

                                                                                                        1/2 size 400 connector solderless breadboard

                                                                                                        +

                                                                                                        +

                                                                                                        10K potentiometer with pre-soldered connectors. You will need two of these. You can use a male-to-male header to connect it to the breadboard.

                                                                                                        +

                                                                                                        Connections

                                                                                                        +
                                                                                                          +
                                                                                                        1. Connect the GND of the OLED to GND of the Pico
                                                                                                        2. +
                                                                                                        3. Connect the VCC of the OLED to 3V3 OUT (physical pin 36)
                                                                                                        4. +
                                                                                                        5. Connect the SDA (data) of the OLED to the Pico GP0 (physical pin 1 on the top left with USB up)
                                                                                                        6. +
                                                                                                        7. Connect the SCL (clock) of the OLED to GP1 (physical pin 2)
                                                                                                        8. +
                                                                                                        9. Connect the center tap of both potentiometers to ADC0 (GP26 - pin 31) and ADC1 (GP27 - pin 32)
                                                                                                        10. +
                                                                                                        11. Connect the outer connectors of the potentiometers to VCC and GND
                                                                                                        12. +
                                                                                                        +

                                                                                                        Getting the Right Python Libraries

                                                                                                        +

                                                                                                        To run this program, you will need a MicroPython display driver. Our display in this example is the popular SSD1306 driver chip. Your OLED might have a slightly different driver type.

                                                                                                        +

                                                                                                        Here is the line that must be customized for your display:

                                                                                                        +
                                                                                                        1
                                                                                                        from ssd1306 import SSD1306_I2C
                                                                                                        +
                                                                                                        +

                                                                                                        Testing the OLED

                                                                                                        +

                                                                                                        This test will verify that your OLED connections are correct.

                                                                                                        +
                                                                                                         1
                                                                                                        + 2
                                                                                                        + 3
                                                                                                        + 4
                                                                                                        + 5
                                                                                                        + 6
                                                                                                        + 7
                                                                                                        + 8
                                                                                                        + 9
                                                                                                        +10
                                                                                                        +11
                                                                                                        from machine import Pin, I2C
                                                                                                        +from ssd1306 import SSD1306_I2C
                                                                                                        +WIDTH  = 128
                                                                                                        +HEIGHT = 64
                                                                                                        +sda=machine.Pin(0)
                                                                                                        +scl=machine.Pin(1)
                                                                                                        +i2c=machine.I2C(0,sda=sda, scl=scl)
                                                                                                        +oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)
                                                                                                        +oled.fill(0)
                                                                                                        +oled.text("CoderDojo Rocks",0,0)
                                                                                                        +oled.show()
                                                                                                        +
                                                                                                        +

                                                                                                        Drawing the Border

                                                                                                        +
                                                                                                        1
                                                                                                        +2
                                                                                                        def border(WIDTH, HEIGHT):
                                                                                                        +    oled.rect(0, 0, WIDTH, HEIGHT, 1)
                                                                                                        +
                                                                                                        +

                                                                                                        Full Program

                                                                                                        +
                                                                                                          1
                                                                                                        +  2
                                                                                                        +  3
                                                                                                        +  4
                                                                                                        +  5
                                                                                                        +  6
                                                                                                        +  7
                                                                                                        +  8
                                                                                                        +  9
                                                                                                        + 10
                                                                                                        + 11
                                                                                                        + 12
                                                                                                        + 13
                                                                                                        + 14
                                                                                                        + 15
                                                                                                        + 16
                                                                                                        + 17
                                                                                                        + 18
                                                                                                        + 19
                                                                                                        + 20
                                                                                                        + 21
                                                                                                        + 22
                                                                                                        + 23
                                                                                                        + 24
                                                                                                        + 25
                                                                                                        + 26
                                                                                                        + 27
                                                                                                        + 28
                                                                                                        + 29
                                                                                                        + 30
                                                                                                        + 31
                                                                                                        + 32
                                                                                                        + 33
                                                                                                        + 34
                                                                                                        + 35
                                                                                                        + 36
                                                                                                        + 37
                                                                                                        + 38
                                                                                                        + 39
                                                                                                        + 40
                                                                                                        + 41
                                                                                                        + 42
                                                                                                        + 43
                                                                                                        + 44
                                                                                                        + 45
                                                                                                        + 46
                                                                                                        + 47
                                                                                                        + 48
                                                                                                        + 49
                                                                                                        + 50
                                                                                                        + 51
                                                                                                        + 52
                                                                                                        + 53
                                                                                                        + 54
                                                                                                        + 55
                                                                                                        + 56
                                                                                                        + 57
                                                                                                        + 58
                                                                                                        + 59
                                                                                                        + 60
                                                                                                        + 61
                                                                                                        + 62
                                                                                                        + 63
                                                                                                        + 64
                                                                                                        + 65
                                                                                                        + 66
                                                                                                        + 67
                                                                                                        + 68
                                                                                                        + 69
                                                                                                        + 70
                                                                                                        + 71
                                                                                                        + 72
                                                                                                        + 73
                                                                                                        + 74
                                                                                                        + 75
                                                                                                        + 76
                                                                                                        + 77
                                                                                                        + 78
                                                                                                        + 79
                                                                                                        + 80
                                                                                                        + 81
                                                                                                        + 82
                                                                                                        + 83
                                                                                                        + 84
                                                                                                        + 85
                                                                                                        + 86
                                                                                                        + 87
                                                                                                        + 88
                                                                                                        + 89
                                                                                                        + 90
                                                                                                        + 91
                                                                                                        + 92
                                                                                                        + 93
                                                                                                        + 94
                                                                                                        + 95
                                                                                                        + 96
                                                                                                        + 97
                                                                                                        + 98
                                                                                                        + 99
                                                                                                        +100
                                                                                                        +101
                                                                                                        +102
                                                                                                        +103
                                                                                                        +104
                                                                                                        +105
                                                                                                        +106
                                                                                                        +107
                                                                                                        +108
                                                                                                        +109
                                                                                                        +110
                                                                                                        +111
                                                                                                        +112
                                                                                                        +113
                                                                                                        +114
                                                                                                        +115
                                                                                                        +116
                                                                                                        +117
                                                                                                        +118
                                                                                                        +119
                                                                                                        +120
                                                                                                        +121
                                                                                                        +122
                                                                                                        +123
                                                                                                        +124
                                                                                                        +125
                                                                                                        +126
                                                                                                        +127
                                                                                                        +128
                                                                                                        +129
                                                                                                        +130
                                                                                                        +131
                                                                                                        +132
                                                                                                        +133
                                                                                                        +134
                                                                                                        +135
                                                                                                        +136
                                                                                                        +137
                                                                                                        +138
                                                                                                        +139
                                                                                                        +140
                                                                                                        +141
                                                                                                        +142
                                                                                                        +143
                                                                                                        +144
                                                                                                        +145
                                                                                                        +146
                                                                                                        +147
                                                                                                        +148
                                                                                                        +149
                                                                                                        +150
                                                                                                        +151
                                                                                                        +152
                                                                                                        +153
                                                                                                        +154
                                                                                                        +155
                                                                                                        +156
                                                                                                        +157
                                                                                                        +158
                                                                                                        +159
                                                                                                        +160
                                                                                                        +161
                                                                                                        +162
                                                                                                        +163
                                                                                                        +164
                                                                                                        +165
                                                                                                        +166
                                                                                                        +167
                                                                                                        +168
                                                                                                        +169
                                                                                                        +170
                                                                                                        +171
                                                                                                        +172
                                                                                                        +173
                                                                                                        +174
                                                                                                        +175
                                                                                                        +176
                                                                                                        # Pong game on Raspberry Pi Pico with a OLED and two Potentimeters
                                                                                                        +from machine import Pin, PWM, SPI
                                                                                                        +import ssd1306
                                                                                                        +from utime import sleep
                                                                                                        +import random # random direction for new ball
                                                                                                        +
                                                                                                        +spi_sck=machine.Pin(2)
                                                                                                        +spi_tx=machine.Pin(3)
                                                                                                        +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                        +CS = machine.Pin(1)
                                                                                                        +DC = machine.Pin(4)
                                                                                                        +RES = machine.Pin(5)
                                                                                                        +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                                        +# connect the center tops of the potentiometers to ADC0 and ADC1
                                                                                                        +pot_pin_1 = machine.ADC(26)
                                                                                                        +pot_pin_2 = machine.ADC(26) # make them the same for testing
                                                                                                        +
                                                                                                        +# lower right corner with USB connector on top
                                                                                                        +SPEAKER_PIN = 16
                                                                                                        +# create a Pulse Width Modulation Object on this pin
                                                                                                        +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                        +
                                                                                                        +# globals variables
                                                                                                        +# static variables are constants are uppercase variable names
                                                                                                        +WIDTH = 128
                                                                                                        +HALF_WIDTH = int(WIDTH / 2)
                                                                                                        +HEIGHT = 64
                                                                                                        +HALF_HEIGHT = HEIGHT
                                                                                                        +BALL_SIZE = 3 # 2X2 pixels
                                                                                                        +PAD_WIDTH = 2
                                                                                                        +PAD_HEIGHT = 8
                                                                                                        +HALF_PAD_WIDTH = int(PAD_WIDTH / 2)
                                                                                                        +HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2)
                                                                                                        +POT_MIN = 3000
                                                                                                        +POT_MAX = 65534
                                                                                                        +MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1
                                                                                                        +# dynamic global variables use lowercase
                                                                                                        +paddle1_vel = 0
                                                                                                        +paddle2_vel = 0
                                                                                                        +l_score = 0
                                                                                                        +r_score = 0
                                                                                                        +# continiuous update of the paddle and ball
                                                                                                        +# play_startup_sound()
                                                                                                        +# start with the ball in the center
                                                                                                        +ball_x = int(WIDTH / 2)
                                                                                                        +ball_y = int(HEIGHT / 2)
                                                                                                        +# set the initial directinon to down to the right
                                                                                                        +ball_x_dir = 1
                                                                                                        +ball_y_dir = 1
                                                                                                        +
                                                                                                        +def play_startup_sound():
                                                                                                        +    speaker.duty_u16(1000)
                                                                                                        +    speaker.freq(600)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.freq(800)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.freq(1200)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.duty_u16(0)
                                                                                                        +
                                                                                                        +def play_bounce_sound():
                                                                                                        +    speaker.duty_u16(1000)
                                                                                                        +    speaker.freq(900)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.duty_u16(0)
                                                                                                        +
                                                                                                        +def play_score_sound():
                                                                                                        +    speaker.duty_u16(1000)
                                                                                                        +    speaker.freq(600)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.freq(800)
                                                                                                        +    sleep(.25)
                                                                                                        +    speaker.duty_u16(0)
                                                                                                        +
                                                                                                        +# note that OLEDs have problems with screen burn it - don't leave this on too long!
                                                                                                        +def border(WIDTH, HEIGHT):
                                                                                                        +    oled.rect(0, 0, WIDTH, HEIGHT, 1)
                                                                                                        +
                                                                                                        +
                                                                                                        +# Takes an input number vale and a range between high-and-low and returns it scaled to the new range
                                                                                                        +# This is similar to the Arduino map() function
                                                                                                        +def valmap(value, istart, istop, ostart, ostop):
                                                                                                        +  return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart)))
                                                                                                        +
                                                                                                        +# draw a vertical bar
                                                                                                        +def draw_paddle(paddle_no, paddle_center):
                                                                                                        +    if paddle_no == 1:
                                                                                                        +         x = 0
                                                                                                        +    else:
                                                                                                        +         x = WIDTH - 2
                                                                                                        +    y = paddle_center - HALF_PAD_HEIGHT
                                                                                                        +    oled.fill_rect(x,  y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s
                                                                                                        +
                                                                                                        +def draw_ball():
                                                                                                        +    oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now
                                                                                                        +
                                                                                                        +# The main event loop
                                                                                                        +while True:
                                                                                                        +    oled.fill(0) # clear screen
                                                                                                        +    oled.vline(int(WIDTH / 2), 0, HEIGHT,  1)
                                                                                                        +    # border(WIDTH, HEIGHT)
                                                                                                        +    # read both the pot values
                                                                                                        +    pot_val_1 = pot_pin_1.read_u16()
                                                                                                        +    pot_val_2 = pot_pin_1.read_u16()
                                                                                                        +    # print(pot_val_1)
                                                                                                        +
                                                                                                        +    # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT
                                                                                                        +    # ideally, it should range from 5 to 58
                                                                                                        +    pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2)
                                                                                                        +    pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2)
                                                                                                        +
                                                                                                        +    # print(pot_val, pot_scaled)
                                                                                                        +    draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT)
                                                                                                        +    draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT)
                                                                                                        +    draw_ball()
                                                                                                        +
                                                                                                        +    #update ball position with the current directions
                                                                                                        +    ball_x = ball_x + ball_x_dir
                                                                                                        +    ball_y = ball_y + ball_y_dir
                                                                                                        +
                                                                                                        +    # update the ball direction if we are at the top or bottom edge
                                                                                                        +    if ball_y < 0:
                                                                                                        +        ball_y_dir = 1
                                                                                                        +        #play_bounce_sound()
                                                                                                        +    if ball_y > HEIGHT - 3:
                                                                                                        +        ball_y_dir = -1
                                                                                                        +        #play_bounce_sound()
                                                                                                        +
                                                                                                        +    # if it hits the paddle bounce else score
                                                                                                        +    if ball_x < 1:
                                                                                                        +        top_paddle = pot_val_1 - HALF_PAD_HEIGHT
                                                                                                        +        bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT
                                                                                                        +        if ball_y > top_paddle and ball_y < bottom_paddle:
                                                                                                        +            # we have a hit
                                                                                                        +            ball_x_dir = 1
                                                                                                        +            ball_x = 2
                                                                                                        +            play_bounce_sound()
                                                                                                        +            print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle)
                                                                                                        +        else:
                                                                                                        +            # we have a score for the right player
                                                                                                        +            play_score_sound()
                                                                                                        +            r_score += 1
                                                                                                        +            ball_x = int(WIDTH / 2)
                                                                                                        +            ball_y = int(HEIGHT / 2)
                                                                                                        +            ball_x_dir = random.randint(-1, 2)
                                                                                                        +            if ball_x_dir == 0:
                                                                                                        +                ball_x_dir = 1
                                                                                                        +            ball_y_dir = random.randint(-1, 2)
                                                                                                        +            print('score on left edge', pot_val_1, top_paddle, bottom_paddle)
                                                                                                        +            sleep(.25)
                                                                                                        +
                                                                                                        +    if ball_x > WIDTH - 3:
                                                                                                        +        ball_x = WIDTH - 4
                                                                                                        +        top_paddle = pot_val_2 - HALF_PAD_HEIGHT
                                                                                                        +        bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT
                                                                                                        +        if ball_y > top_paddle and ball_y < bottom_paddle:
                                                                                                        +            ball_x_dir = -1
                                                                                                        +            print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle)
                                                                                                        +        else:
                                                                                                        +            l_score += 1
                                                                                                        +            play_score_sound()
                                                                                                        +            ball_x = int(WIDTH / 2)
                                                                                                        +            ball_y = int(HEIGHT / 2)
                                                                                                        +            ball_x_dir = random.randint(-1, 2)
                                                                                                        +            if ball_x_dir == 0:
                                                                                                        +                ball_x_dir = 1
                                                                                                        +            ball_y_dir = random.randint(-1, 2)
                                                                                                        +            play_bounce_sound()
                                                                                                        +            print('score on right edge', pot_val_1, top_paddle, bottom_paddle)
                                                                                                        +            sleep(.25)
                                                                                                        +
                                                                                                        +    oled.text(str(l_score), HALF_WIDTH - 20, 5, 1)
                                                                                                        +
                                                                                                        +    oled.text(str(r_score), HALF_WIDTH + 5, 5, 1)
                                                                                                        +
                                                                                                        +    oled.show()
                                                                                                        +
                                                                                                        +

                                                                                                        YouTube Video

                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                        +
                                                                                                        + + + +
                                                                                                        + + + +
                                                                                                        + +
                                                                                                        + + + +
                                                                                                        + + + +
                                                                                                        + + +
                                                                                                        +
                                                                                                        + + Previous + +
                                                                                                        + OLED Ping +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + + +
                                                                                                        + + Next + +
                                                                                                        + OLED Pixel Draw +
                                                                                                        +
                                                                                                        +
                                                                                                        + + +
                                                                                                        +
                                                                                                        + +
                                                                                                        + + +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                        + +
                                                                                                        +
                                                                                                        +
                                                                                                        + +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/12-e-paper-display/index.html b/displays/graph/12-e-paper-display/index.html new file mode 100644 index 000000000..3e223c47b --- /dev/null +++ b/displays/graph/12-e-paper-display/index.html @@ -0,0 +1,1982 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + E-Paper - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                        + + + + Skip to content + + +
                                                                                                        +
                                                                                                        + +
                                                                                                        + + + + + + +
                                                                                                        +
                                                                                                        + + + logo + + + +
                                                                                                        +
                                                                                                        +
                                                                                                        + + MicroPython for Kids + +
                                                                                                        +
                                                                                                        + + + E-Paper + + +
                                                                                                        +
                                                                                                        +
                                                                                                        + + + + + + + +
                                                                                                        + +
                                                                                                        +
                                                                                                        + + +
                                                                                                        + + +
                                                                                                        + +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        +
                                                                                                        + Initializing search +
                                                                                                        +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + +
                                                                                                          + +
                                                                                                          + + +
                                                                                                          +
                                                                                                          + GitHub Repo +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + +
                                                                                                          + + + + + + +
                                                                                                          +
                                                                                                          + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + + +
                                                                                                          + + +
                                                                                                          + +
                                                                                                          + + +
                                                                                                          +
                                                                                                          + GitHub Repo +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                            + + + + + + + +
                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + +
                                                                                                            + +
                                                                                                              + + + + + + + +
                                                                                                            • + + + + + Introduction + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Wiring Harness + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Graphic LCD + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Basic Drawing + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Drawing with Bitmaps + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Custom Drawing Functions + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Color LCD ST7789V + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Timing Draw Speed + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + TFT ILI9341 + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + LCD Waveshare + + + + +
                                                                                                            • + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + E-Paper + + + + + + + +
                                                                                                              + + + + + + + +
                                                                                                                + +
                                                                                                              • + + + Specifications + + + +
                                                                                                              • + +
                                                                                                              • + + + Resources + + + +
                                                                                                              • + +
                                                                                                              + +
                                                                                                              + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Setup + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED SSD 1352 + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Bounce + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Pot + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Ping + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Pong + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Pixel Draw + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED Patterns + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + Random Hearts + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + NeoPixel Matrix + + + + +
                                                                                                            • + + + + + + + + + + +
                                                                                                            • + + + + + OLED References + + + + +
                                                                                                            • + + + + +
                                                                                                            +
                                                                                                            + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + Glossary + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + References + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + Contributing + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + Contact + + + + +
                                                                                                          • + + + + + + + + + +
                                                                                                          • + + + + + Colophon + + + + +
                                                                                                          • + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          + + +
                                                                                                          + + + + + + + +
                                                                                                            + +
                                                                                                          • + + + Specifications + + + +
                                                                                                          • + +
                                                                                                          • + + + Resources + + + +
                                                                                                          • + +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + +
                                                                                                          +
                                                                                                          + + + + + + + +

                                                                                                          Raspberry Pi E-Paper Displays with

                                                                                                          +

                                                                                                          Specifications

                                                                                                          +
                                                                                                            +
                                                                                                          1. 2.9inch capacitive touch ePaper module, 296×128 resolution
                                                                                                          2. +
                                                                                                          3. 5-points touch support, user-defined wakeup gesture
                                                                                                          4. +
                                                                                                          5. No backlight, keeps displaying last content for a long time even when power down
                                                                                                          6. +
                                                                                                          7. Ultra low power consumption, basically power is only required for refreshing
                                                                                                          8. +
                                                                                                          9. SPI / I2C interface, requires minimal IO pins
                                                                                                          10. +
                                                                                                          11. Comes with development resources and manual (Raspberry Pi Pico C/C++ and MicroPython examples)
                                                                                                          12. +
                                                                                                          +

                                                                                                          Resources

                                                                                                          +
                                                                                                            +
                                                                                                          1. Waveshare Product Page
                                                                                                          2. +
                                                                                                          3. Waveshare Wiki
                                                                                                          4. +
                                                                                                          5. [Sample MicroPython Driver](https://github.com/waveshare/Pico_ePaper_Code/blob/main/python/0Pico-ePaper-5.65f.py
                                                                                                          6. +
                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                          +
                                                                                                          + + + +
                                                                                                          + + + +
                                                                                                          + +
                                                                                                          + + + +
                                                                                                          + + + +
                                                                                                          + + +
                                                                                                          +
                                                                                                          + + Previous + +
                                                                                                          + LCD Waveshare +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + + +
                                                                                                          + + Next + +
                                                                                                          + OLED Setup +
                                                                                                          +
                                                                                                          +
                                                                                                          + + +
                                                                                                          +
                                                                                                          + +
                                                                                                          + + +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/12-oled-pot/index.html b/displays/graph/12-oled-pot/index.html new file mode 100644 index 000000000..63b141b22 --- /dev/null +++ b/displays/graph/12-oled-pot/index.html @@ -0,0 +1,2353 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Pot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                          + + + + Skip to content + + +
                                                                                                          +
                                                                                                          + +
                                                                                                          + + + + + + +
                                                                                                          +
                                                                                                          + + + logo + + + +
                                                                                                          +
                                                                                                          +
                                                                                                          + + MicroPython for Kids + +
                                                                                                          +
                                                                                                          + + + OLED Pot + + +
                                                                                                          +
                                                                                                          +
                                                                                                          + + + + + + + +
                                                                                                          + +
                                                                                                          +
                                                                                                          + + +
                                                                                                          + + +
                                                                                                          + +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          +
                                                                                                          + Initializing search +
                                                                                                          +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            + + +
                                                                                                            + +
                                                                                                            + + +
                                                                                                            +
                                                                                                            + GitHub Repo +
                                                                                                            +
                                                                                                            +
                                                                                                            + +
                                                                                                            + +
                                                                                                            + +
                                                                                                            + + + + + + +
                                                                                                            +
                                                                                                            + + + +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + + +
                                                                                                            + + +
                                                                                                            + +
                                                                                                            + + +
                                                                                                            +
                                                                                                            + GitHub Repo +
                                                                                                            +
                                                                                                            +
                                                                                                            + +
                                                                                                              + + + + + + + +
                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + +
                                                                                                              + +
                                                                                                                + + + + + + + +
                                                                                                              • + + + + + Introduction + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Wiring Harness + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Graphic LCD + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Basic Drawing + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Drawing with Bitmaps + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Custom Drawing Functions + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Color LCD ST7789V + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Timing Draw Speed + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + TFT ILI9341 + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + LCD Waveshare + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + E-Paper + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Setup + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED SSD 1352 + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Bounce + + + + +
                                                                                                              • + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + OLED Pot + + + + + + + +
                                                                                                                + + + + + + + +
                                                                                                                  + +
                                                                                                                • + + + Circuit Diagram + + + +
                                                                                                                • + +
                                                                                                                • + + + Sample Code + + + +
                                                                                                                • + +
                                                                                                                • + + + Testing the POT + + + +
                                                                                                                  +
                                                                                                                    + +
                                                                                                                  • + + + Sample 16 bit output + + + +
                                                                                                                  • + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                • + +
                                                                                                                • + + + Testing the OLED + + + +
                                                                                                                  +
                                                                                                                    + +
                                                                                                                  • + + + Getting the defaults + + + +
                                                                                                                  • + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                • + +
                                                                                                                • + + + Continuous Text Display on OLED + + + +
                                                                                                                • + +
                                                                                                                • + + + Bar Chart and Text Display of Pot Value + + + +
                                                                                                                • + +
                                                                                                                • + + + Gif of OLED + + + +
                                                                                                                • + +
                                                                                                                + +
                                                                                                                + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Ping + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Pong + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Pixel Draw + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED Patterns + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + Random Hearts + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + NeoPixel Matrix + + + + +
                                                                                                              • + + + + + + + + + + +
                                                                                                              • + + + + + OLED References + + + + +
                                                                                                              • + + + + +
                                                                                                              +
                                                                                                              + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + Glossary + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + References + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + Contributing + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + Contact + + + + +
                                                                                                            • + + + + + + + + + +
                                                                                                            • + + + + + Colophon + + + + +
                                                                                                            • + + + +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + +
                                                                                                            +
                                                                                                            +
                                                                                                            + + +
                                                                                                            + + + + + + + +
                                                                                                              + +
                                                                                                            • + + + Circuit Diagram + + + +
                                                                                                            • + +
                                                                                                            • + + + Sample Code + + + +
                                                                                                            • + +
                                                                                                            • + + + Testing the POT + + + +
                                                                                                              +
                                                                                                                + +
                                                                                                              • + + + Sample 16 bit output + + + +
                                                                                                              • + +
                                                                                                              +
                                                                                                              + +
                                                                                                            • + +
                                                                                                            • + + + Testing the OLED + + + +
                                                                                                              +
                                                                                                                + +
                                                                                                              • + + + Getting the defaults + + + +
                                                                                                              • + +
                                                                                                              +
                                                                                                              + +
                                                                                                            • + +
                                                                                                            • + + + Continuous Text Display on OLED + + + +
                                                                                                            • + +
                                                                                                            • + + + Bar Chart and Text Display of Pot Value + + + +
                                                                                                            • + +
                                                                                                            • + + + Gif of OLED + + + +
                                                                                                            • + +
                                                                                                            + +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + +
                                                                                                            +
                                                                                                            + + + + + + + +

                                                                                                            OLED Potentiometer Example

                                                                                                            +

                                                                                                            In this lesson, we will use a potentiometer to change the value of an OLED display. We will use a small SSD1306 OLED with an I2C interface.

                                                                                                            +

                                                                                                            A potentiometer has three wires. The two outside wires connect to GND and the 3.3 volt output. The center wire, called the "tap" wire will connect to the pin that converts an continuous analog voltage value into a digital number.

                                                                                                            +

                                                                                                            Wikipedia Page on Potentiometer

                                                                                                            +

                                                                                                            Circuit Diagram

                                                                                                            +

                                                                                                            +

                                                                                                            +

                                                                                                            Sample Code

                                                                                                            +

                                                                                                            Testing the POT

                                                                                                            +

                                                                                                            Our first task is to find what pin to use for our first Analog to Digital concerter. GP26 is the same as ADC0. This is pin number 31 on the Pico.

                                                                                                            +
                                                                                                            1
                                                                                                            +2
                                                                                                            +3
                                                                                                            +4
                                                                                                            +5
                                                                                                            +6
                                                                                                            import machine
                                                                                                            +import utime
                                                                                                            +pot = machine.ADC(26)
                                                                                                            +while True:
                                                                                                            +    print(pot.read_u16())
                                                                                                            +    utime.sleep(.2)
                                                                                                            +
                                                                                                            +

                                                                                                            Sample 16 bit output

                                                                                                            +

                                                                                                            A 16-bit integer can store 216 (or 65,536) distinct values. In an unsigned representation, these values are the integers between 0 and 65,535. So we are expecting numbers from 0 to 65,535.

                                                                                                            +

                                                                                                            Sample results as we move the potentiometer from the minimum to the maximum values. +

                                                                                                             1
                                                                                                            + 2
                                                                                                            + 3
                                                                                                            + 4
                                                                                                            + 5
                                                                                                            + 6
                                                                                                            + 7
                                                                                                            + 8
                                                                                                            + 9
                                                                                                            +10
                                                                                                            +11
                                                                                                            +12
                                                                                                            +13
                                                                                                            +14
                                                                                                            +15
                                                                                                            +16
                                                                                                            +17
                                                                                                            65535
                                                                                                            +52844
                                                                                                            +31047
                                                                                                            +7745
                                                                                                            +256
                                                                                                            +352
                                                                                                            +19140
                                                                                                            +41114
                                                                                                            +62239
                                                                                                            +65535
                                                                                                            +57277
                                                                                                            +33384
                                                                                                            +10114
                                                                                                            +352
                                                                                                            +288
                                                                                                            +19940
                                                                                                            +28086
                                                                                                            +

                                                                                                            +

                                                                                                            Testing the OLED

                                                                                                            +

                                                                                                            Getting the defaults

                                                                                                            +
                                                                                                            1
                                                                                                            +2
                                                                                                            +3
                                                                                                            +4
                                                                                                            +5
                                                                                                            from machine import Pin, I2C
                                                                                                            +# i2c=machine.I2C(0)
                                                                                                            +i2c=machine.I2C(0)
                                                                                                            +print("Device found at decimal", i2c.scan())
                                                                                                            +print(i2c)
                                                                                                            +
                                                                                                            +

                                                                                                            Results: +This tells you the default pins and frequency that the I2C bus is running at.

                                                                                                            +
                                                                                                            1
                                                                                                            +2
                                                                                                            Device found at decimal [60]
                                                                                                            +I2C(0, freq=399361, scl=9, sda=8)
                                                                                                            +
                                                                                                            +
                                                                                                            1
                                                                                                            +2
                                                                                                            Device found at decimal [60]
                                                                                                            +I2C(0, freq=399361, scl=1, sda=0)
                                                                                                            +
                                                                                                            +

                                                                                                            This tells us that the default pins are GP9 (row 12) for clock and GP8 (row 11) for data.

                                                                                                            +
                                                                                                            1
                                                                                                            +2
                                                                                                            +3
                                                                                                            +4
                                                                                                            +5
                                                                                                            +6
                                                                                                            +7
                                                                                                            +8
                                                                                                            +9
                                                                                                            from machine import Pin, I2C
                                                                                                            +from ssd1306 import SSD1306_I2C
                                                                                                            +WIDTH  = 128
                                                                                                            +HEIGHT = 64
                                                                                                            +i2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) 
                                                                                                            +oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)
                                                                                                            +oled.fill(0)
                                                                                                            +oled.text("CoderDojo Rocks",0,0)
                                                                                                            +oled.show()
                                                                                                            +
                                                                                                            +

                                                                                                            Continuous Text Display on OLED

                                                                                                            +
                                                                                                             1
                                                                                                            + 2
                                                                                                            + 3
                                                                                                            + 4
                                                                                                            + 5
                                                                                                            + 6
                                                                                                            + 7
                                                                                                            + 8
                                                                                                            + 9
                                                                                                            +10
                                                                                                            +11
                                                                                                            +12
                                                                                                            +13
                                                                                                            +14
                                                                                                            from machine import Pin, I2C
                                                                                                            +from ssd1306 import SSD1306_I2C
                                                                                                            +WIDTH  = 128
                                                                                                            +HEIGHT = 32
                                                                                                            +i2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) 
                                                                                                            +oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)
                                                                                                            +
                                                                                                            +POT_PIN = machine.ADC(26)
                                                                                                            +
                                                                                                            +while True:
                                                                                                            +    oled.fill(0)
                                                                                                            +    oled.text(POT_PIN.read_u16())
                                                                                                            +    oled.show()
                                                                                                            +    utime.sleep(.2)
                                                                                                            +
                                                                                                            +

                                                                                                            Bar Chart and Text Display of Pot Value

                                                                                                            +
                                                                                                             1
                                                                                                            + 2
                                                                                                            + 3
                                                                                                            + 4
                                                                                                            + 5
                                                                                                            + 6
                                                                                                            + 7
                                                                                                            + 8
                                                                                                            + 9
                                                                                                            +10
                                                                                                            +11
                                                                                                            +12
                                                                                                            +13
                                                                                                            +14
                                                                                                            +15
                                                                                                            +16
                                                                                                            +17
                                                                                                            +18
                                                                                                            +19
                                                                                                            +20
                                                                                                            +21
                                                                                                            +22
                                                                                                            +23
                                                                                                            +24
                                                                                                            +25
                                                                                                            +26
                                                                                                            +27
                                                                                                            +28
                                                                                                            +29
                                                                                                            +30
                                                                                                            +31
                                                                                                            +32
                                                                                                            +33
                                                                                                            +34
                                                                                                            +35
                                                                                                            +36
                                                                                                            +37
                                                                                                            +38
                                                                                                            +39
                                                                                                            +40
                                                                                                            +41
                                                                                                            +42
                                                                                                            +43
                                                                                                            +44
                                                                                                            +45
                                                                                                            +46
                                                                                                            +47
                                                                                                            +48
                                                                                                            +49
                                                                                                            +50
                                                                                                            +51
                                                                                                            import machine
                                                                                                            +import utime
                                                                                                            +import sh1106
                                                                                                            +
                                                                                                            +sda=machine.Pin(0)
                                                                                                            +scl=machine.Pin(1)
                                                                                                            +pot_pin = machine.ADC(26)
                                                                                                            +
                                                                                                            +i2c=machine.I2C(0,sda=sda, scl=scl)
                                                                                                            +# Screen size
                                                                                                            +width=128
                                                                                                            +height=64
                                                                                                            +half_height = int(height / 2)
                                                                                                            +# oled = SSD1306_I2C(width, height, i2c)
                                                                                                            +oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c)
                                                                                                            +
                                                                                                            +oled.fill(0) # clear to black
                                                                                                            +
                                                                                                            +# note that OLEDs have problems with screen burn it - don't leave this on too long!
                                                                                                            +def border(width, height):
                                                                                                            +    oled.hline(0, 0, width - 1, 1) # top edge
                                                                                                            +    oled.hline(0, height - 2, width - 1, 1) # bottom edge
                                                                                                            +    oled.vline(0, 0, height - 1, 1) # left edge
                                                                                                            +    oled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                                            +
                                                                                                            +# Takes an input number vale and a range between high-and-low and returns it scaled to the new range
                                                                                                            +# This is similar to the Arduino map() function
                                                                                                            +def valmap(value, istart, istop, ostart, ostop):
                                                                                                            +  return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart)))
                                                                                                            +
                                                                                                            +# draw a horizontal bar
                                                                                                            +def draw_hbar(inval, height, state):
                                                                                                            +    oled.fill(0) # clear screen
                                                                                                            +    border(width, height) # draw a border
                                                                                                            +    oled.fill_rect(0, 1, inval, height, 1) # fill with 1
                                                                                                            +    utime.sleep(.1) # wait a bit
                                                                                                            +
                                                                                                            +# continuous update
                                                                                                            +while True:
                                                                                                            +    pot_val = int(pot_pin.read_u16())
                                                                                                            +    # the max value of the input is a 2^16 or 65536
                                                                                                            +    pot_scaled = valmap(pot_val, 0, 65536, 0, 127)
                                                                                                            +    print(pot_val, pot_scaled)
                                                                                                            +    draw_hbar(pot_scaled, half_height, 1)
                                                                                                            +
                                                                                                            +    oled.text('raw:', 0, half_height + 5, 1)
                                                                                                            +    oled.text(str(pot_val), 30, half_height + 5, 1)
                                                                                                            +
                                                                                                            +    oled.text('scaled:', 0, half_height + 15, 1)
                                                                                                            +    oled.text(str(pot_scaled), 60, half_height + 15, 1)
                                                                                                            +    oled.show()  
                                                                                                            +
                                                                                                            +

                                                                                                            Gif of OLED

                                                                                                            +

                                                                                                            Gif of small .96" OLED +OLED Pot Small

                                                                                                            +

                                                                                                            Gif of larger 2.42" OLED +OLED Pot Large Screen

                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                            +
                                                                                                            + + + +
                                                                                                            + + + +
                                                                                                            + +
                                                                                                            + + + +
                                                                                                            + + + +
                                                                                                            + + +
                                                                                                            +
                                                                                                            + + Previous + +
                                                                                                            + OLED Bounce +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + + +
                                                                                                            + + Next + +
                                                                                                            + OLED Ping +
                                                                                                            +
                                                                                                            +
                                                                                                            + + +
                                                                                                            +
                                                                                                            + +
                                                                                                            + + +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                            + +
                                                                                                            +
                                                                                                            +
                                                                                                            + +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/12-oled-ssd1306-spi-v1/index.html b/displays/graph/12-oled-ssd1306-spi-v1/index.html new file mode 100644 index 000000000..cf9ae7a2c --- /dev/null +++ b/displays/graph/12-oled-ssd1306-spi-v1/index.html @@ -0,0 +1,2010 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED SSD1306 SPI V1 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                            + + + + Skip to content + + +
                                                                                                            +
                                                                                                            + +
                                                                                                            + + + + + + +
                                                                                                            +
                                                                                                            + + + logo + + + +
                                                                                                            +
                                                                                                            +
                                                                                                            + + MicroPython for Kids + +
                                                                                                            +
                                                                                                            + + + OLED SSD1306 SPI V1 + + +
                                                                                                            +
                                                                                                            +
                                                                                                            + + + + + + + +
                                                                                                            + +
                                                                                                            +
                                                                                                            + + +
                                                                                                            + + +
                                                                                                            + +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            +
                                                                                                            + Initializing search +
                                                                                                            +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              + + +
                                                                                                              + +
                                                                                                              + + +
                                                                                                              +
                                                                                                              + GitHub Repo +
                                                                                                              +
                                                                                                              +
                                                                                                              + +
                                                                                                              + +
                                                                                                              + +
                                                                                                              + + + + + + +
                                                                                                              +
                                                                                                              + + + +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + + +
                                                                                                              + + +
                                                                                                              + +
                                                                                                              + + +
                                                                                                              +
                                                                                                              + GitHub Repo +
                                                                                                              +
                                                                                                              +
                                                                                                              + +
                                                                                                                + + + + + + + +
                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + +
                                                                                                                + +
                                                                                                                  + + + + + + + +
                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Wiring Harness + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Graphic LCD + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Basic Drawing + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Custom Drawing Functions + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Color LCD ST7789V + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Timing Draw Speed + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + TFT ILI9341 + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + LCD Waveshare + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + E-Paper + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Setup + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                • + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + OLED SSD1306 SPI V1 + + + + + + + +
                                                                                                                  + + + + + +
                                                                                                                    + +
                                                                                                                  • + + + OLED SPI Demo + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Image + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Code + + + +
                                                                                                                  • + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED SSD 1352 + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Bounce + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Pot + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Ping + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Pong + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Pixel Draw + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED Patterns + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + Random Hearts + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + NeoPixel Matrix + + + + +
                                                                                                                • + + + + + + + + + + +
                                                                                                                • + + + + + OLED References + + + + +
                                                                                                                • + + + + +
                                                                                                                +
                                                                                                                + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + Glossary + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + References + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + Contributing + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + Contact + + + + +
                                                                                                              • + + + + + + + + + +
                                                                                                              • + + + + + Colophon + + + + +
                                                                                                              • + + + +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + +
                                                                                                              +
                                                                                                              +
                                                                                                              + + +
                                                                                                              + + + + + +
                                                                                                                + +
                                                                                                              • + + + OLED SPI Demo + + + +
                                                                                                              • + +
                                                                                                              • + + + Image + + + +
                                                                                                              • + +
                                                                                                              • + + + Code + + + +
                                                                                                              • + +
                                                                                                              + +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + +
                                                                                                              +
                                                                                                              + + + + + + + +

                                                                                                              OLED SSD1306 SPI V1

                                                                                                              + +

                                                                                                              OLED SPI Demo

                                                                                                              +

                                                                                                              This code was provide by Jim Tannenbaum (aka Jet)

                                                                                                              +

                                                                                                              Image

                                                                                                              +

                                                                                                              +

                                                                                                              +

                                                                                                              Code

                                                                                                              +
                                                                                                               1
                                                                                                              + 2
                                                                                                              + 3
                                                                                                              + 4
                                                                                                              + 5
                                                                                                              + 6
                                                                                                              + 7
                                                                                                              + 8
                                                                                                              + 9
                                                                                                              +10
                                                                                                              +11
                                                                                                              +12
                                                                                                              import machine import ssd1306
                                                                                                              +spi_sck=machine.Pin(2)
                                                                                                              +spi_tx=machine.Pin(3)
                                                                                                              +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                              +CS = machine.Pin(1)
                                                                                                              +DC = machine.Pin(4)
                                                                                                              +RES = machine.Pin(5)
                                                                                                              +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                                              +# flash all pixels on oled.fill(0)
                                                                                                              +oled.show()
                                                                                                              +oled.text('Hello Jet', 0, 0, 1)
                                                                                                              +oled.show()
                                                                                                              +
                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                              +
                                                                                                              + + + +
                                                                                                              + + + +
                                                                                                              + +
                                                                                                              + + + +
                                                                                                              + + + +
                                                                                                              + + +
                                                                                                              +
                                                                                                              + + Previous + +
                                                                                                              + OLED SSD1306 I2C +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + + +
                                                                                                              + + Next + +
                                                                                                              + OLED SSD1306 SPI V2 +
                                                                                                              +
                                                                                                              +
                                                                                                              + + +
                                                                                                              +
                                                                                                              + +
                                                                                                              + + +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                              + +
                                                                                                              +
                                                                                                              +
                                                                                                              + +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/13-pixel-draw/index.html b/displays/graph/13-pixel-draw/index.html new file mode 100644 index 000000000..f8124ab4f --- /dev/null +++ b/displays/graph/13-pixel-draw/index.html @@ -0,0 +1,2019 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Pixel Draw - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                              + + + + Skip to content + + +
                                                                                                              +
                                                                                                              + +
                                                                                                              + + + + + + +
                                                                                                              +
                                                                                                              + + + logo + + + +
                                                                                                              +
                                                                                                              +
                                                                                                              + + MicroPython for Kids + +
                                                                                                              +
                                                                                                              + + + OLED Pixel Draw + + +
                                                                                                              +
                                                                                                              +
                                                                                                              + + + + + + + +
                                                                                                              + +
                                                                                                              +
                                                                                                              + + +
                                                                                                              + + +
                                                                                                              + +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              +
                                                                                                              + Initializing search +
                                                                                                              +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + + +
                                                                                                                + +
                                                                                                                + + +
                                                                                                                +
                                                                                                                + GitHub Repo +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + +
                                                                                                                + + + + + + +
                                                                                                                +
                                                                                                                + + + +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + + +
                                                                                                                + + +
                                                                                                                + +
                                                                                                                + + +
                                                                                                                +
                                                                                                                + GitHub Repo +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                  + + + + + + + +
                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + +
                                                                                                                  + +
                                                                                                                    + + + + + + + +
                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Wiring Harness + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Graphic LCD + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Basic Drawing + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Custom Drawing Functions + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Color LCD ST7789V + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Timing Draw Speed + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + TFT ILI9341 + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + LCD Waveshare + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + E-Paper + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Setup + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED SSD 1352 + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Bounce + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Pot + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Ping + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Pong + + + + +
                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + OLED Pixel Draw + + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED Patterns + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + Random Hearts + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + NeoPixel Matrix + + + + +
                                                                                                                  • + + + + + + + + + + +
                                                                                                                  • + + + + + OLED References + + + + +
                                                                                                                  • + + + + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + References + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + Contact + + + + +
                                                                                                                • + + + + + + + + + +
                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                • + + + +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + +
                                                                                                                +
                                                                                                                +
                                                                                                                + + +
                                                                                                                + + + + + + +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + +
                                                                                                                +
                                                                                                                + + + + + + + +

                                                                                                                Sample Pixel-Based Drawing Program

                                                                                                                +

                                                                                                                Code example provided by Jim Tannenbaum.

                                                                                                                +

                                                                                                                This program will act like an Etch-A-Sketch(TM) program. It will use potentiometers with the center tap on GPIO pins GP26 and GP27 and draw as you move the potentiometers to control the X and Y dimensions.

                                                                                                                +
                                                                                                                 1
                                                                                                                + 2
                                                                                                                + 3
                                                                                                                + 4
                                                                                                                + 5
                                                                                                                + 6
                                                                                                                + 7
                                                                                                                + 8
                                                                                                                + 9
                                                                                                                +10
                                                                                                                +11
                                                                                                                +12
                                                                                                                +13
                                                                                                                +14
                                                                                                                +15
                                                                                                                +16
                                                                                                                +17
                                                                                                                +18
                                                                                                                +19
                                                                                                                +20
                                                                                                                +21
                                                                                                                +22
                                                                                                                +23
                                                                                                                +24
                                                                                                                +25
                                                                                                                +26
                                                                                                                +27
                                                                                                                +28
                                                                                                                +29
                                                                                                                +30
                                                                                                                +31
                                                                                                                +32
                                                                                                                +33
                                                                                                                +34
                                                                                                                +35
                                                                                                                +36
                                                                                                                +37
                                                                                                                +38
                                                                                                                +39
                                                                                                                +40
                                                                                                                +41
                                                                                                                +42
                                                                                                                +43
                                                                                                                +44
                                                                                                                +45
                                                                                                                +46
                                                                                                                +47
                                                                                                                +48
                                                                                                                +49
                                                                                                                +50
                                                                                                                +51
                                                                                                                +52
                                                                                                                +53
                                                                                                                +54
                                                                                                                +55
                                                                                                                +56
                                                                                                                +57
                                                                                                                +58
                                                                                                                +59
                                                                                                                +60
                                                                                                                +61
                                                                                                                +62
                                                                                                                from machine import Pin, SPI, ADC
                                                                                                                +import ssd1306
                                                                                                                +import time
                                                                                                                +
                                                                                                                +# Takes an input number value and a range between high-and-low and returns it scaled to the new range
                                                                                                                +# This is similar to the Arduino map() function
                                                                                                                +def scaled(value, istart, istop, ostart, ostop):
                                                                                                                +  return int(ostart + (ostop - ostart) * ((int(value) - istart) / (istop - istart)))
                                                                                                                +
                                                                                                                +# Define the pins for SPI Clock and Transmit
                                                                                                                +spi_sck = Pin(2)
                                                                                                                +spi_tx = Pin(3)
                                                                                                                +spi = SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx)
                                                                                                                +
                                                                                                                +# Define the pins for Chip Select, DC (Command), and Reset
                                                                                                                +CS = Pin(1)
                                                                                                                +DC = Pin(4)
                                                                                                                +RES = Pin(5)
                                                                                                                +
                                                                                                                +oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)
                                                                                                                +
                                                                                                                +# Turn all pixels off
                                                                                                                +oled.fill(0)
                                                                                                                +oled.show()
                                                                                                                +
                                                                                                                +# Provide info to user
                                                                                                                +oled.text('Etch-A-Sketch', 0, 0, 1)
                                                                                                                +oled.text('Hit the reset', 0, 20, 1)
                                                                                                                +oled.text('button to clear', 0, 30, 1)
                                                                                                                +oled.text('the screen', 0, 40, 1)
                                                                                                                +oled.show()
                                                                                                                +
                                                                                                                +# Define the pin for the reset button
                                                                                                                +resetButton = Pin(14, Pin.IN, Pin.PULL_DOWN)
                                                                                                                +
                                                                                                                +# Wait unti the user hits the button to clear the screen and start drawing
                                                                                                                +while resetButton.value() != 1:
                                                                                                                +    time.sleep(.25)
                                                                                                                +
                                                                                                                +oled.fill(0)
                                                                                                                +oled.show()
                                                                                                                +
                                                                                                                +# Define the Horizontal and Vertical inputs from the Rheostats
                                                                                                                +vert = ADC(26)
                                                                                                                +horiz = ADC(27)
                                                                                                                +
                                                                                                                +# Calculate where to start the line
                                                                                                                +x = newX = scaled(vert.read_u16(), 0, 65536, 0, 128)
                                                                                                                +y = newY = scaled(horiz.read_u16(), 0, 65536, 0, 64)
                                                                                                                +
                                                                                                                +# Loop forever
                                                                                                                +# Draw the line, look for a reset to clear the screen, and get the new end points for the line
                                                                                                                +while True:
                                                                                                                +    oled.line(x, y, newX, newY, 1)
                                                                                                                +    x = newX
                                                                                                                +    y = newY
                                                                                                                +    if resetButton.value():
                                                                                                                +        oled.fill(0)
                                                                                                                +    oled.show()
                                                                                                                +    time.sleep(.2)
                                                                                                                +    newX = scaled(vert.read_u16(), 0, 65536, 0, 128)
                                                                                                                +    newY = scaled(horiz.read_u16(), 0, 65536, 0, 64)
                                                                                                                +
                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                +
                                                                                                                + + + +
                                                                                                                + + + +
                                                                                                                + +
                                                                                                                + + + +
                                                                                                                + + + +
                                                                                                                + + +
                                                                                                                +
                                                                                                                + + Previous + +
                                                                                                                + OLED Pong +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + + +
                                                                                                                + + Next + +
                                                                                                                + OLED Patterns +
                                                                                                                +
                                                                                                                +
                                                                                                                + + +
                                                                                                                +
                                                                                                                + +
                                                                                                                + + +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                + +
                                                                                                                +
                                                                                                                +
                                                                                                                + +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/14-lcd-st7789V/index.html b/displays/graph/14-lcd-st7789V/index.html new file mode 100644 index 000000000..0aebf46e8 --- /dev/null +++ b/displays/graph/14-lcd-st7789V/index.html @@ -0,0 +1,2312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Color LCD ST7789V - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                + + + + Skip to content + + +
                                                                                                                +
                                                                                                                + +
                                                                                                                + + + + + + +
                                                                                                                +
                                                                                                                + + + logo + + + +
                                                                                                                +
                                                                                                                +
                                                                                                                + + MicroPython for Kids + +
                                                                                                                +
                                                                                                                + + + Color LCD ST7789V + + +
                                                                                                                +
                                                                                                                +
                                                                                                                + + + + + + + +
                                                                                                                + +
                                                                                                                +
                                                                                                                + + +
                                                                                                                + + +
                                                                                                                + +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                +
                                                                                                                + Initializing search +
                                                                                                                +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  + +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  + GitHub Repo +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + +
                                                                                                                  + + + + + + +
                                                                                                                  +
                                                                                                                  + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + + +
                                                                                                                  + + +
                                                                                                                  + +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  + GitHub Repo +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                    + + + + + + + +
                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + +
                                                                                                                    + +
                                                                                                                      + + + + + + + +
                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Wiring Harness + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Graphic LCD + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Basic Drawing + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Custom Drawing Functions + + + + +
                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + Color LCD ST7789V + + + + + + + +
                                                                                                                      + + + + + + + +
                                                                                                                        + +
                                                                                                                      • + + + Specifications + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Device Interface + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Interface + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Uploading the ST7789V Python Firmware + + + +
                                                                                                                      • + +
                                                                                                                      • + + + MicroPython Initialization + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Sample Device Initialize + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Sample Hello World In Four Colors + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Driver Implementation Notes + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Timing Diagram + + + +
                                                                                                                      • + +
                                                                                                                      • + + + References + + + +
                                                                                                                      • + +
                                                                                                                      + +
                                                                                                                      + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Timing Draw Speed + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + TFT ILI9341 + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + LCD Waveshare + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + E-Paper + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Setup + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED SSD 1352 + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Bounce + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Pot + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Ping + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Pong + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Pixel Draw + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED Patterns + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + Random Hearts + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + NeoPixel Matrix + + + + +
                                                                                                                    • + + + + + + + + + + +
                                                                                                                    • + + + + + OLED References + + + + +
                                                                                                                    • + + + + +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + References + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                  • + + + + + + + + + +
                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                  • + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  + + + + + + + +
                                                                                                                    + +
                                                                                                                  • + + + Specifications + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Device Interface + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Interface + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Uploading the ST7789V Python Firmware + + + +
                                                                                                                  • + +
                                                                                                                  • + + + MicroPython Initialization + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Sample Device Initialize + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Sample Hello World In Four Colors + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Driver Implementation Notes + + + +
                                                                                                                  • + +
                                                                                                                  • + + + Timing Diagram + + + +
                                                                                                                  • + +
                                                                                                                  • + + + References + + + +
                                                                                                                  • + +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + +
                                                                                                                  +
                                                                                                                  + + + + + + + +

                                                                                                                  MicroPython ST7789V LCD Display

                                                                                                                  +

                                                                                                                  +

                                                                                                                  The Sitronix ST7789 is a driver chip for small color IPS LCD displays that supports SPI interfaces. This example uses a 2-inch color LDC display manufactured by Waveshare with a retail price of approximately $13 or $14.75 on Amazon Prime.

                                                                                                                  +

                                                                                                                  Specifications

                                                                                                                  +
                                                                                                                    +
                                                                                                                  • Resolution: 240(V) x 320(H) RGB
                                                                                                                  • +
                                                                                                                  • 18 bit color (6 bits for R, G and B)
                                                                                                                  • +
                                                                                                                  • 1,382,400 bits of display memory
                                                                                                                  • +
                                                                                                                  • Interface: 4-wire SPI (kind of)
                                                                                                                  • +
                                                                                                                  • Operating voltage: 3.3V
                                                                                                                  • +
                                                                                                                  +

                                                                                                                  Note: The ST7789 uses a SPI interfaces but not a true standard SPI protocol. The device only uses MOSI (DIN) to send data from master to slave for LCD display. Only four wires are needed to connect from the Pico to the device.

                                                                                                                  +

                                                                                                                  Device Interface

                                                                                                                  +

                                                                                                                  +

                                                                                                                  Interface

                                                                                                                  +
                                                                                                                    +
                                                                                                                  1. VCC Power (3.3V input)
                                                                                                                  2. +
                                                                                                                  3. GND Ground
                                                                                                                  4. +
                                                                                                                  5. DIN SPI data input
                                                                                                                  6. +
                                                                                                                  7. CLK SPI clock input
                                                                                                                  8. +
                                                                                                                  9. CS Chip selection, low active
                                                                                                                  10. +
                                                                                                                  11. DC Data/Command selection (high for data, low for command)
                                                                                                                  12. +
                                                                                                                  13. RST Reset, low active
                                                                                                                  14. +
                                                                                                                  15. BL Backlight - tie to GND to turn the backlight on
                                                                                                                  16. +
                                                                                                                  +

                                                                                                                  Although the device has eight wires, your Pico only needs a few of them to be controlled by the GPIO ports.

                                                                                                                  +

                                                                                                                  Uploading the ST7789V Python Firmware

                                                                                                                  +

                                                                                                                  The firmware contains pre-compiled objects for various devices with the st7789 C driver and frozen python font files.

                                                                                                                  +

                                                                                                                  The library for the driver is delivered as a single firmware.uf2 file available here:

                                                                                                                  +

                                                                                                                  https://github.com/russhughes/st7789_mpy/tree/master/firmware/RP2

                                                                                                                  +

                                                                                                                  To load this file you will need to hold down the BOTSEL button on the Pico and drag this file into the RP2 folder that is mounted.

                                                                                                                  +

                                                                                                                  MicroPython Initialization

                                                                                                                  +

                                                                                                                  I used the following SPI Device ID 1 pinout on the lower left corner of the Pico:

                                                                                                                  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  PinGP NumberLabel on LCD
                                                                                                                  14(GP10)BL
                                                                                                                  15(GP11)RST
                                                                                                                  16(GP12)DC
                                                                                                                  17(GP13)CS
                                                                                                                  18(GND)GND
                                                                                                                  19(GP14)CLK
                                                                                                                  20(GP15)DIN
                                                                                                                  +

                                                                                                                  Sample Device Initialize

                                                                                                                  +
                                                                                                                   1
                                                                                                                  + 2
                                                                                                                  + 3
                                                                                                                  + 4
                                                                                                                  + 5
                                                                                                                  + 6
                                                                                                                  + 7
                                                                                                                  + 8
                                                                                                                  + 9
                                                                                                                  +10
                                                                                                                  +11
                                                                                                                  +12
                                                                                                                  +13
                                                                                                                  +14
                                                                                                                  +15
                                                                                                                  +16
                                                                                                                  +17
                                                                                                                  +18
                                                                                                                  +19
                                                                                                                  +20
                                                                                                                  +21
                                                                                                                  +22
                                                                                                                  from machine import Pin, SPI
                                                                                                                  +import st7789
                                                                                                                  +
                                                                                                                  +BACKLIGHT_PIN = 10
                                                                                                                  +RESET_PIN = 11
                                                                                                                  +DC_PIN = 12
                                                                                                                  +CS_PIN = 13
                                                                                                                  +CLK_PIN = 14
                                                                                                                  +DIN_PIN = 15 # lower left corner
                                                                                                                  +
                                                                                                                  +import vga1_bold_16x32 as font
                                                                                                                  +
                                                                                                                  +spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN))
                                                                                                                  +tft = st7789.ST7789(spi, 240, 320,
                                                                                                                  +    reset=Pin(RESET_PIN, Pin.OUT),
                                                                                                                  +    cs=Pin(CS_PIN, Pin.OUT),
                                                                                                                  +    dc=Pin(DC_PIN, Pin.OUT),
                                                                                                                  +    backlight=Pin(BACKLIGHT_PIN, Pin.OUT),
                                                                                                                  +    rotation=3)
                                                                                                                  +tft.init()
                                                                                                                  +# draw white letters on a back background at 10 over and 20 down
                                                                                                                  +tft.text(font, "Hello World!", 10, 20, st7789.color565(255,255,255), st7789.color565(0,0,0))
                                                                                                                  +
                                                                                                                  +

                                                                                                                  +

                                                                                                                  Sample Hello World In Four Colors

                                                                                                                  +
                                                                                                                   1
                                                                                                                  + 2
                                                                                                                  + 3
                                                                                                                  + 4
                                                                                                                  + 5
                                                                                                                  + 6
                                                                                                                  + 7
                                                                                                                  + 8
                                                                                                                  + 9
                                                                                                                  +10
                                                                                                                  +11
                                                                                                                  +12
                                                                                                                  +13
                                                                                                                  +14
                                                                                                                  +15
                                                                                                                  +16
                                                                                                                  +17
                                                                                                                  +18
                                                                                                                  +19
                                                                                                                  +20
                                                                                                                  +21
                                                                                                                  +22
                                                                                                                  +23
                                                                                                                  +24
                                                                                                                  +25
                                                                                                                  from machine import Pin, SPI
                                                                                                                  +import st7789
                                                                                                                  +
                                                                                                                  +BACKLIGHT_PIN = 10
                                                                                                                  +RESET_PIN = 11
                                                                                                                  +DC_PIN = 12
                                                                                                                  +CS_PIN = 13
                                                                                                                  +CLK_PIN = 14
                                                                                                                  +DIN_PIN = 15 # lower left corner
                                                                                                                  +
                                                                                                                  +import vga1_bold_16x32 as font
                                                                                                                  +
                                                                                                                  +spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN))
                                                                                                                  +tft = st7789.ST7789(spi, 240, 320,
                                                                                                                  +    reset=Pin(RESET_PIN, Pin.OUT),
                                                                                                                  +    cs=Pin(CS_PIN, Pin.OUT),
                                                                                                                  +    dc=Pin(DC_PIN, Pin.OUT),
                                                                                                                  +    backlight=Pin(BACKLIGHT_PIN, Pin.OUT),
                                                                                                                  +    rotation=3)
                                                                                                                  +tft.init()
                                                                                                                  +
                                                                                                                  +tft.text(font, "Hello World!",10, 0, st7789.color565(255,255,255), st7789.color565(0,0,0))
                                                                                                                  +tft.text(font, "Hello World!",10, 50, st7789.color565(255,0,0), st7789.color565(0,0,0))
                                                                                                                  +tft.text(font, "Hello World!",10, 100, st7789.color565(0,255,0), st7789.color565(0,0,0))
                                                                                                                  +tft.text(font, "Hello World!",10, 150, st7789.color565(0,0,255), st7789.color565(0,0,0))
                                                                                                                  +
                                                                                                                  +

                                                                                                                  Driver Implementation Notes

                                                                                                                  +

                                                                                                                  The ST7789V supports RGB444, RGB565 and RGB666 three formats. The Waveshare LCD uses RGB565. +For most LCD controllers, the communication method of the controller can be configured, they are usually using 8080 parallel interface, 3-line SPI, 4-line SPI, and other communication methods. This LCD uses a 4-line SPI interface for reducing GPIO and fast speed.LCD

                                                                                                                  +
                                                                                                                    +
                                                                                                                  1. RESX: Reset, should be pull-down when power on, set to 1 other time.
                                                                                                                  2. +
                                                                                                                  3. CSX: Slave chip select. The chip is enabled only CS is set Low
                                                                                                                  4. +
                                                                                                                  5. D/CX: Data/Command selection; DC=0, write command; DC=1, write data
                                                                                                                  6. +
                                                                                                                  7. SDA: Data transmitted. (RGB data)
                                                                                                                  8. +
                                                                                                                  9. SCL: SPI clock
                                                                                                                  10. +
                                                                                                                  +

                                                                                                                  Timing Diagram

                                                                                                                  +

                                                                                                                  You can see what data needs to be changing from the timing diagram below:

                                                                                                                  +

                                                                                                                  +
                                                                                                                    +
                                                                                                                  1. The SPI communication protocol of the data transmission uses control bits: clock phase (CPHA) and clock polarity (CPOL)
                                                                                                                  2. +
                                                                                                                  3. CPOL defines the level while the synchronization clock is idle. If CPOL=0, then it is LOW.
                                                                                                                  4. +
                                                                                                                  5. CPHA defines at whish clock’s tick the data transmission starts. CPHL=0 – at the first one, otherwise at the second one
                                                                                                                  6. +
                                                                                                                  +

                                                                                                                  This combination of two bits provides 4 modes of SPI data transmission. The commonly used is SPI0 mode, i.e. GPHL=0 and CPOL=0.

                                                                                                                  +

                                                                                                                  According to the figure above, data transmitting begins at the first falling edge, 8bit data are transmitted at one clock cycle. It is SPI0. MSB.

                                                                                                                  +

                                                                                                                  References

                                                                                                                  +
                                                                                                                    +
                                                                                                                  1. ST7789C Datasheet (PDF)
                                                                                                                  2. +
                                                                                                                  3. Waveshare Wiki
                                                                                                                  4. +
                                                                                                                  5. Waveshare Pico Dispaly
                                                                                                                  6. +
                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                  +
                                                                                                                  + + + +
                                                                                                                  + + + +
                                                                                                                  + +
                                                                                                                  + + + +
                                                                                                                  + + + +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  + + Previous + +
                                                                                                                  + Custom Drawing Functions +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + + +
                                                                                                                  + + Next + +
                                                                                                                  + Timing Draw Speed +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/14-random-hearts/index.html b/displays/graph/14-random-hearts/index.html new file mode 100644 index 000000000..19ebc9e12 --- /dev/null +++ b/displays/graph/14-random-hearts/index.html @@ -0,0 +1,1986 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Random Hearts - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                  + + + + Skip to content + + +
                                                                                                                  +
                                                                                                                  + +
                                                                                                                  + + + + + + +
                                                                                                                  +
                                                                                                                  + + + logo + + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + MicroPython for Kids + +
                                                                                                                  +
                                                                                                                  + + + Random Hearts + + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + + + + + + + +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  + + +
                                                                                                                  + + +
                                                                                                                  + +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  +
                                                                                                                  + Initializing search +
                                                                                                                  +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + +
                                                                                                                    + +
                                                                                                                    + + +
                                                                                                                    +
                                                                                                                    + GitHub Repo +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                    + +
                                                                                                                    + +
                                                                                                                    + + + + + + +
                                                                                                                    +
                                                                                                                    + + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + + +
                                                                                                                    + + +
                                                                                                                    + +
                                                                                                                    + + +
                                                                                                                    +
                                                                                                                    + GitHub Repo +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                      + + + + + + + +
                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + +
                                                                                                                      + +
                                                                                                                        + + + + + + + +
                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Wiring Harness + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Graphic LCD + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Basic Drawing + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Custom Drawing Functions + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Color LCD ST7789V + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + Timing Draw Speed + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + TFT ILI9341 + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + LCD Waveshare + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + E-Paper + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Setup + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED SSD 1352 + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Bounce + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Pot + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Ping + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Pong + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Pixel Draw + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED Patterns + + + + +
                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + Random Hearts + + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + NeoPixel Matrix + + + + +
                                                                                                                      • + + + + + + + + + + +
                                                                                                                      • + + + + + OLED References + + + + +
                                                                                                                      • + + + + +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + References + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                    • + + + + + + + + + +
                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                    • + + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + +
                                                                                                                    + + + + + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + +
                                                                                                                    +
                                                                                                                    + + + + + + + +

                                                                                                                    Draw Random Hearts

                                                                                                                    +

                                                                                                                    This program uses the MicroPython urandom library to generate random X and Y positions on the display. It then uses an array of binary values to draw a heart icon at that location.

                                                                                                                    +
                                                                                                                     1
                                                                                                                    + 2
                                                                                                                    + 3
                                                                                                                    + 4
                                                                                                                    + 5
                                                                                                                    + 6
                                                                                                                    + 7
                                                                                                                    + 8
                                                                                                                    + 9
                                                                                                                    +10
                                                                                                                    +11
                                                                                                                    +12
                                                                                                                    +13
                                                                                                                    +14
                                                                                                                    +15
                                                                                                                    +16
                                                                                                                    +17
                                                                                                                    +18
                                                                                                                    +19
                                                                                                                    +20
                                                                                                                    +21
                                                                                                                    +22
                                                                                                                    +23
                                                                                                                    +24
                                                                                                                    +25
                                                                                                                    +26
                                                                                                                    +27
                                                                                                                    +28
                                                                                                                    +29
                                                                                                                    +30
                                                                                                                    +31
                                                                                                                    +32
                                                                                                                    +33
                                                                                                                    +34
                                                                                                                    +35
                                                                                                                    +36
                                                                                                                    +37
                                                                                                                    +38
                                                                                                                    +39
                                                                                                                    +40
                                                                                                                    +41
                                                                                                                    +42
                                                                                                                    +43
                                                                                                                    +44
                                                                                                                    +45
                                                                                                                    +46
                                                                                                                    from machine import Pin, PWM, SPI
                                                                                                                    +import urandom
                                                                                                                    +import ssd1306
                                                                                                                    +from utime import sleep
                                                                                                                    +import random # random direction for new ball
                                                                                                                    +
                                                                                                                    +WIDTH = 128
                                                                                                                    +HEIGHT = 64
                                                                                                                    +CS = machine.Pin(1)
                                                                                                                    +spi_sck=machine.Pin(2)
                                                                                                                    +spi_tx=machine.Pin(3)
                                                                                                                    +DC = machine.Pin(4)
                                                                                                                    +RES = machine.Pin(5)
                                                                                                                    +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                                    +
                                                                                                                    +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                    +
                                                                                                                    +HEART = [
                                                                                                                    +    [ 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                                                                                                    +    [ 0, 1, 1, 0, 0, 0, 1, 1, 0],
                                                                                                                    +    [ 1, 1, 1, 1, 0, 1, 1, 1, 1],
                                                                                                                    +    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                                                                                                    +    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],
                                                                                                                    +    [ 0, 1, 1, 1, 1, 1, 1, 1, 0],
                                                                                                                    +    [ 0, 0, 1, 1, 1, 1, 1, 0, 0],
                                                                                                                    +    [ 0, 0, 0, 1, 1, 1, 0, 0, 0],
                                                                                                                    +    [ 0, 0, 0, 0, 1, 0, 0, 0, 0],
                                                                                                                    +]
                                                                                                                    +
                                                                                                                    +def draw_heart(xofs, yofs):
                                                                                                                    +    for y, row in enumerate(HEART):
                                                                                                                    +        for x, c in enumerate(row):
                                                                                                                    +            oled.pixel(x + xofs, y + yofs, c)
                                                                                                                    +
                                                                                                                    +def random_heart():
                                                                                                                    +    xofs = urandom.getrandbits(7)
                                                                                                                    +    yofs = urandom.getrandbits(6)
                                                                                                                    +    print(xofs, yofs)
                                                                                                                    +    draw_heart(xofs, yofs)
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +oled.fill(0)
                                                                                                                    +for n in range(10):
                                                                                                                    +    random_heart()
                                                                                                                    +
                                                                                                                    +oled.show()
                                                                                                                    +
                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                    +
                                                                                                                    + + + +
                                                                                                                    + + + +
                                                                                                                    + +
                                                                                                                    + + + +
                                                                                                                    + + + +
                                                                                                                    + + +
                                                                                                                    +
                                                                                                                    + + Previous + +
                                                                                                                    + OLED Patterns +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + + +
                                                                                                                    + + Next + +
                                                                                                                    + NeoPixel Matrix +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                    + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                    + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/15-cu1609c-led/index.html b/displays/graph/15-cu1609c-led/index.html new file mode 100644 index 000000000..0e4ddeaff --- /dev/null +++ b/displays/graph/15-cu1609c-led/index.html @@ -0,0 +1,2116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Graphic LCD - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                    + + + + Skip to content + + +
                                                                                                                    +
                                                                                                                    + +
                                                                                                                    + + + + + + +
                                                                                                                    +
                                                                                                                    + + + logo + + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + MicroPython for Kids + +
                                                                                                                    +
                                                                                                                    + + + Graphic LCD + + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + + + + + + + +
                                                                                                                    + +
                                                                                                                    +
                                                                                                                    + + +
                                                                                                                    + + +
                                                                                                                    + +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    +
                                                                                                                    + Initializing search +
                                                                                                                    +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + +
                                                                                                                      + +
                                                                                                                      + + +
                                                                                                                      +
                                                                                                                      + GitHub Repo +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                      + +
                                                                                                                      + +
                                                                                                                      + + + + + + +
                                                                                                                      +
                                                                                                                      + + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + + +
                                                                                                                      + + +
                                                                                                                      + +
                                                                                                                      + + +
                                                                                                                      +
                                                                                                                      + GitHub Repo +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                        + + + + + + + +
                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + +
                                                                                                                        + +
                                                                                                                          + + + + + + + +
                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Wiring Harness + + + + +
                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + Graphic LCD + + + + + + + +
                                                                                                                          + + + + + + + +
                                                                                                                            + +
                                                                                                                          • + + + Connections + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Connection Notes + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Hello World + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Similar Drivers + + + +
                                                                                                                          • + +
                                                                                                                          • + + + References + + + +
                                                                                                                          • + +
                                                                                                                          + +
                                                                                                                          + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Basic Drawing + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Custom Drawing Functions + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Color LCD ST7789V + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Timing Draw Speed + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + TFT ILI9341 + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + LCD Waveshare + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + E-Paper + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Setup + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED SSD 1352 + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Bounce + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Pot + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Ping + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Pong + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Pixel Draw + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED Patterns + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + Random Hearts + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + NeoPixel Matrix + + + + +
                                                                                                                        • + + + + + + + + + + +
                                                                                                                        • + + + + + OLED References + + + + +
                                                                                                                        • + + + + +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + References + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                      • + + + + + + + + + +
                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                      • + + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + +
                                                                                                                      + + + + + + + +
                                                                                                                        + +
                                                                                                                      • + + + Connections + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Connection Notes + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Hello World + + + +
                                                                                                                      • + +
                                                                                                                      • + + + Similar Drivers + + + +
                                                                                                                      • + +
                                                                                                                      • + + + References + + + +
                                                                                                                      • + +
                                                                                                                      + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + +
                                                                                                                      +
                                                                                                                      + + + + + + + +

                                                                                                                      CU1609C LED Display

                                                                                                                      +

                                                                                                                      Note: This is a work-in-progress. We have not found a MicroPython driver for this display.

                                                                                                                      +

                                                                                                                      The UC1609 is a graphic LED driver chip with an SPI interface. Because it is low cost ($4) and 2 inches across it is ideal for low-cost robot displays.

                                                                                                                      +

                                                                                                                      192X62 LCD display for $4 USB device +LCD Blue UC1609 SPI

                                                                                                                      +

                                                                                                                      Connections

                                                                                                                      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      Pin NameDescription
                                                                                                                      1 K Backlight CathodeConnect to GND rail
                                                                                                                      2 A Backlight AnodeConnect via 200 ohm to 3.2v rail to limit backlight current to 3 milliamps. The current for backlight is limited to 20 milliamps.
                                                                                                                      3 GND GroundConnect to GND rail
                                                                                                                      4 VDD Power Supplyconnect to +3.3v rail
                                                                                                                      5 SCK Serial clock input.Connect to SPI CLK
                                                                                                                      6 SDA Serial data input.Connect to SPI Data SCL
                                                                                                                      7 RSTConnect to 3.3v rail.
                                                                                                                      8 CDIt determines whether the access is related to data or command. Connect to GPIO
                                                                                                                      9 CSChip select input. Connect to GND when LCD is use.
                                                                                                                      +

                                                                                                                      Connection Notes

                                                                                                                      +

                                                                                                                      When RST=L, all control registers are re-initialized by their default sates. Since UC1609c has +built-in Power-on Reset, the RST pin is not required for proper chip operation. +An RC filter has been included on-chip. There is no need for external RC noise filter. When RST +is not used, connect the pin to High.

                                                                                                                      +

                                                                                                                      CS determines whether the access is related to data or command. When CS=“H” : Display data. When CS=“L” : Command.

                                                                                                                      +

                                                                                                                      Hello World

                                                                                                                      +
                                                                                                                       1
                                                                                                                      + 2
                                                                                                                      + 3
                                                                                                                      + 4
                                                                                                                      + 5
                                                                                                                      + 6
                                                                                                                      + 7
                                                                                                                      + 8
                                                                                                                      + 9
                                                                                                                      +10
                                                                                                                      +11
                                                                                                                      from machine import Pin, SPI
                                                                                                                      +
                                                                                                                      +SPI_CLK = 2 # SPI clock
                                                                                                                      +SPI_SDA = 3
                                                                                                                      +CD = 5 # command or data
                                                                                                                      +# RST is tied to 3.3v
                                                                                                                      +# CS is tied to GND
                                                                                                                      +
                                                                                                                      +# SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=2, mosi=3, miso=4)
                                                                                                                      +spi = SPI(0, baudrate=31250000, sck=Pin(SPI_CLK), mosi=Pin(SPI_SDA))
                                                                                                                      +print(spi)
                                                                                                                      +
                                                                                                                      +

                                                                                                                      Similar Drivers

                                                                                                                      +

                                                                                                                      There are two similar drivers. One is for the LCD160CR

                                                                                                                      +

                                                                                                                      LCD160CR Display Driver

                                                                                                                      +

                                                                                                                      The other is the Arduino C version by Gavin Lyones that has been around for a long time.

                                                                                                                      +

                                                                                                                      Gavin Lyons GitHub Repo supporting the UC1609

                                                                                                                      +

                                                                                                                      Our goal is to port Gavin's C code to use the same function as the LCD160CR driver.

                                                                                                                      +

                                                                                                                      References

                                                                                                                      +
                                                                                                                        +
                                                                                                                      1. BuyDisplay Product 2 inch Blue 192x64 Graphic LCD Display Module,UC1609,SPI for $3.48
                                                                                                                      2. +
                                                                                                                      3. ERM19264-4 SeriesGraphic Display Module Datasheet
                                                                                                                      4. +
                                                                                                                      5. Gavin Lyons GitHub Repo supporting the UC1609
                                                                                                                      6. +
                                                                                                                      7. EBay Product 2 inch White 192x64 Graphic LCD Display Module,UC1609,SPI
                                                                                                                      8. +
                                                                                                                      9. MicroPython Pyboard LCD Class
                                                                                                                      10. +
                                                                                                                      11. List of LCD Graphic Displays
                                                                                                                      12. +
                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                      +
                                                                                                                      + + + +
                                                                                                                      + + + +
                                                                                                                      + +
                                                                                                                      + + + +
                                                                                                                      + + + +
                                                                                                                      + + +
                                                                                                                      +
                                                                                                                      + + Previous + +
                                                                                                                      + Wiring Harness +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + + +
                                                                                                                      + + Next + +
                                                                                                                      + Basic Drawing +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                      + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                      + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/15-oled-patterns/index.html b/displays/graph/15-oled-patterns/index.html new file mode 100644 index 000000000..d64f9f477 --- /dev/null +++ b/displays/graph/15-oled-patterns/index.html @@ -0,0 +1,2478 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED Patterns - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                      + + + + Skip to content + + +
                                                                                                                      +
                                                                                                                      + +
                                                                                                                      + + + + + + +
                                                                                                                      +
                                                                                                                      + + + logo + + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + MicroPython for Kids + +
                                                                                                                      +
                                                                                                                      + + + OLED Patterns + + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + + + + + + + +
                                                                                                                      + +
                                                                                                                      +
                                                                                                                      + + +
                                                                                                                      + + +
                                                                                                                      + +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      +
                                                                                                                      + Initializing search +
                                                                                                                      +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + +
                                                                                                                        + +
                                                                                                                        + + +
                                                                                                                        +
                                                                                                                        + GitHub Repo +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                        + +
                                                                                                                        + +
                                                                                                                        + + + + + + +
                                                                                                                        +
                                                                                                                        + + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + + +
                                                                                                                        + + +
                                                                                                                        + +
                                                                                                                        + + +
                                                                                                                        +
                                                                                                                        + GitHub Repo +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                          + + + + + + + +
                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + +
                                                                                                                          + +
                                                                                                                            + + + + + + + +
                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Wiring Harness + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Graphic LCD + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Basic Drawing + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Custom Drawing Functions + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Color LCD ST7789V + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Timing Draw Speed + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + TFT ILI9341 + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + LCD Waveshare + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + E-Paper + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Setup + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED SSD 1352 + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Bounce + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Pot + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Ping + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Pong + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED Pixel Draw + + + + +
                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + OLED Patterns + + + + + + + +
                                                                                                                            + + + + + + + +
                                                                                                                              + +
                                                                                                                            • + + + Math Functions + + + +
                                                                                                                            • + +
                                                                                                                            • + + + Some Sample Equations + + + +
                                                                                                                            • + +
                                                                                                                            • + + + Sample Code + + + +
                                                                                                                            • + +
                                                                                                                            • + + + Adding a List of Patterns + + + +
                                                                                                                              +
                                                                                                                                + +
                                                                                                                              • + + + The Eval Function + + + +
                                                                                                                              • + +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                            • + +
                                                                                                                            • + + + The Command Design Pattern + + + +
                                                                                                                            • + +
                                                                                                                            • + + + Sample Screen Images + + + +
                                                                                                                              +
                                                                                                                                + +
                                                                                                                              • + + + X Modulo Y + + + +
                                                                                                                              • + +
                                                                                                                              • + + + (x % y) % 4 + + + +
                                                                                                                              • + +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                            • + +
                                                                                                                            • + + + Sierpinsky Triangles (x & y) + + + +
                                                                                                                            • + +
                                                                                                                            • + + + (x * y) & 24 + + + +
                                                                                                                            • + +
                                                                                                                            • + + + (x * y) & 64 + + + +
                                                                                                                            • + +
                                                                                                                            • + + + 40 % x % (y+1) + + + +
                                                                                                                            • + +
                                                                                                                            • + + + Reference + + + +
                                                                                                                            • + +
                                                                                                                            + +
                                                                                                                            + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + Random Hearts + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + NeoPixel Matrix + + + + +
                                                                                                                          • + + + + + + + + + + +
                                                                                                                          • + + + + + OLED References + + + + +
                                                                                                                          • + + + + +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + References + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                        • + + + + + + + + + +
                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                        • + + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + +
                                                                                                                        + + + + + + + +
                                                                                                                          + +
                                                                                                                        • + + + Math Functions + + + +
                                                                                                                        • + +
                                                                                                                        • + + + Some Sample Equations + + + +
                                                                                                                        • + +
                                                                                                                        • + + + Sample Code + + + +
                                                                                                                        • + +
                                                                                                                        • + + + Adding a List of Patterns + + + +
                                                                                                                          +
                                                                                                                            + +
                                                                                                                          • + + + The Eval Function + + + +
                                                                                                                          • + +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                        • + +
                                                                                                                        • + + + The Command Design Pattern + + + +
                                                                                                                        • + +
                                                                                                                        • + + + Sample Screen Images + + + +
                                                                                                                          +
                                                                                                                            + +
                                                                                                                          • + + + X Modulo Y + + + +
                                                                                                                          • + +
                                                                                                                          • + + + (x % y) % 4 + + + +
                                                                                                                          • + +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                        • + +
                                                                                                                        • + + + Sierpinsky Triangles (x & y) + + + +
                                                                                                                        • + +
                                                                                                                        • + + + (x * y) & 24 + + + +
                                                                                                                        • + +
                                                                                                                        • + + + (x * y) & 64 + + + +
                                                                                                                        • + +
                                                                                                                        • + + + 40 % x % (y+1) + + + +
                                                                                                                        • + +
                                                                                                                        • + + + Reference + + + +
                                                                                                                        • + +
                                                                                                                        + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + +
                                                                                                                        +
                                                                                                                        + + + + + + + +

                                                                                                                        OLED Patterns

                                                                                                                        +

                                                                                                                        In this lesson, we will show how you can display interesting repeating patterns on your OLED screen. Our program will write a pattern into the framebuffer using a simple math equation. The oled.show() will then update the pattern on the display.

                                                                                                                        +

                                                                                                                        This lesson was suggested by Parker Erickson.

                                                                                                                        +

                                                                                                                        Math Functions

                                                                                                                        +

                                                                                                                        We will use a few unusual functions to create repeating patterns:

                                                                                                                        +
                                                                                                                          +
                                                                                                                        1. Modulo (%)
                                                                                                                        2. +
                                                                                                                        3. Bitwise AND (&)
                                                                                                                        4. +
                                                                                                                        +

                                                                                                                        The modulo function is written %. It returns the integer remainder after a division. So 7 % 3 is 1 and 7 % 4 is 3. +The Power function of X to the Y power is written in python as pow(x,y). For example pow(7, 2) is seven squared = 49.

                                                                                                                        +

                                                                                                                        The bitwise and is written as x & y

                                                                                                                        +
                                                                                                                        1
                                                                                                                        +2
                                                                                                                        for i in range(8):
                                                                                                                        +    13 & i
                                                                                                                        +
                                                                                                                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        FunctionReturns
                                                                                                                        13 & 00
                                                                                                                        13 & 11
                                                                                                                        13 & 20
                                                                                                                        13 & 31
                                                                                                                        13 & 44
                                                                                                                        13 & 55
                                                                                                                        13 & 64
                                                                                                                        13 & 75
                                                                                                                        13 & 88
                                                                                                                        13 & 99
                                                                                                                        13 & 108
                                                                                                                        13 & 119
                                                                                                                        13 & 1212
                                                                                                                        +

                                                                                                                        Some Sample Equations

                                                                                                                        +
                                                                                                                          +
                                                                                                                        1. x & y
                                                                                                                        2. +
                                                                                                                        3. x % y
                                                                                                                        4. +
                                                                                                                        5. (x ^ y) % 9
                                                                                                                        6. +
                                                                                                                        7. (x ^ y) % 5
                                                                                                                        8. +
                                                                                                                        9. (x ^ y) % 17
                                                                                                                        10. +
                                                                                                                        11. (x ^ y) % 33
                                                                                                                        12. +
                                                                                                                        13. (x * y) & 64
                                                                                                                        14. +
                                                                                                                        15. (x * y) & 24
                                                                                                                        16. +
                                                                                                                        17. (x * y) & 47
                                                                                                                        18. +
                                                                                                                        19. (x * 2) % y
                                                                                                                        20. +
                                                                                                                        21. (x * 64) % y
                                                                                                                        22. +
                                                                                                                        23. (x * 31) % y
                                                                                                                        24. +
                                                                                                                        25. ((x-128) * 64) % (y-128)
                                                                                                                        26. +
                                                                                                                        27. (x % y) % 4
                                                                                                                        28. +
                                                                                                                        29. (y % x) % 20
                                                                                                                        30. +
                                                                                                                        31. 40 % (x % y)
                                                                                                                        32. +
                                                                                                                        +

                                                                                                                        Note there are other patterns that use the power pow(x,y) or Exponentiation ** function but I can't get these to work with Micropython.

                                                                                                                        +

                                                                                                                        Sample Code

                                                                                                                        +

                                                                                                                        This program evaluates the function x % (y+1) for each of the pixels on the screen. If the function returns a non-zero the pixel will be off. If the pixel is zero, the pixel will be on.

                                                                                                                        +

                                                                                                                        draw-patterns-ssd1306-spi.py +

                                                                                                                         1
                                                                                                                        + 2
                                                                                                                        + 3
                                                                                                                        + 4
                                                                                                                        + 5
                                                                                                                        + 6
                                                                                                                        + 7
                                                                                                                        + 8
                                                                                                                        + 9
                                                                                                                        +10
                                                                                                                        +11
                                                                                                                        +12
                                                                                                                        +13
                                                                                                                        +14
                                                                                                                        +15
                                                                                                                        +16
                                                                                                                        +17
                                                                                                                        +18
                                                                                                                        +19
                                                                                                                        +20
                                                                                                                        +21
                                                                                                                        import machine
                                                                                                                        +import ssd1306
                                                                                                                        +
                                                                                                                        +WIDTH = 128
                                                                                                                        +HEIGHT = 64
                                                                                                                        +spi_sck=machine.Pin(2)
                                                                                                                        +spi_tx=machine.Pin(3)
                                                                                                                        +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                                        +CS = machine.Pin(1)
                                                                                                                        +DC = machine.Pin(4)
                                                                                                                        +RES = machine.Pin(5)
                                                                                                                        +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                        +
                                                                                                                        +oled.fill(0) # clear display
                                                                                                                        +for x in range(WIDTH):
                                                                                                                        +    for y in range(HEIGHT):
                                                                                                                        +        if x % (y+1):
                                                                                                                        +           oled.pixel(x,y,0)
                                                                                                                        +        else:
                                                                                                                        +            oled.pixel(x,y,1)
                                                                                                                        +oled.show()
                                                                                                                        +

                                                                                                                        +

                                                                                                                        Adding a List of Patterns

                                                                                                                        +

                                                                                                                        The Eval Function

                                                                                                                        +

                                                                                                                        The eval() function takes any string and passes it to the python interpreter for evaluation within the current context of variables that are in scope. We can use eval to pass an expression that should be evaluated to any function.

                                                                                                                        +
                                                                                                                        1
                                                                                                                        +2
                                                                                                                        +3
                                                                                                                        +4
                                                                                                                        +5
                                                                                                                        +6
                                                                                                                        +7
                                                                                                                        +8
                                                                                                                        list = ["x+y", "x-y", "x*y", "x % (y+1)"]
                                                                                                                        +
                                                                                                                        +for i in range(0, 4):
                                                                                                                        +    print(list[i], ': ', sep='', end='')
                                                                                                                        +    for x in range(5):
                                                                                                                        +      for y in range(5):
                                                                                                                        +         print(eval(list[i]), '', end='')
                                                                                                                        +    print('')
                                                                                                                        +
                                                                                                                        +

                                                                                                                        Output:

                                                                                                                        +
                                                                                                                        1
                                                                                                                        +2
                                                                                                                        +3
                                                                                                                        +4
                                                                                                                        x+y: 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 
                                                                                                                        +x-y: 0 -1 -2 -3 -4 1 0 -1 -2 -3 2 1 0 -1 -2 3 2 1 0 -1 4 3 2 1 0 
                                                                                                                        +x*y: 0 0 0 0 0 0 1 2 3 4 0 2 4 6 8 0 3 6 9 12 0 4 8 12 16 
                                                                                                                        +x % (y+1): 0 0 0 0 0 0 1 1 1 1 0 0 2 2 2 0 1 0 3 3 0 0 1 0 4 
                                                                                                                        +
                                                                                                                        +

                                                                                                                        The Command Design Pattern

                                                                                                                        +

                                                                                                                        The command pattern holds a list of commands in an array. Each command is executed in the sequence it appears in the list of commands.

                                                                                                                        +

                                                                                                                        In the following program we have the equations in a list. The program steps through each item in the list and displays that equation on the OLED display.

                                                                                                                        +
                                                                                                                         1
                                                                                                                        + 2
                                                                                                                        + 3
                                                                                                                        + 4
                                                                                                                        + 5
                                                                                                                        + 6
                                                                                                                        + 7
                                                                                                                        + 8
                                                                                                                        + 9
                                                                                                                        +10
                                                                                                                        +11
                                                                                                                        +12
                                                                                                                        +13
                                                                                                                        +14
                                                                                                                        +15
                                                                                                                        +16
                                                                                                                        +17
                                                                                                                        +18
                                                                                                                        +19
                                                                                                                        +20
                                                                                                                        +21
                                                                                                                        +22
                                                                                                                        +23
                                                                                                                        +24
                                                                                                                        +25
                                                                                                                        +26
                                                                                                                        +27
                                                                                                                        +28
                                                                                                                        +29
                                                                                                                        +30
                                                                                                                        +31
                                                                                                                        +32
                                                                                                                        +33
                                                                                                                        +34
                                                                                                                        +35
                                                                                                                        +36
                                                                                                                        +37
                                                                                                                        +38
                                                                                                                        +39
                                                                                                                        +40
                                                                                                                        import machine
                                                                                                                        +import ssd1306
                                                                                                                        +from utime import sleep, time
                                                                                                                        +
                                                                                                                        +WIDTH = 128
                                                                                                                        +HEIGHT = 64
                                                                                                                        +spi_sck=machine.Pin(2)
                                                                                                                        +spi_tx=machine.Pin(3)
                                                                                                                        +spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
                                                                                                                        +CS = machine.Pin(1)
                                                                                                                        +DC = machine.Pin(4)
                                                                                                                        +RES = machine.Pin(5)
                                                                                                                        +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                        +
                                                                                                                        +equations = ['(x * y) & 24', '(x * y) & 47', '(x * y) & 64', 'x & y', 'x % y', '(x % y) % 4', '40 % (x % y+1)']
                                                                                                                        +
                                                                                                                        +for eqn in range(0, len(equations)):
                                                                                                                        +    start = time()
                                                                                                                        +
                                                                                                                        +    oled.fill(0) # clear display
                                                                                                                        +    oled.text('calculating', 0, 0, 1)
                                                                                                                        +    oled.text(equations[eqn], 0, 10, 1)
                                                                                                                        +    oled.show()
                                                                                                                        +    for x in range(WIDTH):
                                                                                                                        +        for y in range(1, HEIGHT):
                                                                                                                        +            if eval(equations[eqn]):
                                                                                                                        +               oled.pixel(x,y,0)
                                                                                                                        +            else:
                                                                                                                        +                oled.pixel(x,y,1)
                                                                                                                        +    oled.show()
                                                                                                                        +    sleep(5)
                                                                                                                        +
                                                                                                                        +    end = time()
                                                                                                                        +    duration = str(end - start)
                                                                                                                        +    print(equations[eqn])
                                                                                                                        +    print(duration, ' seconds')
                                                                                                                        +
                                                                                                                        +oled.text('done', 0, 0, 1)
                                                                                                                        +oled.show()
                                                                                                                        +print('done')
                                                                                                                        +
                                                                                                                        +

                                                                                                                        Sample Screen Images

                                                                                                                        +

                                                                                                                        X Modulo Y

                                                                                                                        +

                                                                                                                        x % y +

                                                                                                                        +

                                                                                                                        (x % y) % 4

                                                                                                                        +

                                                                                                                        +

                                                                                                                        Sierpinsky Triangles (x & y)

                                                                                                                        +

                                                                                                                        Sierpinsky Triangles +Bitwise and of x and y +

                                                                                                                        +

                                                                                                                        (x * y) & 24

                                                                                                                        +

                                                                                                                        +

                                                                                                                        (x * y) & 64

                                                                                                                        +

                                                                                                                        +

                                                                                                                        40 % x % (y+1)

                                                                                                                        +

                                                                                                                        +

                                                                                                                        Reference

                                                                                                                        +

                                                                                                                        Martin Kleppe Post on Twitter

                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                        +
                                                                                                                        + + + +
                                                                                                                        + + + +
                                                                                                                        + +
                                                                                                                        + + + +
                                                                                                                        + + + +
                                                                                                                        + + +
                                                                                                                        +
                                                                                                                        + + Previous + +
                                                                                                                        + OLED Pixel Draw +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + + +
                                                                                                                        + + Next + +
                                                                                                                        + Random Hearts +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                        + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                        + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/16-tft-ili9341/index.html b/displays/graph/16-tft-ili9341/index.html new file mode 100644 index 000000000..8dbc7669b --- /dev/null +++ b/displays/graph/16-tft-ili9341/index.html @@ -0,0 +1,2509 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + TFT ILI9341 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                        + + + + Skip to content + + +
                                                                                                                        +
                                                                                                                        + +
                                                                                                                        + + + + + + +
                                                                                                                        +
                                                                                                                        + + + logo + + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + MicroPython for Kids + +
                                                                                                                        +
                                                                                                                        + + + TFT ILI9341 + + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + + + + + + + +
                                                                                                                        + +
                                                                                                                        +
                                                                                                                        + + +
                                                                                                                        + + +
                                                                                                                        + +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        +
                                                                                                                        + Initializing search +
                                                                                                                        +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + +
                                                                                                                          + +
                                                                                                                          + + +
                                                                                                                          +
                                                                                                                          + GitHub Repo +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                          + +
                                                                                                                          + +
                                                                                                                          + + + + + + +
                                                                                                                          +
                                                                                                                          + + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + + +
                                                                                                                          + + +
                                                                                                                          + +
                                                                                                                          + + +
                                                                                                                          +
                                                                                                                          + GitHub Repo +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                            + + + + + + + +
                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + +
                                                                                                                            + +
                                                                                                                              + + + + + + + +
                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Wiring Harness + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Graphic LCD + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Basic Drawing + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Custom Drawing Functions + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Color LCD ST7789V + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Timing Draw Speed + + + + +
                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + TFT ILI9341 + + + + + + + +
                                                                                                                              + + + + + + + +
                                                                                                                                + +
                                                                                                                              • + + + Sample SPI Hello World Example + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Draw Random Rectangles + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Draw Color Lists + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Screen Update Speed + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Ball Bounce Animation + + + +
                                                                                                                              • + +
                                                                                                                              • + + + References + + + +
                                                                                                                              • + +
                                                                                                                              + +
                                                                                                                              + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + LCD Waveshare + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + E-Paper + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Setup + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED SSD 1352 + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Bounce + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Pot + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Ping + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Pong + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Pixel Draw + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED Patterns + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + Random Hearts + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + NeoPixel Matrix + + + + +
                                                                                                                            • + + + + + + + + + + +
                                                                                                                            • + + + + + OLED References + + + + +
                                                                                                                            • + + + + +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + References + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                          • + + + + + + + + + +
                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                          • + + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + +
                                                                                                                          + + + + + + + +
                                                                                                                            + +
                                                                                                                          • + + + Sample SPI Hello World Example + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Draw Random Rectangles + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Draw Color Lists + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Screen Update Speed + + + +
                                                                                                                          • + +
                                                                                                                          • + + + Ball Bounce Animation + + + +
                                                                                                                          • + +
                                                                                                                          • + + + References + + + +
                                                                                                                          • + +
                                                                                                                          + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + +
                                                                                                                          +
                                                                                                                          + + + + + + + +

                                                                                                                          LI9341 TDF Display

                                                                                                                          +

                                                                                                                          ILI 9341 Display Demo

                                                                                                                          +

                                                                                                                          This is a 3.2" $10 240X320 color display that is easy to set up on the Raspberry Pi Pico using the SPI interface. The hardware supports a touch screen and an SD card, but we could not locate drivers for these components.

                                                                                                                          +

                                                                                                                          Sample $10 part on Amazon or ebay

                                                                                                                          +

                                                                                                                          ILI 9341 Display Demo

                                                                                                                          +

                                                                                                                          The TFT uses a 16-bit representation of the color of each pixel:

                                                                                                                          +
                                                                                                                            +
                                                                                                                          1. 5-bits for red
                                                                                                                          2. +
                                                                                                                          3. 6-bits for green
                                                                                                                          4. +
                                                                                                                          5. 5-bits for blue
                                                                                                                          6. +
                                                                                                                          +

                                                                                                                          This requires us to include the color565 library for doing color operations. So for example, to get the color yellow, you would need to do the following:

                                                                                                                          +
                                                                                                                          1
                                                                                                                          yellow = color565(255, 255, 0)
                                                                                                                          +
                                                                                                                          +

                                                                                                                          Sample SPI Hello World Example

                                                                                                                          +
                                                                                                                           1
                                                                                                                          + 2
                                                                                                                          + 3
                                                                                                                          + 4
                                                                                                                          + 5
                                                                                                                          + 6
                                                                                                                          + 7
                                                                                                                          + 8
                                                                                                                          + 9
                                                                                                                          +10
                                                                                                                          +11
                                                                                                                          +12
                                                                                                                          +13
                                                                                                                          +14
                                                                                                                          +15
                                                                                                                          +16
                                                                                                                          +17
                                                                                                                          +18
                                                                                                                          +19
                                                                                                                          +20
                                                                                                                          +21
                                                                                                                          # print out "Hello World!" using the rotation=3 using 32-bit high font
                                                                                                                          +# the default is white text on a black background
                                                                                                                          +from ili934x import ILI9341
                                                                                                                          +from machine import Pin, SPI
                                                                                                                          +import tt32
                                                                                                                          +
                                                                                                                          +# Use these PIN definitions.  SCK must be on 2 and data (SDL) on 3
                                                                                                                          +SCK_PIN = 2
                                                                                                                          +MISO_PIN = 3 # labeled SDI(MOSI) on the back of the display
                                                                                                                          +DC_PIN = 4
                                                                                                                          +RESET_PIN = 5
                                                                                                                          +CS_PIN = 6
                                                                                                                          +
                                                                                                                          +# mosi=Pin(23)
                                                                                                                          +# miso=Pin(MISO_PIN)
                                                                                                                          +spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))
                                                                                                                          +display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RESET_PIN), w=320, h=240, r=3)
                                                                                                                          +display.erase()
                                                                                                                          +display.set_font(tt32)
                                                                                                                          +display.set_pos(0,0)
                                                                                                                          +display.print('Hello World!')
                                                                                                                          +
                                                                                                                          +

                                                                                                                          Draw Random Rectangles

                                                                                                                          +
                                                                                                                           1
                                                                                                                          + 2
                                                                                                                          + 3
                                                                                                                          + 4
                                                                                                                          + 5
                                                                                                                          + 6
                                                                                                                          + 7
                                                                                                                          + 8
                                                                                                                          + 9
                                                                                                                          +10
                                                                                                                          +11
                                                                                                                          +12
                                                                                                                          +13
                                                                                                                          +14
                                                                                                                          +15
                                                                                                                          +16
                                                                                                                          +17
                                                                                                                          +18
                                                                                                                          +19
                                                                                                                          +20
                                                                                                                          +21
                                                                                                                          +22
                                                                                                                          +23
                                                                                                                          +24
                                                                                                                          +25
                                                                                                                          +26
                                                                                                                          +27
                                                                                                                          +28
                                                                                                                          +29
                                                                                                                          +30
                                                                                                                          +31
                                                                                                                          +32
                                                                                                                          +33
                                                                                                                          +34
                                                                                                                          +35
                                                                                                                          +36
                                                                                                                          +37
                                                                                                                          +38
                                                                                                                          +39
                                                                                                                          +40
                                                                                                                          +41
                                                                                                                          +42
                                                                                                                          +43
                                                                                                                          +44
                                                                                                                          +45
                                                                                                                          +46
                                                                                                                          +47
                                                                                                                          +48
                                                                                                                          +49
                                                                                                                          +50
                                                                                                                          +51
                                                                                                                          +52
                                                                                                                          +53
                                                                                                                          +54
                                                                                                                          +55
                                                                                                                          +56
                                                                                                                          +57
                                                                                                                          +58
                                                                                                                          +59
                                                                                                                          +60
                                                                                                                          +61
                                                                                                                          +62
                                                                                                                          from ili934x import ILI9341, color565
                                                                                                                          +from machine import Pin, SPI
                                                                                                                          +from utime import sleep
                                                                                                                          +from random import randint
                                                                                                                          +
                                                                                                                          +WIDTH = 320
                                                                                                                          +HALF_WIDTH = int(WIDTH/2)
                                                                                                                          +HEIGHT = 240
                                                                                                                          +HALF_HEIGHT = int(HEIGHT/2)
                                                                                                                          +ROTATION = 3 # landscape with 0,0 in upper left and pins on left
                                                                                                                          +
                                                                                                                          +SCK_PIN = 2
                                                                                                                          +MISO_PIN = 3
                                                                                                                          +DC_PIN = 4
                                                                                                                          +RST_PIN = 5
                                                                                                                          +CS_PIN = 6
                                                                                                                          +
                                                                                                                          +# mosi=Pin(23)
                                                                                                                          +# miso=Pin(MISO_PIN)
                                                                                                                          +spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN), sck=Pin(SCK_PIN))
                                                                                                                          +display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)
                                                                                                                          +display.erase()
                                                                                                                          +
                                                                                                                          +# color defintions converted to 565 represnetations
                                                                                                                          +black = color565(0, 0, 0)
                                                                                                                          +white = color565(255, 255, 255)
                                                                                                                          +red = color565(255, 0, 0)
                                                                                                                          +green = color565(0, 255, 0)
                                                                                                                          +blue = color565(0, 0, 255)
                                                                                                                          +yellow = color565(255, 255, 0)
                                                                                                                          +cyan = color565(0, 255, 255)
                                                                                                                          +magenta = color565(255, 0, 255)
                                                                                                                          +gray = color565(128, 128, 128)
                                                                                                                          +light_gray = color565(192, 192, 192)
                                                                                                                          +dark_gray = color565(64, 64, 64)
                                                                                                                          +brown = color565(165, 42, 42)
                                                                                                                          +orange = color565(255, 60, 0)
                                                                                                                          +# 150 for the green and blue wash out the colors
                                                                                                                          +pink = color565(255, 130, 130)
                                                                                                                          +purple = color565(128, 0, 128)
                                                                                                                          +lavender = color565(150, 150, 200)
                                                                                                                          +beige = color565(200, 200, 150)
                                                                                                                          +# by definition, maroon is 50% of the red on, but 128 is way too bright
                                                                                                                          +maroon = color565(105, 0, 0)
                                                                                                                          +olive = color565(128, 128, 0)
                                                                                                                          +turquoise = color565(64, 224, 208)
                                                                                                                          +dark_green = color565(0,100,0)
                                                                                                                          +color_list = [white, red, green, blue, yellow, cyan, magenta,
                                                                                                                          +              gray, light_gray, dark_gray, brown, orange, pink, purple, lavender,
                                                                                                                          +              beige, maroon, olive, turquoise, dark_green, black]
                                                                                                                          +color_num = len(color_list)
                                                                                                                          +
                                                                                                                          +# Draw forever
                                                                                                                          +while True:
                                                                                                                          +    # rect_fill(x, y, width, height, color)
                                                                                                                          +    x = randint(0, HALF_WIDTH)
                                                                                                                          +    y = randint(0, HALF_HEIGHT)
                                                                                                                          +    width = randint(0, HALF_WIDTH)
                                                                                                                          +    height = randint(0, HALF_HEIGHT)
                                                                                                                          +    color = color_list[randint(0, color_num-1)]
                                                                                                                          +    print('fill_rectangle(', x, y, width, height, color)
                                                                                                                          +    display.fill_rectangle(x, y, width, height, color)
                                                                                                                          +
                                                                                                                          +

                                                                                                                          Draw Color Lists

                                                                                                                          +

                                                                                                                          One of the best ways to study the color values is to display a rectangle +and list the color name and values under the rectangle.

                                                                                                                          +

                                                                                                                          Here is a sample program that will do this.

                                                                                                                          +
                                                                                                                           1
                                                                                                                          + 2
                                                                                                                          + 3
                                                                                                                          + 4
                                                                                                                          + 5
                                                                                                                          + 6
                                                                                                                          + 7
                                                                                                                          + 8
                                                                                                                          + 9
                                                                                                                          +10
                                                                                                                          +11
                                                                                                                          +12
                                                                                                                          +13
                                                                                                                          +14
                                                                                                                          +15
                                                                                                                          +16
                                                                                                                          +17
                                                                                                                          +18
                                                                                                                          +19
                                                                                                                          +20
                                                                                                                          +21
                                                                                                                          +22
                                                                                                                          +23
                                                                                                                          +24
                                                                                                                          +25
                                                                                                                          +26
                                                                                                                          +27
                                                                                                                          +28
                                                                                                                          +29
                                                                                                                          +30
                                                                                                                          +31
                                                                                                                          +32
                                                                                                                          +33
                                                                                                                          +34
                                                                                                                          +35
                                                                                                                          +36
                                                                                                                          +37
                                                                                                                          +38
                                                                                                                          +39
                                                                                                                          +40
                                                                                                                          +41
                                                                                                                          +42
                                                                                                                          +43
                                                                                                                          +44
                                                                                                                          +45
                                                                                                                          +46
                                                                                                                          +47
                                                                                                                          +48
                                                                                                                          +49
                                                                                                                          +50
                                                                                                                          +51
                                                                                                                          +52
                                                                                                                          +53
                                                                                                                          +54
                                                                                                                          +55
                                                                                                                          +56
                                                                                                                          +57
                                                                                                                          +58
                                                                                                                          +59
                                                                                                                          +60
                                                                                                                          +61
                                                                                                                          +62
                                                                                                                          +63
                                                                                                                          +64
                                                                                                                          +65
                                                                                                                          +66
                                                                                                                          +67
                                                                                                                          +68
                                                                                                                          +69
                                                                                                                          +70
                                                                                                                          +71
                                                                                                                          from ili934x import ILI9341, color565
                                                                                                                          +from machine import Pin, SPI
                                                                                                                          +from utime import sleep
                                                                                                                          +from random import randint
                                                                                                                          +import tt32
                                                                                                                          +
                                                                                                                          +WIDTH = 320
                                                                                                                          +HALF_WIDTH = int(WIDTH/2)
                                                                                                                          +HEIGHT = 240
                                                                                                                          +HALF_HEIGHT = int(HEIGHT/2)
                                                                                                                          +ROTATION = 3 # landscape with 0,0 in upper left and pins on left
                                                                                                                          +SCK_PIN = 2
                                                                                                                          +MISO_PIN = 3
                                                                                                                          +DC_PIN = 4
                                                                                                                          +RST_PIN = 5
                                                                                                                          +CS_PIN = 6
                                                                                                                          +
                                                                                                                          +# mosi=Pin(23)
                                                                                                                          +# miso=Pin(MISO_PIN)
                                                                                                                          +spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))
                                                                                                                          +display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)
                                                                                                                          +display.set_font(tt32)
                                                                                                                          +display.erase()
                                                                                                                          +
                                                                                                                          +# color defintions convered to 565 represnetations
                                                                                                                          +black = color565(0, 0, 0)
                                                                                                                          +white = color565(255, 255, 255)
                                                                                                                          +red = color565(255, 0, 0)
                                                                                                                          +green = color565(0, 255, 0)
                                                                                                                          +blue = color565(0, 0, 255)
                                                                                                                          +yellow = color565(255, 255, 0)
                                                                                                                          +cyan = color565(0, 255, 255)
                                                                                                                          +magenta = color565(255, 0, 255)
                                                                                                                          +gray = color565(128, 128, 128)
                                                                                                                          +light_gray = color565(192, 192, 192)
                                                                                                                          +dark_gray = color565(64, 64, 64)
                                                                                                                          +brown = color565(165, 42, 42)
                                                                                                                          +orange = color565(255, 60, 0)
                                                                                                                          +# 150 for the green and blue wash out the colors
                                                                                                                          +pink = color565(255, 130, 130)
                                                                                                                          +purple = color565(128, 0, 128)
                                                                                                                          +lavender = color565(150, 150, 200)
                                                                                                                          +beige = color565(200, 200, 150)
                                                                                                                          +# by definition, maroon is 50% of the red on, but 128 is way too bright
                                                                                                                          +maroon = color565(105, 0, 0)
                                                                                                                          +olive = color565(128, 128, 0)
                                                                                                                          +turquoise = color565(64, 224, 208)
                                                                                                                          +dark_green = color565(0,100,0)
                                                                                                                          +color_list = [white, red, green, blue, yellow, cyan, magenta,
                                                                                                                          +              gray, light_gray, dark_gray, brown, orange, pink, purple, lavender,
                                                                                                                          +              beige, maroon, olive, turquoise, dark_green, black]
                                                                                                                          +color_names = ['white (255,255,255)', 'red (255,0,0)', 'green (0,255,0)', 'blue (0,0,255)', 'yellow (255,255,0)',
                                                                                                                          +               'cyan (0,255,255)', 'magenta (255,0,255)',
                                                                                                                          +              'gray (128,128,128)', 'light gray (192,192,192)', 'dark gray (64,64,64)',
                                                                                                                          +               'brown (165,42,42)', 'orange (255,60,0)', 'pink (255,130,130)', 'purple (128,0,128)',
                                                                                                                          +               'lavender (150,150,200)',
                                                                                                                          +              'beige (200,200,150)', 'maroon (105,0,0)', 'olive (128,128,0)', 'turquoise (64,224,208)',
                                                                                                                          +               'dark green (0,100,0)', 'black (0,0,0)']
                                                                                                                          +color_num = len(color_list)
                                                                                                                          +
                                                                                                                          +display.fill_rectangle(0, 0, WIDTH, HEIGHT, black)
                                                                                                                          +while True:
                                                                                                                          +    for i in range(0, color_num):
                                                                                                                          +        display.fill_rectangle(0, 0, WIDTH, HEIGHT-33, color_list[i])
                                                                                                                          +        # black behind the white text
                                                                                                                          +        display.fill_rectangle(0, HEIGHT-32, WIDTH, 32, black)
                                                                                                                          +
                                                                                                                          +        display.set_pos(0,HEIGHT-32)
                                                                                                                          +        display.print(color_names[i])
                                                                                                                          +        print(color_names[i])
                                                                                                                          +        sleep(1)
                                                                                                                          +
                                                                                                                          +

                                                                                                                          Screen Update Speed

                                                                                                                          +

                                                                                                                          One large disadvantage of this display is the very slow refresh rate. Transmitting the entire screen of 240X320 with two bytes per pixel takes +a long time over SPI. This makes this setup difficult to use for animation.

                                                                                                                          +

                                                                                                                          Ball Bounce Animation

                                                                                                                          +

                                                                                                                          Here is a very slow "ball bounce" animation that is slow and has a lot of flicker.

                                                                                                                          +
                                                                                                                           1
                                                                                                                          + 2
                                                                                                                          + 3
                                                                                                                          + 4
                                                                                                                          + 5
                                                                                                                          + 6
                                                                                                                          + 7
                                                                                                                          + 8
                                                                                                                          + 9
                                                                                                                          +10
                                                                                                                          +11
                                                                                                                          +12
                                                                                                                          +13
                                                                                                                          +14
                                                                                                                          +15
                                                                                                                          +16
                                                                                                                          +17
                                                                                                                          +18
                                                                                                                          +19
                                                                                                                          +20
                                                                                                                          +21
                                                                                                                          +22
                                                                                                                          +23
                                                                                                                          +24
                                                                                                                          +25
                                                                                                                          +26
                                                                                                                          +27
                                                                                                                          +28
                                                                                                                          +29
                                                                                                                          +30
                                                                                                                          +31
                                                                                                                          +32
                                                                                                                          +33
                                                                                                                          +34
                                                                                                                          +35
                                                                                                                          +36
                                                                                                                          +37
                                                                                                                          +38
                                                                                                                          +39
                                                                                                                          +40
                                                                                                                          +41
                                                                                                                          +42
                                                                                                                          +43
                                                                                                                          +44
                                                                                                                          +45
                                                                                                                          +46
                                                                                                                          +47
                                                                                                                          +48
                                                                                                                          +49
                                                                                                                          +50
                                                                                                                          +51
                                                                                                                          +52
                                                                                                                          +53
                                                                                                                          +54
                                                                                                                          +55
                                                                                                                          +56
                                                                                                                          +57
                                                                                                                          +58
                                                                                                                          +59
                                                                                                                          +60
                                                                                                                          +61
                                                                                                                          +62
                                                                                                                          +63
                                                                                                                          from ili934x import ILI9341, color565
                                                                                                                          +from machine import Pin, SPI
                                                                                                                          +from utime import sleep
                                                                                                                          +
                                                                                                                          +WIDTH = 320
                                                                                                                          +HEIGHT = 240
                                                                                                                          +ROTATION = 3 # landscape with 0,0 in upper left and pins on left
                                                                                                                          +SCK_PIN = 2
                                                                                                                          +MISO_PIN = 3
                                                                                                                          +DC_PIN = 4
                                                                                                                          +RST_PIN = 5
                                                                                                                          +CS_PIN = 6
                                                                                                                          +
                                                                                                                          +# mosi=Pin(23)
                                                                                                                          +# miso=Pin(MISO_PIN)
                                                                                                                          +spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))
                                                                                                                          +display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)
                                                                                                                          +display.erase()
                                                                                                                          +
                                                                                                                          +# color defintions convered to 565 represnetations
                                                                                                                          +black = color565(0, 0, 0)
                                                                                                                          +white = color565(255, 255, 255)
                                                                                                                          +red = color565(255, 0, 0)
                                                                                                                          +green = color565(0, 255, 0)
                                                                                                                          +blue = color565(0, 0, 255)
                                                                                                                          +
                                                                                                                          +# ok, not really a circle - just a square for now
                                                                                                                          +def draw_ball(x,y, size, color):
                                                                                                                          +    if size == 1:
                                                                                                                          +        display.pixel(x, y, color) # draw a single pixel
                                                                                                                          +    else:
                                                                                                                          +        display.fill_rectangle(x, y, size, size, color)
                                                                                                                          +
                                                                                                                          +ball_size = 20
                                                                                                                          +# start in the middle of the screen
                                                                                                                          +current_x = int(WIDTH / 2)
                                                                                                                          +current_y = int(HEIGHT / 2)
                                                                                                                          +# start going down to the right
                                                                                                                          +direction_x = 1
                                                                                                                          +direction_y = -1
                                                                                                                          +# delay_time = .0001
                                                                                                                          +
                                                                                                                          +# Bounce forever
                                                                                                                          +while True:
                                                                                                                          +    # draw the square ball in white
                                                                                                                          +    draw_ball(current_x,current_y, ball_size, white)
                                                                                                                          +    sleep(.1)
                                                                                                                          +    # the erase the old ball takes too long and causes a flicker
                                                                                                                          +    draw_ball(current_x,current_y,ball_size, black)
                                                                                                                          +    if current_x < 0:
                                                                                                                          +        direction_x = 1
                                                                                                                          +    # right edge test
                                                                                                                          +    if current_x > WIDTH - ball_size -2:
                                                                                                                          +        direction_x = -1
                                                                                                                          +    # top edge test
                                                                                                                          +    if current_y < 0:
                                                                                                                          +        direction_y = 1
                                                                                                                          +    # bottom edge test
                                                                                                                          +    if current_y > HEIGHT - ball_size - 2:
                                                                                                                          +        direction_y = -1
                                                                                                                          +    # update the ball
                                                                                                                          +    current_x = current_x + direction_x
                                                                                                                          +    current_y = current_y + direction_y
                                                                                                                          +
                                                                                                                          +

                                                                                                                          References

                                                                                                                          +
                                                                                                                            +
                                                                                                                          1. +

                                                                                                                            Jeffmer's GitHub library which includes four fonts - the sizes are 8, 14, 24 and 32 pixels.

                                                                                                                            +
                                                                                                                          2. +
                                                                                                                          3. +

                                                                                                                            Amazon HiLetgo ILI9341 2.8" SPI TFT LCD Display Touch Panel 240X320 with PCB 5V/3.3V STM32

                                                                                                                            +
                                                                                                                          4. +
                                                                                                                          5. +

                                                                                                                            ebay Listing

                                                                                                                            +
                                                                                                                          6. +
                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                          +
                                                                                                                          + + + +
                                                                                                                          + + + +
                                                                                                                          + +
                                                                                                                          + + + +
                                                                                                                          + + + +
                                                                                                                          + + +
                                                                                                                          +
                                                                                                                          + + Previous + +
                                                                                                                          + Timing Draw Speed +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + + +
                                                                                                                          + + Next + +
                                                                                                                          + LCD Waveshare +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                          + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                          + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/17-ssd1352/index.html b/displays/graph/17-ssd1352/index.html new file mode 100644 index 000000000..353fdadd0 --- /dev/null +++ b/displays/graph/17-ssd1352/index.html @@ -0,0 +1,2154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED SSD 1352 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                          + + + + Skip to content + + +
                                                                                                                          +
                                                                                                                          + +
                                                                                                                          + + + + + + +
                                                                                                                          +
                                                                                                                          + + + logo + + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + MicroPython for Kids + +
                                                                                                                          +
                                                                                                                          + + + OLED SSD 1352 + + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + + + + + + + +
                                                                                                                          + +
                                                                                                                          +
                                                                                                                          + + +
                                                                                                                          + + +
                                                                                                                          + +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          +
                                                                                                                          + Initializing search +
                                                                                                                          +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + +
                                                                                                                            + +
                                                                                                                            + + +
                                                                                                                            +
                                                                                                                            + GitHub Repo +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                            + +
                                                                                                                            + +
                                                                                                                            + + + + + + +
                                                                                                                            +
                                                                                                                            + + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + + +
                                                                                                                            + + +
                                                                                                                            + +
                                                                                                                            + + +
                                                                                                                            +
                                                                                                                            + GitHub Repo +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                              + + + + + + + +
                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + +
                                                                                                                              + +
                                                                                                                                + + + + + + + +
                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Wiring Harness + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Graphic LCD + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Basic Drawing + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Custom Drawing Functions + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Color LCD ST7789V + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Timing Draw Speed + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + TFT ILI9341 + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + LCD Waveshare + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + E-Paper + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Setup + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + OLED SSD 1352 + + + + + + + +
                                                                                                                                + + + + + + + +
                                                                                                                                  + +
                                                                                                                                • + + + Drawing Shapes + + + +
                                                                                                                                • + +
                                                                                                                                • + + + SSD1351 MicroPython Driver + + + +
                                                                                                                                • + +
                                                                                                                                • + + + SSD1351 Datasheet + + + +
                                                                                                                                • + +
                                                                                                                                + +
                                                                                                                                + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Bounce + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Pot + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Ping + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Pong + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Pixel Draw + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED Patterns + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + Random Hearts + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + NeoPixel Matrix + + + + +
                                                                                                                              • + + + + + + + + + + +
                                                                                                                              • + + + + + OLED References + + + + +
                                                                                                                              • + + + + +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + References + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                            • + + + + + + + + + +
                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                            • + + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + +
                                                                                                                            + + + + + + + +
                                                                                                                              + +
                                                                                                                            • + + + Drawing Shapes + + + +
                                                                                                                            • + +
                                                                                                                            • + + + SSD1351 MicroPython Driver + + + +
                                                                                                                            • + +
                                                                                                                            • + + + SSD1351 Datasheet + + + +
                                                                                                                            • + +
                                                                                                                            + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + +
                                                                                                                            +
                                                                                                                            + + + + + + + +

                                                                                                                            OLED SSD1351 MicroPython Driver

                                                                                                                            +

                                                                                                                            The SSD1351 is a $40 color OLED measures 1.5" diagonal and contains 128x128 RGB pixels. It supports a SPI interface.

                                                                                                                            +

                                                                                                                            Drawing Shapes

                                                                                                                            +

                                                                                                                            This demo shows how to draw shapes on the display. It starts out with simple lines and rectangles then progresses to more complex shapes such as circles and ellipses.

                                                                                                                            +
                                                                                                                             1
                                                                                                                            + 2
                                                                                                                            + 3
                                                                                                                            + 4
                                                                                                                            + 5
                                                                                                                            + 6
                                                                                                                            + 7
                                                                                                                            + 8
                                                                                                                            + 9
                                                                                                                            +10
                                                                                                                            +11
                                                                                                                            +12
                                                                                                                            +13
                                                                                                                            +14
                                                                                                                            +15
                                                                                                                            +16
                                                                                                                            +17
                                                                                                                            +18
                                                                                                                            +19
                                                                                                                            +20
                                                                                                                            +21
                                                                                                                            +22
                                                                                                                            +23
                                                                                                                            +24
                                                                                                                            +25
                                                                                                                            +26
                                                                                                                            +27
                                                                                                                            +28
                                                                                                                            +29
                                                                                                                            +30
                                                                                                                            +31
                                                                                                                            +32
                                                                                                                            +33
                                                                                                                            +34
                                                                                                                            +35
                                                                                                                            +36
                                                                                                                            +37
                                                                                                                            +38
                                                                                                                            +39
                                                                                                                            +40
                                                                                                                            +41
                                                                                                                            +42
                                                                                                                            +43
                                                                                                                            +44
                                                                                                                            +45
                                                                                                                            +46
                                                                                                                            +47
                                                                                                                            +48
                                                                                                                            +49
                                                                                                                            +50
                                                                                                                            +51
                                                                                                                            +52
                                                                                                                            +53
                                                                                                                            +54
                                                                                                                            +55
                                                                                                                            +56
                                                                                                                            +57
                                                                                                                            +58
                                                                                                                            +59
                                                                                                                            +60
                                                                                                                            +61
                                                                                                                            +62
                                                                                                                            +63
                                                                                                                            +64
                                                                                                                            +65
                                                                                                                            +66
                                                                                                                            +67
                                                                                                                            +68
                                                                                                                            +69
                                                                                                                            +70
                                                                                                                            +71
                                                                                                                            +72
                                                                                                                            +73
                                                                                                                            +74
                                                                                                                            +75
                                                                                                                            +76
                                                                                                                            +77
                                                                                                                            +78
                                                                                                                            +79
                                                                                                                            +80
                                                                                                                            """SSD1351 demo (shapes)."""
                                                                                                                            +from time import sleep
                                                                                                                            +from ssd1351 import Display, color565
                                                                                                                            +from machine import Pin, SPI
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +def test():
                                                                                                                            +    """Test code."""
                                                                                                                            +    # Baud rate of 14500000 seems about the max
                                                                                                                            +    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
                                                                                                                            +    print('spi started')
                                                                                                                            +    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
                                                                                                                            +    print('display started')
                                                                                                                            +
                                                                                                                            +    display.clear(color565(64, 0, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.clear()
                                                                                                                            +
                                                                                                                            +    display.draw_hline(10, 127, 63, color565(255, 0, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_vline(10, 0, 127, color565(0, 255, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_hline(0, 0, 127, color565(255, 0, 0))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_line(127, 0, 64, 127, color565(255, 255, 0))
                                                                                                                            +    sleep(2)
                                                                                                                            +
                                                                                                                            +    display.clear()
                                                                                                                            +
                                                                                                                            +    coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]]
                                                                                                                            +    display.draw_lines(coords, color565(0, 255, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.clear()
                                                                                                                            +    display.fill_polygon(7, 63, 63, 50, color565(0, 255, 0))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.fill_rectangle(0, 0, 15, 127, color565(255, 0, 0))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.clear()
                                                                                                                            +
                                                                                                                            +    display.fill_rectangle(0, 0, 63, 63, color565(128, 128, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_rectangle(0, 64, 63, 63, color565(255, 0, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.fill_rectangle(64, 0, 63, 63, color565(128, 0, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_polygon(3, 96, 96, 30, color565(0, 64, 255),
                                                                                                                            +                         rotate=15)
                                                                                                                            +    sleep(3)
                                                                                                                            +
                                                                                                                            +    display.clear()
                                                                                                                            +
                                                                                                                            +    display.fill_circle(32, 32, 30, color565(0, 255, 0))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_circle(32, 96, 30, color565(0, 0, 255))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.fill_ellipse(96, 32, 30, 16, color565(255, 0, 0))
                                                                                                                            +    sleep(1)
                                                                                                                            +
                                                                                                                            +    display.draw_ellipse(96, 96, 16, 30, color565(255, 255, 0))
                                                                                                                            +
                                                                                                                            +    sleep(5)
                                                                                                                            +    display.cleanup()
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +test()
                                                                                                                            +
                                                                                                                            +

                                                                                                                            SSD1351 MicroPython Driver

                                                                                                                            +

                                                                                                                            The driver is here +RDagger GitHub

                                                                                                                            +

                                                                                                                            SSD1351 MicroPython Driver on RDagger GitHub

                                                                                                                            +

                                                                                                                            SSD1351 Datasheet

                                                                                                                            +

                                                                                                                            Datasheet on NewHaven Displays

                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                            +
                                                                                                                            + + + +
                                                                                                                            + + + +
                                                                                                                            + +
                                                                                                                            + + + +
                                                                                                                            + + + +
                                                                                                                            + + +
                                                                                                                            +
                                                                                                                            + + Previous + +
                                                                                                                            + OLED SH1106 I2C Example +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + + +
                                                                                                                            + + Next + +
                                                                                                                            + OLED Bounce +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                            + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                            + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/18-neopixel-matrix/index.html b/displays/graph/18-neopixel-matrix/index.html new file mode 100644 index 000000000..5c808a06f --- /dev/null +++ b/displays/graph/18-neopixel-matrix/index.html @@ -0,0 +1,2527 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + NeoPixel Matrix - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                            + + + + Skip to content + + +
                                                                                                                            +
                                                                                                                            + +
                                                                                                                            + + + + + + +
                                                                                                                            +
                                                                                                                            + + + logo + + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + MicroPython for Kids + +
                                                                                                                            +
                                                                                                                            + + + NeoPixel Matrix + + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + + + + + + + +
                                                                                                                            + +
                                                                                                                            +
                                                                                                                            + + +
                                                                                                                            + + +
                                                                                                                            + +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            +
                                                                                                                            + Initializing search +
                                                                                                                            +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + +
                                                                                                                              + +
                                                                                                                              + + +
                                                                                                                              +
                                                                                                                              + GitHub Repo +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                              + +
                                                                                                                              + +
                                                                                                                              + + + + + + +
                                                                                                                              +
                                                                                                                              + + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + + +
                                                                                                                              + + +
                                                                                                                              + +
                                                                                                                              + + +
                                                                                                                              +
                                                                                                                              + GitHub Repo +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                                + + + + + + + +
                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + +
                                                                                                                                + +
                                                                                                                                  + + + + + + + +
                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Wiring Harness + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Graphic LCD + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Basic Drawing + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Custom Drawing Functions + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Color LCD ST7789V + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Timing Draw Speed + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + TFT ILI9341 + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + LCD Waveshare + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + E-Paper + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Setup + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED SSD 1352 + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Bounce + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Pot + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Ping + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Pong + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Pixel Draw + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED Patterns + + + + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + Random Hearts + + + + +
                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + NeoPixel Matrix + + + + + + + +
                                                                                                                                  + + + + + + + +
                                                                                                                                    + +
                                                                                                                                  • + + + Introduction + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Purchasing Hardware + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Basic Software Setup + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Testing Your Write Pixel Function + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Bounce a Ball + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Bitmap LIbrary + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + Full Code + + + +
                                                                                                                                  • + +
                                                                                                                                  • + + + References + + + +
                                                                                                                                  • + +
                                                                                                                                  + +
                                                                                                                                  + +
                                                                                                                                • + + + + + + + + + + +
                                                                                                                                • + + + + + OLED References + + + + +
                                                                                                                                • + + + + +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + References + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                              • + + + + + + + + + +
                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                              • + + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + +
                                                                                                                              + + + + + + + +
                                                                                                                                + +
                                                                                                                              • + + + Introduction + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Purchasing Hardware + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Basic Software Setup + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Testing Your Write Pixel Function + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Bounce a Ball + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Bitmap LIbrary + + + +
                                                                                                                              • + +
                                                                                                                              • + + + Full Code + + + +
                                                                                                                              • + +
                                                                                                                              • + + + References + + + +
                                                                                                                              • + +
                                                                                                                              + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + +
                                                                                                                              +
                                                                                                                              + + + + + + + +

                                                                                                                              NeoPixel Matrix Display

                                                                                                                              +

                                                                                                                              +

                                                                                                                              Introduction

                                                                                                                              +

                                                                                                                              This lesson uses MicroPython to control display that uses a 8X32 matrix of WS2812 RGB LEDs to display information. The entire display is controlled by three wires, a ground, +5V, and a serial data signal. We will use the MicroPython builtin NeoPixel library to control the display. You can use many of the programs in the NeoPixel Basics lesson to control the display. The key difference is that we will need to convert matrix coordinates to NeoPixel index numbers.

                                                                                                                              +

                                                                                                                              Purchasing Hardware

                                                                                                                              +

                                                                                                                              You can purchase a matrix of 8X32 WS2812 RGB LED on eBay for about $12 on eBay or about $100 on Adafruit. They are also available in 16X16 versions and the devices can be chained together to make larger displays. On our version tested here, we have a total of 8*32 = 256 pixels.

                                                                                                                              +

                                                                                                                              WS2811B 8X32 Matrix

                                                                                                                              +

                                                                                                                              Basic Software Setup

                                                                                                                              +

                                                                                                                              We must first create a function that will draw a pixel at a given x and y position. This is +complicated by the fact that the matrix is not a regular grid, but rather a grid that is connected +in a zig-zag serpentine pattern illustrated below.

                                                                                                                              +

                                                                                                                              Matrix Mapping Function

                                                                                                                              +

                                                                                                                              Note that the math for doing even and odd columns is different. The even columns are drawn from the top down and the odd columns are drawn from the bottom to the top which is the order the pixels are wired together in the matrix.

                                                                                                                              +

                                                                                                                              To use the functions that draw pixels, we must first create a function that will convert the x and y coordinates to a NeoPixel index. This is done by the following function. We will then pass this function into the library that will draw characters on the screen.

                                                                                                                              +
                                                                                                                               1
                                                                                                                              + 2
                                                                                                                              + 3
                                                                                                                              + 4
                                                                                                                              + 5
                                                                                                                              + 6
                                                                                                                              + 7
                                                                                                                              + 8
                                                                                                                              + 9
                                                                                                                              +10
                                                                                                                              +11
                                                                                                                              +12
                                                                                                                              +13
                                                                                                                              +14
                                                                                                                              +15
                                                                                                                              +16
                                                                                                                              +17
                                                                                                                              from machine import Pin
                                                                                                                              +from neopixel import NeoPixel
                                                                                                                              +
                                                                                                                              +NEOPIXEL_PIN = 0
                                                                                                                              +ROWS = 8
                                                                                                                              +COLS = 32
                                                                                                                              +NUMBER_PIXELS = ROWS * COLS
                                                                                                                              +# Allocate memory for the NeoPixel matrix
                                                                                                                              +matrix = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                                                                              +
                                                                                                                              +def write_pixel(x, y, value):
                                                                                                                              +    if y >= 0 and y < ROWS and x >=0 and x < COLS:
                                                                                                                              +        # odd count rows 1, 3, 5 the wire goes from bottup
                                                                                                                              +        if x % 2: 
                                                                                                                              +            strip[(x+1)*ROWS - y - 1] = value             
                                                                                                                              +        else: # even count rows, 0, 2, 4 the wire goes from the top down up
                                                                                                                              +            strip[x*ROWS + y] = value
                                                                                                                              +
                                                                                                                              +

                                                                                                                              Testing Your Write Pixel Function

                                                                                                                              +

                                                                                                                              We can then test the function by calling it at four corners with different colors.

                                                                                                                              +
                                                                                                                              1
                                                                                                                              +2
                                                                                                                              +3
                                                                                                                              +4
                                                                                                                              +5
                                                                                                                              # draw four colors at each corner of the matrix
                                                                                                                              +write_pixel(0, 0, (255, 0, 0)) # draw a red pixel at the top left corner
                                                                                                                              +write_pixel(7, 0, (0, 255, 0)) # draw a green pixel at the lower left corner
                                                                                                                              +write_pixel(0, 7, (0, 0, 255)) # draw a blue pixel at the top right corner
                                                                                                                              +write_pixel(7, 7, (255, 255, 255)) # draw a white pixel at the lower right corner
                                                                                                                              +
                                                                                                                              +

                                                                                                                              Bounce a Ball

                                                                                                                              +

                                                                                                                              To test the write_pixel() function, lets write a function that will draw a ball at a given x and y position. We will move the ball around the screen and reverse the direction when the ball hits the edge of the screen.

                                                                                                                              +
                                                                                                                               1
                                                                                                                              + 2
                                                                                                                              + 3
                                                                                                                              + 4
                                                                                                                              + 5
                                                                                                                              + 6
                                                                                                                              + 7
                                                                                                                              + 8
                                                                                                                              + 9
                                                                                                                              +10
                                                                                                                              +11
                                                                                                                              +12
                                                                                                                              +13
                                                                                                                              +14
                                                                                                                              +15
                                                                                                                              +16
                                                                                                                              +17
                                                                                                                              +18
                                                                                                                              +19
                                                                                                                              +20
                                                                                                                              +21
                                                                                                                              +22
                                                                                                                              +23
                                                                                                                              +24
                                                                                                                              +25
                                                                                                                              +26
                                                                                                                              +27
                                                                                                                              +28
                                                                                                                              +29
                                                                                                                              +30
                                                                                                                              +31
                                                                                                                              +32
                                                                                                                              +33
                                                                                                                              +34
                                                                                                                              +35
                                                                                                                              +36
                                                                                                                              +37
                                                                                                                              +38
                                                                                                                              +39
                                                                                                                              +40
                                                                                                                              +41
                                                                                                                              +42
                                                                                                                              +43
                                                                                                                              +44
                                                                                                                              +45
                                                                                                                              +46
                                                                                                                              +47
                                                                                                                              +48
                                                                                                                              +49
                                                                                                                              +50
                                                                                                                              +51
                                                                                                                              +52
                                                                                                                              +53
                                                                                                                              +54
                                                                                                                              +55
                                                                                                                              +56
                                                                                                                              +57
                                                                                                                              +58
                                                                                                                              # Bounce a ball around a NeoPixel Matrix
                                                                                                                              +from neopixel import NeoPixel
                                                                                                                              +from utime import sleep
                                                                                                                              +
                                                                                                                              +NEOPIXEL_PIN = 0
                                                                                                                              +ROWS = 8
                                                                                                                              +COLS = 32
                                                                                                                              +NUMBER_PIXELS = ROWS * COLS
                                                                                                                              +strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                                                                              +
                                                                                                                              +# matrix = [[0 for _ in range(cols)] for _ in range(rows)]
                                                                                                                              +def clear():
                                                                                                                              +    for i in range(0, NUMBER_PIXELS):
                                                                                                                              +        strip[i] = (0,0,0)
                                                                                                                              +    strip.write()
                                                                                                                              +
                                                                                                                              +def write_pixel(x, y, value):
                                                                                                                              +    if y >= 0 and y < ROWS and x >=0 and x < COLS:
                                                                                                                              +        # odd count rows 1, 3, 5 the wire goes from bottup
                                                                                                                              +        if x % 2: 
                                                                                                                              +            strip[(x+1)*ROWS - y - 1] = value             
                                                                                                                              +        else: # even count rows, 0, 2, 4 the wire goes from the top down up
                                                                                                                              +            strip[x*ROWS + y] = value
                                                                                                                              +
                                                                                                                              +def show():
                                                                                                                              +    strip.write()
                                                                                                                              +
                                                                                                                              +brightness=1
                                                                                                                              +x=0
                                                                                                                              +y=0
                                                                                                                              +dx = 1
                                                                                                                              +dy = 1
                                                                                                                              +counter = 0
                                                                                                                              +while True:
                                                                                                                              +    if x <= 0:
                                                                                                                              +        dx = 1
                                                                                                                              +    if y <= 0:
                                                                                                                              +        dy = 1
                                                                                                                              +    if x >= COLS-1:
                                                                                                                              +        dx = -1
                                                                                                                              +    if y >= ROWS-1:
                                                                                                                              +        dy = -1
                                                                                                                              +    print(x,y)
                                                                                                                              +    if counter < 100:
                                                                                                                              +        write_pixel(x, y, (brightness,0,0)) # blue
                                                                                                                              +    elif counter < 200:
                                                                                                                              +        write_pixel(x, y, (0,brightness,0)) # blue
                                                                                                                              +    elif counter < 300:
                                                                                                                              +        write_pixel(x, y, (0,0,brightness)) # blue
                                                                                                                              +    show()
                                                                                                                              +    x += dx
                                                                                                                              +    y += dy
                                                                                                                              +    counter += 1
                                                                                                                              +    if counter > 300:
                                                                                                                              +        counter = 0
                                                                                                                              +    if not counter % 150:
                                                                                                                              +        x += 1
                                                                                                                              +    sleep(.1)
                                                                                                                              +
                                                                                                                              +

                                                                                                                              Bitmap LIbrary

                                                                                                                              +
                                                                                                                               1
                                                                                                                              + 2
                                                                                                                              + 3
                                                                                                                              + 4
                                                                                                                              + 5
                                                                                                                              + 6
                                                                                                                              + 7
                                                                                                                              + 8
                                                                                                                              + 9
                                                                                                                              +10
                                                                                                                              +11
                                                                                                                              +12
                                                                                                                              +13
                                                                                                                              +14
                                                                                                                              +15
                                                                                                                              +16
                                                                                                                              +17
                                                                                                                              +18
                                                                                                                              +19
                                                                                                                              +20
                                                                                                                              +21
                                                                                                                              +22
                                                                                                                              +23
                                                                                                                              +24
                                                                                                                              +25
                                                                                                                              +26
                                                                                                                              +27
                                                                                                                              +28
                                                                                                                              +29
                                                                                                                              +30
                                                                                                                              +31
                                                                                                                              +32
                                                                                                                              +33
                                                                                                                              +34
                                                                                                                              +35
                                                                                                                              +36
                                                                                                                              +37
                                                                                                                              +38
                                                                                                                              +39
                                                                                                                              +40
                                                                                                                              +41
                                                                                                                              +42
                                                                                                                              +43
                                                                                                                              +44
                                                                                                                              +45
                                                                                                                              +46
                                                                                                                              +47
                                                                                                                              +48
                                                                                                                              +49
                                                                                                                              +50
                                                                                                                              +51
                                                                                                                              +52
                                                                                                                              +53
                                                                                                                              +54
                                                                                                                              +55
                                                                                                                              +56
                                                                                                                              +57
                                                                                                                              +58
                                                                                                                              +59
                                                                                                                              +60
                                                                                                                              +61
                                                                                                                              +62
                                                                                                                              +63
                                                                                                                              +64
                                                                                                                              +65
                                                                                                                              +66
                                                                                                                              +67
                                                                                                                              +68
                                                                                                                              +69
                                                                                                                              # MicroPython basic bitmap font renderer.
                                                                                                                              +# Author: Tony DiCola
                                                                                                                              +# License: MIT License (https://opensource.org/licenses/MIT)
                                                                                                                              +try:
                                                                                                                              +    import ustruct
                                                                                                                              +except ImportError:
                                                                                                                              +    import struct as ustruct
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +class BitmapFont:
                                                                                                                              +
                                                                                                                              +    def __init__(self, width, height, pixel, font_name='font5x8.bin'):
                                                                                                                              +        # Specify the drawing area width and height, and the pixel function to
                                                                                                                              +        # call when drawing pixels (should take an x and y param at least).
                                                                                                                              +        # Optionally specify font_name to override the font file to use (default
                                                                                                                              +        # is font5x8.bin).  The font format is a binary file with the following
                                                                                                                              +        # format:
                                                                                                                              +        # - 1 unsigned byte: font character width in pixels
                                                                                                                              +        # - 1 unsigned byte: font character height in pixels
                                                                                                                              +        # - x bytes: font data, in ASCII order covering all 255 characters.
                                                                                                                              +        #            Each character should have a byte for each pixel column of
                                                                                                                              +        #            data (i.e. a 5x8 font has 5 bytes per character).
                                                                                                                              +        self._width = width
                                                                                                                              +        self._height = height
                                                                                                                              +        self._pixel = pixel
                                                                                                                              +        self._font_name = font_name
                                                                                                                              +
                                                                                                                              +    def init(self):
                                                                                                                              +        # Open the font file and grab the character width and height values.
                                                                                                                              +        # Note that only fonts up to 8 pixels tall are currently supported.
                                                                                                                              +        self._font = open(self._font_name, 'rb')
                                                                                                                              +        self._font_width, self._font_height = ustruct.unpack('BB', self._font.read(2))
                                                                                                                              +
                                                                                                                              +    def deinit(self):
                                                                                                                              +        # Close the font file as cleanup.
                                                                                                                              +        self._font.close()
                                                                                                                              +
                                                                                                                              +    def __enter__(self):
                                                                                                                              +        self.init()
                                                                                                                              +        return self
                                                                                                                              +
                                                                                                                              +    def __exit__(self, exception_type, exception_value, traceback):
                                                                                                                              +        self.deinit()
                                                                                                                              +
                                                                                                                              +    def draw_char(self, ch, x, y, *args, **kwargs):
                                                                                                                              +        # Don't draw the character if it will be clipped off the visible area.
                                                                                                                              +        if x < -self._font_width or x >= self._width or \
                                                                                                                              +           y < -self._font_height or y >= self._height:
                                                                                                                              +            return
                                                                                                                              +        # Go through each column of the character.
                                                                                                                              +        for char_x in range(self._font_width):
                                                                                                                              +            # Grab the byte for the current column of font data.
                                                                                                                              +            self._font.seek(2 + (ord(ch) * self._font_width) + char_x)
                                                                                                                              +            line = ustruct.unpack('B', self._font.read(1))[0]
                                                                                                                              +            # Go through each row in the column byte.
                                                                                                                              +            for char_y in range(self._font_height):
                                                                                                                              +                # Draw a pixel for each bit that's flipped on.
                                                                                                                              +                if (line >> char_y) & 0x1:
                                                                                                                              +                    self._pixel(x + char_x, y + char_y, *args, **kwargs)
                                                                                                                              +
                                                                                                                              +    def text(self, text, x, y, *args, **kwargs):
                                                                                                                              +        # Draw the specified text at the specified location.
                                                                                                                              +        for i in range(len(text)):
                                                                                                                              +            self.draw_char(text[i], x + (i * (self._font_width + 1)), y,
                                                                                                                              +                           *args, **kwargs)
                                                                                                                              +
                                                                                                                              +    def width(self, text):
                                                                                                                              +        # Return the pixel width of the specified text message.
                                                                                                                              +        return len(text) * (self._font_width + 1)
                                                                                                                              +
                                                                                                                              +

                                                                                                                              Full Code

                                                                                                                              +
                                                                                                                               1
                                                                                                                              + 2
                                                                                                                              + 3
                                                                                                                              + 4
                                                                                                                              + 5
                                                                                                                              + 6
                                                                                                                              + 7
                                                                                                                              + 8
                                                                                                                              + 9
                                                                                                                              +10
                                                                                                                              +11
                                                                                                                              +12
                                                                                                                              +13
                                                                                                                              +14
                                                                                                                              +15
                                                                                                                              +16
                                                                                                                              +17
                                                                                                                              +18
                                                                                                                              +19
                                                                                                                              +20
                                                                                                                              +21
                                                                                                                              +22
                                                                                                                              +23
                                                                                                                              +24
                                                                                                                              +25
                                                                                                                              +26
                                                                                                                              +27
                                                                                                                              +28
                                                                                                                              +29
                                                                                                                              +30
                                                                                                                              +31
                                                                                                                              +32
                                                                                                                              +33
                                                                                                                              +34
                                                                                                                              +35
                                                                                                                              +36
                                                                                                                              +37
                                                                                                                              +38
                                                                                                                              +39
                                                                                                                              +40
                                                                                                                              +41
                                                                                                                              +42
                                                                                                                              +43
                                                                                                                              +44
                                                                                                                              +45
                                                                                                                              +46
                                                                                                                              +47
                                                                                                                              +48
                                                                                                                              +49
                                                                                                                              +50
                                                                                                                              +51
                                                                                                                              +52
                                                                                                                              +53
                                                                                                                              +54
                                                                                                                              +55
                                                                                                                              +56
                                                                                                                              +57
                                                                                                                              +58
                                                                                                                              +59
                                                                                                                              +60
                                                                                                                              +61
                                                                                                                              +62
                                                                                                                              +63
                                                                                                                              +64
                                                                                                                              +65
                                                                                                                              +66
                                                                                                                              +67
                                                                                                                              # LED Matrix message scroller demo.
                                                                                                                              +
                                                                                                                              +import bitmapfont
                                                                                                                              +import machine
                                                                                                                              +import utime
                                                                                                                              +from neopixel import NeoPixel
                                                                                                                              +
                                                                                                                              +NEOPIXEL_PIN = 0
                                                                                                                              +ROWS = 8
                                                                                                                              +COLS = 32
                                                                                                                              +NUMBER_PIXELS = ROWS * COLS
                                                                                                                              +matrix = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                                                                              +
                                                                                                                              +def fill(val):
                                                                                                                              +    for i in range(0, NUMBER_PIXELS):
                                                                                                                              +        matrix[i] = val
                                                                                                                              +
                                                                                                                              +# Configuration:
                                                                                                                              +DISPLAY_WIDTH  = 32      # Display width in pixels.
                                                                                                                              +DISPLAY_HEIGHT = 8       # Display height in pixels.
                                                                                                                              +SPEED          = 20.0    # Scroll speed in pixels per second.
                                                                                                                              +
                                                                                                                              +def show():
                                                                                                                              +    matrix.write()
                                                                                                                              +
                                                                                                                              +def write_pixel_value(x, y, value):
                                                                                                                              +    if y >= 0 and y < ROWS and x >=0 and x < COLS:
                                                                                                                              +        # odd count rows 1, 3, 5 the wire goes from bottup
                                                                                                                              +        if x % 2: 
                                                                                                                              +            matrix[(x+1)*ROWS - y - 1] = value             
                                                                                                                              +        else: # even count rows, 0, 2, 4 the wire goes from the top down up
                                                                                                                              +            matrix[x*ROWS + y] = value
                                                                                                                              +
                                                                                                                              +def write_pixel(x, y):
                                                                                                                              +    write_pixel_value(x, y, (1,1,2))
                                                                                                                              +
                                                                                                                              +def scroll_text(message):
                                                                                                                              +
                                                                                                                              +    with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, write_pixel) as bf:
                                                                                                                              +        # Global state:
                                                                                                                              +        pos = DISPLAY_WIDTH                 # X position of the message start.
                                                                                                                              +        message_width = bf.width(message)   # Message width in pixels.
                                                                                                                              +        last = utime.ticks_ms()             # Last frame millisecond tick time.
                                                                                                                              +        speed_ms = SPEED / 1000.0           # Scroll speed in pixels/ms.
                                                                                                                              +        # Main loop:
                                                                                                                              +        while True:
                                                                                                                              +            # Compute the time delta in milliseconds since the last frame.
                                                                                                                              +            current = utime.ticks_ms()
                                                                                                                              +            delta_ms = utime.ticks_diff(current, last)
                                                                                                                              +            last = current
                                                                                                                              +            # Compute position using speed and time delta.
                                                                                                                              +            pos -= speed_ms*delta_ms
                                                                                                                              +            if pos < -message_width:
                                                                                                                              +                pos = DISPLAY_WIDTH
                                                                                                                              +            # Clear the matrix and draw the text at the current position.
                                                                                                                              +            fill((0,0,0))
                                                                                                                              +            bf.text(message, int(pos), 0)
                                                                                                                              +            # Update the matrix LEDs.
                                                                                                                              +            show()
                                                                                                                              +            # Sleep a bit to give USB mass storage some processing time (quirk
                                                                                                                              +            # of SAMD21 firmware right now).
                                                                                                                              +            utime.sleep_ms(20)
                                                                                                                              +
                                                                                                                              +write_pixel(0,0)
                                                                                                                              +show()
                                                                                                                              +#scroll_text('Dan Loves Ann!')
                                                                                                                              +scroll_text('MicroPython Rocks')
                                                                                                                              +
                                                                                                                              +

                                                                                                                              References

                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                              +
                                                                                                                              + + + +
                                                                                                                              + + + +
                                                                                                                              + +
                                                                                                                              + + + +
                                                                                                                              + + + +
                                                                                                                              + + +
                                                                                                                              +
                                                                                                                              + + Previous + +
                                                                                                                              + Random Hearts +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + + +
                                                                                                                              + + Next + +
                                                                                                                              + OLED References +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                              + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                              + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/19-wiring-harness/index.html b/displays/graph/19-wiring-harness/index.html new file mode 100644 index 000000000..29dd22052 --- /dev/null +++ b/displays/graph/19-wiring-harness/index.html @@ -0,0 +1,2106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Wiring Harness - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                              + + + + Skip to content + + +
                                                                                                                              +
                                                                                                                              + +
                                                                                                                              + + + + + + +
                                                                                                                              +
                                                                                                                              + + + logo + + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + MicroPython for Kids + +
                                                                                                                              +
                                                                                                                              + + + Wiring Harness + + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + + + + + + + +
                                                                                                                              + +
                                                                                                                              +
                                                                                                                              + + +
                                                                                                                              + + +
                                                                                                                              + +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              +
                                                                                                                              + Initializing search +
                                                                                                                              +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + +
                                                                                                                                + +
                                                                                                                                + + +
                                                                                                                                +
                                                                                                                                + GitHub Repo +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                                + +
                                                                                                                                + +
                                                                                                                                + + + + + + +
                                                                                                                                +
                                                                                                                                + + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + + +
                                                                                                                                + + +
                                                                                                                                + +
                                                                                                                                + + +
                                                                                                                                +
                                                                                                                                + GitHub Repo +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                                  + + + + + + + +
                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + +
                                                                                                                                  + +
                                                                                                                                    + + + + + + + +
                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + Wiring Harness + + + + + + + +
                                                                                                                                    + + + + + + + +
                                                                                                                                      + +
                                                                                                                                    • + + + Cable Wiring Diagram + + + +
                                                                                                                                    • + +
                                                                                                                                    • + + + Sample Python Code + + + +
                                                                                                                                    • + +
                                                                                                                                    • + + + Building A Harness for the Cytron Maker Pi RP2040 Board + + + +
                                                                                                                                    • + +
                                                                                                                                    + +
                                                                                                                                    + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Graphic LCD + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Basic Drawing + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Custom Drawing Functions + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Color LCD ST7789V + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Timing Draw Speed + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + TFT ILI9341 + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + LCD Waveshare + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + E-Paper + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Setup + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED SSD 1352 + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Bounce + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Pot + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Ping + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Pong + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Pixel Draw + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED Patterns + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + Random Hearts + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + NeoPixel Matrix + + + + +
                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                  • + + + + + OLED References + + + + +
                                                                                                                                  • + + + + +
                                                                                                                                  +
                                                                                                                                  + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + References + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                • + + + + + + + + + +
                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                • + + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + +
                                                                                                                                + + + + + + + +
                                                                                                                                  + +
                                                                                                                                • + + + Cable Wiring Diagram + + + +
                                                                                                                                • + +
                                                                                                                                • + + + Sample Python Code + + + +
                                                                                                                                • + +
                                                                                                                                • + + + Building A Harness for the Cytron Maker Pi RP2040 Board + + + +
                                                                                                                                • + +
                                                                                                                                + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + +
                                                                                                                                +
                                                                                                                                + + + + + + + +

                                                                                                                                Display Wiring Harness

                                                                                                                                +

                                                                                                                                Unlike simple sensors that only have a few wires, displays have up to seven wires that need to be connected. This can be tricky when +we use breadboards where we can accidentally pull one wire out.

                                                                                                                                +

                                                                                                                                To keep our displays running reliably, we can use a 20 cm ribbon cable and some hot glue to make a connector that is easy to hook up. It will be very reliable.

                                                                                                                                +

                                                                                                                                We start by purchasing some 20 cm long Male-Female Dupont ribbon connectors from eBay. The price should be about $8 +for 120 connectors. Make sure to get the Male-Female version.

                                                                                                                                +

                                                                                                                                Dupont Ribbon Cable

                                                                                                                                +

                                                                                                                                We then will separate 7 of these wires making sure to put the black and red colors in the GND and VCC edge of the group of wires.

                                                                                                                                +

                                                                                                                                Harness 1

                                                                                                                                +

                                                                                                                                You can see a close-up of each of the colors and their connections in the picture below.

                                                                                                                                +

                                                                                                                                Harness 2

                                                                                                                                +

                                                                                                                                At the other end of the cable, we need to make a small change in the order of the cable. Here are the changes:

                                                                                                                                +
                                                                                                                                  +
                                                                                                                                1. We separate the red wire from the rest of the group and connect the red to the 3.3V regulated output of the Raspberry Pi Pico.
                                                                                                                                2. +
                                                                                                                                3. We move the back GND wire two be in between the blue and purple CS and DC wires. This allows the row of all the wires to be connected in a single block of wires.
                                                                                                                                4. +
                                                                                                                                +

                                                                                                                                Harness 3

                                                                                                                                +

                                                                                                                                We can then plug this group of wires directly into the breadboard from breadboard rows 3 to 9. This is shown below.

                                                                                                                                +

                                                                                                                                Harness 4

                                                                                                                                +

                                                                                                                                We designed these connections with the following rules:

                                                                                                                                +
                                                                                                                                  +
                                                                                                                                1. The Clock (SCL) and Data (SDA) MUST be connected to rows 4 and 5 respectively because this is where SPI0 CLK and SPI0 TX are located.
                                                                                                                                2. +
                                                                                                                                3. The other three signals RES, DC and CS can be on pin so we will use the rows that make the cable connectors direct to rows 6, 7 and 9. Note that GND is on breadboard row 8.
                                                                                                                                4. +
                                                                                                                                +

                                                                                                                                We have found that once we create these cable assemblies with hot glue to keep the pins in the right order it makes it much easier to connect the displays.

                                                                                                                                +
                                                                                                                                +

                                                                                                                                Warning

                                                                                                                                +

                                                                                                                                Note that we still MUST make sure that the black wire in the wiring harness is connected to the GND. It is easy to get the cable reversed so make sure to double-check the cable orientation before you use it.

                                                                                                                                +
                                                                                                                                +

                                                                                                                                Cable Wiring Diagram

                                                                                                                                +

                                                                                                                                Here is the detailed wiring diagram showing the +wires as they route from the back of the OLED display +to the pins on the breadboard:

                                                                                                                                +

                                                                                                                                Wiring Diagram Circuit

                                                                                                                                +

                                                                                                                                Sample Python Code

                                                                                                                                +
                                                                                                                                 1
                                                                                                                                + 2
                                                                                                                                + 3
                                                                                                                                + 4
                                                                                                                                + 5
                                                                                                                                + 6
                                                                                                                                + 7
                                                                                                                                + 8
                                                                                                                                + 9
                                                                                                                                +10
                                                                                                                                +11
                                                                                                                                +12
                                                                                                                                +13
                                                                                                                                +14
                                                                                                                                +15
                                                                                                                                +16
                                                                                                                                +17
                                                                                                                                +18
                                                                                                                                +19
                                                                                                                                +20
                                                                                                                                from machine import Pin
                                                                                                                                +
                                                                                                                                +# Customize these GPIO numbers for your layout
                                                                                                                                +# Note these are not breadboard row numbers
                                                                                                                                +# The breadboard row numbers are 4,5,6,7 and 9 with GND on row 8
                                                                                                                                +SCL_PIN = 2
                                                                                                                                +SDA_PIN = 3
                                                                                                                                +RES_PIN = 4
                                                                                                                                +DC_PIN = 5
                                                                                                                                +CS_PIN = 6
                                                                                                                                +
                                                                                                                                +# create the Pin objects
                                                                                                                                +scl=Pin(SCL_PIN)
                                                                                                                                +sda=Pin(SDA_PIN)
                                                                                                                                +res=Pin(RES_PIN)
                                                                                                                                +dc=Pin(DC_PIN)
                                                                                                                                +cs = Pin(CS_PIN)
                                                                                                                                +
                                                                                                                                +spi=machine.SPI(0, sck=scl, mosi=sda)
                                                                                                                                +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs)
                                                                                                                                +
                                                                                                                                +

                                                                                                                                Building A Harness for the Cytron Maker Pi RP2040 Board

                                                                                                                                +

                                                                                                                                We can also make a display harness for the Cytron Maker Pi RP2040 Board. To do this we will need +to use three grove connectors. We use all four wires of the first Grove connector, two of the data signals on the second and just a single wire on the third Grove connector. This connector is shown below.

                                                                                                                                +

                                                                                                                                Cytron Make Pi RP2040

                                                                                                                                +

                                                                                                                                The MicroPython code for this harness is the following:

                                                                                                                                +
                                                                                                                                 1
                                                                                                                                + 2
                                                                                                                                + 3
                                                                                                                                + 4
                                                                                                                                + 5
                                                                                                                                + 6
                                                                                                                                + 7
                                                                                                                                + 8
                                                                                                                                + 9
                                                                                                                                +10
                                                                                                                                +11
                                                                                                                                +12
                                                                                                                                +13
                                                                                                                                +14
                                                                                                                                +15
                                                                                                                                +16
                                                                                                                                +17
                                                                                                                                +18
                                                                                                                                from machine import Pin
                                                                                                                                +
                                                                                                                                +# Customize these GPIO pin numbers for your layout
                                                                                                                                +SCL_PIN = 2
                                                                                                                                +SDA_PIN = 3
                                                                                                                                +RES_PIN = 4
                                                                                                                                +DC_PIN = 5
                                                                                                                                +CS_PIN = 16
                                                                                                                                +
                                                                                                                                +# create the Pin objects
                                                                                                                                +scl=Pin(SCL_PIN)
                                                                                                                                +sda=Pin(SDA_PIN)
                                                                                                                                +res=Pin(RES_PIN)
                                                                                                                                +dc=Pin(DC_PIN)
                                                                                                                                +cs = Pin(CS_PIN)
                                                                                                                                +
                                                                                                                                +spi=machine.SPI(0, sck=scl, mosi=sda)
                                                                                                                                +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs)
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +

                                                                                                                                Note

                                                                                                                                +

                                                                                                                                This code is exactly the same as the Pico version above +with the exception of the CS_PIN which was on GPIO 6 +but we now moved it to GPIO 16.

                                                                                                                                +
                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                +
                                                                                                                                + + + +
                                                                                                                                + + + +
                                                                                                                                + +
                                                                                                                                + + + +
                                                                                                                                + + + +
                                                                                                                                + + +
                                                                                                                                +
                                                                                                                                + + Previous + +
                                                                                                                                + Introduction +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + + +
                                                                                                                                + + Next + +
                                                                                                                                + Graphic LCD +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                                + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/20-seven-segments/index.html b/displays/graph/20-seven-segments/index.html new file mode 100644 index 000000000..25e56e13d --- /dev/null +++ b/displays/graph/20-seven-segments/index.html @@ -0,0 +1,1290 @@ + + + + + + + + + + + + + + + + + + + + + + + Drawing a Seven Segment Display - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                + + + + Skip to content + + +
                                                                                                                                +
                                                                                                                                + +
                                                                                                                                + + + + + + +
                                                                                                                                +
                                                                                                                                + + + logo + + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                +
                                                                                                                                + + + Drawing a Seven Segment Display + + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + + + + + + + +
                                                                                                                                + +
                                                                                                                                +
                                                                                                                                + + +
                                                                                                                                + + +
                                                                                                                                + +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                +
                                                                                                                                + Initializing search +
                                                                                                                                +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + +
                                                                                                                                  + +
                                                                                                                                  + + +
                                                                                                                                  +
                                                                                                                                  + GitHub Repo +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + +
                                                                                                                                  + +
                                                                                                                                  + +
                                                                                                                                  + + + + + + +
                                                                                                                                  +
                                                                                                                                  + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + + +
                                                                                                                                  + + +
                                                                                                                                  + +
                                                                                                                                  + + +
                                                                                                                                  +
                                                                                                                                  + GitHub Repo +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + +
                                                                                                                                    + + + + + + + +
                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                  • + + + + + + + + + +
                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                  • + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + +
                                                                                                                                  + + + + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + +
                                                                                                                                  +
                                                                                                                                  + + + + + + + +

                                                                                                                                  Drawing a Seven Segment Display

                                                                                                                                  +

                                                                                                                                  https://en.wikipedia.org/wiki/Seven-segment_display

                                                                                                                                  +

                                                                                                                                  Wikipedia Seven Segment Display

                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                  +
                                                                                                                                  + + + +
                                                                                                                                  + + + +
                                                                                                                                  + +
                                                                                                                                  + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                  + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/displays/graph/40-oled-references/index.html b/displays/graph/40-oled-references/index.html new file mode 100644 index 000000000..b012240e9 --- /dev/null +++ b/displays/graph/40-oled-references/index.html @@ -0,0 +1,1900 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OLED References - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                  +
                                                                                                                                  + +
                                                                                                                                  + + + + + + +
                                                                                                                                  +
                                                                                                                                  + + + logo + + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                  +
                                                                                                                                  + + + OLED References + + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + + + + + + + +
                                                                                                                                  + +
                                                                                                                                  +
                                                                                                                                  + + +
                                                                                                                                  + + +
                                                                                                                                  + +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  +
                                                                                                                                  + Initializing search +
                                                                                                                                  +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + +
                                                                                                                                    + +
                                                                                                                                    + + +
                                                                                                                                    +
                                                                                                                                    + GitHub Repo +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + +
                                                                                                                                    + +
                                                                                                                                    + +
                                                                                                                                    + + + + + + +
                                                                                                                                    +
                                                                                                                                    + + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + + +
                                                                                                                                    + + +
                                                                                                                                    + +
                                                                                                                                    + + +
                                                                                                                                    +
                                                                                                                                    + GitHub Repo +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + +
                                                                                                                                      + + + + + + + +
                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + +
                                                                                                                                      + +
                                                                                                                                        + + + + + + + +
                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Wiring Harness + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Graphic LCD + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Basic Drawing + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Drawing with Bitmaps + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Custom Drawing Functions + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Color LCD ST7789V + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Timing Draw Speed + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + TFT ILI9341 + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + LCD Waveshare + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + E-Paper + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Setup + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED SSD1306 I2C + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED SSD1306 SPI V1 + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED SSD1306 SPI V2 + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED SH1106 I2C Example + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED SSD 1352 + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Bounce + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Pot + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Ping + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Pong + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Pixel Draw + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + OLED Patterns + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + Random Hearts + + + + +
                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                      • + + + + + NeoPixel Matrix + + + + +
                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + OLED References + + + + + +
                                                                                                                                      • + + + + +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                    • + + + + + + + + + +
                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                    • + + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + +
                                                                                                                                    + + + + + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + +
                                                                                                                                    +
                                                                                                                                    + + + + + + + +

                                                                                                                                    OLED References

                                                                                                                                    +
                                                                                                                                      +
                                                                                                                                    1. Analysis of OLED drawing performance using SPI interface
                                                                                                                                    2. +
                                                                                                                                    3. Analysis of OLED drawing performance using SPI interface
                                                                                                                                    4. +
                                                                                                                                    5. Example of displaying a complex animation on an OLED with SPI
                                                                                                                                    6. +
                                                                                                                                    7. Video of the Above on YouTube
                                                                                                                                    8. +
                                                                                                                                    9. Peter Hinch's MicroPython Nano GUI
                                                                                                                                    10. +
                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                    +
                                                                                                                                    + + + +
                                                                                                                                    + + + +
                                                                                                                                    + +
                                                                                                                                    + + + +
                                                                                                                                    + + + +
                                                                                                                                    + + +
                                                                                                                                    +
                                                                                                                                    + + Previous + +
                                                                                                                                    + NeoPixel Matrix +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + + +
                                                                                                                                    + + Next + +
                                                                                                                                    + Introduction +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + +
                                                                                                                                    +
                                                                                                                                    + +
                                                                                                                                    + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                    + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/01-intro/index.html b/displays/non-graph/01-intro/index.html new file mode 100644 index 000000000..440ec1fe1 --- /dev/null +++ b/displays/non-graph/01-intro/index.html @@ -0,0 +1,1474 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                    +
                                                                                                                                    + +
                                                                                                                                    + + + + + + +
                                                                                                                                    +
                                                                                                                                    + + + logo + + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                    +
                                                                                                                                    + + + Introduction + + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + + + + + + + +
                                                                                                                                    + +
                                                                                                                                    +
                                                                                                                                    + + +
                                                                                                                                    + + +
                                                                                                                                    + +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    +
                                                                                                                                    + Initializing search +
                                                                                                                                    +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + +
                                                                                                                                      + +
                                                                                                                                      + + +
                                                                                                                                      +
                                                                                                                                      + GitHub Repo +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                      + +
                                                                                                                                      + +
                                                                                                                                      + + + + + + +
                                                                                                                                      +
                                                                                                                                      + + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + + +
                                                                                                                                      + + +
                                                                                                                                      + +
                                                                                                                                      + + +
                                                                                                                                      +
                                                                                                                                      + GitHub Repo +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                        + + + + + + + +
                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + +
                                                                                                                                        + +
                                                                                                                                          + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + Introduction + + + + + +
                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                        • + + + + + 7 Segment Display + + + + +
                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                        • + + + + + 10 Bar LEDs + + + + +
                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                        • + + + + + 8x8 LED Matrix + + + + +
                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                        • + + + + + Character LCD + + + + +
                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                        • + + + + + 4 Digit LED + + + + +
                                                                                                                                        • + + + + +
                                                                                                                                        +
                                                                                                                                        + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                      • + + + + + + + + + +
                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                      • + + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + +
                                                                                                                                      + + + + + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + +
                                                                                                                                      +
                                                                                                                                      + + + + + + + +

                                                                                                                                      Using Non-Graphic Displays with MicroPython

                                                                                                                                      +

                                                                                                                                      In this section cover small non-graphical displays such as LED bar displays, LCD character displays and other displays that don't require a drawing library and support for framebuffers. There is a separate section for graphical displays.

                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                      +
                                                                                                                                      + + + +
                                                                                                                                      + + + +
                                                                                                                                      + +
                                                                                                                                      + + + +
                                                                                                                                      + + + +
                                                                                                                                      + + +
                                                                                                                                      +
                                                                                                                                      + + Previous + +
                                                                                                                                      + Stepper Motors +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + + +
                                                                                                                                      + + Next + +
                                                                                                                                      + 7 Segment Display +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                      + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                      + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/02-led-button/index.html b/displays/non-graph/02-led-button/index.html new file mode 100644 index 000000000..273fd6fcf --- /dev/null +++ b/displays/non-graph/02-led-button/index.html @@ -0,0 +1,1289 @@ + + + + + + + + + + + + + + + + + + + + + + + LED Buttons Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                      +
                                                                                                                                      + +
                                                                                                                                      + + + + + + +
                                                                                                                                      +
                                                                                                                                      + + + logo + + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                      +
                                                                                                                                      + + + LED Buttons Lab + + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + + + + + + + +
                                                                                                                                      + +
                                                                                                                                      +
                                                                                                                                      + + +
                                                                                                                                      + + +
                                                                                                                                      + +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      +
                                                                                                                                      + Initializing search +
                                                                                                                                      +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + +
                                                                                                                                        + +
                                                                                                                                        + + +
                                                                                                                                        +
                                                                                                                                        + GitHub Repo +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + +
                                                                                                                                        + +
                                                                                                                                        + +
                                                                                                                                        + + + + + + +
                                                                                                                                        +
                                                                                                                                        + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + + +
                                                                                                                                        + + +
                                                                                                                                        + +
                                                                                                                                        + + +
                                                                                                                                        +
                                                                                                                                        + GitHub Repo +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + +
                                                                                                                                          + + + + + + + +
                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                        • + + + + + + + + + +
                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                        • + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + +
                                                                                                                                        + + + + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + +
                                                                                                                                        +
                                                                                                                                        + + + + + + + +

                                                                                                                                        LED Buttons Lab

                                                                                                                                        +

                                                                                                                                        LED Button

                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                        +
                                                                                                                                        + + + +
                                                                                                                                        + + + +
                                                                                                                                        + +
                                                                                                                                        + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                        + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/03-10-bar-leds/index.html b/displays/non-graph/03-10-bar-leds/index.html new file mode 100644 index 000000000..ba494aff7 --- /dev/null +++ b/displays/non-graph/03-10-bar-leds/index.html @@ -0,0 +1,1683 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 Bar LEDs - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                        +
                                                                                                                                        + +
                                                                                                                                        + + + + + + +
                                                                                                                                        +
                                                                                                                                        + + + logo + + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                        +
                                                                                                                                        + + + 10 Bar LEDs + + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + + + + + + + +
                                                                                                                                        + +
                                                                                                                                        +
                                                                                                                                        + + +
                                                                                                                                        + + +
                                                                                                                                        + +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        +
                                                                                                                                        + Initializing search +
                                                                                                                                        +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + +
                                                                                                                                          + +
                                                                                                                                          + + +
                                                                                                                                          +
                                                                                                                                          + GitHub Repo +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + +
                                                                                                                                          + +
                                                                                                                                          + +
                                                                                                                                          + + + + + + +
                                                                                                                                          +
                                                                                                                                          + + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + + +
                                                                                                                                          + + +
                                                                                                                                          + +
                                                                                                                                          + + +
                                                                                                                                          +
                                                                                                                                          + GitHub Repo +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + +
                                                                                                                                            + + + + + + + +
                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + +
                                                                                                                                            + +
                                                                                                                                              + + + + + + + +
                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                            • + + + + + 7 Segment Display + + + + +
                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + 10 Bar LEDs + + + + + + + +
                                                                                                                                              + + + + + + + +
                                                                                                                                                + +
                                                                                                                                              • + + + Goals for the Lesson + + + +
                                                                                                                                              • + +
                                                                                                                                              • + + + Circuit + + + +
                                                                                                                                              • + +
                                                                                                                                              • + + + Programming + + + +
                                                                                                                                              • + +
                                                                                                                                              + +
                                                                                                                                              + +
                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                            • + + + + + 8x8 LED Matrix + + + + +
                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                            • + + + + + Character LCD + + + + +
                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                            • + + + + + 4 Digit LED + + + + +
                                                                                                                                            • + + + + +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                          • + + + + + + + + + +
                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                          • + + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + +
                                                                                                                                          + + + + + + + +
                                                                                                                                            + +
                                                                                                                                          • + + + Goals for the Lesson + + + +
                                                                                                                                          • + +
                                                                                                                                          • + + + Circuit + + + +
                                                                                                                                          • + +
                                                                                                                                          • + + + Programming + + + +
                                                                                                                                          • + +
                                                                                                                                          + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + +
                                                                                                                                          +
                                                                                                                                          + + + + + + + +

                                                                                                                                          Ten Bar LED Display

                                                                                                                                          + + +

                                                                                                                                          +

                                                                                                                                          Goals for the Lesson

                                                                                                                                          +

                                                                                                                                          These LED displays can be purchased on eBay for around 40 cents each in quantity 10. These displays are ideal for showing a reading such as a battery charge or a signal strength.

                                                                                                                                          +

                                                                                                                                          Our goal is to learn how to use python lists to turn on and off a row of 10 LEDs.

                                                                                                                                          +

                                                                                                                                          Circuit

                                                                                                                                          +

                                                                                                                                          +

                                                                                                                                          The LEDs come in a dual-in-line package with each of the LEDs connected by the pins aligned across the package.

                                                                                                                                          +

                                                                                                                                          In the circuit below, I connected the positive (anode) of each LED to a GPIO pin and the negative (cathode) through a 330-ohm resistor to the GND rail of the solderless breadboard.

                                                                                                                                          +

                                                                                                                                          +

                                                                                                                                          Note! You MUST use a current limiting resistor or you will burn out the LED.

                                                                                                                                          +

                                                                                                                                          One end of each of the bars will go to one of the power rails and the other to a GIPO pin. I used the pis on the lower part of the Raspberry Pi Pico for this demo.

                                                                                                                                          +

                                                                                                                                          Programming

                                                                                                                                          +

                                                                                                                                          We will create a list that has each of the GPIO pins for output.

                                                                                                                                          +
                                                                                                                                          1
                                                                                                                                          pin_ids = [12,13,14,15,20,19,18,17,16]
                                                                                                                                          +
                                                                                                                                          +

                                                                                                                                          For each pin on this list, we will create a new list that contains the pin object that we can turn on or off.

                                                                                                                                          +
                                                                                                                                          1
                                                                                                                                          +2
                                                                                                                                          +3
                                                                                                                                          +4
                                                                                                                                          +5
                                                                                                                                          +6
                                                                                                                                          +7
                                                                                                                                          +8
                                                                                                                                          from machine import Pin
                                                                                                                                          +from utime import sleep
                                                                                                                                          +
                                                                                                                                          +pin_ids = [12,13,14,15,20,19,18,17,16]
                                                                                                                                          +pins = []
                                                                                                                                          +pin_ids
                                                                                                                                          +for i in pin_ids:
                                                                                                                                          +    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))
                                                                                                                                          +
                                                                                                                                          +

                                                                                                                                          We will use this same preamble code in all our examples.

                                                                                                                                          +

                                                                                                                                          Code to Blink all 10 LEDs

                                                                                                                                          +
                                                                                                                                           1
                                                                                                                                          + 2
                                                                                                                                          + 3
                                                                                                                                          + 4
                                                                                                                                          + 5
                                                                                                                                          + 6
                                                                                                                                          + 7
                                                                                                                                          + 8
                                                                                                                                          + 9
                                                                                                                                          +10
                                                                                                                                          +11
                                                                                                                                          +12
                                                                                                                                          +13
                                                                                                                                          +14
                                                                                                                                          +15
                                                                                                                                          +16
                                                                                                                                          +17
                                                                                                                                          +18
                                                                                                                                          +19
                                                                                                                                          from machine import Pin
                                                                                                                                          +from utime import sleep
                                                                                                                                          +
                                                                                                                                          +pin_ids = [12,13,14,15,20,19,18,17,16]
                                                                                                                                          +pins = []
                                                                                                                                          +pin_ids
                                                                                                                                          +for i in pin_ids:
                                                                                                                                          +    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))
                                                                                                                                          +
                                                                                                                                          +delay = .5
                                                                                                                                          +while True:
                                                                                                                                          +    # turn all the pins on
                                                                                                                                          +    for pin in pins:
                                                                                                                                          +        pins.on()
                                                                                                                                          +    sleep(delay) # wait
                                                                                                                                          +    # turn all the pins off
                                                                                                                                          +    for pin in pins:
                                                                                                                                          +        pins[i].off()
                                                                                                                                          +    sleep(delay)
                                                                                                                                          +
                                                                                                                                          +

                                                                                                                                          Sample Running Lights Example

                                                                                                                                          +

                                                                                                                                          The "running lights" pattern gives the impression that there is a red object that is moving up and down a row. We do this by successively turning on adjacently LEDs and then turning them off. This give the illusion of motion.

                                                                                                                                          +
                                                                                                                                           1
                                                                                                                                          + 2
                                                                                                                                          + 3
                                                                                                                                          + 4
                                                                                                                                          + 5
                                                                                                                                          + 6
                                                                                                                                          + 7
                                                                                                                                          + 8
                                                                                                                                          + 9
                                                                                                                                          +10
                                                                                                                                          +11
                                                                                                                                          +12
                                                                                                                                          +13
                                                                                                                                          +14
                                                                                                                                          +15
                                                                                                                                          +16
                                                                                                                                          +17
                                                                                                                                          +18
                                                                                                                                          +19
                                                                                                                                          from machine import Pin
                                                                                                                                          +from utime import sleep
                                                                                                                                          +
                                                                                                                                          +pin_ids = [12,13,14,15,20,19,18,17,16]
                                                                                                                                          +pins = []
                                                                                                                                          +
                                                                                                                                          +for i in range(0, 9):
                                                                                                                                          +    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))
                                                                                                                                          +
                                                                                                                                          +delay = .1
                                                                                                                                          +while True:
                                                                                                                                          +    for i in range(0, 9):
                                                                                                                                          +        pins[i].on()
                                                                                                                                          +        sleep(delay)
                                                                                                                                          +        pins[i].off()
                                                                                                                                          +    for i in range(8, 1, -1):
                                                                                                                                          +        pins[i].on()
                                                                                                                                          +        sleep(delay)
                                                                                                                                          +        pins[i].off()
                                                                                                                                          +
                                                                                                                                          +

                                                                                                                                          swipe

                                                                                                                                          +

                                                                                                                                          The swipe pattern turns each LED on but keeps it on until the direction is reversed.

                                                                                                                                          +

                                                                                                                                          Adding a Binary Counter Patterns

                                                                                                                                          +

                                                                                                                                          We can also create another patten that will demonstrate binary counting. In this pattern, the least significant bit flickers on and off. For each cycle the adjacent pixel toggles once. The happens for each adjacent pixel. The most significant bit will only change every 1024 cycles of the least significant bit.

                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                          +
                                                                                                                                          + + + +
                                                                                                                                          + + + +
                                                                                                                                          + +
                                                                                                                                          + + + +
                                                                                                                                          + + + +
                                                                                                                                          + + +
                                                                                                                                          +
                                                                                                                                          + + Previous + +
                                                                                                                                          + 7 Segment Display +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + + +
                                                                                                                                          + + Next + +
                                                                                                                                          + 8x8 LED Matrix +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + +
                                                                                                                                          +
                                                                                                                                          + +
                                                                                                                                          + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                          + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/04-8x8-led-matrix/index.html b/displays/non-graph/04-8x8-led-matrix/index.html new file mode 100644 index 000000000..19fff09ba --- /dev/null +++ b/displays/non-graph/04-8x8-led-matrix/index.html @@ -0,0 +1,1730 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 8x8 LED Matrix - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                          +
                                                                                                                                          + +
                                                                                                                                          + + + + + + +
                                                                                                                                          +
                                                                                                                                          + + + logo + + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                          +
                                                                                                                                          + + + 8x8 LED Matrix + + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + + + + + + + +
                                                                                                                                          + +
                                                                                                                                          +
                                                                                                                                          + + +
                                                                                                                                          + + +
                                                                                                                                          + +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          +
                                                                                                                                          + Initializing search +
                                                                                                                                          +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + +
                                                                                                                                            + +
                                                                                                                                            + + +
                                                                                                                                            +
                                                                                                                                            + GitHub Repo +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                            + +
                                                                                                                                            + +
                                                                                                                                            + + + + + + +
                                                                                                                                            +
                                                                                                                                            + + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + + +
                                                                                                                                            + + +
                                                                                                                                            + +
                                                                                                                                            + + +
                                                                                                                                            +
                                                                                                                                            + GitHub Repo +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                              + + + + + + + +
                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + +
                                                                                                                                              + +
                                                                                                                                                + + + + + + + +
                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                              • + + + + + 7 Segment Display + + + + +
                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                              • + + + + + 10 Bar LEDs + + + + +
                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + 8x8 LED Matrix + + + + + + + +
                                                                                                                                                + + + + + + + +
                                                                                                                                                  + +
                                                                                                                                                • + + + Basic Program + + + +
                                                                                                                                                • + +
                                                                                                                                                • + + + Full Demo + + + +
                                                                                                                                                • + +
                                                                                                                                                + +
                                                                                                                                                + +
                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                              • + + + + + Character LCD + + + + +
                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                              • + + + + + 4 Digit LED + + + + +
                                                                                                                                              • + + + + +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                            • + + + + + + + + + +
                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                            • + + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + +
                                                                                                                                            + + + + + + + +
                                                                                                                                              + +
                                                                                                                                            • + + + Basic Program + + + +
                                                                                                                                            • + +
                                                                                                                                            • + + + Full Demo + + + +
                                                                                                                                            • + +
                                                                                                                                            + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + +
                                                                                                                                            +
                                                                                                                                            + + + + + + + +

                                                                                                                                            MAX7219 8x8 LED Matrix

                                                                                                                                            +

                                                                                                                                            MAX7219 +MAX7219

                                                                                                                                            +

                                                                                                                                            This is a low-cost ($3) and easy-to-program device that is perfect for small projects that don't +need a full graphical display. You will be surprised at how creative our students are with +just an 8x8 display!

                                                                                                                                            +

                                                                                                                                            eBay Search for "MAX7219 8x8 matrix"

                                                                                                                                            +

                                                                                                                                            The device comes with five connectors:

                                                                                                                                            +
                                                                                                                                              +
                                                                                                                                            1. Power (VCC)
                                                                                                                                            2. +
                                                                                                                                            3. Ground (GND)
                                                                                                                                            4. +
                                                                                                                                            5. Clock (SCK)
                                                                                                                                            6. +
                                                                                                                                            7. Data (MOSI)
                                                                                                                                            8. +
                                                                                                                                            9. Chip Select (CS)
                                                                                                                                            10. +
                                                                                                                                            +

                                                                                                                                            We can communicate with the device using the standard SPI interface. There is also +an 8x8 driver supplied by Mike Causer Here is an excerpt of how we +configured the driver to use a single display:

                                                                                                                                            +
                                                                                                                                             1
                                                                                                                                            + 2
                                                                                                                                            + 3
                                                                                                                                            + 4
                                                                                                                                            + 5
                                                                                                                                            + 6
                                                                                                                                            + 7
                                                                                                                                            + 8
                                                                                                                                            + 9
                                                                                                                                            +10
                                                                                                                                            +11
                                                                                                                                            +12
                                                                                                                                            from machine import SPI, Pin
                                                                                                                                            +import max7219
                                                                                                                                            +from utime import sleep
                                                                                                                                            +CLOCK_PIN = 2
                                                                                                                                            +DATA_PIN = 3
                                                                                                                                            +CS_PIN = 4
                                                                                                                                            +spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN))
                                                                                                                                            +cs = Pin(CS_PIN, Pin.OUT)
                                                                                                                                            +matrix = max7219.Matrix8x8(spi0, cs , 1)
                                                                                                                                            +# display text a x=0, y=0 and state = 1 (on)
                                                                                                                                            +matrix.text('1234', 0, 0, 1)
                                                                                                                                            +matrix.show()
                                                                                                                                            +
                                                                                                                                            +

                                                                                                                                            You can change the last parameter from "1" to "4" if you have 4 displays wired together:

                                                                                                                                            +
                                                                                                                                            1
                                                                                                                                            +2
                                                                                                                                            +3
                                                                                                                                            +4
                                                                                                                                            +5
                                                                                                                                            +6
                                                                                                                                            import max7219
                                                                                                                                            +from machine import Pin, SPI
                                                                                                                                            +spi = SPI(1)
                                                                                                                                            +matrix = max7219.Matrix8x8(spi0, cs , 4)
                                                                                                                                            +display.text('1234',0,0,1)
                                                                                                                                            +display.show()
                                                                                                                                            +
                                                                                                                                            +

                                                                                                                                            The displays can also be "cascaded"

                                                                                                                                            +

                                                                                                                                            Basic Program

                                                                                                                                            +
                                                                                                                                             1
                                                                                                                                            + 2
                                                                                                                                            + 3
                                                                                                                                            + 4
                                                                                                                                            + 5
                                                                                                                                            + 6
                                                                                                                                            + 7
                                                                                                                                            + 8
                                                                                                                                            + 9
                                                                                                                                            +10
                                                                                                                                            +11
                                                                                                                                            +12
                                                                                                                                            +13
                                                                                                                                            +14
                                                                                                                                            +15
                                                                                                                                            from machine import SPI, Pin
                                                                                                                                            +import max7219
                                                                                                                                            +from utime import sleep
                                                                                                                                            +CLOCK_PIN = 2
                                                                                                                                            +DATA_PIN = 3
                                                                                                                                            +CS_PIN = 4
                                                                                                                                            +spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN))
                                                                                                                                            +
                                                                                                                                            +cs = Pin(CS_PIN, Pin.OUT)
                                                                                                                                            +
                                                                                                                                            +matrix = max7219.Matrix8x8(spi0, cs , 1)
                                                                                                                                            +
                                                                                                                                            +matrix.text('A', 0, 0, 1)
                                                                                                                                            +matrix.show()
                                                                                                                                            +sleep(delay_time)
                                                                                                                                            +
                                                                                                                                            +

                                                                                                                                            Full Demo

                                                                                                                                            +
                                                                                                                                             1
                                                                                                                                            + 2
                                                                                                                                            + 3
                                                                                                                                            + 4
                                                                                                                                            + 5
                                                                                                                                            + 6
                                                                                                                                            + 7
                                                                                                                                            + 8
                                                                                                                                            + 9
                                                                                                                                            +10
                                                                                                                                            +11
                                                                                                                                            +12
                                                                                                                                            +13
                                                                                                                                            +14
                                                                                                                                            +15
                                                                                                                                            +16
                                                                                                                                            +17
                                                                                                                                            +18
                                                                                                                                            +19
                                                                                                                                            +20
                                                                                                                                            +21
                                                                                                                                            +22
                                                                                                                                            +23
                                                                                                                                            +24
                                                                                                                                            +25
                                                                                                                                            +26
                                                                                                                                            +27
                                                                                                                                            +28
                                                                                                                                            +29
                                                                                                                                            +30
                                                                                                                                            +31
                                                                                                                                            +32
                                                                                                                                            +33
                                                                                                                                            +34
                                                                                                                                            +35
                                                                                                                                            +36
                                                                                                                                            +37
                                                                                                                                            +38
                                                                                                                                            +39
                                                                                                                                            +40
                                                                                                                                            +41
                                                                                                                                            +42
                                                                                                                                            +43
                                                                                                                                            +44
                                                                                                                                            +45
                                                                                                                                            +46
                                                                                                                                            +47
                                                                                                                                            +48
                                                                                                                                            from machine import SPI, Pin
                                                                                                                                            +import max7219
                                                                                                                                            +from utime import sleep
                                                                                                                                            +spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
                                                                                                                                            +
                                                                                                                                            +cs = Pin(4, Pin.OUT)
                                                                                                                                            +
                                                                                                                                            +matrix = max7219.Matrix8x8(spi0, cs , 1)
                                                                                                                                            +
                                                                                                                                            +delay_time = 1
                                                                                                                                            +while True:
                                                                                                                                            +    # Draw a single character
                                                                                                                                            +
                                                                                                                                            +    matrix.text('A', 0, 0, 1)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +
                                                                                                                                            +    # Draw an X in a box
                                                                                                                                            +    matrix.fill(0)
                                                                                                                                            +    matrix.line(0, 0, 7, 7, 1)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +
                                                                                                                                            +    matrix.line(7, 0, 0, 7, 1)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +
                                                                                                                                            +    matrix.rect(0, 0, 8, 8, 1)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +    matrix.fill(0)
                                                                                                                                            +
                                                                                                                                            +    # Smile Face
                                                                                                                                            +    matrix.pixel(1, 1, 1)
                                                                                                                                            +    matrix.pixel(6, 1, 1)
                                                                                                                                            +    matrix.pixel(0, 4, 1)
                                                                                                                                            +    matrix.pixel(7, 4, 1)
                                                                                                                                            +    matrix.pixel(1, 5, 1)
                                                                                                                                            +    matrix.pixel(6, 5, 1)
                                                                                                                                            +    matrix.pixel(2, 6, 1)
                                                                                                                                            +    matrix.pixel(5, 6, 1)
                                                                                                                                            +    matrix.pixel(3, 7, 1)
                                                                                                                                            +    matrix.pixel(4, 7, 1)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +    matrix.fill(0)
                                                                                                                                            +    matrix.show()
                                                                                                                                            +    sleep(delay_time)
                                                                                                                                            +
                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                            +
                                                                                                                                            + + + +
                                                                                                                                            + + + +
                                                                                                                                            + +
                                                                                                                                            + + + +
                                                                                                                                            + + + +
                                                                                                                                            + + +
                                                                                                                                            +
                                                                                                                                            + + Previous + +
                                                                                                                                            + 10 Bar LEDs +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + + +
                                                                                                                                            + + Next + +
                                                                                                                                            + Character LCD +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                            + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                            + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/05-4-digit/index.html b/displays/non-graph/05-4-digit/index.html new file mode 100644 index 000000000..9e64eb926 --- /dev/null +++ b/displays/non-graph/05-4-digit/index.html @@ -0,0 +1,1787 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 4 Digit LED - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                            +
                                                                                                                                            + +
                                                                                                                                            + + + + + + +
                                                                                                                                            +
                                                                                                                                            + + + logo + + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                            +
                                                                                                                                            + + + 4 Digit LED + + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + + + + + + + +
                                                                                                                                            + +
                                                                                                                                            +
                                                                                                                                            + + +
                                                                                                                                            + + +
                                                                                                                                            + +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            +
                                                                                                                                            + Initializing search +
                                                                                                                                            +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + +
                                                                                                                                              + +
                                                                                                                                              + + +
                                                                                                                                              +
                                                                                                                                              + GitHub Repo +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                              + +
                                                                                                                                              + +
                                                                                                                                              + + + + + + +
                                                                                                                                              +
                                                                                                                                              + + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + + +
                                                                                                                                              + + +
                                                                                                                                              + +
                                                                                                                                              + + +
                                                                                                                                              +
                                                                                                                                              + GitHub Repo +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                                + + + + + + + +
                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + +
                                                                                                                                                + +
                                                                                                                                                  + + + + + + + +
                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                • + + + + + 7 Segment Display + + + + +
                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                • + + + + + 10 Bar LEDs + + + + +
                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                • + + + + + 8x8 LED Matrix + + + + +
                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                • + + + + + Character LCD + + + + +
                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + 4 Digit LED + + + + + + + +
                                                                                                                                                  + + + + + + + +
                                                                                                                                                    + +
                                                                                                                                                  • + + + Connections + + + +
                                                                                                                                                  • + +
                                                                                                                                                  • + + + Clock + + + +
                                                                                                                                                  • + +
                                                                                                                                                  • + + + Accurate Clock + + + +
                                                                                                                                                  • + +
                                                                                                                                                  • + + + References + + + +
                                                                                                                                                  • + +
                                                                                                                                                  + +
                                                                                                                                                  + +
                                                                                                                                                • + + + + +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                              • + + + + + + + + + +
                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                              • + + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + +
                                                                                                                                              + + + + + + + +
                                                                                                                                                + +
                                                                                                                                              • + + + Connections + + + +
                                                                                                                                              • + +
                                                                                                                                              • + + + Clock + + + +
                                                                                                                                              • + +
                                                                                                                                              • + + + Accurate Clock + + + +
                                                                                                                                              • + +
                                                                                                                                              • + + + References + + + +
                                                                                                                                              • + +
                                                                                                                                              + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + +
                                                                                                                                              +
                                                                                                                                              + + + + + + + +

                                                                                                                                              Four Digit LED Display

                                                                                                                                              +

                                                                                                                                              In this lesson, we will use a 4-digit LED display to create a clock that displays the time of day.
                                                                                                                                              +These clocks will use Mike Causer's tm1637 library to communicate +with the four-digit display. Some of these displays also have a "colon" +between the hour and minute digits that flashes every second.

                                                                                                                                              +

                                                                                                                                              You can purchase 4-digit LED displays on eBay for about $2 each.

                                                                                                                                              +

                                                                                                                                              +

                                                                                                                                              +

                                                                                                                                              +

                                                                                                                                              Connections

                                                                                                                                              +

                                                                                                                                              These displays have four pins:

                                                                                                                                              +
                                                                                                                                                +
                                                                                                                                              1. Ground (GND)
                                                                                                                                              2. +
                                                                                                                                              3. Power (3.2 v or 5 v)
                                                                                                                                              4. +
                                                                                                                                              5. Data (DIO)
                                                                                                                                              6. +
                                                                                                                                              7. Clock (CLK)
                                                                                                                                              8. +
                                                                                                                                              +

                                                                                                                                              In our examples, we will connect the power to our 3.3 regulated output +of the Pico. We will connect Data to GP0 and Clock to GP1.

                                                                                                                                              +

                                                                                                                                              The following example +

                                                                                                                                               1
                                                                                                                                              + 2
                                                                                                                                              + 3
                                                                                                                                              + 4
                                                                                                                                              + 5
                                                                                                                                              + 6
                                                                                                                                              + 7
                                                                                                                                              + 8
                                                                                                                                              + 9
                                                                                                                                              +10
                                                                                                                                              +11
                                                                                                                                              +12
                                                                                                                                              from machine import Pin
                                                                                                                                              +from time import sleep
                                                                                                                                              +import tm1637
                                                                                                                                              +
                                                                                                                                              +# data and clock pins
                                                                                                                                              +DIO_PIN = 0
                                                                                                                                              +CLK_PIN = 1
                                                                                                                                              +
                                                                                                                                              +tm = tm1637.TM1637(clk=Pin(CLK_PIN), dio=Pin(DIO_PIN))
                                                                                                                                              +
                                                                                                                                              +# display "1234"
                                                                                                                                              +tm.write([1, 2, 3, 4])
                                                                                                                                              +

                                                                                                                                              +

                                                                                                                                              The tm.write() function takes a sequence of numbers and will shifts them in from right to left.

                                                                                                                                              +

                                                                                                                                              Clock

                                                                                                                                              +

                                                                                                                                              We can create a simple clock by using the localtime() function when the +programs first starts up and then we just update the time after the sleep() functions run for a second. +This also can updates the colon between the hours +and minutes.

                                                                                                                                              +

                                                                                                                                              localtime() returns an array of numbers for date, hour, minute and second. In our example here, we only need the hour and minutes.

                                                                                                                                              +

                                                                                                                                              4 Digit Clock

                                                                                                                                              +
                                                                                                                                               1
                                                                                                                                              + 2
                                                                                                                                              + 3
                                                                                                                                              + 4
                                                                                                                                              + 5
                                                                                                                                              + 6
                                                                                                                                              + 7
                                                                                                                                              + 8
                                                                                                                                              + 9
                                                                                                                                              +10
                                                                                                                                              +11
                                                                                                                                              +12
                                                                                                                                              +13
                                                                                                                                              +14
                                                                                                                                              +15
                                                                                                                                              +16
                                                                                                                                              +17
                                                                                                                                              +18
                                                                                                                                              +19
                                                                                                                                              +20
                                                                                                                                              +21
                                                                                                                                              +22
                                                                                                                                              +23
                                                                                                                                              +24
                                                                                                                                              +25
                                                                                                                                              +26
                                                                                                                                              +27
                                                                                                                                              +28
                                                                                                                                              +29
                                                                                                                                              +30
                                                                                                                                              +31
                                                                                                                                              +32
                                                                                                                                              +33
                                                                                                                                              # a simple clock that only grabs the time from the server on startup
                                                                                                                                              +import tm1637
                                                                                                                                              +from machine import Pin
                                                                                                                                              +from utime import sleep, localtime
                                                                                                                                              +
                                                                                                                                              +tm = tm1637.TM1637(clk=Pin(1), dio=Pin(0))
                                                                                                                                              +
                                                                                                                                              +now = localtime()
                                                                                                                                              +hour = now[3]
                                                                                                                                              +# use AM/PM 12 hour time
                                                                                                                                              +if hour > 12:
                                                                                                                                              +    hour = hour - 12
                                                                                                                                              +minute = now[4]
                                                                                                                                              +sec = now[5]
                                                                                                                                              +print(hour, ':', minute, ' ', sec, sep='')
                                                                                                                                              +
                                                                                                                                              +# update from the first time
                                                                                                                                              +while True:
                                                                                                                                              +    # turn the colon on
                                                                                                                                              +    tm.numbers(hour,minute,colon=True)
                                                                                                                                              +    sleep(0.5)
                                                                                                                                              +    # turn the colon off
                                                                                                                                              +    tm.numbers(hour,minute,colon=False)
                                                                                                                                              +    sleep(0.5)
                                                                                                                                              +    sec = sec + 1
                                                                                                                                              +    if sec == 60:
                                                                                                                                              +        minute = minute + 1
                                                                                                                                              +        sec = 0
                                                                                                                                              +        if minute == 60:
                                                                                                                                              +            hour = hour + 1
                                                                                                                                              +            minute = 0
                                                                                                                                              +            if hour == 24:
                                                                                                                                              +                hour = 0
                                                                                                                                              +
                                                                                                                                              +

                                                                                                                                              A more accurate version will access the new time from the server every minute.

                                                                                                                                              +

                                                                                                                                              Accurate Clock

                                                                                                                                              +
                                                                                                                                               1
                                                                                                                                              + 2
                                                                                                                                              + 3
                                                                                                                                              + 4
                                                                                                                                              + 5
                                                                                                                                              + 6
                                                                                                                                              + 7
                                                                                                                                              + 8
                                                                                                                                              + 9
                                                                                                                                              +10
                                                                                                                                              +11
                                                                                                                                              +12
                                                                                                                                              +13
                                                                                                                                              +14
                                                                                                                                              +15
                                                                                                                                              +16
                                                                                                                                              +17
                                                                                                                                              +18
                                                                                                                                              +19
                                                                                                                                              +20
                                                                                                                                              +21
                                                                                                                                              +22
                                                                                                                                              +23
                                                                                                                                              +24
                                                                                                                                              +25
                                                                                                                                              +26
                                                                                                                                              +27
                                                                                                                                              +28
                                                                                                                                              +29
                                                                                                                                              +30
                                                                                                                                              +31
                                                                                                                                              +32
                                                                                                                                              +33
                                                                                                                                              +34
                                                                                                                                              +35
                                                                                                                                              +36
                                                                                                                                              +37
                                                                                                                                              +38
                                                                                                                                              +39
                                                                                                                                              +40
                                                                                                                                              # a more accurate clock that only grabs the time from the server once per minute
                                                                                                                                              +import tm1637
                                                                                                                                              +from machine import Pin
                                                                                                                                              +from utime import sleep, localtime
                                                                                                                                              +
                                                                                                                                              +hour = 0
                                                                                                                                              +minute = 0
                                                                                                                                              +sec = 0
                                                                                                                                              +
                                                                                                                                              +def update_time():
                                                                                                                                              +    global hour, minute, second
                                                                                                                                              +    now = localtime()
                                                                                                                                              +    hour = now[3]
                                                                                                                                              +    # use AM/PM
                                                                                                                                              +    if hour > 12:
                                                                                                                                              +        hour = hour - 12
                                                                                                                                              +    minute = now[4]
                                                                                                                                              +    sec = now[5]
                                                                                                                                              +
                                                                                                                                              +tm = tm1637.TM1637(clk=Pin(1), dio=Pin(0))
                                                                                                                                              +
                                                                                                                                              +update_time()
                                                                                                                                              +# loop every second
                                                                                                                                              +while True:
                                                                                                                                              +    tm.numbers(hour,minute,colon=True)
                                                                                                                                              +    sleep(0.5)
                                                                                                                                              +    tm.numbers(hour,minute,colon=False)
                                                                                                                                              +    sleep(0.5)
                                                                                                                                              +    sec = sec + 1
                                                                                                                                              +    if sec == 60:
                                                                                                                                              +        # get the new time from the host
                                                                                                                                              +        update_time()
                                                                                                                                              +        print(hour, ':', minute, ' ', sec, sep='')
                                                                                                                                              +        minute = minute + 1
                                                                                                                                              +        sec = 0
                                                                                                                                              +        if minute == 60:
                                                                                                                                              +            hour = hour + 1
                                                                                                                                              +            minute = 0
                                                                                                                                              +            if hour == 24:
                                                                                                                                              +                hour = 0
                                                                                                                                              +
                                                                                                                                              +

                                                                                                                                              References

                                                                                                                                              +
                                                                                                                                                +
                                                                                                                                              • Nerd Cave YouTube Tutorial
                                                                                                                                              • +
                                                                                                                                              • Mike Causer's GitHub Repo with TM-1637 driver
                                                                                                                                              • +
                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                              +
                                                                                                                                              + + + +
                                                                                                                                              + + + +
                                                                                                                                              + +
                                                                                                                                              + + + +
                                                                                                                                              + + + +
                                                                                                                                              + + +
                                                                                                                                              +
                                                                                                                                              + + Previous + +
                                                                                                                                              + Character LCD +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + + +
                                                                                                                                              + + Next + +
                                                                                                                                              + Introduction +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                              + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                              + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/10-character-lcd-display/index.html b/displays/non-graph/10-character-lcd-display/index.html new file mode 100644 index 000000000..821d3c428 --- /dev/null +++ b/displays/non-graph/10-character-lcd-display/index.html @@ -0,0 +1,1820 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Character LCD - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                              +
                                                                                                                                              + +
                                                                                                                                              + + + + + + +
                                                                                                                                              +
                                                                                                                                              + + + logo + + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                              +
                                                                                                                                              + + + Character LCD + + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + + + + + + + +
                                                                                                                                              + +
                                                                                                                                              +
                                                                                                                                              + + +
                                                                                                                                              + + +
                                                                                                                                              + +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              +
                                                                                                                                              + Initializing search +
                                                                                                                                              +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + +
                                                                                                                                                + +
                                                                                                                                                + + +
                                                                                                                                                +
                                                                                                                                                + GitHub Repo +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                                + +
                                                                                                                                                + +
                                                                                                                                                + + + + + + +
                                                                                                                                                +
                                                                                                                                                + + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + + +
                                                                                                                                                + + +
                                                                                                                                                + +
                                                                                                                                                + + +
                                                                                                                                                +
                                                                                                                                                + GitHub Repo +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                                  + + + + + + + +
                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + +
                                                                                                                                                  + +
                                                                                                                                                    + + + + + + + +
                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                  • + + + + + 7 Segment Display + + + + +
                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                  • + + + + + 10 Bar LEDs + + + + +
                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                  • + + + + + 8x8 LED Matrix + + + + +
                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + Character LCD + + + + + + + +
                                                                                                                                                    + + + + + + + +
                                                                                                                                                      + +
                                                                                                                                                    • + + + I2C Address Scanner Test + + + +
                                                                                                                                                      +
                                                                                                                                                        + +
                                                                                                                                                      • + + + Scanner Result + + + +
                                                                                                                                                      • + +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + Testing the LCD + + + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + Putting the Device Through Display Option Tests + + + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + References + + + +
                                                                                                                                                    • + +
                                                                                                                                                    + +
                                                                                                                                                    + +
                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                  • + + + + + 4 Digit LED + + + + +
                                                                                                                                                  • + + + + +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                • + + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + +
                                                                                                                                                + + + + + + + +
                                                                                                                                                  + +
                                                                                                                                                • + + + I2C Address Scanner Test + + + +
                                                                                                                                                  +
                                                                                                                                                    + +
                                                                                                                                                  • + + + Scanner Result + + + +
                                                                                                                                                  • + +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                • + +
                                                                                                                                                • + + + Testing the LCD + + + +
                                                                                                                                                • + +
                                                                                                                                                • + + + Putting the Device Through Display Option Tests + + + +
                                                                                                                                                • + +
                                                                                                                                                • + + + References + + + +
                                                                                                                                                • + +
                                                                                                                                                + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + +
                                                                                                                                                +
                                                                                                                                                + + + + + + + +

                                                                                                                                                Character LCD Display

                                                                                                                                                +

                                                                                                                                                LCD 1602

                                                                                                                                                +

                                                                                                                                                This lesson is for using the LCM1602 I2C LCD interface. It is a popular It has four wires:

                                                                                                                                                +
                                                                                                                                                  +
                                                                                                                                                1. GND - connect to any GND pin
                                                                                                                                                2. +
                                                                                                                                                3. VCC - connect to 3V3(out) pin unless you have a 3.3 to 5v voltage converter
                                                                                                                                                4. +
                                                                                                                                                5. SDA - connect to GP0
                                                                                                                                                6. +
                                                                                                                                                7. SCL - connect to GP1
                                                                                                                                                8. +
                                                                                                                                                +

                                                                                                                                                The photo above shows the use of a 3.3 to 5v voltage converter. This allows us to use the full 5v to the LCD backlight so we get bright contrast. You can connect the VCC to the 3V3(out) pin but the display will be harder to read.

                                                                                                                                                +

                                                                                                                                                I2C Address Scanner Test

                                                                                                                                                +

                                                                                                                                                Our first task is to make sure that the 1602 chip's I2C circuits are working. We use the following I2C scanner code to do this.

                                                                                                                                                +
                                                                                                                                                 1
                                                                                                                                                + 2
                                                                                                                                                + 3
                                                                                                                                                + 4
                                                                                                                                                + 5
                                                                                                                                                + 6
                                                                                                                                                + 7
                                                                                                                                                + 8
                                                                                                                                                + 9
                                                                                                                                                +10
                                                                                                                                                +11
                                                                                                                                                +12
                                                                                                                                                +13
                                                                                                                                                +14
                                                                                                                                                import machine
                                                                                                                                                +I2C_SDA_PIN = 0
                                                                                                                                                +I2C_SCL_PIN = 1
                                                                                                                                                +i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
                                                                                                                                                +
                                                                                                                                                +print('Scanning I2C bus.')
                                                                                                                                                +devices = i2c.scan() # this returns a list of devices
                                                                                                                                                +device_count = len(devices)
                                                                                                                                                +if device_count == 0:
                                                                                                                                                +    print('No i2c device found.')
                                                                                                                                                +else:
                                                                                                                                                +    print(device_count, 'devices found.')
                                                                                                                                                +for device in devices:
                                                                                                                                                +    print('Decimal address:', device, ", Hex address: ", hex(device))
                                                                                                                                                +
                                                                                                                                                +

                                                                                                                                                Scanner Result

                                                                                                                                                +
                                                                                                                                                1
                                                                                                                                                +2
                                                                                                                                                +3
                                                                                                                                                Scanning I2C bus.
                                                                                                                                                +1 devices found.
                                                                                                                                                +Decimal address: 39 , Hex address:  0x27
                                                                                                                                                +
                                                                                                                                                +

                                                                                                                                                Testing the LCD

                                                                                                                                                +
                                                                                                                                                 1
                                                                                                                                                + 2
                                                                                                                                                + 3
                                                                                                                                                + 4
                                                                                                                                                + 5
                                                                                                                                                + 6
                                                                                                                                                + 7
                                                                                                                                                + 8
                                                                                                                                                + 9
                                                                                                                                                +10
                                                                                                                                                +11
                                                                                                                                                from machine import I2C
                                                                                                                                                +from lcd_api import LcdApi
                                                                                                                                                +from pico_i2c_lcd import I2cLcd
                                                                                                                                                +
                                                                                                                                                +I2C_ADDR     = 0x27
                                                                                                                                                +I2C_NUM_ROWS = 2
                                                                                                                                                +I2C_NUM_COLS = 16
                                                                                                                                                +
                                                                                                                                                +i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
                                                                                                                                                +lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)    
                                                                                                                                                +lcd.putstr("CoderDojo Rocks!")
                                                                                                                                                +
                                                                                                                                                +

                                                                                                                                                Putting the Device Through Display Option Tests

                                                                                                                                                +

                                                                                                                                                Now that we know how to display text on the device, we can learn how other functions work:

                                                                                                                                                +
                                                                                                                                                  +
                                                                                                                                                1. lcd.move_to(x,y)
                                                                                                                                                2. +
                                                                                                                                                3. lcd.display_on() and lcd.display_off()
                                                                                                                                                4. +
                                                                                                                                                5. lcd.show_cursor() and lcd.hide_cursor()
                                                                                                                                                6. +
                                                                                                                                                7. lcd.blink_cursor_on() and lcd.blink_cursor_off()
                                                                                                                                                8. +
                                                                                                                                                9. lcd.backlight_on() and lcd.backlight_off()
                                                                                                                                                10. +
                                                                                                                                                11. lcd.clear()
                                                                                                                                                12. +
                                                                                                                                                +
                                                                                                                                                 1
                                                                                                                                                + 2
                                                                                                                                                + 3
                                                                                                                                                + 4
                                                                                                                                                + 5
                                                                                                                                                + 6
                                                                                                                                                + 7
                                                                                                                                                + 8
                                                                                                                                                + 9
                                                                                                                                                +10
                                                                                                                                                +11
                                                                                                                                                +12
                                                                                                                                                +13
                                                                                                                                                +14
                                                                                                                                                +15
                                                                                                                                                +16
                                                                                                                                                +17
                                                                                                                                                +18
                                                                                                                                                +19
                                                                                                                                                +20
                                                                                                                                                +21
                                                                                                                                                +22
                                                                                                                                                +23
                                                                                                                                                +24
                                                                                                                                                +25
                                                                                                                                                +26
                                                                                                                                                +27
                                                                                                                                                +28
                                                                                                                                                +29
                                                                                                                                                +30
                                                                                                                                                +31
                                                                                                                                                +32
                                                                                                                                                +33
                                                                                                                                                +34
                                                                                                                                                +35
                                                                                                                                                +36
                                                                                                                                                +37
                                                                                                                                                +38
                                                                                                                                                +39
                                                                                                                                                +40
                                                                                                                                                +41
                                                                                                                                                +42
                                                                                                                                                +43
                                                                                                                                                +44
                                                                                                                                                +45
                                                                                                                                                +46
                                                                                                                                                +47
                                                                                                                                                +48
                                                                                                                                                +49
                                                                                                                                                +50
                                                                                                                                                +51
                                                                                                                                                +52
                                                                                                                                                +53
                                                                                                                                                +54
                                                                                                                                                +55
                                                                                                                                                +56
                                                                                                                                                +57
                                                                                                                                                +58
                                                                                                                                                +59
                                                                                                                                                +60
                                                                                                                                                +61
                                                                                                                                                +62
                                                                                                                                                import utime
                                                                                                                                                +
                                                                                                                                                +import machine
                                                                                                                                                +from machine import I2C
                                                                                                                                                +from lcd_api import LcdApi
                                                                                                                                                +from pico_i2c_lcd import I2cLcd
                                                                                                                                                +
                                                                                                                                                +I2C_ADDR     = 0x27
                                                                                                                                                +I2C_NUM_ROWS = 2
                                                                                                                                                +I2C_NUM_COLS = 16
                                                                                                                                                +
                                                                                                                                                +def test_main():
                                                                                                                                                +    #Test function for verifying basic functionality
                                                                                                                                                +    print("Running test_main")
                                                                                                                                                +    i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
                                                                                                                                                +    lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)    
                                                                                                                                                +    lcd.putstr("CoderDojo Rocks!")
                                                                                                                                                +    utime.sleep(10)
                                                                                                                                                +    lcd.clear()
                                                                                                                                                +    count = 0
                                                                                                                                                +    while True:
                                                                                                                                                +        lcd.clear()
                                                                                                                                                +        time = utime.localtime()
                                                                                                                                                +        lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format(
                                                                                                                                                +            year=time[0], month=time[1], day=time[2],
                                                                                                                                                +            HH=time[3], MM=time[4], SS=time[5]))
                                                                                                                                                +        if count % 10 == 0:
                                                                                                                                                +            print("Turning cursor on")
                                                                                                                                                +            lcd.show_cursor()
                                                                                                                                                +        if count % 10 == 1:
                                                                                                                                                +            print("Turning cursor off")
                                                                                                                                                +            lcd.hide_cursor()
                                                                                                                                                +        if count % 10 == 2:
                                                                                                                                                +            print("Turning blink cursor on")
                                                                                                                                                +            lcd.blink_cursor_on()
                                                                                                                                                +        if count % 10 == 3:
                                                                                                                                                +            print("Turning blink cursor off")
                                                                                                                                                +            lcd.blink_cursor_off()                    
                                                                                                                                                +        if count % 10 == 4:
                                                                                                                                                +            print("Turning backlight off")
                                                                                                                                                +            lcd.backlight_off()
                                                                                                                                                +        if count % 10 == 5:
                                                                                                                                                +            print("Turning backlight on")
                                                                                                                                                +            lcd.backlight_on()
                                                                                                                                                +        if count % 10 == 6:
                                                                                                                                                +            print("Turning display off")
                                                                                                                                                +            lcd.display_off()
                                                                                                                                                +        if count % 10 == 7:
                                                                                                                                                +            print("Turning display on")
                                                                                                                                                +            lcd.display_on()
                                                                                                                                                +        if count % 10 == 8:
                                                                                                                                                +            print("Filling display")
                                                                                                                                                +            lcd.clear()
                                                                                                                                                +            string = ""
                                                                                                                                                +            for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS):
                                                                                                                                                +                string += chr(x)
                                                                                                                                                +            lcd.putstr(string)
                                                                                                                                                +        count += 1
                                                                                                                                                +        utime.sleep(2)
                                                                                                                                                +
                                                                                                                                                +#if __name__ == "__main__":
                                                                                                                                                +test_main()
                                                                                                                                                +
                                                                                                                                                +

                                                                                                                                                References

                                                                                                                                                +

                                                                                                                                                MFitzp article on OLED displays

                                                                                                                                                +

                                                                                                                                                Adafruit SSD1306 Driver

                                                                                                                                                +

                                                                                                                                                Adafruit LCD Guide

                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                +
                                                                                                                                                + + + +
                                                                                                                                                + + + +
                                                                                                                                                + +
                                                                                                                                                + + + +
                                                                                                                                                + + + +
                                                                                                                                                + + +
                                                                                                                                                +
                                                                                                                                                + + Previous + +
                                                                                                                                                + 8x8 LED Matrix +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + + +
                                                                                                                                                + + Next + +
                                                                                                                                                + 4 Digit LED +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                                + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/displays/non-graph/seven-segment/index.html b/displays/non-graph/seven-segment/index.html new file mode 100644 index 000000000..74e6b71b6 --- /dev/null +++ b/displays/non-graph/seven-segment/index.html @@ -0,0 +1,1686 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 7 Segment Display - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                +
                                                                                                                                                + +
                                                                                                                                                + + + + + + +
                                                                                                                                                +
                                                                                                                                                + + + logo + + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                +
                                                                                                                                                + + + 7 Segment Display + + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + + + + + + + +
                                                                                                                                                + +
                                                                                                                                                +
                                                                                                                                                + + +
                                                                                                                                                + + +
                                                                                                                                                + +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                +
                                                                                                                                                + Initializing search +
                                                                                                                                                +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + +
                                                                                                                                                  + +
                                                                                                                                                  + + +
                                                                                                                                                  +
                                                                                                                                                  + GitHub Repo +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                  + +
                                                                                                                                                  + +
                                                                                                                                                  + + + + + + +
                                                                                                                                                  +
                                                                                                                                                  + + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + + +
                                                                                                                                                  + + +
                                                                                                                                                  + +
                                                                                                                                                  + + +
                                                                                                                                                  +
                                                                                                                                                  + GitHub Repo +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                    + + + + + + + +
                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                    + +
                                                                                                                                                      + + + + + + + +
                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + 7 Segment Display + + + + + + + +
                                                                                                                                                      + + + + + + + +
                                                                                                                                                        + +
                                                                                                                                                      • + + + 4 Digit Seven Segment Display + + + +
                                                                                                                                                      • + +
                                                                                                                                                      + +
                                                                                                                                                      + +
                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                    • + + + + + 10 Bar LEDs + + + + +
                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                    • + + + + + 8x8 LED Matrix + + + + +
                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                    • + + + + + Character LCD + + + + +
                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                    • + + + + + 4 Digit LED + + + + +
                                                                                                                                                    • + + + + +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                  • + + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + +
                                                                                                                                                  + + + + + + + +
                                                                                                                                                    + +
                                                                                                                                                  • + + + 4 Digit Seven Segment Display + + + +
                                                                                                                                                  • + +
                                                                                                                                                  + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + +
                                                                                                                                                  +
                                                                                                                                                  + + + + + + + +

                                                                                                                                                  Sample Seven Segment Display Lab

                                                                                                                                                  +

                                                                                                                                                  4 Digit Seven Segment Display

                                                                                                                                                  +

                                                                                                                                                  4 digit seven segment display

                                                                                                                                                  +

                                                                                                                                                  Make sure to put a current limiting resistor in series with each LED. A 330 ohm resistor is a generally safe value for 5 volt circuits and you can use a 220 ohm resistor for 3.3 volt circuits.

                                                                                                                                                  +

                                                                                                                                                  This code was provided by Jaison Miller from his GitHub Repo.

                                                                                                                                                  +

                                                                                                                                                  ```py +from machine import Pin, PWM, Timer +import utime

                                                                                                                                                  +

                                                                                                                                                  Constants - where the pins are currently plugged into, etc.

                                                                                                                                                  +

                                                                                                                                                  number_bitmaps = { 0: 0b00111111, 1: 0b00000110, 2: 0b01011011, 3: 0b01001111, 4: 0b01100110, 5: 0b01101101, 6: 0b01111101, 7: 0b00000111, 8: 0b01111111, 9: 0b01100111 } +segment_masks = { 'a': 0b00000001, 'b': 0b00000010, 'c': 0b00000100, 'd': 0b00001000, 'e': 0b00010000, 'f': 0b00100000, 'g': 0b01000000 } +pin_segments = { 'a': 10, 'b': 11, 'c': 12, 'd': 17, 'e': 16, 'f': 13, 'g': 14} +pin_others = { 'decimal': 22, 'colon': 6, 'dash': 8 } +pin_digits = { 1: 18, 2: 19, 3: 20, 4: 21 } +pin_control_others = { 'colon': 27, 'dash': 7 }

                                                                                                                                                  +

                                                                                                                                                  initial setup of the pins, alternatives include using PWM to set the brightness

                                                                                                                                                  +

                                                                                                                                                  if not using PWM then make sure to use appropriate resistors to avoid blowing the LEDs in the display (like I have)

                                                                                                                                                  +

                                                                                                                                                  segment_maps = {}

                                                                                                                                                  +

                                                                                                                                                  for segment, pin in pin_segments.items(): + segment_maps[segment] = Pin(pin, Pin.OUT)

                                                                                                                                                  +

                                                                                                                                                  other_pin_maps = {}

                                                                                                                                                  +

                                                                                                                                                  for feature, pin in pin_others.items(): + other_pin_maps[feature] = Pin(pin, Pin.OUT)

                                                                                                                                                  +

                                                                                                                                                  digit_maps = {}

                                                                                                                                                  +

                                                                                                                                                  for digit, pin in pin_digits.items(): + digit_maps[digit] = Pin(pin, Pin.OUT)

                                                                                                                                                  +

                                                                                                                                                  other_maps = {}

                                                                                                                                                  +

                                                                                                                                                  for feature, pin in pin_control_others.items(): + other_maps[feature] = Pin(pin, Pin.OUT)

                                                                                                                                                  +

                                                                                                                                                  def render_digit_display(show_digit=1, number=8, decimal=False):

                                                                                                                                                  +
                                                                                                                                                   1
                                                                                                                                                  + 2
                                                                                                                                                  + 3
                                                                                                                                                  + 4
                                                                                                                                                  + 5
                                                                                                                                                  + 6
                                                                                                                                                  + 7
                                                                                                                                                  + 8
                                                                                                                                                  + 9
                                                                                                                                                  +10
                                                                                                                                                  +11
                                                                                                                                                  +12
                                                                                                                                                  +13
                                                                                                                                                  +14
                                                                                                                                                  +15
                                                                                                                                                  +16
                                                                                                                                                  +17
                                                                                                                                                  +18
                                                                                                                                                  +19
                                                                                                                                                  +20
                                                                                                                                                  +21
                                                                                                                                                  +22
                                                                                                                                                  +23
                                                                                                                                                  +24
                                                                                                                                                  +25
                                                                                                                                                  +26
                                                                                                                                                  +27
                                                                                                                                                  +28
                                                                                                                                                  +29
                                                                                                                                                  +30
                                                                                                                                                  +31
                                                                                                                                                  +32
                                                                                                                                                  +33
                                                                                                                                                  +34
                                                                                                                                                  +35
                                                                                                                                                  # turn everything off
                                                                                                                                                  +for segment, mask in segment_masks.items():
                                                                                                                                                  +    segment_maps[segment].value(1)
                                                                                                                                                  +
                                                                                                                                                  +other_pin_maps['decimal'].value(1)
                                                                                                                                                  +
                                                                                                                                                  +# turn on the digit required to be displayed
                                                                                                                                                  +for digit, digit_pin in digit_maps.items():
                                                                                                                                                  +    if show_digit == digit:
                                                                                                                                                  +        digit_pin.value(1)
                                                                                                                                                  +        # print("\n\nDigit: {} - Pin: {} - Number: {}\n".format(digit, pin, number))
                                                                                                                                                  +    else:
                                                                                                                                                  +        digit_pin.value(0)
                                                                                                                                                  +
                                                                                                                                                  +utime.sleep(0.001)
                                                                                                                                                  +
                                                                                                                                                  +display_number_bitmap = number_bitmaps[number]
                                                                                                                                                  +
                                                                                                                                                  +# check every
                                                                                                                                                  +for segment, mask in segment_masks.items():
                                                                                                                                                  +    # print("segment: {}\nmask: {}".format(segment, mask))
                                                                                                                                                  +
                                                                                                                                                  +    if display_number_bitmap & mask == mask:
                                                                                                                                                  +        # print("segment OFF: {}".format(segment))
                                                                                                                                                  +        segment_maps[segment].value(0)
                                                                                                                                                  +    else:
                                                                                                                                                  +        segment_maps[segment].value(1)
                                                                                                                                                  +
                                                                                                                                                  +# show decimal
                                                                                                                                                  +if decimal:
                                                                                                                                                  +    other_pin_maps['decimal'].value(0)
                                                                                                                                                  +else:
                                                                                                                                                  +    other_pin_maps['decimal'].value(1)
                                                                                                                                                  +
                                                                                                                                                  +utime.sleep(0.001)
                                                                                                                                                  +
                                                                                                                                                  +

                                                                                                                                                  def render_feature_display(show_colon=False, show_dash=False): + if show_colon: + other_pin_maps['colon'].value(0) + other_maps['colon'].value(1) + else: + other_pin_maps['colon'].value(0) + other_maps['colon'].value(0)

                                                                                                                                                  +
                                                                                                                                                  1
                                                                                                                                                  +2
                                                                                                                                                  +3
                                                                                                                                                  +4
                                                                                                                                                  +5
                                                                                                                                                  +6
                                                                                                                                                  if show_dash:
                                                                                                                                                  +    other_pin_maps['dash'].value(0)
                                                                                                                                                  +    other_maps['dash'].value(1)
                                                                                                                                                  +else:
                                                                                                                                                  +    other_pin_maps['dash'].value(0)
                                                                                                                                                  +    other_maps['dash'].value(0)
                                                                                                                                                  +
                                                                                                                                                  +

                                                                                                                                                  while True:

                                                                                                                                                  +
                                                                                                                                                   1
                                                                                                                                                  + 2
                                                                                                                                                  + 3
                                                                                                                                                  + 4
                                                                                                                                                  + 5
                                                                                                                                                  + 6
                                                                                                                                                  + 7
                                                                                                                                                  + 8
                                                                                                                                                  + 9
                                                                                                                                                  +10
                                                                                                                                                  +11
                                                                                                                                                  +12
                                                                                                                                                  +13
                                                                                                                                                  +14
                                                                                                                                                  +15
                                                                                                                                                  +16
                                                                                                                                                  +17
                                                                                                                                                  +18
                                                                                                                                                  +19
                                                                                                                                                  lt_year, lt_month, lt_mday, lt_hour, lt_minute, lt_second, lt_weekday, lt_yearday = utime.localtime()
                                                                                                                                                  +
                                                                                                                                                  +# testing out all the features of the display
                                                                                                                                                  +digit_1_decimal = (lt_second % 4 == 0)
                                                                                                                                                  +digit_2_decimal = (lt_second % 4 == 1)
                                                                                                                                                  +digit_3_decimal = (lt_second % 4 == 2)
                                                                                                                                                  +digit_4_decimal = (lt_second % 4 == 3)
                                                                                                                                                  +
                                                                                                                                                  +render_digit_display(1, lt_minute // 10, digit_1_decimal)
                                                                                                                                                  +render_digit_display(2, lt_minute % 10, digit_2_decimal)
                                                                                                                                                  +render_digit_display(3, lt_second // 10, digit_3_decimal)
                                                                                                                                                  +render_digit_display(4, lt_second % 10, digit_4_decimal)
                                                                                                                                                  +
                                                                                                                                                  +if (lt_second % 2 == 0):
                                                                                                                                                  +    render_feature_display(True, False)
                                                                                                                                                  +else:
                                                                                                                                                  +    render_feature_display(False, True)
                                                                                                                                                  +
                                                                                                                                                  + ```
                                                                                                                                                  +
                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                  +
                                                                                                                                                  + + + +
                                                                                                                                                  + + + +
                                                                                                                                                  + +
                                                                                                                                                  + + + +
                                                                                                                                                  + + + +
                                                                                                                                                  + + +
                                                                                                                                                  +
                                                                                                                                                  + + Previous + +
                                                                                                                                                  + Introduction +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + + +
                                                                                                                                                  + + Next + +
                                                                                                                                                  + 10 Bar LEDs +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                  + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                  + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/docs/advanced-labs/01-intro.md b/docs/advanced-labs/01-intro.md deleted file mode 100644 index e8bd45645..000000000 --- a/docs/advanced-labs/01-intro.md +++ /dev/null @@ -1,16 +0,0 @@ -# Advanced Labs - -This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects. - -Topics include: - -1. Writing Interrupt Handlers -2. Monitoring the internal temperature of your RP2040 CPU -3. Timing the speed of functions for performance optimization -4. Setting up a Conda virtual Python development environment -5. Using operating system functions such as listing files on the file system -6. Scanning for I2C devices -7. Using a framebuffer -8. Using the minicom tool to move files to and from you PC from your microcontroller -9. Reading files from a SD card -10. Converting CircuitPython code and drivers to MicroPython \ No newline at end of file diff --git a/docs/advanced-labs/02-interrupt-handlers.md b/docs/advanced-labs/02-interrupt-handlers.md deleted file mode 100644 index 2026ccc0d..000000000 --- a/docs/advanced-labs/02-interrupt-handlers.md +++ /dev/null @@ -1,188 +0,0 @@ -# Interrupt Handlers in MicroPython - -## What is an Interrupt Handler? -An Interrupt Handler (also called an ISR for Interrupt Service Request) is a special Python function that is called when specific events occur such as a button being pressed. ISRs are the preferred way to detect external events, as opposed to polling methods that are inconsistent and inefficient. However, they are a bit tricky to setup and debug. So a good design should be as simple as possible and avoid using complex features unless you really know you need them. - -## Polling vs. Interrupt Handlers - -So why are ISRs so important? Let's illustrate this is a story. - -Imagine you have 10 friends each with a button at their home. In the polling method you would need to drive to each of their houses and ask them "Is the button get pressed"? You would have to do this frequently in case the button was pressed and released too quickly. This is a slow and painful process and takes a lot of CPU cycles. - -An interrupt handler on the other hand has each friend tell you directly if their button has been pressed. The messages are quick and efficient. They don't use a lot of extra CPU power and the results get handled quickly. - -However, there are specific rules about what we can and can't do within an ISR function. They need to be quick and efficient. We can't wonder off and do crazy things like printing debugging lines within a good ISR. Our job is typically update a global value and finish ASAP. A good ISR should be as efficient as possible. - -## Simple Button Press ISR Example - -This is our first ISR example. It has several parts: - -1. **import statements** - (pretty standard but we have to add the import micropython) -2. **global variables** - we will update these to communicate the result of our ISR -3. **the callback function** - this is the function will be automatically called on a pin event -4. **the button defintion** - this is where we indicate what pin and the PULL_DOWN value -5. **the irq handler** - this is where we associate the event with the callback function -6. **the main loop** - here we only print the button press count if it has changed - -```py -# Use an interrupt function count the number of times a button has been pressed -from machine import Pin -import micropython -import time - -# global value -button_pressed_count = 0 - -# Interrupt Service Routine for Button Pressed Events - with no debounce -def button1_pressed(change): - global button_pressed_count - button_pressed_count += 1 - -# we define button1 as being connected to GP14 and to use the internal Pico PULL_DOWN resistor -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) - -# here is how we associate the falling value on the input pin with the callback function -button1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING) - -button_pressed_count_old = 0 -while True: - if button_pressed_count_old != button_pressed_count: - print('Button 1 value:', button_pressed_count) - button_pressed_count_old = button_pressed_count -``` - -Now if you run this program, you will see that it prints to the Terminal each time the button is pressed and it also tells us how many times the button has been pressed. - -example output: - -``` -Button 1 value: 1 -Button 1 value: 2 -Button 1 value: 3 -Button 1 value: 4 -Button 1 value: 5 -Button 1 value: 6 -Button 1 value: 8 -Button 1 value: 9 -Button 1 value: 10 -Button 1 value: 11 -Button 1 value: 12 -Button 1 value: 13 -Button 1 value: 14 -Button 1 value: 15 -Button 1 value: 16 -Button 1 value: 17 -Button 1 value: 18 -Button 1 value: 19 -Button 1 value: 20 -Button 1 value: 21 -``` - -But if you are careful, you will note something slightly unexpected might happen. I the example above, I actually only pressed the button about 10 times. But the button value is 21! What could be going on here? Could there be a bug in the code? - -The answer is that buttons are not perfect on/off switches. They are essentially noisy on/off devices that may go through a transition of off/on/off/on each time we press the button. - -As a switch goes from open to closed, it moves from a stable state, through an unstable transition state and then it finally arrives at a new stable state. This is illustrated in the drawing below. - -![Debounce Transition State](../img/debounce-transition.png) - -We can reduce this "noise" with a small capacitor next to the button. The capacitor will quickly absorb the energy of the button transition and it will "smooth" out the spikes. This will give us a more consistent readout of the number of button presses and avoid accidental "double presses" that were not intended. - -However, we can also get a clean signal by using software. The key is when we first detect that a transition may be happening we "stop listening" for a short period of time until we are confident that the unstable transition state is over. This is typically around 20 milliseconds, but there may be a few stray signals left. Since we may not have to detect changes more frequently than 5 presses per second, we can go to sleep in our ISR for up to 200 milliseconds. This will give us a nice stable reading from the button. - -These are general rules but for our breadboard mounted momentary switches, the values are appropriate. - -## Debounced Version of a Button Press Detection - -Now let's show you the code that does the hard work of debouncing a signal from a button or switch. - -In this example, our ISR is called ```button_pressed_handler(pin)```. As soon as it is called, it checks the number of milliseconds since it was last called. If the time difference is under 200 milliseconds we are good to go and we update the button_presses global variable. If we are under the 200 millisecond window, we might be in that transition state and we don't do anything. - -```py -new_time = utime.ticks_ms() -# if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time -``` - -The net effect is that the presses variable will ONLY be incremented once, and not multiple times during the transition. Here is the full code: - -```python -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# the lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# this function gets called every time the button is pressed -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses -``` - -## ISR with Deactivation - -Although there are benefits to the simplicity of the code above, some microcontrollers developers suggest that you simply deactivate the IRQ during the debounce sleep. This makes sense since there is two small calculation of the time differences (a subtraction and a compare operation) that do not need to be performed. - -The key lines we add are a deactivate of the IRQ, a sleep for 200 milliseconds and a re-enable of the IRQ after the sleep. Both approaches have worked for me and I will let you decide the tradeoffs. - -```py -import machine, utime - -# the lower right coner has a wire that goes throuh -count_input = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) -presses = 0 - -def count_handler(pin): - global presses - # disable the IRQ during our debounce check - count_input.irq(handler=None) - presses +=1 - # debounce time - we ignore any activity diring this period - utime.sleep_ms(200) - # re-enable the IRQ - count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler) - -count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler) - -old_presses = 0 -while True: - # only print on change - if presses != old_presses: - if presses > old_presses + 1: - print('double counting in irq. Fixing...') - presses = old_presses + 1 - print(presses) - old_presses = presses -``` - -## Debounce Without Disabling the IRQ - - -## References - -1. [MicroPython Documentation on Interrupt Handlers](https://docs.micropython.org/en/latest/reference/isr_rules.html) -2. [A Guide to Debouncing by Jack G. Ganssle](https://my.eng.utah.edu/~cs5780/debouncing.pdf) - this is an excellent reference if you want to know how long to set the debounce intervals for various types of switches. It has lots of transition plots and shows the incredible variation in transition states of switches. In the Summary of the final page, Jack suggest that most low-cost switch denouncers should use a debounce period of between 20 and 50 milliseconds if the users want a fast response. diff --git a/docs/advanced-labs/03-internal-temperature.md b/docs/advanced-labs/03-internal-temperature.md deleted file mode 100644 index d566433df..000000000 --- a/docs/advanced-labs/03-internal-temperature.md +++ /dev/null @@ -1,31 +0,0 @@ -# Using the Builtin Temperature Sensor - -The Raspberry Pi Pico has an internal temperature sensor that can be access using ```machine.ADC(4)```. This might be useful to see if your RP2040 CPY is running "hot" and might benefit from a cooling fan. - -## Reading the temperature -```py -import machine -import utime -sensor_temp = machine.ADC(4) -while True: - reading = sensor_temp.read_u16() * conversion_factor - temperature = 27 - (reading - 0.706)/0.001721 - print(temperature) - print('\n') -``` - -## Logging the Temperature -```py -import machine -import utime -sensor_temp = machine.ADC(machine.ADC.CORE_TEMP) -conversion_factor = 3.3 / (65535) -file = open("temps.txt", "w") -while True: - reading = sensor_temp.read_u16() * conversion_factor - temperature = 27 - (reading - 0.706)/0.001721 - file.write(str(temperature)) - file.flush() - utime.sleep(10) -``` - diff --git a/docs/advanced-labs/03-timing-functions.md b/docs/advanced-labs/03-timing-functions.md deleted file mode 100644 index e78e9e991..000000000 --- a/docs/advanced-labs/03-timing-functions.md +++ /dev/null @@ -1,68 +0,0 @@ -# Timing Functions - -We often need to calculate how much time has elapsed since an event occurred. To to this we can use the ```ticks``` functions in the MicroPython utime library. - -## Microsecond Timer - -There are one million microseconds in a single second. The ```utime``` library allows us to count the number of microseconds that have elapsed since the processor was powered up. - -The following example times the sleep function and measures the difference in the number of clock ticks in microseconds between the two events. - -```py -import machine, utime - -start_time = utime.ticks_us() -# sleep for 1 second -utime.sleep(1) -end_time = utime.ticks_us() - -while True: - print("Start Time:", start_time) - print("End Time:", end_time) - print("Delta Time:", end_time - start_time) - print("") -``` - -results: - -``` -Start Time: 403122147 -End Time: 404122241 -Delta Time: 1000094 - -Start Time: 403122147 -End Time: 404122241 -Delta Time: 1000096 -``` - -You will note that the difference between the start and end time should be one million microseconds. However, the run-time libraries on the pico have some variability, so you will see the actual time vary by a few microseconds. Most of the time you can use milliseconds to compare time intervals. - -## Millisecond Timer - -```py -import machine, utime - -start_time = utime.ticks_ms() -utime.sleep(1) -end_time = utime.ticks_ms() - -while True: - print("Start Time:", start_time) - print("End Time:", end_time) - print("Delta Time:", end_time - start_time) - print("") -``` - -results: - -``` -Start Time: 855845 -End Time: 856845 -Delta Time: 1000 - -Start Time: 858031 -End Time: 859032 -Delta Time: 1001 -``` - -These results are almost always 1000 with an occasional 1001 value. \ No newline at end of file diff --git a/docs/advanced-labs/04-conda-env.md b/docs/advanced-labs/04-conda-env.md deleted file mode 100644 index 680a3febd..000000000 --- a/docs/advanced-labs/04-conda-env.md +++ /dev/null @@ -1,44 +0,0 @@ -# Creating a Conda Environment for MicroPython - -Conda is a powerful tool for building consistent and stable Python environments. These environments include all the Python libraries that you need to be a productive MicroPython developer. Using Conda allows you to keep each of your Python projects cleanly separated. This may not be important on your 2nd or 3rd Python project, but as you do more Python projects you will benefit from isolated environments that each have their own versions of each Python libraries that will not conflict with each other. - -One other important fact to remember is that if you use a conda virtual environment you should never need to use sudo (root) to install Python libraries. This means your installation scripts are more secure and less likely to introduce security problems and accidentally remove libraries that other projects depend on. - -## Getting Started -To get started, it is best to go directly to the [Conda web site](https://docs.conda.io/en/latest/#) and follow the [installation instructions](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) for you specific version of your operating system. There are many variations of installation not just for Windows, Mac and Linux, but each version my had different steps required. - -Once you can open a terminal and type in ```conda --version``` you have successfully installed Conda. For this document we have used conda: - -```sh -conda --version -``` - -which returns: - -``` -conda 4.10.1 -``` - -## Creating Your Conda Environment - -Our fist job is to create a desktop environment that allows us to run Python programs that support the MicroPython development process. - -```sh -conda create -n micropython python=3 -``` - -```sh -conda activate micropython -``` - -After this your prompt should now show that you are in the micropython environment. - -This process may take about five minutes, since all the most current libraries must be downloaded onto your desktop. Once this process finsihes you must remember to deactivate your current conda environment (if you have one and then activate your new micropython environment. - -## References - -## Raspberry Pi Pico Forum on MicroPython Site -[MicroPython Pico Forum](https://forum.micropython.org/viewforum.php?f=21) - -### MicroPython PyCopy (pycopy) -[MicroPython PyCopy](https://github.com/pfalcon/pycopy) \ No newline at end of file diff --git a/docs/advanced-labs/05-os-functions.md b/docs/advanced-labs/05-os-functions.md deleted file mode 100644 index a78d6e2f6..000000000 --- a/docs/advanced-labs/05-os-functions.md +++ /dev/null @@ -1,93 +0,0 @@ -# Raspberry Pi Pico OS Functions - -In the Thonny tool, open the Terminal. At the REPL prompt type: - -```help()``` - -which returns - -```py -help() -``` - -returns - -``` -Welcome to MicroPython! - -For online help please visit https://micropython.org/help/. - -For access to the hardware use the 'machine' module. RP2 specific commands -are in the 'rp2' module. - -Quick overview of some objects: - machine.Pin(pin) -- get a pin, eg machine.Pin(0) - machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p - methods: init(..), value([v]), high(), low(), irq(handler) - machine.ADC(pin) -- make an analog object from a pin - methods: read_u16() - machine.PWM(pin) -- make a PWM object from a pin - methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d]) - machine.I2C(id) -- create an I2C object (id=0,1) - methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True) - readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg) - machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1) - methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf) - machine.Timer(freq, callback) -- create a software timer object - eg: machine.Timer(freq=1, callback=lambda t:print(t)) - -Pins are numbered 0-29, and 26-29 have ADC capabilities -Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT -Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN - -Useful control commands: - CTRL-C -- interrupt a running program - CTRL-D -- on a blank line, do a soft reset of the board - CTRL-E -- on a blank line, enter paste mode - -For further help on a specific object, type help(obj) -For a list of available modules, type help('modules') -``` - -followed by - -help(modules) - -```py -help('modules') -__main__ gc uasyncio/funcs uos -_boot machine uasyncio/lock urandom -_onewire math uasyncio/stream ure -_rp2 micropython ubinascii uselect -_thread onewire ucollections ustruct -_uasyncio rp2 uctypes usys -builtins uarray uerrno utime -cmath uasyncio/__init__ uhashlib uzlib -ds18x20 uasyncio/core uio -framebuf uasyncio/event ujson -``` - -## OS Functions - -```py -import os -print(dir(os)) -``` - -returns - -``` -['__class__', '__name__', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', 'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', 'umount', 'uname', 'urandom'] -``` - -## Real Time Clock - -```py -from machine import RTC - -rtc = RTC() -rtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time -rtc.datetime() # get date and time -``` - -See [MicroPython Real Time Clock](https://docs.micropython.org/en/latest/rp2/quickref.html#real-time-clock-rtc) \ No newline at end of file diff --git a/docs/advanced-labs/06-i2c.md b/docs/advanced-labs/06-i2c.md deleted file mode 100644 index 8d6c83f84..000000000 --- a/docs/advanced-labs/06-i2c.md +++ /dev/null @@ -1,85 +0,0 @@ -# Raspberry Pi Pico I2C - -The Pico has two I2C hardware controllers. Each controller can talk to multiple IIC devices as long as all the devices communicating on each controller have distinct addresses. - -1. I2C0 SDA are on GPIOs 0, 4, 8, 12, 16 and 20 -2. I2C0 SCL are on GPIOs 1, 5, 9, 13, 17 and 21 -3. I2C1 SDA are on GPIOs 2, 6, 10, 14, 18 and 26 -3. I2C1 SCL are on GPIOs 3, 7, 11, 15, 19 and 27 - -## I2C Scanner for I2C 0 - -```py -import machine - -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -print('Scanning I2C bus.') -devices = i2c.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) -``` - -## I2C Scanner for Both I2C 0 and 1 - -```py -import machine - -I2C0_SDA_PIN = 0 -I2C0_SCL_PIN = 1 -I2C1_SDA_PIN = 2 -I2C1_SCL_PIN = 3 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000) -i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000) - -print('Scanning I2C bus 0.') -devices = i2c0.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found on bus 0.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) - -print('Scanning I2C bus 1.') -devices = i2c1.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found on bus 1.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) -``` - -Results for both a OLED display on I2C 0 and a time-of-flight sensor on I2C 1 - -``` -Scanning I2C bus 0. -1 devices found. -Decimal address: 60 , Hex address: 0x3c -Scanning I2C bus 1. -1 devices found. -Decimal address: 41 , Hex address: 0x29 -``` - -## References - -1. [Article on Hackster.io](https://www.hackster.io/mr-alam/how-to-use-i2c-pins-in-raspberry-pi-pico-i2c-scanner-code-8f489f) diff --git a/docs/advanced-labs/07-framebuffer.md b/docs/advanced-labs/07-framebuffer.md deleted file mode 100644 index a98738858..000000000 --- a/docs/advanced-labs/07-framebuffer.md +++ /dev/null @@ -1,5 +0,0 @@ -# Framebuffers in MicroPython - -# References - -[MicroPython.org docs on framebuf](https://docs.micropython.org/en/latest/library/framebuf.html) \ No newline at end of file diff --git a/docs/advanced-labs/08-minicom.md b/docs/advanced-labs/08-minicom.md deleted file mode 100644 index 86a92d8d7..000000000 --- a/docs/advanced-labs/08-minicom.md +++ /dev/null @@ -1,82 +0,0 @@ -# Minicom - -## Installation - -### Installation on a Mac - -```sh -brew install minicom -``` - -### Installation on Linux (Raspberry Pi OS) - -```sh -sudo apt install minicom -``` - -## Verification of Installation - -```sh -which minicom -``` - -``` -/usr/local/bin/minicom -``` - -```sh -minicom --version -``` - -``` -minicom version 2.8 (compiled Jan 4 2021) -``` - -```sh -minicom --help -``` - -returns: -``` -Usage: minicom [OPTION]... [configuration] -A terminal program for Linux and other unix-like systems. - - -b, --baudrate : set baudrate (ignore the value from config) - -D, --device : set device name (ignore the value from config) - -s, --setup : enter setup mode - -o, --noinit : do not initialize modem & lockfiles at startup - -m, --metakey : use meta or alt key for commands - -M, --metakey8 : use 8bit meta key for commands - -l, --ansi : literal; assume screen uses non IBM-PC character set - -L, --iso : don't assume screen uses ISO8859 - -w, --wrap : Linewrap on - -H, --displayhex : display output in hex - -z, --statline : try to use terminal's status line - -7, --7bit : force 7bit mode - -8, --8bit : force 8bit mode - -c, --color=on/off : ANSI style color usage on or off - -a, --attrib=on/off : use reverse or highlight attributes on or off - -t, --term=TERM : override TERM environment variable - -S, --script=SCRIPT : run SCRIPT at startup - -d, --dial=ENTRY : dial ENTRY from the dialing directory - -p, --ptty=TTYP : connect to pseudo terminal - -C, --capturefile=FILE : start capturing to FILE - --capturefile-buffer-mode=MODE : set buffering mode of capture file - -F, --statlinefmt : format of status line - -R, --remotecharset : character set of communication partner - -v, --version : output version information and exit - -h, --help : show help - configuration : configuration file to use - -These options can also be specified in the MINICOM environment variable. -This variable is currently unset. -The configuration directory for the access file and the configurations -is compiled to /usr/local/Cellar/minicom/2.8/etc. - -Report bugs to . -``` - - -## References - -1. [](https://github.com/lilberick/MicroPython/tree/main/RPiPico) \ No newline at end of file diff --git a/docs/advanced-labs/09-micro-sd-card-reader.md b/docs/advanced-labs/09-micro-sd-card-reader.md deleted file mode 100644 index c95ea81fc..000000000 --- a/docs/advanced-labs/09-micro-sd-card-reader.md +++ /dev/null @@ -1,94 +0,0 @@ -# Micro SD Card Reader - -[Secure Digital](https://en.wikipedia.org/wiki/SD_card) (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices. - -On Microcontrollers SD cards are usually access through an [SPI interface](https://en.wikipedia.org/wiki/SD_card#Transfer_modes) although there are also devices that use I2C interfaces. - -## Maker Pi Pico Connections - -| GPIO Pin | SD Mode | SPI Mode | -| -------- | ------- | -------- | -| GP10 | CLK | SCK | -| GP11 | CMD | SDI | -| GP12 | DAT0 | SD0 | -| GP13 | DAT1 | X | -| GP14 | DAT2 | X | -| GP15 | CD/DAT3 | CSn | - -## Maker Pi Pico Example Code - -### Pin Definitions - - -```py - - -# SD Mode Definitions -SDCARD_CLK = 10 -SDCARD_CMD = 11 -SDCARD_DAT0 = 12 -SDCARD_DAT1 = 13 -SDCARD_DAT2 = 14 -SDCARD_CD_DAT3 = 15 - -# SPI Mode Definitions -SDCARD_SCK = 10 -SDCARD_SDI = 11 -SDCARD_SD0 = 12 -SDCARD_X1 = 13 -SDCARD_X2 = 14 -SDCARD_CS = 15 -``` - -### Sample Code for SPI Mode - - -```py -import machine, os, sdcard - -# Assign chip select (CS) pin (and start it high) -cs = machine.Pin(15, machine.Pin.OUT) -# Intialize SPI peripheral (start with 1 MHz) -spi = machine.SPI(1, - baudrate=1000000, - polarity=0, - phase=0, - bits=8, - firstbit=machine.SPI.MSB, - sck=machine.Pin(10), - mosi=machine.Pin(11), - miso=machine.Pin(12)) -# Initialize SD card -sd = sdcard.SDCard(spi, cs) - -# OR this simpler initialization code should works on Maker Pi Pico too... -#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15)) - -os.mount(sd, '/sd') -# check the content -os.listdir('/sd') - -# try some standard file operations -file = open('/sd/test.txt', 'w') -file.write('Testing SD card on Maker Pi Pico') -file.close() -file = open('/sd/test.txt', 'r') -data = file.read() -print(data) -file.close() -``` - -Results: - -``` -Testing SD card on Maker Pi Pico -``` -## References - -1. [MicroPython sdcard.py driver](https://docs.google.com/document/d/1JoHsZk5IipQPCLXWbZYpDKjGlnkyACOJ1[taUrKVsRg8/edit](https://github.com/micropython/micropython/blob/master/drivers/sdcard/sdcard.py)) - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266 -1. [MicroPython.org Documentation](https://docs.micropython.org/en/latest/library/machine.SDCard.html) -2. [Raspberry Pi Pico Forum](https://forums.raspberrypi.com/viewtopic.php?t=307275) -3. [YouTube Video by Shawn Hymel](https://www.youtube.com/watch?v=u-vmsIr-s7w) -4. [Cytron Maker Pi Pico Datasheet](https://docs.google.com/document/d/1JoHsZk5IipQPCLXWbZYpDKjGlnkyACOJ1taUrKVsRg8/edit) -5. [SparkFun microSD Transflash Breakout](https://www.sparkfun.com/products/544) - $4.75 - pins are labeled CD, DO, GND, SCK, VCC, DI and CS -6. [](https://mpython.readthedocs.io/en/master/library/mPython/sdcard.html) \ No newline at end of file diff --git a/docs/advanced-labs/10-converting-circuitpython-to-micropython.md b/docs/advanced-labs/10-converting-circuitpython-to-micropython.md deleted file mode 100644 index a2bced64d..000000000 --- a/docs/advanced-labs/10-converting-circuitpython-to-micropython.md +++ /dev/null @@ -1,97 +0,0 @@ -# Converting CircuitPython to MicroPython - -MicroPython was created in by Australian programmer Damian George in May of 2014. Although Adafruit originally supported MicroPython, in July 2017 Adafruit created a fork of MicroPython and called it *CircuitPython*. We can only speculate why this decisive action was taken, but the result is it divided the community into two incompatible branches and it doubled the amount of work needed to be done to introduce a new device to the Python community. Unfortunately, the consequence is that many programs written in CircuitPython are difficult to port to MicroPython. - -Today, according to [Google Trends](https://trends.google.com/trends/explore?date=today%205-y&q=micropython,circuitpython), MicroPython is still four more popular than CircuitPython when we look at worldwide web search comparisons. However, in the US, the popularity is more equal. Although the claim was that CircuitPython was done for "simplicity" there is little evidence that CircuitPython programs are smaller or easier to maintain than MicroPython. - -The one thing is clear, CircuitPython has lots of drivers for unusual hardware devices. If you find a driver you need in MicroPython you will need to convert it to MicroPython. This is usually done manually on a line-by-line basis. - -## Setting up a CircuitPython Virtual Environment - -Because MicroPython and CircuitPython are incompatible, it is important that you don't intermix your Python libraries. - -Here is how we setup a virtual environment for CircuitPython using [Conda](https://docs.conda.io/en/latest/). - -```sh -conda create -n circuitpython python=3 -conda activate circuitpython -``` - -### Installing the SSD1306 CircuitPython Library - -[Per Directions Here](https://github.com/adafruit/Adafruit_CircuitPython_SSD1306) - -```sh -pip3 install adafruit-circuitpython-ssd1306 -``` - -```sh -pip3 install adafruit-circuitpython-displayio-ssd1306 -``` - -!!! Note - ERROR: Could not find a version that satisfies the requirement adafruit-circuitpython-displayio-ssd1306 - ERROR: No matching distribution found for adafruit-circuitpython-displayio-ssd1306 - - -``` -Successfully installed Adafruit-Blinka-6.3.2 Adafruit-PlatformDetect-3.2.0 Adafruit-PureIO-1.1.8 adafruit-circuitpython-busdevice-5.0.6 adafruit-circuitpython-framebuf-1.4.6 adafruit-circuitpython-ssd1306-2.11.1 pyftdi-0.52.9 pyserial-3.5 pyusb-1.1.1 -``` - -```py -# Basic example of clearing and drawing pixels on a SSD1306 OLED display. -# This example and library is meant to work with Adafruit CircuitPython API. -# Author: Tony DiCola -# License: Public Domain - -# Import all board pins. -from board import SCL, SDA -import busio - -# Import the SSD1306 module. -import adafruit_ssd1306 - - -# Create the I2C interface. -i2c = busio.I2C(SCL, SDA) - -# Create the SSD1306 OLED class. -# The first two parameters are the pixel width and pixel height. Change these -# to the right size for your display! -display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) -# Alternatively you can change the I2C address of the device with an addr parameter: -#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31) - -# Clear the display. Always call show after changing pixels to make the display -# update visible! -display.fill(0) - -display.show() - -# Set a pixel in the origin 0,0 position. -display.pixel(0, 0, 1) -# Set a pixel in the middle 64, 16 position. -display.pixel(64, 16, 1) -# Set a pixel in the opposite 127, 31 position. -display.pixel(127, 31, 1) -display.show() -``` - -## Using ChatGPT to convert CircuitPython to MicroPython - -ChatGPT does a good job of automatically converting CircuitPython to MicroPython. In your prompt you just add the following instruction: - -``` -Convert the following CircuitPython code to MicroPython: -``` - -An example of this working with the basic blink example is shown below: - -![](../img/circuitpython-to-micropython-chatgpt.png) - -## Trend analysis - -As of March 2021, MicroPython is about two to four times more popular than CircuitPython. - -[Google Worldwide Search Trends](https://trends.google.com/trends/explore?date=today%205-y&q=micropython,circuitpython) - diff --git a/docs/advanced-labs/11-mpremote.md b/docs/advanced-labs/11-mpremote.md deleted file mode 100644 index 8b852d45b..000000000 --- a/docs/advanced-labs/11-mpremote.md +++ /dev/null @@ -1,185 +0,0 @@ -# MicroPython Remote - -MicroPython now has a standard format for all remote access. The program -is called [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html). There is -ample documentation on the site, and there is a higher chance it will include the latest features. - -## Why Use MicroPython Remote - -There are three main reasons to use **mpremote**: - -1. Setting up a new device with many device drivers, data files and code. -2. Automatically updating software to get new versions and fix bugs such as security patches. -3. Moving data back and forth from your Pico to and from your host computer or a cloud server on the internet, - - -## List of Commands - -A partial list of the most frequently used commands are: - -1. **connect** - connect to a remote device -2. **disconnect** - disconnect from a remote device -3. **resume** - maintain existing interpreter state for subsequent commands. Useful for multiple REPL commands without soft resets between the commands. -4. **soft_reset** - perform a soft-reset of the device which will clear out the Python heap and restart the interpreter. -5. **repl** - enter the line-at-time REPL Python interpreter loop on the connected device. -6. **eval** - evaluate a string you give as a parameter on the pico using the MicroPython interpreter. -7. **exec** - execute a string and potentially run it in the background. -8. **run** - run a script from the local filesystem on the Pico -9. **fs** - file system commands like copy, move, rename. Examples below. -10. **df** - print size/used/free statistics for teach of the device filesystems -11. **edit** - edit a file locally. This will copy the file to your local file systems, launch your ```$EDITOR``` program and then copy the file back to the Pico. -12. **mip** - intaller. Like pip but it runs on the pico. It install packages from micropython-lib (or GitHub) using the mip tool. This can be useful if you want to automatically upgrade your software and restart the device. If you have a wireless Pico "W" you can get new software directly from the Internet without ever needing a hardline to the Pico. -13. **mount** - mount the local directory on your PC onto the remote device (the Pico). This will allow you to use local files directly from your MicroPython code. -14. **unmount** - unmount a local directory. This happens automatically when mpremote terminates. -15. **rtc** - get or set the real-time clock - useful if you want to keep clocks in sync -16. **sleep** - (delay) n seconds before executing the next command -17. **reset** - hard reset the device. It will then rerun the main.py if it finds it. -18. **bootloader** - This will make the device enter its bootloader mode so it can get an new uf2 file. Useful if you need to upgrade to a new version of MicroPython. - -Note that you can only be connected to one remote device at a time to use many commands. - -## Installing - -The first time: - -```sh -pip install --user mpremote -``` - -```sh -pip install --upgrade --user mpremote -``` - -### Install Log - -I use conda and you can see that it found the mpremote package version 1.20.0 - -```txt -Requirement already satisfied: mpremote in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (1.20.0) -Requirement already satisfied: pyserial>=3.3 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (3.5) -Requirement already satisfied: importlib-metadata>=1.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (4.8.3) -Requirement already satisfied: zipp>=0.5 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.4.0) -Requirement already satisfied: typing-extensions>=3.6.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.7.4.3) -``` - -## Testing the Version - -The version of mpremote is not yet working, but eventually, it will be used like this: - -```sh -$ mpremote --version -``` - -``` -mpremote 0.0.0-unknown -``` - -## Getting Help - -```sh -$ mpremote --help -``` - -### Help Results - -```txt -mpremote -- MicroPython remote control -See https://docs.micropython.org/en/latest/reference/mpremote.html - -List of commands: - connect connect to given device - disconnect disconnect current device - edit edit files on the device - eval evaluate and print the string - exec execute the string - fs execute filesystem commands on the device - help print help and exit - mip install packages from micropython-lib or third-party sources - mount mount local directory on device - repl connect to given device - resume resume a previous mpremote session (will not auto soft-reset) - run run the given local script - soft-reset perform a soft-reset of the device - umount unmount the local directory - version print version and exit - -List of shortcuts: - --help - --version - a0 connect to serial port "/dev/ttyACM0" - a1 connect to serial port "/dev/ttyACM1" - a2 connect to serial port "/dev/ttyACM2" - a3 connect to serial port "/dev/ttyACM3" - bootloader make the device enter its bootloader - c0 connect to serial port "COM0" - c1 connect to serial port "COM1" - c2 connect to serial port "COM2" - c3 connect to serial port "COM3" - cat - cp - devs list available serial ports - df - ls - mkdir - reset reset the device after delay - rm - rmdir - setrtc - touch - u0 connect to serial port "/dev/ttyUSB0" - u1 connect to serial port "/dev/ttyUSB1" - u2 connect to serial port "/dev/ttyUSB2" - u3 connect to serial port "/dev/ttyUSB3"``` -``` - -## Examples of File System Commands - -Here is the syntax of the copy file command: - -```sh -mpremote fs cp main.py :main.py -``` - -This copies the local file "main.py" to your pico. The colon ":" is the root of the pico. - -### Setting Up a UNIX Alias - -If you get tired of typing "mpremote fs cp" you can create an command-line alias called "pcp" for Pico Copy: - -```sh -alias pcp='mpremote fs cp' -``` - -The copy command the becomes simply: - -```sh -pcp main.py :main.py -``` - -If you place this line in your .bashrc or similar shell startup it saves you a lot of typing. - -File systems examples include: - -1. ```cat ``` to show the contents of a file or files on the device -2. ```ls``` to list the current directory -3. ```ls ``` to list the given directories -4. ```cp [-r] ``` to copy files -5. ```rm ``` to remove files on the device -6. ```mkdir ``` to create directories on the device -7. ```rmdir ``` to remove directories on the device -8. ```touch ``` to create the files (if they don’t already exist) - -## Creating Deployment Scripts - -For large classrooms that teach MicroPython using kits, we recommend that you arrange -all the ```mkdir``` and copy (```cp```) file shell commands in a single UNIX shell script for consistency. - -Here are the steps: - -1. Update the Pico with a new image -2. Make a /lib directory using the ```mkdir``` -3. Copy all the drivers for your projects to /lib directory. The drivers you use will be dependent on the hardware you use. For example if your kit has a display you might need to load the ssd1306.py display driver into the /lib directory. -4. Copy the default startup program to the /main.py -5. Have a sequence of "labs" that start with numbers such as 01_blink.py, 02_button.py etc. - -If you follow these steps, then when the students connect to the Pico using Thonny they will see all the labs in the right order from simple to the most complex. \ No newline at end of file diff --git a/docs/advanced-labs/11-os.md b/docs/advanced-labs/11-os.md deleted file mode 100644 index 936c2ebc1..000000000 --- a/docs/advanced-labs/11-os.md +++ /dev/null @@ -1,111 +0,0 @@ -# Sample MicroPython OS functions - -MicroPython provides a small list of [os functions](https://docs.micropython.org/en/latest/library/os.html) that allow you to manipulate files on the local filesystem of a MicroController. - -These functions for filesystem access, and mounting, terminal redirection and duplication, and the uname and urandom functions. - -These commands include: - -* **uname** - get system information such as the release of the runtime and machine type -* **listdir** - list directory -* ilistdir - list all files including low-level i-node statistics -* getcwd - get current working directory -* chdir - change directory -* mkdir - -* **mount/umount** - mount or unmount a remote directory as a local file system -* remove - remove a file -* stat - get statistics about a file or directory -* rmdir - remove a directory - -## UName: Getting System Information - -```python -import os -uname = os.uname() -print(uname) -``` - -Returns: - -```python -( - sysname='rp2', - nodename='rp2', - release='1.19.1', - version='v1.19.1-88-g74e33e714 on 2022-06-30 (GNU 11.2.0 MinSizeRel)', - machine='Raspberry Pi Pico W with RP2040' -) -``` - -Thonny does not easily allow you to delete files. To do this you will need to use the "os" functions. - -```python -import os -os.listdir() -os.remove('myfile') -os.listdir() -``` - -To find out all the os functions use: - -```python -import os -print(dir(os)) -`` - -Returns - -``` -['__class__', '__name__', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', -'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', -'umount', 'uname', 'urandom']` - -## Percent Storage Full and Free RAM - -```python -import gc -import os - -def df(): - s = os.statvfs('//') - return ('{0} MB'.format((s[0]*s[3])/1048576)) - -def free(full=False): - F = gc.mem_free() - A = gc.mem_alloc() - T = F+A - P = '{0:.2f}%'.format(F/T*100) - if not full: return P - else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P)) - -def free-gc(full=False): - gc.collect() - F = gc.mem_free() - A = gc.mem_alloc() - T = F+A - P = '{0:.2f}%'.format(F/T*100) - if not full: return P - else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P)) - -print(df()) - -print(free()) - -print(free-gc()) -``` - -## Machine Clock frequency - -```python -print('Machine Clock Frequency:', '{:,} MHz'.format(machine.freq()/1000000)) -``` - -returns: - -``` -Machine Clock Frequency: 125 MHz -``` - -## References - -https://www.youtube.com/watch?v=jnSX8ZMmHZ4 \ No newline at end of file diff --git a/docs/advanced-labs/11-rshell.md b/docs/advanced-labs/11-rshell.md deleted file mode 100644 index 81188850c..000000000 --- a/docs/advanced-labs/11-rshell.md +++ /dev/null @@ -1,190 +0,0 @@ -# Using rshell on the Raspberry Pi Pico - -!!! Note - MicroPython now has standardized file transfers with the new "MicroPython Remote" or mpremote commands. - See the [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) docs for details. - We will be updating all our documentation to use this standard. - This page is mostly for older systems. - -Using an IDE such as Thonny you can copy many files at a time to the Raspberry Pi Pico by using the GUI. - -However, this process becomes error prone if you want to copy a large number of files. To do this we will use the "remote shell" program from the command line. In our classes we often want to copy a dozen or more files to a new robot for student to try out. - -Rshell was written by David Hyland. The source code and installations are documented on Dave's GitHub repository here: [https://github.com/dhylands/rshell](https://github.com/dhylands/rshell). Dave added support for the Raspberry Pi Pico in release [0.0.30](https://github.com/dhylands/rshell/releases/tag/v0.0.30) in March of 2021. - -Rshell's primary use is to to get filesystem information on the pico (ls), and to copy files to and from MicroPython's filesystem. It can also be used as a terminal to run interactive REPL commands. - - -## Conda Setup - -If you are new to Python and you don't have any previous virtual environments set up you can skip this step. Experienced Python developers have many different environments that they want to keep separated due to library incompatibility issues. Here is how to create a new Python Conda environment that keeps your rshell libraries separated. - -```sh -conda create -n pico python=3 -conda deactivate -conda activate pico -``` - -Your prompt should now indicate you are in the pico environment. - -## Install rshell in your pico environment -We will now use the standard pip installer tool to install the rshell command. - -```sh -python -m pip install rshell -``` - -You can check that rshell has been correctly installed in your command PATH by running the UNIX ```which``` command. - -```sh -which rshell -``` - -## Running shell - -Rshell communicates with the Pico through the USB port. When you plug in the Pico you should see a new file created in the UNIX /dev directory. It typically begins with the letters ```/dev/cu.modem```. One way to test this is to unlpug the pico and run the following command: - -```sh -ls /dev/cu.usbmodem* -``` -With the pico unplugged, there should be no files that match the ls wildcard pattern. However, after you plug in the pico the following should be returned: - -``` -/dev/cu.usbmodem14101 -``` - -This is the port you will use to connect to the pico. We will use the ```-p``` for port option to startup rshell. - -```sh -rshell -p /dev/cu.usbmodem14101 -``` - -``` -Using buffer-size of 128 -Connecting to /dev/cu.usbmodem14101 (buffer-size 128)... -Trying to connect to REPL connected -Retrieving sysname ... rp2 -Testing if ubinascii.unhexlify exists ... Y -Retrieving root directories ... /LCD_SPI.py/ /lcd-spi-test.py/ /lcd-test.py/ /lcd.py/ -Setting time ... Oct 28, 2021 20:30:56 -Evaluating board_name ... pyboard -Retrieving time epoch ... Jan 01, 1970 -Welcome to rshell. Use Control-D (or the exit command) to exit rshell. -``` - -## Boards - -The boards command will list the boards rshell is connected to: - -boards -pyboard @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pyboard/hello.py /pyboard/main.py - -## Listing Files - -We can see that the board is called "pyboard" and you can use that as a path to list the files on the board. - -```sh -ls /pyboard -hello.py main.py -``` - -## Giving Your Board a Name - -rshell will look for a program called board.py when it connects to the board. If this file contains a board name it will use that as the board name the next time it connects to the board. You can use the "echo" command to generate the file. In the example below, we will call our board "pico" - -```sh -echo 'name="pico"' > /pyboard/board.py -``` - -After you use the CONTROL-C and reconnect you will see the following: - -``` -pico @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pico/hello.py /pico/main.py -``` - -Remember you must disconnect from rshell and reconnect before the boards.py function is used. - -For the remainder of this lesson we will assume you have renamed your board "pico". - -You can then type ```cd /pico``` followed by a ```ls``` to see the files on your pico. - -## Entering REPL -You can enter the REPL loop using the ```repl``` command and use the same commands that you used in the Thonny shell. - -``` -repl -print('Hello World!') -``` - -returns - -``` -Hello World! -``` - -## Getting Help on rshell commands - -You can type the ```help``` command to see all the rshell commands: - -``` -help - -Documented commands (type help ): -======================================== -args cat connect date edit filesize help mkdir rm shell -boards cd cp echo exit filetype ls repl rsync - -Use Control-D (or the exit command) to exit rshell. -``` - -## Running Backup - -If you want to copy all the python files from the pico to a backup directory you can use the following command: - -``` -cd /pico -cp *.py /Users/dan/backup -``` - -You will need to create the /Users/dan/backup directory before you do this. You can also use the tilde ```~``` character to stand in for your home directory like this: - -```sh -cp *.py /Users/dan/backup -``` - -Copying '/pico/hello.py' to '/Users/dan/backup/hello.py' ... -Copying '/pico/main.py' to '/Users/dan/backup/main.py' ... - -## Installing files - -If you have a directory called ```~/build``` that contains many files you want to install on the pico file system you can use the following command: - -```sh -cp ~/build/* /pico -``` - -If you have done a clone to the CoderDojoTC micropython repository and put it in your home directory under ~/micropython then following command will copy the python files from the Maker Pi RP2040 kit to your pico: - -```sh -mkdir /pico/lib -cp ~/micropython/src/drivers/*.py /pico/lib -cp ~/micropython/src/kits/maker-pi-rp2040/*.py /pico -cp ~Documents/ws/micropython/src/kits/maker-pi-rp2040-robots/*.py /pico/lib -``` - -Note that the drivers will be placed in the /lob directory. - -## Direct Command Execution - -You do not need to use an interactive session to run a command with rshell. You can just add the command you would like to run to the end of the rshell command like this: - -```sh -rshell -p /dev/cu.usbmodem14101 ls /pico -``` - -returns: - -``` -hello.py main.py -``` - diff --git a/docs/advanced-labs/12-string-formatting.md b/docs/advanced-labs/12-string-formatting.md deleted file mode 100644 index 4e188c27b..000000000 --- a/docs/advanced-labs/12-string-formatting.md +++ /dev/null @@ -1,27 +0,0 @@ -# MicroPython String Formatting - -The normal Python has advanced string formatting functions using "%" and .format methods documented at the [PyFormat](https://pyformat.info/) website. - -Although most of these functions work, there are some exceptions when using date formats. - -The following % formats do **not** work under MicroPython: - -1. %Y - year -1. %m - month -1. %d - day of month -1. %H - hour of day -1. %M - minute - -## Padding Example - -The following example prints a floating point number with two decimals of precision in a field of six characters with leading zeros. - -```python -print('{:06.2f}'.format(3.141592653589793)) -``` - -returns: - -``` -003.14 -``` \ No newline at end of file diff --git a/docs/advanced-labs/13-timers.md b/docs/advanced-labs/13-timers.md deleted file mode 100644 index 9a22e8eb2..000000000 --- a/docs/advanced-labs/13-timers.md +++ /dev/null @@ -1,160 +0,0 @@ -# Timers in MicroPython - -![Timer Tutorial Banner](../img/timer-tutorial-banner.png) -When clocks are used to trigger future events, they are called timers. Timers are used to efficiently use CPU resources. In microcontrollers, the work of keeping track of timers is frequently delegated to hardware outside of the main CPU loop. This makes your microcontroller more efficient, more reliable, and makes your code easier to read. - -Timers work independently of the main CPU's clock. As a result, they are called *asynchronous* objects. Using timers can be both efficient and reliable, but they can be complex to debug. Errors within Timers and interrupts can be difficult to get information on. - -## Types of Timers - -Timers are used to schedule events in the future. There are two types: - -1. A **PERIODIC** timer will continually fire events in the future at periodic intervals. -2. A **ONE_SHOT** timer will fire an event once and then stop. - -Both of these timer objects need a callback function to be specified when they are initialized. These callback functions are also called interrupt service routines (ISRs). This is the function that will be executed when the timer gets triggered. So we must define an ISR function before timers are properly initialized. - -Periodic timers are usually initialized with a `period` parameter. This is the amount of time in milliseconds between each event. They are useful for doing like checking if new data is available on a network connection or checking if a sensor is still working. - -One-shot timers are also initialized with a `period` parameter often called a "timeout" period. This is the amount of time in milliseconds before the timer will fire. One-shot timers are used if you want to do something in the future but don't want to deal with it now. You can think of this as a reminder service. - -Here is how both Periodic and one-shot timers are setup: - -```python -myOneShotTimer = Timer() -# call once in 10 seconds from now -myOneShotTimer.init(mode=Timer.ONE_SHOT, callback=myCallbackFunction, period=10000) - -# call every two seconds until the timer is deactivated -myPeriodicTimer = Timer() -myPeriodicTimer.init(mode=Timer.PERIODIC, callback=myCallbackFunction, period=2000) -``` - -## Using Frequency on Periodic Timers - -A Periodic timer can be configured to use either a period or a frequency as a parameter. The frequency is the number of times the timer will fire per second. The period is the amount of time in milliseconds between each event. The frequency is used to calculate the period. The following are equivalent: - -```python -# 50ms between events -myTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel) -# 20 events per second -myTimer.init(freq=20, mode=Timer.PERIODIC, callback=move_pixel) -``` - -You can always convert between the two by taking the inverse and multiplying by 1000. - -```python -frequency = 1 / period * 1000 -period = 1 / frequency * 1000 -``` - -## Hardware vs. Virtual Software Timers -Older microcontrollers have fixed hardware associated with each timer. These are call "hardware timers". When you initialize a hardware timer, you specify what set of hardware to use using a fixed ID (0,1,2,3 etc.). On the Raspberry Pi Pico all timers are "virtual" and are implemented in software. All virtual timers have an ID of -1 and the timer ID does not need to be specified. - -## Sample Timer Program - -In the following program we will create timer that will toggle the built-in LED on the Raspberry Pi Pico every second. We will create a new function called ```toggle_led()``` that will toggle the builtin LED on and off each time it is called. There are three key lines in this program. - -1. line 1 imports the Timer library -2. line 7 creates the uninitialized timer object -3. line 16 initialize the timer object to indicate how often to trigger the timer, the mode (periodic) and the callback function (toggle_led) - -## Sample Code to Toggle the Builtin LED - -Here is a sample code to toggle the builtin LED on the Raspberry Pi Pico and off. - -```python -from machine import Pin, Timer -from utime import sleep - -# create an LED object using the onboard LED -myLED = machine.Pin("LED", machine.Pin.OUT) - -# create an uninitialized timer object -myTimer = Timer() - -# create a function to be called when the timer goes off -# this function just toggles the onboard LED -def toggle_led(timer): - myLED.toggle() - -# initialize the timer object to tick every second (1,000 milliseconds) -myTimer.init(period=1000, mode=Timer.PERIODIC, callback=toggle_led) - -while True: - sleep(10) - print('just sleeping here') -``` - -## Sample Code to Animate an LED Strip With a Timer - -Many times you want to animate an LED strip but not complicate up your main event loop with this code. For example, you might want to light up the entire strip with a pattern of motion on the LED strip. You can do this by creating a new function that will conditionally turn one pixel to a color and increment a global variable that keeps track of which pixel to turn on. This function will be called every time the timer goes off. - -```python -from machine import Pin, Timer -from utime import sleep -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 8 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# create an uninitialized timer object -myTimer = Timer() - -counter = 0 -# a callback function. Use this with a timer that triggers 20 times a second -def move_pixel(myTimer): - global counter - for i in range(0, NUMBER_PIXELS): - if i == counter: - strip[i] = (10,0,0) - else: - strip[i] = (0,0,10) - strip.write() - counter += 1 - if counter > NUMBER_PIXELS: - counter = 0 - -# initialize the timer object to tick 20 times per second (50 milliseconds) -myTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel) - -while True: - print('Just sleeping here. The timer is doing all the work flashing the LED...', counter) - sleep(5) # sleep for five seconds -``` - -For example, if a robot has a set of "modes" like driving forward, turning left, turning right, backing up etc. You can use a timer to flash the LED strip in different colors with different patterns to indicate the robot is in different modes. - -## Removing a Timer - -The ```Timer.deinit()``` can be used to remove a timer from the system. This is useful if you want to stop a timer that is currently running. If you have many timers that are each using memory, it is a good practice to remove them when you are done with them. - -## Limits on the Number of Timers - -In MicroPython on the RP2040, there are no limits placed on the number of timers other than you must have enough memory available. Because there are no specific hardware limits, these are often referred to as "virtual" timers. The number of virtual timers is limited by the amount of memory available to the microcontroller. - -Other implementations of MicroPython on different hardware have stricter limits placed on the number of timers. The ESP32 MicroPython port currently only has four hardware timers and a numeric ID of 0 to 3 must be used when you setup these timers. For the [pyboard](https://docs.pyboard.org/en/latest/timers.html) has a limit of 14 timers. Be aware of these limits if you are interested in creating portable MicroPython code. - -## Drawbacks of Timers and ISRs - -Unfortunately, different hardware implementations of MicroPython have different ways to setup and use timers. Some hardware requires timers to each have an ID tied to a specific resource. Because of this, be cautious about using timers in your code if you require portability between hardware. - -As we mentioned, timers need callback functions are a type of function called interrupt service requests (ISRs). In multi-core systems like the RP2040 these interrupts can only be called from the core that executed the timer. This means that if you are using a timer to trigger an interrupt, you must make sure that the interrupt is only called from the core that is executing the timer. - -There are special limitations on what can and can't be done within interrupts in most systems. For example, you are not allowed to allocate dynamic memory within an interrupt. Your interrupt handler should be a short function that performs the minimum work to change external variables. This is because the interrupt handler is called in a separate thread and can't allocate memory. - -In general, doing complex logic within timers and interrupts is not a good idea. If you are interested in doing complex logic, you should use a different method that is easy to debug. This will make your code easier to understand and maintain. - -## Exercises - -1. Can you change the frequency of the times in the sample code above? -2. How much memory do you think a timer will use? How many timers can be used on a RP2040 with 264K of memory? -3. What if you wanted a timer to check in on the health of your program? Could it reboot the Raspberry Pi using ```machine.reset()``` if it gets stuck? Hint: See [Watchdog Timers](https://docs.micropython.org/en/latest/library/machine.WDT.html) - - -## References - -1. [MicroPython Timers](https://docs.micropython.org/en/latest/library/machine.Timer.html) -1. [MicroPython Documentation on Timers on the RP2040](https://docs.micropython.org/en/latest/rp2/quickref.html) -2. [Engineers Garage on Time and Timers in MicroPython](https://www.engineersgarage.com/micropython-time-related-functions-timers-interrupts-in-esp8266-and-esp32/) \ No newline at end of file diff --git a/docs/advanced-labs/14-memory-management.md b/docs/advanced-labs/14-memory-management.md deleted file mode 100644 index fe455d115..000000000 --- a/docs/advanced-labs/14-memory-management.md +++ /dev/null @@ -1,154 +0,0 @@ -# Memory Management in MicroPython - -In the recent past, memory management has been a challenge for embedded systems. Before 2020 microcontrollers like the Arduino usually only came with a few kilobytes of RAM, and careful attention needed to be paid to each byte using clever memory management trickery. The memory management system in recent years has become much easier. Even a low-cost $4 Raspberry Pi Pico now comes with 264K RAM! This is an almost 100-fold increase over the older Arduino Uno which only had 2K of RAM. That being said, there are always developers that push their hardware to the limit, and knowing the basics of memory management is important to understand how embedded systems work. - -MicroPython is very clever about how memory is allocated. It is very stingy about memory use and will only allocate memory for what is needed. This is very different from the standard Python that allocates memory for everything that is needed up-front assuming that most laptops, desktops and servers have gigabytes of RAM and virtual memory support. This is an important difference, and it is important to understand if you want to push the limits of your microcontroller. - -This lab will cover the basics of memory management, and how to use the memory management system in MicroPython. -We will cover the following topics: - -1. Memory Management Concepts: The Heap, Stack, and Garbage Collection -2. Functions to show the amount of free and used memory and current memory usage -3. Functions to manually allocate and free memory -4. Functions to debug memory allocation - -## Memory Management Concepts - -![Memory Heap Stack](../img/memory-heap-stack.png) - -The **memory management system** is responsible for allocating and freeing memory. The memory management system must allocate memory for data variables, and for freeing this memory when a variable is no longer needed. The system is also responsible for allocating memory for the parameters used by functions, and for freeing memory when a function is no longer needed. You can read more about memory management on the [MicroPython Memory Management Docs](https://docs.micropython.org/en/latest/develop/memorymgt.html) website. - -The **heap** is the area of memory that is used to store general data. In MicroPython the heap is located in the lower memory and it grows upwards in memory address space. The exception is memory used as parameters to functions, which is stored in the stack. - -The **stack** is the area of memory that is used to store all the parameters to function calls. In MicroPython the stack is located in the upper memory and it grows downwards in memory address space. If you are calling highly recursive functions, the stack will get a lot of use. - -The **garbage collector** is a process to reuse memory that is no longer in use. The garbage collector is automatically run when the heap is full, but you can also run it manually to reclaim unused memory to get finer-grain control over memory usage and to avoid memory fragmentation. - -In MicroPython most of these operations are done automatically for you. You don't really need to worry about how memory works unless you are reaching the limits of what your microcontroller can do. - -One other key concept is **continuous memory**. If you are allocating a large amount of memory in an array or a long string, we need to allocate all this memory in one large chunk. As programs run for a long time memory becomes **fragmented** (many small free sections) and can't be used for storing large arrays. - -You can read more about how MicroPython is clever about memory usage by reading the [MicroPython Optimizations Docs](https://docs.micropython.org/en/latest/develop/optimizations.html) website. - -## Functions to show free and used memory - -We will be using the "gc" module to show the amount of free and used memory. "gc" orignally stood for "garbage collection", but the model has been generalized to perform other memory management tasks. - -Here are the key functions to show the amount of free and used memory and current memory usage on a Raspberry Pi Pico with an RP2040 microcontroller: ```gc.mem_free()``` and ```gc.mem_alloc()```: - -```python -import gc -import micropython - -print('Memory Free:', "{:,}".format(gc.mem_free()), 'bytes') -print('Memory Allocated:', "{:,}".format(gc.mem_alloc()), 'bytes') -``` - -results for RP2040: - -``` -Memory Free: 187,232 bytes -Memory Allocated: 4,864 bytes -``` - -You can see that although the RP2040 chip has a specification of 264K of RAM, it only has 187,232 bytes of RAM available for program use. The other RAM us used to store the MicroPython interpreter software. You can also see that the heap is currently using 4,864 bytes of RAM. This is typical of the additional overhead that MicroPython requires to run a program. - -### Viewing Memory Layout - -You can use the ```micropython.mem_info(1)``` function to view the memory layout of the MicroPython interpreter. This function returns a list of tuples, each tuple containing the address, size and type of each memory block. The address on the left of each row is the memory address of the start of the block within the heap. In MicroPython, memory blocks are each typically 16 bytes. - -```python - -```python -import micropython -print(micropython.mem_info(1)) -``` - -results: -``` -stack: 532 out of 7936 -GC: total: 192064, used: 4896, free: 187168 - No. of 1-blocks: 52, 2-blocks: 13, max blk sz: 64, max free sz: 11650 -GC memory layout; from 200084a0: -00000: h=MhhhBDhhBTTBDhTBDBBBh===DBDh====B=BBBBBBTB=BTB=BBBTB=TBTB=Bh== -00400: =BB=h===========TB=h=h===================h=====h==h============= -00800: ====h=========================================================== -00c00: ====h=========================================================== -01000: ====h=hBhh=ShhS..h=.........Sh=................................. -01400: ....Shh=======h========h====h=====.............................. - (181 lines all free) -2ec00: .................................... -None -``` - -This shows that the garbage collector is responsible for managing a total of 192,064 bytes of memory. The other numbers give you an indication of how fragmented you heap is. - -* The number of 1-blocks is 52 -* The number of 2-block spaces is 13 -* The maximum block size is 64 -* The maximum free size is 11,650 -* The heap starts at memory location: 2000 84a0 - -Each of the letters represents the type of memory at that position on the heap: - -| Letter | Description | -|_|_| -|.|Free memory| -|h|head of a block of memory| -|=|tail of a block of memory| -|T|Tuple| -|L|List| -|D|Dictionary| -|S|String| -|A|Array or Byte Array| -|F|Float| -|B|Function BC| -|M|Module| - -If the heap is 192,064 bytes and each block is 16 bytes then there should be 12,004 blocks on the heap. If each row in the report displays 62 characters then there are 12,004/62=193 rows in the report. To keep the report short, the function will only show the rows that are not free. The report indicates that there are 181 lines all free blocks, so it will only show the non-free lines which in the example above is about six non-free rows in lower heap memory. - -## Functions to manually allocate and free memory - -You can manually run the garbage collector using the ```gc.collect()``` functions. This function is used to force garbage collection exactly when you want to, not when the heap is full. This may occur at a time that is inconvenient for the program when it must be sending data at a specific speed. - -!!! Note - Still under development. - -```python -import gc -import micropython - -def show_memory(): - print('Memory Free:', "{:,}".format(gc.mem_free()), 'bytes') - print('Memory Allocated:', "{:,}".format(gc.mem_alloc()), 'bytes') - -show_memory() -# allocate a block of memory -print('Allocating a block of memory') -myBigBlockOfMemory = matrix[100][100] -show_memory() -print('Freeing the block of memory') -# free the block of memory -gc.mem_free(ptr) -show_memory() -``` - -## Image Size - -You can determine how much space we have available on the Pico flash after programming an ELF or UF2 file. For example, if we have an ELF file that's 1 MB and we were to program via openocd, then where should we offset my user data in flash? (i.e. XIP_BASE + OFFSET) - -With an elf or uf2 file, using ```picotool info -a``` on it will show the start and end of the binary (the start is usually 0x10000000 unless you did something to change it). - -Inside your code, you can use the symbols defined by the linker script __flash_binary_start (defined here) and __flash_binary_end (defined here) like this: - -```c -extern char __flash_binary_start; // defined in linker script -extern char __flash_binary_end; // defined in linker script -uintptr_t start = (uintptr_t) &__flash_binary_start; -uintptr_t end = (uintptr_t) &__flash_binary_end; -printf("Binary starts at %08x and ends at %08x, size is %08x\n", start, end, end-start); -``` - -## References - -* [Code that Prints Memory Block Types](https://github.com/micropython/micropython/blob/fabaa6143745cf09928dfc13367ddc91e0eb9ad2/py/gc.c#L837-L856) \ No newline at end of file diff --git a/docs/advanced-labs/15-measuring-vsys.md b/docs/advanced-labs/15-measuring-vsys.md deleted file mode 100644 index 21f7d9f72..000000000 --- a/docs/advanced-labs/15-measuring-vsys.md +++ /dev/null @@ -1,19 +0,0 @@ -# Measuring VSys - -You need to set GP25 to output and set it high and also set GP29 to input with no pull resistors before reading. -And don't forget that the input from VSYS to ADC is divided by 3, so you have to multiply your result to get real value. -When I do that I get around 4.7 V when powered from USB, so it definitely works. - -https://forums.raspberrypi.com/viewtopic.php?t=301152 - -```py -import machine - -# Vsys = machine.ADC(3) -Vsys = machine.ADC(29) -conversion_factor = (3.3 / (65535)) * 3 - -reading = Vsys.read_u16() * conversion_factor - -print(reading) -``` diff --git a/docs/advanced-labs/16-dual-core.md b/docs/advanced-labs/16-dual-core.md deleted file mode 100644 index 870d65d33..000000000 --- a/docs/advanced-labs/16-dual-core.md +++ /dev/null @@ -1 +0,0 @@ -https://circuitdigest.com/microcontroller-projects/dual-core-programming-on-raspberry-pi-pico-using-micropython \ No newline at end of file diff --git a/docs/advanced-labs/17-file-system.md b/docs/advanced-labs/17-file-system.md deleted file mode 100644 index e1ddb81cd..000000000 --- a/docs/advanced-labs/17-file-system.md +++ /dev/null @@ -1,74 +0,0 @@ -# MicroPython File Systems - -Unlike older Arduino systems, MicroPython has full support for a "virtual file system" (VFS) that we use to store and retrieve programs and data. The way we access the file systems in MicroPython -is similar to the way we access files in standard Python. - -## Blocks and Fragments - -First, we need to define two key terms: blocks and fragments. - -The block size refers to the size of the fundamental unit of storage on the file system. All files and directories occupy an integral number of blocks, with the size of each file and directory being a multiple of the block size. The block size is typically a power of 2, and can vary depending on the file system and the size of the storage medium. - -The fragment size, on the other hand, refers to the smallest unit of space that can be allocated for a file or directory. Files and directories may occupy a number of fragments that is not necessarily an integer multiple of the fragment size. Fragmentation occurs when the file system is unable to allocate a contiguous block of storage for a file or directory, resulting in the file or directory being spread out over multiple fragments. The fragment size is typically smaller than the block size, and may also vary depending on the file system and the size of the storage medium. - -## File Systems Statistics - -In MicroPython, the [os.statvfs('/')](https://docs.micropython.org/en/latest/library/os.html?highlight=os#os.statvfs) function provides information about the root file system. Among the information it provides is the block size and fragment size of the file system. - -In the ```os.statvfs('/')``` function, the block size and fragment size are reported as the first and second elements of the tuple returned by the function, respectively. Specifically, stats[0] contains the block size, and stats[1] contains the fragment size. These values can be used to calculate various file system statistics, such as the total size of the file system, the total number of blocks and fragments, and the amount of free space available. - -You can also mount file systems on other flash drives. You can get the stats of these file systems by using the new mount point with the ```os.statvfs()``` function. - -## Using Statvfs - -```py -""" -Print the statistics from the virtual file system (vfs) - -https://docs.micropython.org/en/latest/library/os.html?highlight=os#os.statvfs - -0 f_bsize – file system block size -1 f_frsize – fragment size -2 f_blocks – size of fs in f_frsize units -3 f_bfree – number of free blocks -4 f_bavail – number of free blocks for unprivileged users -5 f_files – number of inodes -6 f_ffree – number of free inodes -7 f_favail – number of free inodes for unprivileged users -8 f_flag – mount flags -9 f_namemax – maximum filename length -""" - -import os - -stats = os.statvfs("/") -print(stats) - -block_size = stats[0] -fragment_size = stats[1] -total_blocks = stats[2] - -free_blocks = stats[3] -available_blocks = stats[4] - -mount_flags = stats[8] -max_filename_length = stats[9] - -# byte calculations -total_bytes = total_blocks * fragment_size -free_bytes = free_blocks * fragment_size -available_bytes = available_blocks * fragment_size - -print("File system block size: {:,} bytes".format(block_size)) -print("Fragement size: {:,} bytes".format(fragment_size)) -print("Size of entire file system in fragement blocks: {:,}".format(total_blocks)) -print("Size of entire file system in bytes: {:,}".format(total_bytes)) - -print("Total free blocks for system and users: {:,}".format(free_blocks)) -print("Number of free blocks for unprivileged users: {:,} bytes".format(available_blocks)) - -print("Free size for system and users: {:,} bytes".format(free_bytes)) -print("Free size for users: {:,} bytes".format(available_bytes)) -print("Mount flags: {:,}".format(mount_flags)) -print("Max filename length: {:,}".format(max_filename_length)) -``` \ No newline at end of file diff --git a/docs/advanced-labs/20-tinyml.md b/docs/advanced-labs/20-tinyml.md deleted file mode 100644 index 2c63ffa21..000000000 --- a/docs/advanced-labs/20-tinyml.md +++ /dev/null @@ -1,9 +0,0 @@ -# TinyML - -TinyML is designed to help you do machine learning and embedded systems. Once you have trained a deep learning model, you can use TinyML perform data analysis (inference) on a microcontroller or a cell phone. - -## References -* [UCTRONICS RP2040 Dev Board for TinyMLd](https://www.tindie.com/products/uctronics/rp2040-dev-board-for-tinyml-arducam-pico4ml/) - $50.00 US -* [Harvard Fundamentals of TinyML Course](https://pll.harvard.edu/course/fundamentals-tinyml) - free without certificate. -* [EMLearn GitHub Repo for Machine Learning](https://github.com/emlearn/emlearn-micropython/) -* [EMLearn YouTube Video](https://www.youtube.com/watch?v=S3GjLr0ZIE0) \ No newline at end of file diff --git a/docs/advanced-labs/21-botton-callback.md b/docs/advanced-labs/21-botton-callback.md deleted file mode 100644 index e6d30affd..000000000 --- a/docs/advanced-labs/21-botton-callback.md +++ /dev/null @@ -1,24 +0,0 @@ -# Button Callback - -```py -import re - -def extract_gpio_pin(input_string): - # Use a regular expression to find the GPIO number - match = re.search(r"GPIO(\d+)", input_string) - if match: - # Convert the extracted number to an integer to remove leading zeros - return int(match.group(1)) - else: - # Return None if no match is found (or raise an exception if that's preferable) - return None - -# Test the function with examples -print(extract_gpio_pin("Pin(GPIO15, mode=IN, pull=PULL_UP)")) # Output: 15 -print(extract_gpio_pin("Pin(GPIO7, mode=IN, pull=PULL_UP)")) # Output: 7 -print(extract_gpio_pin("Pin(GPIO03, mode=IN, pull=PULL_UP)")) # Output: 3 - -``` - - -https://chat.openai.com/share/6e6d8123-ed4d-4dc6-a915-030fe2245dfe \ No newline at end of file diff --git a/docs/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound.md b/docs/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound.md deleted file mode 100644 index 72ec245c7..000000000 --- a/docs/advanced-labs/30-spectrum-analyzer/01-test-incoming-sound.md +++ /dev/null @@ -1,93 +0,0 @@ -# Test Incoming Sound - -## Prompt - -```linenums="0" -OK, I now have a Raspberry Pi Pico and the OLED display hooked up. I also have a microphone hooked up to ADC0 on port GPIO26. How can I test that the signal is coming into the ADC? Can you write a MicroPython program that displays the audio signal on the OLED? - -I am using a ssd1306 and I use the following MicroPython: -``` - -```python -from machine import Pin -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -# clear the display -display.fill(0) -# draw a diagonal line -display.line(0, 0, WIDTH, HEIGHT, 1) -``` - -## GPT-4 Reponse - -To test that the signal is coming into the ADC (Analog-to-Digital Converter) on the Raspberry Pi Pico via GPIO26, and to display the audio signal on your SSD1306 OLED, you can use the following MicroPython script. This script will read the analog values from the microphone connected to GPIO26 and plot these values in real-time on the OLED display, creating a simple waveform visualization. - -Note: Before running this script, ensure you have properly initialized and connected your microphone to GPIO26 (ADC0), and the OLED display is correctly wired for SPI communication as per your provided initialization. - -```python -import machine -import utime -from machine import Pin, ADC, SPI -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for GPIO26 (ADC0) -adc = ADC(Pin(26)) - -def plot_signal(): - display.fill(0) # Clear the display - old_x = 0 - old_y = HEIGHT // 2 - - # For simplicity, we're plotting every other pixel - for x in range(0, WIDTH, 2): - # Read from ADC (values will be from 0 to 4095) - val = adc.read_u16() - # Scale the ADC value to fit the OLED height - y = int((val / 65535) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - # Draw a line from the last point to the new point - display.line(old_x, old_y, x, y, 1) - old_x, old_y = x, y - - display.show() # Update the display with the new data - -while True: - plot_signal() - utime.sleep(0.1) # Small delay to reduce flickering -``` - -This script continuously reads the analog signal from the microphone and plots a simplified version of the waveform across the OLED display. Here's a breakdown of the plotting part: - -- The screen is cleared at the beginning of each frame with `display.fill(0)`. -- We read a value from the ADC and scale it to fit the OLED's screen height. -- We draw a line from the previous point to the current point to create a continuous waveform. -- The display is updated with `display.show()` to visualize the waveform. - -This example provides a basic way to visualize audio signals. The resolution and quality of the visualization can be further enhanced or adjusted according to your requirements. diff --git a/docs/advanced-labs/30-spectrum-analyzer/02-gain-pot.md b/docs/advanced-labs/30-spectrum-analyzer/02-gain-pot.md deleted file mode 100644 index 7ef9dd584..000000000 --- a/docs/advanced-labs/30-spectrum-analyzer/02-gain-pot.md +++ /dev/null @@ -1,69 +0,0 @@ -# Adding A Gain Potentiometer. - -## Prompt -The signal is very low on the display. I have added a Potentiometer on ADC1 which is on GPIO PIN 27. Can you please regenerate the entire program with sound on ADC0 and gain on ADC1. sound = ADC(Pin(26)) gain = ADC(Pin(27)) - - -## ChatGPT- - -Certainly! To adjust the signal's amplitude on the display based on the gain from a potentiometer connected to ADC1 (GPIO PIN 27), you can modify the program as follows. This updated script will use the value from the potentiometer to scale the audio signal from the microphone, making the waveform larger or smaller on the OLED display according to the potentiometer's position. - -```python -import machine -import utime -from machine import Pin, ADC, SPI -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for sound input (GPIO26) and gain control (GPIO27) -sound = ADC(Pin(26)) -gain = ADC(Pin(27)) - -def plot_signal_with_gain(): - display.fill(0) # Clear the display - old_x = 0 - old_y = HEIGHT // 2 - - # Read gain control (potentiometer) value - gain_value = gain.read_u16() + 1 # Adding 1 to avoid division by zero - - for x in range(0, WIDTH, 2): - # Read from ADC (sound input) - val = sound.read_u16() - - # Adjust the sound value based on the gain - # Note: This scaling might need adjustment depending on your specific potentiometer and desired sensitivity - adjusted_val = min(((val * gain_value) >> 16), 65535) # Ensure the adjusted value does not exceed ADC's max value - - # Scale the adjusted value to fit the OLED height - y = int((adjusted_val / 65535) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - # Draw a line from the last point to the new point - display.line(old_x, old_y, x, y, 1) - old_x, old_y = x, y - - display.show() # Update the display with the new data - -while True: - plot_signal_with_gain() - utime.sleep(0.1) # Small delay to reduce flickering -``` - -In this script, the gain control (potentiometer) reading is used to adjust the amplitude of the sound signal before plotting it. The `gain_value` is read from ADC1 and is used to scale the audio signal from the microphone connected to ADC0. The line `adjusted_val = min(((val * gain_value) >> 16), 65535)` scales the microphone input based on the potentiometer's position, and the bit shift `>> 16` is used to keep the value within the 16-bit range of the ADC's output. - -This method should help make the displayed signal more responsive to the potentiometer's adjustments, allowing you to visually enhance or reduce the waveform amplitude on the OLED display. \ No newline at end of file diff --git a/docs/advanced-labs/30-spectrum-analyzer/03-display-scroll.md b/docs/advanced-labs/30-spectrum-analyzer/03-display-scroll.md deleted file mode 100644 index f92e5c01d..000000000 --- a/docs/advanced-labs/30-spectrum-analyzer/03-display-scroll.md +++ /dev/null @@ -1,46 +0,0 @@ -# Display Scroll - -## Prompt - -```linenums="0" -The display is a bit slow. Can you rewrite the plot\_signal\_with\_gain function so that the scroll() function is used to move the display to the left by one pixel? -``` - -### ChatGPT GPT-4 Response - -To make the display update faster and to create a scrolling effect that moves the waveform to the left by one pixel, you can modify the `plot_signal_with_gain` function to use the `scroll()` method of the SSD1306 library. This will shift the entire display content to the left by one pixel, and then you can plot the new data point at the right edge of the display. Here's how you can implement this: - -```python -def plot_signal_with_gain(): - # Scroll the display content to the left by one pixel - display.scroll(-1, 0) - - # Read gain control (potentiometer) value - gain_value = gain.read_u16() + 1 # Adding 1 to avoid division by zero - - # Read from ADC (sound input) - val = sound.read_u16() - - # Adjust the sound value based on the gain - adjusted_val = min(((val * gain_value) >> 16), 65535) # Ensure the adjusted value does not exceed ADC's max value - - # Scale the adjusted value to fit the OLED height - y = int((adjusted_val / 65535) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - - # Since we've scrolled, we only need to update the last column (x = WIDTH - 1) - # Clear the last column first (optional, depending on the desired visual effect) - for clear_y in range(HEIGHT): - display.pixel(WIDTH - 1, clear_y, 0) - - # Draw the new data point at the right edge of the display - display.pixel(WIDTH - 1, y, 1) - - # Update the display with the new data - display.show() -``` - -In this updated function, the display is scrolled left by one pixel at the beginning of each update cycle using `display.scroll(-1, 0)`. This creates room to draw the new data point at the far right edge (`WIDTH - 1`) of the display. The loop that clears the last column before drawing the new point is optional and can be adjusted or removed depending on the visual effect you're aiming for. - -Remember, while `scroll()` improves the visual fluidity by creating a continuous scrolling effect, the update rate can still be limited by the display's physical refresh rate and the speed at which your MicroPython script can run. Experiment with the `utime.sleep(0.1)` delay at the end of the main loop to find a balance between smoothness and speed that works for your specific application. \ No newline at end of file diff --git a/docs/advanced-labs/30-spectrum-analyzer/index.md b/docs/advanced-labs/30-spectrum-analyzer/index.md deleted file mode 100644 index 9ac73ed37..000000000 --- a/docs/advanced-labs/30-spectrum-analyzer/index.md +++ /dev/null @@ -1,55 +0,0 @@ -# Spectrum Analyzer - -## ChatGPT Prompt - -```linenums="0" -I would like to create an audio spectrum analyzer using a Raspberry Pi Pico and a 128x64 OLED display using MicroPython. How would you suggest I go about this project. Break it down step-by-step. -``` - -## ChatGPT GPT-4 Response - -Creating an audio spectrum analyzer with a Raspberry Pi Pico and a 128x64 OLED display using MicroPython is a fascinating project that combines hardware interfacing with digital signal processing. Below is a step-by-step guide to help you get started on this project. - -### Step 1: Gather the Components - -1. **Raspberry Pi Pico**: A microcontroller board based on the RP2040 microcontroller chip. -2. **128x64 OLED Display**: This will be used for visualizing the audio spectrum. Ensure it's compatible with the Pi Pico, ideally one that communicates over I2C or SPI. -3. **Electret Microphone Amplifier**: This captures the audio signals. A module like the MAX4466 or a similar one would be suitable. -4. **Jump Wires**: For connecting the components. -5. **Breadboard**: Useful for prototyping without soldering. -6. **USB Cable**: For programming the Raspberry Pi Pico. - -### Step 2: Set Up the Raspberry Pi Pico - -1. **Install MicroPython**: Download and flash MicroPython onto the Raspberry Pi Pico. The Raspberry Pi Pico documentation provides clear instructions for this process. -2. **Prepare Your Development Environment**: Install any necessary drivers and a code editor that supports MicroPython, such as Thonny or Visual Studio Code with the appropriate extensions. - -### Step 3: Connect the Hardware - -1. **Microphone to Pi Pico**: Connect the output of the electret microphone amplifier to one of the analog input pins of the Pi Pico. Also, connect the ground and Vcc pins accordingly. -2. **OLED Display to Pi Pico**: Connect the OLED display to the Pi Pico using I2C or SPI, depending on your display module. For I2C, you'll need to connect SDA, SCL, Vcc, and GND. For SPI, the connections will include SCK, MOSI, RES, DC, CS, Vcc, and GND. - -### Step 4: Write the Software - -1. **Initialize the OLED Display**: Write or adapt a MicroPython script to initialize the OLED display using the appropriate library. There are libraries available for both I2C and SPI OLED displays in MicroPython. -2. **Capture Audio Data**: Write a script to capture audio data from the microphone using the ADC (Analog to Digital Converter) of the Pi Pico. The data capture should be done in real-time, and you may need to experiment with sampling rates. -3. **Process Audio Data**: Implement a Fast Fourier Transform (FFT) algorithm to convert the time-domain audio signals into the frequency domain. This step is crucial for creating the spectrum analysis. -4. **Visualize the Spectrum**: Map the frequency domain data to the OLED display. You will likely need to scale the data to fit nicely on the 128x64 display, representing different frequencies and their intensities. - -### Step 5: Testing and Troubleshooting - -1. **Run Your Script**: Test the entire system by running your script. You may need to adjust the audio capture settings or the way the data is visualized on the OLED display. -2. **Troubleshoot**: If you encounter issues, use serial print statements to debug and understand where things might be going wrong. - -### Step 6: Refinement and Expansion - -1. **Refine the Display**: You can refine how the audio spectrum is displayed, perhaps by adjusting the resolution, colors (if your OLED supports it), or adding additional visual elements like peak hold. -2. **Experiment with Features**: Consider adding features such as different modes for the spectrum analyzer, audio input from different sources, or even a GUI for interacting with the device. - -### Resources - -- **MicroPython Documentation**: Essential for understanding how to program the Raspberry Pi Pico. -- **FFT Libraries**: Look for MicroPython libraries or examples of FFT implementations suitable for the Raspberry Pi Pico. -- **OLED Libraries**: Find libraries specific to your OLED display model for easier programming. - -This project involves a mix of hardware setup, digital signal processing, and real-time data visualization. Take it step by step, and don't hesitate to seek out community forums and resources if you encounter challenges. \ No newline at end of file diff --git a/docs/advanced-labs/index.md b/docs/advanced-labs/index.md deleted file mode 100644 index 18f8a7802..000000000 --- a/docs/advanced-labs/index.md +++ /dev/null @@ -1,20 +0,0 @@ -# Advanced Labs - -This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects. - -Topics include: - -1. Writing Interrupt Handlers -2. Monitoring the internal temperature of your RP2040 CPU -3. Timing the speed of functions for performance optimization -4. Setting up a Conda virtual Python development environment -5. Using operating system functions such as listing files on the file system -6. Scanning for I2C devices -7. Using a framebuffer -8. Using the minicom tool to move files to and from you PC from your microcontroller -9. Reading files from a SD card -10. Converting CircuitPython code and drivers to MicroPython - -## References - -[Wokwi ESP32 Simulator for the Raspberry Pi Pico](https://wokwi.com/pi-pico) \ No newline at end of file diff --git a/docs/basics/01-intro.md b/docs/basics/01-intro.md deleted file mode 100644 index c21b7c188..000000000 --- a/docs/basics/01-intro.md +++ /dev/null @@ -1,7 +0,0 @@ -# Introduction to MicroPython - -This lesson assumes that you have at least skimmed the [Getting Started](../getting-started/01-intro.md) sections and have selected one of the MicroPython IDEs to write your code. - -The lesson will introduce you to the basic concepts of using MicroPython using the $4 Raspberry Pi Pico or a similar microcontroller. - -The first two examples just use the Raspberry Pi Pico and don't require a breadboard or wiring. All the subsequent examples will require you to place components on a solderless breadboard. \ No newline at end of file diff --git a/docs/basics/03-blink.md b/docs/basics/03-blink.md deleted file mode 100644 index 531964b01..000000000 --- a/docs/basics/03-blink.md +++ /dev/null @@ -1,178 +0,0 @@ -# Blink in MicroPython - -![Blink GIF](../img/blink-on-board-led.gif) - -## Overview -In this lab, we will use MicroPython to make the green on-board LED on the Raspberry Pi Pico blink on and off every half second. The only things you need to run this program are - -1. a working IDE like [Thonny](../glossary#thonny) -2. a USB cable -3. a $4 Raspberry Pi Pico microcontroller - -## Blinking the Builtin LED - -The pico has a single built in green LED wired to logical pin 25. We call this GPIO 25. GPIO means General Purpose Input and Output pin. Here is a sample program that you can use. Don't worry about understanding each line yet. We will cover the various parts of the file in later sections. - -```py -# Setup - run once -from machine import Pin # Get the Pin function from the machine module. -from time import sleep # Get the sleep library from the time module. - -# This is the built-in green LED on the Pico. -BUILT_IN_LED_PIN = 25 -# change this to the following named pin on the "W" -# BUILT_IN_LED_PIN = Pin("LED", Pin.OUT) - -# The line below indicates we are configuring this as an output (not input) -led = machine.Pin(BUILT_IN_LED_PIN, machine.Pin.OUT) - -# Main loop: Repeat the forever... -while True: - led.high() # turn on the LED - sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second -``` - -This program has two main parts. The first part is often called the preamble or the setup code. This code gets executed only once when the program is run. In this example, the setup loads the right libraries and initializes global variables. - -The second part is the main event loop. This program continues to run until the device is powered down or the program is reset. - -The ```from machine import Pin``` statement is required to define the characteristics of our physical machine. In this case, we are loading the Pin python library. - - The ```from time import sleep``` library is required for the python sleep function. Note that some programs use ```utime``` for MicroPython time. These both work the same. They are really just synonyms or alias of each other. Although the use of ```utime``` is technically a little bit more precise - the reader knows that the code is using the actual MicroPython time library, the use of the ```time``` alias makes our code on character smaller and can make our code more portable to other systems. - -Note that the text after the hash or pound characters are comments. Comments are ignored by the Python interpreter but it is a good practice to put in comments in your code to help others understand your program. - -## Changing the Blink Speed - -Next, lets create a Python global variable for the delay that the LED is on and off. - -```py -from machine import Pin -from time import sleep -BUILT_IN_LED_PIN = 25 -# this is the builtin LED on the Pico -led = Pin(BUILT_IN_LED_PIN, machine.Pin.OUT) - -# global variables -delay = .25 - -# repeat forever -while True: - led.high() # turn on the LED - sleep(delay) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(delay) # leave it off for 1/2 second -``` - -This program will blink the built-in LED on and off every 1/4 of a second. By changing the delay variable you can make the LED blink faster and slower. - -!!! Challenge - What is the fastest you can make the LED blink and still see it changing? What does this tell you about the human eye? - -## Using Toggle - -Instead of using the ```on()``` and ```off()``` methods, we can also just use the ```toggle()``` function. - -```py -from machine import Pin -from time import sleep -led_onboard = machine.Pin(25, machine.Pin.OUT) -while True: - led_onboard.toggle() - sleep(.25) -``` - -The ```toggle()``` function looks at the state of the output pin. If it is high, it sets the value low. If it is low, it sets it high. Whatever the value currently is, it will set it to the opposite value. - -If you save the file as main.py, this program will run when the microcontroller starts up without the BOOTSEL being pressed. - -### Blinking an External LED -Although the builtin LED is convenient, you can use the almost the code to blink any external LED that is connected through a 330 ohm resister in series to the LED. - -We will assume that an LED is connected to pin GIO16 and is connected via a 330 ohm resistor to ground. - -Here is the code that will blink an LED that is connected to PIN GIO16, which is in the upper right corner of the Pico. - -```py -from machine import Pin -from time import sleep -# this is the lower right corner pin on the Pico with USB on the bottom -EXTERNAL_LED_PIN = 16 -led = machine.Pin(EXTERNAL_LED_PIN, machine.Pin.OUT) - -# repeat forever -while True: - led.high() # turn on the LED - time.sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second -``` - -Here is that same program using the ```toggle()``` function: - -```py -from machine import Pin -from time import sleep -EXTERNAL_LED_PIN = 16 -external_led = machine.Pin(EXTERNAL_LED_PIN, machine.Pin.OUT) - -while True: - external_led.toggle() - sleep(5) -``` - - - -### Solution to LED Row Lab - -```py -from machine import Pin -from time import sleep -EXTERNAL_LED_PIN1 = 16 -EXTERNAL_LED_PIN2 = 17 -EXTERNAL_LED_PIN3 = 18 -EXTERNAL_LED_PIN4 = 19 -led1 = machine.Pin(EXTERNAL_LED_PIN1, machine.Pin.OUT) -led2 = machine.Pin(EXTERNAL_LED_PIN2, machine.Pin.OUT) -led3 = machine.Pin(EXTERNAL_LED_PIN3, machine.Pin.OUT) -led4 = machine.Pin(EXTERNAL_LED_PIN4, machine.Pin.OUT) - -while True: - # blink the first LED - led1.high() - sleep(.5) - led1.low() - - # blink the 2nd LED - led2.high() - sleep(.5) - led2.low() - - - # blink the 3rd LED - led3.high() - sleep(.5) - led3.low() - - - # blink the 4th LED - led4.high() - sleep(.5) - led4.low() -``` - -### Extra credit lab - -Can you rewrite the program above using an array of pin values like this: - -```py -LED_PINS = [16,17,28,19] -``` - -## More to Explore - -1. Can you blink both the internal on board LED and an external LED? -2. How many external LEDs can you blink? What is the maximum number of output pins on the Raspberry Pi Pico? -3. What if you wanted to control more LEDs then you have available output pins? What do you think your options might be? (answer - use a NeoPixel or a shift register like a SN74HC595). See the [peppe8o Shift Register Tutorial on the RP2040](https://peppe8o.com/how-to-use-74hc595-shift-register-with-raspberry-pi-pico-and-micropython/s) for an example of this. \ No newline at end of file diff --git a/docs/basics/03-button.md b/docs/basics/03-button.md deleted file mode 100644 index 414e0c1cb..000000000 --- a/docs/basics/03-button.md +++ /dev/null @@ -1,181 +0,0 @@ -# Button - -In this lesson we will hook a single momentary push button up to our Raspberry Pi Nano. We will use it to toggle the built-in LED. We will start out with simply polling the button 10 times a second to check it's state. Then we will show how to use an interrupt handler function to monitor events from the button. - -![Momentary Button Press](../img/button-press.gif) - -In the example above, we are connecting the button on the left to the lower-left corner pin of the Raspberry Pi Pico. This is GPIO Pin 15 and is in row number 20 of our [breadboard](#02_breadboard). - -## Momentary Switch Buttons - -![Momentary Switch](../img/momentary-switch-button.png) - -We use ["B3F" tactile switch buttons](getting-started/03-suggested-parts/#momentary-press-buttons) that can be mounted directly on our breadboards. When the button is pressed, it connects a wire that joins two pins on one side to the two pins on the other side. The buttons can be mounted directly over the trough in the center of the breadboard. They typically cost under $2 for 10 buttons or about 20 cents per button. - -![Momentary Switch Internal Connection Diagram](../img/button-connection-digram.png) -Here are the internal connections within the switch. - -![Momentary Switch External Connection Diagram](../img/button-connections.png) -This is the connection diagram that shows how the button is connected to the GPIO connector in the lower-left corner of the Raspberry Pi Pico. This corresponds to GP15 or Pin #15 in our code. - -## Sample Button Polling Code -Here is our fist example that uses a simple "watching" loop to check if the button value has change 10 times per second. In this case, the built-in LED is connected to pin 25. - -```py -from machine import Pin -import time - -# GPIO is the internal built-in LED -led = Pin(25, Pin.OUT) -# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating -button = Pin(15, Pin.IN, Pin.PULL_DOWN) - -while True: - if button.value(): # if the value changes - led.toggle() - time.sleep(0.1) # wait 1/10th of a second -``` - -## Interrupt Handler Version - -Although the polling version is simple, it does take a lot of the CPU resources. The button.value() is checked 10 times a second, even though the button might only be pressed once a day! - -A more efficient version uses a strategy called an [interrupt handler](../advanced-labs/02-interrupt-handlers). This is a function that is "registered" by micropython to handel external events such as a button press. - -```py -# Use an interrupt function count the number of times a button has been pressed -from machine import Pin -import micropython -import time - -# global value -button_pressed_count = 0 - -# Interrupt Service Routine for Button Pressed Events - with no debounce -def button1_pressed(change): - global button_pressed_count - button_pressed_count += 1 - -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) -button1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING) - -button_pressed_count_old = 0 -while True: - if button_pressed_count_old != button_pressed_count: - print('Button 1 value:', button_pressed_count) - button_pressed_count_old = button_pressed_count -``` - -## Interrupt Handler with a Debounce Feature - -One of the problems with most switches is that they don't turn on and off perfectly each time. As the connection is getting close to closing some electrons jump the gap and the switch appears to turn on for a few microseconds. So to a computer, this looks like someone quickly pressing a button rapidly until it is firmly closed or completely open. This intermediate stage between completely open and closed is called the "bounce" stage of a switch opening and closing. - -![Debounce Transition](../img/debounce-transition.png) - -To remove this problem and get a clean signal, we can use either a hardware solution (wiring a capacitor to remove the high frequency noise) or we can be clever and solve the problem with a few extra lines of code. - -The secret is to setup a timer when the switch is first closed or opened. We then ignore all the crazy stuff that happens for about 1/5th of a second (200 milliseconds). By then we usually have a solid indication that the button is changing state and we can return the new value. - -Here is a example of this "Debounce" code in MicroPython: - -```py -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses -``` - -## Two Button Example - -This example uses two buttons. One adds one to a counter, and the other decrements the counter. In the IRQ we look for the string '''14''' in the incoming pin event string. If the string is present, then we increment the ```button_presses``` variable. If it is not, then we decrement the counter. - -This example is useful whenever you have two buttons that control the ```mode``` of a microcontroller. - -Note that you can tune the delay period. If you have clean buttons and you want to allow for fast double-click events you can lower the time. 200 milliseconds is good for low-cost noisy buttons that may have many spikes in the open and closing transitions. - -```py -import utime -from machine import Pin - -# Sample two button Raspberry Pi Pico MicroPython example -# with a debounce delay value of 200ms in the interrupt handler -# https://www.coderdojotc.org/micropython/basics/03-button/ - -# these are the pins in the lower-left corner (USB on top) -BUTTON_PIN_A = 14 -BUTTON_PIN_B = 15 - -button_presses = 0 # the count of times the button has been pressed. A is +1, B is -1 -last_time = 0 # the last time we pressed the button - -# we toggle the builtin LED to get visual feedback -builtin_led = machine.Pin(25, Pin.OUT) - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_a = machine.Pin(BUTTON_PIN_A, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_b = machine.Pin(BUTTON_PIN_B, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# this is the interrupt callback handler -# get in and out quickly -def button_callback(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - if '14' in str(pin): - button_presses +=1 - else: - button_presses -= 1 - last_time = new_time - -# now we register the handler functions when either of the buttons is pressed -button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback) -button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback) - -# This is for only printing when a new button press count value happens -old_presses = 0 - -print(button_presses) -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses -``` - -## References - -1. [Raspberry Pi Pico Getting Started Guide Lab 6](https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/6) -1. [YouTube Video](https://www.youtube.com/watch?v=nPMU10mfFbs) -2. [Sample eBay List of Switches with trough pins](https://www.ebay.com/itm/381924159238) -3. [Sample B3F Button on eBay](https://www.ebay.com/itm/402898405046) 10 pieces for $1.50 \ No newline at end of file diff --git a/docs/basics/03-potentiometer.md b/docs/basics/03-potentiometer.md deleted file mode 100644 index 7be770755..000000000 --- a/docs/basics/03-potentiometer.md +++ /dev/null @@ -1,108 +0,0 @@ -# MicroPython Potentiometer Lab - -![](../img/pot-blink-speed.jpg) - -In this lab we will use a 10K ohm potentiometer to demonstrate how a turn of a knob can result in getting a continuous variable from a user into our code. We will show how we can use a potentiometer to change the blinking speed of on LED. - -## About Analog to Digital Converters - -Digital microcontrollers are inherently noisy. They have clocks that pull power from the power supply and cause voltage fluctuations when we compare a signal to these power lines. This makes it difficult to get - -ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This -pin can be used with an external reference if better ADC performance is required. -AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and -terminating at this pin. - -## Circuit Diagram - -![](../img/pot-circuit-diagram.png) - -1. Connect the top rail of the potentiometer to row 6 which is the ADC_VREF pin. -2. Connect the center tap to row 10 which is ADC0 -3. Connect row 8 to the bottom rail of the potentiometer to the Analog Ground (AGND) pin - -Note: to get an accurate noise-free reading from the potentiometer you must use the ADC_VREF and the AGND pins. These are special pins designed to reduce the noise on the power areas of the pico. - -## Sample Code To Print Potentiometer Values - -```py -from machine import ADC -from utime import sleep -pot = ADC(26) -while True: - print(pot.read_u16()) - sleep(.2) -``` - -```mermaid -graph LR -p[Pico]-->|ADC_VREF 36 row=6| pos(Positive) -p[Pico]-->|AGND 33 row=8| neg(Negative) -p[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap) - pos(Positive) --- pot(Potentiometer) - neg(Negative) --- pot(Potentiometer) - tap(Center Tap) --- pot(Potentiometer) -``` - -Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins. - -## Changing Blink Speed with a Potentiometer - -```py -from machine import ADC, Pin -from utime import sleep - -# this is the built-in LED on the Pico -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -# repeat forever -while True: - pot_value = pot.read_u16() # read the value from the pot - delay = pot_value/65025 * MAX_DELAY - print("delay:", delay) - if delay > 0: - print("frequency (toggles per second):", 1/delay) - led.high() # turn on the LED - sleep(delay) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(delay) # leave it off for 1/2 second -``` - -The following video shows this script in action. - - -## Changing the Brightness of the Building LED -We can change the brightness of the builtin LED by using the POT value to change the PWM duty cycle. - -Here is a sample progam that does this: - -```py -from machine import ADC, Pin, PWM -from utime import sleep - -# Pins Used -BUILT_IN_LED_PIN = 25 -POT_PIN = 26 - -pot = ADC(POT_PIN) - -builtin_pwm = PWM(Pin(BUILT_IN_LED_PIN)) -builtin_pwm.freq(1000) # 1K Hz - -POLL_DELAY = .1 # poll the pot after this delay in seconds - -# repeat forever -while True: - pot_value = pot.read_u16() # read the value from the pot - print("pot value:", pot_value) - builtin_pwm.duty_u16(pot_value) - sleep(POLL_DELAY) -``` \ No newline at end of file diff --git a/docs/basics/04-fade-in-and-out.md b/docs/basics/04-fade-in-and-out.md deleted file mode 100644 index 8bcceb90a..000000000 --- a/docs/basics/04-fade-in-and-out.md +++ /dev/null @@ -1,75 +0,0 @@ -# Fade an LED in and Out - -In the prior Blink lab, we turned an LED on an off at different speeds. But what if we want to slowly turn on our LED on and off? In this lab we will show you how to dim your LED to any brightness level you want. - -## Welcome to Pulse Width Modulation - -![PWM Duty Cycle](../img/PWM-duty-cycle.png) - -Although digital computers are good at quickly turning signals on and off, they don't really allow us to easily set an output to a given voltage level without complex circuits. But there is an easier way to adjust the brightness of an LED! We can quickly turn the signal to the LED on and off. We can do this so quickly that you can't even see it flicker. Controlling the amount of time a signal is on is all about controlling the width of the ON pulse. That is why this is called Pulse Width Modulation or PWM for short. - -With a PWM design there are two things we need to tell the microcontroller: - -1. How often do you want a square wave to go on and off? -2. How wide should the on part of the pulse be (relative to the total width). This is called the duty cycle. - -The rate of change of the pulse is call the frequency. You can set the frequency to be 1,000 changes per second, which is much faster than the human eye can detect. This is done using the following line: - -```py -pwm.freq(1000) -``` - -Note that we can slow the frequency way down and the dimming effect will still work. As an experiment you can change the PWM frequency to around 20 and you will see a distinct flicker as the LED turns on. - -Here is the sample program that will slowly dim the builtin LED that is on pin 25: - -``` -from machine import Pin, PWM -from time import sleep - -pwm = PWM(Pin(25)) - -pwm.freq(1000) - -while True: - for duty in range(65025): - pwm.duty_u16(duty) - sleep(0.0001) - for duty in range(65025, 0, -1): - pwm.duty_u16(duty) - sleep(0.0001) -``` - -Note that the duty cycle starts at 0 (always off) and moves slowly up to 65,025 (always on). It then does the reverse and slowly dims the LED and then repeats. There is only a 1/10,000 of a delay between these changes so the LED will completely turn on in about six seconds before it starts to dim again. - -## PWM Functions - -Here is a list of the PWM functions. - -```python -from machine import Pin, PWM - -pwm0 = PWM(Pin(0)) # create PWM object from a pin -pwm0.freq() # get current frequency -pwm0.freq(1000) # set frequency (1000 cycles per minute) -pwm0.duty_u16() # get current duty cycle, range 0-65535 -pwm0.duty_u16(200) # set duty cycle, range 0-65535 -pwm0.deinit() # turn off PWM on the pin -``` - -Make sure you ```deinit()``` to de-initialize the PWM controller after you are done. You may have to trap the stop to do this. For example if a PWM is driving motors, your Stop must send deinit() to each motor controller. See the [Interrupt Handlers](../advanced-labs/02-interrupt-handlers.md) for details. - -## Suggested Exercises - -1. Change the frequency from 1,000 to 500, 100, 50, 40, 30, 25, 20, and 10. When can you just barley see it flicker? What does this tell you about the human eye? -2. Can you add a delay so that the LED stays on at full brightness for one second before it starts to dim again? -3. Can you add a delay so that the LED is completely off for five seconds and then goes to full brightness and off in one second? -4. What lights in your home would you like to see slowly dim on and off? How could you modify a light (safely) so that it slowly dimmed on and off. Would PWM work with all lightbulb types such as tungsten filament bulbs that take a long time to heat up and cool down? -5. Can you hook up a set of red, green and blue LEDs program them to fade in and out to display all the colors of the rainbow (red, orange, yellow, green, blue, indigo and violet)? -6. When you stop the program does the LED stop changing brightness? Does it retain the value that it had when you pressed the Stop function? What does that tell you about how main CPU and the role of PWM? Note that we will cover up doing "cleanup" events that stop all PWM activity in our [Interrupt Handlers Lab](../advanced-labs/02-interrupt-handlers.md) - -## References - -### Pulse With Modulation - -1. [Wikipedia Article on Pulse With Modulation](https://en.wikipedia.org/wiki/Pulse-width_modulation) \ No newline at end of file diff --git a/docs/basics/04-motor.md b/docs/basics/04-motor.md deleted file mode 100644 index 72c2dc223..000000000 --- a/docs/basics/04-motor.md +++ /dev/null @@ -1,40 +0,0 @@ -# Driving a Motor with the Pico - -The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the [Raspberry Pi Pico Datasheet Table 5](https://github.com/raspberrypi/documentation/blob/master/hardware/computemodule/datasheets/rpi_DATA_CM_2p0.pdf). 17 milliamps is fine for lighting up an LED. However, motors require much more power. 17 milliamps is not enough current to drive even small motors. Even our small DC hobby motors we use with our robots require around 200 milliamps. - -But don't worry! We have two ways around this problem. - -1. The first option is to use a simple transistor as a "switch" that will use our low-power digital signal to control its on-and-off settings. -2. The second option is to use a full motor driver chip such as an L293D chip. This chip takes the same PWM signal we learned about in our [Fade In and Out Lab](04-fade-in-and-out.md). - -## Basic Transistor Circuit - -1. Transistor NPN 2222A -2. Diode: 1N1448 -3. Motor: 3-6 volt hobby motor - -![Motor Circuit](../img/motor-circuit.png) - -## PWM Control - -### PWM Frequency -Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms) - -## Sample Coder - -```py -import machine - -# set the 7th from the bottom on right as our motor pin -motor_pin = machine.Pin(21, machine.Pin.OUT) -# allocate a PWM object for controlling the motor speed -motor_pwm = machine.PWM(motor_pin) -motor_pwm.freq(50) # 50 hertz -motor_pwm.duty(51) -``` - -## References - -1. [Sparkfun Motor Lab from SIK Kit](https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-12-driving-a-motor) -2. [Nick Zoic MicroPython Motor Control Tutorial](http://mpy-tut.zoic.org/tut/motors.html) - diff --git a/docs/basics/04-read-pot.md b/docs/basics/04-read-pot.md deleted file mode 100644 index e81d828d2..000000000 --- a/docs/basics/04-read-pot.md +++ /dev/null @@ -1,42 +0,0 @@ -# Using MicroPython to Read a Potentiometer - -# Reading a Potentiometer - -ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This -pin can be used with an external reference if better ADC performance is required. -AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and -terminating at this pin. - -```mermaid -graph LR -p[Pico]-->|ADC_VREF 36 row=6| pos(Positive) -p[Pico]-->|AGND 33 row=8| neg(Negative) -p[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap) - pos(Positive) --- pot(Potentiometer) - neg(Negative) --- pot(Potentiometer) - tap(Center Tap) --- pot(Potentiometer) -``` - -Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins. - - -## Sampling data -Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values. - -Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples. - -```py -def sample_pot(pin, count): - total = 0 - for i in range(count): - total += int(pin.read_u16()) - utime.sleep_ms(5) - return int(total / count) -``` - - -```python -pot_pin_1 = machine.ADC(26) -# return a value after sampling 10 times -sample_pot(pot_pin_1, 10) -``` \ No newline at end of file diff --git a/docs/basics/04-servo.md b/docs/basics/04-servo.md deleted file mode 100644 index 310fe9234..000000000 --- a/docs/basics/04-servo.md +++ /dev/null @@ -1,12 +0,0 @@ -# Micropython Servo Lab -TBD - -```py -import machine -import pyb - -# The pyboard has four simple servo connections -servo = pyb.Servo(1) - -servo.angle(90, 5000) -``` diff --git a/docs/basics/05-neopixel.md b/docs/basics/05-neopixel.md deleted file mode 100644 index c47a8671c..000000000 --- a/docs/basics/05-neopixel.md +++ /dev/null @@ -1,282 +0,0 @@ -# NeoPixels - -![NeoPixel Demo](../img/neopixel-demo.gif) - -NeoPixels are Red-Green-Blue LEDs that are designed to makes them easy to control with three wires: GND, +5V and a single serial data line. They are very popular with our students because they are powerful, easy to program and full of **bling**. - -!!! Note - As of March of 2022 there is now built-in support for NeoPixels in the MicroPython 1.18 runtime for the Raspberry Pi RP2040 microcontroller. Although you can still use custom libraries, this tutorial assumes you are using - version 1.18 or later. - -Controlling NeoPixels is challenging since the timing of data being sent must be very precise. Python alone is not fast enough to send bits out of a serial port. So a small function that uses assembly code is used. This code can be called directly from a neopixel driver file so that the user's don't need to see this code. - -[MicroPython Example Code on ESP8266](https://docs.micropython.org/en/latest/esp8266/tutorial/neopixel.html) - -## Different Types of NeoPixels -There are many different types of NeoPixels. They come in many forms such as strips, rings and matrices. - -![NeoPixel Types](../img/neopixel-types.jpg) - -The most common type of NeoPixels are strips. The strips come in a variety of densities and waterproofing. The most common and easiest to use are the 60 pixels-per-meter type. - -## Circuit connections - -![](../img/led-strip-connections.png) - -|LED Strip|Pico Name|Pico Pin|Description| -|---------|---------|--------|-----------| -|GND|GND|3|Ground|Third from top on the left with USB on top| -|5v|VBUS|40|Voltage from the USB bus. Top right with USB on top| -|Data|GP22|22|Row 12 on the right side| - -Note that you can also power most of the LED strips using the 3.3 volts available on Grove connectors. The only difference is the brightness might not be quite as high, but for most applications this will not be a problem. - -## Setup Parameters -Our Python code will have four parts: - -1. Declaration of the imports from the RP2 MicroPython runtime. We also import the sleep function from the utime module and some samples will also need the random library. All our programs have been tested on version 1.18 of the MicroPython RP2 library or later. -2. Initialization of the fixed static parameters. This is done once and the parameters are usually at the top of the file to make them easy to find and change for each application. Make sure you adjust the pin number and the number of pixels in your setup in this area. -3. Initialization of the NeoPixel object using these static parameters. This is also done just once. -4. Sending the drawing commands to the device through the data port. This is usually done within a main loop. - -### Import Statements -Here are the import statements we use: - -```py -from machine import Pin -from utime import sleep -from neopixel import NeoPixel -``` - -### Static Initialization Parameters -There are only two values. The number of pixels in the LED strip or LED ring and the pin number the data pin is connected to. - -```py -NUMBER_PIXELS = 8 -LED_PIN = 22 -``` - -### Initialize the Strip Object - -To setup the NeoPixel object we just pass it the two parameters like this: - -```py -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) -``` - -Here is the full initialization code: - -```py -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 8 -LED_PIN = 22 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -``` - -## Sample Programs -Now we are ready to write our first small test program! - -### Move Red Pixel Across Strip - -![Move LED Up Strip](../img/red-led-move-up.gif) - -```py -from machine import Pin -from time import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - strip[i] = (255,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(.1) # keep on 1/10 of a second - strip[i] = (0,0,0) # change the RAM back but don't resend the data -``` - -### Fade in and Out -Make the first pixel fade the red color in and out. We do this by slowly turning up the color level of the red on strip[0]. - -``` -Off: strip[0] = (0,0,0) -Red Very Dim: strip[0] = (1,0,0) -Dim Red: strip[0] = (10,0,0) -Red Half Brightness: strip[0] = (128,0,0) -Red Full Brightness: strip[0] = (255,0,0) -``` - -We start a 0 and go up to 255. Then we go back from 255 back down to zero. We delay about 5 milliseconds between each of the 255 brightness levels. - - -```py -from machine import Pin -from time import sleep -from neopixel import NeoPixel - - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -delay = .005 - -while True: - for i in range(0, 255): - strip[0] = (i,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(delay) - for i in range(255, 0, -1): - strip[0] = (i,0,0) - strip.write() - sleep(delay) -``` - -### Heartbeat Lab - -What if you were building a robot and you wanted to flash the LED to look like a human heartbeat? Instead of slowing fading in and out, you would want the brightness to follow the electrical signals coming from the heart. This is called an electro cardiogram (EKG) and it look like this: - -![EKG Sample](../img/ekg-sample.png) - -Notice that the signal is low for about one second and then it spikes up to maximum brightness and then comes back down. When we are moving the brightness up and down, we don't have to pause between each of the 256 brightness values. The eye can't usually see the intermediate brightness values if the brightness is changing quickly. To make our code efficient we can skip over 9 out of 10 of the brightness gradations between 0 and 255. We call this the ```skip_interval``` in our code below. - -The following code emulates this heart beat pattern: - -```py -from machine import Pin -from time import sleep -from neopixel import NeoPixel - -# Most people have a heart rate of around 60-70 beats per minute -# If we add a once second delay between "beats" you can make and LED -# look like a beating heart. - -NUMBER_PIXELS = 1 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -ramp_delay = .001 -beat_delay = 1 -skip_interval = 10 - -while True: - # ramp brightness up using the ramp_delay - for i in range(0, 255, skip_interval): - strip[0] = (i,0,0) - strip.write() - sleep(ramp_delay) - # ramp brightness down using the same delay - for i in range(255, 0, -skip_interval): - strip[0] = (i,0,0) - strip.write() - sleep(ramp_delay) - strip[0] = (0,0,0) - strip.write() - sleep(beat_delay) -``` - -### Move Red, Green and Blue - -![neopixel-red-green-blue](../img/neopixel-red-green-blue.gif) - -The following program will just take the block of code in the for loop above and duplicate it three times, one for red, one for blue and one for green. - -```py -from machine import Pin -from neopixel import NeoPixel -from time import sleep - -NUMBER_PIXELS = 8 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# we use the same brightness for each color -brightness = 25 -delay = .1 -# here we define variables for each color -red = (brightness, 0, 0) -green = (0, brightness, 0) -blue = (0, 0, brightness) -while True: - # draw red up the strip - for i in range(0, NUMBER_PIXELS): - strip[i] = red - strip.write() - sleep(delay) - strip[i] = (0,0,0) - # draw blue up the strip - for i in range(0, NUMBER_PIXELS): - strip[i] = green - strip.write() - sleep(delay) - strip[i] = (0,0,0) - # draw green up the strip - for i in range(0, NUMBER_PIXELS): - strip[i] = blue - strip.write() - sleep(delay) - strip[i] = (0,0,0) -``` - -### Rainbow Cycle -The program cycles each pixel through all the colors in a rainbow. It uses two functions: - -1. **wheel(pos)** this function takes a position parameter from 0 to 255 and returns a triple of numbers for the red, green and blue values as the position moves around the color wheel. This is a handy program anytime you want to cycle through all the colors of the rainbow! -2. **rainbow_cycle(wait)** will cycle each of the pixels in a strip through the color wheel. It gives the appearance that colors are moving across the strip. The wait is the delay time between updating the colors. A typical value for wait is .05 seconds or 50 milliseconds. - -```py -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 22 -NUMBER_PIXELS = 8 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(wait): - global NUMBER_PIXELS, strip - for j in range(255): - for i in range(NUMBER_PIXELS): - rc_index = (i * 256 // NUMBER_PIXELS) + j - # print(rc_index) - strip[i] = wheel(rc_index & 255) - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(.05) - counter += 1 -``` - -## References - -* [MicroPython RP2 Reference for NeoPixel Driver](https://docs.micropython.org/en/latest/rp2/quickref.html#neopixel-and-apa106-driver) -* [Core Electronics: How to use WS2812B RGB LEDs with Raspberry Pi Pico](https://core-electronics.com.au/tutorials/how-to-use-ws2812b-rgb-leds-with-raspberry-pi-pico.html) - HTML page, sample code and video -* [MicroPython Library for NeoPixel (used before version 1.18 of the MicroPython RP2 Runtime)](https://docs.micropython.org/en/latest/library/neopixel.html) - note the lack of support for the RP2040 microcontroller. -* [rp2 port no module named array](https://github.com/micropython/micropython/issues/6837) \ No newline at end of file diff --git a/docs/basics/06-wireless.md b/docs/basics/06-wireless.md deleted file mode 100644 index 0d8b7f5b2..000000000 --- a/docs/basics/06-wireless.md +++ /dev/null @@ -1,481 +0,0 @@ -# MicroPython Pico W Wireless Examples - -![Raspberry Pi Pico W](../img/pico-w.png) - -One June 30th, 2022 the [Raspberry Pi Foundation announced](https://www.raspberrypi.com/news/raspberry-pi-pico-w-your-6-iot-platform/) the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth. - -The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the [lwip](https://savannah.nongnu.org/projects/lwip/) TCP/IP stack. This stack is accessible using the MicroPython [network](https://docs.micropython.org/en/latest/library/network.html#) functions. - -The WiFi chip used is the [Infineon CYW43439](https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw43439/) chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication. - -![Wireless Block Architecture](../img/wireless-block-arch.png) - -You can read more about the capabilities of the WiFi/Bluetooth chip by reading the [Infineon CYW43439 Datasheet](https://www.infineon.com/dgdl/Infineon-CYW43439-Single-Chip-IEEE-802.11-b-g-n-MAC-PHY-Radio-with-Integrated-Bluetooth-5.0-Compliance-AdditionalTechnicalInformation-v03_00-EN.pdf?fileId=8ac78c8c7ddc01d7017ddd033d78594d). I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains! - -## Compatibility with Prior Code - -The Pico W code is very similar to prior versions of the Pico with a few small exceptions. One of these is the fact that we must now use a symbolic label called an **alias** such as ```Pin("LED")``` instead of ```Pin(25)``` to access the LED pin, not a hardwired PIN number. This allows us to keep our code more portable as the underlying hardware changes. - -```python -from machine import Pin, Timer - -# was Pin(25) -led = Pin("LED", Pin.OUT) -tim = Timer() -def tick(timer): - global led - led.toggle() - -tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick) -``` - -See the new [Sample Blink](https://github.com/raspberrypi/pico-micropython-examples/blob/master/blink/blink.py) code on the Raspberry Pi Examples site. - -## Getting the New Pico W Image - -I had to download a brand new image for the Pico W runtime from [the Raspberry Pi Foundation Software Site](https://githubdatasheets.raspberrypi.com/soft/micropython-firmware-pico-w-290622.uf2) - -After I downloaded the new image and ran a **Stop/Reset** on Thonny I got the following prompt: - -```sh -MicroPython v1.19.1-88-g74e33e714 on 2022-06-30; Raspberry Pi Pico W with RP2040 -Type "help()" for more information. ->>> -``` - -Note that the "Pico W" is listed in the prompt. If you do not see the "W" then the network code will not work. - -## Beginner WiFi Programs - -We will store the name of our local WiFi network we wish to connect to and the password for that name in a file called secrets.py. This is called you WiFi "access point" and the variable name to store the name is called the ```SSID``. We will need to make sure we never save this file into a public GitHub repo by adding this file to our .gitignore file. - -### Setting Up Your WIFI secrets.py -By convention, we put both our SSID and password in a python file called "secrets.py". This file should never be checked into a public source code repository. We can add ```secrets.py``` to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone. - -```python -SSID = "MY_WIFI_NETWORK_NAME" -PASSWORD = "MY_WIFI_PASSWORD" -``` - -By importing the secrets.py file you can then reference your network name like this: - -```py -print('Connecting to WiFi Network Name:', secrets.SSID) -``` - -### Testing Your WiFi Access Point Connection - -Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable. - -```python -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # power up the WiFi chip -print('Waiting for wifi chip to power up...') -sleep(3) # wait three seconds for the chip to power up and initialize -wlan.connect(secrets.SSID, secrets.PASSWORD) -print('Waiting for access point to log us in.') -sleep(2) -if wlan.isconnected(): - print('Success! We have connected to your access point!') - print('Try to ping the device at', wlan.ifconfig()[0]) -else: - print('Failure! We have not connected to your access point! Check your secrets.py file for errors.') -``` - -Returns: - -``` -Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME -Waiting for wifi chip to power up... -Waiting for access point to log us in... -Success! We have connected to your access point! -Try to ping the device at 10.0.0.70 -``` - -If the result is a ```Failure``` you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing. - -Note that we are using the ```sleep()``` function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly. - -### Waiting for a Valid Access Point Connection - -Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected. - -```python -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta, 'milliseconds') -print('IP Address:', wlan.ifconfig()[0]) -``` - -This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds. - -First run upon power on might take several seconds: -``` ->>> %Run -c $EDITOR_CONTENT -Connecting to WiFi Network Name: MY_NETWORK_NAME -Waiting for connection... -0.1.2.3.Connect Time: 4640 -IP Address: 10.0.0.70 -``` - -The second and consecutive runs will use a cached connection. - -``` ->>> %Run -c $EDITOR_CONTENT -Connecting to WiFi Network Name: MY_NETWORK_NAME -Connect Time: 0 milliseconds -IP Address: 10.0.0.70 ->>> -``` - -### Error Handling - -```python - -lan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(ssid, password) - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('connected') - status = wlan.ifconfig() - print( 'ip = ' + status[0] ) -``` - -The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above. - -### Testing HTTP GET - -The following example was taken from [Tom's Hardware](https://www.tomshardware.com/how-to/connect-raspberry-pi-pico-w-to-the-internet) - -```python -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff -import urequests - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) - -start = ticks_ms() # start a millisecond counter - -astronauts = urequests.get("http://api.open-notify.org/astros.json").json() - -delta = ticks_diff(ticks_ms(), start) - -number = astronauts['number'] -print('There are', number, 'astronauts in space.') -for i in range(number): - print(i+1, astronauts['people'][i]['name']) - -print("HTTP GET Time in milliseconds:", delta) -``` - -Returns: - -``` -There are 10 astronauts in space. -1 Oleg Artemyev -2 Denis Matveev -3 Sergey Korsakov -4 Kjell Lindgren -5 Bob Hines -6 Samantha Cristoforetti -7 Jessica Watkins -8 Cai Xuzhe -9 Chen Dong -10 Liu Yang -HTTP GET Time in milliseconds: 786 -``` - -## Listing the Functions in Your Network Library -The network library provided by the Raspberry Pi Foundation for the Pico W is new an may change as new functions are added. To get the list of functions in your network library you can use the Python help(network) at the prompt or use the ```dir()``` function. - -### Network Help -You can also get a list of the network functions by typing ```help(network)``` at the Python REPL prompt. - -``` -help(network) -object is of type module - __name__ -- network - route -- - WLAN -- - STAT_IDLE -- 0 - STAT_CONNECTING -- 1 - STAT_WRONG_PASSWORD -- -3 - STAT_NO_AP_FOUND -- -2 - STAT_CONNECT_FAIL -- -1 - STAT_GOT_IP -- 3 - STA_IF -- 0 - AP_IF -- 1 -``` - -### Network dir() Function -```python -import network -function_list = dir(network) - -for function in function_list: - print(function) -``` - -Returns: - -``` -__class__ -__name__ -AP_IF -STAT_CONNECTING -STAT_CONNECT_FAIL -STAT_GOT_IP -STAT_IDLE -STAT_NO_AP_FOUND -STAT_WRONG_PASSWORD -STA_IF -WLAN -route -``` - -### Urequest -It is easy to communicate with non-SSL protected HTTP protocols sites using the WLAN ```urequest`` function. It supports the standard GET, POST, PUT and DELETE functions. - -``` -help(urequests) -object is of type module - head -- - post -- - delete -- - get -- - __file__ -- urequests.py - Response -- - patch -- - put -- - usocket -- - __name__ -- urequests - request -- -``` - -## Getting the MAC/Ethernet Access -You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function. - -```python -import network -from utime import sleep, ticks_us, ticks_diff - -print('Getting MAC/Ethernet Address for this device.') - -start = ticks_us() # start a millisecond counter -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # this line powers up the chip - it takes about 2.5 seconds - -# This returns a byte array of hex numbers -mac_addess = wlan.config('mac') -print('Time in microseconds:', ticks_diff(ticks_us(), start)) -# each MAC address is 6 bytes or 48 bits -print("Hex byte array:", mac_addess, 'length:', len(mac_addess)) - -# This should be in hex per the Notational Conventions -# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions -# b'(\xcd\xc1\x015X' -# 28:cd:c1:1:35:58 -# format in MAC Notational Convention -for digit in range(0,5): - print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '') -print(str(hex(mac_addess[5]))[2:4] ) -``` - -First Time After Power On Results: -``` -Getting MAC/Ethernet Address for this device. -Time in microseconds: 2584424 -Hex byte array: b'(\xcd\xc1\x015X' length: 6 -28:cd:c1:1:35:58 -``` - -Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address. - -Subsequent Times -``` -Getting MAC/Ethernet Address for this device. -Time in microseconds: 211 -Hex byte array: b'(\xcd\xc1\x015X' length: 6 -28:cd:c1:1:35:58 -``` - -!!! Note - We must add the ```wlan.active(True)``` line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros. - -The MAC address is six bytes or "octets". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the [Wikipedia Page on MAC Address](https://en.wikipedia.org/wiki/MAC_address) for more information. If you run this on your Pico W the first octets should be similar. - -Here are the two MAC addresses for two different Pico W devices: - -``` -28:cd:c1:1:35:54 -28:cd:c1:1:35:58 -``` - -Because they were purchased together, their MAC address are very similar. - -I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking. - -## Advanced WiFi Programs - -Once we have mastered the basics of connecting to a local access point and returning our IP address, we are no ready to build some sample Internet of Things applications. - -### Using the Pico W as a Web Server - -This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off. - -Screen image of Pico W Web Server: -![](../img/pico-w-web-page.png) - -```python -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -import network -import socket -import time -import secrets - -from machine import Pin - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - -

                                                                                                                                                  Pico Wireless Web Server

                                                                                                                                                  -

                                                                                                                                                  %s

                                                                                                                                                  - Turn On - Turn Off - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -print('addr:', addr) -s = socket.socket() -#if not addr: -s.bind(addr) -s.listen(1) - -print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - print('client connected from', addr) - request = cl.recv(1024) - print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - print( 'led on = ' + str(led_on)) - print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - print('connection closed') -``` - -### SHTTP Support - -!!! Warning - This code is not working. I believe we need to get a SSL certificate for SSL to work. To do this I think we need to use a command line tool to generate a certificate for the device and store it in RAM. - -```python -import network -import secrets -import time -import urequests -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -print(wlan.isconnected()) -my_ip = urequests.get("https://api.myip.com/").json() -print(im_pi) -``` - -### Sending Notifications - -We can connect to a remote server to send text and e-mail notifications if specific events occur on our devices. To do this you must have credentials on some system that response to messages such as [IFTTT](https://ifttt.com/) or an [MQTT](https://en.wikipedia.org/wiki/MQTT) server. - -TBD \ No newline at end of file diff --git a/docs/concept-cards/01-intro.md b/docs/concept-cards/01-intro.md deleted file mode 100644 index ba858b6d6..000000000 --- a/docs/concept-cards/01-intro.md +++ /dev/null @@ -1,56 +0,0 @@ -# MicroPython Concept Cards -This is a list of concept cards that are related to MicroPython. Our goal is to print these concept cards on 1/2 sheet laminated paper and have them available at the center of the tables in our CoderDojo Classrooms. - -Please let me know if you are willing to volunteer. - -Each concept card will have the content stored in a MarkDown file. A Python script will convert the MarkDown into HTML with a CSS file that paginates the output. - - - -[Concept Cards](https://www.coderdojotc.org/CoderDojoTC/designing-concept-cards/) - -## Beginning concepts - -### [Physical Computing](02-physical-computing.md) - -### [Sensors](../sensors/01-intro.md) - -### [Switches and Buttons]() - -### [Sensing Light]() - -### [Sensing Distance] - -#### Ping Distance Sensors - -#### Time of Flight Distance Sensors - -### [Motors](../motors/../01-intro.md) - -### DC Motors - -### Servos - -### Stepper Motors - -### Batteries and Power - -#### AA Batteries - -#### LiPo Batteries - -## Intermediate Concepts - -### Interrupts - -## Advanced Concepts - -### MultiCore Programming - -## References - -https://www.sitepoint.com/css-printer-friendly-pages/ - -https://www.jotform.com/blog/css-perfect-print-stylesheet-98272/ - - diff --git a/docs/debugging/28-debugging-python.md b/docs/debugging/28-debugging-python.md deleted file mode 100644 index a04cb1551..000000000 --- a/docs/debugging/28-debugging-python.md +++ /dev/null @@ -1,26 +0,0 @@ -# How to Debug Micropython - -## Listing the Modules - -```py -help('modules') -``` - -Result: - -```txt -__main__ gc uasyncio/funcs uos -_boot machine uasyncio/lock urandom -_onewire math uasyncio/stream ure -_rp2 micropython ubinascii uselect -_thread onewire ucollections ustruct -_uasyncio rp2 uctypes usys -builtins uasyncio/__init__ uhashlib utime -ds18x20 uasyncio/core uio uzlib -framebuf uasyncio/event ujson -Plus any modules on the filesystem -``` - -## Micropython issues - -https://github.com/micropython/micropython/issues \ No newline at end of file diff --git a/docs/debugging/29-debugging-spi.md b/docs/debugging/29-debugging-spi.md deleted file mode 100644 index 9b5fe5197..000000000 --- a/docs/debugging/29-debugging-spi.md +++ /dev/null @@ -1,61 +0,0 @@ -# Debugging SPI - -In this lab we use a logic analyzer to debug the [SPI](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface) protocol being used to drive a sample OLED device. We will be using the the [8 port Saleae Logic Analyser](https://www.saleae.com/). The retail cost is about $399.00 although there are lower cost logic analyzer available. - -## The SSD1306 SPI OLED Timing Diagram -The OLED display is a read-only interface. It does not send any data back to the microcontroller, so there is no MOSI connection. The data is transmitted on the SDK line when the SCL line goes high. The CS line must be low for the OLED to be active. - -For details, see section 8.1.3 MCU Serial Interface on page 21 of the [SSD1305 132 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller](https://cdn-shop.adafruit.com/product-files/2719/2719+DATA.pdf). - -![SSD1306 Timing Diagram](../img/ssd1306-spi-timing-diagram.png) - -## OLED SPI settings -Our OLED device has seven wires. In addition to power and ground there a five data connections we will be observing on our logic analyzer. - -![SPI OLED Connections](../img/oled-back-connections.png) - -1. CS - Chip Select pin 4 -2. DC - Data/Command - pin 5 -3. RES - Reset - pin 6 -4. SDA - Data - SPIO TX GP7 pin 10 (Data from the ) -5. SCL - Clock - Connect to SPIO SCK GP6 pin 9 -6. VCC - Connect to the 3.3V Out pin 36 -7. GND - pin 38 or 3 any other GND pin - -## Setting up a Logic Analyzer -### Setup SPI Analyser -![SPI Logic Analyser Analysis Option](../img/spi-logic-analyser.png) - -### Configure SPI Channel Settings -![SPI Logic Analyser Settings](../img/spi-logic-analyser-settings.png)
                                                                                                                                                  -Saleae Logic Analyser SPI Logic Analyser Settings - -## Check a Working Device -The first thing we want to see is what the signals to a working SPI OLED should be. There are plenty of working drivers for the Arduino, so I hooked one up to the Logic analizer to see what they were. - -## Viewing Data Clock and RES -![SPI Clock](../img/spi-logic-analyser-data-clock-reset.png) - -![SPI Clock FUll](../img/spi-logic-analyser-full.png)
                                                                                                                                                  -All five signals - -![SPI Logic Analyser](../img/spi-logic-analyser-dc-cs.png)
                                                                                                                                                  -DC and CS signals have a larger period. - -![](../img/spi-logic-analyser-dc-cs-2.png) - -1. DC on was 3.668 milliseconds - -### Clock Period -Our Clock (SCL) has 8 positive pulses with a width of .4167 microseconds. This means that the positve/negative combined width has a period of 2 * .4167 = .8333 microseconds. This can be converted into a frequency of 1.2 megahertz. - -![](../img/spi-logic-analyser-clock-period.png) - -![](../img/spi-logic-analyser-clock-gap.png) - - -## References - -[Video on how to use the Saleae Logic Analyzer](https://www.youtube.com/watch?v=WMV04hzPKuM) - -https://www.youtube.com/watch?v=Ak9R4yxQPhs diff --git a/docs/debugging/29a-debugging-i2c.md b/docs/debugging/29a-debugging-i2c.md deleted file mode 100644 index 4ae705dfb..000000000 --- a/docs/debugging/29a-debugging-i2c.md +++ /dev/null @@ -1,3 +0,0 @@ -# Debugging I2C Bus - -![](../img/logic-analysis-i2c.png) \ No newline at end of file diff --git a/docs/displays/graph/01-intro.md b/docs/displays/graph/01-intro.md deleted file mode 100644 index 530876f2e..000000000 --- a/docs/displays/graph/01-intro.md +++ /dev/null @@ -1,45 +0,0 @@ -# Introduction to OLED Displays - -![](../../img/robot-oled-four-colors.jpg)
                                                                                                                                                  -Four colors of 2.44" OLED displays from DIY More. We can purchase them on EBay for around $18 each. - -We use small OLED displays in many of our labs because: - -1. They are **inexpensive** (around $4). -2. They are **easy** to connect** via I2C and SPI. Just four wires for I2C and seven wires for SPI. -3. They have a **large area** to display feedback. Most of them are 128X64 pixels. -4. Once you get the drivers installed (not always easy) they are **easy to program**. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions. -5. OLEDs, unlike LCDs, have **high contrast over a large range of input voltages**. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast. -6. There is plenty of **sample code and tutorials** available. -7. You can program them with Python (our student's favorite language) -8. They are crazy fun! - -The first step is to find out what type of display graphics chip is used in your OLED. - - -In these lessons we will assume you have a 128X64 or similar OLED display. Many of these displays can be purchased for around $4 on eBay. Many of these displays use the popular SSD1306 chip to drive the displays. There are also to communication options: - -1. I2C - simple 2 wire connection (not including power and ground) -2. SPI - five wires but also faster screen refresh rates - -Updating a 128X64 display using I2C takes around 37ms. When using the SPI interface, updating the display can be reduced to around 2.79ms. - -These labs will assume these parameters, but you can modify the labs to use different sizes and display driver chips by only modifying a few lines of code. - -## I2C Scanner -Because your microcontroller might have multiple displays on it, their must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function. - -```py -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("Device found at decimal", i2c.scan()) -``` - -If you don't see a return value of "60" or similar, then you need to check your wiring and make sure that you have an I2C (not an SPI) device. - -## References - -* [Wokwi web-based simulator of OLED display](https://wokwi.com/projects/359558101922696193) -* [Mike Causer's Awesome MicroPython Display Drivers](https://github.com/mcauser/awesome-micropython?tab=readme-ov-file#display) \ No newline at end of file diff --git a/docs/displays/graph/02-oled-setup.md b/docs/displays/graph/02-oled-setup.md deleted file mode 100644 index 0738b4cfc..000000000 --- a/docs/displays/graph/02-oled-setup.md +++ /dev/null @@ -1,76 +0,0 @@ -# OLED Setup - -At the beginning of of your Python programs there is usually a few lines of setup instruction to tell the system which libraries to use, what pins to assign and what devices to initialize. - -We will first look at the simple I2C setup. Then we will look at the SPI setup. - -## I2C Scanner -Because your microcontroller might have multiple I2C devices and displays on it, there must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function. - -```py -import machine -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("Device found at decimal", i2c.scan()) -``` - -returns: [60] - -returns: [60] - -## SSD1306 Examples - -### SSD1306 I2C Setup - -```py -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 64, i2c) -oled.text('Hello World!', 0, 0, 1) -oled.show() -``` - -### SSD1306 SPI Setup - -Back connections: -![OLED Back Connections](../../img/oled-back-connections.png) - -Front labels on OLED with SPI: -![OLED SPI Connection](../../img/oled-spi-connections.png) - -Here is the connection diagram: - -![SPI Connection](../../img/spi-connectins.png) - -Here is the code: - -```python -import machine import ssd1306 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -oled.text('Hello World!', 0, 0, 1) -oled.show() -``` - -## SSH1106 I2C Setup - -```py -from machine import Pin, I2C -import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) -oled = SH1106_I2C(128, 64, i2c) -oled.text('Hello World!', 0, 0, 1) -oled.show() -``` - -## References - -[Micropython SSD1306 Driver on GitHub](https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py) \ No newline at end of file diff --git a/docs/displays/graph/03-basic-drawing.md b/docs/displays/graph/03-basic-drawing.md deleted file mode 100644 index 75fce8ebf..000000000 --- a/docs/displays/graph/03-basic-drawing.md +++ /dev/null @@ -1,161 +0,0 @@ -### Basic Draw Functions - -For our beginning labs we will just do some basic drawing. We will start out with just four functions: - -1. Initialize the display framebuffer memory with the right object class initialization -2. Fill the framebuffer will zeros which are black pixels with the oled.fill(0) -3. Draw white text in the framebuffer memory with the oled.text("Hello World!", 40, 10) -4. Send the entire framebuffer to the display over the bus with the oled.show() function. - -### Initializing the Framebuffer - -Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled "oled" using the following line: - -```py -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 64, i2c) -``` - -|Function|Description|Parameters| -|--------|-----------|----------| -|oled.fill(0)|Fill the display with white or black|0=black and 1=white| -|oled.text("Hello",|Draw text|String, x (horizontal from left edge) and y (vertical from the top)Example: Draw "Hello World" 40 over and 10 down. oled.text("Hello World!", 40, 10)| -|show|Show the display|Send the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.| - -The full program would look like this: - -```py -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -``` - -This would display the following: - -![OLED SPI Hello World](../../img/oled-hello-world.png) - - -### Full list of Drawing Functions - -Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class. - -```py -from ssd1306 import SSD1306_I2C -print(dir(SSD1306_I2C)) -``` -This returns the following list: - -```py -['__class__', '__init__', '__module__', '__name__', '__qualname__', -'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline', -'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline', -'init_display', 'write_cmd', 'show', 'poweroff', 'poweron', -'contrast', 'write_data'] -``` -Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions. - -The following are relevant for the SSD1306_I2C display. - -The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state or color is 0=off (black) and 1=on (white). - -|Function|Description|Example| -|--------|-----------|-------| -|blit(fbuf, x, y, color)|Bit Level Transfer|blit(fbuf, 1, 1)| -|fill(state)|Fill|Fill with black (0) or white(1)| -|fill_rect|Fill a rectangle|| -|hline(x, x, length, state)|Draw a horizontal line|Draw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1)| -|invert()|invert the display|Filp the orientation of the display| -|line(x1,y1,x2,y2)|draw a line at any angle|Horizontal oled.line(0,0, 127, 63, 1)| -|pixel(x,y, color)|Draw a single point on the screen|| -|rect(x, y, width, height)|Draw an empty rectangle|| -|scroll(x,y)|Scroll the display|| -|text(x,y,color)|Write text at a point|| -|vline(x,y,length, color)|Draw a Vertical Line|oled.vline(width - 1, 0, height - 1, 1) # right edge| -|init_display()|Initialize the display|| -|write_cmd|Write a command to the display|| -|show()|Update the display from the frame buffer|| -|poweroff()||| -|poweron()||| -|contrast()||| -|write_data()||| - - -## Pixel Drawing Example - -```python -ICON = [ - [ 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 1, 1, 0, 0, 0, 1, 1, 0], - [ 1, 1, 1, 1, 0, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 1, 1, 1, 1, 1, 0, 0], - [ 0, 0, 0, 1, 1, 1, 0, 0, 0], - [ 0, 0, 0, 0, 1, 0, 0, 0, 0], -] - -display.fill(0) # Clear the display -for y, row in enumerate(ICON): - for x, c in enumerate(row): - display.pixel(x, y, c) - -display.show() -``` - -## Drawing Tutorial and Primitives - -Taken from the MicroPython site: [Using a SSD1306 OLED display](https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html) - although the path name imply the ESP8266, these functions also run on the Raspberry Pi Pico. - -```py -display.poweroff() # power off the display, pixels persist in memory -display.poweron() # power on the display, pixels redrawn -display.contrast(0) # dim -display.contrast(255) # bright -display.invert(1) # display inverted -display.invert(0) # display normal -display.rotate(True) # rotate 180 degrees -display.rotate(False) # rotate 0 degrees -display.show() # write the contents of the FrameBuffer to display memory -``` - -```py -display.fill(0) # fill entire screen with colour=0 -display.pixel(0, 10) # get pixel at x=0, y=10 -display.pixel(0, 10, 1) # set pixel at x=0, y=10 to colour=1 -display.hline(0, 8, 4, 1) # draw horizontal line x=0, y=8, width=4, colour=1 -display.vline(0, 8, 4, 1) # draw vertical line x=0, y=8, height=4, colour=1 -display.line(0, 0, 127, 63, 1) # draw a line from 0,0 to 127,63 -display.rect(10, 10, 107, 43, 1) # draw a rectangle outline 10,10 to 107,43, colour=1 -display.fill_rect(10, 10, 107, 43, 1) # draw a solid rectangle 10,10 to 107,43, colour=1 -display.text('Hello World', 0, 0, 1) # draw some text at x=0, y=0, colour=1 -display.scroll(20, 0) # scroll 20 pixels to the right -``` - -## Working with the framebuf - -A frame buffer is a region of RAM that holds an exact image of what is on the display. The data can be copied from the framebuffer memory with the ```blit()``` (BLock Transfer) operation that copies a rectangular area of one framebuffer to another framebuffer. - -Here is an example of the blit() function: - -```py -oled.blit(my_frame_buf, 10, 10, 0) -``` - -```py -# draw another FrameBuffer on top of the current one at the given coordinates -import framebuf -fbuf = framebuf.FrameBuffer(bytearray(8 * 8 * 1), 8, 8, framebuf.MONO_VLSB) -fbuf.line(0, 0, 7, 7, 1) -display.blit(fbuf, 10, 10, 0) # draw on top at x=10, y=10, key=0 -display.show() -``` - -## References - -* [MicroPython Documentation on FrameBuffer](https://docs.micropython.org/en/latest/library/framebuf.html) -* [Drawing Primitive Shapes](https://docs.micropython.org/en/latest/library/framebuf.html#drawing-primitive-shapes) -* [Driving I2C OLED displays with MicroPython](https://www.mfitzp.com/article/oled-displays-i2c-micropython/) - by Martin Fitzpatrick -* [ST7735 Micropython Driver by Anthony Norman](https://github.com/AnthonyKNorman/MicroPython_ST7735) \ No newline at end of file diff --git a/docs/displays/graph/03-bitmaps.md b/docs/displays/graph/03-bitmaps.md deleted file mode 100644 index e87fa17e8..000000000 --- a/docs/displays/graph/03-bitmaps.md +++ /dev/null @@ -1,66 +0,0 @@ -# Drawing Bitmaps with MicroPython - -## Framebuffers - -A [Framebuffer](../../misc/glossary.md#framebuffer) is the core data structure we use when drawing bitmaps. - -## Block Image Transfers (blit) -The basic function we use to draw a rectangular region of the screen is called the ```blit()``` function: - -```py -display.blit(frame_buffer, x, y) -``` - -This function moves all the data within any frame buffer to the given (x,y) position of the display. The function will check the dimensions of the frame buffer to know how much data to move to the display. You just need to tell the function where to start drawing. - -## Blit Functions Are Efficient - -Blit operations can be much more efficient then the ```display.show()``` function when you are just updating a small region of the screen. This is because the ```display.show()``` function transfers the entire screen image each time it is called. Using ```blit``` functions can be written to only update the area of the screen that changes. - -For example, if you are writing a video game that has a ball moving across the screen, you only need to update the pixels around the ball, not the entire screen image. The exact performance difference between ```show()``` and ```blit()``` operations will depend on the size of the screen, the size of the blit update and the speed of the transfer of data from the framebuffer to the display device. - -The key disadvantage of using ```blit()``` functions is that you must consider what other artifacts there are on the screen that you might overwrite. Keeping track of the differences requires more computation by the microcontroller. The more powerful your microcontroller is relative to the communication speed, the more difference computations you can do. - -Not all display drivers will let you write directly from the microcontroller resident image directly to a region of the display. Sometimes you must follow your blit() operations with a show() to transfer the entire framebuffer to the display. - -## Working with ByteArrays - -MicroPython blit operations use a data representation format for images called a ByteArray. These are sequences of the bytes that will be sent in a blit operation. They are coded using the following notation: - -```py -my_bytearray = (b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD") -``` - -Note that the letter ```b``` begins the parameter to show the Python interpreter that the all the characters between the double quotes are byte array values. The characters ```\x``` indicate that there are hexadecimals useds to encode the bit values. - -## Creating a Solid Block of Pixels - -Sometimes you want to update an entire region of the screen with a block of pixels that are all on or off. You can do this with the following steps - -```python -# create a 10x10 matrix of on pixels -# allocate an array of 20 bytes = -on_buffer = bytearray(20) -# put all 1's in that buffer -on_buffer[:] = b'\xff' * 20 -# create a frame buffer using monochrome -on_square = framebuf.FrameBuffer(on_buffer, 10, 10, framebuf.MONO_HLSB) - -oled.blit(logo, i, 0) -``` - -## Image Encoding Options - -There are several alternate methods to encode the bits of an image into a byte array. The bits can be coded left to right or top to bottom. You can also put the bits in most-significant bit first or least-significant bit first. All these options and controlled when you interface with a framebuffer. - -### Vertical Least Significant Bit Layout -framebuf.MONO_VLSB -Monochrome (1-bit) color format This defines a mapping where the bits in a byte are vertically mapped with bit 0 being nearest the top of the screen. Consequently each byte occupies 8 vertical pixels. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached. Further bytes are rendered at locations starting at the leftmost edge, 8 pixels lower. - -### Horizontal -MONO_HLSB. Monochrome (1-bit) color format This defines a mapping where the bits in a byte are horizontally mapped. Each byte occupies 8 horizontal pixels with bit 7 being the leftmost. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached. - -## References - -[MicroPython Bitmap Tool Video](https://www.youtube.com/watch?v=a7MzPA0T_MM) - this video created by Lucky Resistor -is a good overview of the image formats used by MicroPython. \ No newline at end of file diff --git a/docs/displays/graph/04-extended-drawing-functions.md b/docs/displays/graph/04-extended-drawing-functions.md deleted file mode 100644 index bb4c5a18c..000000000 --- a/docs/displays/graph/04-extended-drawing-functions.md +++ /dev/null @@ -1,86 +0,0 @@ -# Extending Drawing Functions - -Although there are several drawing functions available in most of the standard graphics libraries, most of them lack some basic shapes such as a circle. To draw circles on your display, you will need to add new Python functions. Here are some examples of these custom drawing functions. - -## Circle - -Here is a function to draw a circle at a given (x,y) point with a radius of r and fill indicator. - -Here are the parameters for circle functions - -1. X position of the circle center -2. Y position of the circle center -3. The radius of the circle in pixels -4. The color of the circle (1 for on and 0 for off. - - -```python -from math import sqrt - -def draw_circle(cx, cy, r, color): - diameter = r*2 - upper_left_x = cx - r - upper_left_y = cy - r - # scan through all pixels and only turn on pixels within r of the center - for i in range(upper_left_x, upper_left_x + diameter): - for j in range(upper_left_y, upper_left_y + diameter): - # distance of the current point (i, j) from the center (cx, cy) - d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 ) - if d < r: - oled.pixel(i, j, color) - -``` - -## Testing Circle Drawing - -```py -from machine import Pin -from utime import sleep -from math import sqrt -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) # SCL -data=Pin(3) # SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def circle(cx, cy, r, color): - diameter = r*2 - upper_left_x = cx - r - upper_left_y = cy - r - # scan through all pixels and only turn on pixels within r of the center - for i in range(upper_left_x, upper_left_x + diameter): - for j in range(upper_left_y, upper_left_y + diameter): - # distance of the current point (i, j) from the center (cx, cy) - d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 ) - if d < r: - oled.pixel(i, j, color) - -HALF_WIDTH = int(WIDTH/2) -HALF_HEIGHT = int(HEIGHT/2) -while True: - for rad in range(1,HALF_HEIGHT+2): - draw_circle(HALF_WIDTH, HALF_HEIGHT, rad, 1) - oled.show() - sleep(.1) - sleep(3) - oled.fill(1) - for rad in range(1,HALF_HEIGHT+2): - circle(HALF_WIDTH, HALF_HEIGHT, rad, 0) - oled.show() - sleep(.1) - oled.fill(0) - sleep(3) -``` - -## Drawing a Face -If we assume we have a 64x128 display we can call two circle functions to draw eyes - -display.fill(0) # Clear the display. -display.circle(32, 32, 10, 1) # draw the left eye \ No newline at end of file diff --git a/docs/displays/graph/05-timing-draw-speed.md b/docs/displays/graph/05-timing-draw-speed.md deleted file mode 100644 index ee17e990a..000000000 --- a/docs/displays/graph/05-timing-draw-speed.md +++ /dev/null @@ -1,97 +0,0 @@ -# Timing Drawing Speed - -If you are writing a video game and want fast drawing times for objects on the screen, there are several different algorithms you can try. You can use the MicroPython ```time_us``` function to -record the time before and after you call a drawing function and return the difference -to get an idea of the time saved in different versions of your drawing functions. - -## Sample Function Timer Code - -## Sample Function Code - -```py -from utime import ticks_us - -start = ticks_us() -my_function() -end = ticks_us() -print('Execution time in microseconds:', end - start) -``` - -MicroPython also supports the ```ticks_cpu()``` function which could return a smaller granularity -for precise time measurements. However, on the Raspberry Pi implementation, the results are exactly -the same as the ```ticks_us()``` function. - -## Comparing Two Circle Drawing Algorithms - -In the following code, we compare two circle drawing algorithms. - -1. **Row Scanner Method** - this method scans each pixel in the square around the circle and turns it on if the pixel is within a distance range. It must calculate the distance of each pixel and compare -2. that distance to both the inside and outside distances. The time-consuming operations are to calculate the squares of the x and y distances. -3. **Point Draw Method** - this method walks around the circle and for each degree, it draws a single pixel at the edge of the circle. Each point uses the ```sine()``` and ```cosine()``` functions to calculate the x and y distance from the center of the circle to that point. - -For small circles, it is very inefficient to calculate all 360 points. Scanning all the points in a 5X5 grid only takes 25 calculations. However, the larger the circle becomes, the more points there are to calculate in the row scanner method. A 20X20 circle will need to run the distance calculation 400 times. - -```py -from utime import sleep, ticks_cpu, ticks_us -import math -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# -def fast_circle(x, y, r, color): - # draw points around a circle skiping every 4th one - for theta in range(0, 360, 2): - # we can save 5% of the time by only doing this once - radians = math.radians(theta) - x_pos = int(x + r * math.cos(radians)) - y_pos = int(y + r * math.sin(radians)) - # check if we are within range - #if 0 <= x_pos < 128 and 0 <= y_pos < 64: - # we can cut another 5% by not doing these checks - oled.pixel(x_pos, y_pos, color) - -def circle(x, y, r, color): - diameter1 = (r - 0.5) ** 2 - diameter2 = (r + 0.5) ** 2 - x_min = max(0, int(x - r)) - x_max = min(128, int(x + r + 1)) - y_min = max(0, int(y - r)) - y_max = min(64, int(y + r + 1)) - - for y_pos in range(y_min, y_max): - for x_pos in range(x_min, x_max): - if ((x_pos - x) ** 2 + (y_pos - y) ** 2 >= diameter1) and ((x_pos - x) ** 2 + (y_pos - y) ** 2 <= diameter2): - oled.pixel(x_pos, y_pos, color) - - -start = ticks_us() -circle(32, 32, 10, 1) -end = ticks_us() -print('Standard scanner circle draw time in cpu ticks', end - start) -oled.show() -sleep(1) -start = ticks_us() -fast_circle(96, 32, 10, 1) -end = ticks_us() -print('Fast draw time in cpu ticks', end - start) -oled.show() -``` - -!!! Challenge - 1. Write a program that compares drawing speed for various sizes of circles. - 2. Modify the circle function to use the most efficient algorithm - 3. If you have a small circle, how many points do you need to not make the circle appear broken? Try changing the number of points calculated in the line ```for theta in range(0, 360, 2):``. Can you dynamically change the number of points skipped as the circle becomes smaller? - 4. Can you add a parameter to the circle function that only draws every 3rd point? \ No newline at end of file diff --git a/docs/displays/graph/10-oled-bounce.md b/docs/displays/graph/10-oled-bounce.md deleted file mode 100644 index 025b4f09a..000000000 --- a/docs/displays/graph/10-oled-bounce.md +++ /dev/null @@ -1,96 +0,0 @@ -# OLED Bounce - -In this lesson, we will draw a box around the edge of the display using the commands that draw horizontal and vertical lines: ```hline``` and ```vline```. Then we will draw a ball that bounces off these edges. - - -## Draw a border - -```py -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.hline(0, 0, width - 1, 1) # top edge -oled.hline(0, height - 1, width - 1, 1) # bottom edge -oled.vline(0, 0, height - 1, 1) # left edge -oled.vline(width - 1, 0, height - 1, 1) # right edge -oled.show() -``` - -## Make a Ball Bounce Around Inside the Wall - -```py -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 1, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, state): - if size == 1: - oled.pixel(x, y, state) # draw a single pixel - else: - for i in range(0,size): # draw a box of pixels of the right size - for j in range(0,size): - oled.pixel(x + i, y + j, state) - # TODO: for size above 4 round the corners - -border(width, height) - -ball_size = 2 -# start in the middle of the screen -current_x = int(width / 2) -current_y = int(height / 2) -# start going down to the right -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - draw_ball(current_x,current_y, ball_size,1) - oled.show() - # utime.sleep(delay_time) - draw_ball(current_x,current_y,ball_size,0) - # reverse at the edges - # left edge test - if current_x < 2: - direction_x = 1 - # right edge test - if current_x > width - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 2: - direction_y = 1 - # bottom edge test - if current_y > height - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y -``` - diff --git a/docs/displays/graph/11-lcd-waveshare.md b/docs/displays/graph/11-lcd-waveshare.md deleted file mode 100644 index 2dfe5a542..000000000 --- a/docs/displays/graph/11-lcd-waveshare.md +++ /dev/null @@ -1,21 +0,0 @@ -# Waveshare LCD - -## Specification -1. Description: 1.8 inch TFT LCD Display Module For Raspberry Pi Pico -2. List price: $10 US + shipping -3. 65K RGB Colors -4. Resolution: 160×128 Pixels -5. Interface: SPI -6. Driver: ST7735S Driver -7. Onboard Female Pin Header For Direct Attaching To Raspberry Pi Pico -8. Pixel size: 0.219 × 0.219 mm -9. Dimensions 52.0 × 34.5 mm -10. Operating voltage: 2.6~5.5V -11. 18 bits per pixel (6 bits per color) - - -## References -[Waveshare spec](https://www.waveshare.com/pico-lcd-1.8.htm) -[Waveshare wiki](https://www.waveshare.com/wiki/Pico-LCD-1.8) -[Demo Code](https://www.waveshare.com/w/upload/9/9c/Pico_LCD_code.zip) -[ST7735S Datasheet](https://www.waveshare.com/w/upload/e/e2/ST7735S_V1.1_20111121.pdf) \ No newline at end of file diff --git a/docs/displays/graph/11-oled-ping.md b/docs/displays/graph/11-oled-ping.md deleted file mode 100644 index 819e6cf34..000000000 --- a/docs/displays/graph/11-oled-ping.md +++ /dev/null @@ -1,66 +0,0 @@ -# OLED PING - -## Circuit - -![](../../img/oled-ping-circuit.png) - -## Coder - -```py -from machine import Pin, I2C, Timer -from ssd1306 import SSD1306_I2C -import utime - - -# global toggle button variable -measure_on = False - -# debounce for button -def debounce(pin): - timer.init(mode=Timer.ONE_SHOT, period=200, callback=on_pressed) - -# if button pressed, toggle measure_on -def on_pressed(timer): - global measure_on - measure_on = not measure_on - -# Init button -button = Pin(16, Pin.IN, Pin.PULL_DOWN) -timer = Timer() -button.irq(debounce, Pin.IRQ_RISING) - -# Init Display -i2c = I2C(0,sda=Pin(0),scl=Pin(1),freq=40000) -oled = SSD1306_I2C(128,64,i2c) - -# Init HC-SR04 pins -trigger = Pin(14, Pin.OUT) -echo = Pin(13, Pin.IN) - - -def ultra(): - trigger.low() - utime.sleep_us(2) - trigger.high() - utime.sleep_us(5) - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -try: - while True: - oled.fill(0) - if measure_on: - result = ultra() - oled.text("Distance:",0,0) - oled.text(str(result) + " cm",0,10) - oled.show() - utime.sleep(1) -except KeyboardInterrupt: - pass -``` \ No newline at end of file diff --git a/docs/displays/graph/11-oled-sh1106-i2c.md b/docs/displays/graph/11-oled-sh1106-i2c.md deleted file mode 100644 index 713504b26..000000000 --- a/docs/displays/graph/11-oled-sh1106-i2c.md +++ /dev/null @@ -1,175 +0,0 @@ -# OLED SSD1306 I2C Examples - -We use small OLED displays in many of our labs because: - -1. They are **inexpensive** (around $4). -2. They are **easy to connect** via SPI. Just four wires: GND, VCC, Clock and Data. -3. They have a **large area** to display feedback. Most of them are 128X64 pixels. -4. Once you get the drivers installed (not always easy) they are **easy to program**. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions. -5. OLEDs, unlike LCDs, have **high contrast over a large range of input voltages**. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast. -6. There is plenty of **sample code and tutorials** available. - - -The first step is to find out what type of display graphics chip is used in your OLED. - - -## SH1106 Example - -```py -from machine import Pin, I2C -import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c) -display.sleep(False) - -display.fill(0) -display.text('CoderDojo', 0, 0, 1) -display.show() - -print('done') -``` - -## Counter Example -In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50. - -```py -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) - -for i in range(1, 51): # count 1 to 50 - oled.fill(0) # clear to black - oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black - oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top - oled.show() # update display - utime.sleep(0.1) #wait 1/10th of a second - -print('done') -``` - -## Animated Box -This draws a title and four lines around a drawing area. It then draws boxes that move to the right. - -```py -from machine import Pin, I2C -import sh1106 -import utime - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) - -## note that we can only draw from 0 to 62 -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c) -display.sleep(False) - -display.fill(0) # clear to black -display.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black -# line under title -display.hline(0, 9, 127, 1) -# bottom of display -display.hline(0, 30, 127, 1) -# left edge -display.vline(0, 10, 32, 1) -# right edge -display.vline(127, 10, 32, 1) - -for i in range(0, 118): - # box x0, y0, width, height, on - display.fill_rect(i,10, 10, 10, 1) - # draw black behind number - display.fill_rect(10, 21, 30, 8, 0) - display.text(str(i), 10, 21, 1) - display.show() # update display - # utime.sleep(0.001) - -print('done') -``` - -## Bounce on the SH1106 Display using I2C - -This example is a ball that bounces around the inside of a border rectangle. Is similar to other bounce examples with the exception that you can't draw on the last row of pixels. - -```py -import machine -import utime -# from ssd1306 import SSD1306_I2C -import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 # we could make this be 63 but the init method should use the full value -# oled = SSD1306_I2C(width, height, i2c) -oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 2, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, state): - if size == 1: - oled.pixel(x, y, state) # draw a single pixel - else: - for i in range(0,size): # draw a box of pixels of the right size - for j in range(0,size): - oled.pixel(x + i, y + j, state) - # TODO: for size above 4 round the corners - -border(width, height) - -ball_size = 5 -current_x = int(width / 2) -current_y = int(height / 2) -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# oled.line(0, height-2, width-1, height-2, 1) - -# Bounce forever -while True: - draw_ball(current_x,current_y, ball_size,1) - oled.show() - # utime.sleep(delay_time) - draw_ball(current_x,current_y,ball_size,0) - # reverse at the edges - # left edge test - if current_x < 2: - direction_x = 1 - # right edge test - if current_x > width - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 2: - direction_y = 1 - # bottom edge test - if current_y > height - ball_size - 3: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y - -print('done') -``` - -## SH1106 References - -1. [Robert HH SH1106 Driver GitHub](https://github.com/robert-hh/SH1106/blob/master/sh1106.py) \ No newline at end of file diff --git a/docs/displays/graph/11-oled-ssd1306-i2c.md b/docs/displays/graph/11-oled-ssd1306-i2c.md deleted file mode 100644 index 601424724..000000000 --- a/docs/displays/graph/11-oled-ssd1306-i2c.md +++ /dev/null @@ -1,250 +0,0 @@ -# OLED SSD1306 Examples - - -## Using the SSD1306 with I2C Interfaces - -### Add the ssd1306 Python Module - -You can now use the Thonny "Tools -> Manage Packages..." menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use. - -![](../../img/thonny-add-ssd1306.png) - -If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command. - -## I2C Hello World - -```py -import machine -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -print('Done') -``` - -After this program runs you should see the text on your OLED display. -![](../../img/oled-hello-world.png) - -## SH1106 Example - -```py -from machine import Pin, I2C -import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c) -display.sleep(False) - -display.fill(0) -display.text('CoderDojo', 0, 0, 1) -display.show() - -print('done') -``` - -## Counter Example -In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50. - -```py -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) - -for i in range(1, 51): # count 1 to 50 - oled.fill(0) # clear to black - oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black - oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top - oled.show() # update display - utime.sleep(0.1) #wait 1/10th of a second - -print('done') -``` - -## Animated Box -This draws a title and four lines around a drawing area. It then draws boxes that move to the right. - -```py -from machine import Pin, I2C -import sh1106 -import utime - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c) -display.sleep(False) - -display.fill(0) # clear to black -display.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black -# line under title -display.hline(0, 9, 127, 1) -# bottom of display -display.hline(0, 30, 127, 1) -# left edge -display.vline(0, 10, 32, 1) -# right edge -display.vline(127, 10, 32, 1) - -for i in range(0, 118): - # box x0, y0, width, height, on - display.fill_rect(i,10, 10, 10, 1) - # draw black behind number - display.fill_rect(10, 21, 30, 8, 0) - display.text(str(i), 10, 21, 1) - display.show() # update display - # utime.sleep(0.001) - -print('done') -``` - -## Install SSD1306 Module - -![](../../img/install-ssd1306.png) - -## ssd1306 module - -[SSD1306 Library](https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py) - click the RAW button and then right click to do a "Save As" - -## SSD1306 vs. SH1106 -There is only one small difference between SSD1306 and SH1106: The SH1106 controller has an internal RAM of 132x64 pixel. The SSD1306 only has 128x64 pixel. - -## The SPI interface -The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy. - -### SPI Baudrate -https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c - -The seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display: - -![](../../img/oled-back-connections.png) - -1. CS - Chip Select - pin 4 -2. DC - Data/Command - pin 5 -3. RES - Reset - pin 6 -4. SDA - Data - SPIO TX GP7 pin 10 -5. SCL - Clock - Connect to SPIO SCK GP6 pin 9 -6. VCC - Connect to the 3.3V Out pin 36 -7. GND - pin 38 or 3 any other GND pin - - -### Pico Pins - -``` -# Sample code sections - 28 # ------------ SPI ------------------ - 29 # Pin Map SPI - 30 # - 3v - xxxxxx - Vcc - 31 # - G - xxxxxx - Gnd - 32 # - D7 - GPIO 13 - Din / MOSI fixed - 33 # - D5 - GPIO 14 - Clk / Sck fixed - 34 # - D8 - GPIO 4 - CS (optional, if the only connected device) - 35 # - D2 - GPIO 5 - D/C - 36 # - D1 - GPIO 2 - Res -``` - -SCK is the clock - hook this to the oled SCL -MOSI is the line taking data from your Pico to the peripheral device. Hook this to SDA - -From the SDK: -https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf -Section 3.7 - -1. SPI0_SCK - pin 6 -2. SPI0_MOSI - pin 7 -3. SPI0_MISO - pin 8 - -This contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO - -``` -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi_rx=machine.Pin(4) -``` - - -### SPI Terms -Master Out Slave In (MOSI) - - -We send the data to the SPI RX (Receive) port on the Pico. These are pin 1 (GP0) or pin 6 (GP4) - -## Sample Nonworking SPI Code - -From the documentation: - -!!! From Raspberry Pi Pico Documentation - **spi** is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used. - - **dc** is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver. - - **res** is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies. - - **cs** is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies. - -```py -import machine -import machine -import utime -import ssd1306 -led = machine.Pin(25, machine.Pin.OUT) - -# From: https://github.com/robert-hh/SH1106 -# display = sh1106.SH1106_SPI(width, height, spi, dc, res, cs) -#MOSI=machine.Pin(7) -#SCK=machine.Pin(6) -#spi = machine.SPI(0, baudrate=400000, sck=SCK, mosi=MOSI) -spi_sck=machine.Pin(6) -spi_tx=machine.Pin(7) -# spi_rx=machine.Pin(4) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) - -CS = machine.Pin(8) -DC = machine.Pin(9) -RES = machine.Pin(10) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# flash all pixels on -oled.fill(1) -oled.show() -utime.sleep(0.5) - -oled.fill(0) -oled.text('CoderDojo Rocks!', 0, 0, 1) -oled.show() - -# flash the LED to show end -led.high() -utime.sleep(0.5) -led.low() - -print('Done') -``` - -## References - -1. [MicroPython Tutorial on the SSD1306](https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html) - -2. [robert-hh's SH1106 Driver](https://github.com/robert-hh/SH1106) - -3. [M Fitzp OLED Display i2c Article](https://www.mfitzp.com/article/oled-displays-i2c-micropython/) - -4. [Adafruit Stats](https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/master/examples/ssd1306_stats.py) - -[DIY More OLED Product Description](https://www.diymore.cc/collections/all-about-arduino/products/2-42-inch-12864-oled-display-module-iic-i2c-spi-serial-for-arduino-c51-stm32-green-white-blue-yellow?variant=17060396597306) - -1. [Using I2C Defaults](https://github.com/raspberrypi/pico-micropython-examples/blob/master/i2c/1306oled/i2c_1306oled_using_defaults.py) \ No newline at end of file diff --git a/docs/displays/graph/11-oled-ssd1306-spi.md b/docs/displays/graph/11-oled-ssd1306-spi.md deleted file mode 100644 index d49ff8b1e..000000000 --- a/docs/displays/graph/11-oled-ssd1306-spi.md +++ /dev/null @@ -1,152 +0,0 @@ -# OLED SSD1306 SPI Examples - -## Using the SSD1306 with SPI Interfaces - -### Add the ssd1306 Python Module - -You can now use the Thonny "Tools -> Manage Packages..." menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use. - -![](../../img/thonny-add-ssd1306.png) - -If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command. - - -## Install SSD1306 Module - -![](../../img/install-ssd1306.png) - -## ssd1306 module - -[SSD1306 Library](https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py) - click the RAW button and then right click to do a "Save As" - -[SSD1306 Library Searchable](https://github.com/stlehmann/micropython-ssd1306/blob/master/ssd1306.py) - -## The SPI interface -The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy. - -## Displaying SPI Defaults - -```py -from machine import Pin -from ssd1306 import SSD1306_SPI -# default is data (MOSI) on GP7 and clock (sck) on GP6 -spi=machine.SPI(0) -print(spi) -SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=6, mosi=7, miso=4) -### SPI Baudrate -https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c - -The seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display: - -![](../../img/oled-back-connections.png) - -1. CS - Chip Select - pin 4 -2. DC - Data/Command - pin 5 -3. RES - Reset - pin 6 -4. SDA - Data - SPIO TX GP7 pin 10 -5. SCL - Clock - Connect to SPIO SCK GP6 pin 9 -6. VCC - Connect to the 3.3V Out pin 36 -7. GND - pin 38 or 3 any other GND pin - -### Pico Pins - -``` -# Sample code sections - 28 # ------------ SPI ------------------ - 29 # Pin Map SPI - 30 # - 3v - xxxxxx - Vcc - 31 # - G - xxxxxx - Gnd - 32 # - D7 - GPIO 13 - Din / MOSI fixed - 33 # - D5 - GPIO 14 - Clk / Sck fixed - 34 # - D8 - GPIO 4 - CS (optional, if the only connected device) - 35 # - D2 - GPIO 5 - D/C - 36 # - D1 - GPIO 2 - Res -``` - -* SCK is the clock - hook this to the oled SCL -* MOSI is the line taking data from your Pico to the peripheral device. Hook this to SDA - -From the SDK: -https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf -Section 3.7 - -1. SPI0_SCK - pin 6 -2. SPI0_MOSI - pin 7 -3. SPI0_MISO - pin 8 - -This contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO - -``` -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi_rx=machine.Pin(4) -``` - -We send the data to the SPI RX (Receive) port on the Pico. These are pin 1 (GP0) or pin 6 (GP4) - -## Sample Nonworking SPI Code - -From the documentation: - -!!! From Raspberry Pi Pico Documentation - **spi** is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used. - - **dc** is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver. - - **res** is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies. - - **cs** is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies. - -```py -import machine -import utime -import ssd1306 -led = machine.Pin(25, machine.Pin.OUT) - -spi_sck=machine.Pin(6) -spi_tx=machine.Pin(7) -# spi_rx=machine.Pin(4) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) - -CS = machine.Pin(8) -DC = machine.Pin(9) -RES = machine.Pin(10) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# flash all pixels on -oled.fill(1) -oled.show() -utime.sleep(0.5) - -oled.fill(0) -oled.text('CoderDojo Rocks!', 0, 0, 1) -oled.show() - -# flash the LED to show end -led.high() -utime.sleep(0.5) -led.low() - -print('Done') -``` - -## References - -[robert-hh's SH1106 Driver](https://github.com/robert-hh/SH1106) - -[MicroPython SSD1306 Class](https://github.com/stlehmann/micropython-ssd1306/blob/master/ssd1306.py) - -https://www.mfitzp.com/article/oled-displays-i2c-micropython/ - -https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/master/examples/ssd1306_stats.py - -https://github.com/robert-hh/SH1106/blob/master/sh1106.py - -[DIY More OLED Product Description](https://www.diymore.cc/collections/all-about-arduino/products/2-42-inch-12864-oled-display-module-iic-i2c-spi-serial-for-arduino-c51-stm32-green-white-blue-yellow?variant=17060396597306) - -## SSD1306 -https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1306/ - -## SSD1307 -https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1307/ \ No newline at end of file diff --git a/docs/displays/graph/11-pong.md b/docs/displays/graph/11-pong.md deleted file mode 100644 index ebf4b2d86..000000000 --- a/docs/displays/graph/11-pong.md +++ /dev/null @@ -1,255 +0,0 @@ -# Pong -Using a low-cost OLED device you can write a pong game. If you use a small 128X64 OLED the price can be around $12. - -## Part list - -|Part Name|Price|Link|Description| -|---------|-----|----|-----------| -|Raspberry Pi Pico|$4|[Microcenter](https://www.microcenter.com/search/search_results.aspx?N=&cat=&Ntt=raspberry+pi+pico&searchButton=search)|With 264K RAM it has plenty of room for storing the framebuffer| -|1/2 Size Solderless Breadboard|$2|link|400 tie breadboard|Used to mount the pico| -|128X64 OLED|$5|[eBay](https://www.ebay.com/itm/0-96-OLED-LCD-Display-Module-IIC-I2C-Interface-128x64-For-SSD1306-Prof/373470677081)|You can also get larger 2.42" displays for around $20| -|2 10K Potentiometers|$1.5 each|[eBay](https://www.ebay.com/itm/10K-OHM-Linear-Taper-Rotary-Potentiometer-10KB-B10K-Pot-With-Wire-Portable-H/303636919492)|You can purchase these in QTY 10 for less. Use the part number B10K to narrow your search.| -|Clear Plastic Box|$4|[The Container Store](https://www.containerstore.com/s/clear-stackable-rectangle-containers-with-white-lids)|Shallow Narrow Stackable Rectangle Clear with Lids 8-1/4" x 3-1/2" x 1-7/8" h. The link is to the white lids.| - -![](../../img/raspberry-pi-pico.png) - -Raspberry Pi Pico for $4. - -![](../../img/oled-i2c.png) - -OLED with I2C Interface. Note the pins are VCC, GND, SCL (clock), SDA (data). - -![](../../img/breadboard.png) - -1/2 size 400 connector solderless breadboard - -![](../../img/10k-pot.png) - -10K potentiometer with pre-soldered connectors. You will need two of these. You can use a male-to-male header to connect it to the breadboard. - -## Connections - -1. Connect the GND of the OLED to GND of the Pico -2. Connect the VCC of the OLED to 3V3 OUT (physical pin 36) -3. Connect the SDA (data) of the OLED to the Pico GP0 (physical pin 1 on the top left with USB up) -4. Connect the SCL (clock) of the OLED to GP1 (physical pin 2) -5. Connect the center tap of both potentiometers to ADC0 (GP26 - pin 31) and ADC1 (GP27 - pin 32) -6. Connect the outer connectors of the potentiometers to VCC and GND - -## Getting the Right Python Libraries - -To run this program, you will need a MicroPython display driver. Our display in this example is the popular SSD1306 driver chip. Your OLED might have a slightly different driver type. - -Here is the line that must be customized for your display: - -``` -from ssd1306 import SSD1306_I2C -``` - -## Testing the OLED - -This test will verify that your OLED connections are correct. - -```py -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -WIDTH = 128 -HEIGHT = 64 -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) -oled.fill(0) -oled.text("CoderDojo Rocks",0,0) -oled.show() -``` - -## Drawing the Border - -``` -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) -``` - -## Full Program - -```python -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(26) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# globals variables -# static variables are constants are uppercase variable names -WIDTH = 128 -HALF_WIDTH = int(WIDTH / 2) -HEIGHT = 64 -HALF_HEIGHT = HEIGHT -BALL_SIZE = 3 # 2X2 pixels -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 -# continiuous update of the paddle and ball -# play_startup_sound() -# start with the ball in the center -ball_x = int(WIDTH / 2) -ball_y = int(HEIGHT / 2) -# set the initial directinon to down to the right -ball_x_dir = 1 -ball_y_dir = 1 - -def play_startup_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.freq(1200) - sleep(.25) - speaker.duty_u16(0) - -def play_bounce_sound(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.25) - speaker.duty_u16(0) - -def play_score_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.duty_u16(0) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) - - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 0 - else: - x = WIDTH - 2 - y = paddle_center - HALF_PAD_HEIGHT - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - -def draw_ball(): - oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now - -# The main event loop -while True: - oled.fill(0) # clear screen - oled.vline(int(WIDTH / 2), 0, HEIGHT, 1) - # border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = pot_pin_1.read_u16() - pot_val_2 = pot_pin_1.read_u16() - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT) - draw_ball() - - #update ball position with the current directions - ball_x = ball_x + ball_x_dir - ball_y = ball_y + ball_y_dir - - # update the ball direction if we are at the top or bottom edge - if ball_y < 0: - ball_y_dir = 1 - #play_bounce_sound() - if ball_y > HEIGHT - 3: - ball_y_dir = -1 - #play_bounce_sound() - - # if it hits the paddle bounce else score - if ball_x < 1: - top_paddle = pot_val_1 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - # we have a hit - ball_x_dir = 1 - ball_x = 2 - play_bounce_sound() - print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle) - else: - # we have a score for the right player - play_score_sound() - r_score += 1 - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - print('score on left edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - if ball_x > WIDTH - 3: - ball_x = WIDTH - 4 - top_paddle = pot_val_2 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - ball_x_dir = -1 - print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle) - else: - l_score += 1 - play_score_sound() - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - play_bounce_sound() - print('score on right edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - oled.text(str(l_score), HALF_WIDTH - 20, 5, 1) - - oled.text(str(r_score), HALF_WIDTH + 5, 5, 1) - - oled.show() -``` - -[YouTube Video](https://www.youtube.com/watch?v=W6Yr9gv2dTQ) \ No newline at end of file diff --git a/docs/displays/graph/12-e-paper-display.md b/docs/displays/graph/12-e-paper-display.md deleted file mode 100644 index 6b7cbc4dd..000000000 --- a/docs/displays/graph/12-e-paper-display.md +++ /dev/null @@ -1,16 +0,0 @@ -# Raspberry Pi E-Paper Displays with - -## Specifications - -1. 2.9inch capacitive touch ePaper module, 296×128 resolution -1. 5-points touch support, user-defined wakeup gesture -1. No backlight, keeps displaying last content for a long time even when power down -1. Ultra low power consumption, basically power is only required for refreshing -1. SPI / I2C interface, requires minimal IO pins -1. Comes with development resources and manual (Raspberry Pi Pico C/C++ and MicroPython examples) - -## Resources - -1. [Waveshare Product Page](https://www.waveshare.com/pico-captouch-epaper-2.9.htm) -2. [Waveshare Wiki](https://www.waveshare.com/wiki/Pico-CapTouch-ePaper-2.9) -3. [Sample MicroPython Driver](https://github.com/waveshare/Pico_ePaper_Code/blob/main/python/0Pico-ePaper-5.65f.py \ No newline at end of file diff --git a/docs/displays/graph/12-oled-pot.md b/docs/displays/graph/12-oled-pot.md deleted file mode 100644 index a76cba666..000000000 --- a/docs/displays/graph/12-oled-pot.md +++ /dev/null @@ -1,171 +0,0 @@ -# OLED Potentiometer Example - -In this lesson, we will use a potentiometer to change the value of an OLED display. We will use a small SSD1306 OLED with an I2C interface. - -A potentiometer has three wires. The two outside wires connect to GND and the 3.3 volt output. The center wire, called the "tap" wire will connect to the pin that converts an continuous analog voltage value into a digital number. - -[Wikipedia Page on Potentiometer](https://en.wikipedia.org/wiki/Potentiometer) - -## Circuit Diagram - -![](../../img/oled-i2c-clock-data.png) - -![](../../img/oled-pot-lab-pins.png) -## Sample Code - -## Testing the POT - -Our first task is to find what pin to use for our first Analog to Digital concerter. GP26 is the same as ADC0. This is pin number 31 on the Pico. - -```py -import machine -import utime -pot = machine.ADC(26) -while True: - print(pot.read_u16()) - utime.sleep(.2) -``` -### Sample 16 bit output -A 16-bit integer can store 216 (or 65,536) distinct values. In an unsigned representation, these values are the integers between 0 and 65,535. So we are expecting numbers from 0 to 65,535. - -Sample results as we move the potentiometer from the minimum to the maximum values. -```data -65535 -52844 -31047 -7745 -256 -352 -19140 -41114 -62239 -65535 -57277 -33384 -10114 -352 -288 -19940 -28086 -``` - -## Testing the OLED - -### Getting the defaults - -```py -from machine import Pin, I2C -# i2c=machine.I2C(0) -i2c=machine.I2C(0) -print("Device found at decimal", i2c.scan()) -print(i2c) -``` - -Results: -This tells you the default pins and frequency that the I2C bus is running at. - -```data -Device found at decimal [60] -I2C(0, freq=399361, scl=9, sda=8) -``` - -```data -Device found at decimal [60] -I2C(0, freq=399361, scl=1, sda=0) -``` - -This tells us that the default pins are GP9 (row 12) for clock and GP8 (row 11) for data. - -```py -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -WIDTH = 128 -HEIGHT = 64 -i2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) -oled.fill(0) -oled.text("CoderDojo Rocks",0,0) -oled.show() -``` - -## Continuous Text Display on OLED - -```py -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -WIDTH = 128 -HEIGHT = 32 -i2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) - -POT_PIN = machine.ADC(26) - -while True: - oled.fill(0) - oled.text(POT_PIN.read_u16()) - oled.show() - utime.sleep(.2) -``` - -## Bar Chart and Text Display of Pot Value - -```py -import machine -import utime -import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -pot_pin = machine.ADC(26) - -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -half_height = int(height / 2) -# oled = SSD1306_I2C(width, height, i2c) -oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 2, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, height, state): - oled.fill(0) # clear screen - border(width, height) # draw a border - oled.fill_rect(0, 1, inval, height, 1) # fill with 1 - utime.sleep(.1) # wait a bit - -# continuous update -while True: - pot_val = int(pot_pin.read_u16()) - # the max value of the input is a 2^16 or 65536 - pot_scaled = valmap(pot_val, 0, 65536, 0, 127) - print(pot_val, pot_scaled) - draw_hbar(pot_scaled, half_height, 1) - - oled.text('raw:', 0, half_height + 5, 1) - oled.text(str(pot_val), 30, half_height + 5, 1) - - oled.text('scaled:', 0, half_height + 15, 1) - oled.text(str(pot_scaled), 60, half_height + 15, 1) - oled.show() -``` -## Gif of OLED - -Gif of small .96" OLED -![OLED Pot Small](../../img/pot-oled.gif) - -Gif of larger 2.42" OLED -![OLED Pot Large Screen](../../img/oled-pot-i2c-large.gif) \ No newline at end of file diff --git a/docs/displays/graph/12-oled-ssd1306-spi-v1.md b/docs/displays/graph/12-oled-ssd1306-spi-v1.md deleted file mode 100644 index 270cf75c4..000000000 --- a/docs/displays/graph/12-oled-ssd1306-spi-v1.md +++ /dev/null @@ -1,27 +0,0 @@ -## OLED SPI Demo - -This code was provide by Jim Tannenbaum (aka Jet) - -## Image - -![](../../img/oled-spi-connections.png) - -![](../../img/oled-ssd1306-spi-connections.png) -## Code - -```python -import machine import ssd1306 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -# flash all pixels on oled.fill(0) -oled.show() -oled.text('Hello Jet', 0, 0, 1) -oled.show() -``` - - diff --git a/docs/displays/graph/13-pixel-draw.md b/docs/displays/graph/13-pixel-draw.md deleted file mode 100644 index 96d33a33f..000000000 --- a/docs/displays/graph/13-pixel-draw.md +++ /dev/null @@ -1,70 +0,0 @@ -# Sample Pixel-Based Drawing Program - -Code example provided by Jim Tannenbaum. - -This program will act like an Etch-A-Sketch(TM) program. It will use potentiometers with the center tap on GPIO pins GP26 and GP27 and draw as you move the potentiometers to control the X and Y dimensions. - -```py -from machine import Pin, SPI, ADC -import ssd1306 -import time - -# Takes an input number value and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def scaled(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((int(value) - istart) / (istop - istart))) - -# Define the pins for SPI Clock and Transmit -spi_sck = Pin(2) -spi_tx = Pin(3) -spi = SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx) - -# Define the pins for Chip Select, DC (Command), and Reset -CS = Pin(1) -DC = Pin(4) -RES = Pin(5) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# Turn all pixels off -oled.fill(0) -oled.show() - -# Provide info to user -oled.text('Etch-A-Sketch', 0, 0, 1) -oled.text('Hit the reset', 0, 20, 1) -oled.text('button to clear', 0, 30, 1) -oled.text('the screen', 0, 40, 1) -oled.show() - -# Define the pin for the reset button -resetButton = Pin(14, Pin.IN, Pin.PULL_DOWN) - -# Wait unti the user hits the button to clear the screen and start drawing -while resetButton.value() != 1: - time.sleep(.25) - -oled.fill(0) -oled.show() - -# Define the Horizontal and Vertical inputs from the Rheostats -vert = ADC(26) -horiz = ADC(27) - -# Calculate where to start the line -x = newX = scaled(vert.read_u16(), 0, 65536, 0, 128) -y = newY = scaled(horiz.read_u16(), 0, 65536, 0, 64) - -# Loop forever -# Draw the line, look for a reset to clear the screen, and get the new end points for the line -while True: - oled.line(x, y, newX, newY, 1) - x = newX - y = newY - if resetButton.value(): - oled.fill(0) - oled.show() - time.sleep(.2) - newX = scaled(vert.read_u16(), 0, 65536, 0, 128) - newY = scaled(horiz.read_u16(), 0, 65536, 0, 64) -``` \ No newline at end of file diff --git a/docs/displays/graph/14-lcd-st7789V.md b/docs/displays/graph/14-lcd-st7789V.md deleted file mode 100644 index 2954e6ee4..000000000 --- a/docs/displays/graph/14-lcd-st7789V.md +++ /dev/null @@ -1,149 +0,0 @@ -# MicroPython ST7789V LCD Display - -![](../../img/st7789-lcd.png) - -The Sitronix ST7789 is a driver chip for small color IPS LCD displays that supports SPI interfaces. This example uses a 2-inch color LDC display manufactured by [Waveshare](https://www.waveshare.com/2inch-lcd-module.htm) with a retail price of approximately $13 or $14.75 on [Amazon Prime](https://www.amazon.com/Waveshare-Resolution-Interface-Examples-Raspberry/dp/B081Q79X2F). - -## Specifications - -* Resolution: 240(V) x 320(H) RGB -* 18 bit color (6 bits for R, G and B) -* 1,382,400 bits of display memory -* Interface: 4-wire SPI (kind of) -* Operating voltage: 3.3V - -Note: The ST7789 uses a SPI interfaces but not a true standard SPI protocol. The device only uses MOSI (DIN) to send data from master to slave for LCD display. Only four wires are needed to connect from the Pico to the device. - -## Device Interface - -![](../../img/st7789-lcd-back.png) - -## Interface - -1. VCC Power (3.3V input) -1. GND Ground -1. DIN SPI data input -1. CLK SPI clock input -1. CS Chip selection, low active -1. DC Data/Command selection (high for data, low for command) -1. RST Reset, low active -1. BL Backlight - tie to GND to turn the backlight on - - -Although the device has eight wires, your Pico only needs a few of them to be controlled by the GPIO ports. - -## Uploading the ST7789V Python Firmware - -The firmware contains pre-compiled objects for various devices with the st7789 C driver and frozen python font files. - -The library for the driver is delivered as a single firmware.uf2 file available here: - -[https://github.com/russhughes/st7789_mpy/tree/master/firmware/RP2](https://github.com/russhughes/st7789_mpy/tree/master/firmware/RP2) - -To load this file you will need to hold down the BOTSEL button on the Pico and drag this file into the RP2 folder that is mounted. - -## MicroPython Initialization - -I used the following SPI Device ID 1 pinout on the lower left corner of the Pico: - -| Pin | GP Number | Label on LCD | -| --- | --------- | ------------ | -|14 |(GP10) | BL | -|15 |(GP11) | RST | -|16 |(GP12) | DC | -|17 |(GP13) | CS | -|18 |(GND) | GND | -|19 |(GP14) | CLK | -|20 |(GP15) | DIN | - -## Sample Device Initialize - -```py -from machine import Pin, SPI -import st7789 - -BACKLIGHT_PIN = 10 -RESET_PIN = 11 -DC_PIN = 12 -CS_PIN = 13 -CLK_PIN = 14 -DIN_PIN = 15 # lower left corner - -import vga1_bold_16x32 as font - -spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN)) -tft = st7789.ST7789(spi, 240, 320, - reset=Pin(RESET_PIN, Pin.OUT), - cs=Pin(CS_PIN, Pin.OUT), - dc=Pin(DC_PIN, Pin.OUT), - backlight=Pin(BACKLIGHT_PIN, Pin.OUT), - rotation=3) -tft.init() -# draw white letters on a back background at 10 over and 20 down -tft.text(font, "Hello World!", 10, 20, st7789.color565(255,255,255), st7789.color565(0,0,0)) -``` - -![](../../img/st7789-lcd-hello.jpeg) - -## Sample Hello World In Four Colors - -```py -from machine import Pin, SPI -import st7789 - -BACKLIGHT_PIN = 10 -RESET_PIN = 11 -DC_PIN = 12 -CS_PIN = 13 -CLK_PIN = 14 -DIN_PIN = 15 # lower left corner - -import vga1_bold_16x32 as font - -spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN)) -tft = st7789.ST7789(spi, 240, 320, - reset=Pin(RESET_PIN, Pin.OUT), - cs=Pin(CS_PIN, Pin.OUT), - dc=Pin(DC_PIN, Pin.OUT), - backlight=Pin(BACKLIGHT_PIN, Pin.OUT), - rotation=3) -tft.init() - -tft.text(font, "Hello World!",10, 0, st7789.color565(255,255,255), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 50, st7789.color565(255,0,0), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 100, st7789.color565(0,255,0), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 150, st7789.color565(0,0,255), st7789.color565(0,0,0)) - -``` - -## Driver Implementation Notes - -The ST7789V supports RGB444, RGB565 and RGB666 three formats. The Waveshare LCD uses RGB565. -For most LCD controllers, the communication method of the controller can be configured, they are usually using 8080 parallel interface, 3-line SPI, 4-line SPI, and other communication methods. This LCD uses a 4-line SPI interface for reducing GPIO and fast speed.LCD - - -1. RESX: Reset, should be pull-down when power on, set to 1 other time. -1. CSX: Slave chip select. The chip is enabled only CS is set Low -1. D/CX: Data/Command selection; DC=0, write command; DC=1, write data -1. SDA: Data transmitted. (RGB data) -1. SCL: SPI clock - -## Timing Diagram - -You can see what data needs to be changing from the timing diagram below: - -![](../../img/st7789-lcd-timing.png) - -2. The SPI communication protocol of the data transmission uses control bits: clock phase (CPHA) and clock polarity (CPOL) -3. CPOL defines the level while the synchronization clock is idle. If CPOL=0, then it is LOW. -4. CPHA defines at whish clock’s tick the data transmission starts. CPHL=0 – at the first one, otherwise at the second one - -This combination of two bits provides 4 modes of SPI data transmission. The commonly used is SPI0 mode, i.e. GPHL=0 and CPOL=0. - -According to the figure above, data transmitting begins at the first falling edge, 8bit data are transmitted at one clock cycle. It is SPI0. MSB. - -## References - -1. [ST7789C Datasheet (PDF)](https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf) -2. [Waveshare Wiki](https://www.waveshare.com/wiki/2inch_LCD_Module) -3. [Waveshare Pico Dispaly](https://www.waveshare.com/pico-lcd-2.htm) diff --git a/docs/displays/graph/14-random-hearts.md b/docs/displays/graph/14-random-hearts.md deleted file mode 100644 index a99e997fa..000000000 --- a/docs/displays/graph/14-random-hearts.md +++ /dev/null @@ -1,52 +0,0 @@ -# Draw Random Hearts - -This program uses the MicroPython ```urandom``` library to generate random X and Y positions on the display. It then uses an array of binary values to draw a heart icon at that location. - -```py -from machine import Pin, PWM, SPI -import urandom -import ssd1306 -from utime import sleep -import random # random direction for new ball - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -HEART = [ - [ 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 1, 1, 0, 0, 0, 1, 1, 0], - [ 1, 1, 1, 1, 0, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 1, 1, 1, 1, 1, 0, 0], - [ 0, 0, 0, 1, 1, 1, 0, 0, 0], - [ 0, 0, 0, 0, 1, 0, 0, 0, 0], -] - -def draw_heart(xofs, yofs): - for y, row in enumerate(HEART): - for x, c in enumerate(row): - oled.pixel(x + xofs, y + yofs, c) - -def random_heart(): - xofs = urandom.getrandbits(7) - yofs = urandom.getrandbits(6) - print(xofs, yofs) - draw_heart(xofs, yofs) - - -oled.fill(0) -for n in range(10): - random_heart() - -oled.show() -``` \ No newline at end of file diff --git a/docs/displays/graph/15-cu1609c-led.md b/docs/displays/graph/15-cu1609c-led.md deleted file mode 100644 index 88805255d..000000000 --- a/docs/displays/graph/15-cu1609c-led.md +++ /dev/null @@ -1,66 +0,0 @@ -# CU1609C LED Display - -Note: This is a work-in-progress. We have not found a MicroPython driver for this display. - -The UC1609 is a graphic LED driver chip with an SPI interface. Because it is low cost ($4) and 2 inches across it is ideal for low-cost robot displays. - -192X62 LCD display for $4 USB device -![LCD Blue UC1609 SPI](../../img/lcd-uc1609-spi.jpg) - -## Connections -| Pin Name | Description | -| -------- | ----------- | -|1 K Backlight Cathode|Connect to GND rail| -|2 A Backlight Anode| Connect via 200 ohm to 3.2v rail to limit backlight current to 3 milliamps. The current for backlight is limited to 20 milliamps.| -|3 GND Ground|Connect to GND rail| -|4 VDD Power Supply| connect to +3.3v rail | -|5 SCK Serial clock input.|Connect to SPI CLK| -|6 SDA Serial data input.|Connect to SPI Data SCL| -|7 RST | Connect to 3.3v rail. | -|8 CD | It determines whether the access is related to data or command. Connect to GPIO | -|9 CS | Chip select input. Connect to GND when LCD is use. | - -## Connection Notes -When RST=L, all control registers are re-initialized by their default sates. Since UC1609c has -built-in Power-on Reset, the RST pin is not required for proper chip operation. -An RC filter has been included on-chip. There is no need for external RC noise filter. When RST -is not used, connect the pin to High. - -CS determines whether the access is related to data or command. When CS=“H” : Display data. When CS=“L” : Command. - -## Hello World -```py -from machine import Pin, SPI - -SPI_CLK = 2 # SPI clock -SPI_SDA = 3 -CD = 5 # command or data -# RST is tied to 3.3v -# CS is tied to GND - -# SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=2, mosi=3, miso=4) -spi = SPI(0, baudrate=31250000, sck=Pin(SPI_CLK), mosi=Pin(SPI_SDA)) -print(spi) - -``` - -## Similar Drivers - -There are two similar drivers. One is for the LCD160CR - -[LCD160CR Display Driver](https://github.com/micropython/micropython/blob/master/drivers/display/lcd160cr.py) - -The other is the Arduino C version by Gavin Lyones that has been around for a long time. - -[Gavin Lyons GitHub Repo supporting the UC1609](https://github.com/gavinlyonsrepo/ERM19264_UC1609) - -Our goal is to port Gavin's C code to use the same function as the LCD160CR driver. - -## References - -1. [BuyDisplay Product 2 inch Blue 192x64 Graphic LCD Display Module,UC1609,SPI for $3.48](https://www.buydisplay.com/2-inch-blue-192x64-graphic-lcd-display-module-uc1609-spi-for-arduino) -2. [ERM19264-4 SeriesGraphic Display Module Datasheet](https://www.buydisplay.com/download/manual/ERM19264-4_Datasheet.pdf) -3. [Gavin Lyons GitHub Repo supporting the UC1609](https://github.com/gavinlyonsrepo/ERM19264_UC1609) -4. [EBay Product 2 inch White 192x64 Graphic LCD Display Module,UC1609,SPI](https://www.ebay.ie/itm/2-inch-White-192x64-Graphic-LCD-Display-Module-UC1609-SPI-for-Arduino/293617684779) -5. [MicroPython Pyboard LCD Class](https://docs.micropython.org/en/latest/library/pyb.LCD.html) -6. [List of LCD Graphic Displays](https://awesome-micropython.com/#lcd-graphic) \ No newline at end of file diff --git a/docs/displays/graph/15-oled-patterns.md b/docs/displays/graph/15-oled-patterns.md deleted file mode 100644 index c7bfab2bd..000000000 --- a/docs/displays/graph/15-oled-patterns.md +++ /dev/null @@ -1,190 +0,0 @@ -# OLED Patterns - -In this lesson, we will show how you can display interesting repeating patterns on your OLED screen. Our program will write a pattern into the framebuffer using a simple math equation. The oled.show() will then update the pattern on the display. - -This lesson was suggested by Parker Erickson. - -## Math Functions -We will use a few unusual functions to create repeating patterns: - -1. Modulo (%) -2. Bitwise AND (&) - -The modulo function is written ```%```. It returns the integer remainder after a division. So ```7 % 3``` is 1 and ```7 % 4``` is 3. -The Power function of X to the Y power is written in python as ```pow(x,y)```. For example pow(7, 2) is seven squared = 49. - -The bitwise and is written as ```x & y``` - -```py -for i in range(8): - 13 & i -``` - -|Function|Returns| -|---|---| -|13 & 0 | 0 | -|13 & 1 | 1 | -|13 & 2 | 0 | -|13 & 3 | 1 | -|13 & 4 | 4 | -|13 & 5 | 5 | -|13 & 6 | 4 | -|13 & 7 | 5 | -|13 & 8 | 8 | -|13 & 9 | 9 | -|13 & 10 | 8 | -|13 & 11 | 9 | -|13 & 12 | 12 | - - -## Some Sample Equations - -1. x & y -1. x % y -1. (x ^ y) % 9 -1. (x ^ y) % 5 -1. (x ^ y) % 17 -1. (x ^ y) % 33 -1. (x * y) & 64 -1. (x * y) & 24 -1. (x * y) & 47 -1. (x * 2) % y -1. (x * 64) % y -1. (x * 31) % y -1. ((x-128) * 64) % (y-128) -1. (x % y) % 4 -1. (y % x) % 20 -1. 40 % (x % y) - -Note there are other patterns that use the power ```pow(x,y)``` or Exponentiation ```**``` function but I can't get these to work with Micropython. - -## Sample Code -This program evaluates the function ```x % (y+1)``` for each of the pixels on the screen. If the function returns a non-zero the pixel will be off. If the pixel is zero, the pixel will be on. - -draw-patterns-ssd1306-spi.py -```py -import machine -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.fill(0) # clear display -for x in range(WIDTH): - for y in range(HEIGHT): - if x % (y+1): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) -oled.show() - -``` - -## Adding a List of Patterns - -### The Eval Function -The eval() function takes any string and passes it to the python interpreter for evaluation within the current context of variables that are in scope. We can use eval to pass an expression that should be evaluated to any function. - -```py -list = ["x+y", "x-y", "x*y", "x % (y+1)"] - -for i in range(0, 4): - print(list[i], ': ', sep='', end='') - for x in range(5): - for y in range(5): - print(eval(list[i]), '', end='') - print('') -``` - -Output: - -```data -x+y: 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 -x-y: 0 -1 -2 -3 -4 1 0 -1 -2 -3 2 1 0 -1 -2 3 2 1 0 -1 4 3 2 1 0 -x*y: 0 0 0 0 0 0 1 2 3 4 0 2 4 6 8 0 3 6 9 12 0 4 8 12 16 -x % (y+1): 0 0 0 0 0 0 1 1 1 1 0 0 2 2 2 0 1 0 3 3 0 0 1 0 4 -``` - -## The Command Design Pattern -The command pattern holds a list of commands in an array. Each command is executed in the sequence it appears in the list of commands. - -In the following program we have the equations in a list. The program steps through each item in the list and displays that equation on the OLED display. - -```py -import machine -import ssd1306 -from utime import sleep, time - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -equations = ['(x * y) & 24', '(x * y) & 47', '(x * y) & 64', 'x & y', 'x % y', '(x % y) % 4', '40 % (x % y+1)'] - -for eqn in range(0, len(equations)): - start = time() - - oled.fill(0) # clear display - oled.text('calculating', 0, 0, 1) - oled.text(equations[eqn], 0, 10, 1) - oled.show() - for x in range(WIDTH): - for y in range(1, HEIGHT): - if eval(equations[eqn]): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) - oled.show() - sleep(5) - - end = time() - duration = str(end - start) - print(equations[eqn]) - print(duration, ' seconds') - -oled.text('done', 0, 0, 1) -oled.show() -print('done') -``` - -## Sample Screen Images - -### X Modulo Y -```x % y``` -![](../../img/pattern6.jpg) - - -### (x % y) % 4 -![](../../img/pattern5.jpg) - -## Sierpinsky Triangles (x & y) -[Sierpinsky Triangles](https://en.wikipedia.org/wiki/Sierpi%C5%84ski_triangle) -Bitwise and of x and y -![](../../img/pattern1.jpg) - -## (x * y) & 24 -![](../../img/pattern2.jpg) - -## (x * y) & 64 -![](../../img/pattern3.jpg) - -## 40 % x % (y+1) -![](../../img/pattern4.jpg) - - -## Reference - -[Martin Kleppe Post on Twitter](https://twitter.com/aemkei/status/1378106731386040322) diff --git a/docs/displays/graph/16-tft-ili9341.md b/docs/displays/graph/16-tft-ili9341.md deleted file mode 100644 index 8cb3c751e..000000000 --- a/docs/displays/graph/16-tft-ili9341.md +++ /dev/null @@ -1,281 +0,0 @@ -# LI9341 TDF Display - -![ILI 9341 Display Demo](../../img/ili9341-demo.png) - -This is a 3.2" $10 240X320 color display that is easy to set up on the Raspberry Pi Pico using the SPI interface. The hardware supports a touch screen and an SD card, but we could not locate drivers for these components. - -Sample $10 part on [Amazon](https://www.amazon.com/dp/B0BMVXNQ22?psc=1&ref=ppx_yo2ov_dt_b_product_details) or [ebay](https://www.ebay.com/itm/385436352305?hash=item59bdcbff31:g:QjwAAOSwoy1j9vw7) - -![ILI 9341 Display Demo](../../img/ili9341-listing.png) - -The TFT uses a 16-bit representation of the color of each pixel: - -1. 5-bits for red -2. 6-bits for green -3. 5-bits for blue - -This requires us to include the ```color565``` library for doing color operations. So for example, to get the color yellow, you would need to do the following: - -```py -yellow = color565(255, 255, 0) -``` - -## Sample SPI Hello World Example - - - -```py -# print out "Hello World!" using the rotation=3 using 32-bit high font -# the default is white text on a black background -from ili934x import ILI9341 -from machine import Pin, SPI -import tt32 - -# Use these PIN definitions. SCK must be on 2 and data (SDL) on 3 -SCK_PIN = 2 -MISO_PIN = 3 # labeled SDI(MOSI) on the back of the display -DC_PIN = 4 -RESET_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RESET_PIN), w=320, h=240, r=3) -display.erase() -display.set_font(tt32) -display.set_pos(0,0) -display.print('Hello World!') -``` - -## Draw Random Rectangles - -```py -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -from random import randint - -WIDTH = 320 -HALF_WIDTH = int(WIDTH/2) -HEIGHT = 240 -HALF_HEIGHT = int(HEIGHT/2) -ROTATION = 3 # landscape with 0,0 in upper left and pins on left - -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN), sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.erase() - -# color defintions converted to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) -yellow = color565(255, 255, 0) -cyan = color565(0, 255, 255) -magenta = color565(255, 0, 255) -gray = color565(128, 128, 128) -light_gray = color565(192, 192, 192) -dark_gray = color565(64, 64, 64) -brown = color565(165, 42, 42) -orange = color565(255, 60, 0) -# 150 for the green and blue wash out the colors -pink = color565(255, 130, 130) -purple = color565(128, 0, 128) -lavender = color565(150, 150, 200) -beige = color565(200, 200, 150) -# by definition, maroon is 50% of the red on, but 128 is way too bright -maroon = color565(105, 0, 0) -olive = color565(128, 128, 0) -turquoise = color565(64, 224, 208) -dark_green = color565(0,100,0) -color_list = [white, red, green, blue, yellow, cyan, magenta, - gray, light_gray, dark_gray, brown, orange, pink, purple, lavender, - beige, maroon, olive, turquoise, dark_green, black] -color_num = len(color_list) - -# Draw forever -while True: - # rect_fill(x, y, width, height, color) - x = randint(0, HALF_WIDTH) - y = randint(0, HALF_HEIGHT) - width = randint(0, HALF_WIDTH) - height = randint(0, HALF_HEIGHT) - color = color_list[randint(0, color_num-1)] - print('fill_rectangle(', x, y, width, height, color) - display.fill_rectangle(x, y, width, height, color) -``` - -## Draw Color Lists - -One of the best ways to study the color values is to display a rectangle -and list the color name and values under the rectangle. - -Here is a sample program that will do this. - -```py -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -from random import randint -import tt32 - -WIDTH = 320 -HALF_WIDTH = int(WIDTH/2) -HEIGHT = 240 -HALF_HEIGHT = int(HEIGHT/2) -ROTATION = 3 # landscape with 0,0 in upper left and pins on left -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.set_font(tt32) -display.erase() - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) -yellow = color565(255, 255, 0) -cyan = color565(0, 255, 255) -magenta = color565(255, 0, 255) -gray = color565(128, 128, 128) -light_gray = color565(192, 192, 192) -dark_gray = color565(64, 64, 64) -brown = color565(165, 42, 42) -orange = color565(255, 60, 0) -# 150 for the green and blue wash out the colors -pink = color565(255, 130, 130) -purple = color565(128, 0, 128) -lavender = color565(150, 150, 200) -beige = color565(200, 200, 150) -# by definition, maroon is 50% of the red on, but 128 is way too bright -maroon = color565(105, 0, 0) -olive = color565(128, 128, 0) -turquoise = color565(64, 224, 208) -dark_green = color565(0,100,0) -color_list = [white, red, green, blue, yellow, cyan, magenta, - gray, light_gray, dark_gray, brown, orange, pink, purple, lavender, - beige, maroon, olive, turquoise, dark_green, black] -color_names = ['white (255,255,255)', 'red (255,0,0)', 'green (0,255,0)', 'blue (0,0,255)', 'yellow (255,255,0)', - 'cyan (0,255,255)', 'magenta (255,0,255)', - 'gray (128,128,128)', 'light gray (192,192,192)', 'dark gray (64,64,64)', - 'brown (165,42,42)', 'orange (255,60,0)', 'pink (255,130,130)', 'purple (128,0,128)', - 'lavender (150,150,200)', - 'beige (200,200,150)', 'maroon (105,0,0)', 'olive (128,128,0)', 'turquoise (64,224,208)', - 'dark green (0,100,0)', 'black (0,0,0)'] -color_num = len(color_list) - -display.fill_rectangle(0, 0, WIDTH, HEIGHT, black) -while True: - for i in range(0, color_num): - display.fill_rectangle(0, 0, WIDTH, HEIGHT-33, color_list[i]) - # black behind the white text - display.fill_rectangle(0, HEIGHT-32, WIDTH, 32, black) - - display.set_pos(0,HEIGHT-32) - display.print(color_names[i]) - print(color_names[i]) - sleep(1) -``` - -## Screen Update Speed - -One large disadvantage of this display is the very slow refresh rate. Transmitting the entire screen of 240X320 with two bytes per pixel takes -a long time over SPI. This makes this setup difficult to use for animation. - -## Ball Bounce Animation - -Here is a very slow "ball bounce" animation that is slow and has a lot of flicker. - -```py -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep - -WIDTH = 320 -HEIGHT = 240 -ROTATION = 3 # landscape with 0,0 in upper left and pins on left -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.erase() - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, color): - if size == 1: - display.pixel(x, y, color) # draw a single pixel - else: - display.fill_rectangle(x, y, size, size, color) - -ball_size = 20 -# start in the middle of the screen -current_x = int(WIDTH / 2) -current_y = int(HEIGHT / 2) -# start going down to the right -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - # draw the square ball in white - draw_ball(current_x,current_y, ball_size, white) - sleep(.1) - # the erase the old ball takes too long and causes a flicker - draw_ball(current_x,current_y,ball_size, black) - if current_x < 0: - direction_x = 1 - # right edge test - if current_x > WIDTH - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 0: - direction_y = 1 - # bottom edge test - if current_y > HEIGHT - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y -``` - - -## References - -1. [Jeffmer's GitHub library which includes four fonts](https://github.com/jeffmer/micropython-ili9341) - the sizes are 8, 14, 24 and 32 pixels. - -2. [Amazon HiLetgo ILI9341 2.8" SPI TFT LCD Display Touch Panel 240X320 with PCB 5V/3.3V STM32](https://www.amazon.com/s?k=TFT+display&tag=all3dp0c-20) - -3. [ebay Listing](https://www.ebay.com/itm/304736177265) diff --git a/docs/displays/graph/17-ssd1352.md b/docs/displays/graph/17-ssd1352.md deleted file mode 100644 index 490c6b797..000000000 --- a/docs/displays/graph/17-ssd1352.md +++ /dev/null @@ -1,101 +0,0 @@ -# OLED SSD1351 MicroPython Driver - -The SSD1351 is a $40 color OLED measures 1.5" diagonal and contains 128x128 RGB pixels. It supports a SPI interface. - -## Drawing Shapes - -This demo shows how to draw shapes on the display. It starts out with simple lines and rectangles then progresses to more complex shapes such as circles and ellipses. - -```python -"""SSD1351 demo (shapes).""" -from time import sleep -from ssd1351 import Display, color565 -from machine import Pin, SPI - - -def test(): - """Test code.""" - # Baud rate of 14500000 seems about the max - spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) - print('spi started') - display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) - print('display started') - - display.clear(color565(64, 0, 255)) - sleep(1) - - display.clear() - - display.draw_hline(10, 127, 63, color565(255, 0, 255)) - sleep(1) - - display.draw_vline(10, 0, 127, color565(0, 255, 255)) - sleep(1) - - display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255)) - sleep(1) - - display.draw_hline(0, 0, 127, color565(255, 0, 0)) - sleep(1) - - display.draw_line(127, 0, 64, 127, color565(255, 255, 0)) - sleep(2) - - display.clear() - - coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]] - display.draw_lines(coords, color565(0, 255, 255)) - sleep(1) - - display.clear() - display.fill_polygon(7, 63, 63, 50, color565(0, 255, 0)) - sleep(1) - - display.fill_rectangle(0, 0, 15, 127, color565(255, 0, 0)) - sleep(1) - - display.clear() - - display.fill_rectangle(0, 0, 63, 63, color565(128, 128, 255)) - sleep(1) - - display.draw_rectangle(0, 64, 63, 63, color565(255, 0, 255)) - sleep(1) - - display.fill_rectangle(64, 0, 63, 63, color565(128, 0, 255)) - sleep(1) - - display.draw_polygon(3, 96, 96, 30, color565(0, 64, 255), - rotate=15) - sleep(3) - - display.clear() - - display.fill_circle(32, 32, 30, color565(0, 255, 0)) - sleep(1) - - display.draw_circle(32, 96, 30, color565(0, 0, 255)) - sleep(1) - - display.fill_ellipse(96, 32, 30, 16, color565(255, 0, 0)) - sleep(1) - - display.draw_ellipse(96, 96, 16, 30, color565(255, 255, 0)) - - sleep(5) - display.cleanup() - - -test() -``` - - -## SSD1351 MicroPython Driver -The driver is here -[RDagger GitHub](https://github.com/rdagger/micropython-ssd1351) - -[SSD1351 MicroPython Driver on RDagger GitHub](https://github.com/rdagger/micropython-ssd1351/blob/master/ssd1351.py) - -## SSD1351 Datasheet - -[Datasheet on NewHaven Displays](https://newhavendisplay.com/content/app_notes/SSD1351.pdf) \ No newline at end of file diff --git a/docs/displays/graph/18-neopixel-matrix.md b/docs/displays/graph/18-neopixel-matrix.md deleted file mode 100644 index 11cc57e6d..000000000 --- a/docs/displays/graph/18-neopixel-matrix.md +++ /dev/null @@ -1,274 +0,0 @@ -# NeoPixel Matrix Display - -![](../../img/neopixel-matrix.gif) - -## Introduction - -This lesson uses MicroPython to control display that uses a 8X32 matrix of WS2812 RGB LEDs to display information. The entire display is controlled by three wires, a ground, +5V, and a serial data signal. We will use the MicroPython builtin NeoPixel library to control the display. You can use many of the programs in the [NeoPixel Basics](../basics/../../basics/05-neopixel.md) lesson to control the display. The key difference is that we will need to convert matrix coordinates to NeoPixel index numbers. - -## Purchasing Hardware - -You can purchase a matrix of 8X32 WS2812 RGB LED on eBay for about $12 on [eBay](https://www.ebay.com/itm/255390906966) or about [$100](https://www.adafruit.com/product/2294) on Adafruit. They are also available in 16X16 versions and the devices can be chained together to make larger displays. On our version tested here, we have a total of 8*32 = 256 pixels. - -![WS2811B 8X32 Matrix](../../img/ws2811B-8x32-matrix.png) - -## Basic Software Setup - -We must first create a function that will draw a pixel at a given x and y position. This is -complicated by the fact that the matrix is not a regular grid, but rather a grid that is connected -in a zig-zag serpentine pattern illustrated below. - -![Matrix Mapping Function](../../img/matrix-mapping-function.png) - -Note that the math for doing even and odd columns is different. The even columns are drawn from the top down and the odd columns are drawn from the bottom to the top which is the order the pixels are wired together in the matrix. - -To use the functions that draw pixels, we must first create a function that will convert the x and y coordinates to a NeoPixel index. This is done by the following function. We will then pass this function into the library that will draw characters on the screen. - -```python -from machine import Pin -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -# Allocate memory for the NeoPixel matrix -matrix = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def write_pixel(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - strip[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - strip[x*ROWS + y] = value -``` - -## Testing Your Write Pixel Function - -We can then test the function by calling it at four corners with different colors. - -```python -# draw four colors at each corner of the matrix -write_pixel(0, 0, (255, 0, 0)) # draw a red pixel at the top left corner -write_pixel(7, 0, (0, 255, 0)) # draw a green pixel at the lower left corner -write_pixel(0, 7, (0, 0, 255)) # draw a blue pixel at the top right corner -write_pixel(7, 7, (255, 255, 255)) # draw a white pixel at the lower right corner -``` - -## Bounce a Ball - -To test the write_pixel() function, lets write a function that will draw a ball at a given x and y position. We will move the ball around the screen and reverse the direction when the ball hits the edge of the screen. - -```python -# Bounce a ball around a NeoPixel Matrix -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# matrix = [[0 for _ in range(cols)] for _ in range(rows)] -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def write_pixel(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - strip[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - strip[x*ROWS + y] = value - -def show(): - strip.write() - -brightness=1 -x=0 -y=0 -dx = 1 -dy = 1 -counter = 0 -while True: - if x <= 0: - dx = 1 - if y <= 0: - dy = 1 - if x >= COLS-1: - dx = -1 - if y >= ROWS-1: - dy = -1 - print(x,y) - if counter < 100: - write_pixel(x, y, (brightness,0,0)) # blue - elif counter < 200: - write_pixel(x, y, (0,brightness,0)) # blue - elif counter < 300: - write_pixel(x, y, (0,0,brightness)) # blue - show() - x += dx - y += dy - counter += 1 - if counter > 300: - counter = 0 - if not counter % 150: - x += 1 - sleep(.1) -``` - - -## Bitmap LIbrary - - -```python -# MicroPython basic bitmap font renderer. -# Author: Tony DiCola -# License: MIT License (https://opensource.org/licenses/MIT) -try: - import ustruct -except ImportError: - import struct as ustruct - - -class BitmapFont: - - def __init__(self, width, height, pixel, font_name='font5x8.bin'): - # Specify the drawing area width and height, and the pixel function to - # call when drawing pixels (should take an x and y param at least). - # Optionally specify font_name to override the font file to use (default - # is font5x8.bin). The font format is a binary file with the following - # format: - # - 1 unsigned byte: font character width in pixels - # - 1 unsigned byte: font character height in pixels - # - x bytes: font data, in ASCII order covering all 255 characters. - # Each character should have a byte for each pixel column of - # data (i.e. a 5x8 font has 5 bytes per character). - self._width = width - self._height = height - self._pixel = pixel - self._font_name = font_name - - def init(self): - # Open the font file and grab the character width and height values. - # Note that only fonts up to 8 pixels tall are currently supported. - self._font = open(self._font_name, 'rb') - self._font_width, self._font_height = ustruct.unpack('BB', self._font.read(2)) - - def deinit(self): - # Close the font file as cleanup. - self._font.close() - - def __enter__(self): - self.init() - return self - - def __exit__(self, exception_type, exception_value, traceback): - self.deinit() - - def draw_char(self, ch, x, y, *args, **kwargs): - # Don't draw the character if it will be clipped off the visible area. - if x < -self._font_width or x >= self._width or \ - y < -self._font_height or y >= self._height: - return - # Go through each column of the character. - for char_x in range(self._font_width): - # Grab the byte for the current column of font data. - self._font.seek(2 + (ord(ch) * self._font_width) + char_x) - line = ustruct.unpack('B', self._font.read(1))[0] - # Go through each row in the column byte. - for char_y in range(self._font_height): - # Draw a pixel for each bit that's flipped on. - if (line >> char_y) & 0x1: - self._pixel(x + char_x, y + char_y, *args, **kwargs) - - def text(self, text, x, y, *args, **kwargs): - # Draw the specified text at the specified location. - for i in range(len(text)): - self.draw_char(text[i], x + (i * (self._font_width + 1)), y, - *args, **kwargs) - - def width(self, text): - # Return the pixel width of the specified text message. - return len(text) * (self._font_width + 1) - -``` - -## Full Code - -```python -# LED Matrix message scroller demo. - -import bitmapfont -import machine -import utime -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -matrix = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def fill(val): - for i in range(0, NUMBER_PIXELS): - matrix[i] = val - -# Configuration: -DISPLAY_WIDTH = 32 # Display width in pixels. -DISPLAY_HEIGHT = 8 # Display height in pixels. -SPEED = 20.0 # Scroll speed in pixels per second. - -def show(): - matrix.write() - -def write_pixel_value(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - matrix[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - matrix[x*ROWS + y] = value - -def write_pixel(x, y): - write_pixel_value(x, y, (1,1,2)) - -def scroll_text(message): - - with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, write_pixel) as bf: - # Global state: - pos = DISPLAY_WIDTH # X position of the message start. - message_width = bf.width(message) # Message width in pixels. - last = utime.ticks_ms() # Last frame millisecond tick time. - speed_ms = SPEED / 1000.0 # Scroll speed in pixels/ms. - # Main loop: - while True: - # Compute the time delta in milliseconds since the last frame. - current = utime.ticks_ms() - delta_ms = utime.ticks_diff(current, last) - last = current - # Compute position using speed and time delta. - pos -= speed_ms*delta_ms - if pos < -message_width: - pos = DISPLAY_WIDTH - # Clear the matrix and draw the text at the current position. - fill((0,0,0)) - bf.text(message, int(pos), 0) - # Update the matrix LEDs. - show() - # Sleep a bit to give USB mass storage some processing time (quirk - # of SAMD21 firmware right now). - utime.sleep_ms(20) - -write_pixel(0,0) -show() -#scroll_text('Dan Loves Ann!') -scroll_text('MicroPython Rocks') -``` - -## References - diff --git a/docs/displays/graph/19-wiring-harness.md b/docs/displays/graph/19-wiring-harness.md deleted file mode 100644 index 51594cd31..000000000 --- a/docs/displays/graph/19-wiring-harness.md +++ /dev/null @@ -1,108 +0,0 @@ -# Display Wiring Harness - -Unlike simple sensors that only have a few wires, displays have up to seven wires that need to be connected. This can be tricky when -we use breadboards where we can accidentally pull one wire out. - -To keep our displays running reliably, we can use a 20 cm ribbon cable and some hot glue to make a connector that is easy to hook up. It will be very reliable. - -We start by purchasing some 20 cm long Male-Female Dupont ribbon connectors from [eBay](https://www.ebay.com/itm/294317793020?hash=item4486b51efc:g:i0UAAOSwPFhhDPYR). The price should be about $8 -for 120 connectors. Make sure to get the Male-Female version. - -![Dupont Ribbon Cable](../../img/dupont-ribbon-cable.png) - -We then will separate 7 of these wires making sure to put the black and red colors in the GND and VCC edge of the group of wires. - -![Harness 1](../../img/harness-1.jpg) - -You can see a close-up of each of the colors and their connections in the picture below. - -![Harness 2](../../img/harness-2.jpg) - -At the other end of the cable, we need to make a small change in the order of the cable. Here are the changes: - -1. We separate the red wire from the rest of the group and connect the red to the 3.3V regulated output of the Raspberry Pi Pico. -2. We move the back GND wire two be in between the blue and purple CS and DC wires. This allows the row of all the wires to be connected in a single block of wires. - -![Harness 3](../../img/harness-3.jpg) - -We can then plug this group of wires directly into the breadboard from breadboard rows 3 to 9. This is shown below. - -![Harness 4](../../img/harness-4.jpg) - -We designed these connections with the following rules: - -1. The Clock (SCL) and Data (SDA) MUST be connected to rows 4 and 5 respectively because this is where SPI0 CLK and SPI0 TX are located. -2. The other three signals RES, DC and CS can be on pin so we will use the rows that make the cable connectors direct to rows 6, 7 and 9. Note that GND is on breadboard row 8. - -We have found that once we create these cable assemblies with hot glue to keep the pins in the right order it makes it much easier to connect the displays. - -!!! Warning - Note that we still MUST make sure that the black wire in the wiring harness is connected to the GND. It is easy to get the cable reversed so make sure to double-check the cable orientation before you use it. - -## Cable Wiring Diagram - -Here is the detailed wiring diagram showing the -wires as they route from the back of the OLED display -to the pins on the breadboard: - -![Wiring Diagram Circuit](../../img/harness-5.png) - -## Sample Python Code - -```py -from machine import Pin - -# Customize these GPIO numbers for your layout -# Note these are not breadboard row numbers -# The breadboard row numbers are 4,5,6,7 and 9 with GND on row 8 -SCL_PIN = 2 -SDA_PIN = 3 -RES_PIN = 4 -DC_PIN = 5 -CS_PIN = 6 - -# create the Pin objects -scl=Pin(SCL_PIN) -sda=Pin(SDA_PIN) -res=Pin(RES_PIN) -dc=Pin(DC_PIN) -cs = Pin(CS_PIN) - -spi=machine.SPI(0, sck=scl, mosi=sda) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs) -``` - -## Building A Harness for the Cytron Maker Pi RP2040 Board - -We can also make a display harness for the [Cytron Maker Pi RP2040 Board](../../kits/maker-pi-rp2040/). To do this we will need -to use three grove connectors. We use all four wires of the first Grove connector, two of the data signals on the second and just a single wire on the third Grove connector. This connector is shown below. - -![Cytron Make Pi RP2040](../../img/cytron-display-harness.jpg) - -The MicroPython code for this harness is the following: - -```py -from machine import Pin - -# Customize these GPIO pin numbers for your layout -SCL_PIN = 2 -SDA_PIN = 3 -RES_PIN = 4 -DC_PIN = 5 -CS_PIN = 16 - -# create the Pin objects -scl=Pin(SCL_PIN) -sda=Pin(SDA_PIN) -res=Pin(RES_PIN) -dc=Pin(DC_PIN) -cs = Pin(CS_PIN) - -spi=machine.SPI(0, sck=scl, mosi=sda) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs) -``` - -!!! Note - This code is exactly the same as the Pico version above - with the exception of the CS_PIN which was on GPIO 6 - but we now moved it to GPIO 16. \ No newline at end of file diff --git a/docs/displays/graph/20-seven-segments.md b/docs/displays/graph/20-seven-segments.md deleted file mode 100644 index dff3df41d..000000000 --- a/docs/displays/graph/20-seven-segments.md +++ /dev/null @@ -1,5 +0,0 @@ -# Drawing a Seven Segment Display - -https://en.wikipedia.org/wiki/Seven-segment_display - -[Wikipedia Seven Segment Display](https://en.wikipedia.org/wiki/Seven-segment_display_character_representations) \ No newline at end of file diff --git a/docs/displays/graph/40-oled-references.md b/docs/displays/graph/40-oled-references.md deleted file mode 100644 index 1c9a16f7e..000000000 --- a/docs/displays/graph/40-oled-references.md +++ /dev/null @@ -1,7 +0,0 @@ -# OLED References - -1. [Analysis of OLED drawing performance using SPI interface](http://merkles.com/MediaWiki/index.php?title=SSD1306_128x64_I2C_OLED_Display) -2. [Analysis of OLED drawing performance using SPI interface](http://merkles.com/MediaWiki/index.php?title=SSD1306_128x64_SPI_OLED_Display) -3. [Example of displaying a complex animation on an OLED with SPI](https://github.com/KonradStuewe/BadApple-ESP8266) -4. [Video of the Above on YouTube](https://www.youtube.com/watch?v=7ZWeEIJo95U) -5. [Peter Hinch's MicroPython Nano GUI](https://github.com/peterhinch/micropython-nano-gui) \ No newline at end of file diff --git a/docs/displays/non-graph/01-intro.md b/docs/displays/non-graph/01-intro.md deleted file mode 100644 index 8f4bbd8ca..000000000 --- a/docs/displays/non-graph/01-intro.md +++ /dev/null @@ -1,3 +0,0 @@ -# Using Non-Graphic Displays with MicroPython - -In this section cover small non-graphical displays such as LED bar displays, LCD character displays and other displays that don't require a drawing library and support for framebuffers. There is a separate section for graphical displays. \ No newline at end of file diff --git a/docs/displays/non-graph/02-led-button.md b/docs/displays/non-graph/02-led-button.md deleted file mode 100644 index cb6096397..000000000 --- a/docs/displays/non-graph/02-led-button.md +++ /dev/null @@ -1,5 +0,0 @@ -# LED Buttons Lab - - - -[LED Button](https://wiki.seeedstudio.com/Grove-LED_Button/) \ No newline at end of file diff --git a/docs/displays/non-graph/03-10-bar-leds.md b/docs/displays/non-graph/03-10-bar-leds.md deleted file mode 100644 index 079e9a5b0..000000000 --- a/docs/displays/non-graph/03-10-bar-leds.md +++ /dev/null @@ -1,107 +0,0 @@ -# Ten Bar LED Display - - - - -![](../img/led-bar-graph-10-segments.png) - -## Goals for the Lesson - - These LED displays can be purchased on eBay for around 40 cents each in quantity 10. These displays are ideal for showing a reading such as a battery charge or a signal strength. - - Our goal is to learn how to use python lists to turn on and off a row of 10 LEDs. - -## Circuit - -![](../img/led-10-segment-package-circuit.png) - -The LEDs come in a dual-in-line package with each of the LEDs connected by the pins aligned across the package. - -In the circuit below, I connected the positive (anode) of each LED to a GPIO pin and the negative (cathode) through a 330-ohm resistor to the GND rail of the solderless breadboard. - -![](../img/led-10-segment-circuit.png) - -Note! You **MUST** use a current limiting resistor or you will burn out the LED. - -One end of each of the bars will go to one of the power rails and the other to a GIPO pin. I used the pis on the lower part of the Raspberry Pi Pico for this demo. - -## Programming - -We will create a list that has each of the GPIO pins for output. - -```py -pin_ids = [12,13,14,15,20,19,18,17,16] -``` - -For each pin on this list, we will create a new list that contains the pin object that we can turn on or off. - -```py -from machine import Pin -from utime import sleep - -pin_ids = [12,13,14,15,20,19,18,17,16] -pins = [] -pin_ids -for i in pin_ids: - pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT)) -``` - -We will use this same preamble code in all our examples. - -# Code to Blink all 10 LEDs - -```py -from machine import Pin -from utime import sleep - -pin_ids = [12,13,14,15,20,19,18,17,16] -pins = [] -pin_ids -for i in pin_ids: - pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT)) - -delay = .5 -while True: - # turn all the pins on - for pin in pins: - pins.on() - sleep(delay) # wait - # turn all the pins off - for pin in pins: - pins[i].off() - sleep(delay) -``` - -## Sample Running Lights Example - -The "running lights" pattern gives the impression that there is a red object that is moving up and down a row. We do this by successively turning on adjacently LEDs and then turning them off. This give the illusion of motion. - -```python -from machine import Pin -from utime import sleep - -pin_ids = [12,13,14,15,20,19,18,17,16] -pins = [] - -for i in range(0, 9): - pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT)) - -delay = .1 -while True: - for i in range(0, 9): - pins[i].on() - sleep(delay) - pins[i].off() - for i in range(8, 1, -1): - pins[i].on() - sleep(delay) - pins[i].off() -``` - -## swipe - -The swipe pattern turns each LED on but keeps it on until the direction is reversed. - -## Adding a Binary Counter Patterns - -We can also create another patten that will demonstrate binary counting. In this pattern, the least significant bit flickers on and off. For each cycle the adjacent pixel toggles once. The happens for each adjacent pixel. The most significant bit will only change every 1024 cycles of the least significant bit. \ No newline at end of file diff --git a/docs/displays/non-graph/04-8x8-led-matrix.md b/docs/displays/non-graph/04-8x8-led-matrix.md deleted file mode 100644 index b22d4fa04..000000000 --- a/docs/displays/non-graph/04-8x8-led-matrix.md +++ /dev/null @@ -1,122 +0,0 @@ -# MAX7219 8x8 LED Matrix - -![MAX7219 ](../../img/max7219-8x8-led.png) -![MAX7219 ](../../img/led-matrix-display-back.png) - -This is a low-cost ($3) and easy-to-program device that is perfect for small projects that don't -need a full graphical display. You will be surprised at how creative our students are with -just an 8x8 display! - -[eBay Search for "MAX7219 8x8 matrix"](https://www.ebay.com/sch/i.html?_nkw=MAX7219+8x8+matrix) - -The device comes with five connectors: - -1. Power (VCC) -2. Ground (GND) -3. Clock (SCK) -4. Data (MOSI) -5. Chip Select (CS) - -We can communicate with the device using the standard SPI interface. There is also -an 8x8 driver supplied by [Mike Causer](https://github.com/mcauser/micropython-max7219) Here is an excerpt of how we -configured the driver to use a single display: - -```py -from machine import SPI, Pin -import max7219 -from utime import sleep -CLOCK_PIN = 2 -DATA_PIN = 3 -CS_PIN = 4 -spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN)) -cs = Pin(CS_PIN, Pin.OUT) -matrix = max7219.Matrix8x8(spi0, cs , 1) -# display text a x=0, y=0 and state = 1 (on) -matrix.text('1234', 0, 0, 1) -matrix.show() -``` - -You can change the last parameter from "1" to "4" if you have 4 displays wired together: - -```py -import max7219 -from machine import Pin, SPI -spi = SPI(1) -matrix = max7219.Matrix8x8(spi0, cs , 4) -display.text('1234',0,0,1) -display.show() -``` - -The displays can also be "cascaded" - -## Basic Program - -```py -from machine import SPI, Pin -import max7219 -from utime import sleep -CLOCK_PIN = 2 -DATA_PIN = 3 -CS_PIN = 4 -spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN)) - -cs = Pin(CS_PIN, Pin.OUT) - -matrix = max7219.Matrix8x8(spi0, cs , 1) - -matrix.text('A', 0, 0, 1) -matrix.show() -sleep(delay_time) -``` - -## Full Demo -```py -from machine import SPI, Pin -import max7219 -from utime import sleep -spi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3)) - -cs = Pin(4, Pin.OUT) - -matrix = max7219.Matrix8x8(spi0, cs , 1) - -delay_time = 1 -while True: - # Draw a single character - - matrix.text('A', 0, 0, 1) - matrix.show() - sleep(delay_time) - - # Draw an X in a box - matrix.fill(0) - matrix.line(0, 0, 7, 7, 1) - matrix.show() - sleep(delay_time) - - matrix.line(7, 0, 0, 7, 1) - matrix.show() - sleep(delay_time) - - matrix.rect(0, 0, 8, 8, 1) - matrix.show() - sleep(delay_time) - matrix.fill(0) - - # Smile Face - matrix.pixel(1, 1, 1) - matrix.pixel(6, 1, 1) - matrix.pixel(0, 4, 1) - matrix.pixel(7, 4, 1) - matrix.pixel(1, 5, 1) - matrix.pixel(6, 5, 1) - matrix.pixel(2, 6, 1) - matrix.pixel(5, 6, 1) - matrix.pixel(3, 7, 1) - matrix.pixel(4, 7, 1) - matrix.show() - sleep(delay_time) - matrix.fill(0) - matrix.show() - sleep(delay_time) -``` \ No newline at end of file diff --git a/docs/displays/non-graph/05-4-digit.md b/docs/displays/non-graph/05-4-digit.md deleted file mode 100644 index d8ffbab6e..000000000 --- a/docs/displays/non-graph/05-4-digit.md +++ /dev/null @@ -1,142 +0,0 @@ -# Four Digit LED Display - -In this lesson, we will use a 4-digit LED display to create a clock that displays the time of day. -These clocks will use [Mike Causer's **tm1637**](https://github.com/mcauser/micropython-tm1637) library to communicate -with the four-digit display. Some of these displays also have a "colon" -between the hour and minute digits that flashes every second. - -You can purchase 4-digit LED displays on eBay for about $2 each. - -![](../../img/4-digit-led-display.png) - -![](../../img/4-digit-led-display-clock.png) - -![](../../img/4-digit-7-segment-colon.png) - -## Connections - -These displays have four pins: - -1. Ground (GND) -2. Power (3.2 v or 5 v) -3. Data (DIO) -4. Clock (CLK) - -In our examples, we will connect the power to our 3.3 regulated output -of the Pico. We will connect Data to GP0 and Clock to GP1. - -The following example -```py -from machine import Pin -from time import sleep -import tm1637 - -# data and clock pins -DIO_PIN = 0 -CLK_PIN = 1 - -tm = tm1637.TM1637(clk=Pin(CLK_PIN), dio=Pin(DIO_PIN)) - -# display "1234" -tm.write([1, 2, 3, 4]) -``` - -The ```tm.write()``` function takes a sequence of numbers and will shifts them in from right to left. - -## Clock - -We can create a simple clock by using the ```localtime()``` function when the -programs first starts up and then we just update the time after the sleep() functions run for a second. -This also can updates the colon between the hours -and minutes. - -```localtime()``` returns an array of numbers for date, hour, minute and second. In our example here, we only need the hour and minutes. - -![4 Digit Clock](../../img/4-digit-clock.png) - -```py -# a simple clock that only grabs the time from the server on startup -import tm1637 -from machine import Pin -from utime import sleep, localtime - -tm = tm1637.TM1637(clk=Pin(1), dio=Pin(0)) - -now = localtime() -hour = now[3] -# use AM/PM 12 hour time -if hour > 12: - hour = hour - 12 -minute = now[4] -sec = now[5] -print(hour, ':', minute, ' ', sec, sep='') - -# update from the first time -while True: - # turn the colon on - tm.numbers(hour,minute,colon=True) - sleep(0.5) - # turn the colon off - tm.numbers(hour,minute,colon=False) - sleep(0.5) - sec = sec + 1 - if sec == 60: - minute = minute + 1 - sec = 0 - if minute == 60: - hour = hour + 1 - minute = 0 - if hour == 24: - hour = 0 -``` - -A more accurate version will access the new time from the server every minute. - -## Accurate Clock -```py -# a more accurate clock that only grabs the time from the server once per minute -import tm1637 -from machine import Pin -from utime import sleep, localtime - -hour = 0 -minute = 0 -sec = 0 - -def update_time(): - global hour, minute, second - now = localtime() - hour = now[3] - # use AM/PM - if hour > 12: - hour = hour - 12 - minute = now[4] - sec = now[5] - -tm = tm1637.TM1637(clk=Pin(1), dio=Pin(0)) - -update_time() -# loop every second -while True: - tm.numbers(hour,minute,colon=True) - sleep(0.5) - tm.numbers(hour,minute,colon=False) - sleep(0.5) - sec = sec + 1 - if sec == 60: - # get the new time from the host - update_time() - print(hour, ':', minute, ' ', sec, sep='') - minute = minute + 1 - sec = 0 - if minute == 60: - hour = hour + 1 - minute = 0 - if hour == 24: - hour = 0 -``` - -## References - -* [Nerd Cave YouTube Tutorial](https://www.youtube.com/watch?v=D68XtvZlk00) -* [Mike Causer's GitHub Repo with TM-1637 driver](https://github.com/mcauser/micropython-tm1637) \ No newline at end of file diff --git a/docs/displays/non-graph/10-character-lcd-display.md b/docs/displays/non-graph/10-character-lcd-display.md deleted file mode 100644 index 5dd4e51c3..000000000 --- a/docs/displays/non-graph/10-character-lcd-display.md +++ /dev/null @@ -1,140 +0,0 @@ -# Character LCD Display - -![LCD 1602](../../img/lcd-1602.jpg) - -This lesson is for using the LCM1602 I2C LCD interface. It is a popular It has four wires: - -1. GND - connect to any GND pin -2. VCC - connect to 3V3(out) pin unless you have a 3.3 to 5v voltage converter -3. SDA - connect to GP0 -4. SCL - connect to GP1 - -The photo above shows the use of a 3.3 to 5v voltage converter. This allows us to use the full 5v to the LCD backlight so we get bright contrast. You can connect the VCC to the 3V3(out) pin but the display will be harder to read. - -## I2C Address Scanner Test - -Our first task is to make sure that the 1602 chip's I2C circuits are working. We use the following I2C scanner code to do this. - -```py -import machine -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -print('Scanning I2C bus.') -devices = i2c.scan() # this returns a list of devices -device_count = len(devices) -if device_count == 0: - print('No i2c device found.') -else: - print(device_count, 'devices found.') -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) -``` - -### Scanner Result -``` -Scanning I2C bus. -1 devices found. -Decimal address: 39 , Hex address: 0x27 -``` - -## Testing the LCD - -```py -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000) -lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) -lcd.putstr("CoderDojo Rocks!") -``` - -## Putting the Device Through Display Option Tests - -Now that we know how to display text on the device, we can learn how other functions work: - -1. lcd.move_to(x,y) -1. lcd.display_on() and lcd.display_off() -1. lcd.show_cursor() and lcd.hide_cursor() -2. lcd.blink_cursor_on() and lcd.blink_cursor_off() -3. lcd.backlight_on() and lcd.backlight_off() -4. lcd.clear() - -```py -import utime - -import machine -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -def test_main(): - #Test function for verifying basic functionality - print("Running test_main") - i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000) - lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) - lcd.putstr("CoderDojo Rocks!") - utime.sleep(10) - lcd.clear() - count = 0 - while True: - lcd.clear() - time = utime.localtime() - lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format( - year=time[0], month=time[1], day=time[2], - HH=time[3], MM=time[4], SS=time[5])) - if count % 10 == 0: - print("Turning cursor on") - lcd.show_cursor() - if count % 10 == 1: - print("Turning cursor off") - lcd.hide_cursor() - if count % 10 == 2: - print("Turning blink cursor on") - lcd.blink_cursor_on() - if count % 10 == 3: - print("Turning blink cursor off") - lcd.blink_cursor_off() - if count % 10 == 4: - print("Turning backlight off") - lcd.backlight_off() - if count % 10 == 5: - print("Turning backlight on") - lcd.backlight_on() - if count % 10 == 6: - print("Turning display off") - lcd.display_off() - if count % 10 == 7: - print("Turning display on") - lcd.display_on() - if count % 10 == 8: - print("Filling display") - lcd.clear() - string = "" - for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS): - string += chr(x) - lcd.putstr(string) - count += 1 - utime.sleep(2) - -#if __name__ == "__main__": -test_main() -``` - -## References - -[MFitzp article on OLED displays](https://www.mfitzp.com/article/oled-displays-i2c-micropython/) - -[Adafruit SSD1306 Driver](https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/master/examples/ssd1306_stats.py) - -[Adafruit LCD Guide](https://learn.adafruit.com/character-lcds) \ No newline at end of file diff --git a/docs/displays/non-graph/seven-segment.md b/docs/displays/non-graph/seven-segment.md deleted file mode 100644 index af4f49e43..000000000 --- a/docs/displays/non-graph/seven-segment.md +++ /dev/null @@ -1,121 +0,0 @@ -# Sample Seven Segment Display Lab - -## 4 Digit Seven Segment Display - -![4 digit seven segment display](../../img/4-digit-7-segment-colon.png) - -Make sure to put a current limiting resistor in series with each LED. A 330 ohm resistor is a generally safe value for 5 volt circuits and you can use a 220 ohm resistor for 3.3 volt circuits. - -This code was provided by Jaison Miller from his [GitHub Repo](https://github.com/zimchaa/pico_examples/blob/main/4by7segmentdisplay.py). - -```py -from machine import Pin, PWM, Timer -import utime - -# Constants - where the pins are currently plugged into, etc. -number_bitmaps = { 0: 0b00111111, 1: 0b00000110, 2: 0b01011011, 3: 0b01001111, 4: 0b01100110, 5: 0b01101101, 6: 0b01111101, 7: 0b00000111, 8: 0b01111111, 9: 0b01100111 } -segment_masks = { 'a': 0b00000001, 'b': 0b00000010, 'c': 0b00000100, 'd': 0b00001000, 'e': 0b00010000, 'f': 0b00100000, 'g': 0b01000000 } -pin_segments = { 'a': 10, 'b': 11, 'c': 12, 'd': 17, 'e': 16, 'f': 13, 'g': 14} -pin_others = { 'decimal': 22, 'colon': 6, 'dash': 8 } -pin_digits = { 1: 18, 2: 19, 3: 20, 4: 21 } -pin_control_others = { 'colon': 27, 'dash': 7 } - -# initial setup of the pins, alternatives include using PWM to set the brightness -# if not using PWM then make sure to use appropriate resistors to avoid blowing the LEDs in the display (like I have) - -segment_maps = {} - -for segment, pin in pin_segments.items(): - segment_maps[segment] = Pin(pin, Pin.OUT) - -other_pin_maps = {} - -for feature, pin in pin_others.items(): - other_pin_maps[feature] = Pin(pin, Pin.OUT) - -digit_maps = {} - -for digit, pin in pin_digits.items(): - digit_maps[digit] = Pin(pin, Pin.OUT) - -other_maps = {} - -for feature, pin in pin_control_others.items(): - other_maps[feature] = Pin(pin, Pin.OUT) - - -def render_digit_display(show_digit=1, number=8, decimal=False): - - # turn everything off - for segment, mask in segment_masks.items(): - segment_maps[segment].value(1) - - other_pin_maps['decimal'].value(1) - - # turn on the digit required to be displayed - for digit, digit_pin in digit_maps.items(): - if show_digit == digit: - digit_pin.value(1) - # print("\n\nDigit: {} - Pin: {} - Number: {}\n".format(digit, pin, number)) - else: - digit_pin.value(0) - - utime.sleep(0.001) - - display_number_bitmap = number_bitmaps[number] - - # check every - for segment, mask in segment_masks.items(): - # print("segment: {}\nmask: {}".format(segment, mask)) - - if display_number_bitmap & mask == mask: - # print("segment OFF: {}".format(segment)) - segment_maps[segment].value(0) - else: - segment_maps[segment].value(1) - - # show decimal - if decimal: - other_pin_maps['decimal'].value(0) - else: - other_pin_maps['decimal'].value(1) - - utime.sleep(0.001) - - -def render_feature_display(show_colon=False, show_dash=False): - if show_colon: - other_pin_maps['colon'].value(0) - other_maps['colon'].value(1) - else: - other_pin_maps['colon'].value(0) - other_maps['colon'].value(0) - - if show_dash: - other_pin_maps['dash'].value(0) - other_maps['dash'].value(1) - else: - other_pin_maps['dash'].value(0) - other_maps['dash'].value(0) - -while True: - - lt_year, lt_month, lt_mday, lt_hour, lt_minute, lt_second, lt_weekday, lt_yearday = utime.localtime() - - # testing out all the features of the display - digit_1_decimal = (lt_second % 4 == 0) - digit_2_decimal = (lt_second % 4 == 1) - digit_3_decimal = (lt_second % 4 == 2) - digit_4_decimal = (lt_second % 4 == 3) - - render_digit_display(1, lt_minute // 10, digit_1_decimal) - render_digit_display(2, lt_minute % 10, digit_2_decimal) - render_digit_display(3, lt_second // 10, digit_3_decimal) - render_digit_display(4, lt_second % 10, digit_4_decimal) - - if (lt_second % 2 == 0): - render_feature_display(True, False) - else: - render_feature_display(False, True) - - ``` diff --git a/docs/getting-started/01-intro.md b/docs/getting-started/01-intro.md deleted file mode 100644 index 6c74053c8..000000000 --- a/docs/getting-started/01-intro.md +++ /dev/null @@ -1,44 +0,0 @@ -# Welcome to the CoderDojo course on MicroPython - -This course is about [MicroPython](https://en.wikipedia.org/wiki/MicroPython), a variation of the popular [Python](https://en.wikipedia.org/wiki/Python_(programming_language)) programming language that is used to program [microcontrollers](https://en.wikipedia.org/wiki/Microcontroller). - -## Intended Audience -* Junior High or High School Students -* Age 10-16 - -## Preferred Skills -* Familiarity with basic text editing functions such as select, copy and paste -* Understand how to save files to disk -* Basic understanding of Python programming language (_We strongly suggest you take the [Introduction to Python Programming CoderDojo Course](https://www.coderdojotc.org/python/trinket/00-introduction/) if you are not familiar with Python._) -* User should be familiar with the the following Python concepts: - -1. imports -2. libraries -3. variables -4. loops -5. conditionals -6. lists -7. functions -8. function parameters - -## Course Outline -* What is a Microcontroller? -* What is Micropython? -* Raspberry Pi Pico -* Getting Started: Setting up MicroPython environment using Thonny or VS Code -* Introduction to MicroPython - Getting Started -* Sensors: getting information about the world around us -* Displays: showing information to users -* Sound and Music: playing tones, sounds and music -* OLED Displays: drawing on displays -* Robots: making robots move around with motors -* Advanced Topics - -## License of Content -Our intent is to allow teachers and mentors around the world to integrate MicroPython into their courses without any fees. We want you to be able to use this content freely with a few conditions: please give us attribution and please don't resell our content for profit. - -Note that we use the same Creative Commons licensing as the Raspberry Pi Foundation and the CoderDojo Foundation: - -[Creative Commons Attribution NonCommercial ShareAlike](https://creativecommons.org/licenses/by-nc-sa/3.0/) - -This means you are free to reuse and remix this content for non-commercial educational purposes as long as you keep the attribution and preserve the license agreement. diff --git a/docs/getting-started/01b-libraries.md b/docs/getting-started/01b-libraries.md deleted file mode 100644 index 88c628541..000000000 --- a/docs/getting-started/01b-libraries.md +++ /dev/null @@ -1,169 +0,0 @@ -# What is MicroPython? -MicroPython is an implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers. (*From [micropython.org](https://micropython.org/)*) - -MicroPython was originally created by the Australian programmer and physicist Damien George. It is written in [C](https://en.wikipedia.org/wiki/C_(programming_language)). - -MicroPython is now an OpenSource project and the source code is available in [GitHub](https://github.com/micropython/micropython). -## Micropython Libraries - -When you start up your IDE, it may have a list of python modules built in. You can list the current modules you have installed by running the `help('modules')` command. - -```py -help('modules') -``` - -## MicroPython Builtin Functions -MicroPython is designed to run quickly in a small memory system. So it has trimmed down many of the standard Python libraries to fit the needs of microcontrollers. Most of these libraries start with the letter "u" so that you are aware they are designed to run on microcontrollers. - -```txt -cmath – mathematical functions for complex numbers -gc – control the garbage collector -math – mathematical functions -uarray – arrays of numeric data -uasyncio — asynchronous I/O scheduler -ubinascii – binary/ASCII conversions -ucollections – collection and container types -uerrno – system error codes -uhashlib – hashing algorithms -uheapq – heap queue algorithm -uio – input/output streams -ujson – JSON encoding and decoding -uos – basic “operating system” services -ure – simple regular expressions -uselect – wait for events on a set of streams -usocket – socket module -ussl – SSL/TLS module -ustruct – pack and unpack primitive data types -usys – system specific functions -utime – time related functions -uzlib – zlib decompression -_thread – multithreading support -``` - -## MicroPython Specific Libraries - -```text -btree – simple BTree database -framebuf — frame buffer manipulation -machine — functions related to the hardware -micropython – access and control MicroPython internals -network — network configuration -ubluetooth — low-level Bluetooth -ucryptolib – cryptographic ciphers -uctypes – access binary data in a structured way -``` - -## Adding a module - -When you are using python and you attempt to use a module that python can't find you will get an error. You must then use the python `pip` installer tool to add the new library. - -## Getting MicroPython Libraries from PyPi - - -[Filter Only MicroPython Libraries](https://pypi.org/search/?c=Programming+Language+%3A%3A+Python+%3A%3A+Implementation+%3A%3A+MicroPython) - -## Full List of modules - -```text -ESP-test audioop filecmp random -__future__ base64 fileinput re -_abc bcrypt fnmatch readline -_ast bdb formatter reedsolo -_asyncio binascii fractions reprlib -_bisect binhex ftplib resource -_blake2 bisect functools rlcompleter -_bootlocale bitstring gc runpy -_bz2 blink-builtin-led genericpath sched -_cffi_backend brain_argparse getopt secrets -_codecs brain_attrs getpass select -_codecs_cn brain_builtin_inference gettext selectors -_codecs_hk brain_collections glob send2trash -_codecs_iso2022 brain_crypt grp serial -_codecs_jp brain_curses gzip setuptools -_codecs_kr brain_dataclasses hashlib sh1106 -_codecs_tw brain_dateutil heapq sh1106-test -_collections brain_fstrings hmac shelve -_collections_abc brain_functools html shlex -_compat_pickle brain_gi http shutil -_compression brain_hashlib i2c-display signal -_contextvars brain_http i2c-scanner site -_crypt brain_io i2c_lcd six -_csv brain_mechanize i2clcd smtpd -_ctypes brain_multiprocessing imaplib smtplib -_ctypes_test brain_namedtuple_enum imghdr sndhdr -_curses brain_nose imp socket -_curses_panel brain_numpy_core_fromnumeric importlib socketserver -_datetime brain_numpy_core_function_base inspect spi-debug -_dbm brain_numpy_core_multiarray io sqlite3 -_decimal brain_numpy_core_numeric ipaddress sre_compile -_dummy_thread brain_numpy_core_numerictypes isort sre_constants -_elementtree brain_numpy_core_umath itertools sre_parse -_functools brain_numpy_ndarray jedi ssl -_hashlib brain_numpy_random_mtrand json stat -_heapq brain_numpy_utils keyword statistics -_imp brain_pkg_resources lazy_object_proxy string -_io brain_pytest led-strip stringprep -_json brain_qt lib2to3 struct -_locale brain_random linecache subprocess -_lsprof brain_re list-modules sunau -_lzma brain_six locale symbol -_markupbase brain_ssl logging symtable -_md5 brain_subprocess lzma sys -_multibytecodec brain_threading macpath sysconfig -_multiprocessing brain_typing mailbox syslog -_opcode brain_uuid mailcap tabnanny -_operator builtins marshal tarfile -_osx_support bz2 math telnetlib -_pickle cProfile mccabe tempfile -_posixsubprocess calendar mimetypes termios -_py_abc certifi mmap test -_pydecimal cffi modulefinder textwrap -_pyio cgi multiprocessing this -_queue cgitb mypy thonny -_random chunk mypy_extensions threading -_scproxy clonevirtualenv mypyc time -_sha1 cmath nacl timeit -_sha256 cmd netrc tkinter -_sha3 code nis token -_sha512 codecs nntplib tokenize -_signal codeop ntpath toml -_sitebuiltins collections nturl2path trace -_socket colorsys numbers traceback -_sqlite3 compileall opcode tracemalloc -_sre concurrent operator tty -_ssl configparser optparse turtle -_stat contextlib os turtledemo -_string contextvars paramiko typed_ast -_strptime copy parser types -_struct copyreg parso typing -_symtable crypt pathlib typing_extensions -_sysconfigdata_m_darwin_darwin cryptography pdb unicodedata -_testbuffer csv pickle unittest -_testcapi ctypes pickletools urllib -_testimportmultiple curses pip uu -_testmultiphase dataclasses pipenv uuid -_thread datetime pipes venv -_threading_local dbm pkg_resources virtualenv -_tkinter decimal pkgutil virtualenv_support -_tracemalloc difflib platform warnings -_uuid dir-example plistlib wave -_warnings dis poplib weakref -_weakref distutils posix webbrowser -_weakrefset doctest posixpath websockets -_xxtestfuzz docutils pprint wheel -abc dummy_threading profile wrapt -aifc easy_install pstats wsgiref -antigravity ecdsa pty xdrlib -argparse email ptyprocess xml -array encodings pwd xmlrpc -array-test ensurepip py_compile xxlimited -ast enum pyclbr xxsubtype -astroid errno pycparser zipapp -asttokens espefuse pydoc zipfile -asynchat espressif pydoc_data zipimport -asyncio espsecure pyexpat zlib -asyncore esptool pylint -at faulthandler queue -atexit fcntl quopri -``` - diff --git a/docs/getting-started/02-boards.md b/docs/getting-started/02-boards.md deleted file mode 100644 index 5932d6489..000000000 --- a/docs/getting-started/02-boards.md +++ /dev/null @@ -1,20 +0,0 @@ -# Micropython Boards - -Technically, any computer that has at least 16K of RAM can run MicroPython as long as someone has ported the MicroPython runtime to use that instruction set. - -## Raspberry Pi Pico -Most of these lessons use a low-cost ($4 retail list price) [Raspberry Pi Pico]()(../glossary.md#pico). The microcontroller was designed by the Raspberry Pi Foundation specifically to provide a low-cost way for student to learn how to program MicroPython. The Raspberry Pi Foundation has also worked with the [Thonny](misc/glossary.md@thonny) developers to create a simple clean kid-friendly interface that is ideal for beginning students. - -## ESP32 -The [ESP32](../misc/glossary.md#ESP32) is similar to the Raspberry Pi Pico but ESP32 also has both WiFi and bluetooth. - -## Cables -You will need a USB cable to program your microcontroller. These cables are frequently sold at high margin rates at retail stores. If you plan ahead, you can usually find these cables on eBay for about 50% less. Classroom purchases make this a good option. - - -## Getting Machine Statistics - -``` -import machine -help(machine) -``` \ No newline at end of file diff --git a/docs/getting-started/02-breadboards.md b/docs/getting-started/02-breadboards.md deleted file mode 100644 index c279ee181..000000000 --- a/docs/getting-started/02-breadboards.md +++ /dev/null @@ -1,36 +0,0 @@ -# Breadboards - -![Solderless Mini Breadboard](../img/solderless-mini-breadboard.jpg) - -We use standard solderless mini breadboards in our labs. The breadboards have holes that are spaced 1/10th of an inch apart which is a standard for most electronics in the US. - -Our breadboards are usually 1/2 size with 400-ties. They have a central trough and power rails on the left and right edges. - -## Breadboard Regions and Connections - -![Breadboard Regions and Connections](../img/breadboard-regions.png) -Learning how a breadboard works is critical for building your projects. In the figure above you will see that there are two types of regions of the breadboard - -1. The side regions are called the power distribution rails. They are similar to power lines that reach across our projects. -2. The central region is call the row connector region. In this area the horizontal rows are all connected inside the breadboard. Within any row, columns ```a, b, c, d and e``` are all electrically connected. Within any row, columns ```f, h, i, j, and k``` are also electrically connected. However, there is a gap between columns e and f called the center gap or component slot that parts are usually placed over. Components like buttons and chips usually have their pins straddle the component slot. - -## Pico Placement on Breadboard - -For most of our labs we place the Pico so that pin 1 of the Pico is in row 1 of the breadboard as in the image below. - -![Pico on Breadboard](../img/pico-on-breadboard.png) - -This means that the GND connections to the Pico are always in rows 3, 8, 13 and 18 on both sides of the breadboard. One of the ground pins is usually hooked up to the vertical blue power rails on the sides of the breadboard. - -## Pico Placement Annotations - -![Pico on Breadboard](../img/pico-on-breadboard-annotated.png) - -1. **GND** are the ground connections. There are -2. **VBUS** is the 5V power from the USB and is high only when the USB is connected. This is nominally 5V (or 0V if the USB is not connected or not powered). -3. **VSYS** (also know and Voltage System Input) is the main system input voltage. When the Pico is disconnected from the USB you apply power to the Voltage System Input. The input can vary in the allowed range 1.8V to 5.5V, and is used by the on-board SMPS to generate the 3.3V for the RP2040 and its GPIO connections. When the input voltage is less than 3.3 volts the Pico uses an internal DC voltage Boost converter to get the correct voltage to the processor. - -3V3_EN connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. To disable the 3.3V (which also de-powers the RP2040), short this pin low. In effect by making the 3V3_EN LOW you are turning off the Pico. - -## Breadboard Connections - diff --git a/docs/getting-started/02-esp32.md b/docs/getting-started/02-esp32.md deleted file mode 100644 index 4aba19a8b..000000000 --- a/docs/getting-started/02-esp32.md +++ /dev/null @@ -1,119 +0,0 @@ -# ESP32 TTGO -The ESP32 is a low-cost (under $10) microcontroller with both built-in WiFi and Bluetooth. This lab demonstrates using a version of the ESP32 that includes an integrated display. - -## Step 1: Install the USB to UART Bridge VCP Drivers - -Follow the directions here: - -[https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers](https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers) - -Test this by running the ``ls -l /dev/cu*``` and verify you see: - -/dev/cu.SLAB_USBtoUART - -If you don't see this try to reboot. - -Mac: -https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/establish-serial-connection.html -https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/raw/master/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip - -## Step 2: Create a Python Conda Environment for ESP32 -This is so we don't mess up other Python projects on your system. - -```sh -conda create -n esp32 python=3 -conda activate esp32 -``` - -## Step #3: Install the esptool - -```sh -$ pip3 install esptool -Collecting esptool - Downloading esptool-3.0.tar.gz (149 kB) - |████████████████████████████████| 149 kB 2.9 MB/s - ... -Installing collected packages: pycparser, six, cffi, reedsolo, pyserial, ecdsa, cryptography, bitstring, esptool -Successfully installed bitstring-3.1.7 cffi-1.14.5 cryptography-3.4.6 ecdsa-0.16.1 esptool-3.0 pycparser-2.20 pyserial-3.5 reedsolo-1.5.4 six-1.15.0 -``` - -## Step 4: Erase the Old Firmware - -```sh -esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash -``` - -## Step 5: Download the New Firmware -Get the ESP32_All prebuilt binary: - -[https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/firmwares -](https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/firmwares) - -## Step 6: Reflash the new ESP32 Firmware - -```sh -cd esp32_all/ -../flash.sh -p /dev/cu.SLAB_USBtoUART -``` - -this will run... -```sh -$ esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash -esptool.py v3.0 -Serial port /dev/cu.SLAB_USBtoUART -Connecting........_ -Detecting chip type... ESP32 -Chip is ESP32-D0WDQ6 (revision 1) -Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None -Crystal is 40MHz -MAC: 24:62:ab:ca:62:84 -Uploading stub... -Running stub... -Stub running... -Erasing flash (this may take a while)... -Chip erase completed successfully in 2.5s -Hard resetting via RTS pin... -``` - -## Configure Thonny -You must configure Thonny to use the ESP32. - -### Set the Serial Port -First, you must tell Thonny how to find the right port. - -![](../img/esp32-config-serial-port.png) - -### Set the Interpreter -Next, yo must tell Thonny to use the ESP32 interpreter. - -![](../img/micropython-esp32.png) - -## Run a test - -```py -import machine, display, time, math, network, utime - - -tft = display.TFT() -tft.init(tft.ST7789,bgr=False,rot=tft.LANDSCAPE, miso=17,backl_pin=4,backl_on=1, mosi=19, clk=18, cs=5, dc=16) - -tft.setwin(40,52,320,240) - -for i in range(0,241): - color=0xFFFFFF-tft.hsb2rgb(i/241*360, 1, 1) - tft.line(i,0,i,135,color) - -tft.set_fg(0x000000) -tft.ellipse(120,67,120,67) -tft.line(0,0,240,135) - -text="CoderDojo Rocks!" -tft.text(120-int(tft.textWidth(text)/2),67-int(tft.fontSize()[1]/2),text,0xFFFFFF) -``` - -You should see the following on the ESP32 display: -![](../img/color-oled.jpg) - -## References - -https://www.instructables.com/TTGO-color-Display-With-Micropython-TTGO-T-display/ \ No newline at end of file diff --git a/docs/getting-started/02-pi-pico.md b/docs/getting-started/02-pi-pico.md deleted file mode 100644 index d6a56c0ac..000000000 --- a/docs/getting-started/02-pi-pico.md +++ /dev/null @@ -1,156 +0,0 @@ -# Getting Started with the Raspberry Pi RP2040 Microcontroller - -![Raspberry Pi Pico](../img/raspberry-pi-pico.png) - -The Raspberry Pi RP2040 is a custom silicon microcontroller built by the [Raspberry Pi Foundation](glossary#raspberry-pi-foundation). The RP2040 is used in the Raspberry Pi Pico with a retail list prices of $4. With 264K SRAM, it has around 100 times the RAM of an Arduino Uno (2K). It is ideal for projects that need more RAM such as projects that require drawing to an OLED display. - -![](../img/pico-h-microcenter.png) -"H" is with headers. - -## Specs - -* RP2040 microcontroller chip designed by Raspberry Pi Foundation -* Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz -* 264KB of SRAM, and 2MB of on-board Flash memory -* Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus -* DMA controller -* Interpolator and integer divider peripherals -* Castellated module allows soldering direct to carrier boards -* USB 1.1 and PHY with device and host support -* Low-power sleep and dormant modes -* Drag-and-drop programming using mass storage over USB -* 26 × multi-function GPIO pins -* 3 12 bit analogue inputs -* 16 controllable PWM channels -* 2 SPI, 2 I2C, and 2 UART channels -* Accurate clock and timer on-chip -* 8 Raspberry Pi Programmable I/O (PIO) state machines -* Temperature sensor -* Accelerated floating-point libraries on-chip -* 8 × Programmable I/O (PIO) state machines for custom peripheral support -* Created using the TSMC 40LP (40 nano meter low power) manufacturing process -* USB mass-storage boot mode with UF2 support, for drag-and-drop programming - -## Runtimes - -![Micropython.org RP2 Runtime Page](https://micropython.org/download/rp2-pico/) - -## USB Cable -The Raspberry Pi Pico uses a USB-micro connector. You can purchase USB Micro-B to USB-A or USB-C (Mac) cables on e-bay for under $2 or for $5 at Microcenter. -![usb-micro-to-c](../img/usb-micro-to-c.png) - image from ebay - -## Pico Pinout -The pinout diagram for the Raspberry Pi Pico is shown below. - -![Raspberry Pi Pico Pins](../img/pico-pins.png) - -It features: -* 26 × multi-function GPIO pins -* 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM - - -Raspberry Pi Pico’s 40 pins with pin 1 in the upper right corner with the USB connector at the top. The pin numbers are incremented as you go counterclockwise around the board. You go down the left side and then continue up on the right side until you get to pin 40 in the upper right corner. - -When you program the Pico, you use the ```machine.Pin()``` but you always use the GP* number, never the pin number on the board pin numbers. - -The diagram above shows the top view where pins 1, 2 and 40 are printed next to the pins. - -* [Pico Pinout Datasheet PDF](https://datasheets.raspberrypi.org/pico/Pico-R3-A4-Pinout.pdf) - -Next to each pin is the primary label of what the pin does. Pins 3, 8, 13, 18, 23, 28, 33 and 38 with the black background are all GND pins. - -Pins are numbered 0-29, and 26-29 have ADC capabilities -Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT -Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN - -| Label | Name | Description | -|-------|------|-------------| -|V3|3.3 volts power|A source of 3.3 V power, the same voltage your Pico runs at internally, generated from the VSYS input. This power supply can be switched on and off using the 3V3_EN pin above it, which also switches your Pico off.| -|VSYS|~2-5 volts power|A pin directly connected to your Pico’s internal power supply, which cannot be switched off without also switching Pico off.| -VBUS|5 volts power|A source of 5 V power taken from your Pico’s micro USB port, and used to power hardware which needs more than 3.3 V.| -|GND|0 volts ground|A ground connection, used to complete a circuit connected to a power source. Several of these pins are dotted around your Pico to make wiring easier. -|GPxx|General-purpose input/output pin number ‘xx|The GPIO pins available for your program, labelled ‘GP0’ through to ‘GP28’.| -|GPxx_ADCx|General-purpose input/output pin number ‘xx’, with analogue input number ‘x’|A GPIO pin which ends in ‘ADC’ and a number can be used as an analogue input as well as a digital input or output – but not both at the same time.| -|ADC_VREF|Analogue-to-digital converter (ADC) voltage reference|A special input pin which sets a reference voltage for any analogue inputs.| -|AGND|Analogue-to-digital converter (ADC) 0 volts ground|A special ground connection for use with the ADC_VREF pin.| -|RUN|Enables or disables your Pico|The RUN header is used to start and stop your Pico from another microcontroller.| - -## Steps To Get Micropython Running on the Mac - -1. Download the MicroPython UF2 file. -2. Push and hold the BOOTSEL button and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected. -It will mount as a Mass Storage Device called RPI-RP2. -3. Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython. - -## Using Thonny -Thonny is a free lightweight Python development tool. - -1. Download the Thonny Application -2. Download the Thonny Pico driver -3. Configure Thonny to use the Pico interpreter -4. Test using the help() function -5. Test by running a blink application - - -![Thonny Micropython Firmware Update](../img/thonny-micropython-firmware-update.png) - -``` -Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2 -Writing to /Volumes/RPI-RP2/firmware -100% -Waiting for the port... -Found 2e8a:0005 at /dev/cu.usbmodem0000000000001 - -Done! -``` - -## Getting The Bootloader Running from the Thonny Python Shell - -Although you can hold down the BOOTSEL button as you are plugging in the Pico, there is a much easier way. Just type the following into the Thonny shell: - -```sh -machine.bootloader() -``` - -This will make the Pico go into the Bootloader Mode and mount the file system. You can then copy the bootloader file using the drag-and-drop from your file system or use a UNIX copy command. Once the copy is finished the Pico will automaticaly restart using the new uf2 file. - -## Using the Onboard LED - -```py -from machine import Pin -import utime -led_onboard = machine.Pin(25, machine.Pin.OUT) -led_onboard.value(1) -``` - -```py -from machine import Pin -import utime - -# right uppermost pin with USB on the left -led = Pin(16, Pin.OUT) -led.low() -while True: - led.toggle() - utime.sleep(1) -``` -Press the Play Button - -## Adding GND Markers - -One of the key disadvantages - -![](../img/pico-on-breadboard-with-gnd-markers.jpg) -## References - -### Getting Started Guide -[Raspberry Pi Getting Started](https://www.raspberrypi.org/documentation/pico/getting-started/) - -### MicroPython RP2040 Reference - -[MicroPython RP2040 Quick Reference](https://docs.micropython.org/en/latest/rp2/quickref.html) - this web page has details on how MicroPython was ported to the RP2040 Microcontroller. - -### Book PDF -[Raspberry Pi Book PDF Download from HackSpace](https://hackspace.raspberrypi.org/downloads/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBaThSIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--d43ee613629bddf78bc41c1479c2acb2ec6ef34e/RPi_PiPico_Digital_v10.pdf) -Commons Attribution-NonCommercial-ShareAlike 3.0 Unported -(CC BY-NC-SA 3.0) diff --git a/docs/getting-started/02c-thonny.md b/docs/getting-started/02c-thonny.md deleted file mode 100644 index c0d681abd..000000000 --- a/docs/getting-started/02c-thonny.md +++ /dev/null @@ -1,125 +0,0 @@ -# Thonny Python IDE - -A lightweight Python integrated development environment (IDE) that is ideal for beginners writing simple Python programs for first-time users. It has been modified to work well with the Raspberry Pi Pico. It supports different ways of stepping through the code, step-by-step expression evaluation, detailed visualization of the call stack and a mode for explaining the concepts of references and heap. - -We strongly suggest that classes begin with Thonny for the first several weeks. As students want to do more complex functions such as build automatic deployment scripts other IDEs are more appropriate. - -Thonny 3.3.3 (2021-01-21) was the first version to support the Raspberry Pi Pico. There have also been several enhancements since that release. For a release history, see the [Thonny Release History](https://github.com/thonny/thonny/blob/master/CHANGELOG.rst). We suggest checking this link monthly for updates. - -## Installing Thonny - -The best way to install Thonny is to go to the Thonny website an look for the "Download" area for your operating system. That link is here: - -[https://thonny.org/](https://thonny.org/) - -Make sure you upgrade to the latest version of Thonny if you already have a Thonny installed on your computer. - -You can find more tips on getting started with Thonny on the Raspberry Pi website: - -[https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2](https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2) - - -Thonny runs on Mac, Windows and Linux. - -## Upgrading Thonny - -Although you can always upgrade Thonny by removing it and reinstalling a new version, on Mac and Linux systems there is an easier method. - -Run the following shell command: - -```sh -sudo yum upgrade thonny -``` - -or - -```sh -sudo apt-get upgrade thonny -``` - -#### Running help() -You can enter the help() function in the main script area and then press the Play button. This will tell you - -``` -MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040 -Type "help()" for more information. ->>> %Run -c $EDITOR_CONTENT -Welcome to MicroPython! - -For online help please visit https://micropython.org/help/. - -For access to the hardware use the 'machine' module. RP2 specific commands -are in the 'rp2' module. - -Quick overview of some objects: - machine.Pin(pin) -- get a pin, eg machine.Pin(0) - machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p - methods: init(..), value([v]), high(), low(), irq(handler) - machine.ADC(pin) -- make an analog object from a pin - methods: read_u16() - machine.PWM(pin) -- make a PWM object from a pin - methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d]) - machine.I2C(id) -- create an I2C object (id=0,1) - methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True) - readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg) - machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1) - methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf) - machine.Timer(freq, callback) -- create a software timer object - eg: machine.Timer(freq=1, callback=lambda t:print(t)) - -Pins are numbered 0-29, and 26-29 have ADC capabilities -Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT -Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN - -Useful control commands: - CTRL-C -- interrupt a running program - CTRL-D -- on a blank line, do a soft reset of the board - CTRL-E -- on a blank line, enter paste mode - -For further help on a specific object, type help(obj) -For a list of available modules, type help('modules') ->>> -``` - -## Save Options -You can save a python file in Thonny to either the Pico or to your local computer's file system. - -![](../img/save-local-pico.png) - -first stop execution of any program you are running. - -## Downloading the Firmware -After you start up Thonny there will be a button in the lower right corner. - -After you click on it you will see the following: - -``` -Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2 -Writing to /Volumes/RPI-RP2/firmware -100% -Waiting for the port... -Found 2e8a:0005 at /dev/cu.usbmodem0000000000001 - -Done! -``` - -## Version -After you press play the following will appear in the console. - -```sh -MicroPython v1.13-290-g556ae7914 on 2021-01-21; Raspberry Pi Pico with RP2040 -Type "help()" for more information. ->>> %Run -c $EDITOR_CONTENT -``` - -## Plotting Values on Thonny - -If you are reading sensor values and want to see a nice plot of the values, you can use Thonny's Plot function to view the values. Simply add numeric print values to your main loop and they will be displayed in the plot window. This is very useful for any analog to digital conversions and can be used as a simple tool to view anomalies in incoming data. For example if you accidentally hook up a potentiometer's positive rail to 3.3OUT instead of the 3.3REF you will see noise in the incoming data caused by spikes on the power rails. - -## Background on Thonny - -MicroPython was originally developed by Damien George and first released in 2014. However, MicroPython did not have a development environment that was easy for students to use. Thonny was developed to provide an easy to use tool just for MicroPython development. Thonny was created at the [University of Tartu Institute of Computer Science](https://www.cs.ut.ee/en) in Estonia for this purpose. They continue to support Thonny. - -Several feature for Thonny were sponsored by the [Raspberry Pi Foundation](glossary#raspberry-pi-foundation) and we continue to see a close relationship between the Raspberry Pi Foundation and the Thonny development team. - -* [Thonny web site](https://thonny.org/) diff --git a/docs/getting-started/02d-vscode.md b/docs/getting-started/02d-vscode.md deleted file mode 100644 index 90ee67ce9..000000000 --- a/docs/getting-started/02d-vscode.md +++ /dev/null @@ -1,28 +0,0 @@ -# Using Visual Studio Code to Program MicroPython - -Although the [Thonny IDE](02c-thonny.md) is a great way for kids to start programming in Python on the Raspberry Pi Pico, it has limited advanced features and no large library of extensions. - -For intermediate to advanced Python developers, the Visual Studio Code IDE is a good options when it is used with an appropriate extension such as the [Pico Go](https://marketplace.visualstudio.com/items?itemName=ChrisWood.pico-go) extension by Chris Wood. - -Note that Visual Studio Code is sometimes just called VS Code. - -Code extensions provide code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REPL console. You can a single file on your board, sync your entire project or directly type and execute commands. Because the files are stored on your local computer, it makes it easier to use version control software to allow you to work in teams with remote developers. - -## Installing Visual Studio Code - -Visual Studio Code runs on Windows, Mac and Linux systems such as the operating systems that run on the Raspberry Pi 3 or 4. You typically need around 2GB of RAM to run VS-Code. - -See the [VS Code Requirements](https://code.visualstudio.com/docs/supporting/requirements). - -If you have a Raspberry Pi the installation instructions are [here](https://code.visualstudio.com/docs/setup/raspberry-pi). - -## Adding the Pico Go Extension - -After you have installed VS-Code you must download the Pico Go Extension: - -[Pico Go Quick Start](http://pico-go.net/docs/start/quick/) - -## References - -1. [Pico Go by Chris Wood](https://marketplace.visualstudio.com/items?itemName=ChrisWood.pico-go) -2. [Bao Phan Micropython Extension](https://marketplace.visualstudio.com/items?itemName=dphans.micropython-ide-vscode) diff --git a/docs/getting-started/03-suggested-parts.md b/docs/getting-started/03-suggested-parts.md deleted file mode 100644 index cb1252f11..000000000 --- a/docs/getting-started/03-suggested-parts.md +++ /dev/null @@ -1,138 +0,0 @@ -# Sourcing Parts - -One of the key values of CoderDojo clubs around the world is to not charge any fees for attending these clubs. Parts need to be purchase by limited funds raised through donations. Club organizers need to be frugal about getting low-cost parts for the participants. - -Our experience is that is difficult to get the right parts at low cost using firms that promise quick delivery times of a few days. The lowest price parts often must be purchased weeks in advance from places like China and Taiwan. As a result, clubs that use funds carefully must plan weeks if not months in advance of classes and events. So we strongly suggest bringing an robot part procurement team together two months before you begin to offer robot courses where students can each have their own robots. - -## Purchasing The Raspberry Pi Kits -As of June 2021, the Raspberry Pi Pico did not come integrated into low-cost development kits that include robot kit parts. You frequently must to purchase the independent parts yourself. - -Here are some of the parts we recommend. - -## The Raspberry Pi Pico -In the US, our best source of these has been Microcenter stores. They sell them for $3.99 and they often have them on sale for $1.99. - -[Microcenter Pico Part Listing](https://www.microcenter.com/product/0632771/pi-pico-microcontroller-development-board-based-on-the-raspberry-pi-dual-core-arm-cortex-m0-rp2040-processor,-up-to-133-mhz,-supports-c-c-micropython-#tabReviews) - -Microcenter has around 25 [Locations](https://www.microcenter.com/site/stores/default.aspx) in the US. - -## USB Cable -For a Mac with USB-C connectors, you will need to get a USB micro to C cable: -![USB Micro to USB C for Mac](../img/usb-micro-to-c.png) - -* [Ebay USB 3.1 USB C Type C to Micro USB Male Sync OTG Charge Data Transfers Adapters](https://www.ebay.com/itm/USB-3-1-USB-C-Type-C-to-Micro-USB-Male-Sync-OTG-Charge-Data-Transfers-Adapters/303826979844) Sample 1 meter USB cable on eBay for $2.40. - -## Headers -We need male breakaway headers with standard 1/10th inch spacing. The Raspberry Pi Pico will need 20 pins on each side. If you get 40-pin versions they can easily be broken in half. - -* EBay: [Ebay 40-Pin Male Header 0.1" 2.54mm Breadboard PCB Strip Connectors 5pc](https://www.ebay.com/itm/40-Pin-Male-Header-0-1-2-54mm-Breadboard-PCB-Strip-Connectors-5pc/193920261898) - these ship from China in a few weeks and you can get five of them for $1 (including shipping). - -* Amazon: [Amazon MCIGICM 10pcs Male Header Pin, 40 Pin Header Strip (2.54 mm) for Arduino Connector](https://www.amazon.com/MCIGICM-Header-2-45mm-Arduino-Connector/dp/B07PKKY8BX/ref=sr_1_11) - -## Solderless Breadboards -We like the 1/2 size boards that have 400 connection points. We like to mount them with the USB connector at the top with the numbers running down the left side to align with the pin numbers. - -* EBay: [Solderless Breadboard 400 Point Tie Prototype Test Bread Board PCB For Arduino](https://www.ebay.com/itm/Solderless-Breadboard-400-Point-Tie-Prototype-Test-Bread-Board-PCB-For-Arduino/312519250320) - -* Amazon: [Amazon 4 Pieces for $6](https://www.amazon.com/Pcs-MCIGICM-Points-Solderless-Breadboard/dp/B07PCJP9DY/ref=sr_1_3) - -## Hookup Wire -Use 22 gauge wire. Get a large spool of black and red and smaller spools of other colors. We use - -## Breakable 40-Pin Headers - -If you purchase the Raspberry Pi Pico kit that does not have the header pins soldered in, you can use the following to add your own header pins in so the Pico's can be used with the header pins. - -[40 pin Breakable Pin Header 2.54mm Single Row Male Header Connector Kit on eBay](https://www.ebay.com/itm/223971948942). I purchased 12 of these for $5 or $4.24 per pack of 12 when I purchase 4 packs. - -## Male-to-Male Breadboard Jumper Wires -You can use 22 gauge wire to build your projects, however kids that don't have fine motor skills sometimes get frustrated with raw wires. You can purchase a Jumper Wire Kit with 65 jumpers on EBay for under $2 that has nice plastic ends that are easier to use. - -* Ebay: [65pcs Jumper Wire cable kit for Solderless Breadboard New](https://www.ebay.com/itm/65pcs-Jumper-Wire-cable-kit-for-Solderless-Breadboard-New/191674144210) - 65 of various lengths for $1.50 - -* Ebay: [65X 65PCS Jumper Wire Cable Kit For Solderless Breadboard](https://www.ebay.com/itm/65X-65PCS-Jumper-Wire-Cable-Kit-For-Solderless-Breadboard-cs/264496035854) - -* Amazon: [ZYAMY 195pcs Breadboard Jumper Wire 12cm 16cm 20cm 24cm Solderless Flexible Breadboard Connecting Line Cables Male to Male Breadboard Jumpers (65pcs/Set x 3)](https://www.amazon.com/ZYAMY-Breadboard-Solderless-Flexible-Connecting/dp/B075F37HXW/ref=sr_1_9) - three packs of 65 for about $8 - -## Momentary Press Buttons - -![](../img/momentary-switch-button.png){:style="height:300px;width:300px"} - -A B3F Momentary Press Button with a blue cap. - -![](../img/momentary-button.jpg) - -Note the schematic in the lower right corner that shows the internal connections of the button. - -We like the B3F-4055 12 x12x7.3mm Tactile Switch Momentary Press Buttons that have small dimples on the bottom that fit into the breadboard center trough. They can be purchased for under 10 cents per unit on eBay. You can by them with our without colored caps. The links below have example listings on eBay. - -* [eBay Tactile Push Button Switch Momentary Tact & Cap 12x12x7.3mm Assorted Kit](https://www.ebay.com/itm/192318434746) - this kit includes 15 switchs with seven colors of caps for US $8.95. -* [eBay: 10PCS New B3F Tactile Switch Key Button Switch 12x12x7.3mm Blue](https://www.ebay.com/itm/381924159238) -* [eBay 100PCS B3F-4055 Tactile Switch W/ OMRON Tact Push Button Momentary 12 x12 x7.3mm](https://www.ebay.com/itm/363125477978) -* [eBay Button Caps 140PCS Round Tactile Button Cap Kits 9.58*5.1mm for 12*12*7.3mm Tact Switch](https://www.ebay.com/itm/401225666722) - -## Sensor Kit - -Although not all of these items are really "sensors" (some are displays), these kits provide high value at a low price-per item cost. Note that some of these kits contain tilt switches that contain Mercery. I remove these from the kits. - -* EBay 16 Sensor Kit [Raspberry Pi / Arduino Sensor Kit 16 Modules Package 16 kinds of sensor](https://www.ebay.com/itm/Raspberry-Pi-Arduino-Sensor-Kit-16-Modules-Package-16-kinds-of-sensor/274696315019) -* EBay 45 Sensor Kit for $18 US [45 In 1 Sensor Module Starter Kit Updated Set For Arduino Raspberry Pi Education](https://www.ebay.com/itm/45-In-1-Sensor-Module-Starter-Kit-Updated-Set-For-Arduino-Raspberry-Pi-Education/265001016990) -* [HiLetgo 37 Sensors Assortment Kit 37 Sensors Kit Sensor Starter Kit for Arduino Raspberry pi Sensor kit 37 in 1 Robot Projects Starter Kits for Arduino Raspberry pi](https://www.amazon.com/HiLetgo-Sensors-Assortment-Raspberry-Projects/dp/B01N5910XS/ref=sr_1_4) - -## Linear 10K Potentiometers -We use linear 10K potentiometers in many labs and kits. The pre-wired options are very handy but you will need some male-to-male jumpers. - -* EBay: [Pre-wired Potentiometer with Knob](https://www.ebay.com/itm/10K-OHM-Linear-Taper-Rotary-Potentiometer-10KB-B10K-Pot-With-Wire-Portable-cb/124480518885) -* EBay: [10 10K Pots for $2.29](https://www.ebay.com/itm/10pcs-B10K-10KB-Ohm-Linear-Taper-Rotary-Potentiometer-Panel-Pot-15mm-Shaft/273966791619) -* Amazon: [10K Pot Kit with 8 pots and knobs for $8](https://www.amazon.com/Ted-Lele-Knurled-Potentiometer-Screwdriver/dp/B07MF234W8/ref=sr_1_5) - -## Momentary Press Buttons -We like these small momentary press buttons because they are easy to mount directly on the breadboard. They provide ideal "Mode Programming" buttons to put the microcontroller into a programming mode. - - -## Switches -These are ideal for turning your project boxes on and off. - -## Small 0.96" OLED displays -We love these low-cost 128X64 OLED displays. They are bright and draw very little power. There are two different connectors: 4-wire I2C and 7-wire SPI. I would suggest the simpler I2C for most starter projects. - -* EBay: [0.96" OLED LCD Display Module IIC I2C Interface 128x64 For SSD1306](https://www.ebay.com/itm/0-96-OLED-LCD-Display-Module-IIC-I2C-Interface-128x64-For-SSD1306/233702086908) -* Amazon: [Five OLED displays for $7](https://www.amazon.com/gp/product/B08LYQHFJV?pf_rd_r=8CT0205PZ9NXJEKJ0PCK) - -### Larger 2.42" OLEDs -For our robot projects our students like to view the values from a distance. For them we use these $17 OLED displays that are about twice the size. - -[2.42" OLED Display wired with SPI](https://www.ebay.com/itm/2-42-OLED-Display-SSD1309-Blue-Green-Yellow-White-SPI-Port-For-Arduino-128-64/164240863927) - -## Non-rechargeable AA and AAA Battery Packs - -## Rechargeable Battery Packs -If you are work on project that need long-lasting portable power such as LED strip costumes, there are a wide variety of long-lasting rechargeable battery packs available from prices around $9 to $15. My favorites are ones that have percentage of power remaining displayed. - - -## Ultrasonic Distance Sensors -These inexpensive "ping" sensors are used in many robot projects. - -* [HC-SR04 Ultrasonic Distance Sensor](https://www.ebay.com/itm/1PS-NEW-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor/393125567677) - $1 on eBay - -## Motor Controllers - -We like two motor three wheel robots in our classrooms. They need a H-Bridge circuit for controlling the motor direction. The popular L293D chip takes four PWM signals and will use these to drive two 3-12v DC motors. The L293D chip can be mounted directly on your breadboard. However, we like the low-cost Mini motor controller boards that are only $2 that also have handy screw headers for easily attaching and removing the motor and power wires. - -Here are the specs: Here - -* Input DC 4.5-36V -* 600mA output per channel (per motor) - -* [See section 4.4 in the Raspberry Pi Pico Datasheet on the Powerchain](https://datasheets.raspberrypi.org/pico/pico-datasheet.pdf) - note that the input VSYS, the main system input voltage, is only designed to go up to up to 5.5 volts. VSYS feeds the RVT6150 buck-boost SMPS. - -* [Mini Motor Drive Shield Expansion Board L293D Module For Arduino UNO MEGA2560 R3](https://www.ebay.com/itm/Mini-Motor-Drive-Shield-Expansion-Board-L293D-Module-For-Arduino-UNO-MEGA2560-R3/182057002265) $3 -* [Amazon 3 motor drives for $7] -* [L293 Datasheet](https://www.sparkfun.com/datasheets/Components/l293.pdf) -* [Banggood L293D Motor Drive Module](https://www.banggood.com/MINI-L293D-Motor-Drive-Expansion-Board-Mini-L293D-Motor-Drive-Module-p-1202756.html?cur_warehouse=CN) -* [Parshavele](https://www.parshavelecom.com/product-page/mini-l293d-motor-driver-expansion-board) -* [ST Microelectronics L78M Datasheet](https://www.st.com/resource/en/datasheet/l78m.pdf) -* [Datasheet for 78M05 Voltage](http://solarbotics.net/library/datasheets/78M05.pdf) -* [Datasheet for ST 78M05 Voltage Regulators](https://www.generationrobots.com/media/ST_78M05DataSheet.pdf) - -Note that the L293D Mini Motor Drive shield also has a voltage regulator that delivers a constant 5 volt signal to the robot microcontroller. \ No newline at end of file diff --git a/docs/getting-started/04-power.md b/docs/getting-started/04-power.md deleted file mode 100644 index 13201c728..000000000 --- a/docs/getting-started/04-power.md +++ /dev/null @@ -1,91 +0,0 @@ -# Powering Your MicroPython Projects - -If you are just using MicroPython to learn how to code you can use the USB connector from your Mac or PC to power your project. However, if you are creating a device that can't be connected to the USB cable such as a robot, then you will need to hook up portable power supply like a battery pack to power your device. - -The good news is that most microcontrollers like the Raspberry Pi Pico or ESP32 have many options and they are easy to use. Just be careful about applying too much power since unlike the old 5V Arduino boards, these devices only use 3.3v power supplies. Connecting the Pico to a 4 AA batteries (4 X 1.5 volts = 6 volt total) can damage the Pico microcontroller. - -## Power Connectors - -The Raspberry Pi Pico has three important power connectors you should learn about. - -![](../img/pico-power-pins.png) - -1. **VBUS** - A direct connection to the USB System bus and available in the upper right corner of the Pico. When connected, circuits inside the Pico will disconnect the other power sources. This is the preferred way to power the Pico when doing development and if a USB battery pack is used. -2. **VSYS** - This the main system input voltage and used when the device is not connected to the USB. The Pico has on-board power control circuits that allow VSYS to vary anywhere in the range of 1.8V to 5.5V. This is great since three AAA batteries which start at 4.5 volts can be used even as their voltage drops to 1.8 volts. -VSYS is used by the on-board SMPS (Switched Mode Power Supply) to generate the 3.3V for the RP2040 and its GPIO. -You can use this to power the Pico if you have any non-USB battery pack such as 3 AA batteries or an external 5 volt power supply that is generated by a motor driver circuit. -3. **3V3_EN** connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. -To disable the 3.3V (which also de-powers the RP2040), short this pin low. -4. **3.3OUT** This pin can be used to power external circuitry. The maximum output -current will depend on RP2040 load and VSYS voltage, it is recommended to keep the load on this pin less than 300mA. -In in other words, you don't want to drive more than about 15 LEDs that each draw up to 20 milliamps at full power. -3V3 is the main 3.3V supply to RP2040 and its I/O, generated by the on-board SMPS. -5. **ADC_VREF** - This should not be used for any purpose other than to provide a low-current voltage reference for any of the three analog-to-digital inputs. For example if you have three potentiometers you would hook the positive rail of each of them to this pin. This allows for reasonably high-resolution analog to digital that is mostly free of the power noise present on the 3.3OUT pin. - - -### USB Battery Packs - -![USB Battery Pack Large](../img/usb-battery-pack-large.png) -There is large and growing market for rechargeable cell-phone power packs that are ideal for applications such as robotics and powering a remote microcontroller for a long time. They can be purchased in many power storage levels from 2500 milliamp hours up to over 1 million milliamp hours. - -## Preventing USB Power Pack Autoshutdown - -The one issue to be aware of with battery packs is that they automatically power down if they don't sense a minimum current being drawn such as about 10 milliamps. In many applications the Pico draws less than that amount. One fix is to simply add LED power indicator that draws 10 milliamps. This will - -### Battery Power - -3 AA alkaline batteries wired in series provide plenty of power for small Pico-based MicroPython projects. Each battery is 1.5 volts which give a total of 4.5 volts which is well within the maximum power use by the VSYS input on the Pico. - -As an alternative, you can also use 4 rechargeable NiCad batteries that have a [nominal rating of 1.2 volts each](https://www.teamtekin.com/manuals/nicad_bt.pdf). This is a total of 4.8 volts, which is still under the 5.5 volt limit. - -!!! WARNING - Do not connect 4 AA batteries directly to VSYS. 6 volts is too high for the Pico's power system and could damage it. Use a voltage regulator such as is found on motor driver boards. Another alternative is to use a DC-to-DC voltage regulator such as a [Buck Converter](https://en.wikipedia.org/wiki/Buck_converter). - -## Monitoring USB Power - -On the Pico, GP24 can be used to indicate if power is being drawn from the USB cable. You can also use this information to change the behavior such as drop into low-power mode when disconnected from a USB source. - -See [here](https://www.raspberrypi.org/forums/viewtopic.php?t=300676) - -Here is some sample MicroPython code that displays this value: - -```py -import machine -import utime - -led_onboard = machine.Pin(25, machine.Pin.OUT) -USBpower = machine.Pin(24, machine.Pin.IN) - -while True: - led_onboard.value(1) - utime.sleep(0.5) - led_onboard.value(0) - utime.sleep(0.5) - if USBpower() != 1: - utime.sleep(1) -``` - -This program prints out the value of the USB Power indicator. - -```py -import machine -import utime - -led_onboard = machine.Pin(25, machine.Pin.OUT) -USBpower = machine.Pin(24, machine.Pin.IN) - -if USBpower() = 1: - print('drawing power from the USB') -else - print('drawing power from VSYS - a battery or external power source') -``` - -Power consumption when running this code is approximately 0.1W (19mA at 4.99V, so 4 x AA batteries (@ 2,000mAh each) would keep the Pico running for well over 4 days. - -## Running both USB and External Battery Power on the Raspberry Pi Pico - -The battery should provide a voltage greater than 1.8v and less than 5.5v. Importantly if both a battery and a micro USB cable are connected at the same time a Schottky diode should be placed between the battery positive and VSYS [see section 4.4 & 4.5 of the [Raspberry Pi Pico Datasheet](https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf). As long as the battery voltage is less than that coming in from the USB cable, power will be drawn from the USB supply and not the battery and, when you unplug the Pico from its USB supply, the Pico will keep on running, using power from the battery (and visa versa when you plug it back in). - -## Monitoring Batter Power Level on the Raspberry Pi Pico - -You can use one of the three analog to digital converters to allow the Pico to monitor the power remaining in an external battery. For example if you have 3 AA batteries you can connect two 100K ohm resistors in series and connect the top and bottom to the power and ground. Then connect the midpoint to one of the three ADC inputs. This will give you a way to monitor the power remaining in an external battery. A fully charge battery pack voltage such at 4.5 volts will generate a voltage of 1/2 the maximum level. As the voltage drops to 1.8 volts it should display a value of 0%. An OLED can provide an ideal way to display the power level remaining. \ No newline at end of file diff --git a/docs/getting-started/06-yd-2040.md b/docs/getting-started/06-yd-2040.md deleted file mode 100644 index ae5de7d5f..000000000 --- a/docs/getting-started/06-yd-2040.md +++ /dev/null @@ -1,37 +0,0 @@ -# The YD-RP2040 - -![](../img/YD-RP2040-pinout.png) - -The [VCC-GND](http://vcc-gnd.com/) YD-RP2040 is a microcontroller that sells for $5-$10 on e-Bay. It is rumored to come -with either 4MB or 16MB flash, but the units I have received only have 2MB. - -## Additions - -* Pin labels are on the top where they should be! -* There is a red LED to show that power is connected -* There is a RESET button -* There is a USER button on GP24 -* There is a blue LED on GP25 -* There is an RGB NeoPixel LED on GP23 -* Four Analog to digital converters (the Pico only had two) -* - -## W25Q32 Flash Chip - -The board has a W25Q32 (32M-bit) Serial Flash chip. - -From the [W25Q32 Datasheet](https://www.alldatasheet.com/datasheet-pdf/pdf/231258/WINBOND/W25Q32.html): - - It provides a storage solution for systems with limited space, pins and power. The 25Q series offers flexibility and performance well beyond ordinary Serial Flash devices. They are ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI (XIP) and storing voice, text and data. The devices operate on a single 2.7V to 3.6V power supply with current consumption as low as 5mA active and 1µA for power-down. All devices are offered in space-saving packages. - -## Demo Program - -This program shows the blue LED flashing and the NeoPixel cycling through colors. -You can press the USR button to change the cycle speed. - -```py -``` - -## References - -* [Walmart](https://www.walmart.com/ip/YD-RP2040-Development-Board-16MB-Flash-Core-Board-Compatible-PICO-Dual-Core-Microcontroller-Motherboard/3989683668?wmlspartner=wlpa&selectedSellerId=101229946) \ No newline at end of file diff --git a/docs/getting-started/10-displays.md b/docs/getting-started/10-displays.md deleted file mode 100644 index bbd74def8..000000000 --- a/docs/getting-started/10-displays.md +++ /dev/null @@ -1,158 +0,0 @@ -# Adding A Display to Your Project - -In the past, the memory available in an standard Arduino Uno (2K bytes) was too small to add high quality displays. With the arrival of the ESP32 and the Raspberry Pi Pico this has all changed. These microcontrollers have around 100 times that RAM - typically around 200K bytes. So we are integrating low-cost OLED displays into many of our CoderDojo projects! - -## Display Types -There are four main types of display technology that use for small microcontrollers. - -1. **LED** - Light Emitting Diode - these are often low-resolution but have larger area. The start with single color displays but there are also multi-color LED strips and LED matrix displays. -2. **OLED** - Organic Light Emitting Diode - small low-cost and high-contrast monochrome displays used in watches. -3. **LCD** - Liquid Crystal Display - many of these are monochrome displays that must have precise power to get consistent contrast. -4. **TFT** - Thin Film Transistor - a type of LCD that are used for larger color screens. - -![8X8 LED Matrix Display](../img/led-matrix-display.png) -![240x240 Full Color TFT Display](../img/tft-color-display.png) -![Color OLED](../img/color-oled.jpg) -240X240 TFT Display - -[Full Color LCD TFT Display SPI HD 65K Module ST7735](https://www.ebay.com/itm/Full-Color-LCD-TFT-Display-IPS-7P-SPI-HD-65K-Module-ST7735-Not-OLED-For-Arduino/265047107918) - -## Concepts -Before you begin to use these displays, there are a few things to understand to use them effectively. Based on your project needs, you can use this knowledge to find the right solution for you. - -### Framebuffers -A framebuffer is a copy of the display information that is resident within the RAM of the microcontroller. It must be as large as the display. For a 128X64 monochrome display this would be 128 * 64 = 8192 bits or 1,024 bytes (1K). A full color 240X240 TFT which uses 8 bits for red, green and blue would require 3 X 8 X 240 X 240 = 1,382,400 bits or 172K bytes. - -Not all all displays need framebuffers. Some displays can take a series of vector drawing commands such as "draw line" and "draw text". These displays can be useful if you don't have a large amount of RAM. - -## Display Chip Types - -There are two common versions: - -1. **SSD1306** - This is the most popular and versatile chip. It can be used to drive many different types and sizes of OLEDs. The SSD1306 can be used with both the simple 4 wire I2C interface as well as the slightly faster 7 wire SPI interface. These devices have only four wires labeled VCC, GND, SDA and SCL. SDA is for data and SCL is for the clock. -2. **SH1106** - This is less popular version and supports the 4-wire I2C interface. -3. **ST7735** - This chip is used on larger color TFT displays. -4. **ILI9341** - This chip is used on larger TDF displays. - -You can usually look on the back of the display device and see what type of check controls your OLED display. - -## Communication Protocols - -In addition to the multiple types of displays and types of chips driving the displays, there are also two options on how you want to communicate between your microcontroller and the display. - -1. **I2C** - This is the most common type and only requires two wires beside power and ground. Us this as your default unless you display does not support it. The original specification of I2C had a communication speed of 100K bits per second. Many systems can be run at 400K per second. -2. **SPI** - This is a more complex interface and requires up to seven wires. Some devices only support SPI interfaces. SPI typically runs around 1M bits/second although it can go up to 10M bits/second in some applications. SPI is ideal when you want to transfer a large amount of display data to a screen quickly. - -### Basic Draw Functions - -For our beginning labs we will just do some basic drawing. We will start out with just four functions: - -1. Initialize the display framebuffer memory with the right object class initialization -2. Fill the framebuffer will zeros which are black pixels with the oled.fill(0) -3. Draw white text in the framebuffer memory with the oled.text("Hello World!", 40, 10) -4. Send the entire framebuffer to the display over the bus with the oled.show() function. - -### Initializing the Framebuffer - -Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled "oled" using the following line: - -```py -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 64, i2c) -``` - -|Function|Description|Parameters| -|--------|-----------|----------| -|oled.fill(0)|Fill the display with white or black|0=black and 1=white| -|oled.text("Hello",|Draw text|String, x (horizontal from left edge) and y (vertical from the top)Example: Draw "Hello World" 40 over and 10 down. oled.text("Hello World!", 40, 10)| -|show|Show the display|Send the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.| - -The full program would look like this: - -```py -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -``` - -This would display the following: - -![OLED SPI Hello World](../img/oled-hello-world.png) - - -### Full list of Drawing Functions - -Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class. - -```py -from ssd1306 import SSD1306_I2C -print(dir(SSD1306_I2C)) -``` -This returns the following list: - -```py -['__class__', '__init__', '__module__', '__name__', '__qualname__', -'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline', -'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline', -'init_display', 'write_cmd', 'show', 'poweroff', 'poweron', -'contrast', 'write_data'] -``` -Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions. - -The following are relevant for the SSD1306_I2C display. - -The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state is 0=off (black) and 1=on (white). - -|Function|Description|Example| -|--------|-----------|-------| -|blit| -|fill(state)|Fill|Fill with black (0) or white(1)| -|fill_rect|Fill a rectangle|| -|hline(x1, x2, y, state)|Draw a horizontal line|Draw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1)| -|invert|invert the display|| -|line(x1,y1,x2,y2)|draw a line at any angle|Horizontal oled.line(0,0, 127, 63, 1)| -|pixel|Draw a single point on the screen|| -|rect|Draw an empty rectangle|| -|scroll|Scroll the display|| -|text|Write text at a point|| -|vline|Draw a Vertical Line|oled.vline(width - 1, 0, height - 1, 1) # right edge| -|init_display|Initialize the display|| -|write_cmd|Write a command to the display|| -|show|Update the display from the frame buffer|| -|poweroff||| -|poweron||| -|contrast||| -|write_data||| - - -### Interfaces - -### I2C - -Pros: Simple four wire interface - -|Pin|Purpose|Description| -|---|-------|-----------| - -### SPI - -Example: 128X64 pixel monochrome displays - -## Types of Displays - -### Summary Table - -|Display Type|Cost|Links|Notes| -|------------|----|-----|-----| - -### LCD - -### OLED - -### TFT Displays - -## References - -[ST7735 Micropython Driver by Anthony Norman](https://github.com/AnthonyKNorman/MicroPython_ST7735) \ No newline at end of file diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 066193aba..000000000 --- a/docs/index.md +++ /dev/null @@ -1,96 +0,0 @@ -# CoderDojo Twin Cities Micropython - -![Micropython logo](img/banner.png) - -This website and GitHub repository are for sharing resources to teach MicroPython to students in 5th to 12th grades (10-18 years old). The course assumes that either a mentor, teacher or students have access to at least one microcontroller such as the $4 Raspberry Pi Pico or the $10 ESP32. Students should also have access to some low-cost sensors (buttons, potentiometers, ultrasonic distance sensor) and displays such as LEDs or OLED displays. - -If you are looking for a specific topic, please remember to use the search function in the upper right of the website. The website is best displayed on a wide screen to see the navigation bar on the left although the website also works on the small screens of mobile phones and tablets. - -## Course Outline - -You can use the navigation area on the left side panel to navigate to different parts of the website. Here is a high-level overview of the main sections of the site. - -### Section 1: Introduction to Physical Computing - -This part is a high-level overview of what MicroPython is and why is has become the most popular way to do physical computing, program microcontrollers and build robots. We also discuss the different types of microcontrollers available, their price and features and how to purchase them independently or in kits. - -### Section 2: Getting Started with MicroPython - -This part will help you get started programming MicroPython on your microcontroller and learn how to hook up parts on a solderless breadboard. We discuss the need for a desktop Integrated Development Environment (IDE) and how to get started writing simple programs - -### Section 3: Basic Examples - -These ten lessons are the foundations for learning [MicroPython](misc/glossary#micropython). They include learning how to blink one or more LEDs, monitor for button presses, fade LEDs in and out using PWM signals, read analog values from potentiometers, read light sensors, turn motors and servos and display rainbow patterns on a NeoPixel strip. Many other labs are variations of these 10 labs. - -[Introduction to Basic MicroPython Examples](intro/01-intro.md) - -### Section 4: Sensors - -This section will give you more examples of how to use different types of sensors such as heat sensors, current sensors, rotary encoders, accelerometers, gesture sensors, and magnetic field sensors. - -[Reading Sensors with MicroPython](sensors/01-intro.md) - -### Section 5: Motors and Robots - -This is our student's favorite part of this site! Once you can make a motor go forward and reverse, you are close to being able to make a robot move. We walk you through the basics of using a simple transistor to control a motor, to using simple motor controllers like the L293D chips. - -[Introduction to Motors and Robots with MicroPython](motors/01-intro.md) - -Note that we have many other advanced labs that use our $11 [Cytron Maker Pi RP2040 Kits](kits/maker-pi-rp2040-robot/01-intro.md). These incredible boards have everything integrated to build robots with lights and sounds. - -### Section 6: Displays - -This section shows you how to use many different types of displays, from simple 7-segment digital displays to complex OLED graphic displays. On the old 2K Arduino controllers these graphics labs used to be hard, but now we have 264K of RAM on the Raspberry Pi RP2040 microcontrollers. Now these labs are easy! - -* [Simple Character Displays](displays/01-intro.md) -* [Graphical Displays](oled/01-intro.md) - -### Section 7: Sound and Music - -Having powerful microcontrollers allows us to generate complex sounds, play tones and even playback recoded sound effects. - -[Introduction to Sound and Music with MicroPython](sound/01-intro.md) - -### Section 8: Advanced Labs - -We have now covered all the things you need to build hundreds of projects. This section contains deeper dives into other topics -such as how to use the MicroPython Remote ```pmremote`````` tools to automate the loading of software onto your microcontroller. - -[Advanced Topics](advanced-labs/01-intro.md) - -### Section 9: Kits - -This section contains detailed steps to use the popular educational kits that are now integrating MicroPython and the RP2040 microcontroller. There are many kits and these lessons contain full working programs to build complex projects like a collision avoidance robot with OLED displays. - -[MicroPython Kits](kits/01-intro.md) - -## Related and Reference Material - -Lastly, we have a large glossary of terms, contact information and references to other websites that might be useful in your projects. Many of our more advanced projects have been moved into separate websites. -Here are a few of these sites: - -1. [Moving Rainbow](https://dmccreary.github.io/moving-rainbow/) - focus on a full curriculum around using LED strips to make displays and costumes. -2. [Robot Faces](https://dmccreary.github.io/robot-faces/) and have been moved into their own repositories. -3. [Clocks and Watches](https://dmccreary.github.io/micropython-clocks-and-watches/) - dozens of examples that just focus on creating clock and watch projects. These projects use the Pico "W" and the new low-cost SmartWatch displays. -4. [Robot Day](https://dmccreary.github.io/robot-day/) - details of building a single-day event to promote STEM at your school using -collision avoidance robots. -5. [Beginning Electronics](https://dmccreary.github.io/beginning-electronics/) -6. [AI Racing League](https://www.coderdojotc.org/ai-racing-league/) - this site moves from MicroPython on the Raspberry Pi Pico to full Python on Raspberry Pi single-board computers. It is designed for students -who have mastered many of our programming labs and want more challenging projects involving data literacy, machine learning and computer vision. - -### Glossary of Terms - -[Glossary of MicroPython Terms](misc/glossary.md) - -### References - -This is an annotated list of other on-line resources to help you learn MicroPython and use microcontrollers. - -[Micropython References](misc/references.md) - links to other useful sites. - -If you have suggestions for additional references projects, please [let us know](mailto:info@codesavvy.org)! - -### Contact -[Contact](misc/contact.md) - - diff --git a/docs/intro/01-about.md b/docs/intro/01-about.md deleted file mode 100644 index 07bfbeeb4..000000000 --- a/docs/intro/01-about.md +++ /dev/null @@ -1,31 +0,0 @@ -# About MicroPython for Kids - -The this site provides a rich collection of resources to teach computational thinking to students from 10 to 16 years old using fun Python programs that control the physical world around us. - -The sub-field of computer science that reads sensors and controls lights and motors is called [Physical Computing](../misc/glossary#phyical-computing). We cover physical computing in our [next section](./02-physical-computing.md). - -## Content Licenses -All the content on this website is licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike](https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). This means if your preserve the attribution and license you can use the content for free in your classrooms and modify and extend the curriculum to meet your needs. However, you can not charge your students additional feeds for the content or resell the content. - -## Contributing to This Website - -We invite all students, teachers and mentors to help us build a better website. You can read our publishing process on the [CoderDojo Twin Cities Content Authoring Guide](https://www.coderdojotc.org/CoderDojoTC/content-authoring-guide/). - -Please make sure you using original content and avoid using any images that you have not created yourself. It is always a good idea to have a friend check your spelling, typos and links. - -There are several ways to contribute to get your content on this website. - -### Git Pull Requests -If you know how, you can student submit a Git [Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests). This tells our team that you have content to contribute. Don't be scared about learning how to do this. There are lots of examples online and please reach out if you are having trouble. This is our preferred approach, but we realize that the first time you do this there are several things you need to know. - -### Adding a New Issues -You can just open a new [Issue](https://github.com/CoderDojoTC/micropython/issues and put your content in [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/about-writing-and-formatting-on-github). You will also need to tell us where you store any images and videos. It might take us some time get this content into a new release. - -### Let Us Setup a Edit Page -If learning how to do pull requests is too daunting for you, don't worry! You are not alone. If you want us to setup a web page you can edit using the simple "Edit" button on GitHub we can do that for you. Just tell us where you want the page located and give us your GitHub ID and we will set this up. You will need to let us know when your content is ready to be merged in to our releases. - -### Manual Methods -What if you have an urgent class coming up and don't have time to learn Markdown? If this happens, you can send us your raw content in MS-Word, PowerPoint or a Google Doc. Since we are an all-volunteer organization, we will need time to find a volunteer to convert your content into Markdown. All urgent requests should go to: - -info@codesavvy.org - diff --git a/docs/intro/02-physical-computing.md b/docs/intro/02-physical-computing.md deleted file mode 100644 index 34d4f08e6..000000000 --- a/docs/intro/02-physical-computing.md +++ /dev/null @@ -1,98 +0,0 @@ -# What is Physical Computing? - -Physical Computing is the process of using computers to read data from sensors about the world around us and then taking actions on this incoming data stream. These actions are typically doing things like blinking and LED, moving a motor or updating a display. - -![](../img/physical-computing.png) - -## Physical Computing in Teaching Computational Thinking - -Physical computing plays an important role in teaching the core concepts in Computational Thinking. Often times students quickly lose interest when only abstract concepts are used. Physical computing allows direct hands-on experiences that keeps students engaged and gives them immediate feedback. Although our labs start slowly with simply blinking LEDs, they quick move to controlling motors and building robots. - -The material in this website is designed to leverage everything we have learned to make our lessons be fun, engaging and allow students to come up with their own ideas for project-based learning. - -## Why Physical Computing Has Become So Popular - -In the past, the chips we used to teach physical computing (called microcontrollers) were slow, had huge memory limitations, and were expensive. They were also hard to program and since we could not use the Python language that is popular in most classrooms today. - -This all changed in [January of 2021](https://www.raspberrypi.com/news/raspberry-pi-silicon-pico-now-on-sale/) when the Raspberry Pi Foundation released a $4 microcontroller called the Pico that has 200 times the memory of the most popular microcontroller (The $25 [Arduino Uno](https://store-usa.arduino.cc/products/arduino-uno-rev3/)). Now teachers could purchase an entire classroom full of microcontrollers that were powerful enough to even do [machine learning](https://www.arducam.com/raspberry-pi-pico-machine-learning/). - -One way to measure the cost effectiveness of this system is to compare the cost per kilobyte of RAM. The Arduino Uno was about $12.50 per kilobyte. The new Raspberry Pi Pico, with 264K RAM cost only 2 cents per kilobyte! - -![](../img/cost-per-kilobyte-ram.png) - -There was also one other *HUGE* advantage of these microcontrollers. They ran Python! Python is the most popular language for students today. There are millions of on-line websites that show kids how to learn Python like our own [CoderDojo Beginning Python](https://www.coderdojotc.org/python/trinket/00-introduction/) classes. Teachers now had the big three factors: - -1. Low cost ($4) -2. Powerful (264K RAM) -3. Runs Python - the most popular language for teaching - -But there was a small problem. Although there were millions of sample programs for the old under-powered Arduino microcontrollers, we needed high-quality lessons for our students to learn to use the new microcontrollers. And these lessons need to be flexible so teachers around the world could build new courses out of this content without having to purchase expensive textbooks. That is why this website is so important. We hope you see how excited we are to bring you this new content! - -## Examples of Sensors - -Here are some sample sensors that we use: - -1. Buttons and switches -2. Light sensors (photoresistor) -3. Distance sensor (both ultrasonic and light) -4. Sound sensors -5. Motion and acceleration sensors -6. Gesture sensors -7. Magnetic field sensors (like a compass) -8. Heat sensors -9. Touch sensor -10. Voltage and current sensors -11. Orientation and tilt sensors -12. Water and moisture sensors -13. Chemistry sensors such as Ph level (acidity) -14. Smoke and gas sensors -15. Air quality sensors - -## Examples of Actuators - -Here are some of the Actuators we use: - -1. LEDs -2. Motors (simple DC motors) -3. Servos -4. Displays (character displays, graphic displays) - -## What are the Challenges in Physical Computing - -In the real world, sensor data can be complex. We often need to look for complex patterns in an incoming data stream. For example, how can we detect complex motion such as gestures from a simple distance measurement? Other questions that we have to consider include: - -1. How often should we sample the data provided by a sensor? -2. How to we calibrate sensors to get accurate readings? -3. How do we convert sensor data into forms that are easy to use? -4. How can we look for patterns in data? Can we detect specific sounds or speech? -5. How can use use machine learning to train a model to detect specific patterns such as a "wake word" in a smart speaker system? -9. If you have allergies, what types of sensors could tell you how bad the pollen counts are outside today? -10. How can we send data back to a central server? - - -## Questions for Discussion - -1. What other sensors and actuators can you think of? -2. How would you determine how much battery power is left in your robot? -6. Can you give an example of a sensor in your house that is used to regulate temperature? -7. Can you name a sensor in your house that could save your life? -8. How many sensors do you think a typical car has? -11. What data could you gather and sell? - -## References -1. [Wikipedia on Physical Computing in Education](https://en.wikipedia.org/wiki/Physical_computing#In_Education) -2. [Sample Sensor Kit on Amazon](https://www.amazon.com/kuman-K5-USFor-Raspberry-Projects-Tutorials/dp/B016D5L5KE) - - -## Answers to Discussion questions - -* You would use a voltage sensor to see how much power is available in a battery. -* The name of a device that controls the temperature in your home is called a thermostat. It tells your home furnace or air conditioner to go on or off. -* Smoke detectors and carbon monoxide detectors are examples of devices that save thousands of lives every year. According the the [New York Department of Health](https://www.health.ny.gov/prevention/injury_prevention/children/toolkits/fire/smoke_alarms_effective_preventing_deaths.htm) presence of a working smoke alarm in a home reduces the risk of dying in a fire by about 50%. Worldwide, over 10,000 lives are saved every year by smoke detectors. [Freakonomics](https://freakonomics.com/2012/02/how-many-lives-do-smoke-alarms-really-save/) -* A modern car has almost 100 sensors in it. This includes motor sensors and sensors to detect if your doors are closed and your seatbelt is fastened. - -## References - -* [How a Small Charity is Upsetting the Trillion-Dollar Silicon Chip Industry](https://dmccreary.medium.com/how-a-small-charity-is-upsetting-the-trillion-dollar-silicon-chip-industry-ad8062e8c627) -* [Raspberry Pi Pico Robot in Micropython] -(https://dmccreary.medium.com/raspberry-pi-pico-robot-in-micropython-51f956486270) \ No newline at end of file diff --git a/docs/intro/03-microcontrollers.md b/docs/intro/03-microcontrollers.md deleted file mode 100644 index 2190f6d84..000000000 --- a/docs/intro/03-microcontrollers.md +++ /dev/null @@ -1,74 +0,0 @@ -# Microcontrollers - -![Microcontrollers](../img/microcontrollers.jpg) -Left to right: Raspberry Pi Pico, Cytron Maker Pi Nano, Cytron Maker Pi 2040, Cytron Maker Pi Pico, ESP-32, ESP TTGO - -This lesson is an overview of microcontrollers and their role in teaching [physical computing](https://en.wikipedia.org/wiki/Physical_computing). - -A [microcontroller](https://en.wikipedia.org/wiki/Microcontroller) is a small low-cost computer used to control physical devices such as LED, servos and motors. Microcontroller boards typically cost around $4 to $6 and are an ideal way to learn about computer science because you can use them to build fun projects. For example you can control a row of LEDs, move a robot and sense the world around us with a variety of light, sound and motion sensors. - -## Types of Microcontroller Boards Used in These Labs - -We use a variety of microcontroller boards that are based on either the Raspberry Pi RP2040 chip or the ESP32. The boards we use are all low-cost (under $10) but have a variety of on-board devices such as buttons, LEDs, speakers and motor controllers. Which board you use depends on how many of these components you need in your projects. The RP2040 has 264K RAM and the ESP32 has 520K RAM. - -Some of the boards are mounted on breadboards and others use Grove connectors to connect sensors and actuators. - -### Raspberry Pi Pico - -This microcontroller is low cost (retail list price is $4) and can be mounted directly on a breadboard. The Pico has just a single LED and no buttons. - -In the past, microcontrollers were difficult for younger students to program. They were also too expensive for every student to purchase and take home. A typical Arduino kit could easily cost over $20 and required you to learn C to program it. - -Today, microcontrollers such as the [Raspberry Pi Pico](https://www.raspberrypi.org/products/raspberry-pi-pico/) and the [ESP32](https://en.wikipedia.org/wiki/ESP32) cost as little as four dollars. And these devices are designed to be programmed in Python, the most popular programming language for students. - -## What is Physical Computing? -[Physical Computing](https://en.wikipedia.org/wiki/Physical_computing) is a field of study that can sense and respond to the world around us. Unlike programming a cell phone or a laptop computer, our focus is reading sensor values and quickly responding to changes. Physical Computing is widely used to teach principals of computer science because students can create their own projects and express creativity such a controlling the patterns of lights or creating complex sounds. - -## How Microcontrollers are Used -Microcontrollers do three things: - -1. They read sensor values of the world around them -2. They transform this data into useful representations -3. They send outputs to devices that control the world such as LEDs and motors as well as displays - -Here is a general diagram to think about when you are designing microcontroller systems: -![Microcontroller Architecture](../img/microcontroller-arch.png) - -Here is a specific example instance of what inputs and outputs might do. -![Microcontroller Architecture Example](../img/microcontroller-arch-example.png) - -## Programming a Microcontroller - -In this class, we will use the MicroPython to program our Microcontroller. - -Our programs will usually have the following structure: - -1. **Imports**: Specify the Python libraries used in the code (*More Information on Python libraries are available [here](https://docs.python.org/3/tutorial/modules.html)*) -2. **Setup**: Setup/ Initialize variables and sensors -3. **Main loop**: Continuously monitor sensor inputs and take actions - -The following is an example code in Micropython: - -```python -# Import Section -import machine -import time - -# Setup Section -led = machine.Pin(16, machine.Pin.OUT) - -# Main Loop -while True: - led.high() - time.sleep(0.5) - led.low() - time.sleep(0.5) -``` - -Almost all our programs will start with the `import machine` line. This tells the system that we need to gather all the libraries that understand our physical machine. - -If you couldn't understand the example program - don't worry! We will be going through it in detail as we work on our labs. - -## References - -* [Listing of RP2040-based Boards on the Raspberry Pi Foundation Website](https://www.raspberrypi.com/documentation/microcontrollers/rp2040.html#rp2040-based-boards) diff --git a/docs/kits/01-intro.md b/docs/kits/01-intro.md deleted file mode 100644 index 52a774566..000000000 --- a/docs/kits/01-intro.md +++ /dev/null @@ -1,75 +0,0 @@ -# Kits for Learning MicroPython - -This section review several kits for learning MicroPython. Most of them use the RP2040 chip, but there are some that also use the ESP32 when wireless communication is needed. - -## Solderless Connectors - -There are several types of solderless connectors used in these kits. They connect sensors and motors to these kits without the need for soldering. They are ideal for student labs that don't want the fire-hazards associated with soldering or where solderless breadboards and hot-glue is not flexible enough. - -These are usually 3 and 4-wire connectors that support analog and digital input and output as well as I2C bus and UART communications. They are typically designed to carry about 1 amp of current. - -* [Grove Connectors](https://wiki.seeedstudio.com/Grove_System/) - popular with Seeed and Cyton kits. See the manual [here](https://www.seeedstudio.com/document/pdf/Introduction%20to%20Grove.pdf) -* [Qwiic](https://www.sparkfun.com/qwiic) - SparkFun I2C connector -* [Stemma and Stemma QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt) - Adafruit connectors are built around standard [JST PH 2mm](https://www.jst-mfg.com/product/detail_e.php?series=199) spacing connectors. - -## Example Kits - -The following list is not design to be an exhaustive list of all MicroPython development kits available on the market. We focus on value-based kits that will help our students have fun learning computational thinking. - -* Basic Kit - Our standard labs use a $4 Raspberry Pi Pico on a $2 solderless breadboard. You will also need some 22-gauge wire or a jumper wire kit. -* [Maker Pi RP2040 Kit](maker-pi-rp2040/01-intro.md) - this is a $9.90 kit from Cytron that features a single board with many features for small robots. It is an ideal low-cost starter kit. - -## Searching SparkFun - -You can also use the MicroPython "tag" to search all the kits on the SparkFun site: - -[https://www.sparkfun.com/categories/tags/micropython](https://www.sparkfun.com/categories/tags/micropython) - -## References - -Here are kits that we have seen but have not yet evaluated: - -# Waveshare PicoGo Robot -PicoGo Mobile Robot is a $43 robot based on Raspberry Pi Pico. - -1. SKU: 20380 -2. Part Number: PicoGo-EN -3. Powered by 2x 14500 Li-ion batteries. NOTE! We don't recommend these for classroom use since they are a fire hazard. -4. Battery protection circuit: over charge/discharge protection, over current protection, short circuit protection, reverse proof, more stable and safe operating -Recharge/Discharge circuit, allows programming/debugging concurrently while recharging -4. 5-ch infrared sensor, analog output, combined with PID algorithm, stable line tracking -Onboard multiple smart robot sensors like line tracking, obstacle avoidance, no more messy wiring -5. 1.14 inch IPS colorful LCD display, 240 x135 pixels, 65K colors -6. Integrates Bluetooth module, allows teleoperations like robot movement, RGB LED display color, buzzer, etc. by using mobile phone APP -6. N20 micro geared motors, with metal gears, low noise, high accuracy -7. NeoPixel -8. Line following sensors - -[](https://www.waveshare.com/product/robotics/mobile-robots/picogo.htm?sku=20380) - -## Getting Started Kits - -### Vilros Getting Started Kit -[Vilros Getting Started With MicroPython on Raspberry Pi Pico Kit](https://vilros.com/products/vilros-getting-started-with-micropython-on-raspberry-pi-pico-kit) - -This kit includes: - -1. List price is $44.99 -2. Raspberry Pi Pico with soldered headers -3. Includes printed *Vilros Get Started with MicroPython on Raspberry Pi Pico* booklet -4. USB Type-A to micro cable - 1 meter -5. 3AA battery pack with micro USB connector -6. 30 × Jumper wires -7. 12 LEDs: 3x red, 3x blue,3x yellow and 3x green -8. 5 Push-button switches -9. 10 330 Ω resistors -10. Piezoelectric buzzer -11. 2 10 kΩ potentiometers -12. HC-SR501 PIR sensor -13. I2C 1602 character LCD module -14. WS2812B LED strip -15. Clear hard plastic box for small part storage -16. Neoprene case With pocket -17. Raspberry Pi Pico pinout guide - -The only problem with the parts is the lack of connectors for the potentiometers don't work well directly on the breadboard. You will need to solder wires to use them on the breadboard. diff --git a/docs/kits/larson-scanner/01-intro.md b/docs/kits/larson-scanner/01-intro.md deleted file mode 100644 index 7ee74b205..000000000 --- a/docs/kits/larson-scanner/01-intro.md +++ /dev/null @@ -1,177 +0,0 @@ -# Larson Scanner Pumpkin - -![Larson Scanner Cylon Pumpkin](../../img/cylon-pumpkin.gif) - -The Larson Scanner is a light pattern special effect named after [Glen A. Larson](https://en.wikipedia.org/wiki/Glen_A._Larson). Larson used this pattern to give his [Battlestar Galactica Cylon](https://en.wikipedia.org/wiki/Cylon_(Battlestar_Galactica)) and [KITT](https://en.wikipedia.org/wiki/KITT) robot eyes a sense of sentience. See [Knight Rider](https://en.wikipedia.org/wiki/Knight_Rider_(1982_TV_series)) for the backstory. - -This project uses a 144 pixel/meter LED strip and a Raspberry Pi Pico to produce this effect. - -![Craft Pumpkin](../../img/craft-pumpkin.jpg) -I used a craft pumpkin from Michaels. I cut a slit in it and used hot-glue to hold the LED strip in place. - -## Parts List - -1. 9" Craft Pumpkin from [Micheals](https://www.michaels.com/9-in-orange-craft-pumpkin-by-ashland/10638818.html) $10 -1. Raspberry Pi Pico ($4) -2. Breadboard ($2) -3. 27 pixels of WS2811B NeoPixel Strip [144 pixels per meter preferred](https://www.ebay.com/itm/324452155664?hash=item4b8adb0110:g:-kUAAOSwwT9f9avu) ($8) -4. [3 AA battery pack](https://www.ebay.com/itm/234251696371?hash=item368a7d38f3%3Ag%3AZe8AAOSwTmtaqyvb) or a [USB battery pack](https://www.amazon.com/Compact-5000mAh-External-Portable-More-Black/dp/B09BJGVH17/ref=dp_fod_2?th=1) - -![WS2811b 144](../../img/ws2811b-144.png) -This is a screen image from e-bay showing a 1/2 meter of LED strip for $8. - -## Sample Code - -This code shows a five-pixel wide "eye" moving back-an-forth over a 27 pixel strip. There is a central bright red LED surrounded by dimmer red LEDs that move back-and-forth. We are using the NeoPixel library supplied by [Blaž Rolih](https://github.com/blaz-r/pi_pico_neopixel). - -The example below has a delay of 1/10th of a second between drawing events. You can make the delay smaller to speed up the speed of the eye movement. - -```py -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 27 -STATE_MACHINE = 0 -LED_PIN = 0 - -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0,0,0) - -delay = .1 -while True: - for i in range(2, NUMBER_PIXELS-2): - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - if i > 0: strip.set_pixel(i-3, off) - strip.show() - sleep(delay) - for i in range(NUMBER_PIXELS-4, 1, -1): - if i < NUMBER_PIXELS-2: strip.set_pixel(i+3, off) - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - strip.show() - sleep(delay) -``` - -## Adding Some Color - -The pattern above is faithful to the original Cylon robot pattern, but to be honest, it is a little boring. We can spruce it up a bit by adding some color and the comet-tail pattern. - - - -This program cycles through a "moving rainbow" pattern and then the comet pattern for 10 colors. - -```py -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 25 -STATE_MACHINE = 0 -LED_PIN = 0 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -off = (0,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -def draw_eye_7(r, g, b): - for i in range(6, NUMBER_PIXELS): - strip.set_pixel(i, (r, g, b)) - # step back from the current to 6 back halfing the intensity each time - for j in range(0,7): - strip.set_pixel(i-j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j)))) - if i > 6: strip.set_pixel(i-7, (0,0,0)) - strip.show() - sleep(delay) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-6, 0, -1): - strip.set_pixel(i, (r, g, b)) - for j in range(7,0): - strip.set_pixel(i+j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j)))) - if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0)) - strip.show() - sleep(delay) - -def draw_rainbow(): - for i in range(0, NUMBER_PIXELS-7): - strip.set_pixel(i, violet) - strip.set_pixel(i+1, indigo) - strip.set_pixel(i+2, blue) - strip.set_pixel(i+3, green) - strip.set_pixel(i+4, yellow) - strip.set_pixel(i+5,orange) - strip.set_pixel(i+6, red) - if i > 6: strip.set_pixel(i-7, (0,0,0)) - strip.show() - sleep(delay) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-7, 1, -1): - strip.set_pixel(i, red) - strip.set_pixel(i+1, orange) - strip.set_pixel(i+2, yellow) - strip.set_pixel(i+3, green) - strip.set_pixel(i+4, blue) - strip.set_pixel(i+5, indigo) - strip.set_pixel(i+6, violet) - if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0)) - strip.show() - sleep(delay) - -# delay = .031 - -delay = .06 -color_index = 0 -while True: - draw_rainbow() - draw_eye_7(255,0,0) #red - draw_eye_7(255,60,0) #orange - draw_eye_7(255,255,0) # yellow - draw_eye_7(0,255,0) # green - draw_eye_7(0,0,255) # b;ie - draw_eye_7(0,255,255) # cyan - draw_eye_7(75,30,130) # indigo - draw_eye_7(255,0,255) # violet - draw_eye_7(255,255,255) # white -``` - -## Adding the Cylon Scanner Sounds - -You can also add the Cylon eye scanner sound by addint a .wav file to the pico and using the playWave library. This is covered in the [Sound and Music Play Audio File](../../sound/07-play-audio-file.md) lesson of this microsite. - -## More to Explore - -1. Add a potentiometer to change the speed of the eye scan. -2. Add a button to cycle through colors of the eye. -3. Add multiple patterns such as a "comet trail" that has the first pixel brighter and the following pixels dimmer. -4. Add a PIR motion sensor that will sense motion and get brighter if motion is sensed. -5. Use the new [I2S](https://github.com/miketeachman/micropython-i2s-examples) software to play a sound when the PIR motion sensor has been triggered. -6. Use an MP3 player such as the [DRF0229](https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299) to play the cylon sound when motion is detected. -7. Add an OLED display and buttons to the back of the pumpkin to change the parameters of the display and the sounds. \ No newline at end of file diff --git a/docs/kits/maker-nano-rp2040/01-intro.md b/docs/kits/maker-nano-rp2040/01-intro.md deleted file mode 100644 index ea98e0db9..000000000 --- a/docs/kits/maker-nano-rp2040/01-intro.md +++ /dev/null @@ -1,30 +0,0 @@ -# Cytron Maker Nano RP2040 - -The [Cytron Nano RP2040](https://www.cytron.io/maker-nano-rp2040-simplifying-projects-with-raspberry-pi-rp2040) is a low-cost ($9), high-functionality board. - -## features - -1. Low cost: $9 -2. 14 GPIO blue LEDs -3. 2 RGB LEDs (Neopixels) -4. 1 Piezo buzzer -5. 2 4-wire JST-SH ports (with Grove connectors) - -![](../img/cytron-nano-rp2040-pinout.png) - -## Blink Lab - -```py -from machine import Pin # get the Pin function from the machine module -from time import sleep # get the sleep library from the time module -# this is the built-in green LED on the Pico -led = machine.Pin(0, machine.Pin.OUT) - -# repeat forever -while True: - led.high() # turn on the LED - sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second -``` - diff --git a/docs/kits/maker-pi-pico/02-running-lights.md b/docs/kits/maker-pi-pico/02-running-lights.md deleted file mode 100644 index 886e91ba7..000000000 --- a/docs/kits/maker-pi-pico/02-running-lights.md +++ /dev/null @@ -1,33 +0,0 @@ -# Running lights - -This program turns on all 24 blue LEDs on the board, one at a time. It then turns them all off. - -TODO - record a GIF or video. - -```py -import machine -import utime - -# RUNNING LIGHT - -for i in range(29): # from 0 to 28 - if i != 23 and i != 24: # pin 23 and 24 are not GPIO pins - machine.Pin(i,machine.Pin.OUT) # set the pins to output - -while True: - for i in range(29): - if i != 23 and i != 24: - machine.Pin(i).value(0) # turn off the LED - utime.sleep(0.1) # sleep for 100ms - machine.Pin(i).value(1) # turn on the LED - - for i in range(28,-1,-1): # from 28 to 0 - if i != 23 and i != 24: - machine.Pin(i).value(1) # turn on the LED - utime.sleep(0.1) - machine.Pin(i).value(0) # turn off the LED -``` - -## References - -This program was taken from tje Cytron GitHub site [here](https://github.com/CytronTechnologies/MAKER-PI-PICO/blob/main/Example%20Code/MicroPython/maker-pi-pico-running-light.py). \ No newline at end of file diff --git a/docs/kits/maker-pi-pico/09-micro-sd-card-reader.md b/docs/kits/maker-pi-pico/09-micro-sd-card-reader.md deleted file mode 100644 index 53fe40846..000000000 --- a/docs/kits/maker-pi-pico/09-micro-sd-card-reader.md +++ /dev/null @@ -1,89 +0,0 @@ -# Micro SD Card Reader - -[Secure Digital](https://en.wikipedia.org/wiki/SD_card) (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices. - -On Microcontrollers SD cards are usually access through an [SPI interface](https://en.wikipedia.org/wiki/SD_card#Transfer_modes) although there are also devices that use I2C interfaces. - -## Maker Pi Pico Connections - -| GPIO Pin | SD Mode | SPI Mode | -| -------- | ------- | -------- | -| GP10 | CLK | SCK | -| GP11 | CMD | SDI | -| GP12 | DAT0 | SD0 | -| GP13 | DAT1 | X | -| GP14 | DAT2 | X | -| GP15 | CD/DAT3 | CSn | - -## Maker Pi Pico Example Code - -### Pin Definitions - -```py - -# SD Mode Definitions -SDCARD_CLK = 10 -SDCARD_CMD = 11 -SDCARD_DAT0 = 12 -SDCARD_DAT1 = 13 -SDCARD_DAT2 = 14 -SDCARD_CD_DAT3 = 15 - -# SPI Mode Definitions -SDCARD_SCK = 10 -SDCARD_SDI = 11 -SDCARD_SD0 = 12 -SDCARD_X1 = 13 -SDCARD_X2 = 14 -SDCARD_CSn = 15 -``` - -### Sample Code for SPI Mode - -```py -import machine, os, sdcard - -# Assign chip select (CS) pin (and start it high) -cs = machine.Pin(15, machine.Pin.OUT) -# Intialize SPI peripheral (start with 1 MHz) -spi = machine.SPI(1, - baudrate=1000000, - polarity=0, - phase=0, - bits=8, - firstbit=machine.SPI.MSB, - sck=machine.Pin(10), - mosi=machine.Pin(11), - miso=machine.Pin(12)) -# Initialize SD card -sd = sdcard.SDCard(spi, cs) - -# OR this simpler initialization code should works on Maker Pi Pico too... -#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15)) - -os.mount(sd, '/sd') -# check the content -os.listdir('/sd') - -# try some standard file operations -file = open('/sd/test.txt', 'w') -file.write('Testing SD card on Maker Pi Pico') -file.close() -file = open('/sd/test.txt', 'r') -data = file.read() -print(data) -file.close() -``` - -Results: - -``` -Testing SD card on Maker Pi Pico -``` -## References - -1. [MicroPython sdcard.py driver](https://docs.google.com/document/d/1JoHsZk5IipQPCLXWbZYpDKjGlnkyACOJ1[taUrKVsRg8/edit](https://github.com/micropython/micropython/blob/master/drivers/sdcard/sdcard.py)) - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266 -1. [MicroPython.org Documentation](https://docs.micropython.org/en/latest/library/machine.SDCard.html) -2. [Raspberry Pi Pico Forum](https://forums.raspberrypi.com/viewtopic.php?t=307275) -3. [YouTube Video by Shawn Hymel](https://www.youtube.com/watch?v=u-vmsIr-s7w) -4. [Cytron Maker Pi Pico Datasheet](https://docs.google.com/document/d/1JoHsZk5IipQPCLXWbZYpDKjGlnkyACOJ1taUrKVsRg8/edit) \ No newline at end of file diff --git a/docs/kits/maker-pi-pico/index.md b/docs/kits/maker-pi-pico/index.md deleted file mode 100644 index 19ddc875f..000000000 --- a/docs/kits/maker-pi-pico/index.md +++ /dev/null @@ -1,15 +0,0 @@ -# Cytron Maker Pi Pico - -The Cytron Maker Pi Pico is a $9.99 breakout board for the Raspberry Pi Pico with many features. - -1. Speaker -2. Stereo headphone jacks -3. SD Card reader - -## Sample Labs - -1. [Running Lights](02-running-lights.md) -2. [SD Card File Reader/Writer](09-micro-sd-card-reader.md) - -## References -[Cytron Maker Pi Pico Github Repo](https://github.com/CytronTechnologies/MAKER-PI-PICO/tree/main/Example%20Code/MicroPython) \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/02-assembly.md b/docs/kits/maker-pi-rp2040-robot/02-assembly.md deleted file mode 100644 index 73d7ddc12..000000000 --- a/docs/kits/maker-pi-rp2040-robot/02-assembly.md +++ /dev/null @@ -1,105 +0,0 @@ -# Assembling Your Maker Pi RP2040 Robot - -This kit is a $25 robot kit that we will use in our CoderDojo robotics classes. This kit includes: - -1. A SmartCar Chassis - 1. Two 3 to 6-volt DC geared hobby motors and wheels - 2. Plexiglass (acrylic) main-board - 3. Screws and nuts - 4. 4 AA battery pack - 5. Power switch -2. Cytron Maker Pi RP2040 kit - 1. Maker Pi RP2040 board - 2. 4x Grove to female header cables - 3. Screwdriver - 4. Silicone rubber feet (pack of 4) -3. Ultrasonic sensor - 1. mounting bracket - 2. 2 M2 6mm screws and nuts - -You will need to provide 4 AA batteries and a Micro USB connector that works with your PC or Mac. - -## Assemble the SmartCar Chassis - -In this version of the kit, the wires are pre-soldered onto the motors. - -Here is the robot kit in all the packaging: -![](../../img/IMG_0146.jpg) - -Your first task is to remove the protective backing from the acrylic body. -![](../../img/IMG_0151.jpg) - -Here are all the parts removed from the packaging: -![](../../img/IMG_0153.jpg) - -We mount the motors with the wires on the inside and the heads of the bolts on the outside. -![](../../img/IMG_0162.jpg) -This photo shows cable ties I have added so that the wires don't get pulled out by our students. These cable ties are optional. - -Next, we position the battery pack on the BOTTOM so that we have more room on the top for our circuit board, sensors and add-on displays. - -![](../../img/IMG_0163.jpg) - -I used a 1/8th inch drill bit to put holes where the battery pack should be mounted. -![](../../img/IMG_0164.jpg) - -Next, I put the flat-head screws in the battery pack. We want to make sure the top of the screw is all the way in so that it does not get in the way of the battery. -![](../../img/IMG_0166.jpg) - -Next, we mount the rubber feet on the bottom of the Maker Pi RP2040 circuit board so that we have some space between the PC board and the main chassis. I use the space next to the four corners to mount the feet. Note that we must put the drag wheel on before we put the PC board on top of the chassis. -![](../../img/IMG_0167.jpg) - -Next, we put the four screws and spacers in the four holes at the bottom rear of the robot directly behind the battery pack. -![](../../img/IMG_0172.jpg) - -We then add the four screws to mount the drag wheel. -![](../../img/IMG_0173.jpg) - -Now is a good time to check the spacing of the battery pack and the read drag wheel. The rear drag wheel must be able to spin freely in a full circle without bumping into the battery. If it bumps you might need to remount the battery pack before you proceed to the next step. -![](../../img/IMG_0174.jpg) - -This figure has the switch that comes with the battery pack. For our work, we will not need this switch since the Maker Pi RP2040 circuit board has an no-board power switch. Most of our students put the switch in if they ever need to change circuit boards that don't have a built-in power switch. If you do this, you can solder the switch between the red power of the battery and the positive terminal of VIN. -![](../../img/IMG_0175.jpg) - -Next, line up the printed circuit board with the USB connector facing the rear. Note where the holes are in the board and drill two 1/8" holes to mount the board. -![](../../img/IMG_0169.jpg) - -This photo shows the holes drilled with the screws in them. -![](../../img/IMG_0170.jpg) - -This is the side-view from the rear of the screws holding on the circuit board. -![](../../img/IMG_0176.jpg) - -Next use two 6 mm M3 screws to mount the ultrasonic distance sensor on top front of the robot. -![](../../img/IMG_0180.jpg) -Some of our students like to mount the ultrasonic sensor under the chassis and point the sensor up a little so the sensor does not reflect off the floor. You can use a heat gun to soften the plastic mount to change the angle. - -Next I added a drop of hot-glue under the front screws that mount the pc board. I did this because the battery pack and motor mounts get in the way of adding a nut under the board. -![](../../img/IMG_0182.jpg) - -Next, I used a small rubber coated twist tie to keep the wires under the robot away from the wheels and battery. We don't want them to drag on the floor. -![](../../img/IMG_0185.jpg) - -![](../../img/maker-pi-rp2040-robot-bottom.jpg) - -Next, we connect the motors up to the screw headers on the printed circuit board. There is a screwdriver that comes with the Cytron Maker Pi RP2040 that is handy for tightening the screws. -![](../../img/IMG_0178.jpg) -Don't worry about getting the connections all correct. They can be adjusted in your software. - -Press the wheels on the motors. -![](../../img/IMG_0181.jpg) - -Lastly, we connect the battery to the VIN jumper, making sure to connect the red wire to the "+" terminal and the black wire to the "-" terminal. -![](../../img/IMG_0186.jpg) - -Connect the Maker Pi RP2040 board to the top with the USB connector facing the rear. - - ![Maker Pi RP2040 Motor Connections](../../img/maker-pi-rp2040-motor-connections.jpg) - -Here is a short video of the assembly of a SmartCar Chassis. Note that this video puts the battery on the top, where we put it on the bottom. - - - -![](../../img/maker-pi-rp2040-robot-bottom.jpg) -There are many videos online how to assemble to motors to the chassis. The trick is orienting the motors correctly and making sure the bolts don't get in the way of the wheels. - diff --git a/docs/kits/maker-pi-rp2040-robot/06-up-down-motor-lab.md b/docs/kits/maker-pi-rp2040-robot/06-up-down-motor-lab.md deleted file mode 100644 index a9efd8d34..000000000 --- a/docs/kits/maker-pi-rp2040-robot/06-up-down-motor-lab.md +++ /dev/null @@ -1,178 +0,0 @@ -# Up Down Motor Speed Lab - -In this lab, we will make the motor speed change as the mode changes. - - - -```py -# Motor Setup -# motors just barely turn at this power level -MIN_POWER_LEVEL = 10000 -MAX_POWER_LEVEL = 65025 -POWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10) -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def drive_speed(power_level): - right_forward.duty_u16(power_level) - left_forward.duty_u16(power_level) -``` - -In the main we have: - -```py -power_level = MIN_POWER_LEVEL + mode * POWER_STEP -# turn off the motor if we are at mode 0 -if mode == 0: power_level = 0 -drive_speed(power_level) -``` - -## Full Program - -```py -# Mode Up/Down Lab -# Change a mode using the buttons on the Maker Pi RP2040 board -# Changes the NeoPixel color and the blue GPIO status LEDs -import time -from machine import Pin, PWM -# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -BUZZER_PORT = 22 -buzzer = PWM(Pin(BUZZER_PORT)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") - -# have up to 13 that we can use -blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28] -number_leds = len(blue_led_pins) -led_ports = [] -# create a list of the port pin object instances -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Color RGB values as tuples - needs some Gamma corrections -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -# Motor Setup -# motors just barely turn at this power level -MIN_POWER_LEVEL = 10000 -MAX_POWER_LEVEL = 65025 -POWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10) -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def drive_speed(power_level): - right_forward.duty_u16(power_level) - left_forward.duty_u16(power_level) - -mode = 0 # the default mode on powerup and reset -mode_count = len(color_names) -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# Give our pins some logical names -next_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -previous_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time, power_level - new_time = time.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - mode +=1 - # power_level += POWER_STEP - else: - mode -=1 - # power_level -= POWER_STEP - # wrap around to first mode - if mode >= mode_count: mode = 0 - if mode < 0: mode = mode_count - 1 - last_time = new_time - -def set_blue_led_mode(mode): - global num_colors - for i in range(0, num_colors): - if i == mode: - led_ports[i].high() - else: - led_ports[i].low() - -# Register the handler function when either button is pressed -next_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -previous_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# non-linear increase is frequency - note that some are lowder -tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000] -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -# This is for only printing when a new button press count value happens -old_mode = -1 - -power_level = MIN_POWER_LEVEL -print('found ', mode_count, ' modes.') -while True: - # only print on change in the button_presses value - if mode != old_mode: - print('new mode:', mode, color_names[mode], tone_freq[mode], power_level) - # get the color mode - color = colors[mode] - strip.set_pixel(0, color) - strip.set_pixel(1, color) - strip.show() - set_blue_led_mode(mode) - playtone(tone_freq[mode]) - time.sleep(.2) - bequiet() - power_level = MIN_POWER_LEVEL + mode * POWER_STEP - # turn off the motor if we are at mode 0 - if mode == 0: power_level = 0 - drive_speed(power_level) - old_mode = mode -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/07-motor-connection-lab.md b/docs/kits/maker-pi-rp2040-robot/07-motor-connection-lab.md deleted file mode 100644 index 4ce176e03..000000000 --- a/docs/kits/maker-pi-rp2040-robot/07-motor-connection-lab.md +++ /dev/null @@ -1,73 +0,0 @@ -# Motor Drive Connection Test - -## Built-In Motor Driver - -The Maker Pi RP2040 board contains a MX1508 dual channel H-bridge chip and easy-to-connect screw headers for power and motor connections. This is fantastic for teaching robotics since students can driver two motors without ever having to use a soldering iron. - -!!! Note that the is designed to work with small DC-hobby motors and there is no documentation on exactly what motor driver chip is used or its precise current and power limitations. - -The documentation only indicates that the maximum current is 1A continuous power and 1.5A for up to 5 seconds. The input voltage is only rated at 6 volts, which find for our standard 4 AA battery packs. - -If this motor driver chip is similar to the ubiquitous [L293x motor controllers](https://www.ti.com/document-viewer/L293D/datasheet/specifications#ESD_Rating_1), and the current should be 1A per motor. - -I suspect that if you glued a small [heat sink](https://en.wikipedia.org/wiki/Heat_sink) like a [16 pin DIP fin](https://my.element14.com/fischer-elektronik/ick-14-16-b/heat-sink-dip-glue-on-50-c-w/dp/4620896) to the unknown motor driver IC on the main board you could drive slightly larger motors. - -![Maker Pi RP2040 Motor Driver Chip](../../img/maker-pi-rp2040-motor-driver.jpg) -Close-up of the motor driver chip. I can't quite make out the numbers on the chip, but the logo is not "TI". -## Testing The Connections - -In our standard robot, the M1 is the right wheel as you are looking from the top-back of the robot. The M2 wheel is the left wheel. I connect the red to the right of the two connectors and it is also the right terminal of the motors as you are looking from the rear. - -Look at the buttons near the motor connectors. Press the M1A button and verify that the right wheel -is moving forward. Press the M1B and the motor should turn in reverse. Similarly the M2B button should turn the left wheel forward and the M2A should turn the left wheel in reverse. If you don't wire these connections the same way I did it is not a worry. It is easy to change the code. - -## Motor Pin Definitions - -Now that we know what buttons control what motors and directions they turn, we are ready to define the pins that are associated with each robot movement. We have four pin assignments: both forward and reverse for both the right and left motors. - -```py -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -``` - -## Testing Your Pin Definitions - -The following program is called our motor connection test. It will turn each motor direction for three seconds and it will print out the motor and direction in the console. - -```py -from machine import Pin, PWM -import time - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -``` diff --git a/docs/kits/maker-pi-rp2040-robot/07b-drive-square-lab.md b/docs/kits/maker-pi-rp2040-robot/07b-drive-square-lab.md deleted file mode 100644 index f669e0b4a..000000000 --- a/docs/kits/maker-pi-rp2040-robot/07b-drive-square-lab.md +++ /dev/null @@ -1,148 +0,0 @@ -# Drive Square Lab - -## Prerequsites - -This lab assumes you have your Maker Pi RP2040 mounted on a SmartCar chassis with two motors and a battery hooked up. - -In this lab we will program our robot to drive in a square pattern. We will start out doing a "bench test" that will require you to put the robot up on a block so you can see the wheels turn, but it will not drive off your desktop. You can also observe the red LED lights on the many board to see which motor direction is on. - -The main loop will look like this: - -```py -while True: - forward() - sleep(FWD_TIME) - - stop() - sleep(STOP_TIME) - - turn_right() - sleep(TURN_TIME) - - stop() - sleep(STOP_TIME) -``` - -We will need to adjust the TURN_TIME parameter to have the robot turn 90 degrees. A good value for most robots is about 1/2 second or sleep(.5). - -Since we will be calling the sleep function many times we will use the following import format to keep our code tidy: - -```py -from utime import sleep -``` -This says that whenever we want to pause our system we just use the ```sleep(time)``` function we mean to use the sleep function in the micropython time library. This keeps our code small and portable. - - -## Adding a Keyboard Interrupt Handler (Control-C) - -It is also a problem that when we stop a program running that the PWM circuits keep generating signals, which means the robot keeps moving even after we press the STOP/RESET button. To clean this up we will allow you to run a special cleanup handler that will add a function to set all the motors to off using the ```stop()``` function. - -```py -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() -``` - -## Full Program - -You are now ready to test the full program. Save the following to the main.py file, disconnect the USB connector and turn on the power on the main board. Your robot should not we driving in a square! - -```py -from machine import Pin, PWM -from utime import sleep - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -FWD_TIME = 2 -TURN_TIME = .5 # adjust this to get the turn to be 90 degrees -STOP_TIME = 2 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -print('Running Drive Square Lab') -print('Use Control-C to Stop All Motors') - -def main(): - while True: - print('forward') - forward() - sleep(FWD_TIME) - - print('stop') - stop() - sleep(STOP_TIME) - - print('turning right') - turn_right() - sleep(TURN_TIME) - - print('stop') - stop() - sleep(STOP_TIME) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/08-servo-lab.md b/docs/kits/maker-pi-rp2040-robot/08-servo-lab.md deleted file mode 100644 index 96ce04d15..000000000 --- a/docs/kits/maker-pi-rp2040-robot/08-servo-lab.md +++ /dev/null @@ -1,217 +0,0 @@ -# Maker Pi RP2040 Servo Lab - -Servo motors are ideal for controlling the angle of an item such as a steering angle or the direction of a sensor. The servos used in these labs are inexpensive SG90 micro-servos that draw very little power and are ideal for a teaching lab. They can be purchased for about [$3 each US on eBay](https://www.ebay.com/sch/i.html?_from=R40&_nkw=SG90+micro+servos&_sacat=0&rt=nc&LH_BIN=1). To control a 180 degree servo, you just tell it what angle you would like it to move to. The range of values is typically -90 to 90 degrees with 0 being the nominal resting position for many applications such as the steering wheel angle of a car. - -The Maker Pi RP2040 has four servo ports in the upper left corner of the board (with the USB on the bottom) that use ports GP12, GP13, GP14 and GP15. You can connect any small micro servo directly to these ports. Just make sure to get the polarity correct. The colors for servos may vary somewhat, but the two most common standards are: - -* Orange, red and brown - signal, positive and ground -* White, red, black - signal, positive and ground - -The general rule is that the lighter colors of orange and white will be the signal and the brown and black will be ground. - -## Servo Control - -We will use the PWM functions in our MicroPython library to send a PWM signal to each of the servos. Servos are not controlled by the duty cycle directly. They are controlled by the width of the pulses. But we can control the approximate with of the pulses by holding the frequency constant and changing the duty cycle. - -We will use a 40 hertz signal to send a PWM signal to each of the servos like this. - -```py -SERVO_FREQ_HZ = 40 -# SERVO_PERIOD_MS = 1000 / SERVO_FREQ_HZ is a 25 millisecond pulse width -my_pwm.freq(SERVO_FREQ_HZ) -``` - - -## Calibration of the Servo -There are small manufacturing variations in servos. This means to get the full sweep of a 180% servo you have to adjust the duty cycle. - -* Minimum duty cycle: 1700 -* Maximum duty cycle: 6300 - -By some experimentation I got the following results -```py -SERVO_MIN_DUTY = 1725 # -90 degrees -SERVO_MAX_DUTY = 6378 # 90 degrees -``` - -We can use a linear mapping function to convert the angle (from -90 to 90): - -```py -# This will take in integers of range in (min and max) return a integer in the output range (min and max) -# Used to convert one range of values into another using a linear function like the Arduino map() function -def convert(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min - -angle = 0 -duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY) -print('For angle: ', angle, ' the duty is: ', duty) -pwm.duty_u16(duty) -``` - -## Checking your Servo Calibration with Buttons -We can also use the buttons on the Maker Pi RP2040 to verify that the extreme angles are correct. One button will increase the angle and one will decrease the angle. - -```py -# Maker Pi RP2040 program to check the limits of a 180 degree servo such as a SG90 micro servo -from machine import Pin, PWM -import time - -BUTTON_1_PIN = 20 # increment the angle -BUTTON_2_PIN = 21 # decrement the angle - -SERVO_1_PIN = 12 -SERVO_2_PIN = 13 # MAX=5749@40 -SERVO_3_PIN = 14 -SERVO_4_PIN = 15 -# this is ususlly standard across most servos -SERVO_FREQ_HZ = 40 - -pwm = PWM(Pin(SERVO_2_PIN)) - -# the two button on the Maker Pi RP2040 -increment_angle_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -decrement_angle_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - -# return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 ) -# This will take in integers of range in (min and max) return a integer in the output range (min and max) -# Used to convert one range of values into another using a linear function like the Arduino map() function -def convert(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min - -# globals -angle = -90 -last_time = 0 # the last time we pressed the button - -# if the pin is 20 then increment, else decement -def button_pressed_handler(pin): - global angle, last_time - new_time = time.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - angle +=1 - else: - angle -=1 - last_time = new_time - # now we register the handler function when the button is pressed -increment_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -decrement_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -pwm.freq(SERVO_FREQ_HZ) -old_angle = -1 - -while True: - # only print on change in the button_presses value - if angle != old_angle: - duty = ServoDuty(angle) - print('new angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle -``` - -## Sample Sweep Code - -```py -from machine import Pin, PWM -import time - -BUTTON_1_PIN = 20 -BUTTON_2_PIN = 21 - -SERVO_1_PIN = 12 -SERVO_2_PIN = 13 -SERVO_3_PIN = 14 -SERVO_4_PIN = 15 -SERVO_FREQ_HZ = 50 -SERVO_MIN_DUTY = 1725 -SERVO_MAX_DUTY = 6378 -# this is ususlly standard across most servos -SERVO_FREQ_HZ = 40 - -pwm = PWM(Pin(SERVO_2_PIN)) - -# the two button on the Maker Pi RP2040 -clock_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -counter_clock_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# globals -angle = 90 -last_time = 0 # the last time we pressed the button - -def button_pressed_handler(pin): - global angle, last_time - new_time = time.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - angle +=1 - else: - angle -=1 - # wrap around to first mode - if mode >= mode_count: mode = 0 - if mode < 0: mode = mode_count - 1 - last_time = new_time - -# now we register the handler function when the button is pressed -clock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -counter_clock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -# return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 ) - -# Thisw will take in integers of range in (min and max) return a integer in the output range (min and max) -# Used to convert one range of values into another using a linear function like the Arduino map() function -def convert(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min - -# -90 should generate 1725 -# 90 should generate 7973 - -old_angle = -1 - -pwm.freq(50) -while True: - for angle in range(-90, 90): - duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY) - print('angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle - time.sleep(.01) - for angle in range(90, -90, -1): - duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY) - print('angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle - time.sleep(.01) -``` - -## Shutting Down All Servos - -```py -from machine import Pin, PWM -import time - -SERVO_1_PIN = 12 -SERVO_2_PIN = 13 -SERVO_3_PIN = 14 -SERVO_4_PIN = 15 - -print('shutting down all servos!') -for i in range(12, 16): - print('Servo', i, 'shutting down') - pwm1 = PWM(Pin(SERVO_1_PIN)) - pwm1.duty_u16(0) -``` - -## Adding Cleanup Code - -PWM signals continue to be generated even after you do a STOP/RESET on your microcontroller. This could drain batteries and wear out your servo motors. To stop the servos from getting PWM signals you can add an interrupt to your code to catch these signals and set the PWM duty cycle back to zero. This - -```py - -``` - -## References - -[MicroPython Reference Page](https://docs.micropython.org/en/latest/pyboard/tutorial/servo.html) - this page is not very helpful. The implication is that servo controls are standardized across MicroPython system. This does not appear to be the case. \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/09-i2c-scanner-test.md b/docs/kits/maker-pi-rp2040-robot/09-i2c-scanner-test.md deleted file mode 100644 index 140bee79a..000000000 --- a/docs/kits/maker-pi-rp2040-robot/09-i2c-scanner-test.md +++ /dev/null @@ -1,44 +0,0 @@ -# I2C Scanner Test - -How do we know that our connection to the distance sensor is wired correctly? The quick way to test this is to run a program called the I2C scanner. It will return a list of all the devices it finds on the I2C bus. - -We first run the I2C scanner program to verify that the sensor is connected correct and is responding to the I2C bus scan. - -```py -import machine -# Pins on the Grove Connector 1 on the Maker Pi RP2040 are GP0 and GP1 -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("I2C device ID list:", i2c.scan()) -``` - -This should return a list of the devices it finds. If you just have the Time-of-Flight sensor it will look like this: - -``` -[41] -`` - -```py -device_id = i2c.scan()[0] -``` - -## Testing for the Time-of-Flight Sensor - -```py -import machine -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -device_id = i2c.scan()[0] -print("Device found at decimal", device_id) - -if device_id == 41: - print("TEST PASS") -else: - print("No device found at decimal 41") - print("TEST FAIL") -``` diff --git a/docs/kits/maker-pi-rp2040-robot/10-time-of-flight-lab.md b/docs/kits/maker-pi-rp2040-robot/10-time-of-flight-lab.md deleted file mode 100644 index f3d879abb..000000000 --- a/docs/kits/maker-pi-rp2040-robot/10-time-of-flight-lab.md +++ /dev/null @@ -1,124 +0,0 @@ -# Time of Flight Distance Sensor Lab - -In this lab we create a program that will show the distance measured by the Time-of-Flight sensor by printing the distance on the console and also displaying the distance on 11 blue LEDs. - -First, make sure you have your driver for the Time-of-Flight sensor installed. - -You can copy the code from [here](https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py) and save it in the file VL53L0X.py. Note the zero between the "L" and "X" in the file name, not the letter "O". - -We use a non-linear distance scale as we get closer to an object. We store the numbers of each LED and the distance it should change in a lists: - -```py -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -dist_scale = [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150] -``` - -## Calibration - -There are three numbers you can change when you calibrate the sensor: - -```py -ZERO_DIST = 60 # The value of the sensor when an object is 0 CM away -MAX_DIST = 1200 # max raw distance we are able to read -SCALE_DIST = .3 # multiplier for raw to calibrated distance in CM -``` - -## Full Program - -```py -# Demo for Maker Pi RP2040 board using the VL32L0X time of flight distance sensor -# Note the driver I used came from here: https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py -# Perhaps derived from here: https://github.com/uceeatz/VL53L0X/blob/master/VL53L0X.py - -# This demo makes the blue LEDs show the distance and prints the distance on the console -import machine -import time -import VL53L0X - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs which we can use 11 -# The distance scale is non linear -# GP0 and GP1 will always be on since they are the I2C Data and Clock -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -dist_scale = [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150] -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# initial calibration parameters -ZERO_DIST = 60 -MAX_DIST = 1200 # max raw distance we are able to read -SCALE_DIST = .3 # multiplier for raw to calibrated distance - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > MAX_DIST: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < ZERO_DIST: - zero_dist = tof_distance - return int((tof_distance - ZERO_DIST) * SCALE_DIST) - -# use the dist_scale to turn on LEDs -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -print('Using', number_leds, ' blue leds to show distance.') - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# start our time-of-flight sensor -tof.start() -# autocalibrate the minimum distance -min_distance = 1000 - - -# loop forever -while True: - raw_distance = get_distance() - # recalibrate if we have a new min distance - if raw_distance < min_distance: - min_distance = raw_distance - calibrated_distance = raw_distance - min_distance - print(raw_distance, calibrated_distance) - led_show_dist(calibrated_distance) - time.sleep(0.05) - -# clean up -tof.stop() - -``` - -## References - -[Kevin McAleer's GitHub Repo on the Vl53lx0](https://github.com/kevinmcaleer/vl53lx0) -[Kevin McAleer's 662 line driver](https://github.com/kevinmcaleer/vl53lx0/blob/master/vl53l0x.py) - I am not sure we need all 662 lines of code. -[Kevin McAleer's Time of Flight Test](https://github.com/kevinmcaleer/vl53lx0/blob/master/tof_test.py) \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/11-ping-lab.md b/docs/kits/maker-pi-rp2040-robot/11-ping-lab.md deleted file mode 100644 index c313694f8..000000000 --- a/docs/kits/maker-pi-rp2040-robot/11-ping-lab.md +++ /dev/null @@ -1,108 +0,0 @@ -# Ultrasonic Ping Sensor Lab - -The Grove sensors on our Maker Pi RP2040 only supply 3.3 volts. So the standard very popular low cost HC-SR04 will not work, since it requires 5 volts of power. We have two options. One is to get a separate 5V power source, but the other is to purchase the new HC-SR04**P** (for Pico?) sensor that will work with our 3.3 volt power on our Grove connector. - -Using the Grove 4 connection wire the HC-SP04P sensor with the trigger on GPIO-16 (White cable) and the echo on GPIO-17 (Yellow cable), VCC (Red cable), and GND (Black cable) - -![Ultrasonic Sensor](../../img/HC-SP04P_Grove.jpg) - -All wired up - -![Maker Pi RP2040 with sensor](../../img/Maker_Pi_RP2040-Ping.jpg) - -``` -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), "cm") - utime.sleep(.25) - -``` - -More advanced version with sound - -``` -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer, PWM -import utime - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -BUZZER_PORT = 22 -buzzer = PWM(Pin(BUZZER_PORT)) - -# Note the non-linear increases in frequency - note that some are louder -tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000] -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - dist=round(ping()) - print("Distance:", dist, "cm") - if dist < 20: - print("Panic") - playtone(350) - # Beep faster the closer you get - utime.sleep(.05/(20/dist)) - bequiet() - utime.sleep(.1) - -``` - - -## Link to Sample Ping Lab -This code is very similar to the previous ping lab but with the different GPIO lines used. - -[Link to Standard Ping Lab](../../sensors/03-ping.md) diff --git a/docs/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab.md b/docs/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab.md deleted file mode 100644 index 74a31581d..000000000 --- a/docs/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab.md +++ /dev/null @@ -1,120 +0,0 @@ -# Time of Flight Distance Sensor Test - -```py -# Demo for Maker Pi RP2040 board - -from machine import Pin,PWM -import time -import VL53L0X -buzzer=PWM(Pin(22)) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn(): - playtone(500) - time.sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - while True: - global valid_distance - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - - valid_distance = 0 - else: - print(distance) - if distance < 30: - play_turn() - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - tof.stop() -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot.md b/docs/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot.md deleted file mode 100644 index a0c45c61e..000000000 --- a/docs/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot.md +++ /dev/null @@ -1,210 +0,0 @@ -# Maker Pi RP2040 Collision Avoidance Robot - -This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board. - -The board is mounted on a SmartCar Chassis and Grove Connector 0 is used to connect to a Time-of-Flight distance sensor that is using the I2C bus. - -## Random Turn Direction - -```py -if dist < TURN_DIST: - play_reverse() - reverse() - sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - play_turn_right() - else: - turn_left() - play_turn_left() - sleep(TURN_TIME) - forward() -``` - - -```py -# Demo for Maker Pi RP2040 board - -from machine import Pin,PWM -from time import sleep, sleep_ms -import urandom -import VL53L0X - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# this is the max power level -POWER_LEVEL = 65025 - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# Time of flight sensor is on the I2C bus on Grove connector 0 -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn(): - playtone(500) - sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < 30: - play_turn() - # back up for 1/2 second - reverse() - sleep(0.5) - turn_right() - sleep(0.75) - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('powering down all motors') - stop() - print('stopping time of flight sensor') - tof.stop() -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping.md b/docs/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping.md deleted file mode 100644 index a7b8dc149..000000000 --- a/docs/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping.md +++ /dev/null @@ -1,305 +0,0 @@ -# Maker Pi RP2040 Collision Avoidance Robot With Ping Sensor - -This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board. - -The board is mounted on a SmartCar Chassis and Grove Connector 4 is used to connect -the ultrasonic ping sensor. Connect the Trigger on white and Echo on yellow. The black should be connected to GND and the Red is connected to the VCC which on the - -The robot has an initial mode of 0, which will run the blue LEDs and change colors on the Neopixels. By pressing the on-board button you will start the collision avoidance program. - -## Robot Parameters - -There are four different robot parameters you can adjust. They change the speed and distance before the robot backs up. You can also adjust the time the robots goes into reverse and the time it turns. - -```py -POWER_LEVEL = 35000 # max is -TURN_DISTANCE = 20 # distance in cm we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -``` -## Full Source Code - -```py -# Demo for Maker Pi RP2040 board using Ping sensor -from machine import Pin, PWM, Timer -import utime -import urandom -from neopixel import Neopixel - -# Adjust these parameters to tune the collision avoidance behavior - -POWER_LEVEL = 35000 -TURN_DISTANCE = 20 # distance we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn - -# startup mode is 0 - motors off and LEDs flashing -# mode 1 is slow -# mode 2 is medium -# mode 3 is fast -mode = 0 - -# Use the Grove 4 Connector and put trigger on white and echo on yellow -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -# Init HC-SR04P pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -last_time = 0 # the last time we pressed the button - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - mode +=1 - else: - mode -=1 - # deal with ends - if mode > 4: mode = 2 - if mode < 0: mode = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -MAX_POWER_LEVEL = 65025 - -MAX_DISTANCE = 100 # ignore anything above this - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# returns distance in cm -def ping(): - print('in ping') - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - print('echo is 1') - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - print(distance) - return int(distance) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 16 and 17 since the are used for the ping sensor -blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -number_leds = len(blue_led_pins) -led_ports = [] -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def play_no_signal(): - playnote(100, 0.1) - sound_off() - -def play_turn(): - playnote(500, .1) - sound_off() - -def setfreq(frequency): - buzzer.freq(frequency) - -def playnote(frequency, time): - buzzer.duty_u16(1000) - setfreq(frequency) - utime.sleep(time) - -def sound_off(): - buzzer.duty_u16(0) - -def rest(time): - buzzer.duty_u16(0) - utime.sleep(time) - -def play_startup(): - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.1) - playnote(800, .4) - sound_off() - -valid_distance = 1 -# loop forever -def main(): - global valid_distance - print("running main()") - - play_startup() - - while True: - if mode == 0: - stop() - run_lights() - else: - distance = ping() - print('Distance:', distance) - if distance > MAX_DISTANCE: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < TURN_DISTANCE: - play_turn() - # back up for a bit - reverse() - utime.sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - else: - turn_left() - utime.sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - utime.sleep(0.05) - -# clean up - -# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('shutting motors down') - stop() - -``` - -## Experiments - -1. Adjust the power level and the distance before turning. See how these change the performance of the robot. -2. Adjust the angle of the ping sensor by gently heating the plexiglass holder. How does this change the robot behavior? -3. Add additional modes that change the power and the turn distance. You can have one mode for slow, one for medium and one for fast. -4. Change the Neopixel colors to indicate the distance to an object. -5. Change the pattern of the blue LEDs to indicate the distance to the object. \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/23-microswitch-bot.md b/docs/kits/maker-pi-rp2040-robot/23-microswitch-bot.md deleted file mode 100644 index 8965490b0..000000000 --- a/docs/kits/maker-pi-rp2040-robot/23-microswitch-bot.md +++ /dev/null @@ -1,179 +0,0 @@ -# MicroSwitch Robot using the Cytron Maker Pi RP2040 - -This robot was inspired by my friend, Michael York. - - - -Microswitches can be purchased for [under $1](https://www.amazon.com/Twidec-Straight-Switch-Action-KW11-3Z04/dp/B07P4CJ8TV/ref=sr_1_3). They can be mounted on the front of our robot. When the robot hits a wall in front of it the switch will open (or close) and the robot controller can make the robot go in reverse or turn. - -In the example below, we attached a stiff wire to the lever of the microswitch. - -![](../../img/microswitch-bot-2.jpg) - - - -In the example below, we connected three microswitches to the front of our robot. - -![](../../img/microswitch-bot-1.jpg) - -If the left switch is activated, the robot should turn to the right. If the right switch is activated, the robot should go to the left. - -This image shows how we used two of the Grove connectors to read in the values of the switches. - -![](../../img/microswitch-bot-3.jpg) - -## Testing Switches -The following code can be used to test your switches. A line on the console prints out which of the three switches are activated using the pin ```value()``` function. - -```py -from machine import Pin -from time import sleep - -# GPIO is the internal built-in LED -led0 = Pin(0, Pin.OUT) -led1 = Pin(1, Pin.OUT) -led2 = Pin(2, Pin.OUT) - -# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating -middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) -right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN) -left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN) - -while True: - if middle_switch.value(): # if the value changes - led0.on() - print('middle') - else: led0.off() - - if right_switch.value(): # if the value changes - led1.on() - print('right') - else: led1.off() - - if left_switch.value(): # if the value changes - led2.on() - print('left') - else: led2.off() - sleep(.1) -``` - -## Sample Collision Avoidance Robot Code - -```py -from machine import Pin, PWM -from time import sleep - -# GPIO is the internal built-in LED -led0 = Pin(0, Pin.OUT) -led1 = Pin(1, Pin.OUT) -led2 = Pin(2, Pin.OUT) - -# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating -middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) -right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN) -left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN) - -# Go slow to avoid bending wires -POWER_LEVEL = 25000 # max is 65000 - -# These values depend on motor wiring -RIGHT_FORWARD_PIN = 10 -RIGHT_REVERSE_PIN = 11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -def main(): - while True: - if middle_switch.value(): # if the value changes - print('middle') - led0.on() - reverse() - sleep(1) - turn_right() - sleep(.75) - forward() - else: - led0.off() - forward() - - if right_switch.value(): # if the value changes - print('right') - led1.on() - reverse() - sleep(.75) - turn_left() - sleep(.5) - forward() - else: - led1.off() - forward() - - if left_switch.value(): # if the value changes - led2.on() - print('left') - reverse() - sleep(.75) - turn_right() - sleep(.5) - forward() - else: - led2.off() - forward() - -print('middle', middle_switch.value()) -print('left', left_switch.value()) -print('right', right_switch.value()) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - # sound_off() - print('turning off motors') - stop() - -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/24-ping-servo-meter.md b/docs/kits/maker-pi-rp2040-robot/24-ping-servo-meter.md deleted file mode 100644 index e671ee182..000000000 --- a/docs/kits/maker-pi-rp2040-robot/24-ping-servo-meter.md +++ /dev/null @@ -1,512 +0,0 @@ -# Cytron Maker Pi RP2040 Ping Servo Meter Bot - -This robot works very similar to our standard CoderDojo Collision Avoidance Robot. However it adds a 180 degree servo to show the distance to the object in front of it. It also uses a OLED display to present instructions and display the distance to the object. - -This program was contributed by [Joe Glenn](https://www.linkedin.com/in/jeglenn/) for the Minneapolis Bakken Museum Droid December event in December 2021. - -![](../../img/ping-servo-meter-bot.jpg) - -## Test Servo - -This program tests the servo by sweeping the angle from 0 to 180 and back. - -```py -# servo sweep test -# Brown: GND -# Orange/Red : VCC -# Yellow: Signal -# -# Time for high level (Radio Shack Micro-servo @ 5V) -# 0.5 ms : 0 degree -# 1.0 ms : 45 degree -# 1.5 ms : 90 degree -# 2.0 ms : 135 degree -# 2.5 ms : 180 degree - -from machine import Pin, PWM -from time import sleep - -SERVO_PIN = 15 -servoPin = PWM(Pin(SERVO_PIN)) -servoPin.freq(50) - -def servo(degrees): - if degrees > 180: degrees=180 - if degrees < 0: degrees=0 - maxDuty=8000 # duty*100 - minDuty=2000 # duty*100 - #maxDuty=2000 # test - #minDuty=8000 # test - newDuty=minDuty+(maxDuty-minDuty)*(degrees/180) - servoPin.duty_u16(int(newDuty)) - -while True: - - for degree in range(0,180,1): - servo(degree) - sleep(0.01) - print("increasing -- "+str(degree)) - - for degree in range(180, 0, -1): - servo(degree) - sleep(0.01) - print("decreasing -- "+str(degree)) -``` - -## Main Python Code - -```py -# Demo for Maker Pi RP2040 board using Ping sensor, servo and i2c display - -from machine import Pin, PWM, Timer -import utime -import urandom -from ssd1306 import SSD1306_I2C -from neopixel import Neopixel -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -import framebuf -import math -import utime -# -# Ping Sensor -# Use the Grove 4 Connector and put trigger on white and echo on yellow -# -PING_TRIGGER_PIN = 7 # GP7 -PING_ECHO_PIN = 28 # GP28 - -# -# i2c OLED 128x32 -# -OLED_SDA_PIN = 26 # GP26 -OLED_SCL_PIN = 27 # GP27 - -# -# Servo -# GND: Brown -# VCC: Orange/Red -# GP15 Yellow: Signal -# -# Time for high level (Radio Shack Micro-servo @ 5V) -# 0.5 ms : 0 degree -# 1.0 ms : 45 degree -# 1.5 ms : 90 degree -# 2.0 ms : 135 degree -# 2.5 ms : 180 degree -SERVO_PIN = 15 - -# IQR Pins -FASTER_PIN = 20 -SLOWER_PIN = 21 - -# built-in Buzzer -BUZZER_PIN = 22 - -# Adjust these parameters to tune the collision avoidance behavior - -POWER_LEL = 35000 -TURN_DISTANCE = 20 # distance we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn - -# startup mode is 0 - motors off and LEDs flashing -# mode 1 is slow -# mode 2 is medium -# mode 3 is fast -mode = 0 - -# Init HC-SR04P pins -trigger = Pin(PING_TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(PING_ECHO_PIN, Pin.IN) # get the delay interval back - -faster_pin = machine.Pin(FASTER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(SLOWER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -last_time = 0 # the last time we pressed the button - -# -# DISPLAY STUFF -# -# Display Image & text on I2C driven ssd1306 OLED display - - -WIDTH = 128 # oled display width -HEIGHT = 32 # oled display height - -# Explicit Method -sda=machine.Pin(OLED_SDA_PIN) -scl=machine.Pin(OLED_SCL_PIN) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=40000) # 400k is too fast and has issues -print( 'i2c={:02X}'.format( i2c.scan()[0] ) ) -#print(help(i2c)) -#print(help(i2c.init)) -#print(help(i2c.scan)) -#print(help(i2c.start)) -#print(help(i2c.stop)) -#print(help(i2c.readinto)) -#print(help(i2c.write)) -#print(help(i2c.readfrom)) -#print(help(i2c.readfrom_into)) -#print(help(i2c.writeto)) -#print(help(i2c.writevto)) -#print(help(i2c.readfrom_mem)) -#print(help(i2c.readfrom_mem_into)) -#print(help(i2c.writeto_mem)) -#exit - -oled = SSD1306_I2C(128, 32, i2c) - -# Raspberry Pi logo as 32x32 bytearray -buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB) - -def blk(): - oled.fill(0) - oled.show() - -def horiz(l,t,r,c): # left, right , top - n = r-l+1 # Horizontal line - for i in range(n): - oled.pixel(l + i, t, c) - -def vert(l,t,b,c): # left, top, bottom - n = b-t+1 # Vertical line - for i in range(n): - oled.pixel(l, t+i,c) - -def box(l,t,r,b,c): # left, top, right, bottom - horiz(l,t,r,c) # Hollow rectangle - horiz(l,b,r,c) - vert(l,t,b,c) - vert(r,t,b,c) - -def ring2(cx,cy,r,c): # Centre (x,y), radius, colour - for angle in range(0, 90, 2): # 0 to 90 degrees in 2s - y3=int(r*math.sin(math.radians(angle))) - x3=int(r*math.cos(math.radians(angle))) - oled.pixel(cx-x3,cy+y3,c) # 4 quadrants - oled.pixel(cx-x3,cy-y3,c) - oled.pixel(cx+x3,cy+y3,c) - oled.pixel(cx+x3,cy-y3,c) - -#print(help(oled.text())) -#print(help()) -#help('modules') -#help(oled) -#help(oled.text) -#help(framebuf.FrameBuffer) -#help(framebuf.FrameBuffer.help()) - -# Clear the oled display in case it has junk on it. -oled.fill(0) # Black - -# Blit the image from the framebuffer to the oled display -oled.blit(fb, 96, 0) - -# Basic stuff -oled.text("Raspberry Pi",5,5) -oled.text("RP2040",5,15) -oled.text("press GP21",5,25) -oled.pixel(10,60,1) - -#ring2(50,43,20,1) # Empty circle -# Finally update the oled display so the image & text is displayed -oled.show() -utime.sleep(1) - - -# -# Back to the motor control stuff. (sorry... i'm soppy today) -# -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '21' in str(pin): - mode +=1 - else: - mode -=1 - # deal with ends - if mode > 4: mode = 2 - if mode < 0: mode = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(BUZZER_PIN)) - -MAX_POWER_LEVEL = 65025 - -MAX_DISTANCE = 100 # ignore anything above this - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 # this must be wired backword? -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# returns distance in cm -def ping(): - #print('in ping') - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - #print('echo is 1') - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - print(distance) - - return int(distance) - -def turn_motor_on(pwm): - #pwm.duty_u16(65025) - pwm.duty_u16(16000) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28] -blue_led_pins.remove(PING_TRIGGER_PIN) -blue_led_pins.remove(PING_ECHO_PIN) -blue_led_pins.remove(OLED_SDA_PIN) -blue_led_pins.remove(OLED_SCL_PIN) - - -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -number_leds = len(blue_led_pins) -led_ports = [] -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def play_no_signal(): - playnote(100, 0.1) - sound_off() - -def play_turn(): - playnote(500, .1) - sound_off() - -def setfreq(frequency): - buzzer.freq(frequency) - -def playnote(frequency, time): - buzzer.duty_u16(1000) - setfreq(frequency) - utime.sleep(time) - -def sound_off(): - buzzer.duty_u16(0) - -def rest(time): - buzzer.duty_u16(0) - utime.sleep(time) - -def play_startup(): - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.1) - playnote(800, .4) - sound_off() - -def servo(degrees): - if degrees > 180: degrees=180 - if degrees < 0: degrees=0 - maxDuty=8000 # duty*100 - minDuty=2000 # duty*100 - #maxDuty=2000 # test - #minDuty=8000 # test - newDuty=minDuty+(maxDuty-minDuty)*(degrees/180) - servoPin.duty_u16(int(newDuty)) - -servoPin = PWM(Pin(SERVO_PIN)) -servoPin.freq(50) - -valid_distance = 1 - -def main(): - global valid_distance - print("running main()") - - play_startup() - oled_count=0 # repeat every - oled_count_max=0 # times through loop - servo_count=0 - servo_count_max=0 # when to update - servo_degrees = 0 - servo(servo_degrees) # start in that pos - - # loop forever - while True: - if mode == 0: - stop() - run_lights() - else: - distance = ping() - print('Distance:', distance) - oled_count += 1 - if oled_count > oled_count_max: - oled.fill(0) # Black - oled.text("Distance:",5,5) - oled.text("{:f}".format(distance),5,15) - oled.show() - oled_count = 0 - - servo_count += 1 - if servo_count > servo_count_max: - if distance > MAX_DISTANCE: - servo_degrees = 0 - else: - servo_degrees = 180-distance/MAX_DISTANCE*180 - servo(servo_degrees) - servo_count = 0 - - if distance > MAX_DISTANCE: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - #note=distance*10 - #playnote(note, .025) - - if distance < TURN_DISTANCE: - play_turn() - # back up for a bit - reverse() - utime.sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - else: - turn_left() - utime.sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - utime.sleep(0.05) - -# clean up - -# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -except Exception as e: print(e) -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('shutting motors down') - stop() -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/25-line-follower.md b/docs/kits/maker-pi-rp2040-robot/25-line-follower.md deleted file mode 100644 index c8811d00a..000000000 --- a/docs/kits/maker-pi-rp2040-robot/25-line-follower.md +++ /dev/null @@ -1,160 +0,0 @@ -# Line Follower Robot - - - -Line following robot projects is a favorite project for our students. They teach the students the concept of -feedback to keep a robot following a line on a track or on the floor. They are not easy to get working -and require careful calibration of the sensor sensitivity and carefully adjusting the right and left motor -power to keep the robot on track. Once the student gets the robot working it is a time for celebration! - -The total cost of the kit is about $20. - -## Parts List -|Part Name|Description|Price|Link| -|---------|-----------|-----|----| -|Cytron Board|Main board with RP2040 and motor driver. Kits come with Grove connectors and a screwdriver.|$12|| -|SmartCar Chassis|SmartCar chassis with wheels and 4 AA battery pack|| -|IR Sensors (2)|Low cost IR light sensors|$1|| - -## IR Sensors - -![](../../img/ir-sensors.png) - -We can purchase IR sensors on eBay for about $1 each in quantity 10. -The sensors send a digital 0/1 signal to the microcontroller depending on if they are over the line. -Our job is to write some MicroPython code to keep the robot following the line. -Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room. - -![](../../img/ir-sensor.jpeg) - -Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room. Some -of our rooms have a white floor with a black line and some -of our rooms have a dark floor with a white line. You may have to -adjust both the trim potentiometer and the logic of the code for different situations. - -Use the Grove connectors to hook up the IR sensors. I used the red (VCC), black (GDN) and white wires (Data) and -I just cut off the yellow wires to keep them out of the way. I then connected the Grove connectors -to ports 2 and 3 of the Cytron board. - -I connected the motors to the **MOTOR 1** and **MOTOR 2** headers with a screwdriver and I hooked -the battery wires up to the power header of the board. - -```py -from machine import Pin -from utime import sleep - -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -while True: - r = right_sensor.value() - l = left_sensor.value() - print("r", r, "l=", l) - if r == 0: - print("right over white") - if l == 0: - print("left over white") - sleep(.2) -``` - -## Full Source Code - -```py -from machine import Pin, PWM -from time import sleep - -# sensor setup -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -# speaker pin on the Cytron Maker Pi RP2040 -SPEAKER_PIN = 22 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle -speaker.duty_u16(1000) - -# Motor setup -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN =10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -MAX_POWER_LEVEL = 65025 -QUARTER_POWER = 65025 >> 2 -SLOW_DRIVE_POWER = 16000 -BOOST_LEVEL = 15000 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(SLOW_DRIVE_POWER) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def forward(): - right_forward.duty_u16(SLOW_DRIVE_POWER) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER) - left_reverse.duty_u16(0) - speaker.duty_u16(0) - -def right(): - right_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL) - left_reverse.duty_u16(0) - speaker.duty_u16(1000) - speaker.freq(800) - -def left(): - right_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL) - left_reverse.duty_u16(0) - speaker.duty_u16(1000) - speaker.freq(1000) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - speaker.duty_u16(0) - -def main(): - while True: - r = right_sensor.value() - l = left_sensor.value() - if r == 0 and l == 1: - print("right over white - turning left") - right() - if l == 0: - print("left over white") - left() - else: - forward() - -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/index.md b/docs/kits/maker-pi-rp2040-robot/index.md deleted file mode 100644 index 331b41a46..000000000 --- a/docs/kits/maker-pi-rp2040-robot/index.md +++ /dev/null @@ -1,38 +0,0 @@ -# Cytron Maker Pi RP2040 Collision Avoidance Robot - -We have been working on designing a run robot that can be used to teach computational thinking since 2014. We have gone through many generations, and now we think we have a fantastic design that is powerful, flexible, extendible and inexpensive. We love this robot because: - -1. The cost of parts is under $20.00 US -2. It is programmed with Python -3. It has plenty of power - with 264K RAM it has the ability to run complex programs -4. The design is flexible and it is easy to add displays and other sensors - -## Base Cytron Maker Pi RP2040 Robot Kit - -![Maker Pi RP2040 Top View](../../img/maker-pi-rp2040-tof-robot.jpg) -This version uses the time-of-flight sensor. - -The robot can be built ia a few hours using a screwdriver and soldering four wires onto the motors. - -## Sample Parts List - -![Cytron Ping Kit Parts](../../img/cytron-ping-kit-parts.jpg) - -1. Cytron Maker Pi RP2040 board (includes Grove connectors, screwdriver and feet) [Cytron](https://www.cytron.io/p-maker-pi-rp2040-simplifying-robotics-with-raspberry-pi-rp2040) [DigiKey](https://www.digikey.com/en/products/detail/cytron-technologies-sdn-bhd/MAKER-PI-RP2040/14557836) [Amazon](https://www.amazon.com/Cytron-Simplying-Robotics-Beginner-RP2040/dp/B09HBQL141) [Adafruit](https://www.adafruit.com/product/5129) [YouTube Video](https://www.youtube.com/watch?v=8CXirBVwVoU) -2. 2 Wheel Drive Smart Car Kit: Chassis Main board (acrylic), 2x DC Motors with wires soldered, 2x wheels, 4x AA Battery Case: [Cytron](https://www.cytron.io/p-2wd-smart-robot-car-chassis?search=Smart%20Car%20&description=1) [Amazon](https://www.amazon.com/Smart-Chassis-Motors-Encoder-Battery/dp/B01LXY7CM3/ref=sr_1_7) [eBay](https://www.ebay.com/itm/324919345465?hash=item4ba6b3c139:g:FSIAAOSwTAddc3c2) -3. Distance Sensor (Time-of-flight or Ultrasonic ping): [Cytron](https://www.cytron.io/p-vl53l0x-v2-laser-tof-distance-sensor-module?search=Time%20of%20flight%20sensor) [ebay](https://www.ebay.com/itm/353793425635?hash=item525fbb40e3:g:fUkAAOSwoexftRiN) [Amazon](https://www.amazon.com/VL53L0X-Ranging-Sensor-Breakout-Distance/dp/B09LVGDQD6/ref=sr_1_1?) -4. Ping sensor mount -5. 2x M3 6 mm screws and nuts -6. 4x M3 10 mm screes and nuts -7. Micro USB cable -8. 4x AA batteries - -## Demo with OLED Display - - - -1. Cytron Maker Pi RP2040 robotics board ($10) -2. SmartCar kit ($9) -3. Time-of-flight sensor (4) -4. Optional OLED SPI 2.24" SSD1606 display ($18) - diff --git a/docs/kits/maker-pi-rp2040/01-getting-started.md b/docs/kits/maker-pi-rp2040/01-getting-started.md deleted file mode 100644 index a4d5e1830..000000000 --- a/docs/kits/maker-pi-rp2040/01-getting-started.md +++ /dev/null @@ -1,43 +0,0 @@ -# Getting Started - -## Purchasing - -The retail list price is $9.99. Thie Cytron Maker Pi RP2040 kit includes 3 Grove connectors, screwdriver and feet) [Cytron](https://www.cytron.io/p-maker-pi-rp2040-simplifying-robotics-with-raspberry-pi-rp2040) - -Here are some online retailers that seel this kit: - -* [DigiKey](https://www.digikey.com/en/products/detail/cytron-technologies-sdn-bhd/MAKER-PI-RP2040/14557836) -* [Amazon](https://www.amazon.com/Cytron-Simplying-Robotics-Beginner-RP2040/dp/B09HBQL141) -* [Adafruit](https://www.adafruit.com/product/5129) - - -There is also a [YouTube Video](https://www.youtube.com/watch?v=8CXirBVwVoU) that demonstrates the features of the board. - -## Install the MicroPython Runtime Library - -The **Maker Pi RP2040** comes with an incompatible CircuitPython run-time. Our first step is to re-initialize the board with the Raspberry Pi [flash_nuke.uf2](https://www.raspberrypi.org/documentation/pico/getting-started/static/6f6f31460c258138bd33cc96ddd76b91/flash_nuke.uf2) runtime. We can then load the latest MicroPython libraries. When we wrote these labs we were using MicroPython version 1.7 that was released in September of 2021. - -To install MicroPython you mush **hold down** the **BOTSEL** button on the main board while you turn on the board using the on-board power switch. This will make the board look like a USB drive. You can then just drag the flash-nuke file onto the drive and the board will be initialized. Make sure to power the board off and back on. - -You can now repeat this process with the [Raspberry Pi MicroPython Runtime](https://micropython.org/download/rp2-pico/rp2-pico-latest.uf2). Just remember to press and hold down the BOTSEL **before** you turn on the board and reboot after the image has been copied to the microcontroller. - -If you have never used MicroPython, the Raspberry Pi Foundation has a nice [Getting Started Guide](https://www.raspberrypi.org/documentation/microcontrollers/micropython.html) that can be helpful. - -## Get Familiar with your IDE (Thonny) and the Basic Programs - -There are many Integrated Development Environments (IDEs) that work with the Raspberry Pi RP2040 chip. The one you chose just should support MicroPython and be able to upload and run new programs. Once you turn on the board you should be able to configure Thonny to use the Raspberry Pi MicroPython interface. When you press the Stop/Reset button you should see the MicroPython REPL prompt. - -![](../../img/thonny-micropython-pico.png) - -# -## Test the Motor Connections - -Use the [Motor Connection Lab](../maker-pi-rp2040-robot/07-motor-connection-lab.md) - -## Getting Help - -MicroPython on the RP2040 is the most powerful low-cost system on the market today. With 264K of RAM, it will take a LOT of work to run out of memory. But with all things new, there is a lock of good documentation, drivers and sample code. To help you along, we suggest the following resources: - -1. The [MicroPython Raspsberry Pi Forum](https://forum.micropython.org/viewforum.php?f=21&sid=73745cabd6bbdacfd3e78419d5064dfe). Be sure use the search to check for prior questions. -2. - diff --git a/docs/kits/maker-pi-rp2040/02-blue-led-lab.md b/docs/kits/maker-pi-rp2040/02-blue-led-lab.md deleted file mode 100644 index 489b1a471..000000000 --- a/docs/kits/maker-pi-rp2040/02-blue-led-lab.md +++ /dev/null @@ -1,61 +0,0 @@ -# Blue LED Lab - -Once you have the MicroPython runtime installed and your IDE setup, this board is easy to program! - -Let's take a look at the classic "Blink" program that turns a single LED on and off every second. - -## Blink First Blue LED -The Maker Pi RP2040 has a row of 13 small blue LEDs that monitor the digital input/output of 13 of the GPIO signals. If you set any of the output pins to be HIGH, the LED will be on. If you set the pin to be LOW, the blue LED will be off. These LEDs make it easy for you to view the state of your GPIO pins and can help debugging your programs. - -Just remember that if you are using the pins for communication, you can't use the LEDs for other purposes. - -Here is a small program that will blink the first blue LED: - -```py -import machine -import time -# setup the first LED as an output signal -first_led = machine.Pin(0, machine.Pin.OUT) - -while True: - first_led.toggle() - time.sleep(1) -``` - -Note that the first four lines are the "setup" of the program. These lines will only run once when the program starts. The code indented after the ```while True:``` line will continue to run until the device is reset or powered down. - -## Running Lights on All LEDs - -Here is a demo using the 13 nice blue LEDs used to show the status of the pins. - -![Maker Pi RP2040 LED Demo](../../img/maker-pi-rp2040-leds.gif) - -```py -import machine -import time - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28] -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# loop forever -while True: - # blue up - for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -``` - -This demo uses a list of all the 13 digital I/O ports. For each port it sets the port to be a digital output. In the main loop it then goes up and down the strip of LEDs, turning each one on for 1/20th of a second (.05 seconds). diff --git a/docs/kits/maker-pi-rp2040/03-neopixel-lab.md b/docs/kits/maker-pi-rp2040/03-neopixel-lab.md deleted file mode 100644 index e280d6f94..000000000 --- a/docs/kits/maker-pi-rp2040/03-neopixel-lab.md +++ /dev/null @@ -1,98 +0,0 @@ -## NeoPixel Demo Lab - -The Maker Pi RP2040 comes with two built-in NeoPixels. Each NeoPixel has a red, green and blue LED inside it. Each of these LEDs can be set to any one of 256 values from 0 (off) to 255 (brightest value). - - - - -## NeoPixel Setup - -```py -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") -``` - -## NeoPixel Blink Lab -In this lab, we will turn the first NeoPixel element on red for 1/2 second and then turn it off for 1/2 second. We repeat this until the program is terminated. - -## Setting up the NeoPixel Library - -We will be calling a NeoPixel driver in the /lib directory. We initiaze our NeoPixel strip by calling the init method all Neopixel() and pass it three parameters: - -1. The number of pixels in the strip (in our case there are just two) -2. The state machine (in our case 0) -3. The LED PIN (in our case this is GP18) - - -```py -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -while True: - # turn on first pixel red for 1/2 second - strip.set_pixel(0, (255, 0, 0)) - strip.show() - sleep(.5) - strip.set_pixel(0, (0, 0, 0)) # turn all colors off - strip.show() - sleep(.5) -``` - -```py -import time -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -color_index = 0 -while True: - for color in colors: - for i in range(NUMBER_PIXELS): - print(i, color_names[color_index]) - strip.set_pixel(i, color) - strip.show() - time.sleep(1) - color_index += 1 - if color_index >= num_colors: color_index = 0 - -``` - - diff --git a/docs/kits/maker-pi-rp2040/04-button-lab.md b/docs/kits/maker-pi-rp2040/04-button-lab.md deleted file mode 100644 index 8725815db..000000000 --- a/docs/kits/maker-pi-rp2040/04-button-lab.md +++ /dev/null @@ -1,153 +0,0 @@ -# Two Button Press - -We learned how to write code to monitor a button press in the [Button Lab](../../basics/03-button.md). - -Recall we talked about how to remove the "debounce noise" when a button is pressed by adding a timer to make sure we had a clean transition (debouncing the switch): - -![Debounce Transition](../../img/debounce-transition.png) - -We did this by waiting for the transition to settle down to its new state. - -```py -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - button_presses +=1 - else: - button_presses -=1 - last_time = new_time - - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 - -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses -``` - -## Making the Buttons Change the NeoPixel Color - -In this lab, we will combine the button press lab with our NeoPixel lab to allow you to change the NeoPixel colors if a button on the board is pressed. Each button will control the color of one of the pixels. - -```py -# press buttons to change the color of the NeoPixels -import utime -from machine import Pin -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 -BUTTON_A_PIN = 20 -BUTTON_B_PIN = 21 -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -white = (255, 255, 255) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) - -# color index into colors list -neopixel_a = 0 -neopixel_b = 0 -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_a = machine.Pin(BUTTON_A_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_b = machine.Pin(BUTTON_B_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time, num_colors, neopixel_a, neopixel_b - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - button_presses += 1 - if '20' in str(pin): - neopixel_a +=1 - if neopixel_a > num_colors - 1: - neopixel_a = 0 - else: - neopixel_b +=1 - if neopixel_b > num_colors - 1: - neopixel_b = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -print('Running NeoPixel Button Lab') -strip.set_pixel(0, (4,5,5)) -strip.set_pixel(1, (4,5,5)) -strip.show() - -def main(): - global button_presses, old_presses, colors, neopixel_a, neopixel_b - while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a) - print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b) - strip.set_pixel(0, colors[neopixel_a]) - strip.set_pixel(1, colors[neopixel_b]) - strip.show() - old_presses = button_presses - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Turning off NeoPixels') - strip.set_pixel(0, (0,0,0)) - strip.set_pixel(1, (0,0,0)) - strip.show() - -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040/05-sound-lab.md b/docs/kits/maker-pi-rp2040/05-sound-lab.md deleted file mode 100644 index aab38e7e7..000000000 --- a/docs/kits/maker-pi-rp2040/05-sound-lab.md +++ /dev/null @@ -1,45 +0,0 @@ -# Play Mario on MicroPython - -This program will play the theme music from the Mario video game. - -```python -from machine import Pin, PWM -from utime import sleep -buzzer = PWM(Pin(22)) - -tones = { -"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46, -"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65, -"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98, -"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139, -"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185, -"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311, -"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698, -"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661, -"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520, -"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978 -} - -song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"] -mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6", - 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", - 0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, - "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0] - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def playsong(mysong): - for i in range(len(mysong)): - if (mysong[i] == "P" or mysong[i] == 0 ): - bequiet() - else: - playtone(tones[mysong[i]]) - sleep(0.3) - bequiet() -playsong(mario) -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040/06-up-down-lab.md b/docs/kits/maker-pi-rp2040/06-up-down-lab.md deleted file mode 100644 index 052ed5f2a..000000000 --- a/docs/kits/maker-pi-rp2040/06-up-down-lab.md +++ /dev/null @@ -1,137 +0,0 @@ -# Up Down Mode Lab - -In this lab, we will combine the two buttons with the blue LEDs, the NeoPixels and the buzzer labs. The -We will make the LED, NeoPixels and sound all change for each button press. You will be able to up -and down the color spectrum and the sound frequency. - - - -We will start with the material from our button lab. We will create two functions that will be triggered by the -two buttons. One will increment a counter (add one) and the other will decrement the counter (subtract 1). By pressing one of the two buttons you will cycle through the modes of the program. - -![Mode Cycle Diagram](../img/../../img/mode-cycle-diagram.png) - -The diagram has eight different modes. The default mode is usually mode=0. When you press the left button the mode will increase by one. The NeoPixels will change from red to orange. Pressing the left button will increase the mode by one going to the orange mode. Pressing the right button will subtract one from the mode going from mode 1 (orange) back to model 0 (red). - - -Within our Interrupt Request Handler (IRQ) function we will also have to add two lines to deal with the wrap around logic like this: - -```py - # wrap around to first mode - if mode >= mode_count: mode = 0 - if mode < 0: mode = mode_count - 1 -``` - -## Full Program -```py -# Mode Up/Down Lab -# Change a mode using the buttons on the Maker Pi RP2040 board -# Changes the NeoPixel color and the blue GPIO status LEDs -import time -from machine import Pin, PWM -# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -BUZZER_PORT = 22 -buzzer = PWM(Pin(BUZZER_PORT)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") - -# have up to 13 that we can use -blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28] -number_leds = len(blue_led_pins) -led_ports = [] -# create a list of the port pin object instances -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Color RGB values as tuples - needs some Gamma corrections -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -mode = 0 # the default mode on powerup and reset -mode_count = len(color_names) -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# Give our pins some logical names -next_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -previous_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = time.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - mode +=1 - else: - mode -=1 - # wrap around to first mode - if mode >= mode_count: mode = 0 - if mode < 0: mode = mode_count - 1 - last_time = new_time - -def set_blue_led_mode(mode): - global num_colors - for i in range(0, num_colors): - if i == mode: - led_ports[i].high() - else: - led_ports[i].low() - -# Register the handler function when either button is pressed -next_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -previous_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Note the non-linear increases in frequency - note that some are louder -tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000] -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -# This is for only printing when a new button press count value happens -old_mode = -1 - -print('found ', mode_count, ' modes.') -while True: - # only print on change in the button_presses value - if mode != old_mode: - print('new mode:', mode, color_names[mode], tone_freq[mode]) - # get the color mode - color = colors[mode] - strip.set_pixel(0, color) - strip.set_pixel(1, color) - strip.show() - set_blue_led_mode(mode) - playtone(tone_freq[mode]) - time.sleep(.2) - bequiet() - old_mode = mode -``` \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040/index.md b/docs/kits/maker-pi-rp2040/index.md deleted file mode 100644 index 94df56126..000000000 --- a/docs/kits/maker-pi-rp2040/index.md +++ /dev/null @@ -1,115 +0,0 @@ -# Maker Pi RP2040 MicroPython Robotics Kit - -The Maker Pi PR2040 kit from [Cytron Technologies](https://www.cytron.io/) is a [$9.90 US kit](https://www.cytron.io/p-maker-pi-rp2040-simplifying-robotics-with-raspberry-pi-rp2040) that is designed to simplify learning robotics using the RP2040 chip. It became available in April of 2021, but demand has been very high and it is out-of-stock on many retailers sites. We can understand this. The Maker Pi PR2040 is the most powerful robotics board we have ever seen for under $10! - -![Maker Pi RP2040 Kit](../../img/maker-pi-rp2040-kit.jpeg) - - -The photo above is our base robot kit. It includes the Maker Pi RP2040 board mounted on a standards Smart Car chassis. The image above shows the Time-of-flight distance sensor mounted in the front below the chassis. Note that the batteries are mounted on the bottom of the robot. - -Below is the top view of the Cytron Maker Pi RP2040 robotics board. - -![Maker Pi RP2040 Top View](../../img/maker-pi-rp2040-top-view.png) - -## Features -All our robots are built around a RP2040 and a motor driver with a few low-cost sensors and displays. With the exception of the OLED display, this board packs in a huge number of features for a low cost of $9.90. - -* Power status LED (green) -* On/off switch -* 13 blue LEDs to show status on GP pins 0,1,2,3,4,5,6,16,17,26,27 and 28 -* 2 WS2812B RGB LEDs connected to GP18 -* LiPo Battery Connector -* Micro USB Port (use for powering and programming) -* Reset button -* Boot button -* Momentary press buttons on ports GP20 and GP21 -* 2 Motor drivers. Motor A is controlled by GP8 and GP10 and motor B is controlled by GP9 and GP11. -* 4 motor test buttons for testing motors A and B, forward and backward -* 4 red motor status LEDs buttons for displaying motors A and B, forward and backward -* 7 Grove Ports on GPs 1:0,1; 2:2,3; 3:4,5; 4:16,17; 5:6,26; 6:26,27 and 7:7,28 -* 4 servo connectors on ports GP12, GP13, GP14 and GP15 -* Piezo buzzer on port GP22 -* On/Off switch on GP22 which can be used to mute the sound -* Phillips head screwdriver that works on the header pins - really convenient for students! -* 4 [Grove Connectors](https://wiki.seeedstudio.com/Grove_System/) -* Rubber mounting feet -* Pins numbers clearly labeled both on top and bottom of the board -* Large area on bottom of the board for students to write their name - -## List of Labs - -### Part 1: No Accessories Required Labs - -These labs don't need anything except the Maker Pi RP2040 board. - -1. [**Blue LED Lab**](02-blue-led-lab.md) - make the blue GPIO status LEDs show cool patterns -2. [**NeoPixel Lab**](03-neopixel-lab.md) - make the two NeoPixel each display many colors -3. [**Button Lab**](04-button-lab.md) - make the two buttons change the state of system -4. [**Sound Lab**](05-sound-lab.md) - make the Piezoelectric Buzzer create sounds -5. [**Up Down Mode Lab**](06-up-down-lab.md) - make the buttons change the LEDs, NeoPixels and Sound - -### Part 2: Motor and Servo Labs - -These labs require additional parts such as DC hobby motors and servos - -1. [**Motor Connection Lab**](../maker-pi-rp2040-robot/07-motor-connection-lab.md) - make two motors turn forward and in reverse -2. [**Up/Down Motor Speed Lab**](../maker-pi-rp2040-robot/06-up-down-motor-lab.md) - change the speed as you change the mode -3. [**Servo Lab**](../maker-pi-rp2040-robot/08-servo-lab.md) - control the direction of a 108% servo motor. Calibrate the end angles and sweep the direction back and forth. - -### Part 3: Sensor Labs - -There are literally hundreds of sensors that have Grove connectors on them. In addition, we can purchase Grove connectors for as low as [30 cents each](https://www.cytron.io/p-grove-4-pin-buckled-20cm-cable?search=Grove&description=1). Any other sensors with male pins can be easily connected with these [38 cent connectors with female Dupont jumper connectors](https://www.cytron.io/p-grove-4-pin-buckled-to-female-cable?search=Grove&description=1). Classrooms with a large collection of these sensors can allow students to try new sensors and outputs without needing a breadboard or soldering. We will focus initially on two sensors we will use for our collision avoidance robot. We prefer the Time-of-Flight sensor because it uses a standard I2C interface and thus could share the I2C bus with other devices. - -1. [**Time of Flight Distance Sensor Lab**](../maker-pi-rp2040-robot/10-time-of-flight-lab.md) - measure the distance to an object -2. [**Ultrasonic Ping Distance Sensor**](../maker-pi-rp2040-robot/11-ping-lab.md) - the classic low-cost ultrasonic distance sensor but now it works on a 3.3 volt power! (TBD) -3. [**Time of Flight Sound Lab**](../maker-pi-rp2040-robot/12-time-of-flight-sound-lab.md) - sound pitch changes with distance - -### Part 4: Collision Avoidance Robot - -1. [**Collision Avoidance Robot**](20-collision-avoidance-robot.md) - this lab joins our motor and sensor labs with a SmartCar chassis to create a robot that avoids collisions. -2. Collision Robot with Modes - TBD -3. Adjustable Collision Avoidance - the adjusta bot! TBD -4. Adding a display - -## Basis for a Low-Cost Robot Kit - -When this kit is combined with a standard [2 Wheel Drive Smart Car Chassis](https://www.cytron.io/p-2wd-smart-robot-car-chassis) and a [distance sensor](https://www.coderdojotc.org/micropython/sensors/07-VL53L0X_GY/) it becomes a great low-cost way of getting started with Python and robots. - -## Clearly Labeled Pin Numbers - -One of the biggest disadvantages of the Raspberry Pi Pico is the fact that pin labels are NOT visible when it is mounted on a breadboard. We have to take the Pico out of the breadboard to read the pin numbers on the bottom of the board. A much better design would be to follow the best practices and put the labels on the top of the board where they are visible. This is clearly done on the Maker Pi RP2040 board! - -![Maker Pi RP2040 Pin Labels](../../img/maker-pi-rp2040-labels.png) - -Note the pin labels, GND, 3.3V, GP0 and GP1 are clearly printed on the top of the board. - -![Maker Pi Bottom View](../../img/maker-pi-rp2040-bottom-view.jpeg) - -Note the circuit in the upper right corner displays how you can use the analog input port to read the battery level of the robot. - -## Removing the Default CircuitPython - -Cytron Technologies has a wonderful [YouTube videos](https://www.youtube.com/watch?v=mn1nqgEkufA) on how to program the Maker Pi RP2040 using MicroPython. Unfortunately, this board does NOT come with our standard MicroPython loaded! :-O It uses the non-standard Adafruit CircuitPython that is incompatible with most MicroPython programs being used today. This is a sad state of affairs that confuses our students and makes it difficult to share code and libraries for MicroPython. According to Google trends, over the last 12 months for worldwide searches, [MicroPython has almost five time the interest of CircuitPython](https://trends.google.com/trends/explore?q=micropython,circuitpython). Preloading the board with CircuitPython sends a very confusing message to the marketplace. - -## Flash Nuke -I want to make sure that my RP2040 was starting out with a clean image. I downloaded the [flash_nuke.uf2](https://www.raspberrypi.org/documentation/pico/getting-started/static/6f6f31460c258138bd33cc96ddd76b91/flash_nuke.uf2) file to remove the default CircuitPython runtime and all the related files. - -Note that the board **must** be fully powered down after this load for it to work. I had 4 AA batteries connected to the VIN screw headers, so it was not resetting correctly and the reset was not working until I disconnected the batteries. - -The latests MicroPython runtimes are [here](https://micropython.org/download/rp2-pico/) - -## Easy Motor Testing Buttons - -One of the things I love about this board is how incredibly easy it is for students to test their motors. The board provides four very convenient motor test buttons right on the board. By pressing each one you can make both motors go forward and backwards. This is a great way for students to learn about how we can generate PWM signals to simulate these four buttons. Whoever design this board clearly had their students in mind! - -## References -* [Link on Box](https://link.cytron.io/maker-pi-rp2040-start) -* [GitHub Link](https://github.com/CytronTechnologies/MAKER-PI-RP2040) -* [Cytron Maker Pi RP2040 Product Page](https://www.cytron.io/p-maker-pi-rp2040-simplifying-robotics-with-raspberry-pi-rp2040) -* [Cytron Maker Pi RP2040 Datasheet on Google Docs](https://docs.google.com/document/d/1DJASwxgbattM37V4AIlJVR4pxukq0up25LppA8-z_AY/edit) -* [Digi-Key Cytron Maker Pi RP2040 reseller](https://www.digikey.com/en/products/detail/cytron-technologies-sdn-bhd/MAKER-PI-RP2040/14557836) -* [Amazon Listing](https://www.amazon.com/dp/B096DFH22X) - no availability as of Aug. 15th 2021 -* [Adafruit Cytron Maker Pi RP2040 reseller](https://www.adafruit.com/product/5129) - out of stock as of Aug. 15th 2021 -* [1300 mah battery](https://www.cytron.io/p-lipo-rechargeable-battery-3.7v-1300mah) -* [Ultrasonic Sensor Video on YouTube](https://www.youtube.com/watch?v=mn1nqgEkufA) -* [Circuit Schematic](https://drive.google.com/file/d/1Zp8GYO8x7ThObB1G8RIZx2YdqrXtdUc0/view) \ No newline at end of file diff --git a/docs/kits/microbit.md b/docs/kits/microbit.md deleted file mode 100644 index c86748745..000000000 --- a/docs/kits/microbit.md +++ /dev/null @@ -1,48 +0,0 @@ -# MicroBit - -Although the BBC MicroBit is a good educational product for learning MicroPython, we don't use it in our MicroPython courses for the following reason: - - -1. **Price** - The current price on sites like Amazon is around $22. We can get the Raspberry Pi Pico for $4. -2. **Availability** - MicroBits have not been available due to shortages of chips that it needs. -3. **Memory** - The MicroBit only has 32KB of RAM. The Pico has 256K. We need this extra RAM for our OLED display labs. -4. **Breadboard** - We use simple, standardized, easy-to-upgrade breadboards in our classes. This makes it easy to upgrade our microcontrollers and promotes higher sustainability. We also believe that teaching breadboarding skills is critical for future projects. -5. **Expandability** - we like the ability to expand our base labs to include many low costs sensors -6. **Multi-Core** - we want to be able to teach multi-core coding in our classrooms. Because the MicroBit only has a single core this is not possible on the MicroBit. The Raspberry Pi Pico has two cores. Many projects use one core for monitoring the sensors and another core for doing analysis and updating the display. -7. **Pulse Width Modulation Channels** - The MicroBit only has 3 PWM channels. We need a minimum of 4 to drive our robots. - -## Side-By-Side Comparision - -|Feature Name|MicroBit v2|Raspberry Pi Pico|Notes| -|-----|---|---|-------| -|Price|$22|$4|The Pico "W" with wireless is $6| -|Breadboard|No|Yes|Allows us to teach breadboarding skills| -|RAM|32MB|256MB|We need around 100MB to support our 128x64 OLED frame buffers| -|Flash|2MB|512MB|We use extra flash to store hundreds of programs, images and sounds| -|Sensors|Temp,Accelerometers,Compass,Light,Touch|Temp|For about $5 we can add these sensors to the Pico| -|Processor|ARM Cortex-M4|Dual-core Arm Cortex-M0+|The M4 has better support for DSP and floating point| -|LEDs|25|1|We use 8X8 LEDs and NeoPixels in our labs to create similar displays| -|Block Programming|Microsoft MakeCode|BIPES|Block coding is great for younger students that don't have strong keyboarding skills| -|GPIOs|20|26|This has not been a concern. None of our labs need over 20 GPIOs| -|ADCs|5|3|Also not a concern. None of our labs need more that 3 Analog to Digital converters that run concurrently| -|Serial Bus|1 I2C, 1 SPI|2x UART, 2x I2C, 2x SPI, up to 16 PWM channels| -|Pulse Width Modulation|3|16|We need 4 PWM to drive our robots (a forward and back for each motor)| - - -## Sample Sources - -## Microcenter - -* [MicroCenter MicroBit Go Bundle for $22.92](https://www.microcenter.com/product/648994/microbit-v2-go-bundle) - includes USB cable and battery pack - -## SparkFun - -* [Pico for $3.99](https://www.sparkfun.com/products/17829) -* [Microbit for $22](https://www.sparkfun.com/products/17287) -* [Breakout Board for Breadboards $7](https://www.sparkfun.com/products/16446) - -## References - -* [Cytron](https://www.cytron.io/tutorial/raspberry-pico-vs-microbit) -* [Pico:ed V2 - a RP2040 in MicroBit Form Factor](https://www.cnx-software.com/2022/09/28/raspberry-pi-rp2040-gets-into-bbc-microbit-lookalike-board/) -* [Pico:ed $12](https://www.elecfreaks.com/elecfreaks-pico-ed-v2.html) \ No newline at end of file diff --git a/docs/kits/neopixel/01-getting-started.md b/docs/kits/neopixel/01-getting-started.md deleted file mode 100644 index ffafd6c3f..000000000 --- a/docs/kits/neopixel/01-getting-started.md +++ /dev/null @@ -1,3 +0,0 @@ -# Getting Started with the NeoPixel Kit - -Your kit should have several parts. Place them all on a table and hook them up. When you power on the kit with your USB cable the default ```main.py``` program will be running. \ No newline at end of file diff --git a/docs/kits/neopixel/02-simple-patterns.md b/docs/kits/neopixel/02-simple-patterns.md deleted file mode 100644 index 72445023c..000000000 --- a/docs/kits/neopixel/02-simple-patterns.md +++ /dev/null @@ -1,8 +0,0 @@ -# NeoPixel Simple Patterns - -## Blink - -## Wipe - -## Move Pixel - diff --git a/docs/kits/neopixel/03-buttons.md b/docs/kits/neopixel/03-buttons.md deleted file mode 100644 index 688d289d8..000000000 --- a/docs/kits/neopixel/03-buttons.md +++ /dev/null @@ -1,27 +0,0 @@ -# NeoPixel Button Lab - -## Review of Button Basics - -[Button Basics](../../basics/03-button.md) - -## Working with Two Buttons - -## Changing Color With Buttons - -## Using Modes - -Our LED kit can run a single "main" loop forever. But we often want to have the main loop run a different subprogram. Each subprogram can be triggered by pressing a button. The button will update a variable and the main loop will use this variable to redirect the main to the appropriate function. - -The ```mode``` variable is traditionally used to store the current subprogram being run. You are not limited to a single mode. You can also have modes within modes. - -![Mode Cycle Diagram](../../img/mode-cycle-diagram.png) - - -1. Using a buttons to advance a mode -2. Using a two buttons to move to the next and previous mode -3. Using two modes - one mode or each button - - -## Changing Patterns With Buttons - -## Changing Color and Pattern \ No newline at end of file diff --git a/docs/kits/neopixel/04-rotary-neopixel.md b/docs/kits/neopixel/04-rotary-neopixel.md deleted file mode 100644 index 3f71aeecd..000000000 --- a/docs/kits/neopixel/04-rotary-neopixel.md +++ /dev/null @@ -1,5 +0,0 @@ -# Rotary NeoPixel - -In this lab, we use a rotary encoder to change which pixel is turned on. -Turning the knob will appear to move the pixel. - diff --git a/docs/kits/neopixel/index.md b/docs/kits/neopixel/index.md deleted file mode 100644 index 96645322b..000000000 --- a/docs/kits/neopixel/index.md +++ /dev/null @@ -1,28 +0,0 @@ -# NeoPixel Kit - -![NeoPixel Kit](../../img/neopixel-kit.jpg) - -This is a low-cost (under $10) kit that we use in many of our classes. It contains the following parts: - -1. Raspberry Pi Pico ($4) -2. 1/2 size breadboard ($2) -3. LED Strip (WS2811b) ($3) - these come in many lengths from 8 to 60 pixels -4. Two momentary push buttons (20 cents) -5. USB cable (Micro-B to A) - -These lessons will assume you have these parts and can connect up to the Pico to your laptop using a USB cable. If you have a Mac with a USB-C connector you may need to provide a [USB-C to USB-A adaptor](https://www.amazon.com/Syntech-Adapter-Thunderbolt-Compatible-MacBook/dp/B07CVX3516). - -## Sample Labs - -We start with the sample code in the [Basics/NeoPixel](../../basics/05-neopixel.md) area. - -We then show how you can load full programs. Here is the source code: - -[NeoPixel Samples Source Code](https://github.com/CoderDojoTC/micropython/tree/main/src/neopixels) - -## Getting Started - -[Getting Started Lab](01-getting-started.md) - -## - diff --git a/docs/kits/rfid-rc522/index.md b/docs/kits/rfid-rc522/index.md deleted file mode 100644 index db4635e4f..000000000 --- a/docs/kits/rfid-rc522/index.md +++ /dev/null @@ -1,99 +0,0 @@ -# RFIG Reader RC-522 - -The RC-522 is a popular RFID reader that has strong support in the MicroPython -community. - -## Pinout - -![](./rc522-pinout.png) - -|NAME|PICO GPIO|COLOR| -|----|---------|-----| -|SDA|1|Yellow| -|SCK|2|Orange| -|MOSI|4|Purple| -|MISO|3|Blue| -|IRQ|7|Brown| -|GND|GND|Black| -|RST|0|Green| -|3.3V|3.3v Out|Red| - -### Wires at the RC522 -![](./rc522-wires.png) - -### Wires at the Pico - -## Config File - -Place this in the config.py - -```py -# reader = MFRC522(spi_id=0, sck=2, miso=4, mosi=3, cs=1, rst=0) -SPI_ID = 0 -RESET_PIN = 0 # Green OUT -SDA_PIN = 1 # Yellow OUT but used a Chip Select CS -SCK_PIN = 2 # Orange OUT clock going from Pico to RC522 -MISO_PIN = 3 # Blue -MOSI_PIN = 4 # Purple -IRQ_PIN = 7 # Brown, OUT but not used in the reader demo - -# GND is Black -# Red goes to 3.3v out - -``` - -## Reader - -```py -from mfrc522 import MFRC522 -import utime - - -def uidToString(uid): - mystring = "" - for i in uid: - mystring = "%02X" % i + mystring - return mystring - - -reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0) - -print("") -print("Please place card on reader") -print("") - - - -PreviousCard = [0] - -try: - while True: - - reader.init() - (stat, tag_type) = reader.request(reader.REQIDL) - #print('request stat:',stat,' tag_type:',tag_type) - if stat == reader.OK: - (stat, uid) = reader.SelectTagSN() - if uid == PreviousCard: - continue - if stat == reader.OK: - print("Card detected {} uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid))) - defaultKey = [255,255,255,255,255,255] - reader.MFRC522_DumpClassic1K(uid, Start=0, End=64, keyA=defaultKey) - print("Done") - PreviousCard = uid - else: - pass - else: - PreviousCard=[0] - utime.sleep_ms(50) - -except KeyboardInterrupt: - pass -``` - -## References - -* [How To Electronics: Using RC522 RFID Reader Module with Raspberry Pi Pico](https://how2electronics.com/using-rc522-rfid-reader-module-with-raspberry-pi-pico/) -* [Dan J Perron Driver](https://github.com/danjperron/micropython-mfrc522/blob/master/mfrc522.py) -* [Microcontrollers Lab Tutorial](https://microcontrollerslab.com/raspberry-pi-pico-rfid-rc522-micropython/) \ No newline at end of file diff --git a/docs/misc/30-colophon.md b/docs/misc/30-colophon.md deleted file mode 100644 index 736cdea66..000000000 --- a/docs/misc/30-colophon.md +++ /dev/null @@ -1,16 +0,0 @@ -# Colophon - -We are mostly a group of unpaid volunteers without a large budget for distributed content management software. However, we still want to provide a great user experience for both our mentors and our students. So we use free open-source tools whenever we can. Here is how we built this site. - -* Our content language is [Markdown](https://en.wikipedia.org/wiki/Markdown). -* We use [Python Markdown](https://python-markdown.github.io/) to parse our content. -* We convert Markdown to HTML with [mkdocs](https://www.mkdocs.org/). -* Our user interface theme is[Mkdocs Material](https://squidfunk.github.io/mkdocs-material/). We use an extensive number of Material user interface components. -* Our software version control system is [git](https://git-scm.com/) -* Our site is hosted on [GitHub page](https://pages.github.com/). -* We use standard code highlighting provided by the mkdocs [codehilite](https://python-markdown.github.io/extensions/code_hilite/) extension. -* Our BY-NC-SA content license agreement is created by [Creative Commons](https://creativecommons.org/licenses/by-nc-sa/3.0/) - -We wish to acknowledge the work of everyone that contributes to open-source projects. Without these systems this work would not be possible. - -If you would like to contribute lesson we welcome your contribution as a git pull request. You can read our [CoderDojo Twin CitiesAuthoring Guide](https://www.coderdojotc.org/CoderDojoTC/content-authoring-guide/) if you would like to help out. diff --git a/docs/misc/contact.md b/docs/misc/contact.md deleted file mode 100644 index 9e88cf64e..000000000 --- a/docs/misc/contact.md +++ /dev/null @@ -1,13 +0,0 @@ -# Cybersecurity for Kids Contacts - -## General Code Savvy Contact - -[kidscode@codesavvy.org](mailto:kidscode@codesavvy.org) - -## Contact for CoderDojo Twin Cities - -[hello@coderdojotc.org](mailto:hello@coderdojotc.org) - -## Specific questions on this repository - -[Dan McCreary](https://www.linkedin.com/in/danmccreary/) \ No newline at end of file diff --git a/docs/misc/contributing.md b/docs/misc/contributing.md deleted file mode 100644 index a16f30f7f..000000000 --- a/docs/misc/contributing.md +++ /dev/null @@ -1,49 +0,0 @@ -# MicroPython Book Contributing Guide - -The goal of this microsite is to provide MicroPython content to STEM educational programs around the world. We value inclusion and we love low-cost projects that promote STEM instruction in communities that don't have large budgets. We value a focus on instructional design that teaches computational thinking and uses evidence of the effective delivery of this content to underprivileged communities. - -We welcome anyone that would like to add content to this microsite with the following guidelines: - -## Contribution License - -1. Your content must be your own original content. We discourage copying bulk content from other sites without clear understanding of the copyrights that govern this content. We put a special focus on image attribution. Any images added must clearly state that the images are original content created by the author. -2. You must agree to license your new original content to allow other teachers and mentors to reuse this content in their classrooms free of charge. We use Creative Commons Licenses [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/) for all content in this microsite and other microsites managed by CoderDojo Twin Cities. - -Under these terms teachers and mentors are free to: - -* **Share** — copy and redistribute the material in any medium or format -* **Adapt** — remix, transform, and build upon the material - -The licensor cannot revoke these freedoms as long as you follow the license terms. -Under the following terms: - -* **Attribution** — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - -* **NonCommercial** — You may not use the material for commercial purposes. - -* **ShareAlike** — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original. - -* **No additional restrictions** — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. - -## Ways to Contribute - -1. Start out by helping us proof-read our content and help us find typos, spelling, lack-of clarity, and missing content. As you learn the style of our lessons you will be better able to contribute new lessons that have a similar style -1. You may submit pull requests to this site of if you are not familiar with this process, you can add a link to your content in an issue. -2. You may add an issue to our issues board [here](https://github.com/CoderDojoTC/micropython/issues) -3. You are welcome to participate by looking for open tasks and using GitHub workflows to take on tasks to completion. - -## Teaching Suggestions - -Avoid too much focus on building games that don't promote teaching computational thinking skills. Simple remote control robots might be fun, but sometime the fun of driving a robot around gets in the way of learning new concepts. - -## Lesson Structure - -1. Try to begin each section or lesson with a kid-friendly image. This help readers quickly recall if they have visited this page before. -2. If if it not obvious, include any prior knowledge that is required to understand a lesson in an Intended Audience or Prerequsites section. -3. Try to keep the introductory lessons in a section short and small. After you have introduce the core concepts you can integrate concepts from other areas. -4. Add a "Further Explorations" section to the end of each lesson -Include references to other sites or wikipedia articles that can be explored further. - -## Resources - -Please see our page on [Teaching Computational Thinking](https://www.coderdojotc.org/CoderDojoTC/computational-thinking/). \ No newline at end of file diff --git a/docs/misc/glossary.md b/docs/misc/glossary.md deleted file mode 100644 index 64110771e..000000000 --- a/docs/misc/glossary.md +++ /dev/null @@ -1,200 +0,0 @@ -# Micropython Glossary of Terms - - - - -#### Ampy -An obsolete MicroPython support tool created by Adafruit but no longer supported. - -Check out other MicroPython tools like [rshell](#rshell) or mpfshell for more advanced interaction with boards. - -#### Analog to Digital Converter -A component that takes an analogue signal and changes it to a digital one. - -Every ADC has two parameters, its [resolution](#resolution), measured in digital bits, and its [channels](#channels), or how many analogue signals it can accept and convert at once. - -* Also know as: ADC - -#### Blit -A special form of copy operation; it copies a rectangular area of pixels from one framebuffer to another. It is used in MicroPython when doing drawing to a display such as an OLED display. - -#### BOOTSEL -A button on the pico that when pressed during power up will allow you to mount the device as a USB drive. You can then drag-and-drop any uf2 image file to reset or update the runtime libraries. - -![](../img/boot-selection.png) - -* Also known as: Boot Selection - -#### Castellated Edge -Plated through holes or vias located in the edges of a printed circuit board that make it easier to solder onto another circuit board. - -![](../img/castellated-edge.png) - -The word "Castellated" means having grooves or slots on an edge and is derived from the turrets of a castle. - -#### Dupont Connectors - -Pre-made low-cost used and used to connect breadboards to hardware such as sensors and displays. - -The connectors are available in male and female ends and are typically sold in lengths of 10 or 20cm. They have a with a 2.54mm (100mill) pitch so they are easy to align with our standard breadboards. They are typically sold in a ribbon of mixed colors for around $2.00 US for 40 connectors. - -* Also known as: Jumper Wires -* [Sample eBay Search for Jumper Wires](https://www.ebay.com/sch/92074/i.html?_from=R40&_nkw=jumper+wire+cables) - - -#### ESP32 -A series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. - -Typical costs for the ESP32 is are around $10 US on eBay. - -* [Sample on eBay](https://www.ebay.com/itm/ESP32-ESP-32S-NodeMCU-Development-Board-2-4GHz-WiFi-Bluetooth-Dual-Mode-CP2102/392899357234) $5 -* [Sample on Amazon](https://www.amazon.com/HiLetgo-ESP-WROOM-32-Development-Microcontroller-Integrated/dp/B0718T232Z/ref=sr_1_1_sspa) $11 -* [Sample on Sparkfun](https://www.sparkfun.com/products/13907) $21 -* [ESP32 Quick Reference](http://docs.micropython.org/en/latest/esp32/quickref.html) -* [Sample eBay Search for ESP32 from $5 to $20](https://www.ebay.com/sch/i.html?_from=R40&_nkw=esp32&_sacat=175673&LH_TitleDesc=0&LH_BIN=1&_udhi=20&rt=nc&_udlo=5) - -#### Formatted Strings - -The ability to use a simplified syntax to format strings by added the letter "f" before the string. Values within curly braces are formatted from variables. - -```py -name = "Lisa" -age = 12 -f"Hello, {name}. You are {age}." -``` - -returns - -``` -Hello, Lisa. You are 12. -``` - -Formatted string support was added to MicroPython in release 1.17. Most formats work except the date and time formats. For these we must write our own formatting functions. - -* Also known as: f-strings -* Also known as: Literal String Interpolation -* From Python Enhancement Proposal: PEP 498 -* [Official Python documentation on string formatting](https://docs.python.org/3/library/string.html#string-formatting) -* Link to Formatted Strings Docs: [formatted strings](https://www.python.org/dev/peps/pep-0498/) -* PyFormat library for formatting strings: [PyFormat.info](https://pyformat.info/) - -#### Framebuffer - -A region of your microcontroller RAM that stores a bitmap image of your display. - -For a 128X64 monochrome display this would be 128 * 64 = 8,192 bits or 1,024 bytes (1K). Color displays must store up to 8 bytes per color for each color (red, green and blue). - -* [Wikipedia page on Framebuffer](https://en.wikipedia.org/wiki/Framebuffer) -* [MicroPython Documentation on FrameBuffer](https://docs.micropython.org/en/latest/library/framebuf.html) -] - -#### Interrupts -A type of signal used to pause a program and execute a different program. We -use interrupts to pause our program and execute a different program when a -button is pressed. - -#### I2C -A communications protocol common in microcontroller-based systems, particularly for interfacing with sensors, memory devices and liquid crystal displays. - -I2C is similar to SPI, it's a synchronous protocol because it uses a clock line. - -* Also Known as: Inter-integrated Circuit -* See also: [SPI](#spi) - -#### MicroPython - -A set of Python libraries and tools developed specifically for microcontrollers. - -MicroPython was originally developed by Damien George and first released in 2014. It includes many of the features of mainstream Python, while adding a range of new ones designed to take advantage of the facilities available on Raspberry Pi Pico and other microcontroller boards like the ESP32. - -* See also: [CircuitPython](#circuitpython) - -#### MPG Shell -A simple MicroPython shell based file explorer for ESP8266 and WiPy MicroPython based devices. - -The shell is a helper for up/downloading files to the ESP8266 (over serial line and Websockets) and WiPy (serial line and telnet). It basically offers commands to list and upload/download files on the flash FS of the device. - -[GitHub Repo for MPFShell](https://github.com/wendlers/mpfshell) - -#### OLED Display - -OLED (Organic polymer light emitting diode) dispays are small but bright displays with high contrast, low power and a wide viewing angle. We use these displays throughout our labs. The small displays are around 1" (diagonal) and only cost around $4 to $5. Larger 2.24" displays cost around $20. These displays work both with 4-wire I2C and 7-wire SPI connections. - -Typical chips that control the OLED include the SSD1306 driver chips. - -* See: [Graph Displays](../displays/graph/01-intro.md) - -#### Raspberry Pi Foundation -The company that builds the Raspberry Pi hardware and provides some software. - -#### Raspberry Pi Pico -A microcontroller designed by the Raspberry Pi foundation for doing real-time control systems. - -The Pico was introduced in 2020 with a retail list price of $4. It was a key development because it used a custom chip that had 100 times the RAM of an Arduino Nano. - -#### Pico Pinout Diagram - -The Pico pinout diagram shows you the ways that each Pin can be used. Different colors are used for GPIO numbers, I2C, and SPI interfaces. - -![](../img/pi-pico-pinout.png) - -* [Pinout PDF](https://datasheets.raspberrypi.org/pico/Pico-R3-A4-Pinout.pdf) - -#### PWM -A type of output signal used to control items with continuous values. For example, we use PWM to control the brightness of a light or the speed of a motor. We use pulse-width modulation (PWM) to control the speed of our DC motors. - -![](../img/PWM-duty-cycle.png) - -#### RP2040 chip -A custom chip created by the [Raspberry Pi Foundation](raspberry-pi-foundation) to power the [Raspberry Pi Pico](#raspberry-pi-pico). - -#### rshell - -A MicroPython shell that runs on the host and uses MicroPython's raw-REPL to send python snippets to the pyboard in order to get filesystem information, and to copy files to and from MicroPython's filesystem. - -It also has the ability to invoke the regular REPL, so rshell can be used as a terminal emulator as well. - -Note: With rshell you can disable USB Mass Storage and still copy files into and out of your pyboard. - -[RShell GitHub Repo](https://github.com/dhylands/rshell) - -#### SPI -An interface bus commonly used to send data between microcontrollers and small peripherals such as sensors, displays and SD cards. SPI uses separate clock and data lines, along with a select line to choose the device you wish to talk to. - -Also known as: Serial Peripheral Interface -See also: [I2C](#i2c) - -#### Thonny -A lightweight Python IDE ideal for writing simple Python programs for first time users. - -Thonny runs on Mac, Windows and Linux. - -* [Thonny web site](https://thonny.org/) - -#### UF2 File -The file that must be uploaded into the Raspberry Pi Pico folder to allow it to be used. - -The file name format looks like this: - -```rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2``` - -#### Unicorn -MicroPython on Unicorn is completely open source Micropython emulator - -* Github Repo: [https://github.com/micropython/micropython-unicorn](https://github.com/micropython/micropython-unicorn) - -## See Also - -[MicroPython.org Glossary](https://docs.micropython.org/en/latest/reference/glossary.html) \ No newline at end of file diff --git a/docs/misc/mermaid-test.md b/docs/misc/mermaid-test.md deleted file mode 100644 index 3d2a9aebd..000000000 --- a/docs/misc/mermaid-test.md +++ /dev/null @@ -1,16 +0,0 @@ - -```mermaid -graph LR - p[Pico] -->|ADC_VREF 36 row=6| pos(Positive) - p[Pico] -->|AGND 33 row=8| neg(Negative) - p[Pico] -->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap) - pos(Positive) --- pot(Potentiometer) - neg(Negative) --- pot(Potentiometer) - tap(Center Tap) --- pot(Potentiometer) -``` - -```mermaid -graph LR -MyApp --> DB(fa:fa-database MySQL) -style DB fill:#00758f -``` \ No newline at end of file diff --git a/docs/misc/projects.md b/docs/misc/projects.md deleted file mode 100644 index 1b65c8cd3..000000000 --- a/docs/misc/projects.md +++ /dev/null @@ -1,24 +0,0 @@ -# CoderDojo MicroPython Projects - -Projects are groups lesson plans that need to work together and frequently build on other projects. Key project areas include: - -1. **Sensors** - find low cost sensors and create a lesson around them -2. **Robot Extensions** - build extensions to our Base robot -3. **Sound and Music** - add labs that generate sound and play music -4. **OLED Displays and Graphics** - leverage the new low-cost OLED displays -5. **Debugging** - build lesson plans to help student learn how to debug MicroPython programs and use logic analyzers -6. **Advanced Labs** - using multiple cores, programming the IP processors, integrating C and assembly code - -## Projects that a In Development - -Please connect with [Dan McCreary](https://www.linkedin.com/in/danmccreary/) if you are interested in helping out with these projects. - -|Name|Status|Description| -|----|------|-----------| -|Ping HC-SR04|50%)|Create an OLED ping lab| -|Motion Sensor|0%|Create a lesson that uses a motion sensor. Use an OLED to display motion vs. time| -|Photosensor|0%|Create a lesson that will monitor light on a photo sensor| -|DS18B Temp Sensor|0%|Create a lesson that will read and display a waterproof temperature sensor| -|JoyStick|0%|Create a lesson that will read the X, Y and button of a JoyStick| -|OLED JoyStick|0%|Use a Joystick to move a ball around an OLED and paint pixels| -|OLED Game of Life|0%|Write a Game of Life with an OLED. Add a Joystick to paint initial conditions| diff --git a/docs/misc/references.md b/docs/misc/references.md deleted file mode 100644 index 526cf54bb..000000000 --- a/docs/misc/references.md +++ /dev/null @@ -1,51 +0,0 @@ -# References for MicroPython - -## Micropython References -1. [MicroPython Forum](https://forum.micropython.org/) - a good place to ask questions about MicroPython. Mostly for hard core developers. -2. [MicroPython.org site](http://micropython.org/) - We would not recommend the PyBoard for beginners. They are over 10x more expensive than the the Raspberry Pi Pico. -3. [Spider Maf Github Repo](https://github.com/SpiderMaf/PiPicoDsply) - -## Pico References -1. [MicroPython Firmware for the Raspberry Pi Pico](https://micropython.org/download/rp2-pico/) - You will want to bookmark this site. It has the firmware required to run MicroPython on your Raspberry Pi Pico. As of March 2021, they are fixing bugs weekly, so you will want to make sure your firmware is current. -2. [Pico Launch Video on YouTube](https://www.youtube.com/watch?v=o-tRJPCv0GA) -5. [Raspberry Pi Web Site Project Search](https://projects.raspberrypi.org/en/projects?software%5B%5D=micropython&hardware%5B%5D=pico) -6. [Pico Data Sheet](https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf) - you will only need this for detailed information on how to use the Pico hardware. -7. [Meet Raspberry Silicon: Raspberry Pi Pico now on sale at $4](https://www.raspberrypi.org/blog/raspberry-pi-silicon-pico-now-on-sale/) - The original Raspberry Pi Pico announcement. -8. [The journey to Raspberry Silicon](https://www.raspberrypi.org/blog/the-journey-to-raspberry-silicon/) - blog by Liam Fraser - Feb. 8th 2021. Nice story of how the Raspberry Pi Foundation created the custom silicon chip. -9. [TensorFlow Lite Micro for the Pico](https://github.com/raspberrypi/pico-tflmicro) -10. [Pico Invaders Video](https://www.youtube.com/watch?v=O5S1LC5TFiM) -12. [YouTube video of Raspberry Pi driving a full color VGA screen](https://www.youtube.com/watch?v=WaPJmCgseQw) - Full-speed high-fidelity BBC Micro emulation on a (slightly) overclocked Raspberry Pi Pico -13. [Raspberry Pi RP2040: Our Microcontroller for the Masses](https://www.arm.com/blogs/blueprint/raspberry-pi-rp2040) - James Adams, COO and Director of Hardware, Raspberry Pi -14. [ARM Blueprint post on TinyML](https://www.arm.com/blogs/blueprint/tinyml) - nice review of the Tiny Machine Learning possible on the ARM processor. -15. [Google TensorFlow engineer talking about how ARM and Google are working together on TinyML](https://www.youtube.com/watch?v=9ZIDzkhUrkY) - short 60 second video clip of Google TensorFlow engineer Ian Nappier talking about how they are working with ARM to create a standard TinyML library for all ARM processors to use. - -## Components -[Comparison of RP2040 Boards](https://docs.google.com/spreadsheets/d/e/2PACX-1vRifv83IJa38YcgPIUidSLvbNGoAa7UTeb_fuOU8i0eaYYwDU5C_8fM72aoD0LhjcMCRVXSGvhDiFHC/pubhtml?gid=0&single=true) - -## Components References -11. [2.42" OLED Display from DIY More](https://www.diymore.cc/collections/hot-products/products/2-42-inch-12864-oled-display-module-iic-i2c-spi-serial-for-arduino-c51-stm32-green-white-blue-yellow) - -## Variations of the the Raspberry Pi Pico - -1. [WeAct RP2040 board adds 16MB flash, USB-C port to Raspberry Pi Pico form factor](https://www.cnx-software.com/2022/07/13/weact-rp2040-board-adds-16mb-flash-usb-c-port-to-raspberry-pi-pico-form-factor/) - JULY 13, 2022 BY JEAN-LUC AUFRANC (CNXSOFT) - CNX SOFTWARE – EMBEDDED SYSTEMS NEWS - - -## Open-Source References - -1. [Open Source Guide](https://opensource.guide/) - -## Coding General - -* [Sam Altman on Coding](https://www.youtube.com/shorts/OK0YhF3NMpQ) - -## Getting Started Videos - -* [Raspberry Pi Pico W LESSON 1: Write Your First Program for Absolute Beginners](https://www.youtube.com/watch?v=SL4_oU9t8Ss) by Paul McWhorter. A nice gentle introduction to getting started with Thonny on the Raspberry Pi Pico. - -## Snake Game - -[Micropython Snake Game](https://github.com/hwiguna/HariFun_203_PicoSnake) - -## Turing the Raspberry Pi Pico into a Logic Analyzer - -[Make a 100MHz 24 Channel Logic Analyzer from your favorite Raspberry Pi Pico](https://www.youtube.com/watch?v=Obd1PiW7RO8&t=1s) - In this video you will learn how to setup the Raspberry Pi Pico so it can be used as a 24 channel signal analyzer. You will also see some examples using the signal analyzer decoding some different protocols like a UART, I2C-bus and 1-wire. \ No newline at end of file diff --git a/docs/misc/upip.md b/docs/misc/upip.md deleted file mode 100644 index a5274656d..000000000 --- a/docs/misc/upip.md +++ /dev/null @@ -1,19 +0,0 @@ -# MicroPython PIP (UPIP) - -MicroPython also has a package manager that can be run directly on the microcontoller. - -## Install UPIP From Thonny Package Manager - -![Thonny UPIP Search](../img/thonny-upip.png) - -![Thonny UPIP Search](../img/thonny-upip-details.png) - -## Install A Package - -Connecting to WiFi Network Name: anndan-2.4 -Waiting for connection... -1.2.3.4.Connect Time: 4641 -Ping the following address: 10.0.0.49 -Installing to: /lib/ -Warning: micropython.org SSL certificate is not validated -Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz \ No newline at end of file diff --git a/docs/motors/01-intro.md b/docs/motors/01-intro.md deleted file mode 100644 index e3998527f..000000000 --- a/docs/motors/01-intro.md +++ /dev/null @@ -1,28 +0,0 @@ -# Using MicroPython to Control Motors and Servos - -Controlling motors are one of the funnest ways to learn how to program! They give us quick hand-on feedback on what are programs are doing. Motors are used in almost all our robot project. Robots are used in many STEM courses and coding clubs around the world. Programs like the AI Racing League allow students to learn topics like Machine Learning, Computer Vision and AI. These programs all depend on our understanding of how motors work and how to control them. - -![Geared DC Hobby Motor and Wheel](../img/dc-motor.png) - - -## Motor Types -There are three types of motors we will learn how to control: - -1. DC Motors -2. Servos -3. Stepper Motors - -## Outline of Labs - -## Lab 1: Using and Transistor to Control a Motor -In this lab we will use MicroPython to turn a motor on and off. We will use the digital output from the Raspberry Pi Pico to control a transistor as a switch to control the current to a motor. We will also learn how to use a diode to to protect the transistor from flyback current. - -## Theory: What is an H-Bridge Circuit? -This lab shows a sample circuit with four switches arranged in the shape of the letter "H" with the motor at the center of the letter. By closing switches in opposite corners we can make the motor reverse direction. - -## Lab 2: Controlling a Motor Speed with the L293 H-Bridge Chip -In this lab we will use a PWM signal to control the speed of a motor. - -## Lab 3: Changing Motor Direction - -In this lab we will make a motor go both forward and backward and change the speed. \ No newline at end of file diff --git a/docs/motors/02-transistor.md b/docs/motors/02-transistor.md deleted file mode 100644 index a9fa24b52..000000000 --- a/docs/motors/02-transistor.md +++ /dev/null @@ -1,39 +0,0 @@ -# Using an Transistor to Control a Motor - -## Power Requirements for Motors - -Motors need about 200 milliamps to work. But a microcontroller like the Raspberry Pi Pico only can switch about 18 milliamps. So we need a way to control more power. - -The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the [Raspberry Pi Pico Datasheet Table 5](https://github.com/raspberrypi/documentation/blob/master/hardware/computemodule/datasheets/rpi_DATA_CM_2p0.pdf). The solution is to either use the digital output signal to turn on and off a switch such as a transistor of to use a motor driver chip such as an L293D chip. - -## Basic Transistor Circuit - -1. Transistor NPN 2222A -2. Diode: 1N1448 -3. Motor: 3-6 volt hobby motor - -![Motor Circuit](../img/motor-circuit.png) - -## PWM Control - -### PWM Frequency -Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms) - -## Sample Coder - -```py -import machine - -# set the 7th from the bottom on right as our motor pin -motor_pin = machine.Pin(21, machine.Pin.OUT) -# allocate a PWM object for controlling the motor speed -motor_pwm = machine.PWM(motor_pin) -motor_pwm.freq(50) # 50 hertz -motor_pwm.duty(51) -``` - -## References - -1. [Sparkfun Motor Lab from SIK Kit](https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-12-driving-a-motor) -2. [Nick Zoic MicroPython Motor Control Tutorial](http://mpy-tut.zoic.org/tut/motors.html) - diff --git a/docs/motors/03-h-bridge.md b/docs/motors/03-h-bridge.md deleted file mode 100644 index ae5efb362..000000000 --- a/docs/motors/03-h-bridge.md +++ /dev/null @@ -1,19 +0,0 @@ -# H-Bridge Circuits - -H-Bridge circuits are use to drive a motor both forward and backward. The circuit is called an "H-Bridge" because the arrangement of the switches around a motor form the letter "H". - -![H-Bridge Circuit](../img/h-bridge.png) - -## H-Bridge Circuit Operation - -If you connect a 5 volt power supply to a motor you will turn the motor in a specific direction such as clockwise. If you reverse the connections to the motor, the motor will turn the opposite direction such as counter-clockwise. - -In order to turn on the motor, switches 1 and 4 must be closed to allow current to flow through the motor. Switches 2 and 3 must be turned off. - -To reverse the motor direction you must open switches 1 and 4 and close switches 2 and three in the upper right and lower left portion of the diagram. - -![H-Bridge Circuit](../img/H_bridge_operating.svg.png) - -## References - -1. [Wikipedia Page on H-Bridge Circuits](https://en.wikipedia.org/wiki/H-bridge) diff --git a/docs/motors/04-l293d.md b/docs/motors/04-l293d.md deleted file mode 100644 index b18aa0748..000000000 --- a/docs/motors/04-l293d.md +++ /dev/null @@ -1,18 +0,0 @@ -# Controlling a Motor with the L293D Motor Controller Chip - - - -## What is an H-Bridge? - -## The L293D Circuit - -The L293D motor driver IC has two power input pins viz. ‘Vcc1’ and ‘Vcc2’. - -Vcc1 is used for driving the internal logic circuitry which should be 5V. - -From Vcc2 pin the H-Bridge gets its power for driving the motors which can be 4.5V to 36V. And they both sink to a common ground named GND. - -## Sample Program - -## References -[Last Minute Engineer L293D DC Motor Tutorial (Arduino version)](https://lastminuteengineers.com/l293d-dc-motor-arduino-tutorial/) \ No newline at end of file diff --git a/docs/motors/05-controller-board.md b/docs/motors/05-controller-board.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/motors/06-servos.md b/docs/motors/06-servos.md deleted file mode 100644 index 281206b8a..000000000 --- a/docs/motors/06-servos.md +++ /dev/null @@ -1,25 +0,0 @@ -# Controlling a Servo Motor with MicroPython - -## Types of Servos - -Although there are may types of servos you can purchase, in our labs there are two main types of servos that we use: - -1. SG90 Micro Servo, 9 grams, 180 degree, plastic gears - $4 -2. MG90S Micro Servo, 9 grams, 180 degree, metal gears - $5 - -There are other variations that have 360 degree or continuous rotation servos. - -## Servo Connections - -Almost all servos have a three pin connector that are spaced 1/10th of an inch apart so they will work with our breadboards. - -1. Ground (black or brown wire) -2. 5 volt power (always red) -3. Data (orange or yellow) - -## references - -1. [SparkFun Servos Page](https://www.sparkfun.com/servos) -2. [SparkFun Category for Servos](https://www.sparkfun.com/categories/245) -3. [eBay Servo Plastic Servo](https://www.ebay.com/itm/373083841236) -4. [eBay Servo Metal Gear Servo](https://www.ebay.com/itm/294180115127) diff --git a/docs/motors/07-stepper-motors.md b/docs/motors/07-stepper-motors.md deleted file mode 100644 index 838589575..000000000 --- a/docs/motors/07-stepper-motors.md +++ /dev/null @@ -1,41 +0,0 @@ -# Controlling a Stepper Motor with MicroPython - -![Stepper Motor](../img/stepper-motor.png) - -Stepper motors are specialized motors that precisely control the angle of rotation of the shaft of a motor. They are often used to carefully position items that move along an axis. For example you can use stepper motors to control the position the printing head of a 3D printer. Stepper motors are also quite a bit more expensive than our DC hobby motors and mini servos, so we don't use them frequently in our classes. - -## Sample Code - -```py -# Code example from YoungWorks blog on how to use a stepper motor -# https://www.youngwonks.com/blog/How-to-use-a-stepper-motor-with-the-Raspberry-Pi-Pico -from machine import Pin -import utime - -pins = [ - Pin(15, Pin.Out), - Pin(14, Pin.Out), - Pin(16, Pin.Out), - Pin(17, Pin.Out), -] - -# one hot encoding vectors -full_step_sequence = [ - [1.0.0.0], - [0.1.0.0], - [0.0.1.0], - [0.0.0.1] -] - -while True: - for step in full_step_sequence: - for i in rang(len(pins)): - pins[i].value(step[i]) - utime.sleep(0.001) -``` - -## References - -1. [Wikipedia Page on Stepper Motors](https://en.wikipedia.org/wiki/Stepper_motor) -2. [Raspberry Pi L293D Example](https://tutorials-raspberrypi.com/how-to-control-a-stepper-motor-with-raspberry-pi-and-l293d-uln2003a/) -3. [Young Wonks Stepper Motor Example with a ](https://www.youngwonks.com/blog/How-to-use-a-stepper-motor-with-the-Raspberry-Pi-Pico) \ No newline at end of file diff --git a/docs/projects/01-intro.md b/docs/projects/01-intro.md deleted file mode 100644 index da2f28235..000000000 --- a/docs/projects/01-intro.md +++ /dev/null @@ -1,8 +0,0 @@ -# MicroPython Projects - -## RGB Box for Kids -This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors. - -## Alarm Clock - -https://github.com/wahlencraft/pico-alarm-clock \ No newline at end of file diff --git a/docs/projects/02-rgb-box.md b/docs/projects/02-rgb-box.md deleted file mode 100644 index b99c0cd01..000000000 --- a/docs/projects/02-rgb-box.md +++ /dev/null @@ -1,74 +0,0 @@ -# Raspberry Pi RGB Box - -![RGB Box](../img/rgb-box.png) - -This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors. We use this at many science fairs or demonstration projects that has kids as young as three years old! As the kids learn to adjust the knobs, we say "Hey, your a programmer!". - -## Related Labs - -Before you do this project, it is a good idea to get familiar with the [Potentiometer lab](../basics/03-potentiometer/). This lab will show you how to hook up a single potentiometer to the Raspberry Pi Pico and read it's values. - -## Required Tools - -Although we will be using a solderless breadboard to connect the components, we use a hot-glue gun to make sure the wires don't get dislocated when the box gets bumped around. - -1. Soldering iron (unless you have pre-solders potentiometers) -2. Hot glue gun (for securing the wires to the breadboard) -3. Drill (for putting a hole in the box) - -## Parts List - -1. Raspberry Pi Pico with headers ($4) -2. 1/2 size breadboard ($2) -3. Three 10K linear potentiometers ($2) -4. LED strip with 10 NeoPixels ($2) -5. Battery case with 3 AA batteries (2) -6. 22-gauge solid hookup wire -7. Power switch (optional) (50 cents) -8. Clear plastic box (4) - -With a bit of clever shopping, you can get the total part costs: under about $15. If you purchase the parts in Quantity 10+ you can get the costs under $10/kit. - -## Circuit Diagram - -TBD - -## Assembly -Solder six-inches of hookup wire to each of the three pins on the three potentiometers. - -![Potentiometer Hookups](../img/rgb-box-potentiometer-hookups.png) - -## Sample Code - -### Test the NeoPixel Connection -Our first step will be to verify we have the NeoPixel strip connected correctly and that we have the right configuration. There are two items you might have to change: - -1. The pin number connected to the data wire of the LED strip -2. The number of pixels - -We use two Python variables to configure -```py -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 10 -``` - -```py -import machine, neopixel -from utime import sleep -from neopixel import Neopixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 10 -strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB") - -print('flashing pixel 0 red') -delay=.3 -while True: - strip.set_pixel(0, (255,0,0)) // turn pixel 0 red - strip.show() - sleep(delay) - strip.set_pixel(0, (0,0,0)) // turn pixel 0 off - strip.show() - sleep(delay) -``` - diff --git a/docs/projects/03-neopixel-strip-two-buttons.md b/docs/projects/03-neopixel-strip-two-buttons.md deleted file mode 100644 index 14e6da303..000000000 --- a/docs/projects/03-neopixel-strip-two-buttons.md +++ /dev/null @@ -1,47 +0,0 @@ -# NeoPixel Two Button Kit - -This is a low-cost (around $10) kit that is used for hackathons and activities such as a Halloween costume contest. - -## Contents -1. Raspberry Pi Pico with Headers -2. Breadboard -3. NeoPixel Strip (ideally a 1 meter strip with 60 pixels) -4. Two momentary push buttons - -## Background - -See the Basic Example for the [NeoPixel Strip](../basics/05-neopixel.md) lab. - -## Labs - -We supply a small set of "getting started" labs to demonstrate how -to program colors on the LED strip and give the perception of -motion up and down the strip. - -### Blink - -### Move - -### Fade In and Out - -```py -from neopixel import NeoPixel -from time import sleep - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(machine.Pin(LED_PIN), NUMBER_PIXELS) - -delay = .005 - -while True: - for i in range(0, 255): - strip[0] = (i,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(delay) # keep on 1/10 of a second - for i in range(255, 0, -1): - strip[0] = (i,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(delay) # keep on 1/10 of a second -``` \ No newline at end of file diff --git a/docs/projects/03-rotary-neopixel.md b/docs/projects/03-rotary-neopixel.md deleted file mode 100644 index 4cf2ced4b..000000000 --- a/docs/projects/03-rotary-neopixel.md +++ /dev/null @@ -1,146 +0,0 @@ -# Rotary NeoPixel - -This project has a rotary encoder and a button. Spinning the rotary encoder changes the pixel index. Pressing the knob of the encoder changes the color. Pressing the button changes the pattern. - -## Circuit - -We connect the two ends of the rotary (A and B) to pins 14 and 15. We connect the center pin to the 3.3v rail of the breadboard. - -Next, we connect the rotary button and the other button to pins 16 and 17 and to the 3.3v rail. - -All the buttons use PULL.DOWN option when they are configured. - -## Sample Code - -We use the rotary.py library - -```py -from machine import Pin -from rotary import Rotary - -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) -``` - -You can change the order of A and B to match the turn direction. - -## Full Source Code - -```py -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -mode_names = ['dot', 'hole', 'compare', 'chase', 'rainbow'] - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 5 - print('mode=', mode, mode_names[mode]) -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) - - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('PRESS') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('RELEASE') - color_index += 1 - color_index = color_index % (color_count - 1) - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -color_index = 0 -color = red -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - elif mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 2: - for i in range(0, NUMBER_PIXELS): - if i > val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 3: - for i in range(0, NUMBER_PIXELS): - if (i-val) % 3: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 4: - # if the val + offset is larger than the number of pixels we need to do a modulo - strip[val % (NUMBER_PIXELS)] = violet - strip[(val+1) % (NUMBER_PIXELS)] = indigo - strip[(val+2) % (NUMBER_PIXELS)] = blue - strip[(val+3) % (NUMBER_PIXELS)] = green - strip[(val+4) % (NUMBER_PIXELS)] = yellow - strip[(val+5) % (NUMBER_PIXELS)] = orange - strip[(val+6) % (NUMBER_PIXELS)] = red - # turn off the rest - strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0) - strip.write() - # print('color index', color_index) - color = colors[color_index] -``` diff --git a/docs/robots/02-base-bot.md b/docs/robots/02-base-bot.md deleted file mode 100644 index 048f688d6..000000000 --- a/docs/robots/02-base-bot.md +++ /dev/null @@ -1,461 +0,0 @@ -# Raspberry Pi Pico Micropython Base Robot - -![](../imb/../img/pico-bot.jpg) - -This lesson describes our base robot kit in the CoderDojo Twin Cities coding club. This robot is programmed entirely in Python to be consistent with our [Python Courses](https://www.coderdojotc.org/python/). - -## Base Robot Design - -Our goal is to build a robotics platform for teaching computational thinking. Here are our main design goals: - -1. Low cost (under $25) so that most students can afford their own robot -2. Open platform to make it easy to upgrade (sustainably) -3. Interchangeable parts -4. Minimal amount of soldering - -## Video - -Here is a video of the collision avoidance robot in action: - - - -[YouTube Video](https://youtu.be/0d3tF1oXu90) - -Note that the **forward-speed** and **distance-before-you-turn** can be adjusted. You can see I didn't quite get the distance right and the robot bumps into some of the barriers. - -## Connection Diagram - -Here is a connection diagram of the base robot. - -![](../img/base-bot-connection-diagram.png) - -## Power Regulation -Note that the power comes from the battery at 6 volts and is connected to the input voltage of the motor controller board. The motor controller has a voltage regulator that converts any input voltage from 6 to 12 volts down to 5 volts. The output voltage of the motor controller is then connected to the power rail on the left, which is in turn connected to the VSYS input to the Pico. The Pico, in turn, has another voltage regulator that drop the input from VSYS down to 3.3 volts on the 3.3V OUT pin. This voltage is then used to power the distance sensor. - -One of the downsides to this design is that as the batteries get low, once they drop below around 5 volts the double voltage drops cause the 3.3 OUT to become too low and the sensor becomes unreliable. A better design would be to find a motor controller that produces a stable 3.3 volts as the batteries slowly run down. Let us know if you can find one of these designs that cost under $2. - -## Hardware Description - -Here is a summary of some of the parts we use in this robot and their approximate prices as of June 2021. Some parts come from China so you might need to wait 2-3 weeks for them to arrive. - -![](../img/pico-bot-parts-list.png) - -Here is a Google sheet with these parts: - -[Detailed Parts List Google Sheet](https://docs.google.com/spreadsheets/d/1I6PwM470JuRHZVHkg1uiMuoXlsIpyv0Ak2ayZP8VWFc/edit?usp=sharing) - -### Two Wheel Drive Smart Car Chassis - -Our cars all use a standard Two Wheel Drive (2WD) SmartCar Chassis that is available in many retail outlets online. - -* [$5 Cytron 2WD Smart Car Chassis](https://www.cytron.io/p-2wd-smart-robot-car-chassis) -* [YouTube Video of Assembly](https://www.youtube.com/watch?v=H78t6dnSoG0) - note that he does not remove the backing paper on the Plexiglass and he mounts the battery on the top. We like ours on the bottom. - -### Motor Driver - -![](../img/parts/motor-driver.png) - -## Software - -All software is written in MicroPython. - -### Time-of-Flight Distance Sensor - -![](../img/parts/tof-sensor-GYUN530K.jpg) - -We are using the VL53L0X time-of-flight distance sensor. This works on an I2C bus. After you have hooked up the Power (VCC to the 3.3 rail and GND) you must hook up the I2C data and clock. - -```py -sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top -scl=machine.Pin(17) # One up from the lower right corner of the Pico -i2c=machine.I2C(0, sda=sda, scl=scl) -``` - -Many of our older robots used the ultrasonic ping sensors. The are unreliable with voltage drops as our batteries wear down. - -### Testing the Sensor Connections with the I2C Scanner - -```py -import machine -sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top -scl=machine.Pin(17) # One up from the lower right corner of the Pico -i2c=machine.I2C(0, sda=sda, scl=scl) -print("Device found at decimal", i2c.scan()) -``` - -You should see a decimal number returned. By default the I2C address is 41 (decimal) or x29 (hexadecimal). - -### Download the VL53L0X Driver - -You will need to add a VL53L0X driver file to the file system on the pico. - -We have a copy here: [https://raw.githubusercontent.com/CoderDojoTC/micropython/main/src/drivers/VL53L0X.py](https://raw.githubusercontent.com/CoderDojoTC/micropython/main/src/drivers/VL53L0X.py) - -### Time-of-Flight Sensor Test - -Once the driver file is loaded we are ready to test the time-of-flight distance sensor. - -```py -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor -while True: -# Start ranging - dist = tof.read() - print(dist) - time.sleep(.1) - -``` - -When you run this program a sequence of integers will appear in the console. The numbers usually will range from around 30 if there is an object directly in front of the sensor to a number around 1,300 for a object that is about 1.3 meters away from the sensor. There is a 1/10th of a second pause between each measurement. This can be changed in the last line of the program. - -### Motor Drive Test - -After we have the four wires connected to the motor driver, we need to make sure we get the right wires to the right motors and motor directions. This program will help you debug this. - -```py -from machine import Pin, PWM -import time # sleep - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -``` - -One thing to remember is that the "Right" refers to our orientation from the rear of the car or if we were sitting inside the car. If the robot is facing you with the sensor in the front, it is the wheel on the left that we call the "RIGHT" wheel. Very confusing! Using this naming convention will pay of as we are walking behind larger robots. - -### Sample Drive and Turn Functions - -We will need a set of function to drive our robot: - -1. Forward: both wheels going forward -2. Reverse: both wheels going in reverse -3. Turn Right: The right wheel turning backward and the left going forward -4. Turn Left: The left wheel turning backward and the right wheel going forward -5. Stop: all motors off - -Our challenge is for each of these operations we must change the value of all four PWM signals. We can never have a motor be going both forward and reverse. Here are some sample drive functions: - -```py -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -``` - - -### Turning Logic - -```py -while True: - dist = read_sensor() - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - sleep(BACKUP_TIME) - turn_right() - sleep(TURN_TIME) - else: - forward() -``` - -### Test Motor Connections - -```py -from machine import Pin, PWM -import time # sleep - -POWER_LEVEL = 65025 # usually a number from 30,000 to max of 65,025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -``` - -After you load this program, watch which wheels turn and in what direction. - -### Drive Functions - -We will define Python functions for forward, reverse, turn right and turn left. - -```py -POWER_LEVEL = 65025 - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) -``` - -### Stop All Motors Program - -One other thing to remember is that the PWM signals continue to be generated even after the main loop has stopped. This is because on the Pico, the four PWM signals are being continuously generated by an independent processors. To stop the motors you must run a separate stop program like this: - -stop-all-motors.py: - -```py -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 21 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 20 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -right_forward.duty_u16(0) -right_reverse.duty_u16(0) -left_forward.duty_u16(0) -left_reverse.duty_u16(0) -``` - -This can be frustrating at times when you can't find the stop program. I like to bring the stop program up in a separate tab when I am writing robot motor code. - -!!! TO DO - figure out how to write an interrup handler so that when the IDE STOP function is pressed the stop motors (and speaker) are stopped. - -### Collision Avoidance Logic - -## Final Program - -To get this to work on battery power up you must name the program **main.py** and save it on the Raspberry Pi Pico. - -!!! Note - Make sure you have the VL53L0X distance sensor driver installed. - -```py -from machine import Pin, PWM -from utime import sleep -import VL53L0X - -# used to blink the onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# driving parameters -POWER_LEVEL = 65025 # use a value from 20000 to 65025 -TURN_THRESHOLD = 400 # 25 cm -TURN_TIME = .25 # seconds of turning -BACKUP_TIME = .75 # seconds of backing up if obstacle detected - -# Motor pins to the L293 H-Bridge -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -# setup the PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -def read_sensor_avg(): - total = 0 - for i in range(10): - total = total + tof.read() - sleep(.01) - return int(total/10) - -tof.start() # startup the sensor - -while True: - dist = read_sensor_avg(); - print(dist) - - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - sleep(BACKUP_TIME) - led_onboard.high() - turn_right() - sleep(TURN_TIME) - else: - if dist > 1300: - print('no signal') - led_onboard.low() - else: - print('Go forward') - led_onboard.high() - forward() -``` - -## More To Explore Labs - -1. Can you change the hard-coded parameters at the begging of the program? What happens when you make the POWER_LEVEL go too high and the TURN_THRESHOLD too low? -2. What is the lowest POWER_LEVEL that will allow the robot to move? What if you changed the power from 6 volts to be 9 volts by adding two more AA batteries? -3. Can you randomly turn right or left if you encounter and object? Note you will need to import the random library and generate a random number between 0 and 2 with the random.randint(0,2) function. -4. How would you design a robot that you could adjust the parameters? What parameters would you change? What would their valid ranges be? \ No newline at end of file diff --git a/docs/robots/03-ir-sensor-bot.md b/docs/robots/03-ir-sensor-bot.md deleted file mode 100644 index 40a75ce22..000000000 --- a/docs/robots/03-ir-sensor-bot.md +++ /dev/null @@ -1,215 +0,0 @@ -# IR Collision Avoidance Bot - -Instead of our time-of-flight sensor used in our base robot, this robot uses three low-cost IR distance sensors. - -## Purchasing IR Distance Sensors - -![IR Distance Sensor](../img/parts/ir-distance-sensor.png) - -## Connecting the IR Sensors - -```py -# connections to the three IR distance sensors -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) -``` - -## Connecting the Speaker - -This robot has an optional speaker connected to GPIO Pin 21. This allows us to "hear" what signals are coming into the robot It will generate a different tone if the left, center or right sensor is detecting an object and an different tone for going straight, reversing and turning. - -The speaker is a small buzzer or a Piezoelectric speaker that can be purchased for around $1. It has one wire connected to the GPIO pin and the other connected to any GND pin or GND rail on the breadboard. - -Here are the lines related to setting up the speaker code. -```py -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -``` - -## Drive Logic - -The three IR sensors go LOW if there is an item in front of them. So the statement: - -```py -center.value() -``` - -will normally be HIGH if there is nothing in front of the robot. - -Our main logic look will look like the following: - -```py -while True: - if left.value()==0: - turn_right() - if center.value()==0: - reverse() - if right.value()==0: - turn_left() - if left.value() and center.value() and right.value(): - forward() -``` - -## Full Program - -```py -from machine import Pin, PWM -from utime import sleep -import ssd1306 - -# Motor pins to the L293 H-Bridge -RIGHT_FORWARD_PIN = 17 -RIGHT_REVERSE_PIN = 16 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# connections to the three IR distance sensors -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - -def sound_off(): - speaker.duty_u16(0) - -def left_tone(): - speaker.duty_u16(1000) - speaker.freq(700) # 1 Kilohertz - sleep(.5) # wait a 1/4 second - sound_off() - -def center_tone(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.5) - sound_off() - -def forward_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.1) - speaker.freq(900) - sleep(.1) - speaker.freq(1200) - sleep(.1) - sound_off() - -def update_oled(): - oled.fill(0) - oled.text("CoderDojo Rocks!", 0, 0, 1) - - oled.text("Left:", 0, 10, 1) - oled.text(str(left.value()), 50, 10, 1) - - - oled.text("Center:", 0, 20, 1) - oled.text(str(center.value()), 60, 20, 1) - - oled.text("Right:", 0, 30, 1) - oled.text(str(right.value()), 55, 30, 1) - - BAR_WIDTH = 40 - BAR_HEIGHT = 20 - if left.value(): - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if center.value(): - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if right.value(): - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - oled.show() - - - -# 0=stopped, 1=forward, 2=turing right, 3=turning left -drive_state = 0 -counter = 0 -while True: - if left.value()==0: - print('Left') - #left_tone() - turn_right() - update_oled() - drive_state = 2 - if center.value()==0: - print('Center') - center_tone() - reverse() - update_oled() - drive_state = 0 - if right.value()==0: - print('Right') - #right_tone() - turn_left() - update_oled() - drive_state = 3 - - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - drive_state = 1 - # forward_tone() - forward() - update_oled() - print("counter: ", counter) - counter += 1 - sleep(.25) -``` - -Pins GP6, 7, 8 and 9 \ No newline at end of file diff --git a/docs/robots/03-rainbow-bot.md b/docs/robots/03-rainbow-bot.md deleted file mode 100644 index c174f0ce9..000000000 --- a/docs/robots/03-rainbow-bot.md +++ /dev/null @@ -1,339 +0,0 @@ -# Rainbow Bot - -![Rainbow Bot Cover Image](../img/rainbow-bot.gif) - -This robot takes our base robot and adds an LED strip arranged in a 12X6 pixel grid to display colors and patterns based on what the robot is doing or thinking about. - -We use the same materials as our [Base Robot](02-base-bot.md) but we add a low-cost addressable LED strips that are easy to hook up with just power, ground and data wires added to our breadboard. The LED is known as an addressable LED strip since you can individually program each LED. The standard is called the WS-2812B LED strip and is often called a NeoPixel LED strip (The Adafruit Term). We also used a Python library called a Neopixel micropython library, although the library is not created or maintained by Adafruit. - - - - - -![LED Strip Pico Connections](../img/led-strip-pico-connections.png) - -Of course, you can also add longer LED strips and program the patterns in interesting ways. - -## Part 1: Ordering The LED Strip - -The LED strips come in a variety of lengths, density and packing. We use the 1 meter long strips that have 60 pixels/meter. These strips are easy to cut apart and solder. We like the black backgrounds but they also come with white. The LED strips come with three packaging options: - -1. No waterproofing - these are fine for our indoor robots -2. Waterproofing with the strips coated in silicon rubber called IP65 waterproofing -3. Waterproofing with the strips encased in a flexible rubber sleeve - -The waterproofing options tend to be a little more expensive but can also provide a bit more protection for the components on the strips. Waterproofing keeps moisture and dust out of the circuits, but does not mean that they can be submerged under water. - -A sample place to purchase them is [here](https://www.ebay.com/itm/333953423650?hash=item4dc12cd922%3Ag%3AsxcAAOSwND9gYtgi&LH_BIN=1) - -![](../img/led-strip-ebay-form.png) - -We can take a $3 strip of 60 LEDs and cut them up into six segments of 10 LEDs each for a cost of around 50 cents per strip. We solder stranded wire to the segments and then put 22 gauge solid wire to make them easy to put in the breadboards. - -## Connecting the LED Strips - -![](../img/rainbow-bot-connecting-strips.jpg) - -## Adding a Standoff - -![](../img/rainbow-bot-standoff.jpg) - -## Upgrading to 9 Volt Power - -Our base robot only needed power for the motors. This robot has 72 RGB LEDs so it might draw more power. So we upgraded the 6 volt battery pack with 4 AA batteries to two packs of 3 batteries for a total of 9 volts. This allows the robot to continue to run even when the batteries are partially drained. The battery packs must be wired in series to deliver the full 9 volts to the input of the motor controller where it powers the motors and also runs though a voltage regulator to power the reset of the robot. - -![](../img/rainbow-bot-underside.jpg) - -## 72 Pixel Configuration - -Here is the top view of the LEDs shining through the clear plexiglass. - -![](../img/rainbow-bot-top-view.jpg) - -You can see the individual LEDs in this configuration. By adding a small space between the plexiglass and a diffusion layer you can get a much more uniform color distribution over the top surface of the robot. - -## Part 2: Making The Connections -The LED strips use 5 volts of power and have a GND and a data connector. To make the connections we connect the center pin to Pin 0 (upper left corner of the Pico), the GND to the ground rail and the 5 volt to the 5 volt power rail. - -## Part 3: Adding the Neopixel Library - - -## Part 4: Testing Your Code -In our first test, we will just make the first pixel on the LED strip blink bright red. - -```py -import machine, neopixel, time -# Set the pin number and number of pixels -LED_PIN = machine.Pin(4) -NUMBER_PIXELS = 12 -np = neopixel.NeoPixel(LED_PIN, NUMBER_PIXELS) - -# blink the first pixel red - -while True: - np[0] = (255, 0, 0) - np.write() - time.sleep(1) - np[0] = (0, 0, 0) - np.write() - time.sleep(1) -``` - -## Functions For Drawing on Matrix -The numbering of the pixels is a bit odd. The first 12 are 0 to 11, but the second 12 pixels are in reverse order, so the second row counts from 23 down to 13. Here are some functions that demonstrate this: - -```py -import time -from neopixel import Neopixel - -numpix = 72 -strip = Neopixel(numpix, 0, 0, "GRB") - -red = (255, 0, 0) -orange = (255, 150, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -strip.brightness(255) - -def color_wipe(): - for color in colors: - for i in range(numpix): - strip.set_pixel(i, color) - strip.show() - time.sleep(0.01) - -def color_wipe_2(): - for color in colors: - for i in range(12): - strip.set_pixel(i, color) - strip.set_pixel(i+12, color) - strip.set_pixel(i+24, color) - strip.set_pixel(i+36, color) - strip.set_pixel(i+48, color) - strip.set_pixel(i+60, color) - strip.show() - time.sleep(0.01) - -def color_wipe_3(): - for color in colors: - for i in range(12): - strip.set_pixel(i, color) - strip.set_pixel(23-i, color) - strip.set_pixel(i+24, color) - strip.set_pixel(47-i, color) - strip.set_pixel(48+i, color) - strip.set_pixel(71-i, color) - strip.show() - time.sleep(0.3) - -# offset is the color to start (0 to 6) -# dir is 1 for forward and -1 for reverse -def color_wipe_4(offset, dir): - for i in range(12): - if dir == 1: - this_color = colors[ ((i-offset) %7 )] - else: - this_color = colors[ ((i+offset) %7 )] - strip.set_pixel(i, this_color) - strip.set_pixel(23-i, this_color) - strip.set_pixel(i+24, this_color) - strip.set_pixel(47-i, this_color) - strip.set_pixel(48+i, this_color) - strip.set_pixel(71-i, this_color) - strip.show() - # time.sleep(0.01) - -while True: - for counter in range(100): - color_wipe_4(counter %7, 1) - for counter in range(100): - color_wipe_4(counter%7, -1) -``` - -## Full Source Code -We now combine the motor controls, the distance sensor and the LED functions so that a moving rainbow pattern moves from to back as the robot moves forward. If the robot encounters an obstacle, the robot will backup and change the direction of the rainbow. After it backs up a bit it will turn and move forward again. - -main.py -```py -from machine import Pin, PWM -from time import sleep -from machine import Pin -from machine import I2C -import VL53L0X -from neopixel import Neopixel - -# Motor Code -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 18 -LEFT_FORWARD_PIN = 20 -LEFT_REVERSE_PIN = 21 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# Sensor Code -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor - -# used to blink the onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# LED Code -numpix = 72 -strip = Neopixel(numpix, 0, 0, "GRB") -# we turn the brightness way down to not oversaturate the brightness in the video -strip.brightness(20) - -# driving parameters -POWER_LEVEL = 30000 # use a value from 20000 to 65025 -TURN_THRESHOLD = 400 # 25 cm -TURN_TIME = .25 # seconds of turning -BACKUP_TIME = .75 # seconds of backing up if obstacle detected - -red = (255, 0, 0) -orange = (255, 165, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, green) - #strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, red) - #strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, blue) - #strip.show() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, yellow) - #strip.show() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - for i in range(numpix): - strip.set_pixel(i, violet) - strip.show() - -def read_sensor_avg(): - total = 0 - for i in range(10): - total = total + tof.read() - sleep(.01) - return int(total/10) - -# offset is the color to start (0 to 6) -# dir is 1 for forward and -1 for reverse -def color_wipe_4(offset, dir): - for i in range(12): - if dir == 1: - this_color = colors[ ((i-offset) %7 )] - else: - this_color = colors[ ((i+offset) %7 )] - strip.set_pixel(i, this_color) - strip.set_pixel(23-i, this_color) - strip.set_pixel(i+24, this_color) - strip.set_pixel(47-i, this_color) - strip.set_pixel(48+i, this_color) - strip.set_pixel(71-i, this_color) - strip.show() - # time.sleep(0.01) - -counter = 0 -while True: - dist = read_sensor_avg() - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - turn_right() - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - else: - forward() - color_wipe_4(counter % 7, 1) - counter += 1 -``` - -[Rainbow Bot Source Code](https://github.com/CoderDojoTC/micropython/tree/main/src/robots/rainbow-bot) -## References - -1. Micropython [NeoPixel Library](https://docs.micropython.org/en/v1.15/esp8266/tutorial/neopixel.html) diff --git a/docs/robots/04-face-bot.md b/docs/robots/04-face-bot.md deleted file mode 100644 index ddd02d260..000000000 --- a/docs/robots/04-face-bot.md +++ /dev/null @@ -1,5 +0,0 @@ -# MicroPython FaceBot - -This lesson will allow you to draw simple faces on the display on the front of our robots. The faces can reflect the emotions of your robot. We are inspired by the faces on the - -![Cozmo Faces](../img/cozmo-faces.png) \ No newline at end of file diff --git a/docs/robots/05-ajusta-bot.md b/docs/robots/05-ajusta-bot.md deleted file mode 100644 index df3355d0f..000000000 --- a/docs/robots/05-ajusta-bot.md +++ /dev/null @@ -1,4 +0,0 @@ -# Adjusta Bot - -This robot uses buttons and a rotary encoder to allow the user to reprogram the Pico and adjust the collision avoidance parameters. - diff --git a/docs/robots/20-faqs.md b/docs/robots/20-faqs.md deleted file mode 100644 index 23909c78b..000000000 --- a/docs/robots/20-faqs.md +++ /dev/null @@ -1,11 +0,0 @@ -# Robots Frequently Asked Questions - -## Why a two-motor three wheel robot, not four motor four wheel robot? -We evaluated both the two-motor three wheel robot and the four motor four wheel robots and found that we could achieve all our learning objectives with the two-motor three wheel version. The kits are lower cost, have a simpler assembly process and have plenty of power for our projects. - -## Why do we use the L293D vs L298N Motor Driver? -Both of these popular motor driver chips are commonly used in robot kits. Our focus is teaching the principals of computational thinking using low-cost parts. Since the L293D is lower cost and has plenty of power for our two-motor robots we chose that. There is a detailed side-by-side comparison [here] -(https://www.etechnophiles.com/l293d-vs-l298n-motor-driver-differences-specifications-and-pinouts/) - -## Why don't we just create a remote control robot car? -Remote control cars are very fun to play with. But we find that it often detracts from our mission of learning how to code. So we try to minimize the time students spend just driving their cars around our tracks. \ No newline at end of file diff --git a/docs/robots/index.md b/docs/robots/index.md deleted file mode 100644 index d542f1292..000000000 --- a/docs/robots/index.md +++ /dev/null @@ -1,48 +0,0 @@ -# Introduction to MicroPython Robots - -Robots are the most powerful learning machines in our curriculum. They allow our students to control motion with their own programs. Not only are they incredibly **fun** for our students, our students learn [computational thinking](https://www.coderdojotc.org/CoderDojoTC/computational-thinking/) and enable them to quickly proceed to our advanced AI Racing League projects. - -The Raspberry Pi Pico and the Maker Pi RP2040 components have truly been transformative for our clubs. Instead of being trapped in the 2K RAM on our Arduino systems and being forced to learn "C", our students are programming in their favorite Python language! - -## Robot Journey Map - -This section of the course takes you on a tour of our base $25 collision avoidance robots. It then builds on this robot by adding an OLED display, programming controls and servos. Here is a Journey Map of these lessons: - -![Robot Journey Map](../img/robot-journey-map.png) - -Note that the $25 price assumes you purchase low-cost parts from suppliers like eBay. You can lower the cost per robot by purchasing the parts in higher quantities for classroom use. You can also purchase older Arduino robot kits and upgrade the processors to use the Raspberry Pi Pico. - -!!! Note - This section only covers using the Raspberry Pi Pico robots with external motor drivers. We now have - many additional robot lessons that use the [Cytron Maker Pi RP2040](../kits/maker-pi-rp2040-robot/index.md) robotics board. These robots are still low-cost ($20) but have much more integrated power and are easier for - younger students to use since they don't require any breadboards or soldering. - -Our base robot is a collision avoidance robot that is ideal for teaching beginning robotics principles. The robots have one or more distance sensors on the front and will continue to move forward until they get near an object in front of them. They then will reverse and turn in another direction. We test our robots on the floor in a "Robot Corral" that has six-inch high walls. Students can adjust various parameters to allow the robot to navigate around the corral without colliding with the walls. - -![Robot Journey Map](../img/kids-in-robot-corral.jpg) - -1. **[Base Bot](02-base-bot.md)** - This is the foundational robot that the other projects are built on. The base includes a standard Smart Car chassis, two DC hobby motors, a battery pack and wheels. On top of the chassis we add a breadboard, jumpers, a motor controller, a distance sensor, and our $4 Raspberry Pi microcontroller. - -2. **[Rainbow Bot](03-rainbow-bot.md)** This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red. - -3. **[IR Sensor Bot](03-ir-sensor-bot.md)** This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red. - -4. **[Face Bot](04-face-bot.md)** - We extend the Base Bot by adding a $4 128x64 OLED display. This allows students to see the values of the distance sensor and to hear a sound when a key event occurs. - -5. **[Adjustable Parameter Bot](05-ajusta-bot.md)** - We extend the face-bot to add some buttons and knobs to allow our users to change the collision avoidance parameters such as forward speed and turning threshold distance. - -## Parts - -Our beginning Base Bot - -### Chassis - -SmartCar Chassis - -### Sensors - -* Ping Ultrasonic Distance Sensor -* IR sensors - -### Motor Controllers - diff --git a/docs/sensors/01-intro.md b/docs/sensors/01-intro.md deleted file mode 100644 index b998dfd19..000000000 --- a/docs/sensors/01-intro.md +++ /dev/null @@ -1,5 +0,0 @@ -# Sensors in MicroPython - -## Light Sensor -## Ping -## Temperature diff --git a/docs/sensors/02-photosensor.md b/docs/sensors/02-photosensor.md deleted file mode 100644 index 8099bc6f2..000000000 --- a/docs/sensors/02-photosensor.md +++ /dev/null @@ -1,42 +0,0 @@ -# Light Sensor with Raspberry Pi Pico in MicroPython - -A photoresistor is a sensor that decreases resistance when light is shined on its surface. With no light a photoresistor has high resistance in the range of megaohms. As light shines on the surface the resistance drops to kiloohms. We can use this effect as a light sensor. - -To convert the variable resistance of a photoresistor to something we can measure with our microcontroller we will need to build a small circuit that includes a 10K ohm resistor. We then measure the voltage between the photoresistor and the 10K resistor as light falls on the sensor. The top and bottom of the circuit are tied to ground and a power rail. This will move the voltage of the midpoint of the circuit. - -![Photoresistor on Breadboard](../img/photoresistor-on-breadboard.jpg) - - - -## Circuit - -![Photoresistor Circuit](../img/photoresistor-circuit.png) - -We want to make sure that we use the stable analog ground (AGND) and analog to reference voltage at either end of the circuit to protect the circuit from all the noise of the power in our processor. Using other power and ground pins will work, but power fluctuations will make the result noisy. - -## Sample Code - -Our program will first use the Analog to Digital Circuit (ADC0) as an input. On the Pico this is on pin 26. - -```py -import machine -import time -photo_pin = machine.ADC(26) - -while True: - val = photo_pin.read_u16() - print(val) - time.sleep(.2) -``` - -When you run the program a series of print values is displayed in the shell every 1/5th of a second. You can also use the Thonny plot window to see how the numbers change and you cover and uncover detector from a light source. - -## Experiments - -1. What types of devices could use a light detector? -2. How does a night-light work? How could you add an LED to the circuit so that the LED would turn on if the light level got too low? -3. Could you automatically adjust the brightness of LEDs on a costume to get brighter in a sunny room and dim if you enter a dark room? What would that code look like? - -## References - -1. [Wikipedia Page on Photoresistor](https://en.wikipedia.org/wiki/Photoresistor) \ No newline at end of file diff --git a/docs/sensors/02-pot.md b/docs/sensors/02-pot.md deleted file mode 100644 index 7a94e5821..000000000 --- a/docs/sensors/02-pot.md +++ /dev/null @@ -1,60 +0,0 @@ -# Reading a Potentiometer - - - -[Video Demo](https://youtu.be/7K_M1COfm54) - -In this lab we will hook up a Potentiometer to the [Analog to Digital Converter](../misc/glossary.md#analog-to-digital-converter) of the Raspberry Pi Pico. - - -## Connections - -Potentiometers have three wires: - -1. The ground rail -2. The center tap -3. The positive rail - -The rails are hooked up to fixed reference voltages. As you turn the know, the center tap returns a value that varies between the ground and the positive rail voltages. - -On many microcontrollers, the positive voltage is very "noisy" in that it contains voltage that varies as the components draw power. The Raspberry Pi has a special region for high-quality data gathering that is isolated from this noise. To use this section you **MUST** hook the rails to the right pins. - -ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required. - -AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and -terminating at this pin. - -|ADC_VREF 36 row=6| pos(Positive) -p[Pico]-->|AGND 33 row=8| neg(Negative) -p[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap) - pos(Positive) --- pot(Potentiometer) - neg(Negative) --- pot(Potentiometer) - tap(Center Tap) --- pot(Potentiometer) -``` - -Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins. - - -## Sampling data -Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values. - -Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples. - -```py -def sample_pot(pin, count): - total = 0 - for i in range(count): - total += int(pin.read_u16()) - utime.sleep_ms(5) - return int(total / count) -``` - - -```python -pot_pin_1 = machine.ADC(26) -# return a value after sampling 10 times -sample_pot(pot_pin_1, 10) -``` \ No newline at end of file diff --git a/docs/sensors/03-ping.md b/docs/sensors/03-ping.md deleted file mode 100644 index 8c60b99e1..000000000 --- a/docs/sensors/03-ping.md +++ /dev/null @@ -1,52 +0,0 @@ -# Ultrasonic Ping Sensor -The HC-SR04 is a low cost ($4) sensor that measures the distance to an object in front of it. - -## Wiring Diagram - -1. Connect GND to any GND pin on the Pico -2. Connect VCC to VBUS or 5 Volt power -3. Connect Trigger to pin 15. With USB on the top, this pin is the bottom left corner. -4. Connect Echo to pin 14. One up from bottom left corner. - -## Sample Code - -```py -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 15 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 14 # One up from bottom left corner - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), " cm") - utime.sleep(.25) -``` - -## OLED - -If you have a small OLED screen, you can also display the results -of the distance measurement directly on an OLED screen. - -See the OLED example here: [OLED Ping Example](../displays/graph/11-oled-ping.md) \ No newline at end of file diff --git a/docs/sensors/04-temp-dht11.md b/docs/sensors/04-temp-dht11.md deleted file mode 100644 index 8722b3e28..000000000 --- a/docs/sensors/04-temp-dht11.md +++ /dev/null @@ -1,23 +0,0 @@ -# Sensing Temperature and Humidity with the DHT11 Sensor - -## Sample Code - -```py -from machine import Pin -import utime as time -from dht import DHT11, InvalidChecksum - -DHT_PIN = 15 -# this is a bit odd, since although it is an input, we need a pull down set -dhtSensor = DHT11(Pin(DHT_PIN, Pin.OUT, Pin.PULL_DOWN)) - -while True: - temp = dhtSensor.temperature - humidity = dhtSensor.humidity/100 - print("Temp: {}°C".format(temp), "| Hum: {0:.1%}".format(humidity)) -``` - -## References - -* [Peppe80's Example](https://peppe8o.com/dht11-humidity-and-temperature-sensor-with-raspberry-pi-pico-and-micropython/) -* [Axel Örn Sigurðsson's DHT11 Driver](https://raw.githubusercontent.com/ikornaselur/pico-libs/master/src/dht11/dht.py) \ No newline at end of file diff --git a/docs/sensors/05-temp-dsb20.md b/docs/sensors/05-temp-dsb20.md deleted file mode 100644 index 066193f8a..000000000 --- a/docs/sensors/05-temp-dsb20.md +++ /dev/null @@ -1,23 +0,0 @@ -# Temp with DS18B20 - -https://randomnerdtutorials.com/micropython-ds18b20-esp32-esp8266/ - -```py -# Complete project details at https://RandomNerdTutorials.com - -import machine, onewire, ds18x20, time - -ds_pin = machine.Pin(4) -ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin)) - -roms = ds_sensor.scan() -print('Found DS devices: ', roms) - -while True: - ds_sensor.convert_temp() - time.sleep_ms(750) - for rom in roms: - print(rom) - print(ds_sensor.read_temp(rom)) - time.sleep(5) - ``` \ No newline at end of file diff --git a/docs/sensors/06-accelerometer-compass.md b/docs/sensors/06-accelerometer-compass.md deleted file mode 100644 index cceeea7fe..000000000 --- a/docs/sensors/06-accelerometer-compass.md +++ /dev/null @@ -1,190 +0,0 @@ -# MPU-9250 Accelerometer Gyroscope Compass - -The MPU-9250 by InvenSense is a nine-axis motion tracking device. It includes: - -1. A MPU-6500, which contains a 3-axis accelerometer and a 3-axis gyroscope and -2. A AK8963, the market leading 3-axis digital compass that senses magnetic fields - -(Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device - -1PCS GY-91 10DOF Accelerometer Gyroscope Compass Temp/Pressure MPU-9250 BMP-280 - -* [Art of Circuits](https://artofcircuits.com/product/10dof-gy-91-4-in-1-mpu-9250-and-bmp280-multi-sensor-module) - -## Pinouts - -1. VIN: Voltage Supply Pin -1. 3V3: 3.3v Regulator output -1. GND: 0V Power Supply -1. SCL: I2C Clock / SPI Clock -1. SDA: I2C Data or SPI Data Input -1. SDO/SAO: SPI Data output / I2C Slave Address configuration pin -1. NCS: Chip Select for SPI mode only for MPU-9250 -1. CSB: Chip Select for BMP280 - -You only need to hook the 3.3 to VIN, the GND to GND and the SCL and SDA. The other connections are not needed. - -## I2C Scanner Results - -```py -import machine -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("Device found at decimal", i2c.scan()) -``` - -Device found at decimal [104, 118] - -## MPU9250 Drivers - -[MicroPython Driver](https://github.com/tuupola/micropython-mpu9250) - -```py -import utime -from machine import I2C, Pin -from mpu9250 import MPU9250 - -i2c = I2C(scl=Pin(22), sda=Pin(21)) -sensor = MPU9250(i2c) - -print("MPU9250 id: " + hex(sensor.whoami)) - -while True: - print(sensor.acceleration) - print(sensor.gyro) - print(sensor.magnetic) - print(sensor.temperature) - - utime.sleep_ms(1000) -``` - -## LSM6DS3 Accelerometer and Gyroscope - -The LSM6DS3 is a combined 3-axis accelerometer gyroscope with an 8kb FIFO buffer and an embedded processing interrupt function for the gyro sensor, specifically for the mobile phone market. -Specifications: - -1. 3-axis accelerometer -2. 6 parameter gyroscope -3. 8K FIFO for buffering reads -4. Embedded temperature sensor -5. 3.3 logic. Any voltages above 3.3 will damage the board -6. Gyro read data speed: 6.7ks / s -7. Accelerometer read data speed: 1.7ks / s -8. Power consumption: 0.9 mA for standard rate, 1.25 mA for high-performance mode -9. Input supply voltage: 1.71V to 5V -10. Interfaces: IIC and SPI -11. Accelerometer Sensitivity Ranges: ±2/±4/±16/±8 g -12. Gyro Sensitivity Ranges: ± 125/245/500/1000/2000 degrees per second - -With LSM6DS3 breakout, you will be able to detect the motion, impact, and tilt. - -## Selecting the Accelerometer Sensitivity Range - -The sensitivity ratings for an accelerometer specify the maximum measurable acceleration that the device can sense along its measurement axis (or axes). When an accelerometer states its sensitivity as ±2/±4/±16/±8 g, it usually means that the device can be set to different ranges or scales of measurement. Here's what each of those ratings mean: - -### ±2g Sensitivity Setting - -The accelerometer can measure accelerations between -2g and +2g. This is a lower range, so it can detect small changes in acceleration with high precision. This range would be ideal for applications that require precise measurements of small movements. For example, the orientation of a screen as it is being tilted or rotated. - -### ±4g Sensitivity Setting - -In this setting, the accelerometer can measure accelerations between -4g and +4g. This provides a slightly larger range than the ±2g setting, making it suitable for applications that might experience slightly stronger forces or movements but still require a good amount of precision. - -One example is wearable fitness trackers, like smartwatches and sport bands, often have built-in accelerometers to monitor and analyze user movement. For regular walking or jogging, a ±2g accelerometer might suffice. However, for more intense activities like plyometric exercises, sprinting, or aggressive directional changes in sports like basketball or soccer, the forces exerted on the tracker can exceed 2g. These activities involve rapid starts, stops, jumps, and changes in direction. - -Why ±4g?: The accelerometer needs to capture both the subtleties of everyday motion and the higher-intensity bursts of activity without saturating or clipping the data. A ±4g range provides a good balance between sensitivity and maximum measurable acceleration, making it suitable for wearable devices intended for diverse and dynamic physical activities. - -With this capability, fitness trackers can more accurately measure and analyze the user's movements across a wider range of activities, providing better data and feedback on their workouts and performance. - -±16g: -The accelerometer can measure accelerations between -16g and +16g. This is a much broader range and is less sensitive to small movements. It's ideal for applications that are exposed to stronger forces or rapid movements, such as crash detection or certain sports applications. - -±8g: The accelerometer can measure accelerations between -8g and +8g. This provides a balance between sensitivity and range, suitable for applications that might experience moderate forces. - -In practice, these settings allow the user (or designer) to choose the best range for their application. For applications where precision in detecting small accelerations is essential, a lower range (like ±2g) would be selected. In contrast, for applications where large accelerations may occur, a higher range (like ±16g) would be more appropriate to prevent the sensor from saturating or clipping the readings. - -## Selecting Gyroscope Sensitivity Ranges - -Gyroscopes measure the rate of angular change, often referred to as the angular velocity or angular rate. The unit for this rate of change is typically represented in degrees per second (DPS). - -The sensitivity ranges for a gyroscope describe the maximum rate of rotation it can measure. When a gyroscope has sensitivity ranges listed as ±125/245/500/±1000/±2000 DPS, it means the device has multiple selectable scales or ranges of measurement. Let's break down each of these ranges: - -±125 DPS: At this setting, the gyroscope can measure angular velocities between -125 and +125 degrees per second. This is a low range and would provide high precision for slow rotational movements. For example, a slowly turning sailboat. - -±245 DPS: The device can measure angular velocities between -245 and +245 degrees per second. This offers a slightly larger range than the ±125 DPS setting. - -±500 DPS: This setting allows the gyroscope to measure between -500 and +500 degrees per second. - -±1000 DPS: The device can measure angular velocities ranging between -1000 and +1000 degrees per second. This is suitable for applications that might experience moderately fast rotations. - -±2000 DPS: At this maximum setting, the gyroscope can capture angular velocities between -2000 and +2000 degrees per second. It's best for very fast rotational movements. For example, inside a rapidly spinning ball thown in the air. - - -## Gyroscope Sensitivity Ranges and Their Applications - -Here are some examples of different applications that might be used in each of these ranges. - -### ±125 DPS - -* **Wearable Health Devices**: Devices like posture trackers which monitor the orientation of a user to ensure they are maintaining a healthy posture. -* **Human Movement Analysis**: In biomechanics or rehabilitation scenarios where slow and controlled movements are being assessed. -* **Precision Robotics**: Robots that need to make very slow, controlled, and precise rotations. - -### ±245 DPS - -* **Consumer Electronics**: Gadgets like virtual reality (VR) headsets or augmented reality (AR) devices that track head movements, where moderate but not very rapid turns are common. -* **Gaming Controllers**: For games where precise tracking of tilt and rotation is crucial for gameplay. - -### ±500 DPS - -* **Drones**: Hobby drones or quadcopters that don't perform aggressive maneuvers might fit into this range. -* **Camera Gimbal Systems**: Devices that stabilize cameras may need to compensate for moderate motions. - -### ±1000 DPS - -* **Advanced Drones**: Racing drones or those designed for aerial acrobatics that require swift and agile movements. -* **Sports Analysis**: Tracking rapid movements in sports training equipment, like baseball or golf swing analyzers. -* **Automotive Systems**: Stability control systems in vehicles that monitor and counteract skidding or rollovers. - -### ±2000 DPS - -* **High-performance Aircraft**: Certain maneuvers in aeronautical or aerospace applications might need this high range. -* **High-speed Robotics**: Robots designed for tasks that involve very rapid rotations. -* **Extreme Sports Equipment**: Equipment used in scenarios where extreme rotational velocities can occur, like certain types of motorsport or action sports. - - -Module size: 13 * 18mm - -Package Include: -1 x GY-LSM6DS3 IIC/SPI Accelerometer Tilt Angle Gyro Sensor Breakout Transfer Module - -## Settings for Robot Tracking Orientation and Position - -If we are Tracking Orientation and Position for a Small Robot we need the following: - -## 1. **Accelerometer**: - - **Sensitivity**: Given the maximum speed of 6 inches per second, the accelerometer's main role is to capture any rapid starts, stops, or changes in direction. A ±2g setting is likely sufficient for most small robot applications. If uncertain about specific accelerations or possible bumps or drops, consider a ±4g setting. - - **Purpose**: Measures acceleration and helps detect the robot's orientation with respect to the Earth's gravitational field. - -## 2. **Gyroscope**: - - **Sensitivity**: For moderate speeds and non-rapid spins, a ±250 DPS setting might be adequate. For rapid turns, a higher setting might be needed. - - **Purpose**: Measures the rate of angular change to help determine the robot's orientation. - -## 3. **Magnetometer** (if included in IMU): - - **Purpose**: Measures the Earth's magnetic field to determine the robot's heading relative to magnetic north. - -## 4. **Sensor Fusion**: - - Combine data from the accelerometer, gyroscope, and magnetometer (if available) for a comprehensive understanding of the robot's movement and orientation. - -## 5. **Additional Considerations**: - - **Wheel Encoders**: Useful for position tracking by measuring wheel rotation. - - **External Sensors**: Consider infrared, ultrasonic sensors, or computer vision techniques for advanced navigation and localization. - -Remember to test and calibrate in real-world scenarios for optimal performance. - -## References - -* [MEMS YouTube Video](https://www.youtube.com/watch?v=9X4frIQo7x0) The ingenious micro mechanisms inside your phone -* [LSM6DS3 IIC/SPI 3 Axis Accelerometer Gyroscope 6 Degrees Sensor Transfer Module](https://www.ebay.com/itm/285038122433) - on Ebay for $3 each - IIC and SPI -* [SparkFun LSM6DS3 Breakout Hookup Guide](https://learn.sparkfun.com/tutorials/lsm6ds3-breakout-hookup-guide/all) \ No newline at end of file diff --git a/docs/sensors/06-bme280.md b/docs/sensors/06-bme280.md deleted file mode 100644 index c54d2fc36..000000000 --- a/docs/sensors/06-bme280.md +++ /dev/null @@ -1,107 +0,0 @@ -# BME280 Environmental Sensor -The Bosch BME280 is a low-cost ($2) temperature, and pressure sensor that has an I2C interface. This is an ideal way to learn how to use an I2C interface. - -![](../img/bme280-sensor.jpg) - -Note mbe280 is different from the BMP280 and does not read humidity. The default address is Hex x76 or decimal 118. - -## Circuit - -The BME280 has a standard I2C interface with four wires: - -* **GND** - connect to any of the GND pins -* **VCC** - connect this to the 3.3V output of the Pico -* **SCL** - clock -* **SDA** - data - -## I2C Scanner -After you have connected your sensor you can check the connection by running a quick "I2C Scanner" to find the address of the sensor. - -```py -import machine -sda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top -scl=machine.Pin(1) # Row two of our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("Device found at decimal", i2c.scan()) -``` - -Results: -```txt -[118] -``` - -This is decimal of hex 0x76 - -If the scanner does not return a number then your connections might not be working. - -## BME280 Driver -You should be able to find the BME280 driver by using the Thonny **Tool** -> **Manage Packages...** menu. If that does not work you can try a github search: - -[Search GitHub for MBE 280 Python Code](https://github.com/search?q=MBE280+python&type=code) - -## Test Code - -```python -import machine -from utime import sleep -import BME280 -sda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top -scl=machine.Pin(1) # Row two of our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# initialize the bme class using the default address -bme = BME280() -(chip_id, chip_version) = bme.getID() -print( "Chip ID:", chip_id) -print( "Version:", chip_version) - -while True(): - # get new data from the - temperature,pressure,humidity = bme.getData() - #adj_bar = bme.adj_baro(pressure, temperature) - print("Adj {}".format(bme.adj_baro(pressure, temperature))) - - print( "Temperature: {}C".format(temperature)) - print( "Pressure: {}hpa, {}In".format(pressure, round(pressure * 0.02953, 2))) - - sleep(1) -``` - -## Code 2 - -```py -from machine import I2C -import BME280 -from time import sleep - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -bme = BME280.BME280(i2c=i2c) -# print(i2c.scan()) - -while True: - - temp = bme.temperature - hum = bme.humidity - pres = bme.pressure - # uncomment for temperature in Fahrenheit - temp = (bme.read_temperature()/100) * (9/5) + 32 - #temp = str(round(temp, 2)) + 'F' - print('Temperature: ', temp, end='') - print(' Humidity:', hum, end='') - print(' Pressure:', pres) - - sleep(5) -``` - -## References - -1. [Robert HH BME280 Test Page](https://github.com/robert-hh/BME280/blob/master/bmetest.py) -1. [Official Datasheet](https://www.bosch-sensortec.com/bst/products/all_products/bme280) -2. [eBay BME280 Sensor Search](https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2553889.m570.l1311&_nkw=bme280+sensor) -3. [Driver Sample code](https://github.com/webbhm/GBE-Digital/blob/main/python/BME280.py) -# Digital Barometric Pressure Sensor Board Swap I2C/SPI BMP280 BME280 3.3V -[BME280](https://www.ebay.com/itm/Digital-Barometric-Pressure-Sensor-Board-Swap-I2C-SPI-BMP280-BME280-3-3V/262964983464) -4. [BME280 logger](https://github.com/raymondodinzeo/pico_datalogger/blob/main/pico_datalogger) -5. [The Electronics India](https://www.theelectronics.co.in/2021/10/bme280-interfacing-raspberry-pi-pico-rp2040.html) \ No newline at end of file diff --git a/docs/sensors/07-VL53L0X_GY.md b/docs/sensors/07-VL53L0X_GY.md deleted file mode 100644 index a4f1ffe29..000000000 --- a/docs/sensors/07-VL53L0X_GY.md +++ /dev/null @@ -1,69 +0,0 @@ -# VL53L0X Time-of-Flight Laser Ranging Module IR Distance Sensor - -![](../img/VL53L0X_GY-530.png) -Figure: VL53L0X in the GY-530 package. - -The VL53L0X is a low-cost ($5) time-of-flight light-based distance sensor that is easy to use. It comes packaged in a I2C board and gives precise distance measurements up to 1.5 meters away. It measures the time that light pulses take to travel to an object and back to estimate distance. Light travels about 1 foot every nanosecond, so the timing inside this little chip must be very accurate. - -The VL53L0X integrates a group of Single Photon Avalanche Diodes (SPAD) and embeds ST Electronic's second generation FlightSense™ patented technology. The VL53L0X’s 940 nm emitter Vertical Cavity Surface-Emitting Laser (VCSEL), is safe for kids and totally invisible to the human eye. Coupled with internal physical infrared filters, the sensor enables longer ranging distance, higher immunity to ambient light, and better robustness to cover glass optical crosstalk. - -## Circuit -Hook the VCC to the 3.3 out of the Pico, the GND of the sensor to andy of the GND pins of the Pico and then connect the Clock and Data to two pins such as GPIO pins 16 and 17. - -## I2C Scanner Test - -We first run the I2C scanner program to verify that the sensor is connected correctly and is responding to the I2C bus scan. - -```py -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("Device found at decimal", i2c.scan()) -``` - -This should return a single decimal number. - -## Download The VL53L0X Driver - -If you are using Thonny, you can try to use the "Manage Packages" menu and search for the driver. - -We have a sample of the driver [here](https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py) - -## Create a Test Program - -```py -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # lower right pin -scl=machine.Pin(17) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -while True: - tof.start() - tof.read() - print(tof.read()) - tof.stop() - time.sleep(0.1) -``` - -## Use the Thonny Plot - - -## Reference Purchase links - -1. [ST Microelectronics](https://www.st.com/en/imaging-and-photonics-solutions/vl53l0x.html) -2. [User Manual](https://www.st.com/resource/en/user_manual/dm00279088-world-smallest-timeofflight-ranging-and-gesture-detection-sensor-application-programming-interface-stmicroelectronics.pdf) -3. [Ebay $4](https://www.ebay.com/itm/163960247303) -4. [Amazon $12](https://www.amazon.com/VL53L0X-Ranging-Distance-Measurement-Communication/dp/B07KDQ4XQ4) - -## eBay - -[qty 10 for $25](https://www.ebay.com/itm/294089704191?_trkparms=aid%3D1110013%26algo%3DHOMESPLICE.SIMRXI%26ao%3D1%26asc%3D232333%26meid%3D801d22bde5b0492b9bf25b83f5db6bab%26pid%3D100042%26rk%3D1%26rkt%3D3%26sd%3D313556965987%26itm%3D294089704191%26pmt%3D1%26noa%3D0%26pg%3D2508447%26algv%3DPersonalizedV5&_trksid=p2508447.c100042.m2062&amdata=cksum%3A294089704191801d22bde5b0492b9bf25b83f5db6bab%7Cenc%3AAQAFAAAB8CwJHOQPEmug4Oyzlih%252Fwh%252BnL5IO1ZGLhNU8Mre86yE3mPpr5Z2nF0yzyqMAi21lInzsea1TsKasH6WbuLk5kKptr374oiC0aiAFELJ2TSibW9y5eRtjKhL7g0A3nW3BOeEDJJz9gS03bXYao1qVTcKHURvD%252B9K2wjSGMTarhq%252Bp9mmzesOFmYNmlIzcZ6O7%252FeUO4eCL8xyqkENuP7yIF%252F9AQYDYs6EE%252B%252FrUWTGlZF49WFx2pelOb90bkPNPwQXss%252Fq3XPt3UkCzxnDhCLbtnTcv1LoW%252FAtyvmQv4oPce7nZ6HVupfgqrJeYMCHoh9R1BmRw3We79OV6MHnNvzBfDsVpg6hdYl7oa72moMqCzhxQs%252B0F1fE5gQF17Gk7mQzVOypaewXavOkagziWlpOJkB6qlYvu3EvZ96Md%252BElbqvCArK6NzmijoX9kwQvb10Km6QnsrZZsj%252Fh8tbTRUp8aEq%252FVZoSkZvHoi1EgvN07V6p2yGscAFhJcmm9UvVCRkLlTATJVbLB%252FYkQ9Ec2U%252BknlK6RQgYppl3ax4FHkLV08TfCIG0utL8TOOw6hUCyoGwdfYarFM6bs7%252F102QPzQ1r4zs8VmXuEbuJS6mKkIFjPL9uq6hGTDsBDohl6tgM%252FLjJX0MJngoUKV449xWyxg4sDAM%253D%7Campid%3APL_CLK%7Cclp%3A2508447) diff --git a/docs/sensors/08-ir-distance-sensor.md b/docs/sensors/08-ir-distance-sensor.md deleted file mode 100644 index 7cfc7ccba..000000000 --- a/docs/sensors/08-ir-distance-sensor.md +++ /dev/null @@ -1,271 +0,0 @@ -## IR Distance Sensors - -IR distance sensors are low cost (five for $3) but may have problems working in rooms with outdoor lighting. They have an adjustable potentiometer on them that can be used to adjust a triggering distance call the threshold distance. The sensors return a HIGH signal if there is no object within the threshold distance and a LOW signal if there is an object within this distance. Since the sensor threshold distance can not be adjusted programmatically they are best suited when you can manually adjust the potentiometer to change the threshold. - -![IR Distance Sensor](../img/parts/ir-distance-sensor.png) - -## Connections - -These sensors have three wires: - -1. GND - connect to a ground rail on your breadboard or directly to a GND ping on the Pico. -2. VCC - connect to the 5 volt power rail powered by the motor controller voltage regulator -3. OUT - a 5 volt digital signal that is usually 5 volts but is GND when triggered by an object - - -## Sample Python Code - -```py -# connections to the three IR distance sensors -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) -``` - -## The KY-032 -The KY-032 obstacle avoidance sensor is a four-wire distance-adjustable, infrared proximity sensor designed for wheeled robots. Also known as AD-032. - -The sensor detection distance ranges from 2cm to 40cm, it can be adjusted by turning the potentiometer knob. The operating voltage is 3.3V-5V so it is suitable for a variety of microcontrollers like Arduino, ESP32, Teensy, ESP8266, Raspberry Pi, and others. - -It has strong adaptability to ambient light and it is fairly accurate to sense changes in the surrounding environment. - -## Speaker Test - -```py -from machine import Pin, PWM -from utime import sleep - - -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def sound_off(): - speaker.duty_u16(0) - -def left_tone(): - speaker.duty_u16(1000) - speaker.freq(300) # 1 Kilohertz - sleep(.5) # wait a 1/4 second - sound_off() - -def center_tone(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.25) - sound_off() - -def forward_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.1) - speaker.freq(900) - sleep(.1) - speaker.freq(1200) - sleep(.1) - sound_off() - -# 0=stopped, 1=forward, 2=turing right, 3=turning left -drive_state = 0 -while True: - if left.value()==0: - print('Left') - left_tone() - drive_state = 2 - if center.value()==0: - print('Center') - center_tone() - drive_state = 0 - if right.value()==0: - print('Right') - right_tone() - drive_state = 3 - - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - drive_state = 1 - forward_tone() - sleep(.25) -``` - -## Full Program - -```py -from machine import Pin, PWM -from utime import sleep -import ssd1306 - -# Motor pins to the L293 H-Bridge -RIGHT_FORWARD_PIN = 17 -RIGHT_REVERSE_PIN = 16 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# connections to the three IR distance sensors -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - -def sound_off(): - speaker.duty_u16(0) - -def left_tone(): - speaker.duty_u16(1000) - speaker.freq(700) # 1 Kilohertz - sleep(.5) # wait a 1/4 second - sound_off() - -def center_tone(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.5) - sound_off() - -def forward_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.1) - speaker.freq(900) - sleep(.1) - speaker.freq(1200) - sleep(.1) - sound_off() - -def update_oled(): - oled.fill(0) - oled.text("CoderDojo Rocks!", 0, 0, 1) - - oled.text("Left:", 0, 10, 1) - oled.text(str(left.value()), 50, 10, 1) - - - oled.text("Center:", 0, 20, 1) - oled.text(str(center.value()), 60, 20, 1) - - oled.text("Right:", 0, 30, 1) - oled.text(str(right.value()), 55, 30, 1) - - BAR_WIDTH = 40 - BAR_HEIGHT = 20 - if left.value(): - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if center.value(): - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if right.value(): - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - oled.show() - -# 0=stopped, 1=forward, 2=turing right, 3=turning left -drive_state = 0 -counter = 0 -while True: - if left.value()==0: - print('Left') - #left_tone() - turn_right() - update_oled() - drive_state = 2 - if center.value()==0: - print('Center') - center_tone() - reverse() - update_oled() - drive_state = 0 - if right.value()==0: - print('Right') - #right_tone() - turn_left() - update_oled() - drive_state = 3 - - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - drive_state = 1 - # forward_tone() - forward() - update_oled() - print("counter: ", counter) - counter += 1 - sleep(.25) - ``` - - ## More to Explore - - 1. Try to change the values of the potentiometers on the sensors. What is the minimum and maximum distance you can detect and object? - 2. Does the reflectivity of the object impact the distance of the object? - 3. If you put a small mirror in front of the sensor what happens to the distance measured? - 4. Place the robot near bright sun in a window or try the robot outdoors on both a cloudy day and a sunny day? What is the change is accuracy of the sensors under these conditions? What about running the robot in the dark? diff --git a/docs/sensors/09-bme280.md b/docs/sensors/09-bme280.md deleted file mode 100644 index d7d269039..000000000 --- a/docs/sensors/09-bme280.md +++ /dev/null @@ -1 +0,0 @@ -https://diyprojectslab.com/raspberry-pi-pico-w-web-server-with-bme280/ \ No newline at end of file diff --git a/docs/sensors/10-rotary-encoder.md b/docs/sensors/10-rotary-encoder.md deleted file mode 100644 index 3b3751930..000000000 --- a/docs/sensors/10-rotary-encoder.md +++ /dev/null @@ -1,305 +0,0 @@ -# Rotary Encoder - -![Rotary Encoder](../img/rotary-encoder.png) - -A rotary encoder, or more specifically a directional rotary encoder, may look similar to a potentiometer in some ways. Both have a knob that you turn to adjust a value. But unlike a potentiometer, a rotary encoder is far more flexible in the range and precision of values it can control. Our students love to use them in their projects to change the color or patterns in an LED strip. - -Rotary encoders can be thought of as two concentric rings of switches that go on and off as you turn the knob. The switches are placed so that you can tell the direction of rotation by the order the two switches get turned on and off. They turn on and off quickly so we need a high-quality function to quickly detect their changes. And as we learned in the Button lab, switches can be noisy and have a complex state transition that must be [debounced](../basics/03-button.md) to get a good quality signal. - -![Directional Encoders](../img/Incremental_directional_encoder.gif) - -## Learning How to Monitor the Rotary Switch Transitions - -We will be using a low-cost ($1 USD) encoder that has five connectors, three for the direction and one for a momentary switch that is closed when you press the knob in. Here is the circuit that we will be using: - -![Rotary Encoder Circuit](../img/rotary-encoder-circuit.png) - -We hooked up the outer pins of the encoder to GPIO pins 16 and 17 in the lower right corner of the Pico. - -Then we hooked the center pin to the 3.3 volt rail. The Pico likes to pull switches down from the 3.3 volt rail. This means that we will not be connecting any of the pins to GND. - -We also hooked up the central press button to GPIO 22 and the 3.3 volt rail. - -We then ran this code and turned the knob: - -```py -import time -from machine import Pin - -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -while True: - print(rotaryA.value(), end='') - print(rotaryB.value()) - time.sleep(.1) -``` - -the results look like the following lines: - -``` -00 -00 -00 -10 -01 -00 -00 -00 -11 -00 -00 -00 -01 -11 -00 -``` - -Note that the bit values the encoders switches (on or off as 0 and 1) are place next to each other on the same line. We did this by making the end of the first print statement be the null string not the default newline character. - -This program prints out a LONG stream of numbers, mostly of the value ```00```. The values are printed 10 times each second. Now let's take a closer look at only the values that change. - -What we would like to do is now only print numbers if there is a change. To do this we will "pack" binary values into a two bit number by shifting the A pin value to the left: - -```py -import time -from machine import Pin - -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -# we set the old value to zero for both bits being off -old_combined = 0 -while True: - A_val = rotaryA.value() - B_val = rotaryB.value() - # a sifts by one bit and then is ORed with the B calue - new_combined = (A_val << 1) | B_val - if new_combined != old_combined: - print(A_val, end='') - print(B_val) - old_combined = new_combined - time.sleep(.1) -``` - -Now we get values that look like this: - - -``` -01 -11 -00 -01 -11 -00 -01 -11 -10 -00 -10 -00 -01 -11 -00 -10 -``` -Turning the knob clockwise we see the ```01``` before the 11 frequently - - -Turning the know counterclockwise: - -``` -00 -10 -11 -00 -10 -11 -00 -11 -00 -10 -00 -10 -01 -00 -``` - -Here we see the reverse ```10``` pattern occur more frequently. But there is noise in the switches as they open and close due to small variations in the contacts as they move. - - -``` -import time -from machine import Pin - -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -# we set the old value to zero for both bits being off -old_combined = 0 -while True: - A_val = rotaryA.value() - B_val = rotaryB.value() - # a sifts by one bit and then is ORed with the B calue - new_combined = (A_val << 1) | B_val - if new_combined != old_combined: - #print(A_val, end='') - #print(B_val) - old_combined = new_combined - if A_val == 0 and B_val == 1: - print('clock') - elif A_val == 1 and B_val == 0: - print('counter clock') - time.sleep(.1) -``` - -## The Rotary Class - -Here is one rotary class: - -[Mike Teachman Rotary Class](https://github.com/miketeachman/micropython-rotary). This is preferred since -it does not call a slow scheduler within an interrupt. - - -## Using a Scheduler - -There is another class [Gurgle Apps Rotary Encoder](https://github.com/gurgleapps/rotary-encoder/blob/main/rotary.py) that uses a scheduler within an interrupt which is not a best practice. However, we can show how this does work work with the one she created. The numbers incremented, but they didn't decrement. I had to change the pins to use the PULL_DOWN settings in the init method. - -```py -import machine -import utime as time -from machine import Pin -import micropython - -class Rotary: - - ROT_CW = 1 - ROT_CCW = 2 - SW_PRESS = 4 - SW_RELEASE = 8 - - def __init__(self,dt,clk,sw): - self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN) - self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN) - self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN) - self.last_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - self.dt_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.clk_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.sw_pin.irq(handler=self.switch_detect, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.handlers = [] - self.last_button_status = self.sw_pin.value() - - def rotary_change(self, pin): - new_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - if new_status == self.last_status: - return - transition = (self.last_status << 2) | new_status - if transition == 0b1110: - micropython.schedule(self.call_handlers, Rotary.ROT_CW) - elif transition == 0b1101: - micropython.schedule(self.call_handlers, Rotary.ROT_CCW) - self.last_status = new_status - - def switch_detect(self,pin): - if self.last_button_status == self.sw_pin.value(): - return - self.last_button_status = self.sw_pin.value() - if self.sw_pin.value(): - micropython.schedule(self.call_handlers, Rotary.SW_RELEASE) - else: - micropython.schedule(self.call_handlers, Rotary.SW_PRESS) - - def add_handler(self, handler): - self.handlers.append(handler) - - def call_handlers(self, type): - for handler in self.handlers: - handler(type) -``` - -The following were the lines that I changed: - -```py - self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN) - self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN) - self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN) -``` - -## Testing Script - -```py -from rotary import Rotary -import utime as time -from machine import Pin - -# GPIO Pins 16 and 17 are for the encoder pins. 22 is the button press switch. -rotary = Rotary(16, 17, 22) -val = 0 - -def rotary_changed(change): - global val - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('PRESS') - elif change == Rotary.SW_RELEASE: - print('RELEASE') - -rotary.add_handler(rotary_changed) - -while True: - time.sleep(0.1) -``` - -## Adding Plot - -Now I can move the knob back and forth and get consistent values that go up and down. You can turn on the plot function of Thonny to see the values consistently go up and down. - -![Rotary Encoder Plot](../img/rotery-encoder-up-and-down.png) - -## Mysterious Runtime Error on Scheduling Queue - -I did notice that the Shell output did register the following errors: - -``` -Traceback (most recent call last): - File "rotary.py", line 30, in rotary_change -RuntimeError: schedule queue full -``` - -The error also occurred on line 32. - -The following lines generated this error: - -```py -micropython.schedule(self.call_handlers, Rotary.ROT_CW) -micropython.schedule(self.call_handlers, Rotary.ROT_CCW) - -``` - -This error did not seem to impact the execution of the code. My suspicion is that this is a bug in the Micropython firmware. - -As a fix, you can use the try/except block an catch any runtime error. The pass function is a no-op (no operation) - -```py - def rotary_change(self, pin): - new_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - if new_status == self.last_status: - return - transition = (self.last_status << 2) | new_status - try: - if transition == 0b1110: - micropython.schedule(self.call_handlers, Rotary.ROT_CW) - elif transition == 0b1101: - micropython.schedule(self.call_handlers, Rotary.ROT_CCW) - except RuntimeError: - pass - self.last_status = new_status -``` -## References - -1. [Counter get stuck on "schedule queue full"](https://githubmemory.com/repo/miketeachman/micropython-rotary/issues/14) - suggest using a try/catch \ No newline at end of file diff --git a/docs/sensors/11-compass.md b/docs/sensors/11-compass.md deleted file mode 100644 index b4d95e8a2..000000000 --- a/docs/sensors/11-compass.md +++ /dev/null @@ -1,113 +0,0 @@ -# MicroPython Compass Lab - - - -[Digital Compass Lab Video](https://www.youtube.com/shorts/ed3TPN7XvnM) - -![](../img/compass-hmc5883l-on-breadboard.jpg) - -This lab will use the popular HML5883L chip to show how we can sense a magnetic field and allow our robots to sense the direction they are going. - -## About the HML5883L - -The HMC5883L is a multi-chip module able to measure magnetic sensing. It can communicate with an I2C digital interface with other devices in order to let creating applications such as low-cost compass, being used in many electronic fields like mobile phones, netbooks, consumer electronics, auto navigation systems, and personal navigation devices. - -The module works with a low voltage supply (from 2.16 to 3.6V) and also has a low power consumption (100 μA). - -HMC5883L has a 1° to 2° degrees heading accuracy, which is enough for a wide number of applications. It also allows setting its internal gain to increase resolution with a 3-bit gain control register. But increasing gain also increases noise effects. - -## Pinout - -The HMC5883L pinout has 5 PINs: - -1. Vcc: Connect to the 3.3 volt rail of the breadboard or power supply -2. GND: Ground -3. SCL: I2C clock -4. SDA: I2C data -5. DRDY: Data ready. You can use this to be notified if new data is ready in memory. We will not use this pin in our labs. The - -## Checking I2C Connections - -You can use a standard i2c-scanner program to verify that the four pins are connected correctly: - -```py -import machine - -# Change this if you are using other ports -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -print('Scanning I2C bus.') -devices = i2c.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) -``` - -For my system this returns the following report: - -``` -Scanning I2C bus. -1 devices found. -Decimal address: 30 , Hex address: 0x1e -``` - -You will notice that the scanner found a single device at hex address ```0x1e```. - -Like many sensors, this sensor uses a "memory map" to transmit it's data. You can write a quick test to verify that the values are changing by doing a read from this i2c address like this: - -```py -data = array('B', [0] * 6) -while True: - i2c.readfrom_mem_into(0x1e, 0x03, data) -``` - -Here is a program that will display the raw values. You can rotate the sensor to verify the raw values are changing. - -```py -from array import array -# create an incomming data array of 6 bytes -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -data = array('B', [0] * 6) -while True: - i2c.readfrom_mem_into(0x1e, 0x03, data) -``` - -Note that these are "raw" values because they have not been converted to easy-to-understand values by the driver. - -```py -from hmc5883l import HMC5883L -from utime import sleep - -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 - -# i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -# The default address is address=0x1e - -sensor = HMC5883L(scl=I2C_SDA_PIN, sda=I2C_SCL_PIN) - -while True: - x, y, z = sensor.read() - # print(sensor.format_result(x, y, z)) - if x <400: - print(x) - sleep(.1) -``` - -## References - -1. [PPPPE80 Magnetometer Compass with Raspberry PI Pico: GY-271 HMC5883L wiring and use with MicroPython](https://peppe8o.com/magnetometer-compass-with-raspberry-pi-pico-gy-271-hmc5883l-wiring-and-use-with-micropython/) -1. [PPPPE80 driver](https://github.com/peppe8o/rpi-pico-peppe8o/blob/main/libraries/hmc5883l.py) -3. [Data Sheet](https://cdn-shop.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf) diff --git a/docs/sensors/13-gesture.md b/docs/sensors/13-gesture.md deleted file mode 100644 index ecb74003d..000000000 --- a/docs/sensors/13-gesture.md +++ /dev/null @@ -1,183 +0,0 @@ -# Avago APDS-9960 Gesture Sensor - - - -The APDS-9960 is an I2C device with advanced Gesture detection, Proximity detection, Digital Ambient Light Sense (ALS) and Color Sense (RGBC). It incorporates an IR LED and factory-calibrated LED driver. - -## Gesture detection -Gesture detection utilizes four directional photodiodes to -sense reflected IR energy (sourced by the integrated LED) -to convert physical motion information (i.e. velocity, direction and distance) to a digital information. The architecture of the gesture engine features automatic activation -(based on Proximity engine results), ambient light subtraction, cross-talk cancelation, dual 8-bit data converters, power saving inter-conversion delay, 32-dataset FIFO, and interrupt driven I2C communication. The gesture engine -accommodates a wide range of mobile device gesturing -requirements: simple UP-DOWN-RIGHT-LEFT gestures or -more complex gestures can be accurately sensed. -![Gesture Spectral Response](../img/gesture-spectral-response.png) - - -## Code - -```py -import machine -from time import sleep_ms -from uPy_APDS9960.apds9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c = machine.I2C(0,scl=scl, sda=sda) - -apds9960=APDS9960LITE(i2c) # Enable sensor -apds9960.prox.enableSensor() # Enable Proximit sensing - -while True: - sleep_ms(25) # wait for readout to be ready - print(apds9960.prox.proximityLevel) #Print the proximity value -``` - -Returns - -``` -0 1 1 1 1 1 0 1 1 2 2 1 1 1 1 1 0 -``` - -## Ambient Light - -```py -# from https://github.com/rlangoy/uPy_APDS9960 -import machine -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -apds9960.als.enableSensor() # Enable Light sensor -sleep_ms(25) # Wait for readout to be ready - -#apds9960.powerOn(True) -#print(apds9960.statusRegister()) - -while True: - print(apds9960.als.ambientLightLevel, ' ', end='') - sleep(.1) -``` - -returns - -``` -1 1 0 0 0 0 0 0 0 0 1 1 1 4 8 10 10 10 12 16 17 19 19 20 21 21 22 25 27 30 33 35 36 37 38 33 33 34 34 34 34 34 35 36 36 38 39 40 38 37 38 40 42 45 48 49 55 61 66 73 76 76 82 93 109 132 156 169 171 173 173 171 164 160 169 165 162 162 164 163 159 158 152 148 148 145 141 135 122 106 96 101 108 89 62 48 33 20 10 5 3 1 0 0 0 0 0 0 0 1 2 4 8 14 26 45 65 91 110 121 124 127 132 150 191 225 244 244 254 288 295 243 219 259 299 287 204 99 31 10 2 1 1 1 0 -``` - -## Reading RGB - - - -```py -while True: - print(apds9960.als.ambientLightLevel,'', end='') - print(apds9960.als.redLightLevel,'', end='') - print(apds9960.als.greenLightLevel,'', end='') - print(apds9960.als.blueLightLevel) - sleep(.1) -``` - -``` -1 0 0 0 -2 0 0 1 -4 1 0 1 -8 3 2 2 -17 6 5 5 -28 14 10 8 -38 19 12 11 -37 27 15 12 -38 30 15 12 -43 29 15 14 -35 22 11 11 -26 17 9 7 -18 12 6 5 -13 7 4 3 -9 4 3 2 -``` - -## RGB Display Graph - -This program displays the red, green and blue light values as bars on an OLED display. - -```py -# from https://github.com/rlangoy/uPy_APDS9960 -from machine import Pin, I2C -import ssd1306 -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=Pin(12) -scl=Pin(13) -i2c=I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -apds9960.als.enableSensor() # Enable Light sensor -sleep_ms(25) # Wait for readout to be ready - -# display -WIDTH = 128 -ONE_THIRD_WIDTH = int(WIDTH/3) -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(red, green, blue): - oled.fill(0) - # scale red, green and blue to the height - red = int(red*4) - green = int(green*4) - blue = int(blue*3) - - oled.fill(0) - # rect_fill(x, y, width, height) - oled.fill_rect(0, HEIGHT - red, ONE_THIRD_WIDTH, red, 1) - oled.fill_rect(ONE_THIRD_WIDTH, HEIGHT - green, ONE_THIRD_WIDTH, green, 1) - oled.fill_rect(ONE_THIRD_WIDTH * 2, HEIGHT - blue, ONE_THIRD_WIDTH, blue, 1) - oled.text(str(red), 0, 56, 0) - oled.text(str(green), ONE_THIRD_WIDTH, 56, 0) - oled.text(str(blue), ONE_THIRD_WIDTH*2, 56, 0) - oled.show() - -while True: - # print(apds9960.als.ambientLightLevel,'', end='') - red = apds9960.als.redLightLevel - green = apds9960.als.greenLightLevel - blue = apds9960.als.blueLightLevel - update_display(red, green, blue) - sleep(.05) -``` - -## References - -### Using TinyML -https://www.hackster.io/mjrobot/tinyml-motion-recognition-using-raspberry-pi-pico-6b6071?f=1 - -### Datasheet -https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf - -### Other References -https://robojax.com/learn/arduino/?vid=robojax-gesture-APDS9960 - -https://upy-apds9960.readthedocs.io/en/latest/# - -https://www.youtube.com/watch?v=wH9HpP9bKwE - -https://github.com/rlangoy/uPy_APDS9960/blob/master/uPy_APDS9960/apds9960LITE.py diff --git a/docs/sensors/14-microphone.md b/docs/sensors/14-microphone.md deleted file mode 100644 index 9f5d6c6a8..000000000 --- a/docs/sensors/14-microphone.md +++ /dev/null @@ -1,38 +0,0 @@ -# Microphone - -## Basic Sound Sensor - -**Pros:** - -- low cost ($2 or less) -- able to detect if sound is present and send a digital signal -- adjustable trim pot to adjust sound level trigger level - -**Cons:** - -- low quality sound -- sound impacted by noise on the power supply -- limited frequency response - -## INMP441 - -**Pros:** - -- high quality sound -- excellent frequency response -- I2C interface -- strong isolation from power supply noise - -**Cons:** - -- slightly higher cost ($4) -- triggers must be written in software - -I2C Interface - -## INMP441 24-bit I2S Interface Omnidirectional Microphone Sensor Module - -## References - -* [Sound Detector Board on eBay](https://www.ebay.com/itm/285615094972) -* [YouTube Video Raspberry Pi Pico Audio Recorder with INMP441](https://www.youtube.com/watch?v=6AfcCyxWVEQ) - MCU Application Lab \ No newline at end of file diff --git a/docs/sensors/dht11-temp-humidity.md b/docs/sensors/dht11-temp-humidity.md deleted file mode 100644 index 13600a5e1..000000000 --- a/docs/sensors/dht11-temp-humidity.md +++ /dev/null @@ -1,14 +0,0 @@ -# The DHT22 (AM2302) Temperature and Humidity Sensor - -The DHT22 is a low-cost ($2) digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and transmits a digital signal on the data pin. - -These devices are easy to use since they have an internal analog to digital conversion. They are good for 20-80% humidity readings with 5% accuracy and 0-50°C temperature readings with ±2°C accuracy. They are designed to be polled about once every two seconds. - -## Circuit - -![DHT22 or AM2302 Temperature and Humidity Sensor](../img/AM2302-Image.png) - -## References - - -[DHT22 Datasheet (PDF)](http://j5d2v7d7.stackpathcdn.com/wp-content/uploads/2021/01/DHT22.pdf) \ No newline at end of file diff --git a/docs/sims/breadboard/index.md b/docs/sims/breadboard/index.md deleted file mode 100644 index 4b9aed088..000000000 --- a/docs/sims/breadboard/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# Breadboard Simulator - -[Breadboard Simulator Over Image](https://editor.p5js.org/dmccreary/sketches/6BlWx729A) - simulator written in P5.js - -[Vector Breadboard With Zoom](https://editor.p5js.org/dmccreary/sketches/5hZ6Tmyo2) - -[Vector Drawn Breadboard Simulator](https://editor.p5js.org/dmccreary/sketches/gZCJQoLdf) \ No newline at end of file diff --git a/docs/sims/index.md b/docs/sims/index.md deleted file mode 100644 index 7f3471156..000000000 --- a/docs/sims/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Simulators for Learning MicroPython - -* [Knowledge Graph](./knowledge-graphs/index.md) - -* [Wokwi](https://wokwi.com/micropython) - diff --git a/docs/sims/knowledge-graphs/concept-dependency.md b/docs/sims/knowledge-graphs/concept-dependency.md deleted file mode 100644 index 206bd23a9..000000000 --- a/docs/sims/knowledge-graphs/concept-dependency.md +++ /dev/null @@ -1,267 +0,0 @@ -# Concept Dependency - -## Prompt - -``` -Our next step is to create a fully connected dependency graph. -In this step, for each line or concept on this list, -please create a new list of other concepts on which it depends. -If a concept depends on a specific concept that is not listed, -then we must add it as a new concept. -This will help us determine the teaching order of the concepts. - -Return the new list as a CSV file using the following format: - -The first column is a numeric concept ID you assigned, -the second column is the concept name, -and the third column is a pipe-delimited list of the concept IDs -that the concept depends upon. - -Check your results to make sure that all concepts are -connected to at least one other concept. -``` - -## Response - -ChatGPT o1-mini Thought for 53 seconds - -Here is the CSV file containing the concepts along with their dependencies: - -```csv -ID,Concept Name,Dependencies (IDs) -1,Intro to Computational Thinking, -2,Problem Decomposition,1 -3,Pattern Recognition,1 -4,Abstraction,1 -5,Algorithm Design,1|2|3|4 -6,Basic Programming Concepts,1|5 -7,Variables in Programming,6 -8,Data Types in Programming,6|7 -9,Operators,6|7|8 -10,Control Structures,6|7|8|9 -11,Conditional Statements,10|9 -12,Loops,10 -13,General Functions in Programming,6|7|8|10 -14,Introduction to MicroPython,6 -15,Setting Up MicroPython Environment,14 -16,Syntax in MicroPython,14|15 -17,Functions in MicroPython,13|16 -18,Modules in MicroPython,16|17 -19,Input and Output,16|7|8 -20,Working with Strings,8|16 -21,Working with Numbers,8|16 -22,Lists,8|16 -23,Tuples,8|16 -24,Dictionaries,8|16 -25,Exception Handling,16|10 -26,Microcontroller Basics, -27,The Raspberry Pi Pico,26 -28,Understanding GPIO Pins,26|27 -29,Solderless Breadboards,32 -30,Breadboard Usage,29|32 -31,Circuit Basics, -32,Ohm's Law,31 -33,Resistors in Circuits,31|32 -34,LEDs in Circuits,31 -35,Using Resistors with LEDs,33|34|32 -36,Current Limiting Resistors,33|35 -37,Connecting LEDs,34|30 -38,Blinking an LED with MicroPython,37|16|28 -39,Digital Output Signals,28|16 -40,Digital Input Signals,28|16 -41,Reading Button Inputs,40|30 -42,Debouncing Switches,41|10 -43,Pull-up and Pull-down Resistors,33|41 -44,Controlling Multiple LEDs,37|38|16 -45,Using Breadboard Jumpers,30 -46,Potentiometers in Circuits,31|33 -47,Reading Analog Inputs,46|28 -48,Analog-to-Digital Conversion,47 -49,Using ADC in MicroPython,48|16 -50,Reading Potentiometer Values,49|46 -51,Pulse Width Modulation Fundamentals,6|10 -52,Implementing Pulse Width Modulation in MicroPython,51|16 -53,LED Brightness Control with Pulse Width Modulation,52|37 -54,Fading LEDs Using Pulse Width Modulation,53|12 -55,Advanced Pulse Width Modulation Techniques,54|52 -56,Servo Motors Overview,31 -57,Controlling Servo Motors,52|28|56 -58,DC Motors Overview,31 -59,Transistors as Switches,31|33 -60,Controlling Motors with Transistors,59|58 -61,Transistor Biasing Resistors,59|33 -62,Power Management with Transistors,59|61 -63,Photocells,31|33 -64,Making a Night Light,63|28|16 -65,Voltage Dividers,33|31 -66,Voltage Dividers and Sensors,65|63 -67,Time-of-Flight Sensors,31|28 -68,Interfacing Time-of-Flight Sensors,67|16 -69,I2C Protocol,70|16 -70,SPI Protocol,28|16 -71,Connecting I2C Devices,69|28 -72,LED Displays Overview,34|31 -73,Organic Light-Emitting Diode Displays,72 -74,Display Drawing,73|16 -75,Drawing Circles and Ellipses,74 -76,Drawing Polygons,74 -77,Changing Fonts,74 -78,Advanced I2C,69|16 -79,Advanced SPI,70|16 -80,WS2812B LED Strips,34|31 -81,LED Strip Code,80|16 -82,Moving Pixels on LED Strips,81|12 -83,LED Strip Patterns,81|82 -84,LED Strip Button Demos,83|41 -85,Sensors and Actuators,31|28 -86,Integrating Multiple Sensors,85|16 -87,Event-Driven Programming,6|10 -88,Interrupts,28|87 -89,Using Interrupts with GPIO Pins,88|28 -90,Debouncing with Interrupts,89|42 -91,Timers,6|16 -92,Delays and Timing Functions,91|16 -93,Using the Time Module,92|16 -94,Data Logging with MicroPython,16|97 -95,Storing Data on Raspberry Pi Pico,94|27 -96,File Handling,16|95 -97,Universal Serial Bus Communication,27|16 -98,Universal Asynchronous Receiver-Transmitter Communication,27|16 -99,Introduction to Sensors,31 -100,Temperature Sensors,99|28 -101,Interfacing Temperature Sensors,100|16 -102,Humidity Sensors,99|28 -103,Using DHT11 and DHT22 Sensors,101|102 -104,Reading Sensor Data,103|16 -105,Interpreting Sensor Data,104 -106,Calibrating Sensors,105 -107,Introduction to Actuators,31 -108,Controlling Relays,107|16 -109,Relays Overview,107 -110,Relays Safety,109 -111,Stepper Motors,31 -112,Controlling Stepper Motors,111|16 -113,Using Stepper Motor Drivers,112|28 -114,Generating Sound with Buzzers,31|28 -115,Using Piezoelectric Buzzers,114|16 -116,Generating Tones and Melodies,115|12 -117,Infrared Communication,28|16 -118,Using Infrared Sensors,117|31 -119,Infrared Remote Control,118|16 -120,Ultrasonic Sensors,99|28 -121,Serial Communication Protocols,27|16 -122,I2C vs SPI vs UART,69|70|98 -123,Data Communication Principles,121 -124,Wireless Communication Basics,123 -125,Bluetooth Low Energy,124|27 -126,Wi-Fi Connectivity,124|27 -127,Python Modules Overview,16 -128,Internet of Things Concepts,124|27 -129,Connecting to the Internet,126|16 -130,Sending Data to Web Servers,129|16 -131,Hypertext Transfer Protocol Basics,130 -132,Message Queuing Telemetry Transport Protocol,130 -133,IoT Applications,128|130 -134,Cloud Services Integration,133 -135,Data Visualization Tools,134 -136,Programming Best Practices,6 -137,Code Optimization Techniques,136 -138,Debugging Techniques,16|136 -139,Using Debugging Tools,138 -140,Version Control Systems,6 -141,Using Git for Code Management,140 -142,Collaborative Coding Practices,141 -143,Documentation Standards,136 -144,Commenting Code Effectively,136 -145,Advanced MicroPython Features,16 -146,Object-Oriented Programming,6|136 -147,Classes and Objects,146 -148,Inheritance and Polymorphism,147 -149,Encapsulation in Object-Oriented Programming,147 -150,Designing Reusable Code,146|149 -151,Memory Management,16|136 -152,Managing Resources Efficiently,151 -153,Energy Efficiency in Programming,152 -154,Sleep Modes in Microcontrollers,153|27 -155,Battery-Powered Projects,154 -156,Power Management Techniques,155 -157,Advanced Electronics Concepts,31 -158,Capacitors in Circuits,157 -159,Inductors and Coils,157 -160,Diodes and Rectification,157 -161,Voltage Regulation,160 -162,Using Voltage Regulators,161 -163,Building Power Supplies,162 -164,Analog Signals vs Digital Signals,31|157 -165,Signal Conditioning,164|157 -166,Filtering Noise in Circuits,165 -167,Interference and Shielding,166 -168,Electromagnetic Compatibility,167 -169,Circuit Design Principles,157 -170,Using Simulation Tools,169 -171,Prototyping Techniques,169 -172,Schematic Diagram Reading,169 -173,Understanding Datasheets,169 -174,Component Specifications,173 -175,Safety in Electronics,157 -176,Electrostatic Discharge Precautions,175 -177,Soldering Techniques,175 -178,Printed Circuit Board Design,169 -179,Using PCB Design Software,178 -180,Fabricating Custom PCBs,179 -181,Advanced Sensor Integration,85|157 -182,Gesture Recognition Sensors,181|28 -183,Touch Sensors,181|28 -184,Environmental Monitoring,181|105 -185,Robotics Basics,31|157 -186,Building Simple Robots,185|16 -187,Line-Following Robots,186|83 -188,Obstacle Avoidance Robots,186|120 -189,Control Systems Basics,185 -190,Feedback Mechanisms,189 -191,Proportional-Integral-Derivative Controllers,190 -192,Machine Learning Concepts,6|136 -193,Using MicroPython for Artificial Intelligence,192|16 -194,Edge Computing,193|128 -195,Ethics in Technology,6 -196,Future Trends in Computing,195 -``` - -**Notes:** - -- **Added Concepts:** No additional concepts were required as dependencies were within the provided list. -- **Connectivity Check:** All concepts are connected to at least one other concept through dependencies. -- **Formatting:** The dependencies are listed using concept IDs, separated by a pipe (`|`) as per your instructions. - -### Explanation of Dependencies for Selected Concepts - -- **Concept 1:** Intro to Computational Thinking - - - **Dependencies:** None (foundational concept). -- **Concept 26:** Microcontroller Basics - - - **Dependencies:** None (introduces the hardware aspect). -- **Concept 27:** The Raspberry Pi Pico - - - **Dependencies:** Depends on Microcontroller Basics (26) for understanding microcontrollers. -- **Concept 38:** Blinking an LED with MicroPython - - - **Dependencies:** Connecting LEDs (37), Syntax in MicroPython (16), Understanding GPIO Pins (28). -- **Concept 57:** Controlling Servo Motors - - - **Dependencies:** Implementing PWM in MicroPython (52), Understanding GPIO Pins (28), Servo Motors Overview (56). -- **Concept 95:** Storing Data on Raspberry Pi Pico - - - **Dependencies:** Data Logging with MicroPython (94), The Raspberry Pi Pico (27). -- **Concept 128:** Internet of Things Concepts - - - **Dependencies:** Wireless Communication Basics (124), The Raspberry Pi Pico (27). -- **Concept 193:** Using MicroPython for Artificial Intelligence - - - **Dependencies:** Machine Learning Concepts (192), Syntax in MicroPython (16). - -### Final Remarks - -- The dependencies are designed to ensure that each concept builds upon the necessary foundational knowledge. -- This structure will aid in determining an effective teaching order for the course, ensuring that students have the requisite background before approaching more advanced topics. -- By maintaining clear dependencies, the course can be structured to enhance learning progression and retention. \ No newline at end of file diff --git a/docs/sims/knowledge-graphs/concept-enumeration.md b/docs/sims/knowledge-graphs/concept-enumeration.md deleted file mode 100644 index de3a5f751..000000000 --- a/docs/sims/knowledge-graphs/concept-enumeration.md +++ /dev/null @@ -1,430 +0,0 @@ -# Learning Concept Enumeration - -## Prompt - -```linenums="0" -Raspberry Pi Pico, and solderless breadboards. -In our labs, we also use many parts such as photosensors, potentiometers, LEDs, resistors, transistors, time-0f-flight sensors, WS2812B LED strips, 128x64 OLED displays, motors, and the Cytron Maker Pi RP2040, which has the same RP2040 microcontroller. - -We have a lot of material and lesson plans right now, but I would like an overall list of the 200 key concepts we need to cover in this course. - -For this course, please create a list of the core learning concepts that we need to present in this course and the order in which they should be taught. - -Please create a list of the 200 most essential concepts -in this course. -Return the concept's preferred label in a numbered list for each learning concept. -Make sure that the concept names are distinct and not synonyms. Don't repeat - -Start with the most basic foundational concepts and then -proceed to the most complex concepts. Return just one concept label per line. -Avoid using acronyms or abbreviations. - - - -## Response - -ChatGPT o1-preview Thought for 22 seconds - -1. Intro to Computational Thinking -2. Problem Decomposition -3. Pattern Recognition -4. Abstraction -5. Algorithm Design -6. Basic Programming Concepts -7. Variables -8. Data Types -9. Operators -10. Control Structures -11. Conditional Statements -12. Loops -13. Functions -14. Introduction to MicroPython -15. Setting Up MicroPython Environment -16. Syntax -17. Variables -18. Data Types -19. Input and Output -20. Working with Strings -21. Working with Numbers -22. Lists -23. Tuples -24. Dictionaries -25. Functions -26. Modules -27. Exception Handling -28. The Raspberry Pi Pico -29. The Thonny IDE -30. Microcontroller Basics -31. Understanding GPIO Pins -32. Solderless Breadboards -33. Breadboard Usage -34. Circuit Basics -35. Ohm's Law -36. Resistors in Circuits -37. LEDs in Circuits -38. Using Resistors with LEDs -39. Current Limiting Resistors -40. Connecting LEDs -41. Blinking an LED with MicroPython -42. Digital Output Signals -43. Digital Input Signals -44. Reading Button Inputs -45. Debouncing Switches -46. Pull-up and Pull-down Resistors -47. Controlling Multiple LEDs -48. Using Breadboard Jumpers -49. Potentiometers in Circuits -50. Reading Analog Inputs -51. Analog-to-Digital Conversion -52. Using ADC -53. Reading Potentiometer Values -54. LED Brightness with PWM -55. Pulse Width Modulation -56. Using Pulse Width Modulation -57. Fading an LED with PWM -58. Controlling Servo Motors -59. Servo Motors -60. DC Motors -61. Transistors as Switches -62. Transistors Motors Control -63. Transistor Bias Resistors -64. Transistors Power -65. Photocells -66. Making a Night Light -67. Voltage Dividers -68. Voltage Dividers and Sensors -69. Time-of-Flight Sensors -70. Interfacing Time-of-Flight Sensors -71. I2C Protocol -72. SPI Protocol -73. Connecting Inter-Integrated Circuit Devices -74. LED Displays -75. OLED Displays -76. Display Drawing -77. Drawing Circles and Ellipse -78. Drawing Polygons -79. Changing Fonts -80. Advanced I2C -81. Advanced SPI -82. WS2812B LED Strips -83. LED Strip Code -84. Moving Pixels on LED Strips -85. LED Strip Patterns -86. LED Strip Button Demos -87. Sensors and Actuators -88. Integrating Multiple Sensors -89. Event-Driven Programming -90. Interrupts -91. Using Interrupts with GPIO Pins -92. Debouncing with Interrupts -93. Timers -94. Delays and Timing Functions -95. Using the Time Module -96. Data Logging with MicroPython -97. Storing Data on Raspberry Pi Pico -98. File Handling -99. USB -100. UART -101. Introduction to Sensors -102. Temperature Sensors -103. Interfacing Temperature Sensors -104. Humidity Sensors -105. Using DHT11 and DHT22 Sensors -106. Reading Sensor Data -107. Interpreting Sensor Data -108. Calibrating Sensors -109. Introduction to Actuators -110. Controlling Relays -111. Relays -112. Relays Safety -113. Stepper Motors -114. Controlling Stepper Motors -115. Using Stepper Motor Drivers -116. Advanced PWM -117. Generating Sound with Buzzers -118. Using Piezoelectric Buzzers -119. Generating Tones and Melodies -120. Infrared Communication -121. Using Infrared Sensors -122. Infrared Remote Control -123. Ultrasonic Sensors -124. Time-of-Flight Sensors -125. Serial Communication Protocols -126. I2C vs SPI vs UART -127. Data Communication Principles -128. Wireless Communication Basics -129. Bluetooth Low Energy -130. Wi-Fi Connectivity -131. Python Modules -132. IoT -133. Connecting to the Internet -134. Sending Data to Web Servers -135. Hypertext Transfer Protocol Basics -136. MQTT -137. IoT Applications -138. Cloud Services Integration -139. Data Visualization Tools -140. Programming Best Practices -141. Code Optimization Techniques -142. Debugging Techniques -143. Using Debugging Tools -144. Version Control Systems -145. Using Git for Code Management -146. Collaborative Coding Practices -147. Documentation Standards -148. Commenting Code Effectively -149. Advanced MicroPython Features -150. Object-Oriented Programming -151. Classes and Objects -152. Inheritance and Polymorphism -153. Encapsulation in OOP -154. Designing Reusable Code -155. Memory Management -156. Managing Resources Efficiently -157. Energy Efficiency -158. Sleep Modes in Microcontrollers -159. Battery-Powered Projects -160. Power Management Techniques -161. Advanced Electronics Concepts -162. Capacitors in Circuits -163. Inductors and Coils -164. Diodes and Rectification -165. Voltage Regulation -166. Using Voltage Regulators -167. Building Power Supplies -168. Analog Signals vs. Digital Signals -169. Signal Conditioning -170. Filtering Noise in Circuits -171. Interference and Shielding -172. Electromagnetic Compatibility -173. Circuit Design Principles -174. Using Simulation Tools -175. Prototyping Techniques -176. Schematic Diagram Reading -177. Understanding Datasheets -178. Component Specifications -179. Safety in Electronics -180. Electrostatic Discharge Precautions -181. Soldering Techniques -182. Printed Circuit Board Design -183. Using PCB Design Software -184. Fabricating Custom PCB -185. Advanced Sensor Integration -186. Gesture Recognition Sensors -187. Touch Sensors -188. Environmental Monitoring -189. Robotics Basics -190. Building Simple Robots -191. Line-Following Robots -192. Obstacle Avoidance Robots -193. Control Systems Basics -194. Feedback Mechanisms -195. PID Controllers -196. Machine Learning Concepts -197. Using MicroPython for AI -198. Edge Computing -199. Ethics in Technology -200. Future Trends in Computing - -## Original List - -- Introduction to Computational Thinking -- Problem Decomposition -- Pattern Recognition -- Abstraction -- Algorithm Design -- Basic Programming Concepts -- Variables in Programming -- Data Types in Programming -- Operators in Programming -- Control Structures in Programming -- Conditional Statements -- Loops in Programming -- Functions in Programming -- Introduction to MicroPython -- Setting Up MicroPython Environment -- Syntax in MicroPython -- Variables in MicroPython -- Data Types in MicroPython -- Input and Output in MicroPython -- Working with Strings in MicroPython -- Working with Numbers in MicroPython -- Lists in MicroPython -- Tuples in MicroPython -- Dictionaries in MicroPython -- Functions in MicroPython -- Modules in MicroPython -- Exception Handling in MicroPython -- Introduction to Raspberry Pi Pico -- Setting Up Raspberry Pi Pico -- Microcontroller Basics -- Understanding GPIO Pins -- Breadboard Basics -- Solderless Breadboard Usage -- Circuit Basics -- Ohm's Law -- Resistors in Circuits -- LEDs in Circuits -- Using Resistors with LEDs -- Current Limiting Resistors -- Connecting LEDs to Raspberry Pi Pico -- Blinking an LED with MicroPython -- Digital Output Signals -- Digital Input Signals -- Reading Button Inputs -- Debouncing Switches -- Pull-up and Pull-down Resistors -- Controlling Multiple LEDs -- Using Breadboard Jumpers -- Potentiometers in Circuits -- Reading Analog Inputs -- Analog-to-Digital Conversion -- Using the ADC on Raspberry Pi Pico -- Reading Potentiometer Values -- Controlling LED Brightness with Pulse Width Modulation -- Pulse Width Modulation -- Using Pulse Width Modulation in MicroPython -- Fading an LED with Pulse Width Modulation -- Controlling Servo Motors -- Using Servo Motors with Raspberry Pi Pico -- Interfacing Direct Current Motors -- Transistors as Switches -- Using Transistors to Control Motors -- Understanding NPN Transistors -- Understanding PNP Transistors -- Using Photocells in Circuits -- Reading Light Levels with Photocells -- Voltage Dividers -- Using Voltage Dividers with Sensors -- Time-of-Flight Sensors -- Interfacing Time-of-Flight Sensors -- Inter-Integrated Circuit Communication Protocol -- Using Inter-Integrated Circuit in MicroPython -- Connecting Inter-Integrated Circuit Devices -- Organic Light-Emitting Diode Displays -- Using 128x64 Organic Light-Emitting Diode Displays -- Displaying Text on Organic Light-Emitting Diode Displays -- Displaying Graphics on Organic Light-Emitting Diode Displays -- Understanding Display Coordinates -- Using Fonts on Organic Light-Emitting Diode Displays -- Serial Peripheral Interface Communication Protocol -- Using Serial Peripheral Interface in MicroPython -- WS2812B Light-Emitting Diode Strips -- Controlling WS2812B Light-Emitting Diodes -- Using Neopixel Library -- Creating Color Effects on WS2812B Light-Emitting Diodes -- Programming Color Patterns -- Sensors and Actuators -- Integrating Multiple Sensors -- Event-Driven Programming -- Interrupts in MicroPython -- Using Interrupts with GPIO Pins -- Debouncing with Interrupts -- Timers in MicroPython -- Delays and Timing Functions -- Using the Time Module -- Data Logging with MicroPython -- Storing Data on Raspberry Pi Pico -- File Handling in MicroPython -- Communicating with Personal Computer over Serial -- Using Universal Asynchronous Receiver-Transmitter Communication -- Introduction to Sensors -- Temperature Sensors -- Interfacing Temperature Sensors -- Humidity Sensors -- Using DHT11 and DHT22 Sensors -- Reading Sensor Data -- Interpreting Sensor Data -- Calibrating Sensors -- Introduction to Actuators -- Controlling Relays -- Using Relays with Raspberry Pi Pico -- Safety Precautions with Relays -- Stepper Motors -- Controlling Stepper Motors -- Using Stepper Motor Drivers -- Advanced Pulse Width Modulation Techniques -- Generating Sound with Buzzers -- Using Piezoelectric Buzzers -- Generating Tones and Melodies -- Infrared Communication -- Using Infrared Sensors -- Infrared Remote Control -- Ultrasonic Sensors -- Measuring Distance with Ultrasonic Sensors -- Serial Communication Protocols -- Inter-Integrated Circuit vs Serial Peripheral Interface vs Universal Asynchronous Receiver-Transmitter -- Data Communication Principles -- Wireless Communication Basics -- Bluetooth Low Energy -- Wi-Fi Connectivity -- Using ESP8266 Modules -- Internet of Things Concepts -- Connecting to the Internet -- Sending Data to Web Servers -- Hypertext Transfer Protocol Basics -- Using Message Queuing Telemetry Transport Protocol -- Building Internet of Things Applications -- Cloud Services Integration -- Data Visualization Tools -- Programming Best Practices -- Code Optimization Techniques -- Debugging Techniques -- Using Debugging Tools -- Version Control Systems -- Using Git for Code Management -- Collaborative Coding Practices -- Documentation Standards -- Commenting Code Effectively -- Advanced MicroPython Features -- Object-Oriented Programming -- Classes and Objects in MicroPython -- Inheritance and Polymorphism -- Encapsulation in Object-Oriented Programming -- Designing Reusable Code -- Memory Management -- Managing Resources Efficiently -- Energy Efficiency in Programming -- Sleep Modes in Microcontrollers -- Battery-Powered Projects -- Power Management Techniques -- Advanced Electronics Concepts -- Capacitors in Circuits -- Inductors and Coils -- Diodes and Rectification -- Voltage Regulation -- Using Voltage Regulators -- Building Power Supplies -- Analog Signals vs. Digital Signals -- Signal Conditioning -- Filtering Noise in Circuits -- Interference and Shielding -- Electromagnetic Compatibility -- Circuit Design Principles -- Using Simulation Tools -- Prototyping Techniques -- Schematic Diagram Reading -- Understanding Datasheets -- Component Specifications -- Safety in Electronics -- Electrostatic Discharge Precautions -- Soldering Techniques -- Introduction to Printed Circuit Board Design -- Using Printed Circuit Board Design Software -- Fabricating Custom Printed Circuit Boards -- Advanced Sensor Integration -- Gesture Recognition Sensors -- Touch Sensors -- Environmental Monitoring -- Robotics Basics -- Building Simple Robots -- Line-Following Robots -- Obstacle Avoidance Robots -- Control Systems Basics -- Feedback Mechanisms -- Proportional-Integral-Derivative Controllers -- Machine Learning Concepts -- Using MicroPython for Artificial Intelligence -- Edge Computing -- Ethics in Technology -- Future Trends in Computing diff --git a/docs/sims/knowledge-graphs/concept-taxonomy.md b/docs/sims/knowledge-graphs/concept-taxonomy.md deleted file mode 100644 index d088c7da8..000000000 --- a/docs/sims/knowledge-graphs/concept-taxonomy.md +++ /dev/null @@ -1,295 +0,0 @@ -# Concept Taxonomy - -## Prompt - -```linenums="0" -I am very pleased with these results. Now, can you suggest a -taxonomy to classify each of these learning concepts? Perhaps -about 10 different classifications? -``` - -## Response - -ChatGPT o1-min Thought for a couple of seconds - -I'm glad to hear that you're pleased with the results so far! Creating a taxonomy to classify your 197 learning concepts will help organize the curriculum, ensure comprehensive coverage, and facilitate a logical progression of topics. Below is a suggested taxonomy with **10 classifications**, each accompanied by a description and examples of relevant concepts from your list. - - -### 1. Computational Thinking Foundations - -**Description:** -Covers the basic principles and strategies of computational thinking, essential for problem-solving and algorithm development. - -**Relevant Concepts:** - -- Intro to Computational Thinking (1) -- Problem Decomposition (2) -- Pattern Recognition (3) -- Abstraction (4) -- Algorithm Design (5) - -### 2. Programming Fundamentals - -**Description:** -Introduces the core concepts of programming that are applicable across various programming languages and environments. - -**Relevant Concepts:** - -- Basic Programming Concepts (6) -- Variables in Programming (7) -- Data Types in Programming (8) -- Operators (9) -- Control Structures (10) -- Conditional Statements (11) -- Loops (12) -- General Functions in Programming (13) - - -### 3. MicroPython Programming - -**Description:** -Focuses on programming using MicroPython, including syntax, environment setup, and MicroPython-specific features. - -**Relevant Concepts:** - -- Introduction to MicroPython (14) -- Setting Up MicroPython Environment (15) -- Syntax in MicroPython (16) -- Functions in MicroPython (17) -- Modules in MicroPython (18) -- Input and Output (19) -- Working with Strings (20) -- Working with Numbers (21) -- Lists (22) -- Tuples (23) -- Dictionaries (24) -- Exception Handling (25) -- Advanced MicroPython Features (145) -- Using MicroPython for Artificial Intelligence (193) - -### 4. Hardware Components and Interfacing - -**Description:** -Explores the physical components used in projects and how to interface them with the Raspberry Pi Pico. - -**Relevant Concepts:** - -- Microcontroller Basics (26) -- The Raspberry Pi Pico (27) -- Understanding GPIO Pins (28) -- Solderless Breadboards (32) -- Breadboard Usage (30) -- Using Breadboard Jumpers (45) -- LED Displays Overview (72) -- Organic Light-Emitting Diode Displays (73) -- WS2812B LED Strips (80) - -### **5. Electronics Basics** - -**Description:** -Introduces fundamental electronics concepts necessary for building and understanding circuits. - -**Relevant Concepts:** - -- Circuit Basics (31) -- Ohm's Law (32) -- Resistors in Circuits (33) -- LEDs in Circuits (34) -- Using Resistors with LEDs (35) -- Current Limiting Resistors (36) -- Transistors as Switches (59) -- Capacitors in Circuits (158) -- Inductors and Coils (159) -- Diodes and Rectification (160) -- Voltage Regulation (161) -- Analog Signals vs Digital Signals (164) -- Signal Conditioning (165) -- Filtering Noise in Circuits (166) -- Interference and Shielding (167) -- Electromagnetic Compatibility (168) -- Circuit Design Principles (169) -- Safety in Electronics (175) -- Electrostatic Discharge Precautions (176) -- Soldering Techniques (177) - -### 6. Sensor Integration - -**Description:** -Covers various sensors, their functionalities, and how to integrate and interpret data from them. - -**Relevant Concepts:** - -- Introduction to Sensors (99) -- Temperature Sensors (100) -- Interfacing Temperature Sensors (101) -- Humidity Sensors (102) -- Using DHT11 and DHT22 Sensors (103) -- Reading Sensor Data (104) -- Interpreting Sensor Data (105) -- Calibrating Sensors (106) -- Photocells (63) -- Making a Night Light (64) -- Voltage Dividers (65) -- Voltage Dividers and Sensors (66) -- Time-of-Flight Sensors (67) -- Interfacing Time-of-Flight Sensors (68) -- Gesture Recognition Sensors (182) -- Touch Sensors (183) -- Environmental Monitoring (184) -- Ultrasonic Sensors (120) -- Advanced Sensor Integration (181) - -### **7. Actuator Control** - -**Description:** -Focuses on controlling various actuators such as motors, servos, and relays to perform physical actions. - -**Relevant Concepts:** - -- Introduction to Actuators (107) -- Controlling Relays (108) -- Relays Overview (109) -- Relays Safety (110) -- Stepper Motors (111) -- Controlling Stepper Motors (112) -- Using Stepper Motor Drivers (113) -- Servo Motors Overview (56) -- Controlling Servo Motors (57) -- DC Motors Overview (58) -- Transistors as Switches (59) -- Controlling Motors with Transistors (60) -- Transistor Biasing Resistors (61) -- Power Management with Transistors (62) -- Generating Sound with Buzzers (114) -- Using Piezoelectric Buzzers (115) -- Generating Tones and Melodies (116) - -### 8. Communication Protocols - -**Description:** -Details various communication protocols used for data transmission between devices and components. - -**Relevant Concepts:** - -- Serial Communication Protocols (122) -- I2C Protocol (69) -- SPI Protocol (70) -- Universal Serial Bus Communication (97) -- Universal Asynchronous Receiver-Transmitter Communication (98) -- Connecting I2C Devices (71) -- Advanced I2C (78) -- Advanced SPI (79) -- Infrared Communication (117) -- Using Infrared Sensors (118) -- Infrared Remote Control (119) -- I2C vs SPI vs UART (122) -- Data Communication Principles (123) - -### 9. Internet of Things (IoT) - -**Description:** -Explores IoT concepts, connectivity, data transmission, and integration with cloud services. - -**Relevant Concepts:** - -- Internet of Things Concepts (128) -- Connecting to the Internet (129) -- Sending Data to Web Servers (130) -- Hypertext Transfer Protocol Basics (131) -- Message Queuing Telemetry Transport Protocol (132) -- IoT Applications (133) -- Cloud Services Integration (134) -- Data Visualization Tools (135) -- Wireless Communication Basics (124) -- Bluetooth Low Energy (125) -- Wi-Fi Connectivity (126) -- Edge Computing (194) - -### 10. Advanced Topics and Best Practices - -**Description:** -Includes advanced programming techniques, best practices, version control, and emerging technologies. - -**Relevant Concepts:** - -- Programming Best Practices (136) -- Code Optimization Techniques (137) -- Debugging Techniques (138) -- Using Debugging Tools (139) -- Version Control Systems (140) -- Using Git for Code Management (141) -- Collaborative Coding Practices (142) -- Documentation Standards (143) -- Commenting Code Effectively (144) -- Object-Oriented Programming (146) -- Classes and Objects (147) -- Inheritance and Polymorphism (148) -- Encapsulation in Object-Oriented Programming (149) -- Designing Reusable Code (150) -- Memory Management (151) -- Managing Resources Efficiently (152) -- Energy Efficiency in Programming (153) -- Sleep Modes in Microcontrollers (154) -- Battery-Powered Projects (155) -- Power Management Techniques (156) -- Control Systems Basics (189) -- Feedback Mechanisms (190) -- Proportional-Integral-Derivative Controllers (191) -- Machine Learning Concepts (192) -- Using MicroPython for Artificial Intelligence (193) -- Ethics in Technology (195) -- Future Trends in Computing (196) - -### Additional Considerations - -- **Cross-Cutting Themes:** Some concepts may span multiple categories. For example, "Pulse Width Modulation" could relate to both "Electronics Basics" and "Actuator Control." - -- **Prerequisites:** Ensure that foundational categories like "Computational Thinking Foundations" and "Programming Fundamentals" are taught first, as they underpin many other topics. - -- **Modular Organization:** Consider organizing your curriculum into modules based on these classifications to provide a structured learning path. - -- **Scalability:** This taxonomy allows for the addition of new concepts or subcategories as the course evolves or as new technologies emerge. - -### **Visual Taxonomy Structure** - -For better visualization, here's a hierarchical representation of the taxonomy: - -1. **Computational Thinking Foundations** -2. **Programming Fundamentals** -3. **MicroPython Programming** -4. **Hardware Components and Interfacing** -5. **Electronics Basics** -6. **Sensor Integration** -7. **Actuator Control** -8. **Communication Protocols** -9. **Internet of Things (IoT)** -10. **Advanced Topics and Best Practices** - -### **Example Mapping of Concepts to Taxonomy** - -Here's how some of the concepts map to the suggested taxonomy: - -| Concept ID | Concept Name | Classification | -| --- | --- | --- | -| 1 | Intro to Computational Thinking | Computational Thinking Foundations | -| --- | --- | --- | -| 7 | Variables in Programming | Programming Fundamentals | -| 14 | Introduction to MicroPython | MicroPython Programming | -| 26 | Microcontroller Basics | Hardware Components and Interfacing | -| 31 | Circuit Basics | Electronics Basics | -| 99 | Introduction to Sensors | Sensor Integration | -| 107 | Introduction to Actuators | Actuator Control | -| 122 | Serial Communication Protocols | Communication Protocols | -| 128 | Internet of Things Concepts | Internet of Things (IoT) | -| 136 | Programming Best Practices | Advanced Topics and Best Practices | - - -### Final Remarks - -This taxonomy provides a structured framework to classify -and organize your 197 learning concepts effectively. -It ensures that foundational knowledge is established -before progressing to more advanced topics, facilitating -a coherent and comprehensive learning experience for high -school students. Feel free to adjust the classifications -or add subcategories to better fit the specific needs and goals of your course. \ No newline at end of file diff --git a/docs/sims/knowledge-graphs/graph/index.md b/docs/sims/knowledge-graphs/graph/index.md deleted file mode 100644 index b9b0d8621..000000000 --- a/docs/sims/knowledge-graphs/graph/index.md +++ /dev/null @@ -1,118 +0,0 @@ -# Circuits Course Concept Dependency Graph - -[HTML Page for Dependency Graph](./dep-graph.html) - -## Adjusting Visualization - -In the [JavaScript](script.js) file you can change the display options. -Here is the portion of the JavaScript that changes the options. - -```js -var options = { - nodes: { - shape: 'dot', - size: 10, - font: { - size: 14, - }, - }, - edges: { - arrows: 'to', - smooth: true, - }, - physics: { - stabilization: false, - }, -}; -``` - -## Left to Right Layout - -[HTML Page for Dependency Graph](./lr-layout.html) - -```js -var options = { -layout: { - hierarchical: { - direction: 'LR', // Left to right - sortMethod: 'directed', // Sort nodes based on dependencies - nodeSpacing: 200, // Adjust spacing if needed - levelSeparation: 150 // Adjust for horizontal space between levels - } - } -} -``` - -## Full Layout Options - -```js -layout: { - randomSeed: undefined, - improvedLayout:true, - clusterThreshold: 150, - hierarchical: { - enabled:false, - levelSeparation: 150, - nodeSpacing: 100, - treeSpacing: 200, - blockShifting: true, - edgeMinimization: true, - parentCentralization: true, - direction: 'LR', // UD, DU, LR, RL - sortMethod: 'hubsize', // hubsize, directed - shakeTowards: 'leaves' // roots, leaves - } - } - ``` - -## Hierarchical Layout User Defined -https://visjs.github.io/vis-network/examples/network/layout/hierarchicalLayoutUserdefined.html - -```js - var options = { - edges: { - smooth: { - type: "cubicBezier", - forceDirection: - directionInput.value == "UD" || directionInput.value == "DU" - ? "vertical" - : "horizontal", - roundness: 0.4, - }, - }, - layout: { - hierarchical: { - direction: directionInput.value, - }, - }, - physics: false, - }; -``` - -## Category Colors - -We can use generative AI to categorize each concept. -Here are 11 categories of the concepts - -| CategoryID | Color | CategoryLabel | -|------------|--------|----------------------------------------------| -| 1 | red | Fundamental Concepts | -| 2 | orange | Passive Components | -| 3 | yellow | Active Components and Semiconductor Devices | -| 4 | green | Circuit Analysis Techniques | -| 5 | cyan | AC Circuit Concepts | -| 6 | blue | Transient Analysis | -| 7 | purple | Signal Processing and Filters | -| 8 | pink | Amplifiers and Analog Circuits | -| 9 | gray | Power Electronics | -| 10 | olive | Control Systems and Stability | -| 11 | brown | Types of Circuits | - - -[Category Colors Demo](./category-colors.html) - -[Cat Colors V3 DEBUG](./cat-colors-3.html) - -## Reference - -[Vis.js Network Layout Methods](https://visjs.github.io/vis-network/docs/network/#methodLayout) \ No newline at end of file diff --git a/docs/sims/knowledge-graphs/index.md b/docs/sims/knowledge-graphs/index.md deleted file mode 100644 index 8fe89221d..000000000 --- a/docs/sims/knowledge-graphs/index.md +++ /dev/null @@ -1,12 +0,0 @@ -# Knowledge Graphs - -## Prompt Engineering - -* [Concept Enumeration](concept-enumeration.md) -* [Concept Dependency](concept-dependency.md) -* [Concept Taxonomy](concept-taxonomy.md) - -## Demo Graphs - -* [Dependency Graph](./graph/dep-graph.html) -* [Taxonomy Colored Dependency Graph](./graph/category-colors.html) \ No newline at end of file diff --git a/docs/sound/02-play-tone.md b/docs/sound/02-play-tone.md deleted file mode 100644 index b3a40a475..000000000 --- a/docs/sound/02-play-tone.md +++ /dev/null @@ -1,43 +0,0 @@ -# Play Tones Using the PWM - -Since we will be using the sleep function many times, we will import it by name from the Micropthon time library like this: - -```python -from utime import sleep -``` - -Now, instead of putting ```utime.sleep(.5)``` we can just reference sleep directly like this: - -```python -sleep(.5) -``` - -This will pause for 1/2 a second. This is how long we wait for a tone to stay on or go off. The nice thing about this menthod is that our code is a little smaller. However, you can't run other functions in the utime library. So if you want to add them later you will need to import them also, just like we did for the sleep function. - -## Lab 1: Play A Single Tone - -```python -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle to be 50% -speaker.duty_u16(1000) -speaker.freq(1000) # 50% on and off -sleep(1) # wait a second -speaker.duty_u16(0) -# turn off the PWM circuits off with a zero duty cycle -speaker.duty_u16(0) -``` - -!!! Note - The tone will keep sounding until you turn the speaker duty to 0. This shows you that the circuitry that is generating the sound is independent of the main CPU. - -## Experiments - -1. Try changing the frequency for the first lab. This is the line ```speaker.freq(1000)``` and rerunning the program. Try using values from 10 to 10000. What values seem the loudest to your ear? -2. What happens if you comment out the last line that sets the duty cycle to be 0? Make sure to set it back to zero again or the tone will continue playing until the device is powered off. \ No newline at end of file diff --git a/docs/sound/03-play-three-tones.md b/docs/sound/03-play-three-tones.md deleted file mode 100644 index d07566655..000000000 --- a/docs/sound/03-play-three-tones.md +++ /dev/null @@ -1,89 +0,0 @@ -# Play Three Tones -In this lesson we will play three consecutive tones. Each tone will have a specific time on and we will put a time between the tones. - -```python -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -speaker.duty_u16(1000) -speaker.freq(300) # 1 Kilohertz -sleep(.5) # wait a 1/4 second -speaker.duty_u16(0) -sleep(.25) - -speaker.duty_u16(1000) -speaker.freq(800) -sleep(.5) -speaker.duty_u16(0) -sleep(.25) - -speaker.duty_u16(1000) -speaker.freq(400) -sleep(.5) - -# turn off the PWM -speaker.duty_u16(0) -``` - -## Using Variables - -We can also put the time each tone stays on and the space between the tones into variables so it is easier to modify the values in a single place. - -```python -# set the time each tone will be on -ONTIME = .5 -# the time between the tones -OFFTIME = .100 -``` - -## Three Tones With Variables - -```python -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# the time each tone will be on -ON_TIME = .25 -# the time between the tones -OFF_TIME = .1 - -# Low tone -speaker.duty_u16(1000) -speaker.freq(300) -sleep(ON_TIME) -speaker.duty_u16(0) -sleep(OFF_TIME) - -# High tone -speaker.duty_u16(1000) -speaker.freq(800) -sleep(ON_TIME) -speaker.duty_u16(0) -sleep(OFF_TIME) - -# Medium tone -speaker.duty_u16(1000) -speaker.freq(400) -sleep(ON_TIME) - -# turn off the PWM -speaker.duty_u16(0) -``` - -## Experiments - -1. Change the ON_TIME in the above program. What is the shortest time that you can still hear? -2. Change the order of the Low, High, Medium around. What is the most pleasing to your ears? -3. What order would you suggest for the start of a game and what order would you like for a "Game Over" sound? \ No newline at end of file diff --git a/docs/sound/04-play-scale.md b/docs/sound/04-play-scale.md deleted file mode 100644 index 9e7e014d6..000000000 --- a/docs/sound/04-play-scale.md +++ /dev/null @@ -1,50 +0,0 @@ -# Play a Scale -In this lesson, we will learn about how to automatically generate various pitches. We will see that the spacing between lower pitches is different from the spacing between higher pitches. - -Here is a program that plays a scale of notes from a starting frequency of 30 hertz to an upper frequency of around 10,000 hertz. Note that - -```python -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(0.3) - -def bequiet(): - speaker.duty_u16(0) - -freq = 30 - -for i in range(64): - print(freq) - playtone(freq) - freq = int(freq * 1.1) - -# Turn off the PWM -speaker.duty_u16(0) -``` - -## New Frequency Spacing - -When you run the prior example, note the frequencies printed to the console. Are they evenly spaced? - -Take a close look at the line that creates a new frequency: - -```python -freq = int(freq * 1.1) -``` - -The effect of this line is to create a new frequency that is 10% higher than the prior frequency. - -## Experiments - -1. What happens if you change the frequency update to be ```freq = freq +100``` - diff --git a/docs/sound/05-play-mario.md b/docs/sound/05-play-mario.md deleted file mode 100644 index 97b0dffdd..000000000 --- a/docs/sound/05-play-mario.md +++ /dev/null @@ -1,45 +0,0 @@ -# Play Mario on MicroPython - -This program will play the theme music from the Mario video game. - -```python -from machine import Pin, PWM -from utime import sleep -buzzer = PWM(Pin(16)) - -tones = { -"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46, -"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65, -"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98, -"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139, -"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185, -"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311, -"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698, -"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661, -"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520, -"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978 -} - -song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"] -mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6", - 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", - 0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, - "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0] - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def playsong(mysong): - for i in range(len(mysong)): - if (mysong[i] == "P" or mysong[i] == 0 ): - bequiet() - else: - playtone(tones[mysong[i]]) - sleep(0.3) - bequiet() -playsong(mario) -``` \ No newline at end of file diff --git a/docs/sound/06-eight-key-piano.md b/docs/sound/06-eight-key-piano.md deleted file mode 100644 index da710cfe6..000000000 --- a/docs/sound/06-eight-key-piano.md +++ /dev/null @@ -1,110 +0,0 @@ -# Eight Key Piano - -In this lab we wire up eight momentary press buttons so that when each one is pressed it will play a different note. - - - -To create this project, you will need the following parts: - -1. A Raspberry Pi Pico -2. A standard size breadboard or two 1/2 breadboards -3. 8 momentary press buttons -4. A speaker or a [Piezo buzzer](https://en.wikipedia.org/wiki/Piezoelectric_speaker) -5. An optional sound amplifier such as the [LM386 DC 5V-12V Mini Micro Audio Amplifier](https://www.ebay.com/itm/234012505949?hash=item367c3b775d:g:sPkAAOSwtoVbOFbf) which can be purchased on e-bay for under $2 USD. If you are working in a quiet room you may not need the amplifier. - -![Eight Key Piano](../img/eight-key-piano.jpg) - -Each "key" is a momentary press button that is wired up between a GPIO pin and the +3.3 volt rail on the breadboard connected to [3V3(OUT) pin](../getting-started/02-pi-pico/#pico-pinout). We do not need to use any resistors to pull the signals low since we configure the pins to be inputs with the PULL_DOWN resistor like this: - -```py -button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN) -``` - -## The Play Tone Functions - -We will use two Python functions, one for playing a tone of a given frequency and one for turning off the sound. - -```py -def playtone(frequency): - speaker.duty_u16(1000) # turn the PWM duty to 50% - speaker.freq(frequency) - builtin_led.high() # turn builtin LED on - -def bequiet(): - speaker.duty_u16(0) # turn off the speaker PWM - builtin_led.low() # turn builtin LED off -``` - -We will also use the ```.value()``` method on each pin to detect if it is HIGH (1) like this: - -```py -if button_pin_1.value() == 1: - playtone(220) # A3 -``` - -We will be playing "notes" generating square waves with various frequencies from our lowest note of A3 at 220 Hz up to A4 at 440 Hz. - -## Sample Code - -```py -# play a tone durning button down -from machine import Pin, PWM -from utime import sleep, ticks_ms - -SPEAKER_PIN = 22 # pass through a speaker and tie the other end to GND -speaker = PWM(Pin(SPEAKER_PIN)) - -builtin_led = machine.Pin(25, Pin.OUT) - -# Connect these GP pins through a button to the +3.3 volt rail -button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_2 = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_3 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_4 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_5 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_6 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_7 = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_8 = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN) - -def playtone(frequency): - speaker.duty_u16(1000) # turn the PWM duty to 50% - speaker.freq(frequency) - builtin_led.high() # turn builtin LED on - -def bequiet(): - speaker.duty_u16(0) # turn off the speaker PWM - builtin_led.low() # turn builtin LED off - -while True: - if button_pin_1.value() == 1: - playtone(220) # A3 - elif button_pin_2.value() == 1: - playtone(247) # B3 - elif button_pin_3.value() == 1: - playtone(262) # C4 - elif button_pin_4.value() == 1: - playtone(294) # D4 - elif button_pin_5.value() == 1: - playtone(330) # E4 - elif button_pin_6.value() == 1: - playtone(349) # F4 - elif button_pin_7.value() == 1: - playtone(392) # G4 - elif button_pin_8.value() == 1: - playtone(440) # A4 - else: - bequiet() -``` - -## Exercises - -1. Rewrite the code above using lists for the pin numbers and the notes. -2. Try different notes with other scales. -3. Add another button to change the "octave" of the notes. -4. Add a display to show the notes as they are being played. -5. Print the time each note is being pressed as well as the length of the pauses between the notes. -6. Write the notes to a recording file. -7. Add a menu system so you can do things like start a new song recording, save a recording and playback a recording. -8. Eight keys are not enough for many songs. Use two full-size breadboards to expand the number of keys on your piano. -9. Look into getting a MIDI keyboard such as the 32-key $40 [MIDIPLUS AKM320 USB MIDI Keyboard Controller](https://www.amazon.com/midiplus-32-Key-Midi-Controller-AKM320/dp/B00VHKMK64/ref=bmx_dp_n4il8m3n_37/135-5614730-7499827?th=1) -10. Read this blog about running MIDI on the Pico: [MIDI, MicroPython and the Raspberry Pi Pico](https://diyelectromusic.wordpress.com/2021/01/23/midi-micropython-and-the-raspberry-pi-pico/) \ No newline at end of file diff --git a/docs/sound/07-play-audio-file.md b/docs/sound/07-play-audio-file.md deleted file mode 100644 index 092d0c064..000000000 --- a/docs/sound/07-play-audio-file.md +++ /dev/null @@ -1,262 +0,0 @@ -# Playing an Audio File - - - -!!! Note - This lesson is still a work in progress. The wavePlayer is in an early draft form and has unpredictable interactions with other components. See the wav file test results section below. We also are having problems when different GPIO pins are used. If you stick to pins for GPIO 2 and 3 for the two channels the test run OK. - -## Playing Sounds on The RP2040 Chip - -Although we can play tones of various pitches on the PR2040 using the PMW to generate square waves, the quality of this sound is not close to high-fidelity sound like you would expect in a personal MP3 audio player. - -In this lesson we will demonstrate how to play a high-quality audio files that are stored on the two megabytes of non-volatile static memory of the Pico. According to the specification of the [Raspberry Pi Pico](https://www.raspberrypi.com/products/raspberry-pi-pico/specifications/), the system comes with 2MB on-board QSPI Flash that we can use to store sound files. By combining our Pico with an SD card reader we can also play many sounds and even full-length music and full albums. - -## Background on Audio Encoding - -![PCM Encoding Example](../img/PCM-example.png) - -Audio files are encoded in many formats. For this lab there are two key concepts to understand: - -1. The [Sampling Rate](https://en.wikipedia.org/wiki/Sampling_(signal_processing)#Sampling_rate) which is how frequently an audio signal is sampled. The more frequently we sample (up to 41K per second) the higher the fidelity of the recording. The downside is that the audio file takes more space. -2. The [audio bit depth](https://en.wikipedia.org/wiki/Audio_bit_depth) is how many bits we used to encode the amplitude of the sound. - -For our labs, we will be using mono files (not stereo) a sampling rate of 8,000 samples per second (8K Hz) and a sampling rate of 16-bit depth. This is a good compromise between smaller size and sound fidelity in typical robots. - -Our robots typically will play a short 1-second sound to tell us they are performing an action like stopping, backing up or turning. This one-second 8K Hz WAV file will be about 20K. Our flash budget for the Raspberry Pi Pico is 2M, so we can easily store 10 sound effects in 200K or 1/10 of our available flash memory. We can also add a SD card if we need more flash memory. - -We will be using standard .WAV files with [Pulse Code Modulation Encoding](https://en.wikipedia.org/wiki/Pulse-code_modulation) in .WAV files. WAV files do take more space than compressed MP3 files, but they are easier to play because the decoding steps are trivial for a microcontroller to perform. - -## Overall Architecture - -1. We will be reading .wav files from the MicroPython non-volatile flash memory or an SD card. By convention we will store them in a directory called ```/sounds``` -2. We will be using the wave.py module to read the .wav files -3. We will be using the myPMW.py, chunk.py and myDMA.py modules to stream the data from the WAV files to the PWM controllers -4. The metadata from the .wav files is used to change the sampling frequency of the .wav player - -## Checking Your Sound File Sizes - -```py -import os - -waveFolder= "/sounds" - -total = 0 -# get a list of .wav files and their sizes -for file in os.listdir(waveFolder): - size = os.path.getsize(file) - print(file, size) - total += size -print('Total sound directory size:', total) -``` - -## Connections - -Some of this documentation was take from [Dan Perron's Pico Audio GitHub Repo](https://github.com/danjperron/PicoAudioPWM). - -In these tests we used GPIO pins 2 and 3 to drive the left and right channels of audio that are sent to a stereo amplifier. You can use both an amplifier or head phone with a 1K resistor in series on the pins to limit the current from the 3.3v output signals. - -The myPWM subclass set the maximum count to 255 (8 bits) or 1023(10bits) at a frequency -around 122.5KHz. - -The PWM is now on 10 bits (0..1023) - -The myDMA class allows to use direct memory access to transfer each frame at the current -sample rate. - -We will need to install the wave.py and chunk.py from [Jokey GitHub Awesome MicroPython Repo](https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio) on root file system or the /lib folder on the pico file system. - -Don't forget to increase the SPI clock up to 3Mhz. (TODO not sure what this means) - -The following documentation was take from Daniel Perron's Github page. - -1. We set the PWM to a range of 255 at 122Khz -2. We read the wave file using the class ```wave.py``` which will set the - sample rate and read the audio data by chunk -3. Each chunk is converted to 16 bit signed to unsigned char with the middle at 128, (512 for 10 bits) -1. We wait for the DMA to be completed. On first it will be anyway. -2. The converted chunk is then pass to the DMA to be transfer at the sample rate using one of build in timer -3. Go on step 2 until is done. - -## Steps to test playing a wav file - -### Clone the Pico Audio PWM GitHub Repository -```sh -git clone https://github.com/danjperron/PicoAudioPWM -cd PicoAudioPWM -``` - -## Download some test robot wav files - -The following GitHub location: - -[https://github.com/CoderDojoTC/robot-media/tree/master/wav-8k](https://github.com/CoderDojoTC/robot-media/tree/master/wav-8k) - -contains a set of 8K Hz 16 bit robot sounds that you can use with your robot. - -## Converting .MP3 to .WAV files - -This software only currently support playing .wav files since it is easy to convert these files into a format that can be played. WAV files store uncompressed audio, so they are larger than MP3 files. Wav files are simple ways to store sound patterns. MP3 files are much more complex and require complex algorithms to convert into sound outputs. - - The usual bitstream encoding is the linear pulse-code modulation (LPCM) format. - -If you have just a few MP3 files, can use the following web-site to convert MP3 files into wave files: - -[Cloud Convert Service that Converts MP3 to WAV files](https://cloudconvert.com/mp3-to-wav) - -The [next lab](09-converting-mp3-to-wav.md) shows you how to convert an entire folder of MP3 files to 8K Hz 16-bit WAV files using a shell script. - -## Copy Sound Files to the Pico - -Your pico has 2MB of static memory. A typical robot sound effect you want to play when you bump into and object will play for around 1 second. You can copy many sound effect files to the pico file system and play them. Some IDEs may allow you to do this or you can use the rshell program. - -Here is an example of using the [rshell](../advanced-labs/11-rshell.md) program to copy a directory of wav files to the pico. Lines that start with pc$ are commands that you type into your PC or MAC's terminal. Lines that start with rs$ are commands that you type into the rshell. - -```sh -# list the devices (only works on Mac and UNIX) -pc$ ls /dev/cu.modem* -# start the rshell -pc$ rshell -p /dev/cu.modem* -# change the name of the device to be "pico" -rs$ echo 'name="pico"' > /pyboard/board.py -# exit from rshell - can also use exit -CONTROL-C -# reconnect with the rshell -$pc rshell -p /dev/cu.modem* -# go into the /pico file systems -$rs cd /pico -# create a directory for all our sound files -mkdir sounds -# copy files from hour PC's home ~/tmp/sounds dir to the pico -rs$ cp ~/tmp/sounds/*.wav /pico/sounds -rs$ ls /pico/sounds -``` - -## Listing the Wave Files - -After you have a list of Wave files loaded you can verify them by using the os listdir() function. - -```py -import os - -waveFolder= "/sounds" -wavelist = [] - -# get a list of .wav files -for i in os.listdir(waveFolder): - if i.find(".wav")>=0: - wavelist.append(waveFolder+"/"+i) - elif i.find(".WAV")>=0: - wavelist.append(waveFolder+"/"+i) - -if not wavelist : - print("Warning NO '.wav' files") -else: - for i in wavelist: - print(i) -``` - -Sample console output - -``` -/sounds/cylon-attention.wav -/sounds/cylon-by-your-command.wav -/sounds/cylon-excellent.wav -/sounds/cylon-eye-scanner.wav -/sounds/cylon-see-that-the-humans.wav -/sounds/cylon-those-are-not-the-sounds.wav -``` - -## Checking the WAV File Format - -There is a standard Python module called ```wave.py`` that reads the .wav files and shows the metadata for the file. Wave files come in many formats, single channel, stereo and different bit rates. The wave player can show us all this data that describes the wave file. - -The report shows you how to use fixed-width formatting since the file names and data should fit in columns to make it easier to read. - -```py -import os -import wave - -waveFolder= "/sounds" -wavelist = [] - -# get a list of .wav files -for i in os.listdir(waveFolder): - if i.find(".wav")>=0: - wavelist.append(waveFolder+"/"+i) - elif i.find(".WAV")>=0: - wavelist.append(waveFolder+"/"+i) - -if not wavelist : - print("Warning NO '.wav' files") -else: - print("{0:<45}".format('File Path'), 'Frame Rate Width Chans Frames') - for filename in wavelist: - f = wave.open(filename,'rb') - # the format string "{0:<50}" says print left justified from chars 0 to 50 in a fixed with string - print("{0:<50}".format(filename), - "{0:>5}".format(f.getframerate()), - "{0:>5}".format(f.getsampwidth()), - "{0:>6}".format(f.getnchannels()), - "{0:>6}".format(f.getnframes()) - ) -``` - -Sample Response - -``` -File Path Frame Rate Width Chans Frames -/sounds/cylon-attention.wav 8000 1 1 6399 -/sounds/cylon-by-your-command.wav 11025 1 1 12583 -/sounds/cylon-excellent.wav 22050 1 1 48736 -/sounds/cylon-eye-scanner.wav 16000 2 2 24768 -/sounds/cylon-see-that-the-humans.wav 11025 1 1 30743 -/sounds/cylon-those-are-not-the-sounds.wav 22050 1 1 64137 -``` - -## Adding an Interrupt - -If you halt the RP2040 while it is playing a sound, the independent PWM controllers will continue to generate sound. In order to shut the independent PWM controllers, an interrupt controller system must be used to cleanly disable all the sound. Here is an example of this using a try/except block of code. - -```py -import os as uos -from wavePlayer import wavePlayer -player = wavePlayer() - -try: - while True: - # repeat this over and over until the keyboard shuts down the circuit - player.play('/sounds/cylon-eye-scanner.wav') -except KeyboardInterrupt: - player.stop() - print("wave player terminated") -``` - -## Playing the Same Sound Repeatedly - -```py -import os as uos -from wavePlayer import wavePlayer -player = wavePlayer() - -try: - while True: - player.play('/sounds/cylon-eye-scanner.wav') -except KeyboardInterrupt: - player.stop() - print("wave player terminated") -``` - -## Downloading the Audio Libraries - -Both the wave.py and the chunck.py files are here: - -https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio - -## References - -1. [Daniel Perron](https://github.com/danjperron/PicoAudioPWM) -2. [Wikipedia page for Wave File](https://en.wikipedia.org/wiki/WAV)c -3. [Web-Based Audio Conversion Service Convertio](https://convertio.co/audio-converter/) -4. [Wikipedia page for Audio Interchange File Format](https://en.wikipedia.org/wiki/Audio_Interchange_File_Format) -5. [Wikipedia page for Pulse-code Modulation](https://en.wikipedia.org/wiki/Pulse-code_modulation) -6. [Raspberry Pi Pico Forum on Sounds Files](https://forums.raspberrypi.com/viewtopic.php?p=1847611) \ No newline at end of file diff --git a/docs/sound/07a-test-audio-ports.md b/docs/sound/07a-test-audio-ports.md deleted file mode 100644 index 225f674a9..000000000 --- a/docs/sound/07a-test-audio-ports.md +++ /dev/null @@ -1,36 +0,0 @@ -# Testing Audio Ports - -In this lab, we will be testing stereo audio ports. We will be sending a 1 kilohertz square wave to the left and then right ports. This program allows you to test your stereo connections and make sure that both channels are working correctly. - -```py -from machine import Pin, PWM -from utime import sleep - -# You will need to configure these two digital output ports -AUDIO_LEFT_PIN = 18 -AUDIO_RIGHT_PIN = 19 - -# create a Pulse Width Modulation Object on this pin -left_speaker = PWM(Pin(AUDIO_LEFT_PIN)) -# set the duty cycle to be 50% -left_speaker.duty_u16(1000) -left_speaker.freq(1000) # 50% on and off -sleep(1) # wait a second -left_speaker.duty_u16(0) -# turn off the PWM circuits off with a zero duty cycle -left_speaker.duty_u16(0) -sleep(1) - -# create a Pulse Width Modulation Object on this pin -right_speaker = PWM(Pin(AUDIO_RIGHT_PIN)) -# set the duty cycle to be 50% -right_speaker.duty_u16(1000) -right_speaker.freq(1000) # 50% on and off -sleep(1) # wait a second -right_speaker.duty_u16(0) -# turn off the PWM circuits off with a zero duty cycle -right_speaker.duty_u16(0) -``` - -## References -https://en.wikipedia.org/wiki/Phone_connector_(audio)#Computer_sound \ No newline at end of file diff --git a/docs/sound/08-i2s-standard.md b/docs/sound/08-i2s-standard.md deleted file mode 100644 index 6a61f23c0..000000000 --- a/docs/sound/08-i2s-standard.md +++ /dev/null @@ -1,8 +0,0 @@ -# I2S Standard - -[I2S](https://en.wikipedia.org/wiki/I%C2%B2S) (Inter-IC Sound) pronounced "eye-two-ess", is an electrical serial bus interface standard used for connecting digital audio devices together. It is a general interface to communicate [PCM](https://en.wikipedia.org/wiki/Pulse-code_modulation) audio data between integrated circuits in an electronic device. - -Note that I2S is unrelated to the similar sounding I2C bus protocol. - -Since MicroPython 1.17 we have a library that allows us to play - diff --git a/docs/sound/09-converting-mp3-to-wav.md b/docs/sound/09-converting-mp3-to-wav.md deleted file mode 100644 index 9096dd8ec..000000000 --- a/docs/sound/09-converting-mp3-to-wav.md +++ /dev/null @@ -1,123 +0,0 @@ -# Converting MP3 to WAV formats - -In last lab we will learned how to play an audio file stored on the flash memory or SD card. We used an early version of a Python module that plays .WAV files in a fixed format: 8,000 samples per second using 16-bit encoding. Because there are hundreds of different formats of audio files, we need a consistent way to convert all of these formats to 8K samples/second 16-bit .WAV formats. - -The audio data file conversions are done on your host PC, not the microcontroller. This allows us to use a rich library of tools that don't need to run on our microcontroller. - -## Method 1: Use the ffmpeg Command Line Tool - -One of the easiest ways to get started is to go to the web site [ffmpeg.org](https://www.ffmpeg.org/download.html) and download the program that does the conversion using a command line. Note that on a Mac you will need to go into your System Preferences and indicate that the following programs are trusted: - -Here are the direct links for MacOS - -1. [ffmpeg (mac)](https://evermeet.cx/ffmpeg/ffmpeg-104676-g5593f5cf24.zip) -2. [ffprobe (mac)](https://evermeet.cx/ffmpeg/ffprobe-104676-g5593f5cf24.zip) -3. [ffplay (mac)](https://evermeet.cx/ffmpeg/ffplay-104454-gd92fdc7144.zip) - -This will download a zip file which you will need to unzip and place in a location such as ```~/bin```. After you do this make sure you add ```~/bin`` to your path by adding the following file to your .bash_profile: - -```PATH=$PATH:~/bin``` - -After you source your .bash_profile type in the following: - -```which ffmpeg``` - -This should return the location that it finds the ffmpeg shell script. You can then see the many file-format MPEG options: - -```ffmpeg --help``` - -## Converting MP3 to 8K 16 bit WAV Files - -To get the format we need for the MicroPython wave player class we just specific ```-i``` for the input file and use the ```-ar 8000``` to specify the output bit rate of 8K samples per second. The final parameter is a file name that must in ```.wav``` so the command knows to use WAV PCM encoding. The default value is 16 gits per sample. - -```sh -ffmpeg -i r2d2-beeping.mp3 -ar 8000 r2d2-beeping-8k.wav -``` - -## Bulk Conversions - -We can use unix shell commands to do a batch conversion of all the . The following is an example of using awk and sed to convert all the .mp3 files in a directory and convert them to 8K Hz WAV files and put them in a sibling directory. - -```sh -ls -1 *.mp3 | awk '{print "ffmpeg -i " $1 " -ar 8000 ../wav-8k/"$1}' | sed s/mp3$/wav/ | sh -``` - -## Inspect the Files Using the UNIX file command: - -```sh -cd ../wav-8k -file *.wav -``` - -returns -``` -r2d2-another-beep.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-beeping-2.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-beeping-4.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-beeping-8k.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-beeping-like-an-alarm.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-beeping.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-cheerful.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-determined.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-excited.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-laughing.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-more-chatter.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-processing.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-sad.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-shocked.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-surprised.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-taking-to-himself.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -r2d2-unsure.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz -``` - -Note that these are WAVE audio, Pulse-code Modulated (PCM), 16 bit and mono at 8K Hz. - -## Method 2: Use the pydub Python Module - -!!! Note - This section is only for experienced Python developers. - -### Install Conda and the Python libraries - -```sh -conda create -n mp3-to-wav python=3 -conda activate mp3-to-wav -pip install pydub ffprobe ffmpeg -``` - -Check your versions: - -```sh -pip freeze -``` - -returns: - -``` -ffmpeg==1.4 -ffprobe==0.5 -pydub==0.25.1 -``` - -### Running pydub - -```py -from pydub import AudioSegment - -sound = AudioSegment.from_mp3("r2d2-beeping.mp3") -sound.export("r2d2-beeping.wav", format="wav", tags={'Robot name': 'R2D2'}) -``` - -## Transferring the Files with Rshell - -```sh -cd ../wav-8k -rshell -p /dev/cu.usbmodem14101 -cp *.wav /pico/sounds -``` - -## References - -1. [PyDub Documentation](http://pydub.com/) -2. [File Formats for Audio from MPEG](http://www.ffmpeg.org/general.html#Audio-Codecs) -3. [File Formats for motion picture experts group Python Library](http://www.ffmpeg.org/general.html#File-Formats) diff --git a/docs/sound/10-midi.md b/docs/sound/10-midi.md deleted file mode 100644 index ae09ce90e..000000000 --- a/docs/sound/10-midi.md +++ /dev/null @@ -1,46 +0,0 @@ -# MIDI with MicroPython - -!!! Warnining - I am not an expert on MIDI and I don't have any MIDI gear. This is - mostly a collection of material I have for students that want - to use MicroPython to generate music. - - - -## Sample Code - -### Ascending Notes - -```py -# Play Test MIDI Ascending Notes -from machine import Pin, UART -import time -uart = UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5)) -uart.init(bits=8, parity=None, stop=1) -led=Pin("LED", Pin.OUT) -note = 24 - -while True: - midimessage = bytearray([0x90, note, 64]) - uart.write(midimessage) - led.toggle() - # change third parameter to be 0 - midimessage = bytearray([0x90, note, 0]) - # pause 1/8 of a second - time.sleep(0.125) - note += 2 - if note > 64: - note=24 -``` - -## References - -[Raspberry Pi Pico MIDI Development Board Midimuso](https://www.ebay.com/itm/134794678425?hash=item1f62639099:g:WbcAAOSwvMxk0qof) for $20 US. This board has all the MIDI connectors on it. - -[Simple DIY electromusic Project](https://diyelectromusic.wordpress.com/) - -[DIY Electro Music SDEMP MicroPython Code on GitHub](https://github.com/diyelectromusic/sdemp/tree/main/src/SDEMP/Micropython) - -[Pico MIDI by Barb Arach](https://barbarach.com/pico-midi-external-switches/) - -[PicoMIDI manual v1.0](https://docs.google.com/viewer?url=https%3A%2F%2Fmidimuso.co.uk%2Fwp-content%2Fuploads%2F2023%2F07%2FpicoMIDI_manual-2.pdf) \ No newline at end of file diff --git a/docs/sound/11-sound-parts.md b/docs/sound/11-sound-parts.md deleted file mode 100644 index d20353902..000000000 --- a/docs/sound/11-sound-parts.md +++ /dev/null @@ -1,5 +0,0 @@ -# Sound Parts - -* [PAM8302A Miniature 2.5W Class D Mono Audio Power Amplifier Module Board](https://www.ebay.com/sch/i.html?_nkw=PAM8302A) - -* [PAM8302A 10pcs](https://www.ebay.com/itm/354647594669?hash=item5292a4d6ad:g:bPEAAOSwrHxkEExV&amdata=enc%3AAQAIAAAAwCRR%2BjGzHc1QqgUzZg50TfImB2%2FezhxRjE7yUQNozGL6cv2SDrjR7iOuwZo49L7haNuPr2QT7VjzxUc239%2FnLwwBf9XKrcrc1PW4ltGrU%2BdLRoHBzdyYTIQWIMDQDveovSDkq%2BpCDhFufpmJ1Px%2FqAhXV08xFKXznhPtH2vc79IOM3q2sfNrHuvjGk11IxDzR65VlyK2IANBD9zljk0hEGxKX6GWmee2WkL040%2F4%2BA3AvDZMlEwBAaQHlSO7teXcRw%3D%3D%7Ctkp%3ABk9SR-bu7rvLYg) \ No newline at end of file diff --git a/docs/sound/20-i2s-bus.md b/docs/sound/20-i2s-bus.md deleted file mode 100644 index 41d2b2ca3..000000000 --- a/docs/sound/20-i2s-bus.md +++ /dev/null @@ -1,263 +0,0 @@ -# The I2S Bus - -The **I2S (Inter-IC Sound)** bus on the Raspberry Pi Pico is a versatile and high-quality interface for digital audio. Here are some compelling reasons to use it: - -### 1. **High-Quality Digital Audio** - -- I2S allows for precise, lossless transfer of digital audio between devices, ensuring superior sound quality compared to analog signals that are susceptible to noise and distortion. - -### 2. **Low Pin Usage** - -- I2S requires only a few pins to transmit high-quality audio data. This leaves other GPIO pins available for additional peripherals or projects. - -### 3. **Stereo Audio Support** - -- The I2S bus can handle stereo audio, making it ideal for projects requiring left and right channels, such as music players, audio recorders, or sound-based art installations. - -### 4. **Ease of Integration with Digital Audio Components** - -- Many digital audio devices, such as DACs (Digital-to-Analog Converters), ADCs (Analog-to-Digital Converters), and codecs, natively support I2S. This simplifies the integration of audio into your projects. - -### 5. **Reduced Audio Interference** - -- By keeping the audio in the digital domain until it reaches the final output stage (e.g., DAC), I2S reduces the risk of electromagnetic interference that analog signals might pick up. - -### 6. **Support for Advanced Audio Formats** - -- I2S can transmit audio at various sample rates and bit depths (e.g., 16-bit, 24-bit), enabling support for high-fidelity audio formats used in modern applications. - -### 7. Ideal for Audio Projects - -The I2S interface is perfect for: -- Building audio streaming devices. -- Implementing DIY digital radios or podcast recording setups. -- Creating smart speakers or voice assistants. - -### 8. Integration with MicroPython - -- The Raspberry Pi Pico's support for MicroPython and C/C++ makes it easy to work with I2S in a high-level programming environment, reducing development complexity. - -### 9. Applications in Education and Prototyping - -- For educational purposes, I2S offers an opportunity to learn about digital audio processing and signal transmission. It also facilitates prototyping of commercial audio equipment. - -### Example Applications - -- **DIY Digital Audio Player**: Combine an I2S DAC with an SD card reader to create a custom MP3 or FLAC player. -- **Audio Signal Processing**: Capture audio with an I2S ADC for real-time signal analysis or effects processing. -- **Voice Recognition Systems**: Use I2S microphones for clear audio input in speech-to-text or voice control projects. - -The inclusion of I2S on the Raspberry Pi Pico opens up a world of opportunities for high-quality, efficient, and versatile audio processing in your projects. - -## Robot Sounds Project - -Here we describe a simple project that plays robot sound files on the Raspberry Pi Pico. - -### Project: Robot Sound Player on Raspberry Pi Pico - -This project will use the Raspberry Pi Pico with an I2S DAC to play pre-recorded robot sound files (e.g., "beeps," "boops," "affirmative," "error") stored on a microSD card. The sounds will be triggered using a button or slider switch. - -### Components Needed - -1. **Raspberry Pi Pico** (with headers for easy wiring) -2. **I2S DAC Module** (e.g., PCM5102) -3. **MicroSD Card Module** (for storing sound files) -4. **Speaker** (connected to the DAC) -5. **Push Button** or **Slider Switch** (to trigger sound effects) -6. **Wires** and **Breadboard** - -### Steps to Build - -#### 1. **Prepare the Sound Files** - -- Convert your robot sound files to a compatible format like 16-bit PCM WAV files at 44.1 kHz. -- Store the WAV files on a microSD card with filenames like `robot1.wav`, `robot2.wav`. - -#### 2. **Connect the Components** - -##### MicroSD Module to Pico -- `VCC` → Pico `3.3V` -- `GND` → Pico `GND` -- `MISO` → Pico `GP16` -- `MOSI` → Pico `GP19` -- `SCK` → Pico `GP18` -- `CS` → Pico `GP17` -##### I2S DAC to Pico -- `BCK` → Pico `GP10` -- `LRCK` → Pico `GP11` -- `DIN` → Pico `GP9` -- `GND` → Pico `GND` -- `VCC` → Pico `3.3V` or `5V` (depending on the module) -##### Speaker to DAC**: - - Connect the speaker output from the DAC module to your speaker terminals. -##### Button to Pico:** - - One side of the button → Pico `GP14` - - Other side of the button → `GND` - - Use a 10K pull-up resistor from `GP14` to `3.3V`. - -#### 3. **Install the Required Software** - -- Install MicroPython on your Pico. -- Upload libraries for: - - **I2S Audio Playback**: E.g., `i2s_audio.py` - - **SD Card Access**: `uos` or `os` module with MicroPython SD card libraries. -- Format the microSD card as FAT32. - -#### 4. **Write the Code** - -Below is an example MicroPython code for playing sound files using a button trigger: - -```python -from machine import Pin, I2S, SPI -import uos - -# Initialize I2S for DAC -audio_out = I2S( - 0, - sck=Pin(10), # Bit clock - ws=Pin(11), # Word select - sd=Pin(9), # Serial data - mode=I2S.TX, - bits=16, - format=I2S.MONO, - rate=44100 -) - -# Initialize SD Card -spi = SPI(0, sck=Pin(18), mosi=Pin(19), miso=Pin(16)) -sd_cs = Pin(17, Pin.OUT) -uos.mount(SDCard(spi, sd_cs), "/sd") - -# Button Input -button = Pin(14, Pin.IN, Pin.PULL_UP) - -def play_sound(file_path): - with open(file_path, "rb") as wav: - wav.seek(44) # Skip WAV header - while True: - buf = wav.read(2048) - if not buf: - break - audio_out.write(buf) - -print("Ready to play robot sounds!") -while True: - if not button.value(): # Button pressed - print("Playing sound!") - play_sound("/sd/robot1.wav") -``` - -#### 5. Test the Setup - -- Power up the Pico. -- Press the button to trigger playback of `robot1.wav`. -- Swap out files or add more buttons to trigger additional sounds. - -### Extensions - -1. **Multiple Buttons**: Add more buttons to trigger different sound effects. -2. **Random Playback**: Use the `random` module to pick a random sound from the SD card. -3. **Interactive Robot**: Connect the sound system to sensors (e.g., distance or light sensors) to play sounds based on environmental triggers. - -This project is an engaging way to learn about I2S, digital audio, and MicroPython, while creating a fun and interactive robot sound player! - -##### Storing the Sounds on the Pico's Flash Memory - -We can store the sound files on the Raspberry Pi Pico's internal flash memory instead of using an external microSD card. However, there are a few considerations and limitations to keep in mind: - -### Considerations for Storing Sounds in Flash Memory - -#### **Limited Flash Storage Space** - -- The Raspberry Pi Pico has 2 MB of onboard flash memory, which is shared with the MicroPython firmware and your code. -- Sound files (e.g., WAV) can be quite large, so you'll need to ensure the files fit within the available space. -- Use compressed or low-bitrate audio formats if possible (e.g., 8-bit, mono, low sample rate). - -#### File Size and Format - -- A typical PCM WAV file at 16-bit, 44.1 kHz uses ~88 KB per second of audio. Consider using a lower sample rate (e.g., 8 kHz) to save space. -- Mono sound files consume less space than stereo. - -#### Loading Files into Flash** - -- Store the audio files in the Pico's filesystem (accessible via MicroPython) by uploading them using a file transfer tool like **Thonny** or a command-line tool like `ampy`. - -#### Playback Speed - -- Flash memory access is slower than an I2S DAC with buffered SD card reading. For short sound clips, this isn't usually an issue. - -### Steps to Store and Play Sounds from Flash - -#### 1.Prepare the Sound Files - -- Convert your sound files to a smaller format: - - Mono, 8-bit PCM WAV - - Sample rate: 8 kHz or 16 kHz -- Example tools for conversion: - - [Audacity](https://www.audacityteam.org/) - - `ffmpeg` command-line tool: - -```bash -ffmpeg -i input.wav -ar 16000 -ac 1 -b:a 8k output.wav -``` - -#### 2. Upload Files to Pico - -- Open the Thonny IDE. -- Connect your Pico. -- In the **File Explorer**, upload your WAV file(s) to the Pico's flash memory. - -#### 3. **MicroPython Code for Playback** - -- Below is an example code to play a short WAV file stored in the Pico's flash memory: - -```python -from machine import I2S, Pin - -# Initialize I2S for DAC -audio_out = I2S( - 0, - sck=Pin(10), # Bit clock - ws=Pin(11), # Word select - sd=Pin(9), # Serial data - mode=I2S.TX, - bits=16, - format=I2S.MONO, - rate=16000 # Match the WAV file's sample rate -) - -def play_sound(file_path): - try: - with open(file_path, "rb") as wav: - wav.seek(44) # Skip WAV header - while True: - buf = wav.read(2048) - if not buf: - break - audio_out.write(buf) - except Exception as e: - print(f"Error playing sound: {e}") - -# Play the sound file stored on the Pico -print("Playing robot sound...") -play_sound("robot1.wav") -``` - -#### 4. **Optimize and Test** - -- Use `uos.listdir()` to list files stored in flash memory. -- Ensure the file format matches the I2S configuration (e.g., 8-bit or 16-bit, mono or stereo). -- Test playback and confirm there are no buffer underruns. - -### Advantages - -- Eliminates the need for external storage hardware (microSD card module). -- Simpler wiring and lower cost. -- Suitable for small, self-contained projects where a few short sound clips are needed. - -### Limitations - -- Limited storage for audio files. -- Requires careful management of the flash memory to avoid overwriting important files or the firmware. - -For projects with just a few short robot sound effects, storing the sounds on the Pico's flash memory is a practical and convenient option. \ No newline at end of file diff --git a/docs/sound/dac/index.md b/docs/sound/dac/index.md deleted file mode 100644 index 3dfc77121..000000000 --- a/docs/sound/dac/index.md +++ /dev/null @@ -1,2 +0,0 @@ -# Using a Digital to Analog Converter - diff --git a/docs/sound/index.md b/docs/sound/index.md deleted file mode 100644 index 4d43003fb..000000000 --- a/docs/sound/index.md +++ /dev/null @@ -1,53 +0,0 @@ -# Introduction to Sound and Music in MicroPython - -## How Microcontrollers Generate Sound - -Microcontrollers are really great at generating digital outputs on their GPIO pins. These digital signals that quickly switch between zero and a positive voltage like 3.3 or 5 volts. However, they are not designed to create "analog" output of a continuous varying voltage. However, we can use a technique called "Pulse Width Modulation" to simulate the various frequencies of sound using digital only outputs. - -[Pulse Width Modulation](https://en.wikipedia.org/wiki/Pulse-width_modulation) is the process of changing not the height of a electrical signal, but the width between the pulses of digital signals. By changing the distance of the spaces between the digital signals we can generate a signal that will sound like it has a higher or lower frequency or pitch. - -MicroPython provides a powerful library of tools for you to easily generate pulses of different shapes. This is called the PWM library. Will will use this in our sound and music programs. Here is a sample of how this is called in our code: - -## Duty Cycle -The Duty Cycle is what percent of time a pulse is high. - -![Duty Cycle](../img/duty-cycle.png) - -For working with sound, we want to generate smooth sound waves that are on 1/2 of the time and off 1/2 of the time. So our duty cycles will be set to be 50%. On the Raspberry Pi Pico we can achieve this by the following function: - -``` -speaker.duty_u16(1000) -``` - -When we are done playing a tone, we must always explicitly turn the duty cycle back to 0. - -``` -speaker.duty_u16(0) -``` - -If we forget to add this line, the tone will continue to play despite the main program stopping. This shows you that the part of the chip that generates the tone pulses is an independent processor that is not dependant on the main program running! - -```py -from machine import Pin, PWM -from utime import sleep -``` - -Note that we will also need to pause between notes, so will use the sleep library to pause execution of our sound generation. - -## Connecting a Sound Device - -There are several different ways that you can connect a sound device to you MicroController. Here are three options: - -1. **Buzzers** - These are small inexpensive devices that can mount directly on your breadboard. -2. **Piezoelectric Speaker** - [Wikipedia Page on Piezoelectric Speaker](https://en.wikipedia.org/wiki/Piezoelectric_speaker) -2. **Speaker** - A magnetic speaker with our without an amplifier is another way to hear sound. You can also purchase a small amplifier to increase the volume. -4. **Amplifier** - For about $1.20 you can purchase a small amplifier for your speaker. [eBay LM386 DC 5V-12V Mini Micro Audio Amplifier Module Board](https://www.ebay.com/itm/LM386-DC-5V-12V-Mini-Micro-Audio-Amplifier-Module-Board-Mono-AMP-ModuleEP-I/133596864305) - -![](../img/magnetic-buzzer.png) -![](../img/piezo-buzzer.png) - -## References - -[](https://electronics.stackexchange.com/questions/288930/what-is-the-difference-between-a-buzzer-and-a-speaker-and-are-there-any-other-ba) - -1, [Juke Phone in C](https://github.com/TuriSc/Jukephone) - convert an old land-line telephone to an MP3-player Jukebox. Although this is written in C, it could be converted into MicroPython. \ No newline at end of file diff --git a/docs/sound/midi/index.md b/docs/sound/midi/index.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/status.md b/docs/status.md deleted file mode 100644 index f70f6291a..000000000 --- a/docs/status.md +++ /dev/null @@ -1,23 +0,0 @@ -# Status of MicroPython Labs - -## Project Boxes - -### 10 Element LED Box - -1. Box finished -2. Video done -3. - -### Time of Flight Distance Sensor Display Box - -1. Box finished -2. TODO: Video - -### Pot Display Box - -1. Box finsished -2. Video finished - -### Compass Lab Box - -1. Box finished \ No newline at end of file diff --git a/docs/wireless/01-intro.md b/docs/wireless/01-intro.md deleted file mode 100644 index 5b36f8ee3..000000000 --- a/docs/wireless/01-intro.md +++ /dev/null @@ -1,25 +0,0 @@ -# Introduction to Networking with MicroPython - -These lessons are designed to give our students an understanding of how wireless communications work with MicroPython. - -## Raspberry Pi Pico W - -![Raspberry Pi Pico W](../img/pico-w.png) - -One June 30th, 2022 the [Raspberry Pi Foundation announced](https://www.raspberrypi.com/news/raspberry-pi-pico-w-your-6-iot-platform/) the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth. - -The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the [lwip](https://savannah.nongnu.org/projects/lwip/) TCP/IP stack. This stack is accessible using the MicroPython [network](https://docs.micropython.org/en/latest/library/network.html#) functions. - -The WiFi chip used is the [Infineon CYW43439](https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-wi-fi-plus-bluetooth-combos/cyw43439/) chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication. - -![Wireless Block Architecture](../img/wireless-block-arch.png) - -You can read more about the capabilities of the WiFi/Bluetooth chip by reading the [Infineon CYW43439 Datasheet](https://www.infineon.com/dgdl/Infineon-CYW43439-Single-Chip-IEEE-802.11-b-g-n-MAC-PHY-Radio-with-Integrated-Bluetooth-5.0-Compliance-AdditionalTechnicalInformation-v03_00-EN.pdf?fileId=8ac78c8c7ddc01d7017ddd033d78594d). I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains! - -## ESP32 Wireless - -We have not integrated the ESP32 into our labs. We suggest you try the following links: - -[ESP32 MicroPython: Connecting to a WiFi Network on Tech Tutorials SX](https://techtutorialsx.com/2017/06/01/esp32-micropython-connecting-to-a-wifi-network/) - -[MicroPython: Wi-Fi Manager with ESP32 (ESP8266 compatible) on Random Nerd Tutorials](https://randomnerdtutorials.com/micropython-wi-fi-manager-esp32-esp8266/) \ No newline at end of file diff --git a/docs/wireless/02-connecting-to-wifi.md b/docs/wireless/02-connecting-to-wifi.md deleted file mode 100644 index 794ed7be1..000000000 --- a/docs/wireless/02-connecting-to-wifi.md +++ /dev/null @@ -1,131 +0,0 @@ -# Connecting to a WiFi Network - -### Setting Up Your WIFI secrets.py -By convention, we put both our SSID and password in a python file called "secrets.py". This file should never be checked into a public source code repository. We can add ```secrets.py``` to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone. - -```python -SSID = "MY_WIFI_NETWORK_NAME" -PASSWORD = "MY_WIFI_PASSWORD" -``` - -By importing the secrets.py file you can then reference your network name like this: - -```py -print('Connecting to WiFi Network Name:', secrets.SSID) -``` - -### Testing Your WiFi Access Point Connection - -Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable. - -```python -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # power up the WiFi chip -print('Waiting for wifi chip to power up...') -sleep(3) # wait three seconds for the chip to power up and initialize -wlan.connect(secrets.SSID, secrets.PASSWORD) -print('Waiting for access point to log us in.') -sleep(2) -if wlan.isconnected(): - print('Success! We have connected to your access point!') - print('Try to ping the device at', wlan.ifconfig()[0]) -else: - print('Failure! We have not connected to your access point! Check your secrets.py file for errors.') -``` - -Returns: - -``` -Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME -Waiting for wifi chip to power up... -Waiting for access point to log us in... -Success! We have connected to your access point! -Try to ping the device at 10.0.0.70 -``` - -If the result is a ```Failure``` you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing. - -Note that we are using the ```sleep()``` function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly. - -### Waiting for a Valid Access Point Connection - -Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected. - -```python -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta, 'milliseconds') -print('IP Address:', wlan.ifconfig()[0]) -``` - -This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds. - -First run upon power on might take several seconds: -``` ->>> %Run -c $EDITOR_CONTENT -Connecting to WiFi Network Name: MY_NETWORK_NAME -Waiting for connection... -0.1.2.3.Connect Time: 4640 -IP Address: 10.0.0.70 -``` - -The second and consecutive runs will use a cached connection. - -``` ->>> %Run -c $EDITOR_CONTENT -Connecting to WiFi Network Name: MY_NETWORK_NAME -Connect Time: 0 milliseconds -IP Address: 10.0.0.70 ->>> -``` - -### Error Handling - -```python - -lan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(ssid, password) - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('connected') - status = wlan.ifconfig() - print( 'ip = ' + status[0] ) -``` - -The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above. diff --git a/docs/wireless/03-http-get.md b/docs/wireless/03-http-get.md deleted file mode 100644 index 4e66d91d1..000000000 --- a/docs/wireless/03-http-get.md +++ /dev/null @@ -1,44 +0,0 @@ -### Testing HTTP GET - -The following example was taken from [Tom's Hardware](https://www.tomshardware.com/how-to/connect-raspberry-pi-pico-w-to-the-internet) - -```python -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff -import urequests - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) - -start = ticks_ms() # start a millisecond counter - -astronauts = urequests.get("http://api.open-notify.org/astros.json").json() - -delta = ticks_diff(ticks_ms(), start) - -number = astronauts['number'] -print('There are', number, 'astronauts in space.') -for i in range(number): - print(i+1, astronauts['people'][i]['name']) - -print("HTTP GET Time in milliseconds:", delta) -``` - -Returns: - -``` -There are 10 astronauts in space. -1 Oleg Artemyev -2 Denis Matveev -3 Sergey Korsakov -4 Kjell Lindgren -5 Bob Hines -6 Samantha Cristoforetti -7 Jessica Watkins -8 Cai Xuzhe -9 Chen Dong -10 Liu Yang -HTTP GET Time in milliseconds: 786 -``` \ No newline at end of file diff --git a/docs/wireless/04-web-server.md b/docs/wireless/04-web-server.md deleted file mode 100644 index 6019e5c74..000000000 --- a/docs/wireless/04-web-server.md +++ /dev/null @@ -1,101 +0,0 @@ -# Web Server with MicroPython - -This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off. - -Screen image of Pico W Web Server: -![](../img/pico-w-web-page.png) - -```python -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -import network -import socket -import time -import secrets - -from machine import Pin - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - -

                                                                                                                                                  Pico Wireless Web Server

                                                                                                                                                  -

                                                                                                                                                  %s

                                                                                                                                                  - Turn On - Turn Off - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -print('addr:', addr) -s = socket.socket() -#if not addr: -s.bind(addr) -s.listen(1) - -print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - print('client connected from', addr) - request = cl.recv(1024) - print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - print( 'led on = ' + str(led_on)) - print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - print('connection closed') -``` - -## References - -[](https://www.petecodes.co.uk/creating-a-basic-raspberry-pi-pico-web-server-using-micropython/) \ No newline at end of file diff --git a/docs/wireless/05-mac-address.md b/docs/wireless/05-mac-address.md deleted file mode 100644 index 7eb47a367..000000000 --- a/docs/wireless/05-mac-address.md +++ /dev/null @@ -1,91 +0,0 @@ -# Getting Your MAC Address - -## What is a MAC Address? -Every device that works with Ethernet and WiFi must have a [Wikipedia Page on MAC Address](https://en.wikipedia.org/wiki/MAC_address). - -A MAC address (media access control address) is a unique identifier assigned to a network interface controller (NIC) for use as a network address in communications within a network segment. This use is common in most IEEE 802 networking technologies, including Ethernet, Wi-Fi, and Bluetooth. - -!!! Note - The MAC address has nothing to do with the Apple Macintosh or Mac OS. They just use the same name to mean different things. - -Understanding how devices use MAC addresses is essential to understanding how networks work and debugging them. - -The MAC address is six bytes or "octets". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the [Wikipedia Page on MAC Address](https://en.wikipedia.org/wiki/MAC_address) for more information. If you run this on your Pico W the first octets should be similar. - -Here are the two MAC addresses for two different Pico W devices that were purchase together. They came on adjacent parts of a "real" of devices. - -``` -28:cd:c1:1:35:54 -28:cd:c1:1:35:58 -``` - - -Because they were purchased together, their MAC address are very similar and only differ in the last few bits. - -This Pico W came from another distributer. - -``` -28:cd:c1:0:9e:19 -``` - -You can see that the first three octets are the same. A MAC address often can give clues about the origins of packets on your network. They can also be used as "serial numbers" for each device that connects to WiFi or Ethernet since they are usually burned into ROM at device manufacturing time and are designed to be unique. - -## Getting the MAC/Ethernet Access - -You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function. - -```python -import network -from utime import sleep, ticks_us, ticks_diff - -print('Getting MAC/Ethernet Address for this device.') - -start = ticks_us() # start a millisecond counter -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # this line powers up the chip - it takes about 2.5 seconds - -# This returns a byte array of hex numbers -mac_addess = wlan.config('mac') -print('Time in microseconds:', ticks_diff(ticks_us(), start)) -# each MAC address is 6 bytes or 48 bits -print("Hex byte array:", mac_addess, 'length:', len(mac_addess)) - -# This should be in hex per the Notational Conventions -# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions -# b'(\xcd\xc1\x015X' -# 28:cd:c1:1:35:58 -# format in MAC Notational Convention -for digit in range(0,5): - print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '') -print(str(hex(mac_addess[5]))[2:4] ) -``` - -First Time After Power On Results: -``` -Getting MAC/Ethernet Address for this device. -Time in microseconds: 2584424 -Hex byte array: b'(\xcd\xc1\x015X' length: 6 -28:cd:c1:1:35:58 -``` - -Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address. - -Subsequent Times -``` -Getting MAC/Ethernet Address for this device. -Time in microseconds: 211 -Hex byte array: b'(\xcd\xc1\x015X' length: 6 -28:cd:c1:1:35:58 -``` - -!!! Note - We must add the ```wlan.active(True)``` line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros. - - -I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking. - -## MAC Addresses and Privacy - -MAC addresses are never sent to web servers to protect a clinet's privacy, but if you are debugging networks and looking at tools such as WireShark, they become visible to a local LAN administrator. MAC addresses are also visible to WiFi access points, so your local coffee shop that provides free WiFi could keep track of every time repeat customers use their WiFi access points. - -Some computers such as [Apple generate a different MAC address](https://support.apple.com/en-us/HT211227) for each different access point they connect to. This prevents multiple stores from connecting your profiles together. So Starbucks can't use your MAC address to offer you a free coffee every 10th visit to different stores, but if you visit a local coffee shop they can use their WiFi access logs to see their same-store repeat customers. \ No newline at end of file diff --git a/docs/wireless/06-upip.md b/docs/wireless/06-upip.md deleted file mode 100644 index 3926b367b..000000000 --- a/docs/wireless/06-upip.md +++ /dev/null @@ -1,102 +0,0 @@ -# MicroPython PIP (UPIP) - -MicroPython also has a package manager called ```upip``` that can be run directly on the microcontroller. This means that every time you get a new microcontroller, you can automatically download all the python packages you need directly from the Internet using a single python program after ```upip``` has been installed. - -This also means that you don't need copies of these libraries installed on your local PC. - -## Install UPIP From Thonny Package Manager - -Go to the Thonny Tools -> Manage Packages... menu. Type "upip" in the search field and click the **Search on PyPL** button: - -![Thonny UPIP Search](../img/thonny-upip.png) - -The first search result will be for **micropython-upip". Click on that link and you will see the details. - -![Thonny UPIP Search](../img/thonny-upip-details.png) - -## Install A Package - -The following program assumes that you have followed the steps in our [Connecting to WiFi](./02-connecting-to-wifi.md) and have a secrets.py file that have your WiFi network name (SSID) and password (PASSWORD). - -```python -import upip -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - counter += 1 - print(counter, '.', sep='', end='', ) - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta) - -# This is the line you must modify for each package you want to install -# pystone is a CPU performance benchmarking tool that is easy to run to and test installation - -start = ticks_ms() - -upip.install("micropython-pystone_lowmem") - -print("Download Time:", ticks_diff(ticks_ms(), start), milliseconds) -``` - -Results: - -``` -Connecting to WiFi Network Name: MY_NETWORK_NAME -Waiting for connection... -1.2.3.4.Connect Time: 4641 -Installing to: /lib/ -Warning: micropython.org SSL certificate is not validated -Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz -Download Time: 4918 milliseconds -``` - -## Testing Your Newly Installed Library - -```py -import pystone_lowmem -pystone_lowmem.main() -``` - -Results: - -``` -Pystone(1.2) time for 500 passes = 410ms -This machine benchmarks at 1219 pystones/second -``` - -## Getting UPIP Help - -```python -import upip -upip.help() -``` - -returns: - -``` -upip - Simple PyPI package manager for MicroPython -Usage: micropython -m upip install [-p ] ... | -r -import upip; upip.install(package_or_list, []) - -If isn't given, packages will be installed to sys.path[1], or -sys.path[2] if the former is .frozen (path can be set from MICROPYPATH -environment variable if supported). -Default install path: /lib - -Note: only MicroPython packages (usually, named micropython-*) are supported -for installation, upip does not support arbitrary code in setup.py. -``` \ No newline at end of file diff --git a/docs/wireless/07-web-server-rgb-neopixels.md b/docs/wireless/07-web-server-rgb-neopixels.md deleted file mode 100644 index 95f652058..000000000 --- a/docs/wireless/07-web-server-rgb-neopixels.md +++ /dev/null @@ -1,253 +0,0 @@ -# Web Server NeoPixel RGB - -![](../img/wireless-rgb-web-controller.png) - -## Sample Code with CSS - -```python -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -from machine import Pin -from neopixel import NeoPixel -import network -import socket -from time import sleep -import secrets - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -# setup -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255,0,0) -green = (0,255,0) -blue = (0,0,255) -off = (0,0,0) - -def set_color(color): - for i in range(0, NUMBER_PIXELS): - strip[i] = color - strip.write() - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - - -

                                                                                                                                                  Pico Wireless Web Server

                                                                                                                                                  -

                                                                                                                                                  Onboard LED State: %s

                                                                                                                                                  - - -
                                                                                                                                                  - - - Turn Onboard LED On - Turn Onboard LED Off -
                                                                                                                                                  - - - Red LED On - Red LED Off -
                                                                                                                                                  - - - Green LED On - Green LED Off -
                                                                                                                                                  - - - Blue LED On - Blue LED Off - - -
                                                                                                                                                  - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - sleep(1) - led.toggle() - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -# print('addr:', addr) - -s = socket.socket() -# this prevents the "OSError: [Errno 98] EADDRINUSE" error for repeated tests -s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -# print('Got a sockert. s:', s) - -#if not addr: - -# print('going to run bind to addr on the socket') -s.bind(addr) - -# print('going to run listen(1) on socket') -s.listen(1) - -# print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - # print('client connected from', addr) - request = cl.recv(1024) - # print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - - red_on = request.find('/led/red/on') - red_off = request.find('/led/red/off') - - green_on = request.find('/led/green/on') - green_off = request.find('/led/green/off') - - blue_on = request.find('/led/blue/on') - blue_off = request.find('/led/blue/off') - - # print( 'led on = ' + str(led_on)) - # print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.on() - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.off() - stateis = "LED is OFF" - - if red_on == 6: - print("red on") - set_color(red) - if red_off == 6: - print("red off") - set_color(off) - - if green_on == 6: - print("green on") - set_color(green) - if green_off == 6: - print("green off") - set_color(off) - - if blue_on == 6: - print("blue on") - set_color(blue) - if blue_off == 6: - print("blue off") - set_color(off) - - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - s.close() - print('connection closed') -``` - -## References - -Clear Fix Floating Boxes Example - -https://www.w3schools.com/css/tryit.asp?filename=trycss_float_boxes - -```html - - - - -

                                                                                                                                                  Grid of Boxes

                                                                                                                                                  -

                                                                                                                                                  Float boxes side by side:

                                                                                                                                                  - -
                                                                                                                                                  -
                                                                                                                                                  -

                                                                                                                                                  Some text inside the box.

                                                                                                                                                  -
                                                                                                                                                  -
                                                                                                                                                  -

                                                                                                                                                  Some text inside the box.

                                                                                                                                                  -
                                                                                                                                                  -
                                                                                                                                                  -``` \ No newline at end of file diff --git a/docs/wireless/08-get-weather.md b/docs/wireless/08-get-weather.md deleted file mode 100644 index f1d12e3d7..000000000 --- a/docs/wireless/08-get-weather.md +++ /dev/null @@ -1,199 +0,0 @@ -# Get the Weather Forecast - -This demo uses the free web service [Open Weather Map](http://openweathermap.org). - -The Open Weather Map service returns the predicted temperatures and conditions (sun, cloudy, rain etc.) for three-hour intervals for the next 40 intervals at your specified location. - -You can see this using the UNIX curl command: - -```sh -curl 'http://api.openweathermap.org/data/2.5/forecast?\ - units=imperial&\ - id=5037649&\ - appid=f2b1...' -``` - -In this example, we are asking it to use US standard Fahrenheit (imperial units) for the city with id 5037649 which is Minneapolis, MN in the USA. You can use the Open Weather site to find the id for your city or specify the longitude and latitude of the point you want to get weather forecasts for. You can also use the [GeoNames](https://www.geonames.org/5037649/minneapolis.html) to find your city ID number. - -## How to Use the Open Weather Map API - -To use this service, you must register and get an API key. You then put your key in the secrets.py file: - -Content of secrets.py -```python -appid='f2b1...' -``` - -The secrets.py file is then imported into your program. Make sure to put secrets.py into your .gitignore file so it will not be checked into your public GitHub repo. - -The URL for the service is then created by concatenating the base URL, the city location ID and the application id: - -```python -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # GeoNames ID for Minneapolis in Minnesota, USA -url = base + 'id=' + location + '&appid=' + secrets.appid -``` - -## Parsing the JSON file - -The service returns a JSON file with the following format: - -```json -{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1660078800, - "main": { - "temp": 80.83, - "feels_like": 81.23, - "temp_min": 80.83, - "temp_max": 84.67, - "pressure": 1019, - "sea_level": 1019, - "grnd_level": 988, - "humidity": 47, - "temp_kf": -2.13 - }, - "weather": [ - { - "id": 800, - "main": "Clear", - "description": "clear sky", - "icon": "01d" - } - ], - "clouds": { - "all": 0 - }, - "wind": { - "speed": 6.08, - "deg": 226, - "gust": 6.38 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2022-08-09 21:00:00" - }, - /* ...repeated 40 times */ - , - "city": { - "id": 5037649, - "name": "Minneapolis", - "coord": { - "lat": 44.98, - "lon": -93.2638 - }, - "country": "US", - "population": 0, - "timezone": -18000, - "sunrise": 1660043269, - "sunset": 1660094963 - } -} -``` - -The bulk of the data is in the list structure with 40 items with a small set of data before and after the list. The data about the HTTP status (200) and the count (40) is before the list and the data about the city is after the list. - -Each block of data in the list JSON object contains data about the main data (temperature, min, max, pressure, humidity), cloud cover, wind speed and visibility. It is up to you to decide what data you would like to display within this data. Once you decide what data you want to access you can use JSON path statements to pull the right data out. For example, to get the main temperature for each time period you would run: - -```python -# get the temp and humidity for the next 40 3-hour intervals -for i in range(0, 39): - print('temp:', weather['list'][i]['main']['temp'], end='') - print('humidity:', weather['list'][i]['main']['humidity']) -``` - -## Sample Output - -Here is the output on the Thonny shell of the first 16 temperature values: - -![Network Weather Results](../img/network-weather-results.png) - -## Plotting the Forecast with Thonny Plot - -Here is a plot of the temp and the "feels like" temp using the Thonny Plotter panel. - -![Wireless Forecast Thonny Plot](../img/network-forecast-thonny-plot.png) - -Each line has: - -1. a label string -2. a colon -3. the numeric value - -for each value plotted. There can be multiple values per line. - -Here is that format: - -``` -Temperature: 63 Feels Like: 63.52 -Temperature: 62 Feels Like: 62.56 -Temperature: 70 Feels Like: 69.69 -``` - -## Sample Code - -```python -import network -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta, 'milliseconds') -print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid - -weather = urequests.get(url).json() -print('City:', weather['city']['name']) -print('Timezone:', weather['city']['timezone']) - -max_times = 16 -# for i in range(0, 39): -for i in range(0, max_times): - print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='') -print() -for i in range(0, max_times): - print(round(weather['list'][i]['main']['temp']), ' ', end='') - # print('feels like:', weather['list'][i]['main']['feels_like']) - # print(weather['list'][i]['weather'][0]['description']) - # print(weather['list'][i]['dt_txt']) - -# print(weather) -``` - -## Displaying Predicted Temperatures in a Thonny Plot - -Thonny has a [Plot object](https://github.com/thonny/thonny/blob/707e69ec3a567df5f82205c5a2ae0d79f186ed25/thonny/plugins/help/plotter.rst) that you can use to display the relative temperature for the next 40 3-hour cycles. - -To do this, we only need to print out the temperatures each on a separate line: - -```python -print() -for i in range(0, max_times): - print(round(weather['list'][i]['main']['temp'])) -``` \ No newline at end of file diff --git a/docs/wireless/09-get-weather-display.md b/docs/wireless/09-get-weather-display.md deleted file mode 100644 index 40248d9eb..000000000 --- a/docs/wireless/09-get-weather-display.md +++ /dev/null @@ -1,277 +0,0 @@ -# Get Weather on an OLED Display - -![Network Weather Display](../img/network-weather-display.jpg) - -In this lesson we will use the Pico W to get a weather forecast from a web service and display the current and forecasted temperatures on a 128x64 OLED display. The display above shows the city and current temperature on the top row of the display and then a plot of the predicted temperatures for the next 120 hours. The max temperature is 87 degrees and the minimum is 60 degrees Fahrenheit. - -## Calling the Weather API - -We will use the same method as in the [previous lesson](./08-get-weather.md) to get the weather forecast. However, in this lesson we will not just plot the temperature on the Thonny plot screen, we will use a OLED screen. - -To do this we will need to write a function that will display the temperature data. The function will display the current location city name, the current temperature, and then draw a plot of the next 40 3-hour intervals. This lesson is a bit harder because we have to manually do all the work of scaling and plotting our data. This is all done for us in the prior Thonny plotting lab. - -To achieve this we will need to scale the data to fit the display grid. We will reserve the top 10 pixels for the city and current temp and then draw the plot on the remaining 54 pixel high and 128 pixel wide plot region. - -To scale the data we will need to find the min and max temperatures. These will also be displayed on the screen. The scale is then the ratio of the graph height over the temperature range. For example if the range of temperatures is 27 degrees and the height of the display is 54 we will need to scale the temperature vertically by 2. - -The horizontal axis will go from 0 to 120. Since we have 40 points, each point will occur every 3rd pixel. We can then look at the difference between the current point and the next point to interpolate the dots between the two points. - -The math can be a little confusing since higher temperatures are closer to the top of the display, so they have a lower Y coordinate value. Note the y_delta is subtracted from the next value: - -```py - y_delta = -round((y - y_next)/3) # a small positive or negative number for interpolation -``` - -```py -def display_weather(): - global weather, city, current_temp - oled.fill(0) - min = 120 - max = -50 - for i in range(0, 39): - temp = round(weather['list'][i]['main']['temp']) - if temp < min: - min = temp - if temp > max: - max = temp - min = round(min) - max = round(max) - temp_range_height = max - min - graph_height = 54 - scale = graph_height/temp_range_height - print('min/max/range/scale:', min, max, temp_range_height, scale) - - # display city name, current temp, min and max - oled.text(city + ': ' + str(current_temp), 0, 0, 1) - oled.text(str(min), 0, 57, 1) # bottom left corner - oled.text(str(max), 0, 10, 1) # under top row - - max_points = 39 - - # graph temps for the next n periods - print('Date Tmp TNx Y Y2 Del') - for i in range(0, max_points): - temp = round(weather['list'][i]['main']['temp']) - x = i * 3 # scaled x - y = 63 - round((temp - min)*scale) - oled.pixel(x, y, 1) - - # now draw the next two points - if i < max_points: - temp_next = round(weather['list'][i+1]['main']['temp']) - y_next = 63 - round((temp_next - min)*scale) - y_delta = -round((y - y_next)/3) # a small positive or negative number - - # for debugging - fixed with columns with leading spaces - print(weather['list'][i]['dt_txt'][0:13], - '{: 3.3d}'.format(temp), - '{: 3.3d}'.format(temp_next), - '{: 3.3d}'.format(y), - '{: 3.3d}'.format(y_next), - '{: 3.3d}'.format(y_delta)) - - # should be 1/3 of the way to the next point - oled.pixel(x+1, y + y_delta, 1) - # should be 2/3 of the way to the next point - oled.pixel(x+2, y + 2*y_delta, 1) - oled.show() -``` - -## The Main Loop - -The main loop repeats forever, pausing every hour between updates. It gets first calls the rest service, -extracts the city name and current temperature and then calls the display_weather() function using global variables for the JSON file, city and current temperature. - -```python -while True: - # globals: weather, city, current_temp - weather = urequests.get(url).json() - # print(weather) - city = weather['city']['name'] - current_temp = round(weather['list'][0]['main']['temp']) - display_weather() - print('Going to sleep for one hour') - sleep(3600) # sleep one hour -``` - -## Full Sample Code - -```python -import network -import ssd1306 -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -# startup - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def display_startup(counter): - oled.fill(0) - oled.text('Running startup', 0, 10, 1) - oled.text('Connecting to', 0, 20, 1) - oled.text(secrets.SSID, 0, 30, 1) - oled.text(str(counter), 0, 40, 1) - oled.show() - -def display_status(counter): - oled.fill(0) - # display the network name - oled.text('n:' + secrets.SSID, 0, 0, 1) - - # display the connection time - oled.text('t:', 0, 10, 1) - oled.text(str(connection_time)+ ' ms', 15, 10, 1) - oled.show() - -def display_weather(): - global weather, city, current_temp - oled.fill(0) - min = 120 - max = -50 - for i in range(0, 39): - temp = round(weather['list'][i]['main']['temp']) - if temp < min: - min = temp - if temp > max: - max = temp - min = round(min) - max = round(max) - temp_range_height = max - min - graph_height = 54 - scale = graph_height/temp_range_height - print('min/max/range/scale:', min, max, temp_range_height, scale) - - # display city name, current temp, min and max - oled.text(city + ': ' + str(current_temp), 0, 0, 1) - oled.text(str(min), 0, 57, 1) # bottom left corner - oled.text(str(max), 0, 10, 1) # under top row - - max_points = 39 - - # graph temps for the next n periods - print('Date Tmp TNx Y Y2 Del') - for i in range(0, max_points): - temp = round(weather['list'][i]['main']['temp']) - x = i * 3 # scaled x - y = 63 - round((temp - min)*scale) - oled.pixel(x, y, 1) - - # now draw the next two points - if i < max_points: - temp_next = round(weather['list'][i+1]['main']['temp']) - y_next = 63 - round((temp_next - min)*scale) - y_delta = -round((y - y_next)/3) # a small positive or negative number - - print(weather['list'][i]['dt_txt'][0:13], - '{: 3.3d}'.format(temp), - '{: 3.3d}'.format(temp_next), - '{: 3.3d}'.format(y), - '{: 3.3d}'.format(y_next), - '{: 3.3d}'.format(y_delta)) - - # should be 1/3 of the way to the next point - oled.pixel(x+1, y + y_delta, 1) - # should be 2/3 of the way to the next point - oled.pixel(x+2, y + 2*y_delta, 1) - oled.show() - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - display_startup(counter) - -delta = ticks_diff(ticks_ms(), start) -#print("Connect Time:", delta, 'milliseconds') -#print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # Minneapolis, MN USA -url = base + 'id=' + location + '&appid=' + secrets.appid -#print(url) - -max_times = 39 -#for i in range(0, max_times): - #print(' Temp: ', weather['list'][i]['main']['temp']) - -while True: - # globals: weather, city, current_temp - weather = urequests.get(url).json() - # print(weather) - city = weather['city']['name'] - current_temp = round(weather['list'][0]['main']['temp']) - display_weather() - print('Going to sleep for one hour.') - sleep(3600) # sleep one hour -``` - -## Sample Debugging - -To allow you to see the math for the plotting and interpolation we have added a print that prints the temperatures and y coordinates in fixed with format. Here is an example of this output: - -``` -Connecting to WiFi Network Name: anndan-2.4 -min/max/range/scale: 60 87 27 2.0 -Date Tmp Tnx Y Y2 Del -2022-08-13 03 68 68 47 47 0 -2022-08-13 06 68 68 47 47 0 -2022-08-13 09 68 65 47 53 2 -2022-08-13 12 65 72 53 39 -5 -2022-08-13 15 72 83 39 17 -7 -2022-08-13 18 83 87 17 9 -3 -2022-08-13 21 87 82 9 19 3 -2022-08-14 00 82 71 19 41 7 -2022-08-14 03 71 66 41 51 3 -2022-08-14 06 66 62 51 59 3 -2022-08-14 09 62 60 59 63 1 -2022-08-14 12 60 71 63 41 -7 -2022-08-14 15 71 82 41 19 -7 -2022-08-14 18 82 85 19 13 -2 -2022-08-14 21 85 82 13 19 2 -2022-08-15 00 82 73 19 37 6 -2022-08-15 03 73 69 37 45 3 -2022-08-15 06 69 66 45 51 2 -2022-08-15 09 66 64 51 55 1 -2022-08-15 12 64 74 55 35 -7 -2022-08-15 15 74 83 35 17 -6 -2022-08-15 18 83 85 17 13 -1 -2022-08-15 21 85 81 13 21 3 -2022-08-16 00 81 75 21 33 4 -2022-08-16 03 75 70 33 43 3 -2022-08-16 06 70 69 43 45 1 -2022-08-16 09 69 66 45 51 2 -2022-08-16 12 66 66 51 51 0 -2022-08-16 15 66 79 51 25 -9 -2022-08-16 18 79 80 25 23 -1 -2022-08-16 21 80 70 23 43 7 -2022-08-17 00 70 65 43 53 3 -2022-08-17 03 65 64 53 55 1 -2022-08-17 06 64 63 55 57 1 -2022-08-17 09 63 61 57 61 1 -2022-08-17 12 61 72 61 39 -7 -2022-08-17 15 72 82 39 19 -7 -2022-08-17 18 82 85 19 13 -2 -2022-08-17 21 85 81 13 21 3 -Going to sleep for one hour -``` \ No newline at end of file diff --git a/docs/wireless/10-wifi-clock.md b/docs/wireless/10-wifi-clock.md deleted file mode 100644 index a877e0b8b..000000000 --- a/docs/wireless/10-wifi-clock.md +++ /dev/null @@ -1,136 +0,0 @@ -# WiFi Clock - -In the US, we can access a service called the "Network Time Protocol" or NTP. -This service allows you to get the precise time using your WiFi network. - -Calling the NTP service in MicroPython is simple once you have -connected to your local wireless access point: - -```py -import ntptime -ntptime.host = 'us.pool.ntp.org' -ntptime.timeout = 10 -ntptime.settime() -``` - -After running this code (and checking for errors) your internal Real-time Clock (RTC) will be synced to the NTP server. - -The rest of this code does the work of adjusting the clock to your local timezone and correcting for any changes in daylight savings time in your area. - -## The Config File - -We always put local credentials in a separate file so it does not get checked into GitHub. - -```py -wifi_ssid = 'mywifinetworkname' -wifi_pass = 'mypassword' -``` - -## Full Program - -```py -import ntptime, network -from machine import RTC -from utime import sleep, sleep_ms, time, localtime, mktime -import config - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -def setRTC(): - timeset = False - timetries = 0 - maxtries = 5 - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.') - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - # print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - print('ERROR! Unable to update time from server!') - return False - -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -if __name__ == '__main__': - while True: - update() - sleep(60) -``` - -## Sample Output: - -The console will display the following: - -``` -Connecting......... -Connected: True -IP: 10.0.0.118 -NTP update attempt # 1 of 5 failed! Retrying in 15 seconds.. -... -7:41pm 9/10/23 -7:42pm 9/10/23 -7:43pm 9/10/23 -``` - -Note that connecting to the NTP server failed the first time but worked on the second attempt. - -This program assumes you have a config.py file in the same folder that the clock.py program runs. - -## References - -[NikoKun](https://www.reddit.com/r/raspberrypipico/comments/16f07ww/a_pico_powered_clock/) - - diff --git a/docs/wireless/11-advanced-labs.md b/docs/wireless/11-advanced-labs.md deleted file mode 100644 index 03ca117c8..000000000 --- a/docs/wireless/11-advanced-labs.md +++ /dev/null @@ -1,57 +0,0 @@ -# Advanced Wireless Labs - -## Secure Communications with HTTPS - -In our documentation we frequently refer to secure communications as using a "Secure Sockets Layer". Although the term "SSL" is common, we are actually using a protocol called Transport Layer Security (TLS). - -TLS replaces SSL. It is an Internet Engineering Task Force (IETF) standard protocol that provides authentication, privacy and data integrity between two communicating computer applications. - -!!! Note - The standard Python [request library](https://www.w3schools.com/python/module_requests.asp) does not yet support HTTPS on urequest on the Pico W. This is because there are additional tools that require us to use keys and certificates to validate data on an encrypted SSL stream. - -See the [MicroPython SSL/TLS Library](https://docs.micropython.org/en/latest/library/ssl.html) - -## Testing SSL/TLS on Standard Python - -```python -import socket -import ssl - -hostname = 'www.python.org' -context = ssl.create_default_context() - -with socket.create_connection((hostname, 443)) as sock: - with context.wrap_socket(sock, server_hostname=hostname) as ssock: - print(ssock.version()) -``` - -returns: TLSv1.3 - -This tells you that the standard Python socket libraries use the TLS v1.3 protocol. - -## Performance Monitoring with uiperf3 - -[iperf3](https://iperf.fr/iperf-doc.php) is a standard Python program for internet performance testing. For micropython, we have our own stripped down version called uiperf3. - -IPerf3 uses a client-server testing model and measures networking performance between two system using various protocoos such as - -* UDP - User Datagram Protocol -* TCP - Transmission Control Protocol -* Streaming - -It can also be used to measure total wireless throughput. - -## UPIP Install - -```py -upip.install("uiperf3") -``` - -## Testing Client Performance -```python -import uiperf3 - uiperf3.client('MY_IP_ADDRESS') -``` - - - diff --git a/docs/wireless/12-display-clock.md b/docs/wireless/12-display-clock.md deleted file mode 100644 index 8e418b315..000000000 --- a/docs/wireless/12-display-clock.md +++ /dev/null @@ -1,114 +0,0 @@ -# Display Clock - -This is similar to the [WiFi Clock](./10-wifi-clock.md) but it uses an OLED display to -show the time and date. - -```py -from machine import Pin -import network -import ntptime -import ssd1306 -# where we keep the WiFi password -import secrets -from utime import sleep, ticks_ms, ticks_diff - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(4) -DC = machine.Pin(5) -RES = machine.Pin(6) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -timestr = '' -datestr = '' -dtime = [] -def setRTC(): - global timestr, datestr, dtime - timeset = False - timetries = 0 - maxtries = 5 - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.') - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - # set globals - # hh:mm in 12hr am/pm format - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - # mm/dd/yy - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - # print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - print('ERROR! Unable to update time from server!') - return False - -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -def update_display(): - global timestr, datestr,dtime - oled.fill(0) - oled.text(timestr + ' ' + datestr, 0, 10, 1) - oled.show() - -while True: - update() - update_display() - sleep(60) - -``` \ No newline at end of file diff --git a/docs/wireless/20-display.md b/docs/wireless/20-display.md deleted file mode 100644 index c4138f98c..000000000 --- a/docs/wireless/20-display.md +++ /dev/null @@ -1,97 +0,0 @@ -# Wireless With Display - -![Wireless Display](../img/wireless-display-connection-status.jpg) - -In this lesson, we will add a 128x64 OLED display to our Pico "W" to display network information. - -The display we are using is a 2.42" Diymore OLED display as describe in the [Display Graphics](../displays/graph/11-oled-ssd1306-spi.md). - -```py -# make a number scroll to the right and increment the number and move down one pixel -# this test patten shows the device is working and will not burn any single pixel if it runs a long time -from machine import Pin -import network -import ssd1306 -import secrets -from utime import sleep, ticks_ms, ticks_diff - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def mac_address_fmt(): - mac_addess = wlan.config('mac') - s="" - for digit in range(0,5): - s+=str(hex(mac_addess[digit]))[2:4] + ':' - s+= hex(mac_addess[5])[2:4] - return s - -def display_startup(counter): - oled.fill(0) - oled.text('Running startup', 0, 10, 1) - oled.text('Connecting to', 0, 20, 1) - oled.text(secrets.SSID, 0, 30, 1) - oled.text(str(counter), 0, 40, 1) - oled.show() - -def display_status(counter): - oled.fill(0) - # display the network name - oled.text('n:' + secrets.SSID, 0, 0, 1) - - # display the connection time - oled.text('t:', 0, 10, 1) - oled.text(str(connection_time)+ ' ms', 15, 10, 1) - - # display the MAC address - oled.text(mac_address_fmt(), 0, 20, 1) - - # display the IP address - oled.text('ip:' + wlan.ifconfig()[0], 0, 30, 1) - oled.text('c:' + str(counter), 0, 40, 1) - oled.show() -# startup -led = Pin("LED", Pin.OUT) -led.on() - -start = ticks_ms() # start a millisecond counter - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - # this should normally take 3-5 seconds... - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - display_startup(counter) - while not wlan.isconnected(): - sleep(1) - counter += 1 - led.toggle() - display_startup(counter) - print(counter, '.', sep='', end='') - -connection_time = ticks_diff(ticks_ms(), start) -mac_addess = wlan.config('mac') -print('Connected to', secrets.SSID) -print('Total connect milliseconds:', connection_time) - -counter = 0 -while True: - led.toggle() - counter += 1 - display_status(counter) - sleep(1) - print(counter, 'listening on', wlan.ifconfig()[0]) -``` - diff --git a/getting-started/01-intro/index.html b/getting-started/01-intro/index.html new file mode 100644 index 000000000..4567fc779 --- /dev/null +++ b/getting-started/01-intro/index.html @@ -0,0 +1,1732 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                  +
                                                                                                                                                  + +
                                                                                                                                                  + + + + + + +
                                                                                                                                                  +
                                                                                                                                                  + + + logo + + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                  +
                                                                                                                                                  + + + Introduction + + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + + + + + + + +
                                                                                                                                                  + +
                                                                                                                                                  +
                                                                                                                                                  + + +
                                                                                                                                                  + + +
                                                                                                                                                  + +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                  + Initializing search +
                                                                                                                                                  +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + +
                                                                                                                                                    + +
                                                                                                                                                    + + +
                                                                                                                                                    +
                                                                                                                                                    + GitHub Repo +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                    + +
                                                                                                                                                    + +
                                                                                                                                                    + + + + + + +
                                                                                                                                                    +
                                                                                                                                                    + + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + + +
                                                                                                                                                    + + +
                                                                                                                                                    + +
                                                                                                                                                    + + +
                                                                                                                                                    +
                                                                                                                                                    + GitHub Repo +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                      + + + + + + + +
                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                      + +
                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                                                                                        + + + + + + + +
                                                                                                                                                          + +
                                                                                                                                                        • + + + Intended Audience + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + Preferred Skills + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + Course Outline + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + License of Content + + + +
                                                                                                                                                        • + +
                                                                                                                                                        + +
                                                                                                                                                        + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Boards + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Displays + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Sourcing Parts + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + ESP32 + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Powering Your Projects + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + Thonny IDE + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + VS Code IDE + + + + +
                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                      • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                      • + + + + +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                    • + + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + +
                                                                                                                                                    + + + + + + + +
                                                                                                                                                      + +
                                                                                                                                                    • + + + Intended Audience + + + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + Preferred Skills + + + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + Course Outline + + + +
                                                                                                                                                    • + +
                                                                                                                                                    • + + + License of Content + + + +
                                                                                                                                                    • + +
                                                                                                                                                    + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + +
                                                                                                                                                    +
                                                                                                                                                    + + + + + + + +

                                                                                                                                                    Welcome to the CoderDojo course on MicroPython

                                                                                                                                                    +

                                                                                                                                                    This course is about MicroPython, a variation of the popular Python programming language that is used to program microcontrollers.

                                                                                                                                                    +

                                                                                                                                                    Intended Audience

                                                                                                                                                    +
                                                                                                                                                      +
                                                                                                                                                    • Junior High or High School Students
                                                                                                                                                    • +
                                                                                                                                                    • Age 10-16
                                                                                                                                                    • +
                                                                                                                                                    +

                                                                                                                                                    Preferred Skills

                                                                                                                                                    +
                                                                                                                                                      +
                                                                                                                                                    • Familiarity with basic text editing functions such as select, copy and paste
                                                                                                                                                    • +
                                                                                                                                                    • Understand how to save files to disk
                                                                                                                                                    • +
                                                                                                                                                    • Basic understanding of Python programming language (We strongly suggest you take the Introduction to Python Programming CoderDojo Course if you are not familiar with Python.)
                                                                                                                                                    • +
                                                                                                                                                    • +

                                                                                                                                                      User should be familiar with the the following Python concepts:

                                                                                                                                                      +
                                                                                                                                                    • +
                                                                                                                                                    • +

                                                                                                                                                      imports

                                                                                                                                                      +
                                                                                                                                                    • +
                                                                                                                                                    • libraries
                                                                                                                                                    • +
                                                                                                                                                    • variables
                                                                                                                                                    • +
                                                                                                                                                    • loops
                                                                                                                                                    • +
                                                                                                                                                    • conditionals
                                                                                                                                                    • +
                                                                                                                                                    • lists
                                                                                                                                                    • +
                                                                                                                                                    • functions
                                                                                                                                                    • +
                                                                                                                                                    • function parameters
                                                                                                                                                    • +
                                                                                                                                                    +

                                                                                                                                                    Course Outline

                                                                                                                                                    +
                                                                                                                                                      +
                                                                                                                                                    • What is a Microcontroller?
                                                                                                                                                    • +
                                                                                                                                                    • What is Micropython?
                                                                                                                                                    • +
                                                                                                                                                    • Raspberry Pi Pico
                                                                                                                                                    • +
                                                                                                                                                    • Getting Started: Setting up MicroPython environment using Thonny or VS Code
                                                                                                                                                    • +
                                                                                                                                                    • Introduction to MicroPython - Getting Started
                                                                                                                                                    • +
                                                                                                                                                    • Sensors: getting information about the world around us
                                                                                                                                                    • +
                                                                                                                                                    • Displays: showing information to users
                                                                                                                                                    • +
                                                                                                                                                    • Sound and Music: playing tones, sounds and music
                                                                                                                                                    • +
                                                                                                                                                    • OLED Displays: drawing on displays
                                                                                                                                                    • +
                                                                                                                                                    • Robots: making robots move around with motors
                                                                                                                                                    • +
                                                                                                                                                    • Advanced Topics
                                                                                                                                                    • +
                                                                                                                                                    +

                                                                                                                                                    License of Content

                                                                                                                                                    +

                                                                                                                                                    Our intent is to allow teachers and mentors around the world to integrate MicroPython into their courses without any fees. We want you to be able to use this content freely with a few conditions: please give us attribution and please don't resell our content for profit.

                                                                                                                                                    +

                                                                                                                                                    Note that we use the same Creative Commons licensing as the Raspberry Pi Foundation and the CoderDojo Foundation:

                                                                                                                                                    +

                                                                                                                                                    Creative Commons Attribution NonCommercial ShareAlike

                                                                                                                                                    +

                                                                                                                                                    This means you are free to reuse and remix this content for non-commercial educational purposes as long as you keep the attribution and preserve the license agreement.

                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                    +
                                                                                                                                                    + + + +
                                                                                                                                                    + + + +
                                                                                                                                                    + +
                                                                                                                                                    + + + +
                                                                                                                                                    + + + +
                                                                                                                                                    + + +
                                                                                                                                                    +
                                                                                                                                                    + + Previous + +
                                                                                                                                                    + Microcontrollers +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + + +
                                                                                                                                                    + + Next + +
                                                                                                                                                    + Solderless Breadboards +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                    + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                    + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/01b-libraries/index.html b/getting-started/01b-libraries/index.html new file mode 100644 index 000000000..630cd51e4 --- /dev/null +++ b/getting-started/01b-libraries/index.html @@ -0,0 +1,1999 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroPython Libraries - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                    +
                                                                                                                                                    + +
                                                                                                                                                    + + + + + + +
                                                                                                                                                    +
                                                                                                                                                    + + + logo + + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                    +
                                                                                                                                                    + + + MicroPython Libraries + + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + + + + + + + +
                                                                                                                                                    + +
                                                                                                                                                    +
                                                                                                                                                    + + +
                                                                                                                                                    + + +
                                                                                                                                                    + +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    +
                                                                                                                                                    + Initializing search +
                                                                                                                                                    +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + +
                                                                                                                                                      + +
                                                                                                                                                      + + +
                                                                                                                                                      +
                                                                                                                                                      + GitHub Repo +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                      + +
                                                                                                                                                      + +
                                                                                                                                                      + + + + + + +
                                                                                                                                                      +
                                                                                                                                                      + + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + + +
                                                                                                                                                      + + +
                                                                                                                                                      + +
                                                                                                                                                      + + +
                                                                                                                                                      +
                                                                                                                                                      + GitHub Repo +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                        + + + + + + + +
                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                        + +
                                                                                                                                                          + + + + + + + +
                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Boards + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Displays + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Sourcing Parts + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + ESP32 + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Powering Your Projects + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + Thonny IDE + + + + +
                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                        • + + + + + VS Code IDE + + + + +
                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + MicroPython Libraries + + + + + + + +
                                                                                                                                                          + + + + + + + +
                                                                                                                                                            + +
                                                                                                                                                          • + + + Micropython Libraries + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + MicroPython Builtin Functions + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + MicroPython Specific Libraries + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Adding a module + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Getting MicroPython Libraries from PyPi + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Full List of modules + + + +
                                                                                                                                                          • + +
                                                                                                                                                          + +
                                                                                                                                                          + +
                                                                                                                                                        • + + + + +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                      • + + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + +
                                                                                                                                                      + + + + + + + +
                                                                                                                                                        + +
                                                                                                                                                      • + + + Micropython Libraries + + + +
                                                                                                                                                      • + +
                                                                                                                                                      • + + + MicroPython Builtin Functions + + + +
                                                                                                                                                      • + +
                                                                                                                                                      • + + + MicroPython Specific Libraries + + + +
                                                                                                                                                      • + +
                                                                                                                                                      • + + + Adding a module + + + +
                                                                                                                                                      • + +
                                                                                                                                                      • + + + Getting MicroPython Libraries from PyPi + + + +
                                                                                                                                                      • + +
                                                                                                                                                      • + + + Full List of modules + + + +
                                                                                                                                                      • + +
                                                                                                                                                      + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + +
                                                                                                                                                      +
                                                                                                                                                      + + + + + + + +

                                                                                                                                                      What is MicroPython?

                                                                                                                                                      +

                                                                                                                                                      MicroPython is an implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers. (From micropython.org)

                                                                                                                                                      +

                                                                                                                                                      MicroPython was originally created by the Australian programmer and physicist Damien George. It is written in C.

                                                                                                                                                      +

                                                                                                                                                      MicroPython is now an OpenSource project and the source code is available in GitHub.

                                                                                                                                                      +

                                                                                                                                                      Micropython Libraries

                                                                                                                                                      +

                                                                                                                                                      When you start up your IDE, it may have a list of python modules built in. You can list the current modules you have installed by running the help('modules') command.

                                                                                                                                                      +
                                                                                                                                                      1
                                                                                                                                                      help('modules')
                                                                                                                                                      +
                                                                                                                                                      +

                                                                                                                                                      MicroPython Builtin Functions

                                                                                                                                                      +

                                                                                                                                                      MicroPython is designed to run quickly in a small memory system. So it has trimmed down many of the standard Python libraries to fit the needs of microcontrollers. Most of these libraries start with the letter "u" so that you are aware they are designed to run on microcontrollers.

                                                                                                                                                      +
                                                                                                                                                       1
                                                                                                                                                      + 2
                                                                                                                                                      + 3
                                                                                                                                                      + 4
                                                                                                                                                      + 5
                                                                                                                                                      + 6
                                                                                                                                                      + 7
                                                                                                                                                      + 8
                                                                                                                                                      + 9
                                                                                                                                                      +10
                                                                                                                                                      +11
                                                                                                                                                      +12
                                                                                                                                                      +13
                                                                                                                                                      +14
                                                                                                                                                      +15
                                                                                                                                                      +16
                                                                                                                                                      +17
                                                                                                                                                      +18
                                                                                                                                                      +19
                                                                                                                                                      +20
                                                                                                                                                      +21
                                                                                                                                                      +22
                                                                                                                                                      cmath – mathematical functions for complex numbers
                                                                                                                                                      +gc – control the garbage collector
                                                                                                                                                      +math – mathematical functions
                                                                                                                                                      +uarray – arrays of numeric data
                                                                                                                                                      +uasyncio — asynchronous I/O scheduler
                                                                                                                                                      +ubinascii – binary/ASCII conversions
                                                                                                                                                      +ucollections – collection and container types
                                                                                                                                                      +uerrno – system error codes
                                                                                                                                                      +uhashlib – hashing algorithms
                                                                                                                                                      +uheapq – heap queue algorithm
                                                                                                                                                      +uio – input/output streams
                                                                                                                                                      +ujson – JSON encoding and decoding
                                                                                                                                                      +uos – basic “operating system” services
                                                                                                                                                      +ure – simple regular expressions
                                                                                                                                                      +uselect – wait for events on a set of streams
                                                                                                                                                      +usocket – socket module
                                                                                                                                                      +ussl – SSL/TLS module
                                                                                                                                                      +ustruct – pack and unpack primitive data types
                                                                                                                                                      +usys – system specific functions
                                                                                                                                                      +utime – time related functions
                                                                                                                                                      +uzlib – zlib decompression
                                                                                                                                                      +_thread – multithreading support
                                                                                                                                                      +
                                                                                                                                                      +

                                                                                                                                                      MicroPython Specific Libraries

                                                                                                                                                      +
                                                                                                                                                      1
                                                                                                                                                      +2
                                                                                                                                                      +3
                                                                                                                                                      +4
                                                                                                                                                      +5
                                                                                                                                                      +6
                                                                                                                                                      +7
                                                                                                                                                      +8
                                                                                                                                                      btree – simple BTree database
                                                                                                                                                      +framebuf — frame buffer manipulation
                                                                                                                                                      +machine — functions related to the hardware
                                                                                                                                                      +micropython – access and control MicroPython internals
                                                                                                                                                      +network — network configuration
                                                                                                                                                      +ubluetooth — low-level Bluetooth
                                                                                                                                                      +ucryptolib – cryptographic ciphers
                                                                                                                                                      +uctypes – access binary data in a structured way
                                                                                                                                                      +
                                                                                                                                                      +

                                                                                                                                                      Adding a module

                                                                                                                                                      +

                                                                                                                                                      When you are using python and you attempt to use a module that python can't find you will get an error. You must then use the python pip installer tool to add the new library.

                                                                                                                                                      +

                                                                                                                                                      Getting MicroPython Libraries from PyPi

                                                                                                                                                      +

                                                                                                                                                      Filter Only MicroPython Libraries

                                                                                                                                                      +

                                                                                                                                                      Full List of modules

                                                                                                                                                      +
                                                                                                                                                        1
                                                                                                                                                      +  2
                                                                                                                                                      +  3
                                                                                                                                                      +  4
                                                                                                                                                      +  5
                                                                                                                                                      +  6
                                                                                                                                                      +  7
                                                                                                                                                      +  8
                                                                                                                                                      +  9
                                                                                                                                                      + 10
                                                                                                                                                      + 11
                                                                                                                                                      + 12
                                                                                                                                                      + 13
                                                                                                                                                      + 14
                                                                                                                                                      + 15
                                                                                                                                                      + 16
                                                                                                                                                      + 17
                                                                                                                                                      + 18
                                                                                                                                                      + 19
                                                                                                                                                      + 20
                                                                                                                                                      + 21
                                                                                                                                                      + 22
                                                                                                                                                      + 23
                                                                                                                                                      + 24
                                                                                                                                                      + 25
                                                                                                                                                      + 26
                                                                                                                                                      + 27
                                                                                                                                                      + 28
                                                                                                                                                      + 29
                                                                                                                                                      + 30
                                                                                                                                                      + 31
                                                                                                                                                      + 32
                                                                                                                                                      + 33
                                                                                                                                                      + 34
                                                                                                                                                      + 35
                                                                                                                                                      + 36
                                                                                                                                                      + 37
                                                                                                                                                      + 38
                                                                                                                                                      + 39
                                                                                                                                                      + 40
                                                                                                                                                      + 41
                                                                                                                                                      + 42
                                                                                                                                                      + 43
                                                                                                                                                      + 44
                                                                                                                                                      + 45
                                                                                                                                                      + 46
                                                                                                                                                      + 47
                                                                                                                                                      + 48
                                                                                                                                                      + 49
                                                                                                                                                      + 50
                                                                                                                                                      + 51
                                                                                                                                                      + 52
                                                                                                                                                      + 53
                                                                                                                                                      + 54
                                                                                                                                                      + 55
                                                                                                                                                      + 56
                                                                                                                                                      + 57
                                                                                                                                                      + 58
                                                                                                                                                      + 59
                                                                                                                                                      + 60
                                                                                                                                                      + 61
                                                                                                                                                      + 62
                                                                                                                                                      + 63
                                                                                                                                                      + 64
                                                                                                                                                      + 65
                                                                                                                                                      + 66
                                                                                                                                                      + 67
                                                                                                                                                      + 68
                                                                                                                                                      + 69
                                                                                                                                                      + 70
                                                                                                                                                      + 71
                                                                                                                                                      + 72
                                                                                                                                                      + 73
                                                                                                                                                      + 74
                                                                                                                                                      + 75
                                                                                                                                                      + 76
                                                                                                                                                      + 77
                                                                                                                                                      + 78
                                                                                                                                                      + 79
                                                                                                                                                      + 80
                                                                                                                                                      + 81
                                                                                                                                                      + 82
                                                                                                                                                      + 83
                                                                                                                                                      + 84
                                                                                                                                                      + 85
                                                                                                                                                      + 86
                                                                                                                                                      + 87
                                                                                                                                                      + 88
                                                                                                                                                      + 89
                                                                                                                                                      + 90
                                                                                                                                                      + 91
                                                                                                                                                      + 92
                                                                                                                                                      + 93
                                                                                                                                                      + 94
                                                                                                                                                      + 95
                                                                                                                                                      + 96
                                                                                                                                                      + 97
                                                                                                                                                      + 98
                                                                                                                                                      + 99
                                                                                                                                                      +100
                                                                                                                                                      ESP-test            audioop             filecmp             random
                                                                                                                                                      +__future__          base64              fileinput           re
                                                                                                                                                      +_abc                bcrypt              fnmatch             readline
                                                                                                                                                      +_ast                bdb                 formatter           reedsolo
                                                                                                                                                      +_asyncio            binascii            fractions           reprlib
                                                                                                                                                      +_bisect             binhex              ftplib              resource
                                                                                                                                                      +_blake2             bisect              functools           rlcompleter
                                                                                                                                                      +_bootlocale         bitstring           gc                  runpy
                                                                                                                                                      +_bz2                blink-builtin-led   genericpath         sched
                                                                                                                                                      +_cffi_backend       brain_argparse      getopt              secrets
                                                                                                                                                      +_codecs             brain_attrs         getpass             select
                                                                                                                                                      +_codecs_cn          brain_builtin_inference gettext         selectors
                                                                                                                                                      +_codecs_hk          brain_collections   glob                send2trash
                                                                                                                                                      +_codecs_iso2022     brain_crypt         grp                 serial
                                                                                                                                                      +_codecs_jp          brain_curses        gzip                setuptools
                                                                                                                                                      +_codecs_kr          brain_dataclasses   hashlib             sh1106
                                                                                                                                                      +_codecs_tw          brain_dateutil      heapq               sh1106-test
                                                                                                                                                      +_collections        brain_fstrings      hmac                shelve
                                                                                                                                                      +_collections_abc    brain_functools     html                shlex
                                                                                                                                                      +_compat_pickle      brain_gi            http                shutil
                                                                                                                                                      +_compression        brain_hashlib       i2c-display         signal
                                                                                                                                                      +_contextvars        brain_http          i2c-scanner         site
                                                                                                                                                      +_crypt              brain_io            i2c_lcd             six
                                                                                                                                                      +_csv                brain_mechanize     i2clcd              smtpd
                                                                                                                                                      +_ctypes             brain_multiprocessing imaplib           smtplib
                                                                                                                                                      +_ctypes_test        brain_namedtuple_enum imghdr            sndhdr
                                                                                                                                                      +_curses             brain_nose          imp                 socket
                                                                                                                                                      +_curses_panel       brain_numpy_core_fromnumeric importlib  socketserver
                                                                                                                                                      +_datetime           brain_numpy_core_function_base inspect  spi-debug
                                                                                                                                                      +_dbm                brain_numpy_core_multiarray io          sqlite3
                                                                                                                                                      +_decimal            brain_numpy_core_numeric ipaddress      sre_compile
                                                                                                                                                      +_dummy_thread       brain_numpy_core_numerictypes isort     sre_constants
                                                                                                                                                      +_elementtree        brain_numpy_core_umath itertools        sre_parse
                                                                                                                                                      +_functools          brain_numpy_ndarray jedi                ssl
                                                                                                                                                      +_hashlib            brain_numpy_random_mtrand json          stat
                                                                                                                                                      +_heapq              brain_numpy_utils   keyword             statistics
                                                                                                                                                      +_imp                brain_pkg_resources lazy_object_proxy   string
                                                                                                                                                      +_io                 brain_pytest        led-strip           stringprep
                                                                                                                                                      +_json               brain_qt            lib2to3             struct
                                                                                                                                                      +_locale             brain_random        linecache           subprocess
                                                                                                                                                      +_lsprof             brain_re            list-modules        sunau
                                                                                                                                                      +_lzma               brain_six           locale              symbol
                                                                                                                                                      +_markupbase         brain_ssl           logging             symtable
                                                                                                                                                      +_md5                brain_subprocess    lzma                sys
                                                                                                                                                      +_multibytecodec     brain_threading     macpath             sysconfig
                                                                                                                                                      +_multiprocessing    brain_typing        mailbox             syslog
                                                                                                                                                      +_opcode             brain_uuid          mailcap             tabnanny
                                                                                                                                                      +_operator           builtins            marshal             tarfile
                                                                                                                                                      +_osx_support        bz2                 math                telnetlib
                                                                                                                                                      +_pickle             cProfile            mccabe              tempfile
                                                                                                                                                      +_posixsubprocess    calendar            mimetypes           termios
                                                                                                                                                      +_py_abc             certifi             mmap                test
                                                                                                                                                      +_pydecimal          cffi                modulefinder        textwrap
                                                                                                                                                      +_pyio               cgi                 multiprocessing     this
                                                                                                                                                      +_queue              cgitb               mypy                thonny
                                                                                                                                                      +_random             chunk               mypy_extensions     threading
                                                                                                                                                      +_scproxy            clonevirtualenv     mypyc               time
                                                                                                                                                      +_sha1               cmath               nacl                timeit
                                                                                                                                                      +_sha256             cmd                 netrc               tkinter
                                                                                                                                                      +_sha3               code                nis                 token
                                                                                                                                                      +_sha512             codecs              nntplib             tokenize
                                                                                                                                                      +_signal             codeop              ntpath              toml
                                                                                                                                                      +_sitebuiltins       collections         nturl2path          trace
                                                                                                                                                      +_socket             colorsys            numbers             traceback
                                                                                                                                                      +_sqlite3            compileall          opcode              tracemalloc
                                                                                                                                                      +_sre                concurrent          operator            tty
                                                                                                                                                      +_ssl                configparser        optparse            turtle
                                                                                                                                                      +_stat               contextlib          os                  turtledemo
                                                                                                                                                      +_string             contextvars         paramiko            typed_ast
                                                                                                                                                      +_strptime           copy                parser              types
                                                                                                                                                      +_struct             copyreg             parso               typing
                                                                                                                                                      +_symtable           crypt               pathlib             typing_extensions
                                                                                                                                                      +_sysconfigdata_m_darwin_darwin cryptography        pdb      unicodedata
                                                                                                                                                      +_testbuffer         csv                 pickle              unittest
                                                                                                                                                      +_testcapi           ctypes              pickletools         urllib
                                                                                                                                                      +_testimportmultiple curses              pip                 uu
                                                                                                                                                      +_testmultiphase     dataclasses         pipenv              uuid
                                                                                                                                                      +_thread             datetime            pipes               venv
                                                                                                                                                      +_threading_local    dbm                 pkg_resources       virtualenv
                                                                                                                                                      +_tkinter            decimal             pkgutil             virtualenv_support
                                                                                                                                                      +_tracemalloc        difflib             platform            warnings
                                                                                                                                                      +_uuid               dir-example         plistlib            wave
                                                                                                                                                      +_warnings           dis                 poplib              weakref
                                                                                                                                                      +_weakref            distutils           posix               webbrowser
                                                                                                                                                      +_weakrefset         doctest             posixpath           websockets
                                                                                                                                                      +_xxtestfuzz         docutils            pprint              wheel
                                                                                                                                                      +abc                 dummy_threading     profile             wrapt
                                                                                                                                                      +aifc                easy_install        pstats              wsgiref
                                                                                                                                                      +antigravity         ecdsa               pty                 xdrlib
                                                                                                                                                      +argparse            email               ptyprocess          xml
                                                                                                                                                      +array               encodings           pwd                 xmlrpc
                                                                                                                                                      +array-test          ensurepip           py_compile          xxlimited
                                                                                                                                                      +ast                 enum                pyclbr              xxsubtype
                                                                                                                                                      +astroid             errno               pycparser           zipapp
                                                                                                                                                      +asttokens           espefuse            pydoc               zipfile
                                                                                                                                                      +asynchat            espressif           pydoc_data          zipimport
                                                                                                                                                      +asyncio             espsecure           pyexpat             zlib
                                                                                                                                                      +asyncore            esptool             pylint              
                                                                                                                                                      +at                  faulthandler        queue               
                                                                                                                                                      +atexit              fcntl               quopri              
                                                                                                                                                      +
                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                      +
                                                                                                                                                      + + + +
                                                                                                                                                      + + + +
                                                                                                                                                      + +
                                                                                                                                                      + + + +
                                                                                                                                                      + + + +
                                                                                                                                                      + + +
                                                                                                                                                      +
                                                                                                                                                      + + Previous + +
                                                                                                                                                      + VS Code IDE +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + + +
                                                                                                                                                      + + Next + +
                                                                                                                                                      + Introduction +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                      + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                      + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02-boards/index.html b/getting-started/02-boards/index.html new file mode 100644 index 000000000..e99c40da7 --- /dev/null +++ b/getting-started/02-boards/index.html @@ -0,0 +1,1700 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Boards - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                      +
                                                                                                                                                      + +
                                                                                                                                                      + + + + + + +
                                                                                                                                                      +
                                                                                                                                                      + + + logo + + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                      +
                                                                                                                                                      + + + Boards + + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + + + + + + + +
                                                                                                                                                      + +
                                                                                                                                                      +
                                                                                                                                                      + + +
                                                                                                                                                      + + +
                                                                                                                                                      + +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      +
                                                                                                                                                      + Initializing search +
                                                                                                                                                      +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + +
                                                                                                                                                        + +
                                                                                                                                                        + + +
                                                                                                                                                        +
                                                                                                                                                        + GitHub Repo +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                        + +
                                                                                                                                                        + +
                                                                                                                                                        + + + + + + +
                                                                                                                                                        +
                                                                                                                                                        + + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + + +
                                                                                                                                                        + + +
                                                                                                                                                        + +
                                                                                                                                                        + + +
                                                                                                                                                        +
                                                                                                                                                        + GitHub Repo +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                          + + + + + + + +
                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + +
                                                                                                                                                          + +
                                                                                                                                                            + + + + + + + +
                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + Boards + + + + + + + +
                                                                                                                                                            + + + + + + + +
                                                                                                                                                              + +
                                                                                                                                                            • + + + Raspberry Pi Pico + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + ESP32 + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Cables + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Getting Machine Statistics + + + +
                                                                                                                                                            • + +
                                                                                                                                                            + +
                                                                                                                                                            + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Displays + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Sourcing Parts + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + ESP32 + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Powering Your Projects + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + Thonny IDE + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + VS Code IDE + + + + +
                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                          • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                          • + + + + +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                        • + + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + +
                                                                                                                                                        + + + + + + + +
                                                                                                                                                          + +
                                                                                                                                                        • + + + Raspberry Pi Pico + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + ESP32 + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + Cables + + + +
                                                                                                                                                        • + +
                                                                                                                                                        • + + + Getting Machine Statistics + + + +
                                                                                                                                                        • + +
                                                                                                                                                        + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + +
                                                                                                                                                        +
                                                                                                                                                        + + + + + + + +

                                                                                                                                                        Micropython Boards

                                                                                                                                                        +

                                                                                                                                                        Technically, any computer that has at least 16K of RAM can run MicroPython as long as someone has ported the MicroPython runtime to use that instruction set.

                                                                                                                                                        +

                                                                                                                                                        Raspberry Pi Pico

                                                                                                                                                        +

                                                                                                                                                        Most of these lessons use a low-cost ($4 retail list price) Raspberry Pi Pico(../glossary.md#pico). The microcontroller was designed by the Raspberry Pi Foundation specifically to provide a low-cost way for student to learn how to program MicroPython. The Raspberry Pi Foundation has also worked with the Thonny developers to create a simple clean kid-friendly interface that is ideal for beginning students.

                                                                                                                                                        +

                                                                                                                                                        ESP32

                                                                                                                                                        +

                                                                                                                                                        The ESP32 is similar to the Raspberry Pi Pico but ESP32 also has both WiFi and bluetooth.

                                                                                                                                                        +

                                                                                                                                                        Cables

                                                                                                                                                        +

                                                                                                                                                        You will need a USB cable to program your microcontroller. These cables are frequently sold at high margin rates at retail stores. If you plan ahead, you can usually find these cables on eBay for about 50% less. Classroom purchases make this a good option.

                                                                                                                                                        +

                                                                                                                                                        Getting Machine Statistics

                                                                                                                                                        +
                                                                                                                                                        1
                                                                                                                                                        +2
                                                                                                                                                        import machine
                                                                                                                                                        +help(machine)
                                                                                                                                                        +
                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                        +
                                                                                                                                                        + + + +
                                                                                                                                                        + + + +
                                                                                                                                                        + +
                                                                                                                                                        + + + +
                                                                                                                                                        + + + +
                                                                                                                                                        + + +
                                                                                                                                                        +
                                                                                                                                                        + + Previous + +
                                                                                                                                                        + Solderless Breadboards +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + + +
                                                                                                                                                        + + Next + +
                                                                                                                                                        + Displays +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                        + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                        + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02-breadboards/index.html b/getting-started/02-breadboards/index.html new file mode 100644 index 000000000..74f68b50d --- /dev/null +++ b/getting-started/02-breadboards/index.html @@ -0,0 +1,1711 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Solderless Breadboards - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                        +
                                                                                                                                                        + +
                                                                                                                                                        + + + + + + +
                                                                                                                                                        +
                                                                                                                                                        + + + logo + + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                        +
                                                                                                                                                        + + + Solderless Breadboards + + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + + + + + + + +
                                                                                                                                                        + +
                                                                                                                                                        +
                                                                                                                                                        + + +
                                                                                                                                                        + + +
                                                                                                                                                        + +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        +
                                                                                                                                                        + Initializing search +
                                                                                                                                                        +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + +
                                                                                                                                                          + +
                                                                                                                                                          + + +
                                                                                                                                                          +
                                                                                                                                                          + GitHub Repo +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                          + +
                                                                                                                                                          + +
                                                                                                                                                          + + + + + + +
                                                                                                                                                          +
                                                                                                                                                          + + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + + +
                                                                                                                                                          + + +
                                                                                                                                                          + +
                                                                                                                                                          + + +
                                                                                                                                                          +
                                                                                                                                                          + GitHub Repo +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                            + + + + + + + +
                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                            + +
                                                                                                                                                              + + + + + + + +
                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + Solderless Breadboards + + + + + + + +
                                                                                                                                                              + + + + + + + +
                                                                                                                                                                + +
                                                                                                                                                              • + + + Breadboard Regions and Connections + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Pico Placement on Breadboard + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Pico Placement Annotations + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Breadboard Connections + + + +
                                                                                                                                                              • + +
                                                                                                                                                              + +
                                                                                                                                                              + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Boards + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Displays + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Sourcing Parts + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + ESP32 + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Powering Your Projects + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + Thonny IDE + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + VS Code IDE + + + + +
                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                            • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                            • + + + + +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                          • + + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + +
                                                                                                                                                          + + + + + + + +
                                                                                                                                                            + +
                                                                                                                                                          • + + + Breadboard Regions and Connections + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Pico Placement on Breadboard + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Pico Placement Annotations + + + +
                                                                                                                                                          • + +
                                                                                                                                                          • + + + Breadboard Connections + + + +
                                                                                                                                                          • + +
                                                                                                                                                          + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + +
                                                                                                                                                          +
                                                                                                                                                          + + + + + + + +

                                                                                                                                                          Breadboards

                                                                                                                                                          +

                                                                                                                                                          Solderless Mini Breadboard

                                                                                                                                                          +

                                                                                                                                                          We use standard solderless mini breadboards in our labs. The breadboards have holes that are spaced 1/10th of an inch apart which is a standard for most electronics in the US.

                                                                                                                                                          +

                                                                                                                                                          Our breadboards are usually 1/2 size with 400-ties. They have a central trough and power rails on the left and right edges.

                                                                                                                                                          +

                                                                                                                                                          Breadboard Regions and Connections

                                                                                                                                                          +

                                                                                                                                                          Breadboard Regions and Connections +Learning how a breadboard works is critical for building your projects. In the figure above you will see that there are two types of regions of the breadboard

                                                                                                                                                          +
                                                                                                                                                            +
                                                                                                                                                          1. The side regions are called the power distribution rails. They are similar to power lines that reach across our projects.
                                                                                                                                                          2. +
                                                                                                                                                          3. The central region is call the row connector region. In this area the horizontal rows are all connected inside the breadboard. Within any row, columns a, b, c, d and e are all electrically connected. Within any row, columns f, h, i, j, and k are also electrically connected. However, there is a gap between columns e and f called the center gap or component slot that parts are usually placed over. Components like buttons and chips usually have their pins straddle the component slot.
                                                                                                                                                          4. +
                                                                                                                                                          +

                                                                                                                                                          Pico Placement on Breadboard

                                                                                                                                                          +

                                                                                                                                                          For most of our labs we place the Pico so that pin 1 of the Pico is in row 1 of the breadboard as in the image below.

                                                                                                                                                          +

                                                                                                                                                          Pico on Breadboard

                                                                                                                                                          +

                                                                                                                                                          This means that the GND connections to the Pico are always in rows 3, 8, 13 and 18 on both sides of the breadboard. One of the ground pins is usually hooked up to the vertical blue power rails on the sides of the breadboard.

                                                                                                                                                          +

                                                                                                                                                          Pico Placement Annotations

                                                                                                                                                          +

                                                                                                                                                          Pico on Breadboard

                                                                                                                                                          +
                                                                                                                                                            +
                                                                                                                                                          1. GND are the ground connections. There are
                                                                                                                                                          2. +
                                                                                                                                                          3. VBUS is the 5V power from the USB and is high only when the USB is connected. This is nominally 5V (or 0V if the USB is not connected or not powered).
                                                                                                                                                          4. +
                                                                                                                                                          5. VSYS (also know and Voltage System Input) is the main system input voltage. When the Pico is disconnected from the USB you apply power to the Voltage System Input. The input can vary in the allowed range 1.8V to 5.5V, and is used by the on-board SMPS to generate the 3.3V for the RP2040 and its GPIO connections. When the input voltage is less than 3.3 volts the Pico uses an internal DC voltage Boost converter to get the correct voltage to the processor.
                                                                                                                                                          6. +
                                                                                                                                                          +

                                                                                                                                                          3V3_EN connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. To disable the 3.3V (which also de-powers the RP2040), short this pin low. In effect by making the 3V3_EN LOW you are turning off the Pico.

                                                                                                                                                          +

                                                                                                                                                          Breadboard Connections

                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                          +
                                                                                                                                                          + + + +
                                                                                                                                                          + + + +
                                                                                                                                                          + +
                                                                                                                                                          + + + +
                                                                                                                                                          + + + +
                                                                                                                                                          + + +
                                                                                                                                                          +
                                                                                                                                                          + + Previous + +
                                                                                                                                                          + Introduction +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + + +
                                                                                                                                                          + + Next + +
                                                                                                                                                          + Boards +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                          + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                          + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02-esp32/index.html b/getting-started/02-esp32/index.html new file mode 100644 index 000000000..e92022bc4 --- /dev/null +++ b/getting-started/02-esp32/index.html @@ -0,0 +1,1949 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + ESP32 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                          +
                                                                                                                                                          + +
                                                                                                                                                          + + + + + + +
                                                                                                                                                          +
                                                                                                                                                          + + + logo + + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                          +
                                                                                                                                                          + + + ESP32 + + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + + + + + + + +
                                                                                                                                                          + +
                                                                                                                                                          +
                                                                                                                                                          + + +
                                                                                                                                                          + + +
                                                                                                                                                          + +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          +
                                                                                                                                                          + Initializing search +
                                                                                                                                                          +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + +
                                                                                                                                                            + +
                                                                                                                                                            + + +
                                                                                                                                                            +
                                                                                                                                                            + GitHub Repo +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                            + +
                                                                                                                                                            + +
                                                                                                                                                            + + + + + + +
                                                                                                                                                            +
                                                                                                                                                            + + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + + +
                                                                                                                                                            + + +
                                                                                                                                                            + +
                                                                                                                                                            + + +
                                                                                                                                                            +
                                                                                                                                                            + GitHub Repo +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                              + + + + + + + +
                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + +
                                                                                                                                                              + +
                                                                                                                                                                + + + + + + + +
                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Boards + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Displays + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Sourcing Parts + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + ESP32 + + + + + + + +
                                                                                                                                                                + + + + + + + +
                                                                                                                                                                  + +
                                                                                                                                                                • + + + Step 1: Install the USB to UART Bridge VCP Drivers + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Step 2: Create a Python Conda Environment for ESP32 + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Step #3: Install the esptool + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Step 4: Erase the Old Firmware + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Step 5: Download the New Firmware + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Step 6: Reflash the new ESP32 Firmware + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Configure Thonny + + + +
                                                                                                                                                                  +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + Set the Serial Port + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Set the Interpreter + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Run a test + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                • + +
                                                                                                                                                                + +
                                                                                                                                                                + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Powering Your Projects + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + Thonny IDE + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + VS Code IDE + + + + +
                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                              • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                              • + + + + +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                            • + + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + +
                                                                                                                                                            + + + + + + + +
                                                                                                                                                              + +
                                                                                                                                                            • + + + Step 1: Install the USB to UART Bridge VCP Drivers + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Step 2: Create a Python Conda Environment for ESP32 + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Step #3: Install the esptool + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Step 4: Erase the Old Firmware + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Step 5: Download the New Firmware + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Step 6: Reflash the new ESP32 Firmware + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Configure Thonny + + + +
                                                                                                                                                              +
                                                                                                                                                                + +
                                                                                                                                                              • + + + Set the Serial Port + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Set the Interpreter + + + +
                                                                                                                                                              • + +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + Run a test + + + +
                                                                                                                                                            • + +
                                                                                                                                                            • + + + References + + + +
                                                                                                                                                            • + +
                                                                                                                                                            + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + +
                                                                                                                                                            +
                                                                                                                                                            + + + + + + + +

                                                                                                                                                            ESP32 TTGO

                                                                                                                                                            +

                                                                                                                                                            The ESP32 is a low-cost (under $10) microcontroller with both built-in WiFi and Bluetooth. This lab demonstrates using a version of the ESP32 that includes an integrated display.

                                                                                                                                                            +

                                                                                                                                                            Step 1: Install the USB to UART Bridge VCP Drivers

                                                                                                                                                            +

                                                                                                                                                            Follow the directions here:

                                                                                                                                                            +

                                                                                                                                                            https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

                                                                                                                                                            +

                                                                                                                                                            Test this by running the ``ls -l /dev/cu*``` and verify you see:

                                                                                                                                                            +

                                                                                                                                                            /dev/cu.SLAB_USBtoUART

                                                                                                                                                            +

                                                                                                                                                            If you don't see this try to reboot.

                                                                                                                                                            +

                                                                                                                                                            Mac: +https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/establish-serial-connection.html +https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/raw/master/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip

                                                                                                                                                            +

                                                                                                                                                            Step 2: Create a Python Conda Environment for ESP32

                                                                                                                                                            +

                                                                                                                                                            This is so we don't mess up other Python projects on your system.

                                                                                                                                                            +
                                                                                                                                                            1
                                                                                                                                                            +2
                                                                                                                                                            conda create -n esp32 python=3
                                                                                                                                                            +conda activate esp32
                                                                                                                                                            +
                                                                                                                                                            +

                                                                                                                                                            Step #3: Install the esptool

                                                                                                                                                            +
                                                                                                                                                            1
                                                                                                                                                            +2
                                                                                                                                                            +3
                                                                                                                                                            +4
                                                                                                                                                            +5
                                                                                                                                                            +6
                                                                                                                                                            +7
                                                                                                                                                            $ pip3 install esptool
                                                                                                                                                            +Collecting esptool
                                                                                                                                                            +  Downloading esptool-3.0.tar.gz (149 kB)
                                                                                                                                                            +     |████████████████████████████████| 149 kB 2.9 MB/s 
                                                                                                                                                            +     ...
                                                                                                                                                            +Installing collected packages: pycparser, six, cffi, reedsolo, pyserial, ecdsa, cryptography, bitstring, esptool
                                                                                                                                                            +Successfully installed bitstring-3.1.7 cffi-1.14.5 cryptography-3.4.6 ecdsa-0.16.1 esptool-3.0 pycparser-2.20 pyserial-3.5 reedsolo-1.5.4 six-1.15.0
                                                                                                                                                            +
                                                                                                                                                            +

                                                                                                                                                            Step 4: Erase the Old Firmware

                                                                                                                                                            +
                                                                                                                                                            1
                                                                                                                                                            esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash
                                                                                                                                                            +
                                                                                                                                                            +

                                                                                                                                                            Step 5: Download the New Firmware

                                                                                                                                                            +

                                                                                                                                                            Get the ESP32_All prebuilt binary:

                                                                                                                                                            +

                                                                                                                                                            https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/firmwares +

                                                                                                                                                            +

                                                                                                                                                            Step 6: Reflash the new ESP32 Firmware

                                                                                                                                                            +
                                                                                                                                                            1
                                                                                                                                                            +2
                                                                                                                                                            cd esp32_all/
                                                                                                                                                            +../flash.sh -p /dev/cu.SLAB_USBtoUART
                                                                                                                                                            +
                                                                                                                                                            +

                                                                                                                                                            this will run... +

                                                                                                                                                             1
                                                                                                                                                            + 2
                                                                                                                                                            + 3
                                                                                                                                                            + 4
                                                                                                                                                            + 5
                                                                                                                                                            + 6
                                                                                                                                                            + 7
                                                                                                                                                            + 8
                                                                                                                                                            + 9
                                                                                                                                                            +10
                                                                                                                                                            +11
                                                                                                                                                            +12
                                                                                                                                                            +13
                                                                                                                                                            +14
                                                                                                                                                            +15
                                                                                                                                                            $ esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash
                                                                                                                                                            +esptool.py v3.0
                                                                                                                                                            +Serial port /dev/cu.SLAB_USBtoUART
                                                                                                                                                            +Connecting........_
                                                                                                                                                            +Detecting chip type... ESP32
                                                                                                                                                            +Chip is ESP32-D0WDQ6 (revision 1)
                                                                                                                                                            +Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
                                                                                                                                                            +Crystal is 40MHz
                                                                                                                                                            +MAC: 24:62:ab:ca:62:84
                                                                                                                                                            +Uploading stub...
                                                                                                                                                            +Running stub...
                                                                                                                                                            +Stub running...
                                                                                                                                                            +Erasing flash (this may take a while)...
                                                                                                                                                            +Chip erase completed successfully in 2.5s
                                                                                                                                                            +Hard resetting via RTS pin...
                                                                                                                                                            +

                                                                                                                                                            +

                                                                                                                                                            Configure Thonny

                                                                                                                                                            +

                                                                                                                                                            You must configure Thonny to use the ESP32.

                                                                                                                                                            +

                                                                                                                                                            Set the Serial Port

                                                                                                                                                            +

                                                                                                                                                            First, you must tell Thonny how to find the right port.

                                                                                                                                                            +

                                                                                                                                                            +

                                                                                                                                                            Set the Interpreter

                                                                                                                                                            +

                                                                                                                                                            Next, yo must tell Thonny to use the ESP32 interpreter.

                                                                                                                                                            +

                                                                                                                                                            +

                                                                                                                                                            Run a test

                                                                                                                                                            +
                                                                                                                                                             1
                                                                                                                                                            + 2
                                                                                                                                                            + 3
                                                                                                                                                            + 4
                                                                                                                                                            + 5
                                                                                                                                                            + 6
                                                                                                                                                            + 7
                                                                                                                                                            + 8
                                                                                                                                                            + 9
                                                                                                                                                            +10
                                                                                                                                                            +11
                                                                                                                                                            +12
                                                                                                                                                            +13
                                                                                                                                                            +14
                                                                                                                                                            +15
                                                                                                                                                            +16
                                                                                                                                                            +17
                                                                                                                                                            +18
                                                                                                                                                            import machine, display, time, math, network, utime
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +tft = display.TFT()
                                                                                                                                                            +tft.init(tft.ST7789,bgr=False,rot=tft.LANDSCAPE, miso=17,backl_pin=4,backl_on=1, mosi=19, clk=18, cs=5, dc=16)
                                                                                                                                                            +
                                                                                                                                                            +tft.setwin(40,52,320,240)
                                                                                                                                                            +
                                                                                                                                                            +for i in range(0,241):
                                                                                                                                                            +    color=0xFFFFFF-tft.hsb2rgb(i/241*360, 1, 1)
                                                                                                                                                            +    tft.line(i,0,i,135,color) 
                                                                                                                                                            +
                                                                                                                                                            +tft.set_fg(0x000000) 
                                                                                                                                                            +tft.ellipse(120,67,120,67) 
                                                                                                                                                            +tft.line(0,0,240,135) 
                                                                                                                                                            +
                                                                                                                                                            +text="CoderDojo Rocks!" 
                                                                                                                                                            +tft.text(120-int(tft.textWidth(text)/2),67-int(tft.fontSize()[1]/2),text,0xFFFFFF)
                                                                                                                                                            +
                                                                                                                                                            +

                                                                                                                                                            You should see the following on the ESP32 display: +

                                                                                                                                                            +

                                                                                                                                                            References

                                                                                                                                                            +

                                                                                                                                                            https://www.instructables.com/TTGO-color-Display-With-Micropython-TTGO-T-display/

                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                            +
                                                                                                                                                            + + + +
                                                                                                                                                            + + + +
                                                                                                                                                            + +
                                                                                                                                                            + + + +
                                                                                                                                                            + + + +
                                                                                                                                                            + + +
                                                                                                                                                            +
                                                                                                                                                            + + Previous + +
                                                                                                                                                            + Raspberry Pi Pico +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + + +
                                                                                                                                                            + + Next + +
                                                                                                                                                            + Powering Your Projects +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                            + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                            + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02-pi-pico/index.html b/getting-started/02-pi-pico/index.html new file mode 100644 index 000000000..7e1088a5f --- /dev/null +++ b/getting-started/02-pi-pico/index.html @@ -0,0 +1,2045 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Raspberry Pi Pico - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                            +
                                                                                                                                                            + +
                                                                                                                                                            + + + + + + +
                                                                                                                                                            +
                                                                                                                                                            + + + logo + + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                            +
                                                                                                                                                            + + + Raspberry Pi Pico + + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + + + + + + + +
                                                                                                                                                            + +
                                                                                                                                                            +
                                                                                                                                                            + + +
                                                                                                                                                            + + +
                                                                                                                                                            + +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            +
                                                                                                                                                            + Initializing search +
                                                                                                                                                            +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + +
                                                                                                                                                              + +
                                                                                                                                                              + + +
                                                                                                                                                              +
                                                                                                                                                              + GitHub Repo +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                              + +
                                                                                                                                                              + +
                                                                                                                                                              + + + + + + +
                                                                                                                                                              +
                                                                                                                                                              + + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + + +
                                                                                                                                                              + + +
                                                                                                                                                              + +
                                                                                                                                                              + + +
                                                                                                                                                              +
                                                                                                                                                              + GitHub Repo +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                                + + + + + + + +
                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                + +
                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Boards + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Displays + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Sourcing Parts + + + + +
                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + Raspberry Pi Pico + + + + + + + +
                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + Specs + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Runtimes + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + USB Cable + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Pico Pinout + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Steps To Get Micropython Running on the Mac + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Using Thonny + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Getting The Bootloader Running from the Thonny Python Shell + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Using the Onboard LED + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Adding GND Markers + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                    +
                                                                                                                                                                      + +
                                                                                                                                                                    • + + + Getting Started Guide + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + MicroPython RP2040 Reference + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Book PDF + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                  • + +
                                                                                                                                                                  + +
                                                                                                                                                                  + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + ESP32 + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Powering Your Projects + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + Thonny IDE + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + VS Code IDE + + + + +
                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                • + + + + +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                              • + + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + +
                                                                                                                                                              + + + + + + + +
                                                                                                                                                                + +
                                                                                                                                                              • + + + Specs + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Runtimes + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + USB Cable + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Pico Pinout + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Steps To Get Micropython Running on the Mac + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Using Thonny + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Getting The Bootloader Running from the Thonny Python Shell + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Using the Onboard LED + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + Adding GND Markers + + + +
                                                                                                                                                              • + +
                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                +
                                                                                                                                                                  + +
                                                                                                                                                                • + + + Getting Started Guide + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + MicroPython RP2040 Reference + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Book PDF + + + +
                                                                                                                                                                • + +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                              • + +
                                                                                                                                                              + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + +
                                                                                                                                                              +
                                                                                                                                                              + + + + + + + +

                                                                                                                                                              Getting Started with the Raspberry Pi RP2040 Microcontroller

                                                                                                                                                              +

                                                                                                                                                              Raspberry Pi Pico

                                                                                                                                                              +

                                                                                                                                                              The Raspberry Pi RP2040 is a custom silicon microcontroller built by the Raspberry Pi Foundation. The RP2040 is used in the Raspberry Pi Pico with a retail list prices of $4. With 264K SRAM, it has around 100 times the RAM of an Arduino Uno (2K). It is ideal for projects that need more RAM such as projects that require drawing to an OLED display.

                                                                                                                                                              +

                                                                                                                                                              +"H" is with headers.

                                                                                                                                                              +

                                                                                                                                                              Specs

                                                                                                                                                              +
                                                                                                                                                                +
                                                                                                                                                              • RP2040 microcontroller chip designed by Raspberry Pi Foundation
                                                                                                                                                              • +
                                                                                                                                                              • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz
                                                                                                                                                              • +
                                                                                                                                                              • 264KB of SRAM, and 2MB of on-board Flash memory
                                                                                                                                                              • +
                                                                                                                                                              • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
                                                                                                                                                              • +
                                                                                                                                                              • DMA controller
                                                                                                                                                              • +
                                                                                                                                                              • Interpolator and integer divider peripherals
                                                                                                                                                              • +
                                                                                                                                                              • Castellated module allows soldering direct to carrier boards
                                                                                                                                                              • +
                                                                                                                                                              • USB 1.1 and PHY with device and host support
                                                                                                                                                              • +
                                                                                                                                                              • Low-power sleep and dormant modes
                                                                                                                                                              • +
                                                                                                                                                              • Drag-and-drop programming using mass storage over USB
                                                                                                                                                              • +
                                                                                                                                                              • 26 × multi-function GPIO pins
                                                                                                                                                              • +
                                                                                                                                                              • 3 12 bit analogue inputs
                                                                                                                                                              • +
                                                                                                                                                              • 16 controllable PWM channels
                                                                                                                                                              • +
                                                                                                                                                              • 2 SPI, 2 I2C, and 2 UART channels
                                                                                                                                                              • +
                                                                                                                                                              • Accurate clock and timer on-chip
                                                                                                                                                              • +
                                                                                                                                                              • 8 Raspberry Pi Programmable I/O (PIO) state machines
                                                                                                                                                              • +
                                                                                                                                                              • Temperature sensor
                                                                                                                                                              • +
                                                                                                                                                              • Accelerated floating-point libraries on-chip
                                                                                                                                                              • +
                                                                                                                                                              • 8 × Programmable I/O (PIO) state machines for custom peripheral support
                                                                                                                                                              • +
                                                                                                                                                              • Created using the TSMC 40LP (40 nano meter low power) manufacturing process
                                                                                                                                                              • +
                                                                                                                                                              • USB mass-storage boot mode with UF2 support, for drag-and-drop programming
                                                                                                                                                              • +
                                                                                                                                                              +

                                                                                                                                                              Runtimes

                                                                                                                                                              +

                                                                                                                                                              Micropython.org RP2 Runtime Page

                                                                                                                                                              +

                                                                                                                                                              USB Cable

                                                                                                                                                              +

                                                                                                                                                              The Raspberry Pi Pico uses a USB-micro connector. You can purchase USB Micro-B to USB-A or USB-C (Mac) cables on e-bay for under $2 or for $5 at Microcenter. +usb-micro-to-c - image from ebay

                                                                                                                                                              +

                                                                                                                                                              Pico Pinout

                                                                                                                                                              +

                                                                                                                                                              The pinout diagram for the Raspberry Pi Pico is shown below.

                                                                                                                                                              +

                                                                                                                                                              Raspberry Pi Pico Pins

                                                                                                                                                              +

                                                                                                                                                              It features: +* 26 × multi-function GPIO pins +* 2 × SPI, 2 × I2C, 2 × UART, 3 × 12-bit ADC, 16 × controllable PWM

                                                                                                                                                              + + +

                                                                                                                                                              Raspberry Pi Pico’s 40 pins with pin 1 in the upper right corner with the USB connector at the top. The pin numbers are incremented as you go counterclockwise around the board. You go down the left side and then continue up on the right side until you get to pin 40 in the upper right corner.

                                                                                                                                                              +

                                                                                                                                                              When you program the Pico, you use the machine.Pin() but you always use the GP* number, never the pin number on the board pin numbers.

                                                                                                                                                              +

                                                                                                                                                              The diagram above shows the top view where pins 1, 2 and 40 are printed next to the pins.

                                                                                                                                                              +
                                                                                                                                                                +
                                                                                                                                                              • Pico Pinout Datasheet PDF
                                                                                                                                                              • +
                                                                                                                                                              +

                                                                                                                                                              Next to each pin is the primary label of what the pin does. Pins 3, 8, 13, 18, 23, 28, 33 and 38 with the black background are all GND pins.

                                                                                                                                                              +

                                                                                                                                                              Pins are numbered 0-29, and 26-29 have ADC capabilities +Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT +Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN

                                                                                                                                                              + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              LabelNameDescription
                                                                                                                                                              V33.3 volts powerA source of 3.3 V power, the same voltage your Pico runs at internally, generated from the VSYS input. This power supply can be switched on and off using the 3V3_EN pin above it, which also switches your Pico off.
                                                                                                                                                              VSYS~2-5 volts powerA pin directly connected to your Pico’s internal power supply, which cannot be switched off without also switching Pico off.
                                                                                                                                                              VBUS5 volts powerA source of 5 V power taken from your Pico’s micro USB port, and used to power hardware which needs more than 3.3 V.
                                                                                                                                                              GND0 volts groundA ground connection, used to complete a circuit connected to a power source. Several of these pins are dotted around your Pico to make wiring easier.
                                                                                                                                                              GPxxGeneral-purpose input/output pin number ‘xxThe GPIO pins available for your program, labelled ‘GP0’ through to ‘GP28’.
                                                                                                                                                              GPxx_ADCxGeneral-purpose input/output pin number ‘xx’, with analogue input number ‘x’A GPIO pin which ends in ‘ADC’ and a number can be used as an analogue input as well as a digital input or output – but not both at the same time.
                                                                                                                                                              ADC_VREFAnalogue-to-digital converter (ADC) voltage referenceA special input pin which sets a reference voltage for any analogue inputs.
                                                                                                                                                              AGNDAnalogue-to-digital converter (ADC) 0 volts groundA special ground connection for use with the ADC_VREF pin.
                                                                                                                                                              RUNEnables or disables your PicoThe RUN header is used to start and stop your Pico from another microcontroller.
                                                                                                                                                              +

                                                                                                                                                              Steps To Get Micropython Running on the Mac

                                                                                                                                                              +
                                                                                                                                                                +
                                                                                                                                                              1. Download the MicroPython UF2 file.
                                                                                                                                                              2. +
                                                                                                                                                              3. Push and hold the BOOTSEL button and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected. +It will mount as a Mass Storage Device called RPI-RP2.
                                                                                                                                                              4. +
                                                                                                                                                              5. Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython.
                                                                                                                                                              6. +
                                                                                                                                                              +

                                                                                                                                                              Using Thonny

                                                                                                                                                              +

                                                                                                                                                              Thonny is a free lightweight Python development tool.

                                                                                                                                                              +
                                                                                                                                                                +
                                                                                                                                                              1. Download the Thonny Application
                                                                                                                                                              2. +
                                                                                                                                                              3. Download the Thonny Pico driver
                                                                                                                                                              4. +
                                                                                                                                                              5. Configure Thonny to use the Pico interpreter
                                                                                                                                                              6. +
                                                                                                                                                              7. Test using the help() function
                                                                                                                                                              8. +
                                                                                                                                                              9. Test by running a blink application
                                                                                                                                                              10. +
                                                                                                                                                              +

                                                                                                                                                              Thonny Micropython Firmware Update

                                                                                                                                                              +
                                                                                                                                                              1
                                                                                                                                                              +2
                                                                                                                                                              +3
                                                                                                                                                              +4
                                                                                                                                                              +5
                                                                                                                                                              +6
                                                                                                                                                              +7
                                                                                                                                                              Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2
                                                                                                                                                              +Writing to /Volumes/RPI-RP2/firmware
                                                                                                                                                              +100%
                                                                                                                                                              +Waiting for the port...
                                                                                                                                                              +Found 2e8a:0005 at /dev/cu.usbmodem0000000000001
                                                                                                                                                              +
                                                                                                                                                              +Done!
                                                                                                                                                              +
                                                                                                                                                              +

                                                                                                                                                              Getting The Bootloader Running from the Thonny Python Shell

                                                                                                                                                              +

                                                                                                                                                              Although you can hold down the BOOTSEL button as you are plugging in the Pico, there is a much easier way. Just type the following into the Thonny shell:

                                                                                                                                                              +
                                                                                                                                                              1
                                                                                                                                                              machine.bootloader()
                                                                                                                                                              +
                                                                                                                                                              +

                                                                                                                                                              This will make the Pico go into the Bootloader Mode and mount the file system. You can then copy the bootloader file using the drag-and-drop from your file system or use a UNIX copy command. Once the copy is finished the Pico will automaticaly restart using the new uf2 file.

                                                                                                                                                              +

                                                                                                                                                              Using the Onboard LED

                                                                                                                                                              +
                                                                                                                                                              1
                                                                                                                                                              +2
                                                                                                                                                              +3
                                                                                                                                                              +4
                                                                                                                                                              from machine import Pin
                                                                                                                                                              +import utime
                                                                                                                                                              +led_onboard = machine.Pin(25, machine.Pin.OUT)
                                                                                                                                                              +led_onboard.value(1)
                                                                                                                                                              +
                                                                                                                                                              +

                                                                                                                                                              1
                                                                                                                                                              +2
                                                                                                                                                              +3
                                                                                                                                                              +4
                                                                                                                                                              +5
                                                                                                                                                              +6
                                                                                                                                                              +7
                                                                                                                                                              +8
                                                                                                                                                              +9
                                                                                                                                                              from machine import Pin
                                                                                                                                                              +import utime
                                                                                                                                                              +
                                                                                                                                                              +# right uppermost pin with USB on the left
                                                                                                                                                              +led = Pin(16, Pin.OUT)
                                                                                                                                                              +led.low()
                                                                                                                                                              +while True:
                                                                                                                                                              +   led.toggle()
                                                                                                                                                              +   utime.sleep(1)
                                                                                                                                                              +
                                                                                                                                                              +Press the Play Button

                                                                                                                                                              +

                                                                                                                                                              Adding GND Markers

                                                                                                                                                              +

                                                                                                                                                              One of the key disadvantages

                                                                                                                                                              +

                                                                                                                                                              +

                                                                                                                                                              References

                                                                                                                                                              +

                                                                                                                                                              Getting Started Guide

                                                                                                                                                              +

                                                                                                                                                              Raspberry Pi Getting Started

                                                                                                                                                              +

                                                                                                                                                              MicroPython RP2040 Reference

                                                                                                                                                              +

                                                                                                                                                              MicroPython RP2040 Quick Reference - this web page has details on how MicroPython was ported to the RP2040 Microcontroller.

                                                                                                                                                              +

                                                                                                                                                              Book PDF

                                                                                                                                                              +

                                                                                                                                                              Raspberry Pi Book PDF Download from HackSpace +Commons Attribution-NonCommercial-ShareAlike 3.0 Unported +(CC BY-NC-SA 3.0)

                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                              +
                                                                                                                                                              + + + +
                                                                                                                                                              + + + +
                                                                                                                                                              + +
                                                                                                                                                              + + + +
                                                                                                                                                              + + + +
                                                                                                                                                              + + +
                                                                                                                                                              +
                                                                                                                                                              + + Previous + +
                                                                                                                                                              + Sourcing Parts +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + + +
                                                                                                                                                              + + Next + +
                                                                                                                                                              + ESP32 +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                              + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                              + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02c-thonny/index.html b/getting-started/02c-thonny/index.html new file mode 100644 index 000000000..69d0789a0 --- /dev/null +++ b/getting-started/02c-thonny/index.html @@ -0,0 +1,1905 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Thonny IDE - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                              +
                                                                                                                                                              + +
                                                                                                                                                              + + + + + + +
                                                                                                                                                              +
                                                                                                                                                              + + + logo + + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                              +
                                                                                                                                                              + + + Thonny IDE + + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + + + + + + + +
                                                                                                                                                              + +
                                                                                                                                                              +
                                                                                                                                                              + + +
                                                                                                                                                              + + +
                                                                                                                                                              + +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              +
                                                                                                                                                              + Initializing search +
                                                                                                                                                              +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + +
                                                                                                                                                                + +
                                                                                                                                                                + + +
                                                                                                                                                                +
                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                                + +
                                                                                                                                                                + +
                                                                                                                                                                + + + + + + +
                                                                                                                                                                +
                                                                                                                                                                + + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + + +
                                                                                                                                                                + + +
                                                                                                                                                                + +
                                                                                                                                                                + + +
                                                                                                                                                                +
                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                  + +
                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Boards + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Displays + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Sourcing Parts + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + ESP32 + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + Powering Your Projects + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + Thonny IDE + + + + + + + +
                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                      + +
                                                                                                                                                                    • + + + Installing Thonny + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Upgrading Thonny + + + +
                                                                                                                                                                      +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + Running help() + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Save Options + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Downloading the Firmware + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Version + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Plotting Values on Thonny + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Background on Thonny + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    + +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + VS Code IDE + + + + +
                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                  • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                  • + + + + +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                • + + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + +
                                                                                                                                                                + + + + + + + +
                                                                                                                                                                  + +
                                                                                                                                                                • + + + Installing Thonny + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Upgrading Thonny + + + +
                                                                                                                                                                  +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + Running help() + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Save Options + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Downloading the Firmware + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Version + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Plotting Values on Thonny + + + +
                                                                                                                                                                • + +
                                                                                                                                                                • + + + Background on Thonny + + + +
                                                                                                                                                                • + +
                                                                                                                                                                + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + +
                                                                                                                                                                +
                                                                                                                                                                + + + + + + + +

                                                                                                                                                                Thonny Python IDE

                                                                                                                                                                +

                                                                                                                                                                A lightweight Python integrated development environment (IDE) that is ideal for beginners writing simple Python programs for first-time users. It has been modified to work well with the Raspberry Pi Pico. It supports different ways of stepping through the code, step-by-step expression evaluation, detailed visualization of the call stack and a mode for explaining the concepts of references and heap.

                                                                                                                                                                +

                                                                                                                                                                We strongly suggest that classes begin with Thonny for the first several weeks. As students want to do more complex functions such as build automatic deployment scripts other IDEs are more appropriate.

                                                                                                                                                                +

                                                                                                                                                                Thonny 3.3.3 (2021-01-21) was the first version to support the Raspberry Pi Pico. There have also been several enhancements since that release. For a release history, see the Thonny Release History. We suggest checking this link monthly for updates.

                                                                                                                                                                +

                                                                                                                                                                Installing Thonny

                                                                                                                                                                +

                                                                                                                                                                The best way to install Thonny is to go to the Thonny website an look for the "Download" area for your operating system. That link is here:

                                                                                                                                                                +

                                                                                                                                                                https://thonny.org/

                                                                                                                                                                +

                                                                                                                                                                Make sure you upgrade to the latest version of Thonny if you already have a Thonny installed on your computer.

                                                                                                                                                                +

                                                                                                                                                                You can find more tips on getting started with Thonny on the Raspberry Pi website:

                                                                                                                                                                +

                                                                                                                                                                https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2

                                                                                                                                                                +

                                                                                                                                                                Thonny runs on Mac, Windows and Linux.

                                                                                                                                                                +

                                                                                                                                                                Upgrading Thonny

                                                                                                                                                                +

                                                                                                                                                                Although you can always upgrade Thonny by removing it and reinstalling a new version, on Mac and Linux systems there is an easier method.

                                                                                                                                                                +

                                                                                                                                                                Run the following shell command:

                                                                                                                                                                +
                                                                                                                                                                1
                                                                                                                                                                sudo yum upgrade thonny
                                                                                                                                                                +
                                                                                                                                                                +

                                                                                                                                                                or

                                                                                                                                                                +
                                                                                                                                                                1
                                                                                                                                                                sudo apt-get upgrade thonny
                                                                                                                                                                +
                                                                                                                                                                +

                                                                                                                                                                Running help()

                                                                                                                                                                +

                                                                                                                                                                You can enter the help() function in the main script area and then press the Play button. This will tell you

                                                                                                                                                                +
                                                                                                                                                                 1
                                                                                                                                                                + 2
                                                                                                                                                                + 3
                                                                                                                                                                + 4
                                                                                                                                                                + 5
                                                                                                                                                                + 6
                                                                                                                                                                + 7
                                                                                                                                                                + 8
                                                                                                                                                                + 9
                                                                                                                                                                +10
                                                                                                                                                                +11
                                                                                                                                                                +12
                                                                                                                                                                +13
                                                                                                                                                                +14
                                                                                                                                                                +15
                                                                                                                                                                +16
                                                                                                                                                                +17
                                                                                                                                                                +18
                                                                                                                                                                +19
                                                                                                                                                                +20
                                                                                                                                                                +21
                                                                                                                                                                +22
                                                                                                                                                                +23
                                                                                                                                                                +24
                                                                                                                                                                +25
                                                                                                                                                                +26
                                                                                                                                                                +27
                                                                                                                                                                +28
                                                                                                                                                                +29
                                                                                                                                                                +30
                                                                                                                                                                +31
                                                                                                                                                                +32
                                                                                                                                                                +33
                                                                                                                                                                +34
                                                                                                                                                                +35
                                                                                                                                                                +36
                                                                                                                                                                +37
                                                                                                                                                                +38
                                                                                                                                                                MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040
                                                                                                                                                                +Type "help()" for more information.
                                                                                                                                                                +>>> %Run -c $EDITOR_CONTENT
                                                                                                                                                                +Welcome to MicroPython!
                                                                                                                                                                +
                                                                                                                                                                +For online help please visit https://micropython.org/help/.
                                                                                                                                                                +
                                                                                                                                                                +For access to the hardware use the 'machine' module.  RP2 specific commands
                                                                                                                                                                +are in the 'rp2' module.
                                                                                                                                                                +
                                                                                                                                                                +Quick overview of some objects:
                                                                                                                                                                +  machine.Pin(pin) -- get a pin, eg machine.Pin(0)
                                                                                                                                                                +  machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
                                                                                                                                                                +    methods: init(..), value([v]), high(), low(), irq(handler)
                                                                                                                                                                +  machine.ADC(pin) -- make an analog object from a pin
                                                                                                                                                                +    methods: read_u16()
                                                                                                                                                                +  machine.PWM(pin) -- make a PWM object from a pin
                                                                                                                                                                +    methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])
                                                                                                                                                                +  machine.I2C(id) -- create an I2C object (id=0,1)
                                                                                                                                                                +    methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)
                                                                                                                                                                +             readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)
                                                                                                                                                                +  machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)
                                                                                                                                                                +    methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)
                                                                                                                                                                +  machine.Timer(freq, callback) -- create a software timer object
                                                                                                                                                                +    eg: machine.Timer(freq=1, callback=lambda t:print(t))
                                                                                                                                                                +
                                                                                                                                                                +Pins are numbered 0-29, and 26-29 have ADC capabilities
                                                                                                                                                                +Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT
                                                                                                                                                                +Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN
                                                                                                                                                                +
                                                                                                                                                                +Useful control commands:
                                                                                                                                                                +  CTRL-C -- interrupt a running program
                                                                                                                                                                +  CTRL-D -- on a blank line, do a soft reset of the board
                                                                                                                                                                +  CTRL-E -- on a blank line, enter paste mode
                                                                                                                                                                +
                                                                                                                                                                +For further help on a specific object, type help(obj)
                                                                                                                                                                +For a list of available modules, type help('modules')
                                                                                                                                                                +>>>
                                                                                                                                                                +
                                                                                                                                                                +

                                                                                                                                                                Save Options

                                                                                                                                                                +

                                                                                                                                                                You can save a python file in Thonny to either the Pico or to your local computer's file system.

                                                                                                                                                                +

                                                                                                                                                                +

                                                                                                                                                                first stop execution of any program you are running.

                                                                                                                                                                +

                                                                                                                                                                Downloading the Firmware

                                                                                                                                                                +

                                                                                                                                                                After you start up Thonny there will be a button in the lower right corner.

                                                                                                                                                                +

                                                                                                                                                                After you click on it you will see the following:

                                                                                                                                                                +
                                                                                                                                                                1
                                                                                                                                                                +2
                                                                                                                                                                +3
                                                                                                                                                                +4
                                                                                                                                                                +5
                                                                                                                                                                +6
                                                                                                                                                                +7
                                                                                                                                                                Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2
                                                                                                                                                                +Writing to /Volumes/RPI-RP2/firmware
                                                                                                                                                                +100%
                                                                                                                                                                +Waiting for the port...
                                                                                                                                                                +Found 2e8a:0005 at /dev/cu.usbmodem0000000000001
                                                                                                                                                                +
                                                                                                                                                                +Done!
                                                                                                                                                                +
                                                                                                                                                                +

                                                                                                                                                                Version

                                                                                                                                                                +

                                                                                                                                                                After you press play the following will appear in the console.

                                                                                                                                                                +
                                                                                                                                                                1
                                                                                                                                                                +2
                                                                                                                                                                +3
                                                                                                                                                                MicroPython v1.13-290-g556ae7914 on 2021-01-21; Raspberry Pi Pico with RP2040
                                                                                                                                                                +Type "help()" for more information.
                                                                                                                                                                +>>> %Run -c $EDITOR_CONTENT
                                                                                                                                                                +
                                                                                                                                                                +

                                                                                                                                                                Plotting Values on Thonny

                                                                                                                                                                +

                                                                                                                                                                If you are reading sensor values and want to see a nice plot of the values, you can use Thonny's Plot function to view the values. Simply add numeric print values to your main loop and they will be displayed in the plot window. This is very useful for any analog to digital conversions and can be used as a simple tool to view anomalies in incoming data. For example if you accidentally hook up a potentiometer's positive rail to 3.3OUT instead of the 3.3REF you will see noise in the incoming data caused by spikes on the power rails.

                                                                                                                                                                +

                                                                                                                                                                Background on Thonny

                                                                                                                                                                +

                                                                                                                                                                MicroPython was originally developed by Damien George and first released in 2014. However, MicroPython did not have a development environment that was easy for students to use. Thonny was developed to provide an easy to use tool just for MicroPython development. Thonny was created at the University of Tartu Institute of Computer Science in Estonia for this purpose. They continue to support Thonny.

                                                                                                                                                                +

                                                                                                                                                                Several feature for Thonny were sponsored by the Raspberry Pi Foundation and we continue to see a close relationship between the Raspberry Pi Foundation and the Thonny development team.

                                                                                                                                                                +
                                                                                                                                                                  +
                                                                                                                                                                • Thonny web site
                                                                                                                                                                • +
                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                +
                                                                                                                                                                + + + +
                                                                                                                                                                + + + +
                                                                                                                                                                + +
                                                                                                                                                                + + + +
                                                                                                                                                                + + + +
                                                                                                                                                                + + +
                                                                                                                                                                +
                                                                                                                                                                + + Previous + +
                                                                                                                                                                + Powering Your Projects +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + + +
                                                                                                                                                                + + Next + +
                                                                                                                                                                + VS Code IDE +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                                + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/02d-vscode/index.html b/getting-started/02d-vscode/index.html new file mode 100644 index 000000000..2e28f4399 --- /dev/null +++ b/getting-started/02d-vscode/index.html @@ -0,0 +1,1686 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + VS Code IDE - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                +
                                                                                                                                                                + +
                                                                                                                                                                + + + + + + +
                                                                                                                                                                +
                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                +
                                                                                                                                                                + + + VS Code IDE + + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + + + + + + + +
                                                                                                                                                                + +
                                                                                                                                                                +
                                                                                                                                                                + + +
                                                                                                                                                                + + +
                                                                                                                                                                + +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                +
                                                                                                                                                                + Initializing search +
                                                                                                                                                                +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + +
                                                                                                                                                                  + +
                                                                                                                                                                  + + +
                                                                                                                                                                  +
                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                  + +
                                                                                                                                                                  + +
                                                                                                                                                                  + + + + + + +
                                                                                                                                                                  +
                                                                                                                                                                  + + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + + +
                                                                                                                                                                  + + +
                                                                                                                                                                  + +
                                                                                                                                                                  + + +
                                                                                                                                                                  +
                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                    + +
                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Boards + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Displays + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Sourcing Parts + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + ESP32 + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Powering Your Projects + + + + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + Thonny IDE + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + VS Code IDE + + + + + + + +
                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + Installing Visual Studio Code + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + Adding the Pico Go Extension + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      + +
                                                                                                                                                                      + +
                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                    • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                    • + + + + +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                  • + + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + +
                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                    + +
                                                                                                                                                                  • + + + Installing Visual Studio Code + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + Adding the Pico Go Extension + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                  • + +
                                                                                                                                                                  + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + +
                                                                                                                                                                  +
                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                  Using Visual Studio Code to Program MicroPython

                                                                                                                                                                  +

                                                                                                                                                                  Although the Thonny IDE is a great way for kids to start programming in Python on the Raspberry Pi Pico, it has limited advanced features and no large library of extensions.

                                                                                                                                                                  +

                                                                                                                                                                  For intermediate to advanced Python developers, the Visual Studio Code IDE is a good options when it is used with an appropriate extension such as the Pico Go extension by Chris Wood.

                                                                                                                                                                  +

                                                                                                                                                                  Note that Visual Studio Code is sometimes just called VS Code.

                                                                                                                                                                  +

                                                                                                                                                                  Code extensions provide code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REPL console. You can a single file on your board, sync your entire project or directly type and execute commands. Because the files are stored on your local computer, it makes it easier to use version control software to allow you to work in teams with remote developers.

                                                                                                                                                                  +

                                                                                                                                                                  Installing Visual Studio Code

                                                                                                                                                                  +

                                                                                                                                                                  Visual Studio Code runs on Windows, Mac and Linux systems such as the operating systems that run on the Raspberry Pi 3 or 4. You typically need around 2GB of RAM to run VS-Code.

                                                                                                                                                                  +

                                                                                                                                                                  See the VS Code Requirements.

                                                                                                                                                                  +

                                                                                                                                                                  If you have a Raspberry Pi the installation instructions are here.

                                                                                                                                                                  +

                                                                                                                                                                  Adding the Pico Go Extension

                                                                                                                                                                  +

                                                                                                                                                                  After you have installed VS-Code you must download the Pico Go Extension:

                                                                                                                                                                  +

                                                                                                                                                                  Pico Go Quick Start

                                                                                                                                                                  +

                                                                                                                                                                  References

                                                                                                                                                                  +
                                                                                                                                                                    +
                                                                                                                                                                  1. Pico Go by Chris Wood
                                                                                                                                                                  2. +
                                                                                                                                                                  3. Bao Phan Micropython Extension
                                                                                                                                                                  4. +
                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                  +
                                                                                                                                                                  + + + +
                                                                                                                                                                  + + + +
                                                                                                                                                                  + +
                                                                                                                                                                  + + + +
                                                                                                                                                                  + + + +
                                                                                                                                                                  + + +
                                                                                                                                                                  +
                                                                                                                                                                  + + Previous + +
                                                                                                                                                                  + Thonny IDE +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + + +
                                                                                                                                                                  + + Next + +
                                                                                                                                                                  + MicroPython Libraries +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                  + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                  + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/03-suggested-parts/index.html b/getting-started/03-suggested-parts/index.html new file mode 100644 index 000000000..39fac132e --- /dev/null +++ b/getting-started/03-suggested-parts/index.html @@ -0,0 +1,2093 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Sourcing Parts - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                  +
                                                                                                                                                                  + +
                                                                                                                                                                  + + + + + + +
                                                                                                                                                                  +
                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                  +
                                                                                                                                                                  + + + Sourcing Parts + + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                  + +
                                                                                                                                                                  +
                                                                                                                                                                  + + +
                                                                                                                                                                  + + +
                                                                                                                                                                  + +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  +
                                                                                                                                                                  + Initializing search +
                                                                                                                                                                  +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + +
                                                                                                                                                                    + +
                                                                                                                                                                    + + +
                                                                                                                                                                    +
                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                    + +
                                                                                                                                                                    + +
                                                                                                                                                                    + + + + + + +
                                                                                                                                                                    +
                                                                                                                                                                    + + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + + +
                                                                                                                                                                    + + +
                                                                                                                                                                    + +
                                                                                                                                                                    + + +
                                                                                                                                                                    +
                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                                      + +
                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Boards + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Displays + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + Sourcing Parts + + + + + + + +
                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                          + +
                                                                                                                                                                        • + + + Purchasing The Raspberry Pi Kits + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + The Raspberry Pi Pico + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + USB Cable + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Headers + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Solderless Breadboards + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Hookup Wire + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Breakable 40-Pin Headers + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Male-to-Male Breadboard Jumper Wires + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Momentary Press Buttons + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Sensor Kit + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Linear 10K Potentiometers + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Momentary Press Buttons + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Switches + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Small 0.96" OLED displays + + + +
                                                                                                                                                                          +
                                                                                                                                                                            + +
                                                                                                                                                                          • + + + Larger 2.42" OLEDs + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Non-rechargeable AA and AAA Battery Packs + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Rechargeable Battery Packs + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Ultrasonic Distance Sensors + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Motor Controllers + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        + +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + ESP32 + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Powering Your Projects + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + Thonny IDE + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + VS Code IDE + + + + +
                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                      • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                      • + + + + +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                    • + + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + +
                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                      + +
                                                                                                                                                                    • + + + Purchasing The Raspberry Pi Kits + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + The Raspberry Pi Pico + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + USB Cable + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Headers + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Solderless Breadboards + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Hookup Wire + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Breakable 40-Pin Headers + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Male-to-Male Breadboard Jumper Wires + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Momentary Press Buttons + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Sensor Kit + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Linear 10K Potentiometers + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Momentary Press Buttons + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Switches + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Small 0.96" OLED displays + + + +
                                                                                                                                                                      +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + Larger 2.42" OLEDs + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Non-rechargeable AA and AAA Battery Packs + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Rechargeable Battery Packs + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Ultrasonic Distance Sensors + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    • + + + Motor Controllers + + + +
                                                                                                                                                                    • + +
                                                                                                                                                                    + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + +
                                                                                                                                                                    +
                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                    Sourcing Parts

                                                                                                                                                                    +

                                                                                                                                                                    One of the key values of CoderDojo clubs around the world is to not charge any fees for attending these clubs. Parts need to be purchase by limited funds raised through donations. Club organizers need to be frugal about getting low-cost parts for the participants.

                                                                                                                                                                    +

                                                                                                                                                                    Our experience is that is difficult to get the right parts at low cost using firms that promise quick delivery times of a few days. The lowest price parts often must be purchased weeks in advance from places like China and Taiwan. As a result, clubs that use funds carefully must plan weeks if not months in advance of classes and events. So we strongly suggest bringing an robot part procurement team together two months before you begin to offer robot courses where students can each have their own robots.

                                                                                                                                                                    +

                                                                                                                                                                    Purchasing The Raspberry Pi Kits

                                                                                                                                                                    +

                                                                                                                                                                    As of June 2021, the Raspberry Pi Pico did not come integrated into low-cost development kits that include robot kit parts. You frequently must to purchase the independent parts yourself.

                                                                                                                                                                    +

                                                                                                                                                                    Here are some of the parts we recommend.

                                                                                                                                                                    +

                                                                                                                                                                    The Raspberry Pi Pico

                                                                                                                                                                    +

                                                                                                                                                                    In the US, our best source of these has been Microcenter stores. They sell them for $3.99 and they often have them on sale for $1.99.

                                                                                                                                                                    +

                                                                                                                                                                    Microcenter Pico Part Listing

                                                                                                                                                                    +

                                                                                                                                                                    Microcenter has around 25 Locations in the US.

                                                                                                                                                                    +

                                                                                                                                                                    USB Cable

                                                                                                                                                                    +

                                                                                                                                                                    For a Mac with USB-C connectors, you will need to get a USB micro to C cable: +USB Micro to USB C for Mac

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • Ebay USB 3.1 USB C Type C to Micro USB Male Sync OTG Charge Data Transfers Adapters Sample 1 meter USB cable on eBay for $2.40.
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Headers

                                                                                                                                                                    +

                                                                                                                                                                    We need male breakaway headers with standard 1/10th inch spacing. The Raspberry Pi Pico will need 20 pins on each side. If you get 40-pin versions they can easily be broken in half.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • +

                                                                                                                                                                      EBay: Ebay 40-Pin Male Header 0.1" 2.54mm Breadboard PCB Strip Connectors 5pc - these ship from China in a few weeks and you can get five of them for $1 (including shipping).

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      Amazon: Amazon MCIGICM 10pcs Male Header Pin, 40 Pin Header Strip (2.54 mm) for Arduino Connector

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Solderless Breadboards

                                                                                                                                                                    +

                                                                                                                                                                    We like the 1/2 size boards that have 400 connection points. We like to mount them with the USB connector at the top with the numbers running down the left side to align with the pin numbers.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • +

                                                                                                                                                                      EBay: Solderless Breadboard 400 Point Tie Prototype Test Bread Board PCB For Arduino

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      Amazon: Amazon 4 Pieces for $6

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Hookup Wire

                                                                                                                                                                    +

                                                                                                                                                                    Use 22 gauge wire. Get a large spool of black and red and smaller spools of other colors. We use

                                                                                                                                                                    +

                                                                                                                                                                    Breakable 40-Pin Headers

                                                                                                                                                                    +

                                                                                                                                                                    If you purchase the Raspberry Pi Pico kit that does not have the header pins soldered in, you can use the following to add your own header pins in so the Pico's can be used with the header pins.

                                                                                                                                                                    +

                                                                                                                                                                    40 pin Breakable Pin Header 2.54mm Single Row Male Header Connector Kit on eBay. I purchased 12 of these for $5 or $4.24 per pack of 12 when I purchase 4 packs.

                                                                                                                                                                    +

                                                                                                                                                                    Male-to-Male Breadboard Jumper Wires

                                                                                                                                                                    +

                                                                                                                                                                    You can use 22 gauge wire to build your projects, however kids that don't have fine motor skills sometimes get frustrated with raw wires. You can purchase a Jumper Wire Kit with 65 jumpers on EBay for under $2 that has nice plastic ends that are easier to use.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • +

                                                                                                                                                                      Ebay: 65pcs Jumper Wire cable kit for Solderless Breadboard New - 65 of various lengths for $1.50

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      Ebay: 65X 65PCS Jumper Wire Cable Kit For Solderless Breadboard

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      Amazon: ZYAMY 195pcs Breadboard Jumper Wire 12cm 16cm 20cm 24cm Solderless Flexible Breadboard Connecting Line Cables Male to Male Breadboard Jumpers (65pcs/Set x 3) - three packs of 65 for about $8

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Momentary Press Buttons

                                                                                                                                                                    +

                                                                                                                                                                    +

                                                                                                                                                                    A B3F Momentary Press Button with a blue cap.

                                                                                                                                                                    +

                                                                                                                                                                    +

                                                                                                                                                                    Note the schematic in the lower right corner that shows the internal connections of the button.

                                                                                                                                                                    +

                                                                                                                                                                    We like the B3F-4055 12 x12x7.3mm Tactile Switch Momentary Press Buttons that have small dimples on the bottom that fit into the breadboard center trough. They can be purchased for under 10 cents per unit on eBay. You can by them with our without colored caps. The links below have example listings on eBay.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • eBay Tactile Push Button Switch Momentary Tact & Cap 12x12x7.3mm Assorted Kit - this kit includes 15 switchs with seven colors of caps for US $8.95.
                                                                                                                                                                    • +
                                                                                                                                                                    • eBay: 10PCS New B3F Tactile Switch Key Button Switch 12x12x7.3mm Blue
                                                                                                                                                                    • +
                                                                                                                                                                    • eBay 100PCS B3F-4055 Tactile Switch W/ OMRON Tact Push Button Momentary 12 x12 x7.3mm
                                                                                                                                                                    • +
                                                                                                                                                                    • eBay Button Caps 140PCS Round Tactile Button Cap Kits 9.585.1mm for 1212*7.3mm Tact Switch
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Sensor Kit

                                                                                                                                                                    +

                                                                                                                                                                    Although not all of these items are really "sensors" (some are displays), these kits provide high value at a low price-per item cost. Note that some of these kits contain tilt switches that contain Mercery. I remove these from the kits.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • EBay 16 Sensor Kit Raspberry Pi / Arduino Sensor Kit 16 Modules Package 16 kinds of sensor
                                                                                                                                                                    • +
                                                                                                                                                                    • EBay 45 Sensor Kit for $18 US 45 In 1 Sensor Module Starter Kit Updated Set For Arduino Raspberry Pi Education
                                                                                                                                                                    • +
                                                                                                                                                                    • HiLetgo 37 Sensors Assortment Kit 37 Sensors Kit Sensor Starter Kit for Arduino Raspberry pi Sensor kit 37 in 1 Robot Projects Starter Kits for Arduino Raspberry pi
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Linear 10K Potentiometers

                                                                                                                                                                    +

                                                                                                                                                                    We use linear 10K potentiometers in many labs and kits. The pre-wired options are very handy but you will need some male-to-male jumpers.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • EBay: Pre-wired Potentiometer with Knob
                                                                                                                                                                    • +
                                                                                                                                                                    • EBay: 10 10K Pots for $2.29
                                                                                                                                                                    • +
                                                                                                                                                                    • Amazon: 10K Pot Kit with 8 pots and knobs for $8
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Momentary Press Buttons

                                                                                                                                                                    +

                                                                                                                                                                    We like these small momentary press buttons because they are easy to mount directly on the breadboard. They provide ideal "Mode Programming" buttons to put the microcontroller into a programming mode.

                                                                                                                                                                    +

                                                                                                                                                                    Switches

                                                                                                                                                                    +

                                                                                                                                                                    These are ideal for turning your project boxes on and off.

                                                                                                                                                                    +

                                                                                                                                                                    Small 0.96" OLED displays

                                                                                                                                                                    +

                                                                                                                                                                    We love these low-cost 128X64 OLED displays. They are bright and draw very little power. There are two different connectors: 4-wire I2C and 7-wire SPI. I would suggest the simpler I2C for most starter projects.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • EBay: 0.96" OLED LCD Display Module IIC I2C Interface 128x64 For SSD1306
                                                                                                                                                                    • +
                                                                                                                                                                    • Amazon: Five OLED displays for $7
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Larger 2.42" OLEDs

                                                                                                                                                                    +

                                                                                                                                                                    For our robot projects our students like to view the values from a distance. For them we use these $17 OLED displays that are about twice the size.

                                                                                                                                                                    +

                                                                                                                                                                    2.42" OLED Display wired with SPI

                                                                                                                                                                    +

                                                                                                                                                                    Non-rechargeable AA and AAA Battery Packs

                                                                                                                                                                    +

                                                                                                                                                                    Rechargeable Battery Packs

                                                                                                                                                                    +

                                                                                                                                                                    If you are work on project that need long-lasting portable power such as LED strip costumes, there are a wide variety of long-lasting rechargeable battery packs available from prices around $9 to $15. My favorites are ones that have percentage of power remaining displayed.

                                                                                                                                                                    +

                                                                                                                                                                    Ultrasonic Distance Sensors

                                                                                                                                                                    +

                                                                                                                                                                    These inexpensive "ping" sensors are used in many robot projects.

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • HC-SR04 Ultrasonic Distance Sensor - $1 on eBay
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Motor Controllers

                                                                                                                                                                    +

                                                                                                                                                                    We like two motor three wheel robots in our classrooms. They need a H-Bridge circuit for controlling the motor direction. The popular L293D chip takes four PWM signals and will use these to drive two 3-12v DC motors. The L293D chip can be mounted directly on your breadboard. However, we like the low-cost Mini motor controller boards that are only $2 that also have handy screw headers for easily attaching and removing the motor and power wires.

                                                                                                                                                                    +

                                                                                                                                                                    Here are the specs: Here

                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                    • Input DC 4.5-36V
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      600mA output per channel (per motor)

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      See section 4.4 in the Raspberry Pi Pico Datasheet on the Powerchain - note that the input VSYS, the main system input voltage, is only designed to go up to up to 5.5 volts. VSYS feeds the RVT6150 buck-boost SMPS.

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • +

                                                                                                                                                                      Mini Motor Drive Shield Expansion Board L293D Module For Arduino UNO MEGA2560 R3 $3

                                                                                                                                                                      +
                                                                                                                                                                    • +
                                                                                                                                                                    • [Amazon 3 motor drives for $7]
                                                                                                                                                                    • +
                                                                                                                                                                    • L293 Datasheet
                                                                                                                                                                    • +
                                                                                                                                                                    • Banggood L293D Motor Drive Module
                                                                                                                                                                    • +
                                                                                                                                                                    • Parshavele
                                                                                                                                                                    • +
                                                                                                                                                                    • ST Microelectronics L78M Datasheet
                                                                                                                                                                    • +
                                                                                                                                                                    • Datasheet for 78M05 Voltage
                                                                                                                                                                    • +
                                                                                                                                                                    • Datasheet for ST 78M05 Voltage Regulators
                                                                                                                                                                    • +
                                                                                                                                                                    +

                                                                                                                                                                    Note that the L293D Mini Motor Drive shield also has a voltage regulator that delivers a constant 5 volt signal to the robot microcontroller.

                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                    +
                                                                                                                                                                    + + + +
                                                                                                                                                                    + + + +
                                                                                                                                                                    + +
                                                                                                                                                                    + + + +
                                                                                                                                                                    + + + +
                                                                                                                                                                    + + +
                                                                                                                                                                    +
                                                                                                                                                                    + + Previous + +
                                                                                                                                                                    + Displays +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + + +
                                                                                                                                                                    + + Next + +
                                                                                                                                                                    + Raspberry Pi Pico +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                    + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                    + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/04-power/index.html b/getting-started/04-power/index.html new file mode 100644 index 000000000..7b6a223d7 --- /dev/null +++ b/getting-started/04-power/index.html @@ -0,0 +1,1852 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Powering Your Projects - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                    +
                                                                                                                                                                    + +
                                                                                                                                                                    + + + + + + +
                                                                                                                                                                    +
                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                    +
                                                                                                                                                                    + + + Powering Your Projects + + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                    + +
                                                                                                                                                                    +
                                                                                                                                                                    + + +
                                                                                                                                                                    + + +
                                                                                                                                                                    + +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    +
                                                                                                                                                                    + Initializing search +
                                                                                                                                                                    +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + +
                                                                                                                                                                      + +
                                                                                                                                                                      + + +
                                                                                                                                                                      +
                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                      + +
                                                                                                                                                                      + +
                                                                                                                                                                      + + + + + + +
                                                                                                                                                                      +
                                                                                                                                                                      + + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + + +
                                                                                                                                                                      + + +
                                                                                                                                                                      + +
                                                                                                                                                                      + + +
                                                                                                                                                                      +
                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                        + +
                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Boards + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Displays + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Sourcing Parts + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + ESP32 + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + Powering Your Projects + + + + + + + +
                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                            + +
                                                                                                                                                                          • + + + Power Connectors + + + +
                                                                                                                                                                            +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + USB Battery Packs + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Preventing USB Power Pack Autoshutdown + + + +
                                                                                                                                                                            +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + Battery Power + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Monitoring USB Power + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Running both USB and External Battery Power on the Raspberry Pi Pico + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Monitoring Batter Power Level on the Raspberry Pi Pico + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          + +
                                                                                                                                                                          + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + Thonny IDE + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + VS Code IDE + + + + +
                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                        • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                        • + + + + +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                      • + + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + +
                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                        + +
                                                                                                                                                                      • + + + Power Connectors + + + +
                                                                                                                                                                        +
                                                                                                                                                                          + +
                                                                                                                                                                        • + + + USB Battery Packs + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + Preventing USB Power Pack Autoshutdown + + + +
                                                                                                                                                                        +
                                                                                                                                                                          + +
                                                                                                                                                                        • + + + Battery Power + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + Monitoring USB Power + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + Running both USB and External Battery Power on the Raspberry Pi Pico + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      • + + + Monitoring Batter Power Level on the Raspberry Pi Pico + + + +
                                                                                                                                                                      • + +
                                                                                                                                                                      + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + +
                                                                                                                                                                      +
                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                      Powering Your MicroPython Projects

                                                                                                                                                                      +

                                                                                                                                                                      If you are just using MicroPython to learn how to code you can use the USB connector from your Mac or PC to power your project. However, if you are creating a device that can't be connected to the USB cable such as a robot, then you will need to hook up portable power supply like a battery pack to power your device.

                                                                                                                                                                      +

                                                                                                                                                                      The good news is that most microcontrollers like the Raspberry Pi Pico or ESP32 have many options and they are easy to use. Just be careful about applying too much power since unlike the old 5V Arduino boards, these devices only use 3.3v power supplies. Connecting the Pico to a 4 AA batteries (4 X 1.5 volts = 6 volt total) can damage the Pico microcontroller.

                                                                                                                                                                      +

                                                                                                                                                                      Power Connectors

                                                                                                                                                                      +

                                                                                                                                                                      The Raspberry Pi Pico has three important power connectors you should learn about.

                                                                                                                                                                      +

                                                                                                                                                                      +
                                                                                                                                                                        +
                                                                                                                                                                      1. VBUS - A direct connection to the USB System bus and available in the upper right corner of the Pico. When connected, circuits inside the Pico will disconnect the other power sources. This is the preferred way to power the Pico when doing development and if a USB battery pack is used.
                                                                                                                                                                      2. +
                                                                                                                                                                      3. VSYS - This the main system input voltage and used when the device is not connected to the USB. The Pico has on-board power control circuits that allow VSYS to vary anywhere in the range of 1.8V to 5.5V. This is great since three AAA batteries which start at 4.5 volts can be used even as their voltage drops to 1.8 volts. +VSYS is used by the on-board SMPS (Switched Mode Power Supply) to generate the 3.3V for the RP2040 and its GPIO. +You can use this to power the Pico if you have any non-USB battery pack such as 3 AA batteries or an external 5 volt power supply that is generated by a motor driver circuit.
                                                                                                                                                                      4. +
                                                                                                                                                                      5. 3V3_EN connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. +To disable the 3.3V (which also de-powers the RP2040), short this pin low.
                                                                                                                                                                      6. +
                                                                                                                                                                      7. 3.3OUT This pin can be used to power external circuitry. The maximum output +current will depend on RP2040 load and VSYS voltage, it is recommended to keep the load on this pin less than 300mA. +In in other words, you don't want to drive more than about 15 LEDs that each draw up to 20 milliamps at full power. +3V3 is the main 3.3V supply to RP2040 and its I/O, generated by the on-board SMPS.
                                                                                                                                                                      8. +
                                                                                                                                                                      9. ADC_VREF - This should not be used for any purpose other than to provide a low-current voltage reference for any of the three analog-to-digital inputs. For example if you have three potentiometers you would hook the positive rail of each of them to this pin. This allows for reasonably high-resolution analog to digital that is mostly free of the power noise present on the 3.3OUT pin.
                                                                                                                                                                      10. +
                                                                                                                                                                      +

                                                                                                                                                                      USB Battery Packs

                                                                                                                                                                      +

                                                                                                                                                                      USB Battery Pack Large +There is large and growing market for rechargeable cell-phone power packs that are ideal for applications such as robotics and powering a remote microcontroller for a long time. They can be purchased in many power storage levels from 2500 milliamp hours up to over 1 million milliamp hours.

                                                                                                                                                                      +

                                                                                                                                                                      Preventing USB Power Pack Autoshutdown

                                                                                                                                                                      +

                                                                                                                                                                      The one issue to be aware of with battery packs is that they automatically power down if they don't sense a minimum current being drawn such as about 10 milliamps. In many applications the Pico draws less than that amount. One fix is to simply add LED power indicator that draws 10 milliamps. This will

                                                                                                                                                                      +

                                                                                                                                                                      Battery Power

                                                                                                                                                                      +

                                                                                                                                                                      3 AA alkaline batteries wired in series provide plenty of power for small Pico-based MicroPython projects. Each battery is 1.5 volts which give a total of 4.5 volts which is well within the maximum power use by the VSYS input on the Pico.

                                                                                                                                                                      +

                                                                                                                                                                      As an alternative, you can also use 4 rechargeable NiCad batteries that have a nominal rating of 1.2 volts each. This is a total of 4.8 volts, which is still under the 5.5 volt limit.

                                                                                                                                                                      +
                                                                                                                                                                      +

                                                                                                                                                                      Warning

                                                                                                                                                                      +

                                                                                                                                                                      Do not connect 4 AA batteries directly to VSYS. 6 volts is too high for the Pico's power system and could damage it. Use a voltage regulator such as is found on motor driver boards. Another alternative is to use a DC-to-DC voltage regulator such as a Buck Converter.

                                                                                                                                                                      +
                                                                                                                                                                      +

                                                                                                                                                                      Monitoring USB Power

                                                                                                                                                                      +

                                                                                                                                                                      On the Pico, GP24 can be used to indicate if power is being drawn from the USB cable. You can also use this information to change the behavior such as drop into low-power mode when disconnected from a USB source.

                                                                                                                                                                      +

                                                                                                                                                                      See here

                                                                                                                                                                      +

                                                                                                                                                                      Here is some sample MicroPython code that displays this value:

                                                                                                                                                                      +
                                                                                                                                                                       1
                                                                                                                                                                      + 2
                                                                                                                                                                      + 3
                                                                                                                                                                      + 4
                                                                                                                                                                      + 5
                                                                                                                                                                      + 6
                                                                                                                                                                      + 7
                                                                                                                                                                      + 8
                                                                                                                                                                      + 9
                                                                                                                                                                      +10
                                                                                                                                                                      +11
                                                                                                                                                                      +12
                                                                                                                                                                      +13
                                                                                                                                                                      import machine
                                                                                                                                                                      +import utime
                                                                                                                                                                      +
                                                                                                                                                                      +led_onboard = machine.Pin(25, machine.Pin.OUT)
                                                                                                                                                                      +USBpower = machine.Pin(24, machine.Pin.IN) 
                                                                                                                                                                      +
                                                                                                                                                                      +while True:
                                                                                                                                                                      +   led_onboard.value(1)
                                                                                                                                                                      +   utime.sleep(0.5)
                                                                                                                                                                      +   led_onboard.value(0)
                                                                                                                                                                      +   utime.sleep(0.5)
                                                                                                                                                                      +   if USBpower() != 1:
                                                                                                                                                                      +      utime.sleep(1)
                                                                                                                                                                      +
                                                                                                                                                                      +

                                                                                                                                                                      This program prints out the value of the USB Power indicator.

                                                                                                                                                                      +
                                                                                                                                                                       1
                                                                                                                                                                      + 2
                                                                                                                                                                      + 3
                                                                                                                                                                      + 4
                                                                                                                                                                      + 5
                                                                                                                                                                      + 6
                                                                                                                                                                      + 7
                                                                                                                                                                      + 8
                                                                                                                                                                      + 9
                                                                                                                                                                      +10
                                                                                                                                                                      import machine
                                                                                                                                                                      +import utime
                                                                                                                                                                      +
                                                                                                                                                                      +led_onboard = machine.Pin(25, machine.Pin.OUT)
                                                                                                                                                                      +USBpower = machine.Pin(24, machine.Pin.IN) 
                                                                                                                                                                      +
                                                                                                                                                                      +if USBpower() = 1:
                                                                                                                                                                      +    print('drawing power from the USB')
                                                                                                                                                                      +else
                                                                                                                                                                      +    print('drawing power from VSYS - a battery or external power source')
                                                                                                                                                                      +
                                                                                                                                                                      +

                                                                                                                                                                      Power consumption when running this code is approximately 0.1W (19mA at 4.99V, so 4 x AA batteries (@ 2,000mAh each) would keep the Pico running for well over 4 days.

                                                                                                                                                                      +

                                                                                                                                                                      Running both USB and External Battery Power on the Raspberry Pi Pico

                                                                                                                                                                      +

                                                                                                                                                                      The battery should provide a voltage greater than 1.8v and less than 5.5v. Importantly if both a battery and a micro USB cable are connected at the same time a Schottky diode should be placed between the battery positive and VSYS [see section 4.4 & 4.5 of the Raspberry Pi Pico Datasheet. As long as the battery voltage is less than that coming in from the USB cable, power will be drawn from the USB supply and not the battery and, when you unplug the Pico from its USB supply, the Pico will keep on running, using power from the battery (and visa versa when you plug it back in).

                                                                                                                                                                      +

                                                                                                                                                                      Monitoring Batter Power Level on the Raspberry Pi Pico

                                                                                                                                                                      +

                                                                                                                                                                      You can use one of the three analog to digital converters to allow the Pico to monitor the power remaining in an external battery. For example if you have 3 AA batteries you can connect two 100K ohm resistors in series and connect the top and bottom to the power and ground. Then connect the midpoint to one of the three ADC inputs. This will give you a way to monitor the power remaining in an external battery. A fully charge battery pack voltage such at 4.5 volts will generate a voltage of 1/2 the maximum level. As the voltage drops to 1.8 volts it should display a value of 0%. An OLED can provide an ideal way to display the power level remaining.

                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                      +
                                                                                                                                                                      + + + +
                                                                                                                                                                      + + + +
                                                                                                                                                                      + +
                                                                                                                                                                      + + + +
                                                                                                                                                                      + + + +
                                                                                                                                                                      + + +
                                                                                                                                                                      +
                                                                                                                                                                      + + Previous + +
                                                                                                                                                                      + ESP32 +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + + +
                                                                                                                                                                      + + Next + +
                                                                                                                                                                      + Thonny IDE +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                      + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                      + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/docs/getting-started/05-real-time-clock.py b/getting-started/05-real-time-clock.py similarity index 100% rename from docs/getting-started/05-real-time-clock.py rename to getting-started/05-real-time-clock.py diff --git a/getting-started/06-yd-2040/index.html b/getting-started/06-yd-2040/index.html new file mode 100644 index 000000000..d073ad59a --- /dev/null +++ b/getting-started/06-yd-2040/index.html @@ -0,0 +1,1359 @@ + + + + + + + + + + + + + + + + + + + + + + + The YD-RP2040 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                      +
                                                                                                                                                                      + +
                                                                                                                                                                      + + + + + + +
                                                                                                                                                                      +
                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                      +
                                                                                                                                                                      + + + The YD-RP2040 + + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                      + +
                                                                                                                                                                      +
                                                                                                                                                                      + + +
                                                                                                                                                                      + + +
                                                                                                                                                                      + +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      +
                                                                                                                                                                      + Initializing search +
                                                                                                                                                                      +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + +
                                                                                                                                                                        + +
                                                                                                                                                                        + + +
                                                                                                                                                                        +
                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                        + +
                                                                                                                                                                        + +
                                                                                                                                                                        + + + + + + +
                                                                                                                                                                        +
                                                                                                                                                                        + + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + + +
                                                                                                                                                                        + + +
                                                                                                                                                                        + +
                                                                                                                                                                        + + +
                                                                                                                                                                        +
                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                        • + + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + +
                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                          + +
                                                                                                                                                                        • + + + Additions + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + W25Q32 Flash Chip + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + Demo Program + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                        • + +
                                                                                                                                                                        + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + +
                                                                                                                                                                        +
                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                        The YD-RP2040

                                                                                                                                                                        +

                                                                                                                                                                        +

                                                                                                                                                                        The VCC-GND YD-RP2040 is a microcontroller that sells for $5-$10 on e-Bay. It is rumored to come +with either 4MB or 16MB flash, but the units I have received only have 2MB.

                                                                                                                                                                        +

                                                                                                                                                                        Additions

                                                                                                                                                                        +
                                                                                                                                                                          +
                                                                                                                                                                        • Pin labels are on the top where they should be!
                                                                                                                                                                        • +
                                                                                                                                                                        • There is a red LED to show that power is connected
                                                                                                                                                                        • +
                                                                                                                                                                        • There is a RESET button
                                                                                                                                                                        • +
                                                                                                                                                                        • There is a USER button on GP24
                                                                                                                                                                        • +
                                                                                                                                                                        • There is a blue LED on GP25
                                                                                                                                                                        • +
                                                                                                                                                                        • There is an RGB NeoPixel LED on GP23
                                                                                                                                                                        • +
                                                                                                                                                                        • Four Analog to digital converters (the Pico only had two)
                                                                                                                                                                        • +
                                                                                                                                                                        • +
                                                                                                                                                                        +

                                                                                                                                                                        W25Q32 Flash Chip

                                                                                                                                                                        +

                                                                                                                                                                        The board has a W25Q32 (32M-bit) Serial Flash chip.

                                                                                                                                                                        +

                                                                                                                                                                        From the W25Q32 Datasheet:

                                                                                                                                                                        +

                                                                                                                                                                        It provides a storage solution for systems with limited space, pins and power. The 25Q series offers flexibility and performance well beyond ordinary Serial Flash devices. They are ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI (XIP) and storing voice, text and data. The devices operate on a single 2.7V to 3.6V power supply with current consumption as low as 5mA active and 1µA for power-down. All devices are offered in space-saving packages.

                                                                                                                                                                        +

                                                                                                                                                                        Demo Program

                                                                                                                                                                        +

                                                                                                                                                                        This program shows the blue LED flashing and the NeoPixel cycling through colors. +You can press the USR button to change the cycle speed.

                                                                                                                                                                        +
                                                                                                                                                                        1
                                                                                                                                                                        
                                                                                                                                                                        +
                                                                                                                                                                        +

                                                                                                                                                                        References

                                                                                                                                                                        +
                                                                                                                                                                          +
                                                                                                                                                                        • Walmart
                                                                                                                                                                        • +
                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                        +
                                                                                                                                                                        + + + +
                                                                                                                                                                        + + + +
                                                                                                                                                                        + +
                                                                                                                                                                        + + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                        + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/getting-started/10-displays/index.html b/getting-started/10-displays/index.html new file mode 100644 index 000000000..b55f6691c --- /dev/null +++ b/getting-started/10-displays/index.html @@ -0,0 +1,2212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Displays - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                        +
                                                                                                                                                                        + +
                                                                                                                                                                        + + + + + + +
                                                                                                                                                                        +
                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                        +
                                                                                                                                                                        + + + Displays + + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                        + +
                                                                                                                                                                        +
                                                                                                                                                                        + + +
                                                                                                                                                                        + + +
                                                                                                                                                                        + +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        +
                                                                                                                                                                        + Initializing search +
                                                                                                                                                                        +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + +
                                                                                                                                                                          + +
                                                                                                                                                                          + + +
                                                                                                                                                                          +
                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                          + +
                                                                                                                                                                          + +
                                                                                                                                                                          + + + + + + +
                                                                                                                                                                          +
                                                                                                                                                                          + + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + + +
                                                                                                                                                                          + + +
                                                                                                                                                                          + +
                                                                                                                                                                          + + +
                                                                                                                                                                          +
                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                                            + +
                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Solderless Breadboards + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Boards + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + Displays + + + + + + + +
                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                + +
                                                                                                                                                                              • + + + Display Types + + + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + Concepts + + + +
                                                                                                                                                                                +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Framebuffers + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + Display Chip Types + + + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + Communication Protocols + + + +
                                                                                                                                                                                +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Basic Draw Functions + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Initializing the Framebuffer + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Full list of Drawing Functions + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Interfaces + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + I2C + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + SPI + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + Types of Displays + + + +
                                                                                                                                                                                +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Summary Table + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + LCD + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + OLED + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + TFT Displays + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                              • + +
                                                                                                                                                                              + +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Sourcing Parts + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Raspberry Pi Pico + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + ESP32 + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Powering Your Projects + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + Thonny IDE + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + VS Code IDE + + + + +
                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                            • + + + + + MicroPython Libraries + + + + +
                                                                                                                                                                            • + + + + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                          • + + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + +
                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                            + +
                                                                                                                                                                          • + + + Display Types + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Concepts + + + +
                                                                                                                                                                            +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + Framebuffers + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Display Chip Types + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Communication Protocols + + + +
                                                                                                                                                                            +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + Basic Draw Functions + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + Initializing the Framebuffer + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + Full list of Drawing Functions + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + Interfaces + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + I2C + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + SPI + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + Types of Displays + + + +
                                                                                                                                                                            +
                                                                                                                                                                              + +
                                                                                                                                                                            • + + + Summary Table + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + LCD + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + OLED + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            • + + + TFT Displays + + + +
                                                                                                                                                                            • + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                          • + +
                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                          • + +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + +
                                                                                                                                                                          +
                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                          Adding A Display to Your Project

                                                                                                                                                                          +

                                                                                                                                                                          In the past, the memory available in an standard Arduino Uno (2K bytes) was too small to add high quality displays. With the arrival of the ESP32 and the Raspberry Pi Pico this has all changed. These microcontrollers have around 100 times that RAM - typically around 200K bytes. So we are integrating low-cost OLED displays into many of our CoderDojo projects!

                                                                                                                                                                          +

                                                                                                                                                                          Display Types

                                                                                                                                                                          +

                                                                                                                                                                          There are four main types of display technology that use for small microcontrollers.

                                                                                                                                                                          +
                                                                                                                                                                            +
                                                                                                                                                                          1. LED - Light Emitting Diode - these are often low-resolution but have larger area. The start with single color displays but there are also multi-color LED strips and LED matrix displays.
                                                                                                                                                                          2. +
                                                                                                                                                                          3. OLED - Organic Light Emitting Diode - small low-cost and high-contrast monochrome displays used in watches.
                                                                                                                                                                          4. +
                                                                                                                                                                          5. LCD - Liquid Crystal Display - many of these are monochrome displays that must have precise power to get consistent contrast.
                                                                                                                                                                          6. +
                                                                                                                                                                          7. TFT - Thin Film Transistor - a type of LCD that are used for larger color screens.
                                                                                                                                                                          8. +
                                                                                                                                                                          +

                                                                                                                                                                          8X8 LED Matrix Display +240x240 Full Color TFT Display +Color OLED +240X240 TFT Display

                                                                                                                                                                          +

                                                                                                                                                                          Full Color LCD TFT Display SPI HD 65K Module ST7735

                                                                                                                                                                          +

                                                                                                                                                                          Concepts

                                                                                                                                                                          +

                                                                                                                                                                          Before you begin to use these displays, there are a few things to understand to use them effectively. Based on your project needs, you can use this knowledge to find the right solution for you.

                                                                                                                                                                          +

                                                                                                                                                                          Framebuffers

                                                                                                                                                                          +

                                                                                                                                                                          A framebuffer is a copy of the display information that is resident within the RAM of the microcontroller. It must be as large as the display. For a 128X64 monochrome display this would be 128 * 64 = 8192 bits or 1,024 bytes (1K). A full color 240X240 TFT which uses 8 bits for red, green and blue would require 3 X 8 X 240 X 240 = 1,382,400 bits or 172K bytes.

                                                                                                                                                                          +

                                                                                                                                                                          Not all all displays need framebuffers. Some displays can take a series of vector drawing commands such as "draw line" and "draw text". These displays can be useful if you don't have a large amount of RAM.

                                                                                                                                                                          +

                                                                                                                                                                          Display Chip Types

                                                                                                                                                                          +

                                                                                                                                                                          There are two common versions:

                                                                                                                                                                          +
                                                                                                                                                                            +
                                                                                                                                                                          1. SSD1306 - This is the most popular and versatile chip. It can be used to drive many different types and sizes of OLEDs. The SSD1306 can be used with both the simple 4 wire I2C interface as well as the slightly faster 7 wire SPI interface. These devices have only four wires labeled VCC, GND, SDA and SCL. SDA is for data and SCL is for the clock.
                                                                                                                                                                          2. +
                                                                                                                                                                          3. SH1106 - This is less popular version and supports the 4-wire I2C interface.
                                                                                                                                                                          4. +
                                                                                                                                                                          5. ST7735 - This chip is used on larger color TFT displays.
                                                                                                                                                                          6. +
                                                                                                                                                                          7. ILI9341 - This chip is used on larger TDF displays.
                                                                                                                                                                          8. +
                                                                                                                                                                          +

                                                                                                                                                                          You can usually look on the back of the display device and see what type of check controls your OLED display.

                                                                                                                                                                          +

                                                                                                                                                                          Communication Protocols

                                                                                                                                                                          +

                                                                                                                                                                          In addition to the multiple types of displays and types of chips driving the displays, there are also two options on how you want to communicate between your microcontroller and the display.

                                                                                                                                                                          +
                                                                                                                                                                            +
                                                                                                                                                                          1. I2C - This is the most common type and only requires two wires beside power and ground. Us this as your default unless you display does not support it. The original specification of I2C had a communication speed of 100K bits per second. Many systems can be run at 400K per second.
                                                                                                                                                                          2. +
                                                                                                                                                                          3. SPI - This is a more complex interface and requires up to seven wires. Some devices only support SPI interfaces. SPI typically runs around 1M bits/second although it can go up to 10M bits/second in some applications. SPI is ideal when you want to transfer a large amount of display data to a screen quickly.
                                                                                                                                                                          4. +
                                                                                                                                                                          +

                                                                                                                                                                          Basic Draw Functions

                                                                                                                                                                          +

                                                                                                                                                                          For our beginning labs we will just do some basic drawing. We will start out with just four functions:

                                                                                                                                                                          +
                                                                                                                                                                            +
                                                                                                                                                                          1. Initialize the display framebuffer memory with the right object class initialization
                                                                                                                                                                          2. +
                                                                                                                                                                          3. Fill the framebuffer will zeros which are black pixels with the oled.fill(0)
                                                                                                                                                                          4. +
                                                                                                                                                                          5. Draw white text in the framebuffer memory with the oled.text("Hello World!", 40, 10)
                                                                                                                                                                          6. +
                                                                                                                                                                          7. Send the entire framebuffer to the display over the bus with the oled.show() function.
                                                                                                                                                                          8. +
                                                                                                                                                                          +

                                                                                                                                                                          Initializing the Framebuffer

                                                                                                                                                                          +

                                                                                                                                                                          Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled "oled" using the following line:

                                                                                                                                                                          +
                                                                                                                                                                          1
                                                                                                                                                                          +2
                                                                                                                                                                          from ssd1306 import SSD1306_I2C
                                                                                                                                                                          +oled = SSD1306_I2C(128, 64, i2c)
                                                                                                                                                                          +
                                                                                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          FunctionDescriptionParameters
                                                                                                                                                                          oled.fill(0)Fill the display with white or black0=black and 1=white
                                                                                                                                                                          oled.text("Hello",Draw textString, x (horizontal from left edge) and y (vertical from the top)Example: Draw "Hello World" 40 over and 10 down. oled.text("Hello World!", 40, 10)
                                                                                                                                                                          showShow the displaySend the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.
                                                                                                                                                                          +

                                                                                                                                                                          The full program would look like this:

                                                                                                                                                                          +
                                                                                                                                                                          1
                                                                                                                                                                          +2
                                                                                                                                                                          +3
                                                                                                                                                                          +4
                                                                                                                                                                          +5
                                                                                                                                                                          from ssd1306 import SSD1306_I2C
                                                                                                                                                                          +oled = SSD1306_I2C(128, 64, i2c)
                                                                                                                                                                          +oled.fill(0)
                                                                                                                                                                          +oled.text("Hello World!", 0, 0)
                                                                                                                                                                          +oled.show()
                                                                                                                                                                          +
                                                                                                                                                                          +

                                                                                                                                                                          This would display the following:

                                                                                                                                                                          +

                                                                                                                                                                          OLED SPI Hello World

                                                                                                                                                                          +

                                                                                                                                                                          Full list of Drawing Functions

                                                                                                                                                                          +

                                                                                                                                                                          Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class.

                                                                                                                                                                          +

                                                                                                                                                                          1
                                                                                                                                                                          +2
                                                                                                                                                                          from ssd1306 import SSD1306_I2C
                                                                                                                                                                          +print(dir(SSD1306_I2C))
                                                                                                                                                                          +
                                                                                                                                                                          +This returns the following list:

                                                                                                                                                                          +

                                                                                                                                                                          1
                                                                                                                                                                          +2
                                                                                                                                                                          +3
                                                                                                                                                                          +4
                                                                                                                                                                          +5
                                                                                                                                                                          ['__class__', '__init__', '__module__', '__name__', '__qualname__',
                                                                                                                                                                          +'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline',
                                                                                                                                                                          +'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline',
                                                                                                                                                                          +'init_display', 'write_cmd', 'show', 'poweroff', 'poweron',
                                                                                                                                                                          +'contrast', 'write_data']
                                                                                                                                                                          +
                                                                                                                                                                          +Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions.

                                                                                                                                                                          +

                                                                                                                                                                          The following are relevant for the SSD1306_I2C display.

                                                                                                                                                                          +

                                                                                                                                                                          The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state is 0=off (black) and 1=on (white).

                                                                                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          FunctionDescriptionExample
                                                                                                                                                                          blit
                                                                                                                                                                          fill(state)FillFill with black (0) or white(1)
                                                                                                                                                                          fill_rectFill a rectangle
                                                                                                                                                                          hline(x1, x2, y, state)Draw a horizontal lineDraw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1)
                                                                                                                                                                          invertinvert the display
                                                                                                                                                                          line(x1,y1,x2,y2)draw a line at any angleHorizontal oled.line(0,0, 127, 63, 1)
                                                                                                                                                                          pixelDraw a single point on the screen
                                                                                                                                                                          rectDraw an empty rectangle
                                                                                                                                                                          scrollScroll the display
                                                                                                                                                                          textWrite text at a point
                                                                                                                                                                          vlineDraw a Vertical Lineoled.vline(width - 1, 0, height - 1, 1) # right edge
                                                                                                                                                                          init_displayInitialize the display
                                                                                                                                                                          write_cmdWrite a command to the display
                                                                                                                                                                          showUpdate the display from the frame buffer
                                                                                                                                                                          poweroff
                                                                                                                                                                          poweron
                                                                                                                                                                          contrast
                                                                                                                                                                          write_data
                                                                                                                                                                          +

                                                                                                                                                                          Interfaces

                                                                                                                                                                          +

                                                                                                                                                                          I2C

                                                                                                                                                                          +

                                                                                                                                                                          Pros: Simple four wire interface

                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                          PinPurposeDescription
                                                                                                                                                                          +

                                                                                                                                                                          SPI

                                                                                                                                                                          +

                                                                                                                                                                          Example: 128X64 pixel monochrome displays

                                                                                                                                                                          +

                                                                                                                                                                          Types of Displays

                                                                                                                                                                          +

                                                                                                                                                                          Summary Table

                                                                                                                                                                          + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          Display TypeCostLinksNotes
                                                                                                                                                                          +

                                                                                                                                                                          LCD

                                                                                                                                                                          +

                                                                                                                                                                          OLED

                                                                                                                                                                          +

                                                                                                                                                                          TFT Displays

                                                                                                                                                                          +

                                                                                                                                                                          References

                                                                                                                                                                          +

                                                                                                                                                                          ST7735 Micropython Driver by Anthony Norman

                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                          +
                                                                                                                                                                          + + + +
                                                                                                                                                                          + + + +
                                                                                                                                                                          + +
                                                                                                                                                                          + + + +
                                                                                                                                                                          + + + +
                                                                                                                                                                          + + +
                                                                                                                                                                          +
                                                                                                                                                                          + + Previous + +
                                                                                                                                                                          + Boards +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + + +
                                                                                                                                                                          + + Next + +
                                                                                                                                                                          + Sourcing Parts +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                          + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/glossary/index.html b/glossary/index.html new file mode 100644 index 000000000..a5c67b364 --- /dev/null +++ b/glossary/index.html @@ -0,0 +1,1283 @@ + + + + + + + + + + + + + + + + + + + + + + + Glossary - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          + +
                                                                                                                                                                          + + + + + + +
                                                                                                                                                                          +
                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                          +
                                                                                                                                                                          + + + Glossary + + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          + + +
                                                                                                                                                                          + + +
                                                                                                                                                                          + +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          +
                                                                                                                                                                          + Initializing search +
                                                                                                                                                                          +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + +
                                                                                                                                                                            + +
                                                                                                                                                                            + + +
                                                                                                                                                                            +
                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                            + +
                                                                                                                                                                            + +
                                                                                                                                                                            + + + + + + +
                                                                                                                                                                            +
                                                                                                                                                                            + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + + +
                                                                                                                                                                            + + +
                                                                                                                                                                            + +
                                                                                                                                                                            + + +
                                                                                                                                                                            +
                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                            • + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + +
                                                                                                                                                                            + + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + +
                                                                                                                                                                            +
                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                            Glossary

                                                                                                                                                                            + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            +
                                                                                                                                                                            + + + +
                                                                                                                                                                            + + + +
                                                                                                                                                                            + +
                                                                                                                                                                            + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                            + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/docs/img/10k-pot.png b/img/10k-pot.png similarity index 100% rename from docs/img/10k-pot.png rename to img/10k-pot.png diff --git a/docs/img/4-digit-7-pins.png b/img/4-digit-7-pins.png similarity index 100% rename from docs/img/4-digit-7-pins.png rename to img/4-digit-7-pins.png diff --git a/docs/img/4-digit-7-segment-colon.png b/img/4-digit-7-segment-colon.png similarity index 100% rename from docs/img/4-digit-7-segment-colon.png rename to img/4-digit-7-segment-colon.png diff --git a/docs/img/4-digit-clock.png b/img/4-digit-clock.png similarity index 100% rename from docs/img/4-digit-clock.png rename to img/4-digit-clock.png diff --git a/docs/img/4-digit-led-display-clock.png b/img/4-digit-led-display-clock.png similarity index 100% rename from docs/img/4-digit-led-display-clock.png rename to img/4-digit-led-display-clock.png diff --git a/docs/img/4-digit-led-display.png b/img/4-digit-led-display.png similarity index 100% rename from docs/img/4-digit-led-display.png rename to img/4-digit-led-display.png diff --git a/docs/img/AM2302-Image.png b/img/AM2302-Image.png similarity index 100% rename from docs/img/AM2302-Image.png rename to img/AM2302-Image.png diff --git a/docs/img/HC-SP04P_Grove.jpg b/img/HC-SP04P_Grove.jpg similarity index 100% rename from docs/img/HC-SP04P_Grove.jpg rename to img/HC-SP04P_Grove.jpg diff --git a/docs/img/H_bridge_operating.svg.png b/img/H_bridge_operating.svg.png similarity index 100% rename from docs/img/H_bridge_operating.svg.png rename to img/H_bridge_operating.svg.png diff --git a/docs/img/IMG_0146.jpg b/img/IMG_0146.jpg similarity index 100% rename from docs/img/IMG_0146.jpg rename to img/IMG_0146.jpg diff --git a/docs/img/IMG_0151.jpg b/img/IMG_0151.jpg similarity index 100% rename from docs/img/IMG_0151.jpg rename to img/IMG_0151.jpg diff --git a/docs/img/IMG_0153.jpg b/img/IMG_0153.jpg similarity index 100% rename from docs/img/IMG_0153.jpg rename to img/IMG_0153.jpg diff --git a/docs/img/IMG_0162.jpg b/img/IMG_0162.jpg similarity index 100% rename from docs/img/IMG_0162.jpg rename to img/IMG_0162.jpg diff --git a/docs/img/IMG_0163.jpg b/img/IMG_0163.jpg similarity index 100% rename from docs/img/IMG_0163.jpg rename to img/IMG_0163.jpg diff --git a/docs/img/IMG_0164.jpg b/img/IMG_0164.jpg similarity index 100% rename from docs/img/IMG_0164.jpg rename to img/IMG_0164.jpg diff --git a/docs/img/IMG_0166.jpg b/img/IMG_0166.jpg similarity index 100% rename from docs/img/IMG_0166.jpg rename to img/IMG_0166.jpg diff --git a/docs/img/IMG_0167.jpg b/img/IMG_0167.jpg similarity index 100% rename from docs/img/IMG_0167.jpg rename to img/IMG_0167.jpg diff --git a/docs/img/IMG_0169.jpg b/img/IMG_0169.jpg similarity index 100% rename from docs/img/IMG_0169.jpg rename to img/IMG_0169.jpg diff --git a/docs/img/IMG_0170.jpg b/img/IMG_0170.jpg similarity index 100% rename from docs/img/IMG_0170.jpg rename to img/IMG_0170.jpg diff --git a/docs/img/IMG_0172.jpg b/img/IMG_0172.jpg similarity index 100% rename from docs/img/IMG_0172.jpg rename to img/IMG_0172.jpg diff --git a/docs/img/IMG_0173.jpg b/img/IMG_0173.jpg similarity index 100% rename from docs/img/IMG_0173.jpg rename to img/IMG_0173.jpg diff --git a/docs/img/IMG_0174.jpg b/img/IMG_0174.jpg similarity index 100% rename from docs/img/IMG_0174.jpg rename to img/IMG_0174.jpg diff --git a/docs/img/IMG_0175.jpg b/img/IMG_0175.jpg similarity index 100% rename from docs/img/IMG_0175.jpg rename to img/IMG_0175.jpg diff --git a/docs/img/IMG_0176.jpg b/img/IMG_0176.jpg similarity index 100% rename from docs/img/IMG_0176.jpg rename to img/IMG_0176.jpg diff --git a/docs/img/IMG_0178.jpg b/img/IMG_0178.jpg similarity index 100% rename from docs/img/IMG_0178.jpg rename to img/IMG_0178.jpg diff --git a/docs/img/IMG_0180.jpg b/img/IMG_0180.jpg similarity index 100% rename from docs/img/IMG_0180.jpg rename to img/IMG_0180.jpg diff --git a/docs/img/IMG_0181.jpg b/img/IMG_0181.jpg similarity index 100% rename from docs/img/IMG_0181.jpg rename to img/IMG_0181.jpg diff --git a/docs/img/IMG_0182.jpg b/img/IMG_0182.jpg similarity index 100% rename from docs/img/IMG_0182.jpg rename to img/IMG_0182.jpg diff --git a/docs/img/IMG_0185.jpg b/img/IMG_0185.jpg similarity index 100% rename from docs/img/IMG_0185.jpg rename to img/IMG_0185.jpg diff --git a/docs/img/IMG_0186.jpg b/img/IMG_0186.jpg similarity index 100% rename from docs/img/IMG_0186.jpg rename to img/IMG_0186.jpg diff --git a/docs/img/Incremental_directional_encoder.gif b/img/Incremental_directional_encoder.gif similarity index 100% rename from docs/img/Incremental_directional_encoder.gif rename to img/Incremental_directional_encoder.gif diff --git a/docs/img/Maker-Pi-RP2040-Modes.pptx b/img/Maker-Pi-RP2040-Modes.pptx similarity index 100% rename from docs/img/Maker-Pi-RP2040-Modes.pptx rename to img/Maker-Pi-RP2040-Modes.pptx diff --git a/docs/img/Maker-Pi-RP2040-Robot-Menu.pptx b/img/Maker-Pi-RP2040-Robot-Menu.pptx similarity index 100% rename from docs/img/Maker-Pi-RP2040-Robot-Menu.pptx rename to img/Maker-Pi-RP2040-Robot-Menu.pptx diff --git a/docs/img/Maker_Pi_RP2040-Ping.jpg b/img/Maker_Pi_RP2040-Ping.jpg similarity index 100% rename from docs/img/Maker_Pi_RP2040-Ping.jpg rename to img/Maker_Pi_RP2040-Ping.jpg diff --git a/docs/img/PCM-example.png b/img/PCM-example.png similarity index 100% rename from docs/img/PCM-example.png rename to img/PCM-example.png diff --git a/docs/img/PWM-duty-cycle.png b/img/PWM-duty-cycle.png similarity index 100% rename from docs/img/PWM-duty-cycle.png rename to img/PWM-duty-cycle.png diff --git a/docs/img/Pico-R3-Pinout.svg b/img/Pico-R3-Pinout.svg similarity index 100% rename from docs/img/Pico-R3-Pinout.svg rename to img/Pico-R3-Pinout.svg diff --git a/docs/img/R2D2-hey-you.wav b/img/R2D2-hey-you.wav similarity index 100% rename from docs/img/R2D2-hey-you.wav rename to img/R2D2-hey-you.wav diff --git a/docs/img/SPI0-pins.png b/img/SPI0-pins.png similarity index 100% rename from docs/img/SPI0-pins.png rename to img/SPI0-pins.png diff --git a/docs/img/VL53L0X_GY-530.png b/img/VL53L0X_GY-530.png similarity index 100% rename from docs/img/VL53L0X_GY-530.png rename to img/VL53L0X_GY-530.png diff --git a/docs/img/YD-RP2040-pinout.png b/img/YD-RP2040-pinout.png similarity index 100% rename from docs/img/YD-RP2040-pinout.png rename to img/YD-RP2040-pinout.png diff --git a/docs/img/add-modules-to-thonny.png b/img/add-modules-to-thonny.png similarity index 100% rename from docs/img/add-modules-to-thonny.png rename to img/add-modules-to-thonny.png diff --git a/docs/img/apple-touch-icon.png b/img/apple-touch-icon.png old mode 100755 new mode 100644 similarity index 100% rename from docs/img/apple-touch-icon.png rename to img/apple-touch-icon.png diff --git a/docs/img/banner.png b/img/banner.png similarity index 100% rename from docs/img/banner.png rename to img/banner.png diff --git a/docs/img/base-bot-connection-diagram.png b/img/base-bot-connection-diagram.png similarity index 100% rename from docs/img/base-bot-connection-diagram.png rename to img/base-bot-connection-diagram.png diff --git a/docs/img/blink-on-board-led.gif b/img/blink-on-board-led.gif similarity index 100% rename from docs/img/blink-on-board-led.gif rename to img/blink-on-board-led.gif diff --git a/docs/img/bme280-sensor.jpg b/img/bme280-sensor.jpg similarity index 100% rename from docs/img/bme280-sensor.jpg rename to img/bme280-sensor.jpg diff --git a/docs/img/boot-selection.png b/img/boot-selection.png similarity index 100% rename from docs/img/boot-selection.png rename to img/boot-selection.png diff --git a/docs/img/breadboard-regions.png b/img/breadboard-regions.png similarity index 100% rename from docs/img/breadboard-regions.png rename to img/breadboard-regions.png diff --git a/docs/img/breadboard.png b/img/breadboard.png similarity index 100% rename from docs/img/breadboard.png rename to img/breadboard.png diff --git a/docs/img/builtin-led.png b/img/builtin-led.png similarity index 100% rename from docs/img/builtin-led.png rename to img/builtin-led.png diff --git a/docs/img/button-connection-digram.png b/img/button-connection-digram.png similarity index 100% rename from docs/img/button-connection-digram.png rename to img/button-connection-digram.png diff --git a/docs/img/button-connections.png b/img/button-connections.png similarity index 100% rename from docs/img/button-connections.png rename to img/button-connections.png diff --git a/docs/img/button-press.gif b/img/button-press.gif similarity index 100% rename from docs/img/button-press.gif rename to img/button-press.gif diff --git a/docs/img/castellated-edge.png b/img/castellated-edge.png similarity index 100% rename from docs/img/castellated-edge.png rename to img/castellated-edge.png diff --git a/docs/img/circuitpython-to-micropython-chatgpt.png b/img/circuitpython-to-micropython-chatgpt.png similarity index 100% rename from docs/img/circuitpython-to-micropython-chatgpt.png rename to img/circuitpython-to-micropython-chatgpt.png diff --git a/docs/img/coderdojo-logo-32x32.png b/img/coderdojo-logo-32x32.png similarity index 100% rename from docs/img/coderdojo-logo-32x32.png rename to img/coderdojo-logo-32x32.png diff --git a/docs/img/coderdojo-logo-64x64.png b/img/coderdojo-logo-64x64.png similarity index 100% rename from docs/img/coderdojo-logo-64x64.png rename to img/coderdojo-logo-64x64.png diff --git a/docs/img/coderdojo-logo-dark-bg-light-text.png b/img/coderdojo-logo-dark-bg-light-text.png similarity index 100% rename from docs/img/coderdojo-logo-dark-bg-light-text.png rename to img/coderdojo-logo-dark-bg-light-text.png diff --git a/docs/img/coderdojo-logo.jpg b/img/coderdojo-logo.jpg similarity index 100% rename from docs/img/coderdojo-logo.jpg rename to img/coderdojo-logo.jpg diff --git a/docs/img/coderdojo-logo.png b/img/coderdojo-logo.png similarity index 100% rename from docs/img/coderdojo-logo.png rename to img/coderdojo-logo.png diff --git a/docs/img/coderdojo-oled.gif b/img/coderdojo-oled.gif similarity index 100% rename from docs/img/coderdojo-oled.gif rename to img/coderdojo-oled.gif diff --git a/docs/img/color-oled.jpg b/img/color-oled.jpg similarity index 100% rename from docs/img/color-oled.jpg rename to img/color-oled.jpg diff --git a/docs/img/compass-hmc5883l-on-breadboard.jpg b/img/compass-hmc5883l-on-breadboard.jpg similarity index 100% rename from docs/img/compass-hmc5883l-on-breadboard.jpg rename to img/compass-hmc5883l-on-breadboard.jpg diff --git a/docs/img/cost-per-kilobyte-ram.png b/img/cost-per-kilobyte-ram.png similarity index 100% rename from docs/img/cost-per-kilobyte-ram.png rename to img/cost-per-kilobyte-ram.png diff --git a/docs/img/cozmo-faces.png b/img/cozmo-faces.png similarity index 100% rename from docs/img/cozmo-faces.png rename to img/cozmo-faces.png diff --git a/docs/img/craft-pumpkin.jpg b/img/craft-pumpkin.jpg similarity index 100% rename from docs/img/craft-pumpkin.jpg rename to img/craft-pumpkin.jpg diff --git a/docs/img/cylon-pumpkin.gif b/img/cylon-pumpkin.gif similarity index 100% rename from docs/img/cylon-pumpkin.gif rename to img/cylon-pumpkin.gif diff --git a/docs/img/cytron-display-harness.jpg b/img/cytron-display-harness.jpg similarity index 100% rename from docs/img/cytron-display-harness.jpg rename to img/cytron-display-harness.jpg diff --git a/docs/img/cytron-nano-rp2040-pinout.png b/img/cytron-nano-rp2040-pinout.png similarity index 100% rename from docs/img/cytron-nano-rp2040-pinout.png rename to img/cytron-nano-rp2040-pinout.png diff --git a/docs/img/cytron-ping-kit-parts.jpg b/img/cytron-ping-kit-parts.jpg similarity index 100% rename from docs/img/cytron-ping-kit-parts.jpg rename to img/cytron-ping-kit-parts.jpg diff --git a/docs/img/dc-motor.png b/img/dc-motor.png similarity index 100% rename from docs/img/dc-motor.png rename to img/dc-motor.png diff --git a/docs/img/debounce-transition.png b/img/debounce-transition.png similarity index 100% rename from docs/img/debounce-transition.png rename to img/debounce-transition.png diff --git a/docs/img/dupont-ribbon-cable.png b/img/dupont-ribbon-cable.png similarity index 100% rename from docs/img/dupont-ribbon-cable.png rename to img/dupont-ribbon-cable.png diff --git a/docs/img/duty-cycle.png b/img/duty-cycle.png similarity index 100% rename from docs/img/duty-cycle.png rename to img/duty-cycle.png diff --git a/docs/img/eight-key-piano.jpg b/img/eight-key-piano.jpg similarity index 100% rename from docs/img/eight-key-piano.jpg rename to img/eight-key-piano.jpg diff --git a/docs/img/ekg-sample.png b/img/ekg-sample.png similarity index 100% rename from docs/img/ekg-sample.png rename to img/ekg-sample.png diff --git a/docs/img/esp32-config-serial-port.png b/img/esp32-config-serial-port.png similarity index 100% rename from docs/img/esp32-config-serial-port.png rename to img/esp32-config-serial-port.png diff --git a/docs/img/favicon-16x16.png b/img/favicon-16x16.png old mode 100755 new mode 100644 similarity index 100% rename from docs/img/favicon-16x16.png rename to img/favicon-16x16.png diff --git a/docs/img/favicon-32x32.png b/img/favicon-32x32.png old mode 100755 new mode 100644 similarity index 100% rename from docs/img/favicon-32x32.png rename to img/favicon-32x32.png diff --git a/docs/img/favicon.ico b/img/favicon.ico old mode 100755 new mode 100644 similarity index 100% rename from docs/img/favicon.ico rename to img/favicon.ico diff --git a/docs/img/figures.pptx b/img/figures.pptx similarity index 100% rename from docs/img/figures.pptx rename to img/figures.pptx diff --git a/docs/img/gesture-spectral-response.png b/img/gesture-spectral-response.png similarity index 100% rename from docs/img/gesture-spectral-response.png rename to img/gesture-spectral-response.png diff --git a/docs/img/h-bridge.png b/img/h-bridge.png similarity index 100% rename from docs/img/h-bridge.png rename to img/h-bridge.png diff --git a/docs/img/hackday-photo.jpg b/img/hackday-photo.jpg similarity index 100% rename from docs/img/hackday-photo.jpg rename to img/hackday-photo.jpg diff --git a/docs/img/harness-1.jpg b/img/harness-1.jpg similarity index 100% rename from docs/img/harness-1.jpg rename to img/harness-1.jpg diff --git a/docs/img/harness-2.jpg b/img/harness-2.jpg similarity index 100% rename from docs/img/harness-2.jpg rename to img/harness-2.jpg diff --git a/docs/img/harness-3.jpg b/img/harness-3.jpg similarity index 100% rename from docs/img/harness-3.jpg rename to img/harness-3.jpg diff --git a/docs/img/harness-4.jpg b/img/harness-4.jpg similarity index 100% rename from docs/img/harness-4.jpg rename to img/harness-4.jpg diff --git a/docs/img/harness-5.png b/img/harness-5.png similarity index 100% rename from docs/img/harness-5.png rename to img/harness-5.png diff --git a/docs/img/i2c-display-connections.png b/img/i2c-display-connections.png similarity index 100% rename from docs/img/i2c-display-connections.png rename to img/i2c-display-connections.png diff --git a/docs/img/ili9341-demo.png b/img/ili9341-demo.png similarity index 100% rename from docs/img/ili9341-demo.png rename to img/ili9341-demo.png diff --git a/docs/img/ili9341-listing.png b/img/ili9341-listing.png similarity index 100% rename from docs/img/ili9341-listing.png rename to img/ili9341-listing.png diff --git a/docs/img/install-ssd1306.png b/img/install-ssd1306.png similarity index 100% rename from docs/img/install-ssd1306.png rename to img/install-ssd1306.png diff --git a/docs/img/ir-sensor.jpeg b/img/ir-sensor.jpeg similarity index 100% rename from docs/img/ir-sensor.jpeg rename to img/ir-sensor.jpeg diff --git a/docs/img/ir-sensors.png b/img/ir-sensors.png similarity index 100% rename from docs/img/ir-sensors.png rename to img/ir-sensors.png diff --git a/docs/img/kids-in-robot-corral.jpg b/img/kids-in-robot-corral.jpg similarity index 100% rename from docs/img/kids-in-robot-corral.jpg rename to img/kids-in-robot-corral.jpg diff --git a/docs/img/larson-scanner.gif b/img/larson-scanner.gif similarity index 100% rename from docs/img/larson-scanner.gif rename to img/larson-scanner.gif diff --git a/docs/img/lcd-1602.jpg b/img/lcd-1602.jpg similarity index 100% rename from docs/img/lcd-1602.jpg rename to img/lcd-1602.jpg diff --git a/docs/img/lcd-uc1609-spi.jpg b/img/lcd-uc1609-spi.jpg similarity index 100% rename from docs/img/lcd-uc1609-spi.jpg rename to img/lcd-uc1609-spi.jpg diff --git a/docs/img/led-10-segment-circuit.png b/img/led-10-segment-circuit.png similarity index 100% rename from docs/img/led-10-segment-circuit.png rename to img/led-10-segment-circuit.png diff --git a/docs/img/led-10-segment-package-circuit.png b/img/led-10-segment-package-circuit.png similarity index 100% rename from docs/img/led-10-segment-package-circuit.png rename to img/led-10-segment-package-circuit.png diff --git a/docs/img/led-bar-graph-10-segments.png b/img/led-bar-graph-10-segments.png similarity index 100% rename from docs/img/led-bar-graph-10-segments.png rename to img/led-bar-graph-10-segments.png diff --git a/docs/img/led-matrix-display-back.png b/img/led-matrix-display-back.png similarity index 100% rename from docs/img/led-matrix-display-back.png rename to img/led-matrix-display-back.png diff --git a/docs/img/led-matrix-display.png b/img/led-matrix-display.png similarity index 100% rename from docs/img/led-matrix-display.png rename to img/led-matrix-display.png diff --git a/docs/img/led-strip-connections.png b/img/led-strip-connections.png similarity index 100% rename from docs/img/led-strip-connections.png rename to img/led-strip-connections.png diff --git a/docs/img/led-strip-ebay-form.png b/img/led-strip-ebay-form.png similarity index 100% rename from docs/img/led-strip-ebay-form.png rename to img/led-strip-ebay-form.png diff --git a/docs/img/led-strip-pico-connections.png b/img/led-strip-pico-connections.png similarity index 100% rename from docs/img/led-strip-pico-connections.png rename to img/led-strip-pico-connections.png diff --git a/docs/img/logic-analysis-i2c.png b/img/logic-analysis-i2c.png similarity index 100% rename from docs/img/logic-analysis-i2c.png rename to img/logic-analysis-i2c.png diff --git a/docs/img/mac-allow-accessories-to-connect-always.png b/img/mac-allow-accessories-to-connect-always.png similarity index 100% rename from docs/img/mac-allow-accessories-to-connect-always.png rename to img/mac-allow-accessories-to-connect-always.png diff --git a/docs/img/magnetic-buzzer.png b/img/magnetic-buzzer.png similarity index 100% rename from docs/img/magnetic-buzzer.png rename to img/magnetic-buzzer.png diff --git a/docs/img/maker-pi-fp2040-schematic.pdf b/img/maker-pi-fp2040-schematic.pdf similarity index 100% rename from docs/img/maker-pi-fp2040-schematic.pdf rename to img/maker-pi-fp2040-schematic.pdf diff --git a/docs/img/maker-pi-rp2040-bottom-view.jpeg b/img/maker-pi-rp2040-bottom-view.jpeg similarity index 100% rename from docs/img/maker-pi-rp2040-bottom-view.jpeg rename to img/maker-pi-rp2040-bottom-view.jpeg diff --git a/docs/img/maker-pi-rp2040-kit.jpeg b/img/maker-pi-rp2040-kit.jpeg similarity index 100% rename from docs/img/maker-pi-rp2040-kit.jpeg rename to img/maker-pi-rp2040-kit.jpeg diff --git a/docs/img/maker-pi-rp2040-labels.png b/img/maker-pi-rp2040-labels.png similarity index 100% rename from docs/img/maker-pi-rp2040-labels.png rename to img/maker-pi-rp2040-labels.png diff --git a/docs/img/maker-pi-rp2040-leds.gif b/img/maker-pi-rp2040-leds.gif similarity index 100% rename from docs/img/maker-pi-rp2040-leds.gif rename to img/maker-pi-rp2040-leds.gif diff --git a/docs/img/maker-pi-rp2040-motor-connections.jpg b/img/maker-pi-rp2040-motor-connections.jpg similarity index 100% rename from docs/img/maker-pi-rp2040-motor-connections.jpg rename to img/maker-pi-rp2040-motor-connections.jpg diff --git a/docs/img/maker-pi-rp2040-motor-driver.jpg b/img/maker-pi-rp2040-motor-driver.jpg similarity index 100% rename from docs/img/maker-pi-rp2040-motor-driver.jpg rename to img/maker-pi-rp2040-motor-driver.jpg diff --git a/docs/img/maker-pi-rp2040-robot-bottom.jpg b/img/maker-pi-rp2040-robot-bottom.jpg similarity index 100% rename from docs/img/maker-pi-rp2040-robot-bottom.jpg rename to img/maker-pi-rp2040-robot-bottom.jpg diff --git a/docs/img/maker-pi-rp2040-robot.jpg b/img/maker-pi-rp2040-robot.jpg similarity index 100% rename from docs/img/maker-pi-rp2040-robot.jpg rename to img/maker-pi-rp2040-robot.jpg diff --git a/docs/img/maker-pi-rp2040-tof-robot.jpg b/img/maker-pi-rp2040-tof-robot.jpg similarity index 100% rename from docs/img/maker-pi-rp2040-tof-robot.jpg rename to img/maker-pi-rp2040-tof-robot.jpg diff --git a/docs/img/maker-pi-rp2040-top-view.png b/img/maker-pi-rp2040-top-view.png similarity index 100% rename from docs/img/maker-pi-rp2040-top-view.png rename to img/maker-pi-rp2040-top-view.png diff --git a/docs/img/matrix-mapping-function.png b/img/matrix-mapping-function.png similarity index 100% rename from docs/img/matrix-mapping-function.png rename to img/matrix-mapping-function.png diff --git a/docs/img/max7219-8x8-led.png b/img/max7219-8x8-led.png similarity index 100% rename from docs/img/max7219-8x8-led.png rename to img/max7219-8x8-led.png diff --git a/docs/img/memory-heap-stack.png b/img/memory-heap-stack.png similarity index 100% rename from docs/img/memory-heap-stack.png rename to img/memory-heap-stack.png diff --git a/docs/img/microcontroller-arch-example.png b/img/microcontroller-arch-example.png similarity index 100% rename from docs/img/microcontroller-arch-example.png rename to img/microcontroller-arch-example.png diff --git a/docs/img/microcontroller-arch.png b/img/microcontroller-arch.png similarity index 100% rename from docs/img/microcontroller-arch.png rename to img/microcontroller-arch.png diff --git a/docs/img/microcontrollers.jpg b/img/microcontrollers.jpg similarity index 100% rename from docs/img/microcontrollers.jpg rename to img/microcontrollers.jpg diff --git a/docs/img/micropython-512.png b/img/micropython-512.png old mode 100755 new mode 100644 similarity index 100% rename from docs/img/micropython-512.png rename to img/micropython-512.png diff --git a/docs/img/micropython-badge.png b/img/micropython-badge.png similarity index 100% rename from docs/img/micropython-badge.png rename to img/micropython-badge.png diff --git a/docs/img/micropython-esp32.png b/img/micropython-esp32.png similarity index 100% rename from docs/img/micropython-esp32.png rename to img/micropython-esp32.png diff --git a/docs/img/micropython-logo-192x192.png b/img/micropython-logo-192x192.png old mode 100755 new mode 100644 similarity index 100% rename from docs/img/micropython-logo-192x192.png rename to img/micropython-logo-192x192.png diff --git a/docs/img/micropython-logo-old.png b/img/micropython-logo-old.png similarity index 100% rename from docs/img/micropython-logo-old.png rename to img/micropython-logo-old.png diff --git a/docs/img/micropython-logo.png b/img/micropython-logo.png similarity index 100% rename from docs/img/micropython-logo.png rename to img/micropython-logo.png diff --git a/docs/img/microswitch-bot-1.jpg b/img/microswitch-bot-1.jpg similarity index 100% rename from docs/img/microswitch-bot-1.jpg rename to img/microswitch-bot-1.jpg diff --git a/docs/img/microswitch-bot-2.jpg b/img/microswitch-bot-2.jpg similarity index 100% rename from docs/img/microswitch-bot-2.jpg rename to img/microswitch-bot-2.jpg diff --git a/docs/img/microswitch-bot-3.jpg b/img/microswitch-bot-3.jpg similarity index 100% rename from docs/img/microswitch-bot-3.jpg rename to img/microswitch-bot-3.jpg diff --git a/docs/img/mode-cycle-diagram.png b/img/mode-cycle-diagram.png similarity index 100% rename from docs/img/mode-cycle-diagram.png rename to img/mode-cycle-diagram.png diff --git a/docs/img/momentary-button.jpg b/img/momentary-button.jpg similarity index 100% rename from docs/img/momentary-button.jpg rename to img/momentary-button.jpg diff --git a/docs/img/momentary-switch-button.png b/img/momentary-switch-button.png similarity index 100% rename from docs/img/momentary-switch-button.png rename to img/momentary-switch-button.png diff --git a/docs/img/motor-circuit.png b/img/motor-circuit.png similarity index 100% rename from docs/img/motor-circuit.png rename to img/motor-circuit.png diff --git a/docs/img/motor-driver-voltage-curve.png b/img/motor-driver-voltage-curve.png similarity index 100% rename from docs/img/motor-driver-voltage-curve.png rename to img/motor-driver-voltage-curve.png diff --git a/docs/img/neopixel-demo.gif b/img/neopixel-demo.gif similarity index 100% rename from docs/img/neopixel-demo.gif rename to img/neopixel-demo.gif diff --git a/docs/img/neopixel-kit.jpg b/img/neopixel-kit.jpg similarity index 100% rename from docs/img/neopixel-kit.jpg rename to img/neopixel-kit.jpg diff --git a/docs/img/neopixel-matrix.gif b/img/neopixel-matrix.gif similarity index 100% rename from docs/img/neopixel-matrix.gif rename to img/neopixel-matrix.gif diff --git a/docs/img/neopixel-red-green-blue.gif b/img/neopixel-red-green-blue.gif similarity index 100% rename from docs/img/neopixel-red-green-blue.gif rename to img/neopixel-red-green-blue.gif diff --git a/docs/img/neopixel-types.jpg b/img/neopixel-types.jpg similarity index 100% rename from docs/img/neopixel-types.jpg rename to img/neopixel-types.jpg diff --git a/docs/img/network-forecast-thonny-plot.png b/img/network-forecast-thonny-plot.png similarity index 100% rename from docs/img/network-forecast-thonny-plot.png rename to img/network-forecast-thonny-plot.png diff --git a/docs/img/network-weather-display.jpg b/img/network-weather-display.jpg similarity index 100% rename from docs/img/network-weather-display.jpg rename to img/network-weather-display.jpg diff --git a/docs/img/network-weather-results.png b/img/network-weather-results.png similarity index 100% rename from docs/img/network-weather-results.png rename to img/network-weather-results.png diff --git a/docs/img/oled-back-connections.png b/img/oled-back-connections.png similarity index 100% rename from docs/img/oled-back-connections.png rename to img/oled-back-connections.png diff --git a/docs/img/oled-hello-world.png b/img/oled-hello-world.png similarity index 100% rename from docs/img/oled-hello-world.png rename to img/oled-hello-world.png diff --git a/docs/img/oled-i2c-clock-data.png b/img/oled-i2c-clock-data.png similarity index 100% rename from docs/img/oled-i2c-clock-data.png rename to img/oled-i2c-clock-data.png diff --git a/docs/img/oled-i2c.png b/img/oled-i2c.png similarity index 100% rename from docs/img/oled-i2c.png rename to img/oled-i2c.png diff --git a/docs/img/oled-ping-circuit.png b/img/oled-ping-circuit.png similarity index 100% rename from docs/img/oled-ping-circuit.png rename to img/oled-ping-circuit.png diff --git a/docs/img/oled-pot-i2c-large.gif b/img/oled-pot-i2c-large.gif similarity index 100% rename from docs/img/oled-pot-i2c-large.gif rename to img/oled-pot-i2c-large.gif diff --git a/docs/img/oled-pot-lab-pins.png b/img/oled-pot-lab-pins.png similarity index 100% rename from docs/img/oled-pot-lab-pins.png rename to img/oled-pot-lab-pins.png diff --git a/docs/img/oled-spi-connections.png b/img/oled-spi-connections.png similarity index 100% rename from docs/img/oled-spi-connections.png rename to img/oled-spi-connections.png diff --git a/docs/img/oled-spi-to-i2c-changes.png b/img/oled-spi-to-i2c-changes.png similarity index 100% rename from docs/img/oled-spi-to-i2c-changes.png rename to img/oled-spi-to-i2c-changes.png diff --git a/docs/img/oled-ssd1306-spi-connections.png b/img/oled-ssd1306-spi-connections.png similarity index 100% rename from docs/img/oled-ssd1306-spi-connections.png rename to img/oled-ssd1306-spi-connections.png diff --git a/docs/img/parts/ir-distance-sensor.png b/img/parts/ir-distance-sensor.png similarity index 100% rename from docs/img/parts/ir-distance-sensor.png rename to img/parts/ir-distance-sensor.png diff --git a/docs/img/parts/motor-driver.png b/img/parts/motor-driver.png similarity index 100% rename from docs/img/parts/motor-driver.png rename to img/parts/motor-driver.png diff --git a/docs/img/parts/ping-sensor.png b/img/parts/ping-sensor.png similarity index 100% rename from docs/img/parts/ping-sensor.png rename to img/parts/ping-sensor.png diff --git a/docs/img/parts/time-of-flight-side.png b/img/parts/time-of-flight-side.png similarity index 100% rename from docs/img/parts/time-of-flight-side.png rename to img/parts/time-of-flight-side.png diff --git a/docs/img/parts/tof-sensor-GYUN530K.jpg b/img/parts/tof-sensor-GYUN530K.jpg similarity index 100% rename from docs/img/parts/tof-sensor-GYUN530K.jpg rename to img/parts/tof-sensor-GYUN530K.jpg diff --git a/docs/img/pattern1.jpg b/img/pattern1.jpg similarity index 100% rename from docs/img/pattern1.jpg rename to img/pattern1.jpg diff --git a/docs/img/pattern2.jpg b/img/pattern2.jpg similarity index 100% rename from docs/img/pattern2.jpg rename to img/pattern2.jpg diff --git a/docs/img/pattern3.jpg b/img/pattern3.jpg similarity index 100% rename from docs/img/pattern3.jpg rename to img/pattern3.jpg diff --git a/docs/img/pattern4.jpg b/img/pattern4.jpg similarity index 100% rename from docs/img/pattern4.jpg rename to img/pattern4.jpg diff --git a/docs/img/pattern5.jpg b/img/pattern5.jpg similarity index 100% rename from docs/img/pattern5.jpg rename to img/pattern5.jpg diff --git a/docs/img/pattern6.jpg b/img/pattern6.jpg similarity index 100% rename from docs/img/pattern6.jpg rename to img/pattern6.jpg diff --git a/docs/img/photoresistor-circuit.png b/img/photoresistor-circuit.png similarity index 100% rename from docs/img/photoresistor-circuit.png rename to img/photoresistor-circuit.png diff --git a/docs/img/photoresistor-on-breadboard.jpg b/img/photoresistor-on-breadboard.jpg similarity index 100% rename from docs/img/photoresistor-on-breadboard.jpg rename to img/photoresistor-on-breadboard.jpg diff --git a/docs/img/physical-computing.png b/img/physical-computing.png similarity index 100% rename from docs/img/physical-computing.png rename to img/physical-computing.png diff --git a/docs/img/pi-pico-pinout.png b/img/pi-pico-pinout.png similarity index 100% rename from docs/img/pi-pico-pinout.png rename to img/pi-pico-pinout.png diff --git a/docs/img/pico-blink.mov b/img/pico-blink.mov similarity index 100% rename from docs/img/pico-blink.mov rename to img/pico-blink.mov diff --git a/docs/img/pico-bot-breadboard.jpg b/img/pico-bot-breadboard.jpg similarity index 100% rename from docs/img/pico-bot-breadboard.jpg rename to img/pico-bot-breadboard.jpg diff --git a/docs/img/pico-bot-parts-list.png b/img/pico-bot-parts-list.png similarity index 100% rename from docs/img/pico-bot-parts-list.png rename to img/pico-bot-parts-list.png diff --git a/docs/img/pico-bot-underside.jpg b/img/pico-bot-underside.jpg similarity index 100% rename from docs/img/pico-bot-underside.jpg rename to img/pico-bot-underside.jpg diff --git a/docs/img/pico-bot.jpg b/img/pico-bot.jpg similarity index 100% rename from docs/img/pico-bot.jpg rename to img/pico-bot.jpg diff --git a/docs/img/pico-h-microcenter.png b/img/pico-h-microcenter.png similarity index 100% rename from docs/img/pico-h-microcenter.png rename to img/pico-h-microcenter.png diff --git a/docs/img/pico-on-breadboard-annotated.png b/img/pico-on-breadboard-annotated.png similarity index 100% rename from docs/img/pico-on-breadboard-annotated.png rename to img/pico-on-breadboard-annotated.png diff --git a/docs/img/pico-on-breadboard-with-gnd-markers.jpg b/img/pico-on-breadboard-with-gnd-markers.jpg similarity index 100% rename from docs/img/pico-on-breadboard-with-gnd-markers.jpg rename to img/pico-on-breadboard-with-gnd-markers.jpg diff --git a/docs/img/pico-on-breadboard.png b/img/pico-on-breadboard.png similarity index 100% rename from docs/img/pico-on-breadboard.png rename to img/pico-on-breadboard.png diff --git a/docs/img/pico-pinout-full.png b/img/pico-pinout-full.png similarity index 100% rename from docs/img/pico-pinout-full.png rename to img/pico-pinout-full.png diff --git a/docs/img/pico-pins.png b/img/pico-pins.png similarity index 100% rename from docs/img/pico-pins.png rename to img/pico-pins.png diff --git a/docs/img/pico-power-pins.png b/img/pico-power-pins.png similarity index 100% rename from docs/img/pico-power-pins.png rename to img/pico-power-pins.png diff --git a/docs/img/pico-price.png b/img/pico-price.png similarity index 100% rename from docs/img/pico-price.png rename to img/pico-price.png diff --git a/docs/img/pico-v2.png b/img/pico-v2.png similarity index 100% rename from docs/img/pico-v2.png rename to img/pico-v2.png diff --git a/docs/img/pico-w-web-page.png b/img/pico-w-web-page.png similarity index 100% rename from docs/img/pico-w-web-page.png rename to img/pico-w-web-page.png diff --git a/docs/img/pico-w.png b/img/pico-w.png similarity index 100% rename from docs/img/pico-w.png rename to img/pico-w.png diff --git a/docs/img/piezo-buzzer.png b/img/piezo-buzzer.png similarity index 100% rename from docs/img/piezo-buzzer.png rename to img/piezo-buzzer.png diff --git a/docs/img/ping-servo-meter-bot.jpg b/img/ping-servo-meter-bot.jpg similarity index 100% rename from docs/img/ping-servo-meter-bot.jpg rename to img/ping-servo-meter-bot.jpg diff --git a/docs/img/pot-blink-speed.jpg b/img/pot-blink-speed.jpg similarity index 100% rename from docs/img/pot-blink-speed.jpg rename to img/pot-blink-speed.jpg diff --git a/docs/img/pot-circuit-diagram.png b/img/pot-circuit-diagram.png similarity index 100% rename from docs/img/pot-circuit-diagram.png rename to img/pot-circuit-diagram.png diff --git a/docs/img/pot-oled.gif b/img/pot-oled.gif similarity index 100% rename from docs/img/pot-oled.gif rename to img/pot-oled.gif diff --git a/docs/img/rainbow-bot-connecting-strips.jpg b/img/rainbow-bot-connecting-strips.jpg similarity index 100% rename from docs/img/rainbow-bot-connecting-strips.jpg rename to img/rainbow-bot-connecting-strips.jpg diff --git a/docs/img/rainbow-bot-cover.jpg b/img/rainbow-bot-cover.jpg similarity index 100% rename from docs/img/rainbow-bot-cover.jpg rename to img/rainbow-bot-cover.jpg diff --git a/docs/img/rainbow-bot-standoff.jpg b/img/rainbow-bot-standoff.jpg similarity index 100% rename from docs/img/rainbow-bot-standoff.jpg rename to img/rainbow-bot-standoff.jpg diff --git a/docs/img/rainbow-bot-top-view.jpg b/img/rainbow-bot-top-view.jpg similarity index 100% rename from docs/img/rainbow-bot-top-view.jpg rename to img/rainbow-bot-top-view.jpg diff --git a/docs/img/rainbow-bot-underside.jpg b/img/rainbow-bot-underside.jpg similarity index 100% rename from docs/img/rainbow-bot-underside.jpg rename to img/rainbow-bot-underside.jpg diff --git a/docs/img/rainbow-bot.gif b/img/rainbow-bot.gif similarity index 100% rename from docs/img/rainbow-bot.gif rename to img/rainbow-bot.gif diff --git a/docs/img/raspberry-pi-pico.png b/img/raspberry-pi-pico.png similarity index 100% rename from docs/img/raspberry-pi-pico.png rename to img/raspberry-pi-pico.png diff --git a/docs/img/red-led-move-up.gif b/img/red-led-move-up.gif similarity index 100% rename from docs/img/red-led-move-up.gif rename to img/red-led-move-up.gif diff --git a/docs/img/robot-badge.png.png b/img/robot-badge.png.png similarity index 100% rename from docs/img/robot-badge.png.png rename to img/robot-badge.png.png diff --git a/docs/img/robot-journey-map.png b/img/robot-journey-map.png similarity index 100% rename from docs/img/robot-journey-map.png rename to img/robot-journey-map.png diff --git a/docs/img/robot-oled-four-colors.jpg b/img/robot-oled-four-colors.jpg similarity index 100% rename from docs/img/robot-oled-four-colors.jpg rename to img/robot-oled-four-colors.jpg diff --git a/docs/img/rotary-encoder-circuit.png b/img/rotary-encoder-circuit.png similarity index 100% rename from docs/img/rotary-encoder-circuit.png rename to img/rotary-encoder-circuit.png diff --git a/docs/img/rotary-encoder.png b/img/rotary-encoder.png similarity index 100% rename from docs/img/rotary-encoder.png rename to img/rotary-encoder.png diff --git a/docs/img/rotery-encoder-up-and-down.png b/img/rotery-encoder-up-and-down.png similarity index 100% rename from docs/img/rotery-encoder-up-and-down.png rename to img/rotery-encoder-up-and-down.png diff --git a/docs/img/rtc-ds3231-ebay.png b/img/rtc-ds3231-ebay.png similarity index 100% rename from docs/img/rtc-ds3231-ebay.png rename to img/rtc-ds3231-ebay.png diff --git a/docs/img/save-local-pico.png b/img/save-local-pico.png similarity index 100% rename from docs/img/save-local-pico.png rename to img/save-local-pico.png diff --git a/docs/img/solderless-mini-breadboard.jpg b/img/solderless-mini-breadboard.jpg similarity index 100% rename from docs/img/solderless-mini-breadboard.jpg rename to img/solderless-mini-breadboard.jpg diff --git a/docs/img/spi-connectins.png b/img/spi-connectins.png similarity index 100% rename from docs/img/spi-connectins.png rename to img/spi-connectins.png diff --git a/docs/img/spi-logic-analyser-clock-gap.png b/img/spi-logic-analyser-clock-gap.png similarity index 100% rename from docs/img/spi-logic-analyser-clock-gap.png rename to img/spi-logic-analyser-clock-gap.png diff --git a/docs/img/spi-logic-analyser-clock-period.png b/img/spi-logic-analyser-clock-period.png similarity index 100% rename from docs/img/spi-logic-analyser-clock-period.png rename to img/spi-logic-analyser-clock-period.png diff --git a/docs/img/spi-logic-analyser-data-clock-reset.png b/img/spi-logic-analyser-data-clock-reset.png similarity index 100% rename from docs/img/spi-logic-analyser-data-clock-reset.png rename to img/spi-logic-analyser-data-clock-reset.png diff --git a/docs/img/spi-logic-analyser-dc-cs-2.png b/img/spi-logic-analyser-dc-cs-2.png similarity index 100% rename from docs/img/spi-logic-analyser-dc-cs-2.png rename to img/spi-logic-analyser-dc-cs-2.png diff --git a/docs/img/spi-logic-analyser-dc-cs.png b/img/spi-logic-analyser-dc-cs.png similarity index 100% rename from docs/img/spi-logic-analyser-dc-cs.png rename to img/spi-logic-analyser-dc-cs.png diff --git a/docs/img/spi-logic-analyser-full.png b/img/spi-logic-analyser-full.png similarity index 100% rename from docs/img/spi-logic-analyser-full.png rename to img/spi-logic-analyser-full.png diff --git a/docs/img/spi-logic-analyser-pico.png b/img/spi-logic-analyser-pico.png similarity index 100% rename from docs/img/spi-logic-analyser-pico.png rename to img/spi-logic-analyser-pico.png diff --git a/docs/img/spi-logic-analyser-settings.png b/img/spi-logic-analyser-settings.png similarity index 100% rename from docs/img/spi-logic-analyser-settings.png rename to img/spi-logic-analyser-settings.png diff --git a/docs/img/spi-logic-analyser.png b/img/spi-logic-analyser.png similarity index 100% rename from docs/img/spi-logic-analyser.png rename to img/spi-logic-analyser.png diff --git a/docs/img/ssd1306-spi-timing-diagram.png b/img/ssd1306-spi-timing-diagram.png similarity index 100% rename from docs/img/ssd1306-spi-timing-diagram.png rename to img/ssd1306-spi-timing-diagram.png diff --git a/docs/img/st7789-lcd-back.png b/img/st7789-lcd-back.png similarity index 100% rename from docs/img/st7789-lcd-back.png rename to img/st7789-lcd-back.png diff --git a/docs/img/st7789-lcd-hello.jpeg b/img/st7789-lcd-hello.jpeg similarity index 100% rename from docs/img/st7789-lcd-hello.jpeg rename to img/st7789-lcd-hello.jpeg diff --git a/docs/img/st7789-lcd-timing.png b/img/st7789-lcd-timing.png similarity index 100% rename from docs/img/st7789-lcd-timing.png rename to img/st7789-lcd-timing.png diff --git a/docs/img/st7789-lcd.png b/img/st7789-lcd.png similarity index 100% rename from docs/img/st7789-lcd.png rename to img/st7789-lcd.png diff --git a/docs/img/stepper-motor.png b/img/stepper-motor.png similarity index 100% rename from docs/img/stepper-motor.png rename to img/stepper-motor.png diff --git a/docs/img/tft-color-display.png b/img/tft-color-display.png similarity index 100% rename from docs/img/tft-color-display.png rename to img/tft-color-display.png diff --git a/docs/img/thonny-add-ssd1306.png b/img/thonny-add-ssd1306.png similarity index 100% rename from docs/img/thonny-add-ssd1306.png rename to img/thonny-add-ssd1306.png diff --git a/docs/img/thonny-install-micropython-runtime.png b/img/thonny-install-micropython-runtime.png similarity index 100% rename from docs/img/thonny-install-micropython-runtime.png rename to img/thonny-install-micropython-runtime.png diff --git a/docs/img/thonny-install-module.png b/img/thonny-install-module.png similarity index 100% rename from docs/img/thonny-install-module.png rename to img/thonny-install-module.png diff --git a/docs/img/thonny-micropython-firmware-update.png b/img/thonny-micropython-firmware-update.png similarity index 100% rename from docs/img/thonny-micropython-firmware-update.png rename to img/thonny-micropython-firmware-update.png diff --git a/docs/img/thonny-micropython-pico.png b/img/thonny-micropython-pico.png similarity index 100% rename from docs/img/thonny-micropython-pico.png rename to img/thonny-micropython-pico.png diff --git a/docs/img/thonny-upip-details.png b/img/thonny-upip-details.png similarity index 100% rename from docs/img/thonny-upip-details.png rename to img/thonny-upip-details.png diff --git a/docs/img/thonny-upip.png b/img/thonny-upip.png similarity index 100% rename from docs/img/thonny-upip.png rename to img/thonny-upip.png diff --git a/docs/img/time-of-flight-angle.pptx b/img/time-of-flight-angle.pptx similarity index 100% rename from docs/img/time-of-flight-angle.pptx rename to img/time-of-flight-angle.pptx diff --git a/docs/img/time-of-flight-mount-2.jpg b/img/time-of-flight-mount-2.jpg similarity index 100% rename from docs/img/time-of-flight-mount-2.jpg rename to img/time-of-flight-mount-2.jpg diff --git a/docs/img/time-of-flight-mount.jpg b/img/time-of-flight-mount.jpg similarity index 100% rename from docs/img/time-of-flight-mount.jpg rename to img/time-of-flight-mount.jpg diff --git a/docs/img/time-of-flight-sensor-mount-rear.png b/img/time-of-flight-sensor-mount-rear.png similarity index 100% rename from docs/img/time-of-flight-sensor-mount-rear.png rename to img/time-of-flight-sensor-mount-rear.png diff --git a/docs/img/time-of-flight-sensor-mounted.jpg b/img/time-of-flight-sensor-mounted.jpg similarity index 100% rename from docs/img/time-of-flight-sensor-mounted.jpg rename to img/time-of-flight-sensor-mounted.jpg diff --git a/docs/img/time-of-flight-side-by-side.png b/img/time-of-flight-side-by-side.png similarity index 100% rename from docs/img/time-of-flight-side-by-side.png rename to img/time-of-flight-side-by-side.png diff --git a/docs/img/timer-tutorial-banner.png b/img/timer-tutorial-banner.png similarity index 100% rename from docs/img/timer-tutorial-banner.png rename to img/timer-tutorial-banner.png diff --git a/docs/img/tof-sensor-3d-render.png b/img/tof-sensor-3d-render.png similarity index 100% rename from docs/img/tof-sensor-3d-render.png rename to img/tof-sensor-3d-render.png diff --git a/docs/img/tof-sensor-side-view-2.png b/img/tof-sensor-side-view-2.png similarity index 100% rename from docs/img/tof-sensor-side-view-2.png rename to img/tof-sensor-side-view-2.png diff --git a/docs/img/tof-sensor-side-view.jpg b/img/tof-sensor-side-view.jpg similarity index 100% rename from docs/img/tof-sensor-side-view.jpg rename to img/tof-sensor-side-view.jpg diff --git a/docs/img/tof-vs-ping-distance-sensors.jpg b/img/tof-vs-ping-distance-sensors.jpg similarity index 100% rename from docs/img/tof-vs-ping-distance-sensors.jpg rename to img/tof-vs-ping-distance-sensors.jpg diff --git a/docs/img/usb-battery-pack-large.png b/img/usb-battery-pack-large.png similarity index 100% rename from docs/img/usb-battery-pack-large.png rename to img/usb-battery-pack-large.png diff --git a/docs/img/usb-micro-to-c.png b/img/usb-micro-to-c.png similarity index 100% rename from docs/img/usb-micro-to-c.png rename to img/usb-micro-to-c.png diff --git a/docs/img/wireless-block-arch.png b/img/wireless-block-arch.png similarity index 100% rename from docs/img/wireless-block-arch.png rename to img/wireless-block-arch.png diff --git a/docs/img/wireless-display-connection-status.jpg b/img/wireless-display-connection-status.jpg similarity index 100% rename from docs/img/wireless-display-connection-status.jpg rename to img/wireless-display-connection-status.jpg diff --git a/docs/img/wireless-rgb-web-controller.png b/img/wireless-rgb-web-controller.png similarity index 100% rename from docs/img/wireless-rgb-web-controller.png rename to img/wireless-rgb-web-controller.png diff --git a/docs/img/ws2811B-8x32-matrix.png b/img/ws2811B-8x32-matrix.png similarity index 100% rename from docs/img/ws2811B-8x32-matrix.png rename to img/ws2811B-8x32-matrix.png diff --git a/docs/img/ws2811b-144.png b/img/ws2811b-144.png similarity index 100% rename from docs/img/ws2811b-144.png rename to img/ws2811b-144.png diff --git a/index.html b/index.html new file mode 100644 index 000000000..213f34708 --- /dev/null +++ b/index.html @@ -0,0 +1,1692 @@ + + + + + + + + + + + + + + + + + + + + + + + + + MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                            +
                                                                                                                                                                            + +
                                                                                                                                                                            + + + + + + +
                                                                                                                                                                            +
                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                            +
                                                                                                                                                                            + + + MicroPython Home + + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                            + +
                                                                                                                                                                            +
                                                                                                                                                                            + + +
                                                                                                                                                                            + + +
                                                                                                                                                                            + +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            +
                                                                                                                                                                            + Initializing search +
                                                                                                                                                                            +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + +
                                                                                                                                                                              + +
                                                                                                                                                                              + + +
                                                                                                                                                                              +
                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + +
                                                                                                                                                                              + +
                                                                                                                                                                              + +
                                                                                                                                                                              + + + + + + +
                                                                                                                                                                              +
                                                                                                                                                                              + + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + + +
                                                                                                                                                                              + + +
                                                                                                                                                                              + +
                                                                                                                                                                              + + +
                                                                                                                                                                              +
                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + +
                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                              • + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + MicroPython Home + + + + + + + +
                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Course Outline + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + Section 1: Introduction to Physical Computing + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 2: Getting Started with MicroPython + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 3: Basic Examples + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 4: Sensors + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 5: Motors and Robots + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 6: Displays + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 7: Sound and Music + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 8: Advanced Labs + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Section 9: Kits + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Related and Reference Material + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + Glossary of Terms + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Contact + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + +
                                                                                                                                                                                + +
                                                                                                                                                                                + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                              • + + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + +
                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                + +
                                                                                                                                                                              • + + + Course Outline + + + +
                                                                                                                                                                                +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Section 1: Introduction to Physical Computing + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 2: Getting Started with MicroPython + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 3: Basic Examples + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 4: Sensors + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 5: Motors and Robots + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 6: Displays + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 7: Sound and Music + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 8: Advanced Labs + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Section 9: Kits + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                              • + +
                                                                                                                                                                              • + + + Related and Reference Material + + + +
                                                                                                                                                                                +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Glossary of Terms + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Contact + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                              • + +
                                                                                                                                                                              + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + +
                                                                                                                                                                              +
                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                              CoderDojo Twin Cities Micropython

                                                                                                                                                                              +

                                                                                                                                                                              Micropython logo

                                                                                                                                                                              +

                                                                                                                                                                              This website and GitHub repository are for sharing resources to teach MicroPython to students in 5th to 12th grades (10-18 years old). The course assumes that either a mentor, teacher or students have access to at least one microcontroller such as the $4 Raspberry Pi Pico or the $10 ESP32. Students should also have access to some low-cost sensors (buttons, potentiometers, ultrasonic distance sensor) and displays such as LEDs or OLED displays.

                                                                                                                                                                              +

                                                                                                                                                                              If you are looking for a specific topic, please remember to use the search function in the upper right of the website. The website is best displayed on a wide screen to see the navigation bar on the left although the website also works on the small screens of mobile phones and tablets.

                                                                                                                                                                              +

                                                                                                                                                                              Course Outline

                                                                                                                                                                              +

                                                                                                                                                                              You can use the navigation area on the left side panel to navigate to different parts of the website. Here is a high-level overview of the main sections of the site.

                                                                                                                                                                              +

                                                                                                                                                                              Section 1: Introduction to Physical Computing

                                                                                                                                                                              +

                                                                                                                                                                              This part is a high-level overview of what MicroPython is and why is has become the most popular way to do physical computing, program microcontrollers and build robots. We also discuss the different types of microcontrollers available, their price and features and how to purchase them independently or in kits.

                                                                                                                                                                              +

                                                                                                                                                                              Section 2: Getting Started with MicroPython

                                                                                                                                                                              +

                                                                                                                                                                              This part will help you get started programming MicroPython on your microcontroller and learn how to hook up parts on a solderless breadboard. We discuss the need for a desktop Integrated Development Environment (IDE) and how to get started writing simple programs

                                                                                                                                                                              +

                                                                                                                                                                              Section 3: Basic Examples

                                                                                                                                                                              +

                                                                                                                                                                              These ten lessons are the foundations for learning MicroPython. They include learning how to blink one or more LEDs, monitor for button presses, fade LEDs in and out using PWM signals, read analog values from potentiometers, read light sensors, turn motors and servos and display rainbow patterns on a NeoPixel strip. Many other labs are variations of these 10 labs.

                                                                                                                                                                              +

                                                                                                                                                                              Introduction to Basic MicroPython Examples

                                                                                                                                                                              +

                                                                                                                                                                              Section 4: Sensors

                                                                                                                                                                              +

                                                                                                                                                                              This section will give you more examples of how to use different types of sensors such as heat sensors, current sensors, rotary encoders, accelerometers, gesture sensors, and magnetic field sensors.

                                                                                                                                                                              +

                                                                                                                                                                              Reading Sensors with MicroPython

                                                                                                                                                                              +

                                                                                                                                                                              Section 5: Motors and Robots

                                                                                                                                                                              +

                                                                                                                                                                              This is our student's favorite part of this site! Once you can make a motor go forward and reverse, you are close to being able to make a robot move. We walk you through the basics of using a simple transistor to control a motor, to using simple motor controllers like the L293D chips.

                                                                                                                                                                              +

                                                                                                                                                                              Introduction to Motors and Robots with MicroPython

                                                                                                                                                                              +

                                                                                                                                                                              Note that we have many other advanced labs that use our $11 Cytron Maker Pi RP2040 Kits. These incredible boards have everything integrated to build robots with lights and sounds.

                                                                                                                                                                              +

                                                                                                                                                                              Section 6: Displays

                                                                                                                                                                              +

                                                                                                                                                                              This section shows you how to use many different types of displays, from simple 7-segment digital displays to complex OLED graphic displays. On the old 2K Arduino controllers these graphics labs used to be hard, but now we have 264K of RAM on the Raspberry Pi RP2040 microcontrollers. Now these labs are easy!

                                                                                                                                                                              +
                                                                                                                                                                                +
                                                                                                                                                                              • Simple Character Displays
                                                                                                                                                                              • +
                                                                                                                                                                              • Graphical Displays
                                                                                                                                                                              • +
                                                                                                                                                                              +

                                                                                                                                                                              Section 7: Sound and Music

                                                                                                                                                                              +

                                                                                                                                                                              Having powerful microcontrollers allows us to generate complex sounds, play tones and even playback recoded sound effects.

                                                                                                                                                                              +

                                                                                                                                                                              Introduction to Sound and Music with MicroPython

                                                                                                                                                                              +

                                                                                                                                                                              Section 8: Advanced Labs

                                                                                                                                                                              +

                                                                                                                                                                              We have now covered all the things you need to build hundreds of projects. This section contains deeper dives into other topics +such as how to use the MicroPython Remote ```pmremote`````` tools to automate the loading of software onto your microcontroller.

                                                                                                                                                                              +

                                                                                                                                                                              Advanced Topics

                                                                                                                                                                              +

                                                                                                                                                                              Section 9: Kits

                                                                                                                                                                              +

                                                                                                                                                                              This section contains detailed steps to use the popular educational kits that are now integrating MicroPython and the RP2040 microcontroller. There are many kits and these lessons contain full working programs to build complex projects like a collision avoidance robot with OLED displays.

                                                                                                                                                                              +

                                                                                                                                                                              MicroPython Kits

                                                                                                                                                                              +

                                                                                                                                                                              Related and Reference Material

                                                                                                                                                                              +

                                                                                                                                                                              Lastly, we have a large glossary of terms, contact information and references to other websites that might be useful in your projects. Many of our more advanced projects have been moved into separate websites. +Here are a few of these sites:

                                                                                                                                                                              +
                                                                                                                                                                                +
                                                                                                                                                                              1. Moving Rainbow - focus on a full curriculum around using LED strips to make displays and costumes.
                                                                                                                                                                              2. +
                                                                                                                                                                              3. Robot Faces and have been moved into their own repositories.
                                                                                                                                                                              4. +
                                                                                                                                                                              5. Clocks and Watches - dozens of examples that just focus on creating clock and watch projects. These projects use the Pico "W" and the new low-cost SmartWatch displays.
                                                                                                                                                                              6. +
                                                                                                                                                                              7. Robot Day - details of building a single-day event to promote STEM at your school using +collision avoidance robots.
                                                                                                                                                                              8. +
                                                                                                                                                                              9. Beginning Electronics
                                                                                                                                                                              10. +
                                                                                                                                                                              11. AI Racing League - this site moves from MicroPython on the Raspberry Pi Pico to full Python on Raspberry Pi single-board computers. It is designed for students +who have mastered many of our programming labs and want more challenging projects involving data literacy, machine learning and computer vision.
                                                                                                                                                                              12. +
                                                                                                                                                                              +

                                                                                                                                                                              Glossary of Terms

                                                                                                                                                                              +

                                                                                                                                                                              Glossary of MicroPython Terms

                                                                                                                                                                              +

                                                                                                                                                                              References

                                                                                                                                                                              +

                                                                                                                                                                              This is an annotated list of other on-line resources to help you learn MicroPython and use microcontrollers.

                                                                                                                                                                              +

                                                                                                                                                                              Micropython References - links to other useful sites.

                                                                                                                                                                              +

                                                                                                                                                                              If you have suggestions for additional references projects, please let us know!

                                                                                                                                                                              +

                                                                                                                                                                              Contact

                                                                                                                                                                              +

                                                                                                                                                                              Contact

                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                              +
                                                                                                                                                                              + + + +
                                                                                                                                                                              + + + +
                                                                                                                                                                              + +
                                                                                                                                                                              + + + +
                                                                                                                                                                              + + + + +
                                                                                                                                                                              + + Next + +
                                                                                                                                                                              + About This Site +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + +
                                                                                                                                                                              +
                                                                                                                                                                              + +
                                                                                                                                                                              + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                              + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/intro/01-about/index.html b/intro/01-about/index.html new file mode 100644 index 000000000..027bb1216 --- /dev/null +++ b/intro/01-about/index.html @@ -0,0 +1,1585 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + About This Site - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                              +
                                                                                                                                                                              + +
                                                                                                                                                                              + + + + + + +
                                                                                                                                                                              +
                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                              +
                                                                                                                                                                              + + + About This Site + + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                              + +
                                                                                                                                                                              +
                                                                                                                                                                              + + +
                                                                                                                                                                              + + +
                                                                                                                                                                              + +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              +
                                                                                                                                                                              + Initializing search +
                                                                                                                                                                              +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + +
                                                                                                                                                                                + +
                                                                                                                                                                                + + +
                                                                                                                                                                                +
                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                                + +
                                                                                                                                                                                + +
                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                +
                                                                                                                                                                                + + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + + +
                                                                                                                                                                                + + +
                                                                                                                                                                                + +
                                                                                                                                                                                + + +
                                                                                                                                                                                +
                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + About This Site + + + + + + + +
                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + + + Content Licenses + + + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    • + + + Contributing to This Website + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + Git Pull Requests + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Adding a New Issues + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Let Us Setup a Edit Page + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Manual Methods + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Physical Computing + + + + +
                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Microcontrollers + + + + +
                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                • + + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + +
                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + + + Content Licenses + + + +
                                                                                                                                                                                • + +
                                                                                                                                                                                • + + + Contributing to This Website + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + Git Pull Requests + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Adding a New Issues + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Let Us Setup a Edit Page + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Manual Methods + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                • + +
                                                                                                                                                                                + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + +
                                                                                                                                                                                +
                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                About MicroPython for Kids

                                                                                                                                                                                +

                                                                                                                                                                                The this site provides a rich collection of resources to teach computational thinking to students from 10 to 16 years old using fun Python programs that control the physical world around us.

                                                                                                                                                                                +

                                                                                                                                                                                The sub-field of computer science that reads sensors and controls lights and motors is called Physical Computing. We cover physical computing in our next section.

                                                                                                                                                                                +

                                                                                                                                                                                Content Licenses

                                                                                                                                                                                +

                                                                                                                                                                                All the content on this website is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike. This means if your preserve the attribution and license you can use the content for free in your classrooms and modify and extend the curriculum to meet your needs. However, you can not charge your students additional feeds for the content or resell the content.

                                                                                                                                                                                +

                                                                                                                                                                                Contributing to This Website

                                                                                                                                                                                +

                                                                                                                                                                                We invite all students, teachers and mentors to help us build a better website. You can read our publishing process on the CoderDojo Twin Cities Content Authoring Guide.

                                                                                                                                                                                +

                                                                                                                                                                                Please make sure you using original content and avoid using any images that you have not created yourself. It is always a good idea to have a friend check your spelling, typos and links.

                                                                                                                                                                                +

                                                                                                                                                                                There are several ways to contribute to get your content on this website.

                                                                                                                                                                                +

                                                                                                                                                                                Git Pull Requests

                                                                                                                                                                                +

                                                                                                                                                                                If you know how, you can student submit a Git Pull Request. This tells our team that you have content to contribute. Don't be scared about learning how to do this. There are lots of examples online and please reach out if you are having trouble. This is our preferred approach, but we realize that the first time you do this there are several things you need to know.

                                                                                                                                                                                +

                                                                                                                                                                                Adding a New Issues

                                                                                                                                                                                +

                                                                                                                                                                                You can just open a new [Issue](https://github.com/CoderDojoTC/micropython/issues and put your content in Markdown. You will also need to tell us where you store any images and videos. It might take us some time get this content into a new release.

                                                                                                                                                                                +

                                                                                                                                                                                Let Us Setup a Edit Page

                                                                                                                                                                                +

                                                                                                                                                                                If learning how to do pull requests is too daunting for you, don't worry! You are not alone. If you want us to setup a web page you can edit using the simple "Edit" button on GitHub we can do that for you. Just tell us where you want the page located and give us your GitHub ID and we will set this up. You will need to let us know when your content is ready to be merged in to our releases.

                                                                                                                                                                                +

                                                                                                                                                                                Manual Methods

                                                                                                                                                                                +

                                                                                                                                                                                What if you have an urgent class coming up and don't have time to learn Markdown? If this happens, you can send us your raw content in MS-Word, PowerPoint or a Google Doc. Since we are an all-volunteer organization, we will need time to find a volunteer to convert your content into Markdown. All urgent requests should go to:

                                                                                                                                                                                +

                                                                                                                                                                                info@codesavvy.org

                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                +
                                                                                                                                                                                + + + +
                                                                                                                                                                                + + + +
                                                                                                                                                                                + +
                                                                                                                                                                                + + + +
                                                                                                                                                                                + + + +
                                                                                                                                                                                + + +
                                                                                                                                                                                +
                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                + MicroPython Home +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + + +
                                                                                                                                                                                + + Next + +
                                                                                                                                                                                + Physical Computing +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                                + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/intro/02-physical-computing/index.html b/intro/02-physical-computing/index.html new file mode 100644 index 000000000..23a7cd4a4 --- /dev/null +++ b/intro/02-physical-computing/index.html @@ -0,0 +1,1692 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Physical Computing - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                +
                                                                                                                                                                                + +
                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                +
                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                +
                                                                                                                                                                                + + + Physical Computing + + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                + +
                                                                                                                                                                                +
                                                                                                                                                                                + + +
                                                                                                                                                                                + + +
                                                                                                                                                                                + +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                +
                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                    • + + + + + About This Site + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + Physical Computing + + + + + + + +
                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + Physical Computing in Teaching Computational Thinking + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Why Physical Computing Has Become So Popular + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Examples of Sensors + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Examples of Actuators + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + What are the Challenges in Physical Computing + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Questions for Discussion + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Answers to Discussion questions + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + Microcontrollers + + + + +
                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                  • + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                  • + + + Physical Computing in Teaching Computational Thinking + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Why Physical Computing Has Become So Popular + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Examples of Sensors + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Examples of Actuators + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + What are the Challenges in Physical Computing + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Questions for Discussion + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + Answers to Discussion questions + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                  • + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                  What is Physical Computing?

                                                                                                                                                                                  +

                                                                                                                                                                                  Physical Computing is the process of using computers to read data from sensors about the world around us and then taking actions on this incoming data stream. These actions are typically doing things like blinking and LED, moving a motor or updating a display.

                                                                                                                                                                                  +

                                                                                                                                                                                  +

                                                                                                                                                                                  Physical Computing in Teaching Computational Thinking

                                                                                                                                                                                  +

                                                                                                                                                                                  Physical computing plays an important role in teaching the core concepts in Computational Thinking. Often times students quickly lose interest when only abstract concepts are used. Physical computing allows direct hands-on experiences that keeps students engaged and gives them immediate feedback. Although our labs start slowly with simply blinking LEDs, they quick move to controlling motors and building robots.

                                                                                                                                                                                  +

                                                                                                                                                                                  The material in this website is designed to leverage everything we have learned to make our lessons be fun, engaging and allow students to come up with their own ideas for project-based learning.

                                                                                                                                                                                  +

                                                                                                                                                                                  Why Physical Computing Has Become So Popular

                                                                                                                                                                                  +

                                                                                                                                                                                  In the past, the chips we used to teach physical computing (called microcontrollers) were slow, had huge memory limitations, and were expensive. They were also hard to program and since we could not use the Python language that is popular in most classrooms today.

                                                                                                                                                                                  +

                                                                                                                                                                                  This all changed in January of 2021 when the Raspberry Pi Foundation released a $4 microcontroller called the Pico that has 200 times the memory of the most popular microcontroller (The $25 Arduino Uno). Now teachers could purchase an entire classroom full of microcontrollers that were powerful enough to even do machine learning.

                                                                                                                                                                                  +

                                                                                                                                                                                  One way to measure the cost effectiveness of this system is to compare the cost per kilobyte of RAM. The Arduino Uno was about $12.50 per kilobyte. The new Raspberry Pi Pico, with 264K RAM cost only 2 cents per kilobyte!

                                                                                                                                                                                  +

                                                                                                                                                                                  +

                                                                                                                                                                                  There was also one other HUGE advantage of these microcontrollers. They ran Python! Python is the most popular language for students today. There are millions of on-line websites that show kids how to learn Python like our own CoderDojo Beginning Python classes. Teachers now had the big three factors:

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. Low cost ($4)
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. Powerful (264K RAM)
                                                                                                                                                                                  4. +
                                                                                                                                                                                  5. Runs Python - the most popular language for teaching
                                                                                                                                                                                  6. +
                                                                                                                                                                                  +

                                                                                                                                                                                  But there was a small problem. Although there were millions of sample programs for the old under-powered Arduino microcontrollers, we needed high-quality lessons for our students to learn to use the new microcontrollers. And these lessons need to be flexible so teachers around the world could build new courses out of this content without having to purchase expensive textbooks. That is why this website is so important. We hope you see how excited we are to bring you this new content!

                                                                                                                                                                                  +

                                                                                                                                                                                  Examples of Sensors

                                                                                                                                                                                  +

                                                                                                                                                                                  Here are some sample sensors that we use:

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. Buttons and switches
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. Light sensors (photoresistor)
                                                                                                                                                                                  4. +
                                                                                                                                                                                  5. Distance sensor (both ultrasonic and light)
                                                                                                                                                                                  6. +
                                                                                                                                                                                  7. Sound sensors
                                                                                                                                                                                  8. +
                                                                                                                                                                                  9. Motion and acceleration sensors
                                                                                                                                                                                  10. +
                                                                                                                                                                                  11. Gesture sensors
                                                                                                                                                                                  12. +
                                                                                                                                                                                  13. Magnetic field sensors (like a compass)
                                                                                                                                                                                  14. +
                                                                                                                                                                                  15. Heat sensors
                                                                                                                                                                                  16. +
                                                                                                                                                                                  17. Touch sensor
                                                                                                                                                                                  18. +
                                                                                                                                                                                  19. Voltage and current sensors
                                                                                                                                                                                  20. +
                                                                                                                                                                                  21. Orientation and tilt sensors
                                                                                                                                                                                  22. +
                                                                                                                                                                                  23. Water and moisture sensors
                                                                                                                                                                                  24. +
                                                                                                                                                                                  25. Chemistry sensors such as Ph level (acidity)
                                                                                                                                                                                  26. +
                                                                                                                                                                                  27. Smoke and gas sensors
                                                                                                                                                                                  28. +
                                                                                                                                                                                  29. Air quality sensors
                                                                                                                                                                                  30. +
                                                                                                                                                                                  +

                                                                                                                                                                                  Examples of Actuators

                                                                                                                                                                                  +

                                                                                                                                                                                  Here are some of the Actuators we use:

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. LEDs
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. Motors (simple DC motors)
                                                                                                                                                                                  4. +
                                                                                                                                                                                  5. Servos
                                                                                                                                                                                  6. +
                                                                                                                                                                                  7. Displays (character displays, graphic displays)
                                                                                                                                                                                  8. +
                                                                                                                                                                                  +

                                                                                                                                                                                  What are the Challenges in Physical Computing

                                                                                                                                                                                  +

                                                                                                                                                                                  In the real world, sensor data can be complex. We often need to look for complex patterns in an incoming data stream. For example, how can we detect complex motion such as gestures from a simple distance measurement? Other questions that we have to consider include:

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. How often should we sample the data provided by a sensor?
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. How to we calibrate sensors to get accurate readings?
                                                                                                                                                                                  4. +
                                                                                                                                                                                  5. How do we convert sensor data into forms that are easy to use?
                                                                                                                                                                                  6. +
                                                                                                                                                                                  7. How can we look for patterns in data? Can we detect specific sounds or speech?
                                                                                                                                                                                  8. +
                                                                                                                                                                                  9. How can use use machine learning to train a model to detect specific patterns such as a "wake word" in a smart speaker system?
                                                                                                                                                                                  10. +
                                                                                                                                                                                  11. If you have allergies, what types of sensors could tell you how bad the pollen counts are outside today?
                                                                                                                                                                                  12. +
                                                                                                                                                                                  13. How can we send data back to a central server?
                                                                                                                                                                                  14. +
                                                                                                                                                                                  +

                                                                                                                                                                                  Questions for Discussion

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. What other sensors and actuators can you think of?
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. How would you determine how much battery power is left in your robot?
                                                                                                                                                                                  4. +
                                                                                                                                                                                  5. Can you give an example of a sensor in your house that is used to regulate temperature?
                                                                                                                                                                                  6. +
                                                                                                                                                                                  7. Can you name a sensor in your house that could save your life?
                                                                                                                                                                                  8. +
                                                                                                                                                                                  9. How many sensors do you think a typical car has?
                                                                                                                                                                                  10. +
                                                                                                                                                                                  11. What data could you gather and sell?
                                                                                                                                                                                  12. +
                                                                                                                                                                                  +

                                                                                                                                                                                  References

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  1. Wikipedia on Physical Computing in Education
                                                                                                                                                                                  2. +
                                                                                                                                                                                  3. Sample Sensor Kit on Amazon
                                                                                                                                                                                  4. +
                                                                                                                                                                                  +

                                                                                                                                                                                  Answers to Discussion questions

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  • You would use a voltage sensor to see how much power is available in a battery.
                                                                                                                                                                                  • +
                                                                                                                                                                                  • The name of a device that controls the temperature in your home is called a thermostat. It tells your home furnace or air conditioner to go on or off.
                                                                                                                                                                                  • +
                                                                                                                                                                                  • Smoke detectors and carbon monoxide detectors are examples of devices that save thousands of lives every year. According the the New York Department of Health presence of a working smoke alarm in a home reduces the risk of dying in a fire by about 50%. Worldwide, over 10,000 lives are saved every year by smoke detectors. Freakonomics
                                                                                                                                                                                  • +
                                                                                                                                                                                  • A modern car has almost 100 sensors in it. This includes motor sensors and sensors to detect if your doors are closed and your seatbelt is fastened.
                                                                                                                                                                                  • +
                                                                                                                                                                                  +

                                                                                                                                                                                  References

                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                  • How a Small Charity is Upsetting the Trillion-Dollar Silicon Chip Industry
                                                                                                                                                                                  • +
                                                                                                                                                                                  • [Raspberry Pi Pico Robot in Micropython] +(https://dmccreary.medium.com/raspberry-pi-pico-robot-in-micropython-51f956486270)
                                                                                                                                                                                  • +
                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  + + + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                  + About This Site +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + + +
                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                  + Microcontrollers +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/intro/03-microcontrollers/index.html b/intro/03-microcontrollers/index.html new file mode 100644 index 000000000..6e3886827 --- /dev/null +++ b/intro/03-microcontrollers/index.html @@ -0,0 +1,1633 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Microcontrollers - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + +
                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + Microcontrollers + + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  + + +
                                                                                                                                                                                  + +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  +
                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                  +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                      • + + + + + About This Site + + + + +
                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + Physical Computing + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + Microcontrollers + + + + + + + +
                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                        • + + + Types of Microcontroller Boards Used in These Labs + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                            + +
                                                                                                                                                                                          • + + + Raspberry Pi Pico + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + What is Physical Computing? + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + How Microcontrollers are Used + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + Programming a Microcontroller + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                    • + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + + + Types of Microcontroller Boards Used in These Labs + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + Raspberry Pi Pico + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    • + + + What is Physical Computing? + + + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    • + + + How Microcontrollers are Used + + + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    • + + + Programming a Microcontroller + + + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                    • + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                    Microcontrollers

                                                                                                                                                                                    +

                                                                                                                                                                                    Microcontrollers +Left to right: Raspberry Pi Pico, Cytron Maker Pi Nano, Cytron Maker Pi 2040, Cytron Maker Pi Pico, ESP-32, ESP TTGO

                                                                                                                                                                                    +

                                                                                                                                                                                    This lesson is an overview of microcontrollers and their role in teaching physical computing.

                                                                                                                                                                                    +

                                                                                                                                                                                    A microcontroller is a small low-cost computer used to control physical devices such as LED, servos and motors. Microcontroller boards typically cost around $4 to $6 and are an ideal way to learn about computer science because you can use them to build fun projects. For example you can control a row of LEDs, move a robot and sense the world around us with a variety of light, sound and motion sensors.

                                                                                                                                                                                    +

                                                                                                                                                                                    Types of Microcontroller Boards Used in These Labs

                                                                                                                                                                                    +

                                                                                                                                                                                    We use a variety of microcontroller boards that are based on either the Raspberry Pi RP2040 chip or the ESP32. The boards we use are all low-cost (under $10) but have a variety of on-board devices such as buttons, LEDs, speakers and motor controllers. Which board you use depends on how many of these components you need in your projects. The RP2040 has 264K RAM and the ESP32 has 520K RAM.

                                                                                                                                                                                    +

                                                                                                                                                                                    Some of the boards are mounted on breadboards and others use Grove connectors to connect sensors and actuators.

                                                                                                                                                                                    +

                                                                                                                                                                                    Raspberry Pi Pico

                                                                                                                                                                                    +

                                                                                                                                                                                    This microcontroller is low cost (retail list price is $4) and can be mounted directly on a breadboard. The Pico has just a single LED and no buttons.

                                                                                                                                                                                    +

                                                                                                                                                                                    In the past, microcontrollers were difficult for younger students to program. They were also too expensive for every student to purchase and take home. A typical Arduino kit could easily cost over $20 and required you to learn C to program it.

                                                                                                                                                                                    +

                                                                                                                                                                                    Today, microcontrollers such as the Raspberry Pi Pico and the ESP32 cost as little as four dollars. And these devices are designed to be programmed in Python, the most popular programming language for students.

                                                                                                                                                                                    +

                                                                                                                                                                                    What is Physical Computing?

                                                                                                                                                                                    +

                                                                                                                                                                                    Physical Computing is a field of study that can sense and respond to the world around us. Unlike programming a cell phone or a laptop computer, our focus is reading sensor values and quickly responding to changes. Physical Computing is widely used to teach principals of computer science because students can create their own projects and express creativity such a controlling the patterns of lights or creating complex sounds.

                                                                                                                                                                                    +

                                                                                                                                                                                    How Microcontrollers are Used

                                                                                                                                                                                    +

                                                                                                                                                                                    Microcontrollers do three things:

                                                                                                                                                                                    +
                                                                                                                                                                                      +
                                                                                                                                                                                    1. They read sensor values of the world around them
                                                                                                                                                                                    2. +
                                                                                                                                                                                    3. They transform this data into useful representations
                                                                                                                                                                                    4. +
                                                                                                                                                                                    5. They send outputs to devices that control the world such as LEDs and motors as well as displays
                                                                                                                                                                                    6. +
                                                                                                                                                                                    +

                                                                                                                                                                                    Here is a general diagram to think about when you are designing microcontroller systems: +Microcontroller Architecture

                                                                                                                                                                                    +

                                                                                                                                                                                    Here is a specific example instance of what inputs and outputs might do. +Microcontroller Architecture Example

                                                                                                                                                                                    +

                                                                                                                                                                                    Programming a Microcontroller

                                                                                                                                                                                    +

                                                                                                                                                                                    In this class, we will use the MicroPython to program our Microcontroller.

                                                                                                                                                                                    +

                                                                                                                                                                                    Our programs will usually have the following structure:

                                                                                                                                                                                    +
                                                                                                                                                                                      +
                                                                                                                                                                                    1. Imports: Specify the Python libraries used in the code (More Information on Python libraries are available here)
                                                                                                                                                                                    2. +
                                                                                                                                                                                    3. Setup: Setup/ Initialize variables and sensors
                                                                                                                                                                                    4. +
                                                                                                                                                                                    5. Main loop: Continuously monitor sensor inputs and take actions
                                                                                                                                                                                    6. +
                                                                                                                                                                                    +

                                                                                                                                                                                    The following is an example code in Micropython:

                                                                                                                                                                                    +
                                                                                                                                                                                     1
                                                                                                                                                                                    + 2
                                                                                                                                                                                    + 3
                                                                                                                                                                                    + 4
                                                                                                                                                                                    + 5
                                                                                                                                                                                    + 6
                                                                                                                                                                                    + 7
                                                                                                                                                                                    + 8
                                                                                                                                                                                    + 9
                                                                                                                                                                                    +10
                                                                                                                                                                                    +11
                                                                                                                                                                                    +12
                                                                                                                                                                                    +13
                                                                                                                                                                                    # Import Section
                                                                                                                                                                                    +import machine
                                                                                                                                                                                    +import time
                                                                                                                                                                                    +
                                                                                                                                                                                    +# Setup Section
                                                                                                                                                                                    +led = machine.Pin(16, machine.Pin.OUT)
                                                                                                                                                                                    +
                                                                                                                                                                                    +# Main Loop
                                                                                                                                                                                    +while True:
                                                                                                                                                                                    +    led.high()
                                                                                                                                                                                    +    time.sleep(0.5)
                                                                                                                                                                                    +    led.low()
                                                                                                                                                                                    +    time.sleep(0.5)
                                                                                                                                                                                    +
                                                                                                                                                                                    +

                                                                                                                                                                                    Almost all our programs will start with the import machine line. This tells the system that we need to gather all the libraries that understand our physical machine.

                                                                                                                                                                                    +

                                                                                                                                                                                    If you couldn't understand the example program - don't worry! We will be going through it in detail as we work on our labs.

                                                                                                                                                                                    +

                                                                                                                                                                                    References

                                                                                                                                                                                    +
                                                                                                                                                                                      +
                                                                                                                                                                                    • Listing of RP2040-based Boards on the Raspberry Pi Foundation Website
                                                                                                                                                                                    • +
                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    + + + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                    + Physical Computing +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + + +
                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                    + Introduction +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/kits/01-intro/index.html b/kits/01-intro/index.html new file mode 100644 index 000000000..b13345cd6 --- /dev/null +++ b/kits/01-intro/index.html @@ -0,0 +1,1894 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + +
                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + Introduction + + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    + + +
                                                                                                                                                                                    + +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    +
                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                    +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                        + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + +
                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                          • + + + Solderless Connectors + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          • + + + Example Kits + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          • + + + Searching SparkFun + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + MicroBit + + + + +
                                                                                                                                                                                        • + + + + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                      • + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                      • + + + Solderless Connectors + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Example Kits + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + Searching SparkFun + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                      • + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                      Kits for Learning MicroPython

                                                                                                                                                                                      +

                                                                                                                                                                                      This section review several kits for learning MicroPython. Most of them use the RP2040 chip, but there are some that also use the ESP32 when wireless communication is needed.

                                                                                                                                                                                      +

                                                                                                                                                                                      Solderless Connectors

                                                                                                                                                                                      +

                                                                                                                                                                                      There are several types of solderless connectors used in these kits. They connect sensors and motors to these kits without the need for soldering. They are ideal for student labs that don't want the fire-hazards associated with soldering or where solderless breadboards and hot-glue is not flexible enough.

                                                                                                                                                                                      +

                                                                                                                                                                                      These are usually 3 and 4-wire connectors that support analog and digital input and output as well as I2C bus and UART communications. They are typically designed to carry about 1 amp of current.

                                                                                                                                                                                      +
                                                                                                                                                                                        +
                                                                                                                                                                                      • Grove Connectors - popular with Seeed and Cyton kits. See the manual here
                                                                                                                                                                                      • +
                                                                                                                                                                                      • Qwiic - SparkFun I2C connector
                                                                                                                                                                                      • +
                                                                                                                                                                                      • Stemma and Stemma QT - Adafruit connectors are built around standard JST PH 2mm spacing connectors.
                                                                                                                                                                                      • +
                                                                                                                                                                                      +

                                                                                                                                                                                      Example Kits

                                                                                                                                                                                      +

                                                                                                                                                                                      The following list is not design to be an exhaustive list of all MicroPython development kits available on the market. We focus on value-based kits that will help our students have fun learning computational thinking.

                                                                                                                                                                                      +
                                                                                                                                                                                        +
                                                                                                                                                                                      • Basic Kit - Our standard labs use a $4 Raspberry Pi Pico on a $2 solderless breadboard. You will also need some 22-gauge wire or a jumper wire kit.
                                                                                                                                                                                      • +
                                                                                                                                                                                      • Maker Pi RP2040 Kit - this is a $9.90 kit from Cytron that features a single board with many features for small robots. It is an ideal low-cost starter kit.
                                                                                                                                                                                      • +
                                                                                                                                                                                      +

                                                                                                                                                                                      Searching SparkFun

                                                                                                                                                                                      +

                                                                                                                                                                                      You can also use the MicroPython "tag" to search all the kits on the SparkFun site:

                                                                                                                                                                                      +

                                                                                                                                                                                      https://www.sparkfun.com/categories/tags/micropython

                                                                                                                                                                                      +

                                                                                                                                                                                      References

                                                                                                                                                                                      +

                                                                                                                                                                                      Here are kits that we have seen but have not yet evaluated:

                                                                                                                                                                                      +

                                                                                                                                                                                      Waveshare PicoGo Robot

                                                                                                                                                                                      +

                                                                                                                                                                                      PicoGo Mobile Robot is a $43 robot based on Raspberry Pi Pico.

                                                                                                                                                                                      +
                                                                                                                                                                                        +
                                                                                                                                                                                      1. SKU: 20380
                                                                                                                                                                                      2. +
                                                                                                                                                                                      3. Part Number: PicoGo-EN
                                                                                                                                                                                      4. +
                                                                                                                                                                                      5. Powered by 2x 14500 Li-ion batteries. NOTE! We don't recommend these for classroom use since they are a fire hazard.
                                                                                                                                                                                      6. +
                                                                                                                                                                                      7. Battery protection circuit: over charge/discharge protection, over current protection, short circuit protection, reverse proof, more stable and safe operating +Recharge/Discharge circuit, allows programming/debugging concurrently while recharging
                                                                                                                                                                                      8. +
                                                                                                                                                                                      9. 5-ch infrared sensor, analog output, combined with PID algorithm, stable line tracking +Onboard multiple smart robot sensors like line tracking, obstacle avoidance, no more messy wiring
                                                                                                                                                                                      10. +
                                                                                                                                                                                      11. 1.14 inch IPS colorful LCD display, 240 x135 pixels, 65K colors
                                                                                                                                                                                      12. +
                                                                                                                                                                                      13. Integrates Bluetooth module, allows teleoperations like robot movement, RGB LED display color, buzzer, etc. by using mobile phone APP
                                                                                                                                                                                      14. +
                                                                                                                                                                                      15. N20 micro geared motors, with metal gears, low noise, high accuracy
                                                                                                                                                                                      16. +
                                                                                                                                                                                      17. NeoPixel
                                                                                                                                                                                      18. +
                                                                                                                                                                                      19. Line following sensors
                                                                                                                                                                                      20. +
                                                                                                                                                                                      +

                                                                                                                                                                                      +

                                                                                                                                                                                      Getting Started Kits

                                                                                                                                                                                      +

                                                                                                                                                                                      Vilros Getting Started Kit

                                                                                                                                                                                      +

                                                                                                                                                                                      Vilros Getting Started With MicroPython on Raspberry Pi Pico Kit

                                                                                                                                                                                      +

                                                                                                                                                                                      This kit includes:

                                                                                                                                                                                      +
                                                                                                                                                                                        +
                                                                                                                                                                                      1. List price is $44.99
                                                                                                                                                                                      2. +
                                                                                                                                                                                      3. Raspberry Pi Pico with soldered headers
                                                                                                                                                                                      4. +
                                                                                                                                                                                      5. Includes printed Vilros Get Started with MicroPython on Raspberry Pi Pico booklet
                                                                                                                                                                                      6. +
                                                                                                                                                                                      7. USB Type-A to micro cable - 1 meter
                                                                                                                                                                                      8. +
                                                                                                                                                                                      9. 3AA battery pack with micro USB connector
                                                                                                                                                                                      10. +
                                                                                                                                                                                      11. 30 × Jumper wires
                                                                                                                                                                                      12. +
                                                                                                                                                                                      13. 12 LEDs: 3x red, 3x blue,3x yellow and 3x green
                                                                                                                                                                                      14. +
                                                                                                                                                                                      15. 5 Push-button switches
                                                                                                                                                                                      16. +
                                                                                                                                                                                      17. 10 330 Ω resistors
                                                                                                                                                                                      18. +
                                                                                                                                                                                      19. Piezoelectric buzzer
                                                                                                                                                                                      20. +
                                                                                                                                                                                      21. 2 10 kΩ potentiometers
                                                                                                                                                                                      22. +
                                                                                                                                                                                      23. HC-SR501 PIR sensor
                                                                                                                                                                                      24. +
                                                                                                                                                                                      25. I2C 1602 character LCD module
                                                                                                                                                                                      26. +
                                                                                                                                                                                      27. WS2812B LED strip
                                                                                                                                                                                      28. +
                                                                                                                                                                                      29. Clear hard plastic box for small part storage
                                                                                                                                                                                      30. +
                                                                                                                                                                                      31. Neoprene case With pocket
                                                                                                                                                                                      32. +
                                                                                                                                                                                      33. Raspberry Pi Pico pinout guide
                                                                                                                                                                                      34. +
                                                                                                                                                                                      +

                                                                                                                                                                                      The only problem with the parts is the lack of connectors for the potentiometers don't work well directly on the breadboard. You will need to solder wires to use them on the breadboard.

                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      + + + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                      + Debugging SPI +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + + +
                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                      + Introduction +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/kits/larson-scanner/01-intro/index.html b/kits/larson-scanner/01-intro/index.html new file mode 100644 index 000000000..f9b957c95 --- /dev/null +++ b/kits/larson-scanner/01-intro/index.html @@ -0,0 +1,2158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Larson Scanner Pumpkin - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + +
                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + Larson Scanner Pumpkin + + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      + + +
                                                                                                                                                                                      + +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      +
                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                      +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                          + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + +
                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + Larson Scanner Pumpkin + + + + + + + +
                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                              • + + + Parts List + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + Sample Code + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + Adding Some Color + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + Adding the Cylon Scanner Sounds + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + More to Explore + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + +
                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + MicroBit + + + + +
                                                                                                                                                                                          • + + + + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                        • + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                        • + + + Parts List + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + Sample Code + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + Adding Some Color + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + Adding the Cylon Scanner Sounds + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        • + + + More to Explore + + + +
                                                                                                                                                                                        • + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                        Larson Scanner Pumpkin

                                                                                                                                                                                        +

                                                                                                                                                                                        Larson Scanner Cylon Pumpkin

                                                                                                                                                                                        +

                                                                                                                                                                                        The Larson Scanner is a light pattern special effect named after Glen A. Larson. Larson used this pattern to give his Battlestar Galactica Cylon and KITT robot eyes a sense of sentience. See Knight Rider for the backstory.

                                                                                                                                                                                        +

                                                                                                                                                                                        This project uses a 144 pixel/meter LED strip and a Raspberry Pi Pico to produce this effect.

                                                                                                                                                                                        +

                                                                                                                                                                                        Craft Pumpkin +I used a craft pumpkin from Michaels. I cut a slit in it and used hot-glue to hold the LED strip in place.

                                                                                                                                                                                        +

                                                                                                                                                                                        Parts List

                                                                                                                                                                                        +
                                                                                                                                                                                          +
                                                                                                                                                                                        1. 9" Craft Pumpkin from Micheals $10
                                                                                                                                                                                        2. +
                                                                                                                                                                                        3. Raspberry Pi Pico ($4)
                                                                                                                                                                                        4. +
                                                                                                                                                                                        5. Breadboard ($2)
                                                                                                                                                                                        6. +
                                                                                                                                                                                        7. 27 pixels of WS2811B NeoPixel Strip 144 pixels per meter preferred ($8)
                                                                                                                                                                                        8. +
                                                                                                                                                                                        9. 3 AA battery pack or a USB battery pack
                                                                                                                                                                                        10. +
                                                                                                                                                                                        +

                                                                                                                                                                                        WS2811b 144 +This is a screen image from e-bay showing a 1/2 meter of LED strip for $8.

                                                                                                                                                                                        +

                                                                                                                                                                                        Sample Code

                                                                                                                                                                                        +

                                                                                                                                                                                        This code shows a five-pixel wide "eye" moving back-an-forth over a 27 pixel strip. There is a central bright red LED surrounded by dimmer red LEDs that move back-and-forth. We are using the NeoPixel library supplied by Blaž Rolih.

                                                                                                                                                                                        +

                                                                                                                                                                                        The example below has a delay of 1/10th of a second between drawing events. You can make the delay smaller to speed up the speed of the eye movement.

                                                                                                                                                                                        +
                                                                                                                                                                                         1
                                                                                                                                                                                        + 2
                                                                                                                                                                                        + 3
                                                                                                                                                                                        + 4
                                                                                                                                                                                        + 5
                                                                                                                                                                                        + 6
                                                                                                                                                                                        + 7
                                                                                                                                                                                        + 8
                                                                                                                                                                                        + 9
                                                                                                                                                                                        +10
                                                                                                                                                                                        +11
                                                                                                                                                                                        +12
                                                                                                                                                                                        +13
                                                                                                                                                                                        +14
                                                                                                                                                                                        +15
                                                                                                                                                                                        +16
                                                                                                                                                                                        +17
                                                                                                                                                                                        +18
                                                                                                                                                                                        +19
                                                                                                                                                                                        +20
                                                                                                                                                                                        +21
                                                                                                                                                                                        +22
                                                                                                                                                                                        +23
                                                                                                                                                                                        +24
                                                                                                                                                                                        +25
                                                                                                                                                                                        +26
                                                                                                                                                                                        +27
                                                                                                                                                                                        +28
                                                                                                                                                                                        +29
                                                                                                                                                                                        +30
                                                                                                                                                                                        +31
                                                                                                                                                                                        +32
                                                                                                                                                                                        +33
                                                                                                                                                                                        +34
                                                                                                                                                                                        +35
                                                                                                                                                                                        +36
                                                                                                                                                                                        from utime import sleep
                                                                                                                                                                                        +# We are using https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                        +from neopixel import Neopixel
                                                                                                                                                                                        +
                                                                                                                                                                                        +NUMBER_PIXELS = 27
                                                                                                                                                                                        +STATE_MACHINE = 0
                                                                                                                                                                                        +LED_PIN = 0
                                                                                                                                                                                        +
                                                                                                                                                                                        +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                        +
                                                                                                                                                                                        +# Color RGB values
                                                                                                                                                                                        +red = (255, 0, 0)
                                                                                                                                                                                        +red_med = (32, 0, 0)
                                                                                                                                                                                        +red_light = (8, 0, 0)
                                                                                                                                                                                        +off = (0,0,0)
                                                                                                                                                                                        +
                                                                                                                                                                                        +delay = .1
                                                                                                                                                                                        +while True:
                                                                                                                                                                                        +    for i in range(2, NUMBER_PIXELS-2):
                                                                                                                                                                                        +        strip.set_pixel(i-2, red_light)
                                                                                                                                                                                        +        strip.set_pixel(i-1, red_med)
                                                                                                                                                                                        +        strip.set_pixel(i, red)
                                                                                                                                                                                        +        strip.set_pixel(i+1, red_med)
                                                                                                                                                                                        +        strip.set_pixel(i+2, red_light)
                                                                                                                                                                                        +        if i > 0: strip.set_pixel(i-3, off)
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +    for i in range(NUMBER_PIXELS-4, 1, -1):
                                                                                                                                                                                        +        if i < NUMBER_PIXELS-2: strip.set_pixel(i+3, off)
                                                                                                                                                                                        +        strip.set_pixel(i-2, red_light)
                                                                                                                                                                                        +        strip.set_pixel(i-1, red_med)
                                                                                                                                                                                        +        strip.set_pixel(i, red)
                                                                                                                                                                                        +        strip.set_pixel(i+1, red_med)
                                                                                                                                                                                        +        strip.set_pixel(i+2, red_light)
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +
                                                                                                                                                                                        +

                                                                                                                                                                                        Adding Some Color

                                                                                                                                                                                        +

                                                                                                                                                                                        The pattern above is faithful to the original Cylon robot pattern, but to be honest, it is a little boring. We can spruce it up a bit by adding some color and the comet-tail pattern.

                                                                                                                                                                                        + + +

                                                                                                                                                                                        This program cycles through a "moving rainbow" pattern and then the comet pattern for 10 colors.

                                                                                                                                                                                        +
                                                                                                                                                                                         1
                                                                                                                                                                                        + 2
                                                                                                                                                                                        + 3
                                                                                                                                                                                        + 4
                                                                                                                                                                                        + 5
                                                                                                                                                                                        + 6
                                                                                                                                                                                        + 7
                                                                                                                                                                                        + 8
                                                                                                                                                                                        + 9
                                                                                                                                                                                        +10
                                                                                                                                                                                        +11
                                                                                                                                                                                        +12
                                                                                                                                                                                        +13
                                                                                                                                                                                        +14
                                                                                                                                                                                        +15
                                                                                                                                                                                        +16
                                                                                                                                                                                        +17
                                                                                                                                                                                        +18
                                                                                                                                                                                        +19
                                                                                                                                                                                        +20
                                                                                                                                                                                        +21
                                                                                                                                                                                        +22
                                                                                                                                                                                        +23
                                                                                                                                                                                        +24
                                                                                                                                                                                        +25
                                                                                                                                                                                        +26
                                                                                                                                                                                        +27
                                                                                                                                                                                        +28
                                                                                                                                                                                        +29
                                                                                                                                                                                        +30
                                                                                                                                                                                        +31
                                                                                                                                                                                        +32
                                                                                                                                                                                        +33
                                                                                                                                                                                        +34
                                                                                                                                                                                        +35
                                                                                                                                                                                        +36
                                                                                                                                                                                        +37
                                                                                                                                                                                        +38
                                                                                                                                                                                        +39
                                                                                                                                                                                        +40
                                                                                                                                                                                        +41
                                                                                                                                                                                        +42
                                                                                                                                                                                        +43
                                                                                                                                                                                        +44
                                                                                                                                                                                        +45
                                                                                                                                                                                        +46
                                                                                                                                                                                        +47
                                                                                                                                                                                        +48
                                                                                                                                                                                        +49
                                                                                                                                                                                        +50
                                                                                                                                                                                        +51
                                                                                                                                                                                        +52
                                                                                                                                                                                        +53
                                                                                                                                                                                        +54
                                                                                                                                                                                        +55
                                                                                                                                                                                        +56
                                                                                                                                                                                        +57
                                                                                                                                                                                        +58
                                                                                                                                                                                        +59
                                                                                                                                                                                        +60
                                                                                                                                                                                        +61
                                                                                                                                                                                        +62
                                                                                                                                                                                        +63
                                                                                                                                                                                        +64
                                                                                                                                                                                        +65
                                                                                                                                                                                        +66
                                                                                                                                                                                        +67
                                                                                                                                                                                        +68
                                                                                                                                                                                        +69
                                                                                                                                                                                        +70
                                                                                                                                                                                        +71
                                                                                                                                                                                        +72
                                                                                                                                                                                        +73
                                                                                                                                                                                        +74
                                                                                                                                                                                        +75
                                                                                                                                                                                        +76
                                                                                                                                                                                        +77
                                                                                                                                                                                        +78
                                                                                                                                                                                        +79
                                                                                                                                                                                        +80
                                                                                                                                                                                        +81
                                                                                                                                                                                        +82
                                                                                                                                                                                        +83
                                                                                                                                                                                        +84
                                                                                                                                                                                        +85
                                                                                                                                                                                        +86
                                                                                                                                                                                        from utime import sleep
                                                                                                                                                                                        +# We are using https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                        +from neopixel import Neopixel
                                                                                                                                                                                        +
                                                                                                                                                                                        +NUMBER_PIXELS = 25
                                                                                                                                                                                        +STATE_MACHINE = 0
                                                                                                                                                                                        +LED_PIN = 0
                                                                                                                                                                                        +
                                                                                                                                                                                        +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                        +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                        +
                                                                                                                                                                                        +# Color RGB values
                                                                                                                                                                                        +red = (255, 0, 0)
                                                                                                                                                                                        +off = (0,0,0)
                                                                                                                                                                                        +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                        +yellow = (255, 150, 0)
                                                                                                                                                                                        +green = (0, 255, 0)
                                                                                                                                                                                        +blue = (0, 0, 255)
                                                                                                                                                                                        +cyan = (255, 0, 255)
                                                                                                                                                                                        +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                        +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                        +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')
                                                                                                                                                                                        +num_colors = len(color_names)
                                                                                                                                                                                        +colors = (red, orange, yellow, green, blue, indigo, violet)
                                                                                                                                                                                        +
                                                                                                                                                                                        +# set to be 1 to 100 for percent brightness
                                                                                                                                                                                        +strip.brightness(100)
                                                                                                                                                                                        +
                                                                                                                                                                                        +def draw_eye_7(r, g, b):
                                                                                                                                                                                        +    for i in range(6, NUMBER_PIXELS): 
                                                                                                                                                                                        +        strip.set_pixel(i, (r, g, b))
                                                                                                                                                                                        +        # step back from the current to 6 back halfing the intensity each time
                                                                                                                                                                                        +        for j in range(0,7):
                                                                                                                                                                                        +            strip.set_pixel(i-j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j))))
                                                                                                                                                                                        +        if i > 6: strip.set_pixel(i-7, (0,0,0))
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +        strip.set_pixel(i, off)
                                                                                                                                                                                        +    for i in range(NUMBER_PIXELS-6, 0, -1):
                                                                                                                                                                                        +        strip.set_pixel(i, (r, g, b)) 
                                                                                                                                                                                        +        for j in range(7,0):
                                                                                                                                                                                        +            strip.set_pixel(i+j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j))))
                                                                                                                                                                                        +        if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0))
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +
                                                                                                                                                                                        +def draw_rainbow():
                                                                                                                                                                                        +    for i in range(0, NUMBER_PIXELS-7):
                                                                                                                                                                                        +        strip.set_pixel(i, violet)
                                                                                                                                                                                        +        strip.set_pixel(i+1, indigo)
                                                                                                                                                                                        +        strip.set_pixel(i+2, blue)
                                                                                                                                                                                        +        strip.set_pixel(i+3, green)
                                                                                                                                                                                        +        strip.set_pixel(i+4, yellow)
                                                                                                                                                                                        +        strip.set_pixel(i+5,orange)
                                                                                                                                                                                        +        strip.set_pixel(i+6, red)
                                                                                                                                                                                        +        if i > 6: strip.set_pixel(i-7, (0,0,0))
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +        strip.set_pixel(i, off)
                                                                                                                                                                                        +    for i in range(NUMBER_PIXELS-7, 1, -1):
                                                                                                                                                                                        +        strip.set_pixel(i, red)
                                                                                                                                                                                        +        strip.set_pixel(i+1, orange)
                                                                                                                                                                                        +        strip.set_pixel(i+2, yellow)
                                                                                                                                                                                        +        strip.set_pixel(i+3, green)
                                                                                                                                                                                        +        strip.set_pixel(i+4, blue)
                                                                                                                                                                                        +        strip.set_pixel(i+5, indigo)
                                                                                                                                                                                        +        strip.set_pixel(i+6, violet)
                                                                                                                                                                                        +        if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0))
                                                                                                                                                                                        +        strip.show()
                                                                                                                                                                                        +        sleep(delay)
                                                                                                                                                                                        +
                                                                                                                                                                                        +# delay = .031
                                                                                                                                                                                        +
                                                                                                                                                                                        +delay = .06
                                                                                                                                                                                        +color_index = 0
                                                                                                                                                                                        +while True:
                                                                                                                                                                                        +    draw_rainbow()
                                                                                                                                                                                        +    draw_eye_7(255,0,0) #red
                                                                                                                                                                                        +    draw_eye_7(255,60,0) #orange
                                                                                                                                                                                        +    draw_eye_7(255,255,0) # yellow
                                                                                                                                                                                        +    draw_eye_7(0,255,0) # green
                                                                                                                                                                                        +    draw_eye_7(0,0,255) # b;ie
                                                                                                                                                                                        +    draw_eye_7(0,255,255) # cyan
                                                                                                                                                                                        +    draw_eye_7(75,30,130) # indigo
                                                                                                                                                                                        +    draw_eye_7(255,0,255) # violet
                                                                                                                                                                                        +    draw_eye_7(255,255,255) # white
                                                                                                                                                                                        +
                                                                                                                                                                                        +

                                                                                                                                                                                        Adding the Cylon Scanner Sounds

                                                                                                                                                                                        +

                                                                                                                                                                                        You can also add the Cylon eye scanner sound by addint a .wav file to the pico and using the playWave library. This is covered in the Sound and Music Play Audio File lesson of this microsite.

                                                                                                                                                                                        +

                                                                                                                                                                                        More to Explore

                                                                                                                                                                                        +
                                                                                                                                                                                          +
                                                                                                                                                                                        1. Add a potentiometer to change the speed of the eye scan.
                                                                                                                                                                                        2. +
                                                                                                                                                                                        3. Add a button to cycle through colors of the eye.
                                                                                                                                                                                        4. +
                                                                                                                                                                                        5. Add multiple patterns such as a "comet trail" that has the first pixel brighter and the following pixels dimmer.
                                                                                                                                                                                        6. +
                                                                                                                                                                                        7. Add a PIR motion sensor that will sense motion and get brighter if motion is sensed.
                                                                                                                                                                                        8. +
                                                                                                                                                                                        9. Use the new I2S software to play a sound when the PIR motion sensor has been triggered.
                                                                                                                                                                                        10. +
                                                                                                                                                                                        11. Use an MP3 player such as the DRF0229 to play the cylon sound when motion is detected.
                                                                                                                                                                                        12. +
                                                                                                                                                                                        13. Add an OLED display and buttons to the back of the pumpkin to change the parameters of the display and the sounds.
                                                                                                                                                                                        14. +
                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        + + + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                        + SD Card Reader +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + + +
                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                        + Introduction +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-nano-rp2040/01-intro/index.html b/kits/maker-nano-rp2040/01-intro/index.html new file mode 100644 index 000000000..3998496c3 --- /dev/null +++ b/kits/maker-nano-rp2040/01-intro/index.html @@ -0,0 +1,1347 @@ + + + + + + + + + + + + + + + + + + + + + + + Cytron Maker Nano RP2040 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + +
                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + Cytron Maker Nano RP2040 + + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        + + +
                                                                                                                                                                                        + +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        +
                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                        +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + + +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                          • + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                          • + + + features + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          • + + + Blink Lab + + + +
                                                                                                                                                                                          • + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                          Cytron Maker Nano RP2040

                                                                                                                                                                                          +

                                                                                                                                                                                          The Cytron Nano RP2040 is a low-cost ($9), high-functionality board.

                                                                                                                                                                                          +

                                                                                                                                                                                          features

                                                                                                                                                                                          +
                                                                                                                                                                                            +
                                                                                                                                                                                          1. Low cost: $9
                                                                                                                                                                                          2. +
                                                                                                                                                                                          3. 14 GPIO blue LEDs
                                                                                                                                                                                          4. +
                                                                                                                                                                                          5. 2 RGB LEDs (Neopixels)
                                                                                                                                                                                          6. +
                                                                                                                                                                                          7. 1 Piezo buzzer
                                                                                                                                                                                          8. +
                                                                                                                                                                                          9. 2 4-wire JST-SH ports (with Grove connectors)
                                                                                                                                                                                          10. +
                                                                                                                                                                                          +

                                                                                                                                                                                          +

                                                                                                                                                                                          Blink Lab

                                                                                                                                                                                          +
                                                                                                                                                                                           1
                                                                                                                                                                                          + 2
                                                                                                                                                                                          + 3
                                                                                                                                                                                          + 4
                                                                                                                                                                                          + 5
                                                                                                                                                                                          + 6
                                                                                                                                                                                          + 7
                                                                                                                                                                                          + 8
                                                                                                                                                                                          + 9
                                                                                                                                                                                          +10
                                                                                                                                                                                          +11
                                                                                                                                                                                          from machine import Pin # get the Pin function from the machine module
                                                                                                                                                                                          +from time import sleep # get the sleep library from the time module
                                                                                                                                                                                          +# this is the built-in green LED on the Pico
                                                                                                                                                                                          +led = machine.Pin(0, machine.Pin.OUT)
                                                                                                                                                                                          +
                                                                                                                                                                                          +# repeat forever
                                                                                                                                                                                          +while True:
                                                                                                                                                                                          +    led.high() # turn on the LED
                                                                                                                                                                                          +    sleep(0.5) # leave it on for 1/2 second
                                                                                                                                                                                          +    led.low() # Turn off the LED
                                                                                                                                                                                          +    sleep(0.5) # leave it off for 1/2 second
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/docs/kits/maker-nano-rp2040/Cytron-Nano-RP2040-Figures.pptx b/kits/maker-nano-rp2040/Cytron-Nano-RP2040-Figures.pptx similarity index 100% rename from docs/kits/maker-nano-rp2040/Cytron-Nano-RP2040-Figures.pptx rename to kits/maker-nano-rp2040/Cytron-Nano-RP2040-Figures.pptx diff --git a/kits/maker-pi-pico/02-running-lights/index.html b/kits/maker-pi-pico/02-running-lights/index.html new file mode 100644 index 000000000..93745a265 --- /dev/null +++ b/kits/maker-pi-pico/02-running-lights/index.html @@ -0,0 +1,1884 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Running Lights - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + +
                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + Running Lights + + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          + + +
                                                                                                                                                                                          + +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          +
                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                          +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                              + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + +
                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                + + + + + Maker Pi Pico + + + + + + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                  + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + Running Lights + + + + + + + +
                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                  • + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + SD Card Reader + + + + +
                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + MicroBit + + + + +
                                                                                                                                                                                              • + + + + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                            • + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                            • + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                            Running lights

                                                                                                                                                                                            +

                                                                                                                                                                                            This program turns on all 24 blue LEDs on the board, one at a time. It then turns them all off.

                                                                                                                                                                                            +

                                                                                                                                                                                            TODO - record a GIF or video.

                                                                                                                                                                                            +
                                                                                                                                                                                             1
                                                                                                                                                                                            + 2
                                                                                                                                                                                            + 3
                                                                                                                                                                                            + 4
                                                                                                                                                                                            + 5
                                                                                                                                                                                            + 6
                                                                                                                                                                                            + 7
                                                                                                                                                                                            + 8
                                                                                                                                                                                            + 9
                                                                                                                                                                                            +10
                                                                                                                                                                                            +11
                                                                                                                                                                                            +12
                                                                                                                                                                                            +13
                                                                                                                                                                                            +14
                                                                                                                                                                                            +15
                                                                                                                                                                                            +16
                                                                                                                                                                                            +17
                                                                                                                                                                                            +18
                                                                                                                                                                                            +19
                                                                                                                                                                                            +20
                                                                                                                                                                                            +21
                                                                                                                                                                                            import machine
                                                                                                                                                                                            +import utime
                                                                                                                                                                                            +
                                                                                                                                                                                            +# RUNNING LIGHT
                                                                                                                                                                                            +
                                                                                                                                                                                            +for i in range(29):                     # from 0 to 28  
                                                                                                                                                                                            +    if i != 23 and i != 24:             # pin 23 and 24 are not GPIO pins
                                                                                                                                                                                            +        machine.Pin(i,machine.Pin.OUT)  # set the pins to output
                                                                                                                                                                                            +
                                                                                                                                                                                            +while True:
                                                                                                                                                                                            +    for i in range(29):                      
                                                                                                                                                                                            +        if i != 23 and i != 24:      
                                                                                                                                                                                            +            machine.Pin(i).value(0)     # turn off the LED
                                                                                                                                                                                            +            utime.sleep(0.1)            # sleep for 100ms
                                                                                                                                                                                            +            machine.Pin(i).value(1)     # turn on the LED
                                                                                                                                                                                            +
                                                                                                                                                                                            +    for i in range(28,-1,-1):           # from 28 to 0
                                                                                                                                                                                            +        if i != 23 and i != 24:
                                                                                                                                                                                            +            machine.Pin(i).value(1)     # turn on the LED
                                                                                                                                                                                            +            utime.sleep(0.1)
                                                                                                                                                                                            +            machine.Pin(i).value(0)     # turn off the LED
                                                                                                                                                                                            +
                                                                                                                                                                                            +

                                                                                                                                                                                            References

                                                                                                                                                                                            +

                                                                                                                                                                                            This program was taken from tje Cytron GitHub site here.

                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            + + + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                            + Introduction +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + + +
                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                            + SD Card Reader +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-pico/09-micro-sd-card-reader/index.html b/kits/maker-pi-pico/09-micro-sd-card-reader/index.html new file mode 100644 index 000000000..7edbf9ff1 --- /dev/null +++ b/kits/maker-pi-pico/09-micro-sd-card-reader/index.html @@ -0,0 +1,2074 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + SD Card Reader - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + +
                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + SD Card Reader + + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            + + +
                                                                                                                                                                                            + +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            +
                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                            +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                  + + + + + Maker Pi Pico + + + + + + + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + Running Lights + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + SD Card Reader + + + + + + + +
                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                    • + + + Maker Pi Pico Connections + + + +
                                                                                                                                                                                                    • + +
                                                                                                                                                                                                    • + + + Maker Pi Pico Example Code + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                      • + + + Pin Definitions + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      • + + + Sample Code for SPI Mode + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                    • + +
                                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                                    • + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + MicroBit + + + + +
                                                                                                                                                                                                • + + + + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                              • + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                              • + + + Maker Pi Pico Connections + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + Maker Pi Pico Example Code + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                • + + + Pin Definitions + + + +
                                                                                                                                                                                                • + +
                                                                                                                                                                                                • + + + Sample Code for SPI Mode + + + +
                                                                                                                                                                                                • + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                              • + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                              Micro SD Card Reader

                                                                                                                                                                                              +

                                                                                                                                                                                              Secure Digital (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices.

                                                                                                                                                                                              +

                                                                                                                                                                                              On Microcontrollers SD cards are usually access through an SPI interface although there are also devices that use I2C interfaces.

                                                                                                                                                                                              +

                                                                                                                                                                                              Maker Pi Pico Connections

                                                                                                                                                                                              + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              GPIO PinSD ModeSPI Mode
                                                                                                                                                                                              GP10CLKSCK
                                                                                                                                                                                              GP11CMDSDI
                                                                                                                                                                                              GP12DAT0SD0
                                                                                                                                                                                              GP13DAT1X
                                                                                                                                                                                              GP14DAT2X
                                                                                                                                                                                              GP15CD/DAT3CSn
                                                                                                                                                                                              +

                                                                                                                                                                                              Maker Pi Pico Example Code

                                                                                                                                                                                              +

                                                                                                                                                                                              Pin Definitions

                                                                                                                                                                                              +
                                                                                                                                                                                               1
                                                                                                                                                                                              + 2
                                                                                                                                                                                              + 3
                                                                                                                                                                                              + 4
                                                                                                                                                                                              + 5
                                                                                                                                                                                              + 6
                                                                                                                                                                                              + 7
                                                                                                                                                                                              + 8
                                                                                                                                                                                              + 9
                                                                                                                                                                                              +10
                                                                                                                                                                                              +11
                                                                                                                                                                                              +12
                                                                                                                                                                                              +13
                                                                                                                                                                                              +14
                                                                                                                                                                                              +15
                                                                                                                                                                                              # SD Mode Definitions
                                                                                                                                                                                              +SDCARD_CLK = 10
                                                                                                                                                                                              +SDCARD_CMD = 11
                                                                                                                                                                                              +SDCARD_DAT0 = 12
                                                                                                                                                                                              +SDCARD_DAT1 = 13
                                                                                                                                                                                              +SDCARD_DAT2 = 14
                                                                                                                                                                                              +SDCARD_CD_DAT3 = 15
                                                                                                                                                                                              +
                                                                                                                                                                                              +# SPI Mode Definitions
                                                                                                                                                                                              +SDCARD_SCK = 10
                                                                                                                                                                                              +SDCARD_SDI = 11
                                                                                                                                                                                              +SDCARD_SD0 = 12
                                                                                                                                                                                              +SDCARD_X1 = 13
                                                                                                                                                                                              +SDCARD_X2 = 14
                                                                                                                                                                                              +SDCARD_CSn = 15
                                                                                                                                                                                              +
                                                                                                                                                                                              +

                                                                                                                                                                                              Sample Code for SPI Mode

                                                                                                                                                                                              +
                                                                                                                                                                                               1
                                                                                                                                                                                              + 2
                                                                                                                                                                                              + 3
                                                                                                                                                                                              + 4
                                                                                                                                                                                              + 5
                                                                                                                                                                                              + 6
                                                                                                                                                                                              + 7
                                                                                                                                                                                              + 8
                                                                                                                                                                                              + 9
                                                                                                                                                                                              +10
                                                                                                                                                                                              +11
                                                                                                                                                                                              +12
                                                                                                                                                                                              +13
                                                                                                                                                                                              +14
                                                                                                                                                                                              +15
                                                                                                                                                                                              +16
                                                                                                                                                                                              +17
                                                                                                                                                                                              +18
                                                                                                                                                                                              +19
                                                                                                                                                                                              +20
                                                                                                                                                                                              +21
                                                                                                                                                                                              +22
                                                                                                                                                                                              +23
                                                                                                                                                                                              +24
                                                                                                                                                                                              +25
                                                                                                                                                                                              +26
                                                                                                                                                                                              +27
                                                                                                                                                                                              +28
                                                                                                                                                                                              +29
                                                                                                                                                                                              +30
                                                                                                                                                                                              +31
                                                                                                                                                                                              +32
                                                                                                                                                                                              import machine, os, sdcard
                                                                                                                                                                                              +
                                                                                                                                                                                              +# Assign chip select (CS) pin (and start it high)
                                                                                                                                                                                              +cs = machine.Pin(15, machine.Pin.OUT)
                                                                                                                                                                                              +# Intialize SPI peripheral (start with 1 MHz)
                                                                                                                                                                                              +spi = machine.SPI(1,
                                                                                                                                                                                              +                  baudrate=1000000,
                                                                                                                                                                                              +                  polarity=0,
                                                                                                                                                                                              +                  phase=0,
                                                                                                                                                                                              +                  bits=8,
                                                                                                                                                                                              +                  firstbit=machine.SPI.MSB,
                                                                                                                                                                                              +                  sck=machine.Pin(10),
                                                                                                                                                                                              +                  mosi=machine.Pin(11),
                                                                                                                                                                                              +                  miso=machine.Pin(12))
                                                                                                                                                                                              +# Initialize SD card
                                                                                                                                                                                              +sd = sdcard.SDCard(spi, cs)
                                                                                                                                                                                              +
                                                                                                                                                                                              +# OR this simpler initialization code should works on Maker Pi Pico too...
                                                                                                                                                                                              +#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
                                                                                                                                                                                              +
                                                                                                                                                                                              +os.mount(sd, '/sd')
                                                                                                                                                                                              +# check the content
                                                                                                                                                                                              +os.listdir('/sd')
                                                                                                                                                                                              +
                                                                                                                                                                                              +# try some standard file operations
                                                                                                                                                                                              +file = open('/sd/test.txt', 'w')
                                                                                                                                                                                              +file.write('Testing SD card on Maker Pi Pico')
                                                                                                                                                                                              +file.close()
                                                                                                                                                                                              +file = open('/sd/test.txt', 'r')
                                                                                                                                                                                              +data = file.read()
                                                                                                                                                                                              +print(data)
                                                                                                                                                                                              +file.close()
                                                                                                                                                                                              +
                                                                                                                                                                                              +

                                                                                                                                                                                              Results:

                                                                                                                                                                                              +
                                                                                                                                                                                              1
                                                                                                                                                                                              Testing SD card on Maker Pi Pico
                                                                                                                                                                                              +
                                                                                                                                                                                              +

                                                                                                                                                                                              References

                                                                                                                                                                                              +
                                                                                                                                                                                                +
                                                                                                                                                                                              1. MicroPython sdcard.py driver - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266
                                                                                                                                                                                              2. +
                                                                                                                                                                                              3. MicroPython.org Documentation
                                                                                                                                                                                              4. +
                                                                                                                                                                                              5. Raspberry Pi Pico Forum
                                                                                                                                                                                              6. +
                                                                                                                                                                                              7. YouTube Video by Shawn Hymel
                                                                                                                                                                                              8. +
                                                                                                                                                                                              9. Cytron Maker Pi Pico Datasheet
                                                                                                                                                                                              10. +
                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              + + + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                              + Running Lights +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + + +
                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                              + Larson Scanner Pumpkin +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-pico/index.html b/kits/maker-pi-pico/index.html new file mode 100644 index 000000000..9e64a02b9 --- /dev/null +++ b/kits/maker-pi-pico/index.html @@ -0,0 +1,1811 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + +
                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + Introduction + + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              + + +
                                                                                                                                                                                              + +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              +
                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                              +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                  + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                    + + + + + Maker Pi Pico + + + + + + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                      + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + Running Lights + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + SD Card Reader + + + + +
                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + MicroBit + + + + +
                                                                                                                                                                                                  • + + + + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                • + + + Sample Labs + + + +
                                                                                                                                                                                                • + +
                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                • + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                Cytron Maker Pi Pico

                                                                                                                                                                                                +

                                                                                                                                                                                                The Cytron Maker Pi Pico is a $9.99 breakout board for the Raspberry Pi Pico with many features.

                                                                                                                                                                                                +
                                                                                                                                                                                                  +
                                                                                                                                                                                                1. Speaker
                                                                                                                                                                                                2. +
                                                                                                                                                                                                3. Stereo headphone jacks
                                                                                                                                                                                                4. +
                                                                                                                                                                                                5. SD Card reader
                                                                                                                                                                                                6. +
                                                                                                                                                                                                +

                                                                                                                                                                                                Sample Labs

                                                                                                                                                                                                +
                                                                                                                                                                                                  +
                                                                                                                                                                                                1. Running Lights
                                                                                                                                                                                                2. +
                                                                                                                                                                                                3. SD Card File Reader/Writer
                                                                                                                                                                                                4. +
                                                                                                                                                                                                +

                                                                                                                                                                                                References

                                                                                                                                                                                                +

                                                                                                                                                                                                Cytron Maker Pi Pico Github Repo

                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                + + + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                + Line Follower +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                + Running Lights +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/02-assembly/index.html b/kits/maker-pi-rp2040-robot/02-assembly/index.html new file mode 100644 index 000000000..d69f0d8a9 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/02-assembly/index.html @@ -0,0 +1,2169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Assembly - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + +
                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + Assembly + + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                + + +
                                                                                                                                                                                                + +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                +
                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                    + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                      + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                        + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + Assembly + + + + + + + +
                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                        • + + + Assemble the SmartCar Chassis + + + +
                                                                                                                                                                                                        • + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Square Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Line Follower + + + + +
                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + MicroBit + + + + +
                                                                                                                                                                                                    • + + + + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                  • + + + Assemble the SmartCar Chassis + + + +
                                                                                                                                                                                                  • + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                  Assembling Your Maker Pi RP2040 Robot

                                                                                                                                                                                                  +

                                                                                                                                                                                                  This kit is a $25 robot kit that we will use in our CoderDojo robotics classes. This kit includes:

                                                                                                                                                                                                  +
                                                                                                                                                                                                    +
                                                                                                                                                                                                  1. A SmartCar Chassis
                                                                                                                                                                                                      +
                                                                                                                                                                                                    1. Two 3 to 6-volt DC geared hobby motors and wheels
                                                                                                                                                                                                    2. +
                                                                                                                                                                                                    3. Plexiglass (acrylic) main-board
                                                                                                                                                                                                    4. +
                                                                                                                                                                                                    5. Screws and nuts
                                                                                                                                                                                                    6. +
                                                                                                                                                                                                    7. 4 AA battery pack
                                                                                                                                                                                                    8. +
                                                                                                                                                                                                    9. Power switch
                                                                                                                                                                                                    10. +
                                                                                                                                                                                                    +
                                                                                                                                                                                                  2. +
                                                                                                                                                                                                  3. Cytron Maker Pi RP2040 kit
                                                                                                                                                                                                      +
                                                                                                                                                                                                    1. Maker Pi RP2040 board
                                                                                                                                                                                                    2. +
                                                                                                                                                                                                    3. 4x Grove to female header cables
                                                                                                                                                                                                    4. +
                                                                                                                                                                                                    5. Screwdriver
                                                                                                                                                                                                    6. +
                                                                                                                                                                                                    7. Silicone rubber feet (pack of 4)
                                                                                                                                                                                                    8. +
                                                                                                                                                                                                    +
                                                                                                                                                                                                  4. +
                                                                                                                                                                                                  5. Ultrasonic sensor
                                                                                                                                                                                                      +
                                                                                                                                                                                                    1. mounting bracket
                                                                                                                                                                                                    2. +
                                                                                                                                                                                                    3. 2 M2 6mm screws and nuts
                                                                                                                                                                                                    4. +
                                                                                                                                                                                                    +
                                                                                                                                                                                                  6. +
                                                                                                                                                                                                  +

                                                                                                                                                                                                  You will need to provide 4 AA batteries and a Micro USB connector that works with your PC or Mac.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Assemble the SmartCar Chassis

                                                                                                                                                                                                  +

                                                                                                                                                                                                  In this version of the kit, the wires are pre-soldered onto the motors.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Here is the robot kit in all the packaging: +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Your first task is to remove the protective backing from the acrylic body. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Here are all the parts removed from the packaging: +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  We mount the motors with the wires on the inside and the heads of the bolts on the outside. + +This photo shows cable ties I have added so that the wires don't get pulled out by our students. These cable ties are optional.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, we position the battery pack on the BOTTOM so that we have more room on the top for our circuit board, sensors and add-on displays.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  I used a 1/8th inch drill bit to put holes where the battery pack should be mounted. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, I put the flat-head screws in the battery pack. We want to make sure the top of the screw is all the way in so that it does not get in the way of the battery. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, we mount the rubber feet on the bottom of the Maker Pi RP2040 circuit board so that we have some space between the PC board and the main chassis. I use the space next to the four corners to mount the feet. Note that we must put the drag wheel on before we put the PC board on top of the chassis. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, we put the four screws and spacers in the four holes at the bottom rear of the robot directly behind the battery pack. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  We then add the four screws to mount the drag wheel. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Now is a good time to check the spacing of the battery pack and the read drag wheel. The rear drag wheel must be able to spin freely in a full circle without bumping into the battery. If it bumps you might need to remount the battery pack before you proceed to the next step. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  This figure has the switch that comes with the battery pack. For our work, we will not need this switch since the Maker Pi RP2040 circuit board has an no-board power switch. Most of our students put the switch in if they ever need to change circuit boards that don't have a built-in power switch. If you do this, you can solder the switch between the red power of the battery and the positive terminal of VIN. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, line up the printed circuit board with the USB connector facing the rear. Note where the holes are in the board and drill two 1/8" holes to mount the board. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  This photo shows the holes drilled with the screws in them. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  This is the side-view from the rear of the screws holding on the circuit board. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next use two 6 mm M3 screws to mount the ultrasonic distance sensor on top front of the robot. + +Some of our students like to mount the ultrasonic sensor under the chassis and point the sensor up a little so the sensor does not reflect off the floor. You can use a heat gun to soften the plastic mount to change the angle.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next I added a drop of hot-glue under the front screws that mount the pc board. I did this because the battery pack and motor mounts get in the way of adding a nut under the board. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, I used a small rubber coated twist tie to keep the wires under the robot away from the wheels and battery. We don't want them to drag on the floor. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Next, we connect the motors up to the screw headers on the printed circuit board. There is a screwdriver that comes with the Cytron Maker Pi RP2040 that is handy for tightening the screws. + +Don't worry about getting the connections all correct. They can be adjusted in your software.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Press the wheels on the motors. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Lastly, we connect the battery to the VIN jumper, making sure to connect the red wire to the "+" terminal and the black wire to the "-" terminal. +

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Connect the Maker Pi RP2040 board to the top with the USB connector facing the rear.

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Maker Pi RP2040 Motor Connections

                                                                                                                                                                                                  +

                                                                                                                                                                                                  Here is a short video of the assembly of a SmartCar Chassis. Note that this video puts the battery on the top, where we put it on the bottom.

                                                                                                                                                                                                  + + +

                                                                                                                                                                                                  +There are many videos online how to assemble to motors to the chassis. The trick is orienting the motors correctly and making sure the bolts don't get in the way of the wheels.

                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                  + Introduction +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                  + Motor Lab +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/06-up-down-motor-lab/index.html b/kits/maker-pi-rp2040-robot/06-up-down-motor-lab/index.html new file mode 100644 index 000000000..afe8b47be --- /dev/null +++ b/kits/maker-pi-rp2040-robot/06-up-down-motor-lab/index.html @@ -0,0 +1,2415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Up/Down Motor Speed Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + Up/Down Motor Speed Lab + + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  + + +
                                                                                                                                                                                                  + +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  +
                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                  +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                      + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                        + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Assembly + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + Up/Down Motor Speed Lab + + + + + + + +
                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                          • + + + Full Program + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Square Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Line Follower + + + + +
                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + MicroBit + + + + +
                                                                                                                                                                                                      • + + + + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                    • + + + Full Program + + + +
                                                                                                                                                                                                    • + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                    Up Down Motor Speed Lab

                                                                                                                                                                                                    +

                                                                                                                                                                                                    In this lab, we will make the motor speed change as the mode changes.

                                                                                                                                                                                                    + + +
                                                                                                                                                                                                     1
                                                                                                                                                                                                    + 2
                                                                                                                                                                                                    + 3
                                                                                                                                                                                                    + 4
                                                                                                                                                                                                    + 5
                                                                                                                                                                                                    + 6
                                                                                                                                                                                                    + 7
                                                                                                                                                                                                    + 8
                                                                                                                                                                                                    + 9
                                                                                                                                                                                                    +10
                                                                                                                                                                                                    +11
                                                                                                                                                                                                    +12
                                                                                                                                                                                                    +13
                                                                                                                                                                                                    +14
                                                                                                                                                                                                    +15
                                                                                                                                                                                                    +16
                                                                                                                                                                                                    +17
                                                                                                                                                                                                    +18
                                                                                                                                                                                                    +19
                                                                                                                                                                                                    # Motor Setup
                                                                                                                                                                                                    +# motors just barely turn at this power level
                                                                                                                                                                                                    +MIN_POWER_LEVEL = 10000
                                                                                                                                                                                                    +MAX_POWER_LEVEL = 65025
                                                                                                                                                                                                    +POWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10)
                                                                                                                                                                                                    +# lower right pins with USB on top
                                                                                                                                                                                                    +RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                    +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                    +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                    +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                    +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                    +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                    +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +def drive_speed(power_level):
                                                                                                                                                                                                    +    right_forward.duty_u16(power_level)
                                                                                                                                                                                                    +    left_forward.duty_u16(power_level)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +

                                                                                                                                                                                                    In the main we have:

                                                                                                                                                                                                    +
                                                                                                                                                                                                    1
                                                                                                                                                                                                    +2
                                                                                                                                                                                                    +3
                                                                                                                                                                                                    +4
                                                                                                                                                                                                    power_level = MIN_POWER_LEVEL + mode * POWER_STEP
                                                                                                                                                                                                    +# turn off the motor if we are at mode 0
                                                                                                                                                                                                    +if mode == 0: power_level = 0
                                                                                                                                                                                                    +drive_speed(power_level)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +

                                                                                                                                                                                                    Full Program

                                                                                                                                                                                                    +
                                                                                                                                                                                                      1
                                                                                                                                                                                                    +  2
                                                                                                                                                                                                    +  3
                                                                                                                                                                                                    +  4
                                                                                                                                                                                                    +  5
                                                                                                                                                                                                    +  6
                                                                                                                                                                                                    +  7
                                                                                                                                                                                                    +  8
                                                                                                                                                                                                    +  9
                                                                                                                                                                                                    + 10
                                                                                                                                                                                                    + 11
                                                                                                                                                                                                    + 12
                                                                                                                                                                                                    + 13
                                                                                                                                                                                                    + 14
                                                                                                                                                                                                    + 15
                                                                                                                                                                                                    + 16
                                                                                                                                                                                                    + 17
                                                                                                                                                                                                    + 18
                                                                                                                                                                                                    + 19
                                                                                                                                                                                                    + 20
                                                                                                                                                                                                    + 21
                                                                                                                                                                                                    + 22
                                                                                                                                                                                                    + 23
                                                                                                                                                                                                    + 24
                                                                                                                                                                                                    + 25
                                                                                                                                                                                                    + 26
                                                                                                                                                                                                    + 27
                                                                                                                                                                                                    + 28
                                                                                                                                                                                                    + 29
                                                                                                                                                                                                    + 30
                                                                                                                                                                                                    + 31
                                                                                                                                                                                                    + 32
                                                                                                                                                                                                    + 33
                                                                                                                                                                                                    + 34
                                                                                                                                                                                                    + 35
                                                                                                                                                                                                    + 36
                                                                                                                                                                                                    + 37
                                                                                                                                                                                                    + 38
                                                                                                                                                                                                    + 39
                                                                                                                                                                                                    + 40
                                                                                                                                                                                                    + 41
                                                                                                                                                                                                    + 42
                                                                                                                                                                                                    + 43
                                                                                                                                                                                                    + 44
                                                                                                                                                                                                    + 45
                                                                                                                                                                                                    + 46
                                                                                                                                                                                                    + 47
                                                                                                                                                                                                    + 48
                                                                                                                                                                                                    + 49
                                                                                                                                                                                                    + 50
                                                                                                                                                                                                    + 51
                                                                                                                                                                                                    + 52
                                                                                                                                                                                                    + 53
                                                                                                                                                                                                    + 54
                                                                                                                                                                                                    + 55
                                                                                                                                                                                                    + 56
                                                                                                                                                                                                    + 57
                                                                                                                                                                                                    + 58
                                                                                                                                                                                                    + 59
                                                                                                                                                                                                    + 60
                                                                                                                                                                                                    + 61
                                                                                                                                                                                                    + 62
                                                                                                                                                                                                    + 63
                                                                                                                                                                                                    + 64
                                                                                                                                                                                                    + 65
                                                                                                                                                                                                    + 66
                                                                                                                                                                                                    + 67
                                                                                                                                                                                                    + 68
                                                                                                                                                                                                    + 69
                                                                                                                                                                                                    + 70
                                                                                                                                                                                                    + 71
                                                                                                                                                                                                    + 72
                                                                                                                                                                                                    + 73
                                                                                                                                                                                                    + 74
                                                                                                                                                                                                    + 75
                                                                                                                                                                                                    + 76
                                                                                                                                                                                                    + 77
                                                                                                                                                                                                    + 78
                                                                                                                                                                                                    + 79
                                                                                                                                                                                                    + 80
                                                                                                                                                                                                    + 81
                                                                                                                                                                                                    + 82
                                                                                                                                                                                                    + 83
                                                                                                                                                                                                    + 84
                                                                                                                                                                                                    + 85
                                                                                                                                                                                                    + 86
                                                                                                                                                                                                    + 87
                                                                                                                                                                                                    + 88
                                                                                                                                                                                                    + 89
                                                                                                                                                                                                    + 90
                                                                                                                                                                                                    + 91
                                                                                                                                                                                                    + 92
                                                                                                                                                                                                    + 93
                                                                                                                                                                                                    + 94
                                                                                                                                                                                                    + 95
                                                                                                                                                                                                    + 96
                                                                                                                                                                                                    + 97
                                                                                                                                                                                                    + 98
                                                                                                                                                                                                    + 99
                                                                                                                                                                                                    +100
                                                                                                                                                                                                    +101
                                                                                                                                                                                                    +102
                                                                                                                                                                                                    +103
                                                                                                                                                                                                    +104
                                                                                                                                                                                                    +105
                                                                                                                                                                                                    +106
                                                                                                                                                                                                    +107
                                                                                                                                                                                                    +108
                                                                                                                                                                                                    +109
                                                                                                                                                                                                    +110
                                                                                                                                                                                                    +111
                                                                                                                                                                                                    +112
                                                                                                                                                                                                    +113
                                                                                                                                                                                                    +114
                                                                                                                                                                                                    +115
                                                                                                                                                                                                    +116
                                                                                                                                                                                                    +117
                                                                                                                                                                                                    +118
                                                                                                                                                                                                    +119
                                                                                                                                                                                                    +120
                                                                                                                                                                                                    +121
                                                                                                                                                                                                    +122
                                                                                                                                                                                                    +123
                                                                                                                                                                                                    +124
                                                                                                                                                                                                    +125
                                                                                                                                                                                                    +126
                                                                                                                                                                                                    +127
                                                                                                                                                                                                    +128
                                                                                                                                                                                                    +129
                                                                                                                                                                                                    +130
                                                                                                                                                                                                    +131
                                                                                                                                                                                                    +132
                                                                                                                                                                                                    +133
                                                                                                                                                                                                    +134
                                                                                                                                                                                                    +135
                                                                                                                                                                                                    +136
                                                                                                                                                                                                    +137
                                                                                                                                                                                                    # Mode Up/Down Lab
                                                                                                                                                                                                    +# Change a mode using the buttons on the Maker Pi RP2040 board
                                                                                                                                                                                                    +# Changes the NeoPixel color and the blue GPIO status LEDs
                                                                                                                                                                                                    +import time
                                                                                                                                                                                                    +from machine import Pin, PWM
                                                                                                                                                                                                    +# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                                    +from neopixel import Neopixel
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +BUZZER_PORT = 22
                                                                                                                                                                                                    +buzzer = PWM(Pin(BUZZER_PORT))
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +NUMBER_PIXELS = 2
                                                                                                                                                                                                    +STATE_MACHINE = 0
                                                                                                                                                                                                    +NEOPIXEL_PIN = 18
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                    +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB")
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# have up to 13 that we can use
                                                                                                                                                                                                    +blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]
                                                                                                                                                                                                    +number_leds = len(blue_led_pins)
                                                                                                                                                                                                    +led_ports = []
                                                                                                                                                                                                    +# create a list of the port pin object instances
                                                                                                                                                                                                    +for i in range(number_leds):
                                                                                                                                                                                                    +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# Color RGB values as tuples - needs some Gamma corrections
                                                                                                                                                                                                    +red = (255, 0, 0)
                                                                                                                                                                                                    +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                    +yellow = (255, 150, 0)
                                                                                                                                                                                                    +green = (0, 255, 0)
                                                                                                                                                                                                    +blue = (0, 0, 255)
                                                                                                                                                                                                    +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                    +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                    +cyan = (0, 255, 255)
                                                                                                                                                                                                    +lightgreen = (100, 255, 100)
                                                                                                                                                                                                    +white = (128, 128, 128) # not too bright
                                                                                                                                                                                                    +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')
                                                                                                                                                                                                    +num_colors = len(color_names)
                                                                                                                                                                                                    +colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# set to be 1 to 100 for percent brightness
                                                                                                                                                                                                    +strip.brightness(100)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# Motor Setup
                                                                                                                                                                                                    +# motors just barely turn at this power level
                                                                                                                                                                                                    +MIN_POWER_LEVEL = 10000
                                                                                                                                                                                                    +MAX_POWER_LEVEL = 65025
                                                                                                                                                                                                    +POWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10)
                                                                                                                                                                                                    +# lower right pins with USB on top
                                                                                                                                                                                                    +RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                    +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                    +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                    +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                    +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                    +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                    +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +def drive_speed(power_level):
                                                                                                                                                                                                    +    right_forward.duty_u16(power_level)
                                                                                                                                                                                                    +    left_forward.duty_u16(power_level)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +mode = 0 # the default mode on powerup and reset
                                                                                                                                                                                                    +mode_count = len(color_names)
                                                                                                                                                                                                    +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +builtin_led = machine.Pin(25, Pin.OUT)
                                                                                                                                                                                                    +# Give our pins some logical names
                                                                                                                                                                                                    +next_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                    +previous_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                    +def button_pressed_handler(pin):
                                                                                                                                                                                                    +    global mode, last_time, power_level
                                                                                                                                                                                                    +    new_time = time.ticks_ms()
                                                                                                                                                                                                    +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                    +    if (new_time - last_time) > 200:
                                                                                                                                                                                                    +        # this should be pin.id but it does not work
                                                                                                                                                                                                    +        if '20' in str(pin):
                                                                                                                                                                                                    +            mode +=1
                                                                                                                                                                                                    +            # power_level += POWER_STEP
                                                                                                                                                                                                    +        else:
                                                                                                                                                                                                    +            mode -=1
                                                                                                                                                                                                    +            # power_level -= POWER_STEP
                                                                                                                                                                                                    +        # wrap around to first mode
                                                                                                                                                                                                    +        if mode >= mode_count: mode = 0
                                                                                                                                                                                                    +        if mode < 0: mode = mode_count - 1
                                                                                                                                                                                                    +        last_time = new_time
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +def set_blue_led_mode(mode):
                                                                                                                                                                                                    +    global num_colors
                                                                                                                                                                                                    +    for i in range(0, num_colors):
                                                                                                                                                                                                    +        if i == mode:
                                                                                                                                                                                                    +            led_ports[i].high()
                                                                                                                                                                                                    +        else:
                                                                                                                                                                                                    +            led_ports[i].low()
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# Register the handler function when either button is pressed
                                                                                                                                                                                                    +next_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                    +previous_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# non-linear increase is frequency - note that some are lowder
                                                                                                                                                                                                    +tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]
                                                                                                                                                                                                    +def playtone(frequency):
                                                                                                                                                                                                    +    buzzer.duty_u16(1000)
                                                                                                                                                                                                    +    buzzer.freq(frequency)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +def bequiet():
                                                                                                                                                                                                    +    buzzer.duty_u16(0)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +# This is for only printing when a new button press count value happens
                                                                                                                                                                                                    +old_mode = -1
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +power_level = MIN_POWER_LEVEL
                                                                                                                                                                                                    +print('found ', mode_count, ' modes.')
                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                    +    # only print on change in the button_presses value
                                                                                                                                                                                                    +    if mode != old_mode:
                                                                                                                                                                                                    +        print('new mode:', mode, color_names[mode], tone_freq[mode], power_level)
                                                                                                                                                                                                    +        # get the color mode
                                                                                                                                                                                                    +        color = colors[mode]
                                                                                                                                                                                                    +        strip.set_pixel(0, color)
                                                                                                                                                                                                    +        strip.set_pixel(1, color)
                                                                                                                                                                                                    +        strip.show()
                                                                                                                                                                                                    +        set_blue_led_mode(mode)
                                                                                                                                                                                                    +        playtone(tone_freq[mode])
                                                                                                                                                                                                    +        time.sleep(.2)
                                                                                                                                                                                                    +        bequiet()
                                                                                                                                                                                                    +        power_level = MIN_POWER_LEVEL + mode * POWER_STEP
                                                                                                                                                                                                    +        # turn off the motor if we are at mode 0
                                                                                                                                                                                                    +        if mode == 0: power_level = 0
                                                                                                                                                                                                    +        drive_speed(power_level)
                                                                                                                                                                                                    +        old_mode = mode
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                    + Motor Lab +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                    + Square Lab +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/07-motor-connection-lab/index.html b/kits/maker-pi-rp2040-robot/07-motor-connection-lab/index.html new file mode 100644 index 000000000..1f9f05eba --- /dev/null +++ b/kits/maker-pi-rp2040-robot/07-motor-connection-lab/index.html @@ -0,0 +1,2234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Motor Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + Motor Lab + + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    + + +
                                                                                                                                                                                                    + +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    +
                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                    +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                        + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                          + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Assembly + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + Motor Lab + + + + + + + +
                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                            • + + + Built-In Motor Driver + + + +
                                                                                                                                                                                                            • + +
                                                                                                                                                                                                            • + + + Testing The Connections + + + +
                                                                                                                                                                                                            • + +
                                                                                                                                                                                                            • + + + Motor Pin Definitions + + + +
                                                                                                                                                                                                            • + +
                                                                                                                                                                                                            • + + + Testing Your Pin Definitions + + + +
                                                                                                                                                                                                            • + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Square Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Line Follower + + + + +
                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + MicroBit + + + + +
                                                                                                                                                                                                        • + + + + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                      • + + + Built-In Motor Driver + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      • + + + Testing The Connections + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      • + + + Motor Pin Definitions + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      • + + + Testing Your Pin Definitions + + + +
                                                                                                                                                                                                      • + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                      Motor Drive Connection Test

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Built-In Motor Driver

                                                                                                                                                                                                      +

                                                                                                                                                                                                      The Maker Pi RP2040 board contains a MX1508 dual channel H-bridge chip and easy-to-connect screw headers for power and motor connections. This is fantastic for teaching robotics since students can driver two motors without ever having to use a soldering iron.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      !!! Note that the is designed to work with small DC-hobby motors and there is no documentation on exactly what motor driver chip is used or its precise current and power limitations.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      The documentation only indicates that the maximum current is 1A continuous power and 1.5A for up to 5 seconds. The input voltage is only rated at 6 volts, which find for our standard 4 AA battery packs.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      If this motor driver chip is similar to the ubiquitous L293x motor controllers, and the current should be 1A per motor.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      I suspect that if you glued a small heat sink like a 16 pin DIP fin to the unknown motor driver IC on the main board you could drive slightly larger motors.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Maker Pi RP2040 Motor Driver Chip +Close-up of the motor driver chip. I can't quite make out the numbers on the chip, but the logo is not "TI".

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Testing The Connections

                                                                                                                                                                                                      +

                                                                                                                                                                                                      In our standard robot, the M1 is the right wheel as you are looking from the top-back of the robot. The M2 wheel is the left wheel. I connect the red to the right of the two connectors and it is also the right terminal of the motors as you are looking from the rear.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Look at the buttons near the motor connectors. Press the M1A button and verify that the right wheel +is moving forward. Press the M1B and the motor should turn in reverse. Similarly the M2B button should turn the left wheel forward and the M2A should turn the left wheel in reverse. If you don't wire these connections the same way I did it is not a worry. It is easy to change the code.

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Motor Pin Definitions

                                                                                                                                                                                                      +

                                                                                                                                                                                                      Now that we know what buttons control what motors and directions they turn, we are ready to define the pins that are associated with each robot movement. We have four pin assignments: both forward and reverse for both the right and left motors.

                                                                                                                                                                                                      +
                                                                                                                                                                                                      1
                                                                                                                                                                                                      +2
                                                                                                                                                                                                      +3
                                                                                                                                                                                                      +4
                                                                                                                                                                                                      RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                      +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                      +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                      +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +

                                                                                                                                                                                                      Testing Your Pin Definitions

                                                                                                                                                                                                      +

                                                                                                                                                                                                      The following program is called our motor connection test. It will turn each motor direction for three seconds and it will print out the motor and direction in the console.

                                                                                                                                                                                                      +
                                                                                                                                                                                                       1
                                                                                                                                                                                                      + 2
                                                                                                                                                                                                      + 3
                                                                                                                                                                                                      + 4
                                                                                                                                                                                                      + 5
                                                                                                                                                                                                      + 6
                                                                                                                                                                                                      + 7
                                                                                                                                                                                                      + 8
                                                                                                                                                                                                      + 9
                                                                                                                                                                                                      +10
                                                                                                                                                                                                      +11
                                                                                                                                                                                                      +12
                                                                                                                                                                                                      +13
                                                                                                                                                                                                      +14
                                                                                                                                                                                                      +15
                                                                                                                                                                                                      +16
                                                                                                                                                                                                      +17
                                                                                                                                                                                                      +18
                                                                                                                                                                                                      +19
                                                                                                                                                                                                      +20
                                                                                                                                                                                                      +21
                                                                                                                                                                                                      +22
                                                                                                                                                                                                      +23
                                                                                                                                                                                                      +24
                                                                                                                                                                                                      +25
                                                                                                                                                                                                      +26
                                                                                                                                                                                                      +27
                                                                                                                                                                                                      +28
                                                                                                                                                                                                      +29
                                                                                                                                                                                                      +30
                                                                                                                                                                                                      +31
                                                                                                                                                                                                      +32
                                                                                                                                                                                                      +33
                                                                                                                                                                                                      from machine import Pin, PWM
                                                                                                                                                                                                      +import time
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +POWER_LEVEL = 65025
                                                                                                                                                                                                      +# lower right pins with USB on top
                                                                                                                                                                                                      +RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                      +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                      +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                      +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                      +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                      +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                      +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +def spin_wheel(pwm):
                                                                                                                                                                                                      +        pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                      +        time.sleep(3)
                                                                                                                                                                                                      +        pwm.duty_u16(0)
                                                                                                                                                                                                      +        time.sleep(2)
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                      +    print('right forward')
                                                                                                                                                                                                      +    spin_wheel(right_forward)
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +    print('right reverse')
                                                                                                                                                                                                      +    spin_wheel(right_reverse)
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +    print('left foward')
                                                                                                                                                                                                      +    spin_wheel(left_forward)
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +    print('left_reverse')
                                                                                                                                                                                                      +    spin_wheel(left_reverse)
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                      + Assembly +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                      + Up/Down Motor Speed Lab +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/07b-drive-square-lab/index.html b/kits/maker-pi-rp2040-robot/07b-drive-square-lab/index.html new file mode 100644 index 000000000..e066ea0ec --- /dev/null +++ b/kits/maker-pi-rp2040-robot/07b-drive-square-lab/index.html @@ -0,0 +1,2363 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Square Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + Square Lab + + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      + + +
                                                                                                                                                                                                      + +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      +
                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                      +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                          + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                            + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Assembly + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + Square Lab + + + + + + + +
                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                              • + + + Prerequsites + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              • + + + Adding a Keyboard Interrupt Handler (Control-C) + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              • + + + Full Program + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Line Follower + + + + +
                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + MicroBit + + + + +
                                                                                                                                                                                                          • + + + + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                        • + + + Prerequsites + + + +
                                                                                                                                                                                                        • + +
                                                                                                                                                                                                        • + + + Adding a Keyboard Interrupt Handler (Control-C) + + + +
                                                                                                                                                                                                        • + +
                                                                                                                                                                                                        • + + + Full Program + + + +
                                                                                                                                                                                                        • + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                        Drive Square Lab

                                                                                                                                                                                                        +

                                                                                                                                                                                                        Prerequsites

                                                                                                                                                                                                        +

                                                                                                                                                                                                        This lab assumes you have your Maker Pi RP2040 mounted on a SmartCar chassis with two motors and a battery hooked up.

                                                                                                                                                                                                        +

                                                                                                                                                                                                        In this lab we will program our robot to drive in a square pattern. We will start out doing a "bench test" that will require you to put the robot up on a block so you can see the wheels turn, but it will not drive off your desktop. You can also observe the red LED lights on the many board to see which motor direction is on.

                                                                                                                                                                                                        +

                                                                                                                                                                                                        The main loop will look like this:

                                                                                                                                                                                                        +
                                                                                                                                                                                                         1
                                                                                                                                                                                                        + 2
                                                                                                                                                                                                        + 3
                                                                                                                                                                                                        + 4
                                                                                                                                                                                                        + 5
                                                                                                                                                                                                        + 6
                                                                                                                                                                                                        + 7
                                                                                                                                                                                                        + 8
                                                                                                                                                                                                        + 9
                                                                                                                                                                                                        +10
                                                                                                                                                                                                        +11
                                                                                                                                                                                                        +12
                                                                                                                                                                                                        while True:
                                                                                                                                                                                                        +    forward()
                                                                                                                                                                                                        +    sleep(FWD_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +    stop()
                                                                                                                                                                                                        +    sleep(STOP_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +    turn_right()
                                                                                                                                                                                                        +    sleep(TURN_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +    stop()
                                                                                                                                                                                                        +    sleep(STOP_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +

                                                                                                                                                                                                        We will need to adjust the TURN_TIME parameter to have the robot turn 90 degrees. A good value for most robots is about 1/2 second or sleep(.5).

                                                                                                                                                                                                        +

                                                                                                                                                                                                        Since we will be calling the sleep function many times we will use the following import format to keep our code tidy:

                                                                                                                                                                                                        +

                                                                                                                                                                                                        1
                                                                                                                                                                                                        from utime import sleep
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +This says that whenever we want to pause our system we just use the sleep(time) function we mean to use the sleep function in the micropython time library. This keeps our code small and portable.

                                                                                                                                                                                                        +

                                                                                                                                                                                                        Adding a Keyboard Interrupt Handler (Control-C)

                                                                                                                                                                                                        +

                                                                                                                                                                                                        It is also a problem that when we stop a program running that the PWM circuits keep generating signals, which means the robot keeps moving even after we press the STOP/RESET button. To clean this up we will allow you to run a special cleanup handler that will add a function to set all the motors to off using the stop() function.

                                                                                                                                                                                                        +
                                                                                                                                                                                                        1
                                                                                                                                                                                                        +2
                                                                                                                                                                                                        +3
                                                                                                                                                                                                        +4
                                                                                                                                                                                                        +5
                                                                                                                                                                                                        +6
                                                                                                                                                                                                        +7
                                                                                                                                                                                                        +8
                                                                                                                                                                                                        +9
                                                                                                                                                                                                        try:
                                                                                                                                                                                                        +    main()
                                                                                                                                                                                                        +except KeyboardInterrupt:
                                                                                                                                                                                                        +    print('Got ctrl-c')
                                                                                                                                                                                                        +finally:
                                                                                                                                                                                                        +    # Optional cleanup code
                                                                                                                                                                                                        +    print('Cleaning up')
                                                                                                                                                                                                        +    print('Powering down all motors now.')
                                                                                                                                                                                                        +    stop()
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +

                                                                                                                                                                                                        Full Program

                                                                                                                                                                                                        +

                                                                                                                                                                                                        You are now ready to test the full program. Save the following to the main.py file, disconnect the USB connector and turn on the power on the main board. Your robot should not we driving in a square!

                                                                                                                                                                                                        +
                                                                                                                                                                                                         1
                                                                                                                                                                                                        + 2
                                                                                                                                                                                                        + 3
                                                                                                                                                                                                        + 4
                                                                                                                                                                                                        + 5
                                                                                                                                                                                                        + 6
                                                                                                                                                                                                        + 7
                                                                                                                                                                                                        + 8
                                                                                                                                                                                                        + 9
                                                                                                                                                                                                        +10
                                                                                                                                                                                                        +11
                                                                                                                                                                                                        +12
                                                                                                                                                                                                        +13
                                                                                                                                                                                                        +14
                                                                                                                                                                                                        +15
                                                                                                                                                                                                        +16
                                                                                                                                                                                                        +17
                                                                                                                                                                                                        +18
                                                                                                                                                                                                        +19
                                                                                                                                                                                                        +20
                                                                                                                                                                                                        +21
                                                                                                                                                                                                        +22
                                                                                                                                                                                                        +23
                                                                                                                                                                                                        +24
                                                                                                                                                                                                        +25
                                                                                                                                                                                                        +26
                                                                                                                                                                                                        +27
                                                                                                                                                                                                        +28
                                                                                                                                                                                                        +29
                                                                                                                                                                                                        +30
                                                                                                                                                                                                        +31
                                                                                                                                                                                                        +32
                                                                                                                                                                                                        +33
                                                                                                                                                                                                        +34
                                                                                                                                                                                                        +35
                                                                                                                                                                                                        +36
                                                                                                                                                                                                        +37
                                                                                                                                                                                                        +38
                                                                                                                                                                                                        +39
                                                                                                                                                                                                        +40
                                                                                                                                                                                                        +41
                                                                                                                                                                                                        +42
                                                                                                                                                                                                        +43
                                                                                                                                                                                                        +44
                                                                                                                                                                                                        +45
                                                                                                                                                                                                        +46
                                                                                                                                                                                                        +47
                                                                                                                                                                                                        +48
                                                                                                                                                                                                        +49
                                                                                                                                                                                                        +50
                                                                                                                                                                                                        +51
                                                                                                                                                                                                        +52
                                                                                                                                                                                                        +53
                                                                                                                                                                                                        +54
                                                                                                                                                                                                        +55
                                                                                                                                                                                                        +56
                                                                                                                                                                                                        +57
                                                                                                                                                                                                        +58
                                                                                                                                                                                                        +59
                                                                                                                                                                                                        +60
                                                                                                                                                                                                        +61
                                                                                                                                                                                                        +62
                                                                                                                                                                                                        +63
                                                                                                                                                                                                        +64
                                                                                                                                                                                                        +65
                                                                                                                                                                                                        +66
                                                                                                                                                                                                        +67
                                                                                                                                                                                                        +68
                                                                                                                                                                                                        +69
                                                                                                                                                                                                        +70
                                                                                                                                                                                                        +71
                                                                                                                                                                                                        +72
                                                                                                                                                                                                        +73
                                                                                                                                                                                                        +74
                                                                                                                                                                                                        +75
                                                                                                                                                                                                        +76
                                                                                                                                                                                                        +77
                                                                                                                                                                                                        +78
                                                                                                                                                                                                        +79
                                                                                                                                                                                                        +80
                                                                                                                                                                                                        +81
                                                                                                                                                                                                        +82
                                                                                                                                                                                                        +83
                                                                                                                                                                                                        +84
                                                                                                                                                                                                        +85
                                                                                                                                                                                                        +86
                                                                                                                                                                                                        +87
                                                                                                                                                                                                        +88
                                                                                                                                                                                                        +89
                                                                                                                                                                                                        +90
                                                                                                                                                                                                        +91
                                                                                                                                                                                                        from machine import Pin, PWM
                                                                                                                                                                                                        +from utime import sleep
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +POWER_LEVEL = 65025
                                                                                                                                                                                                        +# lower right pins with USB on top
                                                                                                                                                                                                        +RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                        +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                        +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                        +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                        +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                        +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                        +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +FWD_TIME = 2
                                                                                                                                                                                                        +TURN_TIME = .5 # adjust this to get the turn to be 90 degrees
                                                                                                                                                                                                        +STOP_TIME = 2
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                        +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                        +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                        +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def turn_motor_on(pwm):
                                                                                                                                                                                                        +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def turn_motor_off(pwm):
                                                                                                                                                                                                        +   pwm.duty_u16(0)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def forward():
                                                                                                                                                                                                        +    turn_motor_on(right_forward)
                                                                                                                                                                                                        +    turn_motor_on(left_forward)
                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def reverse():
                                                                                                                                                                                                        +    turn_motor_on(right_reverse)
                                                                                                                                                                                                        +    turn_motor_on(left_reverse)
                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def turn_right():
                                                                                                                                                                                                        +    turn_motor_on(right_forward)
                                                                                                                                                                                                        +    turn_motor_on(left_reverse)
                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def turn_left():
                                                                                                                                                                                                        +    turn_motor_on(right_reverse)
                                                                                                                                                                                                        +    turn_motor_on(left_forward)
                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def stop():
                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +print('Running Drive Square Lab')
                                                                                                                                                                                                        +print('Use Control-C to Stop All Motors')
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +def main():
                                                                                                                                                                                                        +    while True:
                                                                                                                                                                                                        +        print('forward')
                                                                                                                                                                                                        +        forward()
                                                                                                                                                                                                        +        sleep(FWD_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +        print('stop')
                                                                                                                                                                                                        +        stop()
                                                                                                                                                                                                        +        sleep(STOP_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +        print('turning right')
                                                                                                                                                                                                        +        turn_right()
                                                                                                                                                                                                        +        sleep(TURN_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +        print('stop')
                                                                                                                                                                                                        +        stop()
                                                                                                                                                                                                        +        sleep(STOP_TIME)
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +try:
                                                                                                                                                                                                        +    main()
                                                                                                                                                                                                        +except KeyboardInterrupt:
                                                                                                                                                                                                        +    print('Got ctrl-c')
                                                                                                                                                                                                        +finally:
                                                                                                                                                                                                        +    # Optional cleanup code
                                                                                                                                                                                                        +    print('Cleaning up')
                                                                                                                                                                                                        +    print('Powering down all motors now.')
                                                                                                                                                                                                        +    stop()
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                        + Up/Down Motor Speed Lab +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                        + Servo Lab +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/08-servo-lab/index.html b/kits/maker-pi-rp2040-robot/08-servo-lab/index.html new file mode 100644 index 000000000..c15b8147c --- /dev/null +++ b/kits/maker-pi-rp2040-robot/08-servo-lab/index.html @@ -0,0 +1,2534 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Servo Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + Servo Lab + + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        + + +
                                                                                                                                                                                                        + +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        +
                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                        +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                            + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                              + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Assembly + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Square Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + Servo Lab + + + + + + + +
                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                • + + + Servo Control + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + Calibration of the Servo + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + Checking your Servo Calibration with Buttons + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + Sample Sweep Code + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + Shutting Down All Servos + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + Adding Cleanup Code + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Line Follower + + + + +
                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + MicroBit + + + + +
                                                                                                                                                                                                            • + + + + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                          • + + + Servo Control + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + Calibration of the Servo + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + Checking your Servo Calibration with Buttons + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + Sample Sweep Code + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + Shutting Down All Servos + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + Adding Cleanup Code + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                          • + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                          Maker Pi RP2040 Servo Lab

                                                                                                                                                                                                          +

                                                                                                                                                                                                          Servo motors are ideal for controlling the angle of an item such as a steering angle or the direction of a sensor. The servos used in these labs are inexpensive SG90 micro-servos that draw very little power and are ideal for a teaching lab. They can be purchased for about $3 each US on eBay. To control a 180 degree servo, you just tell it what angle you would like it to move to. The range of values is typically -90 to 90 degrees with 0 being the nominal resting position for many applications such as the steering wheel angle of a car.

                                                                                                                                                                                                          +

                                                                                                                                                                                                          The Maker Pi RP2040 has four servo ports in the upper left corner of the board (with the USB on the bottom) that use ports GP12, GP13, GP14 and GP15. You can connect any small micro servo directly to these ports. Just make sure to get the polarity correct. The colors for servos may vary somewhat, but the two most common standards are:

                                                                                                                                                                                                          +
                                                                                                                                                                                                            +
                                                                                                                                                                                                          • Orange, red and brown - signal, positive and ground
                                                                                                                                                                                                          • +
                                                                                                                                                                                                          • White, red, black - signal, positive and ground
                                                                                                                                                                                                          • +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          The general rule is that the lighter colors of orange and white will be the signal and the brown and black will be ground.

                                                                                                                                                                                                          +

                                                                                                                                                                                                          Servo Control

                                                                                                                                                                                                          +

                                                                                                                                                                                                          We will use the PWM functions in our MicroPython library to send a PWM signal to each of the servos. Servos are not controlled by the duty cycle directly. They are controlled by the width of the pulses. But we can control the approximate with of the pulses by holding the frequency constant and changing the duty cycle.

                                                                                                                                                                                                          +

                                                                                                                                                                                                          We will use a 40 hertz signal to send a PWM signal to each of the servos like this.

                                                                                                                                                                                                          +
                                                                                                                                                                                                          1
                                                                                                                                                                                                          +2
                                                                                                                                                                                                          +3
                                                                                                                                                                                                          SERVO_FREQ_HZ = 40
                                                                                                                                                                                                          +# SERVO_PERIOD_MS = 1000 / SERVO_FREQ_HZ is a 25 millisecond pulse width
                                                                                                                                                                                                          +my_pwm.freq(SERVO_FREQ_HZ)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          Calibration of the Servo

                                                                                                                                                                                                          +

                                                                                                                                                                                                          There are small manufacturing variations in servos. This means to get the full sweep of a 180% servo you have to adjust the duty cycle.

                                                                                                                                                                                                          +
                                                                                                                                                                                                            +
                                                                                                                                                                                                          • Minimum duty cycle: 1700
                                                                                                                                                                                                          • +
                                                                                                                                                                                                          • Maximum duty cycle: 6300
                                                                                                                                                                                                          • +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          By some experimentation I got the following results +

                                                                                                                                                                                                          1
                                                                                                                                                                                                          +2
                                                                                                                                                                                                          SERVO_MIN_DUTY = 1725 # -90 degrees
                                                                                                                                                                                                          +SERVO_MAX_DUTY = 6378 # 90 degrees
                                                                                                                                                                                                          +

                                                                                                                                                                                                          +

                                                                                                                                                                                                          We can use a linear mapping function to convert the angle (from -90 to 90):

                                                                                                                                                                                                          +
                                                                                                                                                                                                          1
                                                                                                                                                                                                          +2
                                                                                                                                                                                                          +3
                                                                                                                                                                                                          +4
                                                                                                                                                                                                          +5
                                                                                                                                                                                                          +6
                                                                                                                                                                                                          +7
                                                                                                                                                                                                          +8
                                                                                                                                                                                                          +9
                                                                                                                                                                                                          # This will take in integers of range in (min and max) return a integer in the output range (min and max)
                                                                                                                                                                                                          +# Used to convert one range of values into another using a linear function like the Arduino map() function
                                                                                                                                                                                                          +def convert(x, in_min, in_max, out_min, out_max):
                                                                                                                                                                                                          +    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +angle = 0
                                                                                                                                                                                                          +duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)
                                                                                                                                                                                                          +print('For angle: ', angle, ' the duty is: ', duty)
                                                                                                                                                                                                          +pwm.duty_u16(duty)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          Checking your Servo Calibration with Buttons

                                                                                                                                                                                                          +

                                                                                                                                                                                                          We can also use the buttons on the Maker Pi RP2040 to verify that the extreme angles are correct. One button will increase the angle and one will decrease the angle.

                                                                                                                                                                                                          +
                                                                                                                                                                                                           1
                                                                                                                                                                                                          + 2
                                                                                                                                                                                                          + 3
                                                                                                                                                                                                          + 4
                                                                                                                                                                                                          + 5
                                                                                                                                                                                                          + 6
                                                                                                                                                                                                          + 7
                                                                                                                                                                                                          + 8
                                                                                                                                                                                                          + 9
                                                                                                                                                                                                          +10
                                                                                                                                                                                                          +11
                                                                                                                                                                                                          +12
                                                                                                                                                                                                          +13
                                                                                                                                                                                                          +14
                                                                                                                                                                                                          +15
                                                                                                                                                                                                          +16
                                                                                                                                                                                                          +17
                                                                                                                                                                                                          +18
                                                                                                                                                                                                          +19
                                                                                                                                                                                                          +20
                                                                                                                                                                                                          +21
                                                                                                                                                                                                          +22
                                                                                                                                                                                                          +23
                                                                                                                                                                                                          +24
                                                                                                                                                                                                          +25
                                                                                                                                                                                                          +26
                                                                                                                                                                                                          +27
                                                                                                                                                                                                          +28
                                                                                                                                                                                                          +29
                                                                                                                                                                                                          +30
                                                                                                                                                                                                          +31
                                                                                                                                                                                                          +32
                                                                                                                                                                                                          +33
                                                                                                                                                                                                          +34
                                                                                                                                                                                                          +35
                                                                                                                                                                                                          +36
                                                                                                                                                                                                          +37
                                                                                                                                                                                                          +38
                                                                                                                                                                                                          +39
                                                                                                                                                                                                          +40
                                                                                                                                                                                                          +41
                                                                                                                                                                                                          +42
                                                                                                                                                                                                          +43
                                                                                                                                                                                                          +44
                                                                                                                                                                                                          +45
                                                                                                                                                                                                          +46
                                                                                                                                                                                                          +47
                                                                                                                                                                                                          +48
                                                                                                                                                                                                          +49
                                                                                                                                                                                                          +50
                                                                                                                                                                                                          +51
                                                                                                                                                                                                          +52
                                                                                                                                                                                                          +53
                                                                                                                                                                                                          +54
                                                                                                                                                                                                          +55
                                                                                                                                                                                                          +56
                                                                                                                                                                                                          +57
                                                                                                                                                                                                          # Maker Pi RP2040 program to check the limits of a 180 degree servo such as a SG90 micro servo
                                                                                                                                                                                                          +from machine import Pin, PWM
                                                                                                                                                                                                          +import time
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +BUTTON_1_PIN = 20 # increment the angle
                                                                                                                                                                                                          +BUTTON_2_PIN = 21 # decrement the angle
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +SERVO_1_PIN = 12
                                                                                                                                                                                                          +SERVO_2_PIN = 13 # MAX=5749@40
                                                                                                                                                                                                          +SERVO_3_PIN = 14
                                                                                                                                                                                                          +SERVO_4_PIN = 15
                                                                                                                                                                                                          +# this is ususlly standard across most servos
                                                                                                                                                                                                          +SERVO_FREQ_HZ = 40
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +pwm = PWM(Pin(SERVO_2_PIN))
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# the two button on the Maker Pi RP2040
                                                                                                                                                                                                          +increment_angle_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                          +decrement_angle_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +#  return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 )
                                                                                                                                                                                                          +# This will take in integers of range in (min and max) return a integer in the output range (min and max)
                                                                                                                                                                                                          +# Used to convert one range of values into another using a linear function like the Arduino map() function
                                                                                                                                                                                                          +def convert(x, in_min, in_max, out_min, out_max):
                                                                                                                                                                                                          +    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# globals
                                                                                                                                                                                                          +angle = -90
                                                                                                                                                                                                          +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# if the pin is 20 then increment, else decement
                                                                                                                                                                                                          +def button_pressed_handler(pin):
                                                                                                                                                                                                          +    global angle, last_time
                                                                                                                                                                                                          +    new_time = time.ticks_ms()
                                                                                                                                                                                                          +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                          +    if (new_time - last_time) > 200:
                                                                                                                                                                                                          +        # this should be pin.id but it does not work
                                                                                                                                                                                                          +        if '20' in str(pin):
                                                                                                                                                                                                          +            angle +=1
                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                          +            angle -=1
                                                                                                                                                                                                          +        last_time = new_time
                                                                                                                                                                                                          + # now we register the handler function when the button is pressed
                                                                                                                                                                                                          +increment_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                          +decrement_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +pwm.freq(SERVO_FREQ_HZ)
                                                                                                                                                                                                          +old_angle = -1
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                          +    # only print on change in the button_presses value
                                                                                                                                                                                                          +    if angle != old_angle:
                                                                                                                                                                                                          +        duty = ServoDuty(angle)
                                                                                                                                                                                                          +        print('new angle:', angle, 'duty: ', duty)
                                                                                                                                                                                                          +        pwm.duty_u16(duty)
                                                                                                                                                                                                          +        old_angle = angle
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          Sample Sweep Code

                                                                                                                                                                                                          +
                                                                                                                                                                                                           1
                                                                                                                                                                                                          + 2
                                                                                                                                                                                                          + 3
                                                                                                                                                                                                          + 4
                                                                                                                                                                                                          + 5
                                                                                                                                                                                                          + 6
                                                                                                                                                                                                          + 7
                                                                                                                                                                                                          + 8
                                                                                                                                                                                                          + 9
                                                                                                                                                                                                          +10
                                                                                                                                                                                                          +11
                                                                                                                                                                                                          +12
                                                                                                                                                                                                          +13
                                                                                                                                                                                                          +14
                                                                                                                                                                                                          +15
                                                                                                                                                                                                          +16
                                                                                                                                                                                                          +17
                                                                                                                                                                                                          +18
                                                                                                                                                                                                          +19
                                                                                                                                                                                                          +20
                                                                                                                                                                                                          +21
                                                                                                                                                                                                          +22
                                                                                                                                                                                                          +23
                                                                                                                                                                                                          +24
                                                                                                                                                                                                          +25
                                                                                                                                                                                                          +26
                                                                                                                                                                                                          +27
                                                                                                                                                                                                          +28
                                                                                                                                                                                                          +29
                                                                                                                                                                                                          +30
                                                                                                                                                                                                          +31
                                                                                                                                                                                                          +32
                                                                                                                                                                                                          +33
                                                                                                                                                                                                          +34
                                                                                                                                                                                                          +35
                                                                                                                                                                                                          +36
                                                                                                                                                                                                          +37
                                                                                                                                                                                                          +38
                                                                                                                                                                                                          +39
                                                                                                                                                                                                          +40
                                                                                                                                                                                                          +41
                                                                                                                                                                                                          +42
                                                                                                                                                                                                          +43
                                                                                                                                                                                                          +44
                                                                                                                                                                                                          +45
                                                                                                                                                                                                          +46
                                                                                                                                                                                                          +47
                                                                                                                                                                                                          +48
                                                                                                                                                                                                          +49
                                                                                                                                                                                                          +50
                                                                                                                                                                                                          +51
                                                                                                                                                                                                          +52
                                                                                                                                                                                                          +53
                                                                                                                                                                                                          +54
                                                                                                                                                                                                          +55
                                                                                                                                                                                                          +56
                                                                                                                                                                                                          +57
                                                                                                                                                                                                          +58
                                                                                                                                                                                                          +59
                                                                                                                                                                                                          +60
                                                                                                                                                                                                          +61
                                                                                                                                                                                                          +62
                                                                                                                                                                                                          +63
                                                                                                                                                                                                          +64
                                                                                                                                                                                                          +65
                                                                                                                                                                                                          +66
                                                                                                                                                                                                          +67
                                                                                                                                                                                                          +68
                                                                                                                                                                                                          +69
                                                                                                                                                                                                          +70
                                                                                                                                                                                                          from machine import Pin, PWM
                                                                                                                                                                                                          +import time
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +BUTTON_1_PIN = 20
                                                                                                                                                                                                          +BUTTON_2_PIN = 21
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +SERVO_1_PIN = 12
                                                                                                                                                                                                          +SERVO_2_PIN = 13
                                                                                                                                                                                                          +SERVO_3_PIN = 14
                                                                                                                                                                                                          +SERVO_4_PIN = 15
                                                                                                                                                                                                          +SERVO_FREQ_HZ = 50
                                                                                                                                                                                                          +SERVO_MIN_DUTY = 1725
                                                                                                                                                                                                          +SERVO_MAX_DUTY = 6378
                                                                                                                                                                                                          +# this is ususlly standard across most servos
                                                                                                                                                                                                          +SERVO_FREQ_HZ = 40
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +pwm = PWM(Pin(SERVO_2_PIN))
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# the two button on the Maker Pi RP2040
                                                                                                                                                                                                          +clock_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                          +counter_clock_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# globals
                                                                                                                                                                                                          +angle = 90
                                                                                                                                                                                                          +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +def button_pressed_handler(pin):
                                                                                                                                                                                                          +    global angle, last_time
                                                                                                                                                                                                          +    new_time = time.ticks_ms()
                                                                                                                                                                                                          +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                          +    if (new_time - last_time) > 200:
                                                                                                                                                                                                          +        # this should be pin.id but it does not work
                                                                                                                                                                                                          +        if '20' in str(pin):
                                                                                                                                                                                                          +            angle +=1
                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                          +            angle -=1
                                                                                                                                                                                                          +        # wrap around to first mode
                                                                                                                                                                                                          +        if mode >= mode_count: mode = 0
                                                                                                                                                                                                          +        if mode < 0: mode = mode_count - 1
                                                                                                                                                                                                          +        last_time = new_time
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# now we register the handler function when the button is pressed
                                                                                                                                                                                                          +clock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                          +counter_clock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)      
                                                                                                                                                                                                          +#  return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 )
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# Thisw will take in integers of range in (min and max) return a integer in the output range (min and max)
                                                                                                                                                                                                          +# Used to convert one range of values into another using a linear function like the Arduino map() function
                                                                                                                                                                                                          +def convert(x, in_min, in_max, out_min, out_max):
                                                                                                                                                                                                          +    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +# -90 should generate 1725
                                                                                                                                                                                                          +# 90 should generate 7973
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +old_angle = -1
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +pwm.freq(50)
                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                          +    for angle in range(-90, 90):
                                                                                                                                                                                                          +        duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)
                                                                                                                                                                                                          +        print('angle:', angle, 'duty: ', duty)
                                                                                                                                                                                                          +        pwm.duty_u16(duty)
                                                                                                                                                                                                          +        old_angle = angle
                                                                                                                                                                                                          +        time.sleep(.01)
                                                                                                                                                                                                          +    for angle in range(90, -90, -1):
                                                                                                                                                                                                          +        duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)
                                                                                                                                                                                                          +        print('angle:', angle, 'duty: ', duty)
                                                                                                                                                                                                          +        pwm.duty_u16(duty)
                                                                                                                                                                                                          +        old_angle = angle
                                                                                                                                                                                                          +        time.sleep(.01)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          Shutting Down All Servos

                                                                                                                                                                                                          +
                                                                                                                                                                                                           1
                                                                                                                                                                                                          + 2
                                                                                                                                                                                                          + 3
                                                                                                                                                                                                          + 4
                                                                                                                                                                                                          + 5
                                                                                                                                                                                                          + 6
                                                                                                                                                                                                          + 7
                                                                                                                                                                                                          + 8
                                                                                                                                                                                                          + 9
                                                                                                                                                                                                          +10
                                                                                                                                                                                                          +11
                                                                                                                                                                                                          +12
                                                                                                                                                                                                          +13
                                                                                                                                                                                                          from machine import Pin, PWM
                                                                                                                                                                                                          +import time
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +SERVO_1_PIN = 12
                                                                                                                                                                                                          +SERVO_2_PIN = 13
                                                                                                                                                                                                          +SERVO_3_PIN = 14
                                                                                                                                                                                                          +SERVO_4_PIN = 15
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +print('shutting down all servos!')
                                                                                                                                                                                                          +for i in range(12, 16):
                                                                                                                                                                                                          +    print('Servo', i, 'shutting down')
                                                                                                                                                                                                          +    pwm1 = PWM(Pin(SERVO_1_PIN))
                                                                                                                                                                                                          +    pwm1.duty_u16(0)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          Adding Cleanup Code

                                                                                                                                                                                                          +

                                                                                                                                                                                                          PWM signals continue to be generated even after you do a STOP/RESET on your microcontroller. This could drain batteries and wear out your servo motors. To stop the servos from getting PWM signals you can add an interrupt to your code to catch these signals and set the PWM duty cycle back to zero. This

                                                                                                                                                                                                          +
                                                                                                                                                                                                          1
                                                                                                                                                                                                          
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +

                                                                                                                                                                                                          References

                                                                                                                                                                                                          +

                                                                                                                                                                                                          MicroPython Reference Page - this page is not very helpful. The implication is that servo controls are standardized across MicroPython system. This does not appear to be the case.

                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                          + Square Lab +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                          + Scanner Test +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/09-i2c-scanner-test/index.html b/kits/maker-pi-rp2040-robot/09-i2c-scanner-test/index.html new file mode 100644 index 000000000..53b0307bc --- /dev/null +++ b/kits/maker-pi-rp2040-robot/09-i2c-scanner-test/index.html @@ -0,0 +1,2146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Scanner Test - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + Scanner Test + + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          + + +
                                                                                                                                                                                                          + +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          +
                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                          +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                              + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Assembly + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + Scanner Test + + + + + + + +
                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                  • + + + Testing for the Time-of-Flight Sensor + + + +
                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + MicroBit + + + + +
                                                                                                                                                                                                              • + + + + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                            • + + + Testing for the Time-of-Flight Sensor + + + +
                                                                                                                                                                                                            • + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                            I2C Scanner Test

                                                                                                                                                                                                            +

                                                                                                                                                                                                            How do we know that our connection to the distance sensor is wired correctly? The quick way to test this is to run a program called the I2C scanner. It will return a list of all the devices it finds on the I2C bus.

                                                                                                                                                                                                            +

                                                                                                                                                                                                            We first run the I2C scanner program to verify that the sensor is connected correct and is responding to the I2C bus scan.

                                                                                                                                                                                                            +
                                                                                                                                                                                                            1
                                                                                                                                                                                                            +2
                                                                                                                                                                                                            +3
                                                                                                                                                                                                            +4
                                                                                                                                                                                                            +5
                                                                                                                                                                                                            +6
                                                                                                                                                                                                            import machine
                                                                                                                                                                                                            +# Pins on the Grove Connector 1 on the Maker Pi RP2040 are GP0 and GP1
                                                                                                                                                                                                            +sda=machine.Pin(0)
                                                                                                                                                                                                            +scl=machine.Pin(1)
                                                                                                                                                                                                            +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                            +print("I2C device ID list:", i2c.scan())
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +

                                                                                                                                                                                                            This should return a list of the devices it finds. If you just have the Time-of-Flight sensor it will look like this:

                                                                                                                                                                                                            +
                                                                                                                                                                                                            1
                                                                                                                                                                                                            +2
                                                                                                                                                                                                            +3
                                                                                                                                                                                                            +4
                                                                                                                                                                                                            +5
                                                                                                                                                                                                            [41]
                                                                                                                                                                                                            +``
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +```py
                                                                                                                                                                                                            +device_id = i2c.scan()[0]
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +

                                                                                                                                                                                                            Testing for the Time-of-Flight Sensor

                                                                                                                                                                                                            +
                                                                                                                                                                                                             1
                                                                                                                                                                                                            + 2
                                                                                                                                                                                                            + 3
                                                                                                                                                                                                            + 4
                                                                                                                                                                                                            + 5
                                                                                                                                                                                                            + 6
                                                                                                                                                                                                            + 7
                                                                                                                                                                                                            + 8
                                                                                                                                                                                                            + 9
                                                                                                                                                                                                            +10
                                                                                                                                                                                                            +11
                                                                                                                                                                                                            +12
                                                                                                                                                                                                            +13
                                                                                                                                                                                                            +14
                                                                                                                                                                                                            +15
                                                                                                                                                                                                            import machine
                                                                                                                                                                                                            +sda=machine.Pin(0)
                                                                                                                                                                                                            +scl=machine.Pin(1)
                                                                                                                                                                                                            +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +# i2c.scan() returns a list of devices that have been found
                                                                                                                                                                                                            +# i2c.scan()[0] is the first device found
                                                                                                                                                                                                            +device_id = i2c.scan()[0]
                                                                                                                                                                                                            +print("Device found at decimal", device_id)
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +if device_id == 41:
                                                                                                                                                                                                            +    print("TEST PASS")
                                                                                                                                                                                                            +else:
                                                                                                                                                                                                            +    print("No device found at decimal 41")
                                                                                                                                                                                                            +    print("TEST FAIL")
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                            + Servo Lab +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                            + Time of Flight Lab +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/10-time-of-flight-lab/index.html b/kits/maker-pi-rp2040-robot/10-time-of-flight-lab/index.html new file mode 100644 index 000000000..a704bf3c4 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/10-time-of-flight-lab/index.html @@ -0,0 +1,2323 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Time of Flight Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + Time of Flight Lab + + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            + + +
                                                                                                                                                                                                            + +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            +
                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                            +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                  + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Assembly + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Time of Flight Lab + + + + + + + +
                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                    • + + + Calibration + + + +
                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                    • + + + Full Program + + + +
                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                • + + + + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                              • + + + Calibration + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              • + + + Full Program + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                              • + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                              Time of Flight Distance Sensor Lab

                                                                                                                                                                                                              +

                                                                                                                                                                                                              In this lab we create a program that will show the distance measured by the Time-of-Flight sensor by printing the distance on the console and also displaying the distance on 11 blue LEDs.

                                                                                                                                                                                                              +

                                                                                                                                                                                                              First, make sure you have your driver for the Time-of-Flight sensor installed.

                                                                                                                                                                                                              +

                                                                                                                                                                                                              You can copy the code from here and save it in the file VL53L0X.py. Note the zero between the "L" and "X" in the file name, not the letter "O".

                                                                                                                                                                                                              +

                                                                                                                                                                                                              We use a non-linear distance scale as we get closer to an object. We store the numbers of each LED and the distance it should change in a lists:

                                                                                                                                                                                                              +
                                                                                                                                                                                                              1
                                                                                                                                                                                                              +2
                                                                                                                                                                                                              blue_led_pins = [2, 3, 4,  5,  6,  7,  16, 17, 26, 27, 28]
                                                                                                                                                                                                              +dist_scale =    [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150]
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +

                                                                                                                                                                                                              Calibration

                                                                                                                                                                                                              +

                                                                                                                                                                                                              There are three numbers you can change when you calibrate the sensor:

                                                                                                                                                                                                              +
                                                                                                                                                                                                              1
                                                                                                                                                                                                              +2
                                                                                                                                                                                                              +3
                                                                                                                                                                                                              ZERO_DIST = 60 # The value of the sensor when an object is 0 CM away
                                                                                                                                                                                                              +MAX_DIST = 1200 # max raw distance we are able to read
                                                                                                                                                                                                              +SCALE_DIST = .3 # multiplier for raw to calibrated distance in CM
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +

                                                                                                                                                                                                              Full Program

                                                                                                                                                                                                              +
                                                                                                                                                                                                               1
                                                                                                                                                                                                              + 2
                                                                                                                                                                                                              + 3
                                                                                                                                                                                                              + 4
                                                                                                                                                                                                              + 5
                                                                                                                                                                                                              + 6
                                                                                                                                                                                                              + 7
                                                                                                                                                                                                              + 8
                                                                                                                                                                                                              + 9
                                                                                                                                                                                                              +10
                                                                                                                                                                                                              +11
                                                                                                                                                                                                              +12
                                                                                                                                                                                                              +13
                                                                                                                                                                                                              +14
                                                                                                                                                                                                              +15
                                                                                                                                                                                                              +16
                                                                                                                                                                                                              +17
                                                                                                                                                                                                              +18
                                                                                                                                                                                                              +19
                                                                                                                                                                                                              +20
                                                                                                                                                                                                              +21
                                                                                                                                                                                                              +22
                                                                                                                                                                                                              +23
                                                                                                                                                                                                              +24
                                                                                                                                                                                                              +25
                                                                                                                                                                                                              +26
                                                                                                                                                                                                              +27
                                                                                                                                                                                                              +28
                                                                                                                                                                                                              +29
                                                                                                                                                                                                              +30
                                                                                                                                                                                                              +31
                                                                                                                                                                                                              +32
                                                                                                                                                                                                              +33
                                                                                                                                                                                                              +34
                                                                                                                                                                                                              +35
                                                                                                                                                                                                              +36
                                                                                                                                                                                                              +37
                                                                                                                                                                                                              +38
                                                                                                                                                                                                              +39
                                                                                                                                                                                                              +40
                                                                                                                                                                                                              +41
                                                                                                                                                                                                              +42
                                                                                                                                                                                                              +43
                                                                                                                                                                                                              +44
                                                                                                                                                                                                              +45
                                                                                                                                                                                                              +46
                                                                                                                                                                                                              +47
                                                                                                                                                                                                              +48
                                                                                                                                                                                                              +49
                                                                                                                                                                                                              +50
                                                                                                                                                                                                              +51
                                                                                                                                                                                                              +52
                                                                                                                                                                                                              +53
                                                                                                                                                                                                              +54
                                                                                                                                                                                                              +55
                                                                                                                                                                                                              +56
                                                                                                                                                                                                              +57
                                                                                                                                                                                                              +58
                                                                                                                                                                                                              +59
                                                                                                                                                                                                              +60
                                                                                                                                                                                                              +61
                                                                                                                                                                                                              +62
                                                                                                                                                                                                              +63
                                                                                                                                                                                                              +64
                                                                                                                                                                                                              +65
                                                                                                                                                                                                              +66
                                                                                                                                                                                                              +67
                                                                                                                                                                                                              +68
                                                                                                                                                                                                              +69
                                                                                                                                                                                                              +70
                                                                                                                                                                                                              +71
                                                                                                                                                                                                              +72
                                                                                                                                                                                                              +73
                                                                                                                                                                                                              +74
                                                                                                                                                                                                              +75
                                                                                                                                                                                                              +76
                                                                                                                                                                                                              +77
                                                                                                                                                                                                              +78
                                                                                                                                                                                                              +79
                                                                                                                                                                                                              +80
                                                                                                                                                                                                              +81
                                                                                                                                                                                                              +82
                                                                                                                                                                                                              +83
                                                                                                                                                                                                              +84
                                                                                                                                                                                                              +85
                                                                                                                                                                                                              +86
                                                                                                                                                                                                              +87
                                                                                                                                                                                                              +88
                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board using the VL32L0X time of flight distance sensor
                                                                                                                                                                                                              +# Note the driver I used came from here: https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py
                                                                                                                                                                                                              +# Perhaps derived from here: https://github.com/uceeatz/VL53L0X/blob/master/VL53L0X.py
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# This demo makes the blue LEDs show the distance and prints the distance on the console
                                                                                                                                                                                                              +import machine
                                                                                                                                                                                                              +import time
                                                                                                                                                                                                              +import VL53L0X
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +sda=machine.Pin(0) # row one on our standard Pico breadboard
                                                                                                                                                                                                              +scl=machine.Pin(1) # row two on our standard Pico breadboard
                                                                                                                                                                                                              +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                              +# print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs which we can use 11
                                                                                                                                                                                                              +# The distance scale is non linear
                                                                                                                                                                                                              +# GP0 and GP1 will always be on since they are the I2C Data and Clock
                                                                                                                                                                                                              +blue_led_pins = [2, 3, 4,  5,  6,  7,  16, 17, 26, 27, 28]
                                                                                                                                                                                                              +dist_scale =    [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150]
                                                                                                                                                                                                              +number_leds = len(blue_led_pins)
                                                                                                                                                                                                              +led_ports = []
                                                                                                                                                                                                              +delay = .05
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# initial calibration parameters
                                                                                                                                                                                                              +ZERO_DIST = 60
                                                                                                                                                                                                              +MAX_DIST = 1200 # max raw distance we are able to read
                                                                                                                                                                                                              +SCALE_DIST = .3 # multiplier for raw to calibrated distance
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# create a list of the ports
                                                                                                                                                                                                              +for i in range(number_leds):
                                                                                                                                                                                                              +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# Create a VL53L0X object
                                                                                                                                                                                                              +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# get the normalized time-of-flight distance
                                                                                                                                                                                                              +def get_distance():
                                                                                                                                                                                                              +    global zero_dist, scale_factor
                                                                                                                                                                                                              +    tof_distance = tof.read()
                                                                                                                                                                                                              +    if tof_distance > MAX_DIST:
                                                                                                                                                                                                              +        return tof_distance
                                                                                                                                                                                                              +    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance
                                                                                                                                                                                                              +    if tof_distance < ZERO_DIST:
                                                                                                                                                                                                              +        zero_dist = tof_distance
                                                                                                                                                                                                              +    return  int((tof_distance - ZERO_DIST) * SCALE_DIST)
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# use the dist_scale to turn on LEDs
                                                                                                                                                                                                              +def led_show_dist(in_distance):
                                                                                                                                                                                                              +    global number_leds
                                                                                                                                                                                                              +    for led_index in range(0, number_leds):
                                                                                                                                                                                                              +        if in_distance > dist_scale[led_index]:
                                                                                                                                                                                                              +            led_ports[led_index].high()
                                                                                                                                                                                                              +        else:
                                                                                                                                                                                                              +            led_ports[led_index].low()
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +print('Using', number_leds, ' blue leds to show distance.')
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# blue up
                                                                                                                                                                                                              +for i in range(0, number_leds):
                                                                                                                                                                                                              +    led_ports[i].high()
                                                                                                                                                                                                              +    time.sleep(delay)
                                                                                                                                                                                                              +    led_ports[i].low()
                                                                                                                                                                                                              +# blue down
                                                                                                                                                                                                              +for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                              +    led_ports[i].high()
                                                                                                                                                                                                              +    time.sleep(delay)
                                                                                                                                                                                                              +    led_ports[i].low()
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# start our time-of-flight sensor
                                                                                                                                                                                                              +tof.start()
                                                                                                                                                                                                              +# autocalibrate the minimum distance
                                                                                                                                                                                                              +min_distance = 1000
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# loop forever
                                                                                                                                                                                                              +while True:
                                                                                                                                                                                                              +    raw_distance = get_distance()
                                                                                                                                                                                                              +    # recalibrate if we have a new min distance
                                                                                                                                                                                                              +    if raw_distance < min_distance:
                                                                                                                                                                                                              +        min_distance = raw_distance
                                                                                                                                                                                                              +    calibrated_distance = raw_distance - min_distance
                                                                                                                                                                                                              +    print(raw_distance, calibrated_distance)
                                                                                                                                                                                                              +    led_show_dist(calibrated_distance)
                                                                                                                                                                                                              +    time.sleep(0.05)
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +# clean up
                                                                                                                                                                                                              +tof.stop()
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +

                                                                                                                                                                                                              References

                                                                                                                                                                                                              +

                                                                                                                                                                                                              Kevin McAleer's GitHub Repo on the Vl53lx0 +Kevin McAleer's 662 line driver - I am not sure we need all 662 lines of code. +Kevin McAleer's Time of Flight Test

                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                              + Scanner Test +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                              + Time of Flight Sound Lab +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/11-ping-lab/index.html b/kits/maker-pi-rp2040-robot/11-ping-lab/index.html new file mode 100644 index 000000000..b6c5dd471 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/11-ping-lab/index.html @@ -0,0 +1,2261 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Ultrasonic Ping Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + Ultrasonic Ping Lab + + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              + + +
                                                                                                                                                                                                              + +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              +
                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                              +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                  + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                    + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                      + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Assembly + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Ultrasonic Ping Lab + + + + + + + +
                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                      • + + + Link to Sample Ping Lab + + + +
                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                  • + + + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                • + + + Link to Sample Ping Lab + + + +
                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                Ultrasonic Ping Sensor Lab

                                                                                                                                                                                                                +

                                                                                                                                                                                                                The Grove sensors on our Maker Pi RP2040 only supply 3.3 volts. So the standard very popular low cost HC-SR04 will not work, since it requires 5 volts of power. We have two options. One is to get a separate 5V power source, but the other is to purchase the new HC-SR04P (for Pico?) sensor that will work with our 3.3 volt power on our Grove connector.

                                                                                                                                                                                                                +

                                                                                                                                                                                                                Using the Grove 4 connection wire the HC-SP04P sensor with the trigger on GPIO-16 (White cable) and the echo on GPIO-17 (Yellow cable), VCC (Red cable), and GND (Black cable)

                                                                                                                                                                                                                +

                                                                                                                                                                                                                Ultrasonic Sensor

                                                                                                                                                                                                                +

                                                                                                                                                                                                                All wired up

                                                                                                                                                                                                                +

                                                                                                                                                                                                                Maker Pi RP2040 with sensor

                                                                                                                                                                                                                +
                                                                                                                                                                                                                 1
                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                +10
                                                                                                                                                                                                                +11
                                                                                                                                                                                                                +12
                                                                                                                                                                                                                +13
                                                                                                                                                                                                                +14
                                                                                                                                                                                                                +15
                                                                                                                                                                                                                +16
                                                                                                                                                                                                                +17
                                                                                                                                                                                                                +18
                                                                                                                                                                                                                +19
                                                                                                                                                                                                                +20
                                                                                                                                                                                                                +21
                                                                                                                                                                                                                +22
                                                                                                                                                                                                                +23
                                                                                                                                                                                                                +24
                                                                                                                                                                                                                +25
                                                                                                                                                                                                                +26
                                                                                                                                                                                                                +27
                                                                                                                                                                                                                +28
                                                                                                                                                                                                                +29
                                                                                                                                                                                                                +30
                                                                                                                                                                                                                +31
                                                                                                                                                                                                                # Sample code to test HC-SR04 Ultrasonice Ping Sensor
                                                                                                                                                                                                                +# Connect GND to any GND pin on the Pico
                                                                                                                                                                                                                +# Connnect VCC to VBUS or 5 Volt power
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +from machine import Pin, Timer
                                                                                                                                                                                                                +import utime
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner
                                                                                                                                                                                                                +ECHO_PIN = 17 # One up from bottom left corner
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +# Init HC-SR04 pins
                                                                                                                                                                                                                +trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
                                                                                                                                                                                                                +echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +def ping():
                                                                                                                                                                                                                +    trigger.low()
                                                                                                                                                                                                                +    utime.sleep_us(2) # Wait 2 microseconds low
                                                                                                                                                                                                                +    trigger.high()
                                                                                                                                                                                                                +    utime.sleep_us(5) # Stay high for 5 miroseconds
                                                                                                                                                                                                                +    trigger.low()
                                                                                                                                                                                                                +    while echo.value() == 0:
                                                                                                                                                                                                                +        signaloff = utime.ticks_us()
                                                                                                                                                                                                                +    while echo.value() == 1:
                                                                                                                                                                                                                +        signalon = utime.ticks_us()
                                                                                                                                                                                                                +    timepassed = signalon - signaloff
                                                                                                                                                                                                                +    distance = (timepassed * 0.0343) / 2
                                                                                                                                                                                                                +    return distance
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +while True:
                                                                                                                                                                                                                +    print("Distance:", ping(), "cm")
                                                                                                                                                                                                                +    utime.sleep(.25)
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +

                                                                                                                                                                                                                More advanced version with sound

                                                                                                                                                                                                                +
                                                                                                                                                                                                                 1
                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                +10
                                                                                                                                                                                                                +11
                                                                                                                                                                                                                +12
                                                                                                                                                                                                                +13
                                                                                                                                                                                                                +14
                                                                                                                                                                                                                +15
                                                                                                                                                                                                                +16
                                                                                                                                                                                                                +17
                                                                                                                                                                                                                +18
                                                                                                                                                                                                                +19
                                                                                                                                                                                                                +20
                                                                                                                                                                                                                +21
                                                                                                                                                                                                                +22
                                                                                                                                                                                                                +23
                                                                                                                                                                                                                +24
                                                                                                                                                                                                                +25
                                                                                                                                                                                                                +26
                                                                                                                                                                                                                +27
                                                                                                                                                                                                                +28
                                                                                                                                                                                                                +29
                                                                                                                                                                                                                +30
                                                                                                                                                                                                                +31
                                                                                                                                                                                                                +32
                                                                                                                                                                                                                +33
                                                                                                                                                                                                                +34
                                                                                                                                                                                                                +35
                                                                                                                                                                                                                +36
                                                                                                                                                                                                                +37
                                                                                                                                                                                                                +38
                                                                                                                                                                                                                +39
                                                                                                                                                                                                                +40
                                                                                                                                                                                                                +41
                                                                                                                                                                                                                +42
                                                                                                                                                                                                                +43
                                                                                                                                                                                                                +44
                                                                                                                                                                                                                +45
                                                                                                                                                                                                                +46
                                                                                                                                                                                                                +47
                                                                                                                                                                                                                +48
                                                                                                                                                                                                                +49
                                                                                                                                                                                                                +50
                                                                                                                                                                                                                # Sample code to test HC-SR04 Ultrasonice Ping Sensor
                                                                                                                                                                                                                +# Connect GND to any GND pin on the Pico
                                                                                                                                                                                                                +# Connnect VCC to VBUS or 5 Volt power
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +from machine import Pin, Timer, PWM
                                                                                                                                                                                                                +import utime
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner
                                                                                                                                                                                                                +ECHO_PIN = 17 # One up from bottom left corner
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +# Init HC-SR04 pins
                                                                                                                                                                                                                +trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
                                                                                                                                                                                                                +echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +BUZZER_PORT = 22
                                                                                                                                                                                                                +buzzer = PWM(Pin(BUZZER_PORT))
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +#  Note the non-linear increases in frequency - note that some are louder
                                                                                                                                                                                                                +tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]
                                                                                                                                                                                                                +def playtone(frequency):
                                                                                                                                                                                                                +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                +    buzzer.freq(frequency)
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +def bequiet():
                                                                                                                                                                                                                +    buzzer.duty_u16(0)
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +def ping():
                                                                                                                                                                                                                +    trigger.low()
                                                                                                                                                                                                                +    utime.sleep_us(2) # Wait 2 microseconds low
                                                                                                                                                                                                                +    trigger.high()
                                                                                                                                                                                                                +    utime.sleep_us(5) # Stay high for 5 miroseconds
                                                                                                                                                                                                                +    trigger.low()
                                                                                                                                                                                                                +    while echo.value() == 0:
                                                                                                                                                                                                                +        signaloff = utime.ticks_us()
                                                                                                                                                                                                                +    while echo.value() == 1:
                                                                                                                                                                                                                +        signalon = utime.ticks_us()
                                                                                                                                                                                                                +    timepassed = signalon - signaloff
                                                                                                                                                                                                                +    distance = (timepassed * 0.0343) / 2
                                                                                                                                                                                                                +    return distance
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +while True:
                                                                                                                                                                                                                +    dist=round(ping())
                                                                                                                                                                                                                +    print("Distance:", dist, "cm")
                                                                                                                                                                                                                +    if dist < 20:
                                                                                                                                                                                                                +        print("Panic")
                                                                                                                                                                                                                +        playtone(350)
                                                                                                                                                                                                                +        # Beep faster the closer you get
                                                                                                                                                                                                                +        utime.sleep(.05/(20/dist))
                                                                                                                                                                                                                +        bequiet()
                                                                                                                                                                                                                +    utime.sleep(.1)
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +

                                                                                                                                                                                                                Link to Sample Ping Lab

                                                                                                                                                                                                                +

                                                                                                                                                                                                                This code is very similar to the previous ping lab but with the different GPIO lines used.

                                                                                                                                                                                                                +

                                                                                                                                                                                                                Link to Standard Ping Lab

                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                + MicroSwitch Bot +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                + Collision Avoidance Time-of-Flight +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab/index.html b/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab/index.html new file mode 100644 index 000000000..27d0c34a0 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab/index.html @@ -0,0 +1,2266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Time of Flight Sound Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + Time of Flight Sound Lab + + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                + +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                    + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                      + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Assembly + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + Time of Flight Sound Lab + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                    • + + + + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                  Time of Flight Distance Sensor Test

                                                                                                                                                                                                                  +
                                                                                                                                                                                                                    1
                                                                                                                                                                                                                  +  2
                                                                                                                                                                                                                  +  3
                                                                                                                                                                                                                  +  4
                                                                                                                                                                                                                  +  5
                                                                                                                                                                                                                  +  6
                                                                                                                                                                                                                  +  7
                                                                                                                                                                                                                  +  8
                                                                                                                                                                                                                  +  9
                                                                                                                                                                                                                  + 10
                                                                                                                                                                                                                  + 11
                                                                                                                                                                                                                  + 12
                                                                                                                                                                                                                  + 13
                                                                                                                                                                                                                  + 14
                                                                                                                                                                                                                  + 15
                                                                                                                                                                                                                  + 16
                                                                                                                                                                                                                  + 17
                                                                                                                                                                                                                  + 18
                                                                                                                                                                                                                  + 19
                                                                                                                                                                                                                  + 20
                                                                                                                                                                                                                  + 21
                                                                                                                                                                                                                  + 22
                                                                                                                                                                                                                  + 23
                                                                                                                                                                                                                  + 24
                                                                                                                                                                                                                  + 25
                                                                                                                                                                                                                  + 26
                                                                                                                                                                                                                  + 27
                                                                                                                                                                                                                  + 28
                                                                                                                                                                                                                  + 29
                                                                                                                                                                                                                  + 30
                                                                                                                                                                                                                  + 31
                                                                                                                                                                                                                  + 32
                                                                                                                                                                                                                  + 33
                                                                                                                                                                                                                  + 34
                                                                                                                                                                                                                  + 35
                                                                                                                                                                                                                  + 36
                                                                                                                                                                                                                  + 37
                                                                                                                                                                                                                  + 38
                                                                                                                                                                                                                  + 39
                                                                                                                                                                                                                  + 40
                                                                                                                                                                                                                  + 41
                                                                                                                                                                                                                  + 42
                                                                                                                                                                                                                  + 43
                                                                                                                                                                                                                  + 44
                                                                                                                                                                                                                  + 45
                                                                                                                                                                                                                  + 46
                                                                                                                                                                                                                  + 47
                                                                                                                                                                                                                  + 48
                                                                                                                                                                                                                  + 49
                                                                                                                                                                                                                  + 50
                                                                                                                                                                                                                  + 51
                                                                                                                                                                                                                  + 52
                                                                                                                                                                                                                  + 53
                                                                                                                                                                                                                  + 54
                                                                                                                                                                                                                  + 55
                                                                                                                                                                                                                  + 56
                                                                                                                                                                                                                  + 57
                                                                                                                                                                                                                  + 58
                                                                                                                                                                                                                  + 59
                                                                                                                                                                                                                  + 60
                                                                                                                                                                                                                  + 61
                                                                                                                                                                                                                  + 62
                                                                                                                                                                                                                  + 63
                                                                                                                                                                                                                  + 64
                                                                                                                                                                                                                  + 65
                                                                                                                                                                                                                  + 66
                                                                                                                                                                                                                  + 67
                                                                                                                                                                                                                  + 68
                                                                                                                                                                                                                  + 69
                                                                                                                                                                                                                  + 70
                                                                                                                                                                                                                  + 71
                                                                                                                                                                                                                  + 72
                                                                                                                                                                                                                  + 73
                                                                                                                                                                                                                  + 74
                                                                                                                                                                                                                  + 75
                                                                                                                                                                                                                  + 76
                                                                                                                                                                                                                  + 77
                                                                                                                                                                                                                  + 78
                                                                                                                                                                                                                  + 79
                                                                                                                                                                                                                  + 80
                                                                                                                                                                                                                  + 81
                                                                                                                                                                                                                  + 82
                                                                                                                                                                                                                  + 83
                                                                                                                                                                                                                  + 84
                                                                                                                                                                                                                  + 85
                                                                                                                                                                                                                  + 86
                                                                                                                                                                                                                  + 87
                                                                                                                                                                                                                  + 88
                                                                                                                                                                                                                  + 89
                                                                                                                                                                                                                  + 90
                                                                                                                                                                                                                  + 91
                                                                                                                                                                                                                  + 92
                                                                                                                                                                                                                  + 93
                                                                                                                                                                                                                  + 94
                                                                                                                                                                                                                  + 95
                                                                                                                                                                                                                  + 96
                                                                                                                                                                                                                  + 97
                                                                                                                                                                                                                  + 98
                                                                                                                                                                                                                  + 99
                                                                                                                                                                                                                  +100
                                                                                                                                                                                                                  +101
                                                                                                                                                                                                                  +102
                                                                                                                                                                                                                  +103
                                                                                                                                                                                                                  +104
                                                                                                                                                                                                                  +105
                                                                                                                                                                                                                  +106
                                                                                                                                                                                                                  +107
                                                                                                                                                                                                                  +108
                                                                                                                                                                                                                  +109
                                                                                                                                                                                                                  +110
                                                                                                                                                                                                                  +111
                                                                                                                                                                                                                  +112
                                                                                                                                                                                                                  +113
                                                                                                                                                                                                                  +114
                                                                                                                                                                                                                  +115
                                                                                                                                                                                                                  +116
                                                                                                                                                                                                                  # Demo for Maker Pi RP2040 board
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +from machine import Pin,PWM
                                                                                                                                                                                                                  +import time
                                                                                                                                                                                                                  +import VL53L0X
                                                                                                                                                                                                                  +buzzer=PWM(Pin(22))
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +sda=machine.Pin(0) # row one on our standard Pico breadboard
                                                                                                                                                                                                                  +scl=machine.Pin(1) # row two on our standard Pico breadboard
                                                                                                                                                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                  +# print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs
                                                                                                                                                                                                                  +blue_led_pins = [2, 3,  4,  5,  6,  7, 16, 17, 26, 27, 28]
                                                                                                                                                                                                                  +# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]
                                                                                                                                                                                                                  +dist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                  +led_ports = []
                                                                                                                                                                                                                  +delay = .05
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# calibration parameters
                                                                                                                                                                                                                  +zero_dist = 65 # distance measure when an object is about 1/2 cm away
                                                                                                                                                                                                                  +max_dist = 350 # max distance we are able to read
                                                                                                                                                                                                                  +scale_factor = .2
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# create a list of the ports
                                                                                                                                                                                                                  +for i in range(number_leds):
                                                                                                                                                                                                                  +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# Create a VL53L0X object
                                                                                                                                                                                                                  +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# blue up
                                                                                                                                                                                                                  +for i in range(0, number_leds):
                                                                                                                                                                                                                  +    led_ports[i].high()
                                                                                                                                                                                                                  +    time.sleep(delay)
                                                                                                                                                                                                                  +    led_ports[i].low()
                                                                                                                                                                                                                  +# blue down
                                                                                                                                                                                                                  +for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                                  +    led_ports[i].high()
                                                                                                                                                                                                                  +    time.sleep(delay)
                                                                                                                                                                                                                  +    led_ports[i].low()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# get the normalized time-of-flight distance
                                                                                                                                                                                                                  +def get_distance():
                                                                                                                                                                                                                  +    global zero_dist, scale_factor
                                                                                                                                                                                                                  +    tof_distance = tof.read()
                                                                                                                                                                                                                  +    if tof_distance > max_dist:
                                                                                                                                                                                                                  +        return tof_distance
                                                                                                                                                                                                                  +    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance
                                                                                                                                                                                                                  +    if tof_distance < zero_dist:
                                                                                                                                                                                                                  +        zero_dist = tof_distance
                                                                                                                                                                                                                  +    return  int((tof_distance - zero_dist) * scale_factor)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +def led_show_dist(in_distance):
                                                                                                                                                                                                                  +    global number_leds
                                                                                                                                                                                                                  +    for led_index in range(0, number_leds):
                                                                                                                                                                                                                  +        if in_distance > dist_scale[led_index]:
                                                                                                                                                                                                                  +            led_ports[led_index].high()
                                                                                                                                                                                                                  +        else:
                                                                                                                                                                                                                  +            led_ports[led_index].low()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +def playtone(frequency):
                                                                                                                                                                                                                  +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                  +    buzzer.freq(frequency)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +def bequiet():
                                                                                                                                                                                                                  +    buzzer.duty_u16(0)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +def play_no_signal():
                                                                                                                                                                                                                  +    playtone(100)
                                                                                                                                                                                                                  +    time.sleep(0.1)
                                                                                                                                                                                                                  +    bequiet()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +def play_turn():
                                                                                                                                                                                                                  +    playtone(500)
                                                                                                                                                                                                                  +    time.sleep(0.1)
                                                                                                                                                                                                                  +    bequiet()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# start our time-of-flight sensor
                                                                                                                                                                                                                  +tof.start()
                                                                                                                                                                                                                  +valid_distance = 1
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# loop forever
                                                                                                                                                                                                                  +def main():
                                                                                                                                                                                                                  +    while True:
                                                                                                                                                                                                                  +        global valid_distance
                                                                                                                                                                                                                  +        distance = get_distance()
                                                                                                                                                                                                                  +        if distance > 1000:
                                                                                                                                                                                                                  +            # only print if we used to have a valid distance
                                                                                                                                                                                                                  +            if valid_distance == 1:
                                                                                                                                                                                                                  +                print('no signal')
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +            valid_distance = 0
                                                                                                                                                                                                                  +        else:
                                                                                                                                                                                                                  +            print(distance)
                                                                                                                                                                                                                  +            if distance < 30:
                                                                                                                                                                                                                  +                play_turn()
                                                                                                                                                                                                                  +            valid_distance = 1
                                                                                                                                                                                                                  +            led_show_dist(distance)
                                                                                                                                                                                                                  +        time.sleep(0.05)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# clean up
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup
                                                                                                                                                                                                                  +try:
                                                                                                                                                                                                                  +    main()
                                                                                                                                                                                                                  +except KeyboardInterrupt:
                                                                                                                                                                                                                  +    print('Got ctrl-c')
                                                                                                                                                                                                                  +finally:
                                                                                                                                                                                                                  +    # Optional cleanup code
                                                                                                                                                                                                                  +    print('turning off sound')
                                                                                                                                                                                                                  +    buzzer.duty_u16(0)
                                                                                                                                                                                                                  +    tof.stop()
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                  + Time of Flight Lab +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                  + MicroSwitch Bot +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot/index.html b/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot/index.html new file mode 100644 index 000000000..41b3731ff --- /dev/null +++ b/kits/maker-pi-rp2040-robot/20-collision-avoidance-robot/index.html @@ -0,0 +1,2485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Collision Avoidance Time-of-Flight - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + Collision Avoidance Time-of-Flight + + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                      + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                        + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Assembly + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Collision Avoidance Time-of-Flight + + + + + + + +
                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                          • + + + Random Turn Direction + + + +
                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                      • + + + + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                    • + + + Random Turn Direction + + + +
                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                    Maker Pi RP2040 Collision Avoidance Robot

                                                                                                                                                                                                                    +

                                                                                                                                                                                                                    This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board.

                                                                                                                                                                                                                    +

                                                                                                                                                                                                                    The board is mounted on a SmartCar Chassis and Grove Connector 0 is used to connect to a Time-of-Flight distance sensor that is using the I2C bus.

                                                                                                                                                                                                                    +

                                                                                                                                                                                                                    Random Turn Direction

                                                                                                                                                                                                                    +
                                                                                                                                                                                                                     1
                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                    if dist < TURN_DIST:
                                                                                                                                                                                                                    +    play_reverse()
                                                                                                                                                                                                                    +    reverse()
                                                                                                                                                                                                                    +    sleep(REVERSE_TIME)
                                                                                                                                                                                                                    +    # half right and half left turns
                                                                                                                                                                                                                    +    if urandom.random() < .5:
                                                                                                                                                                                                                    +        turn_right()
                                                                                                                                                                                                                    +        play_turn_right()
                                                                                                                                                                                                                    +    else:
                                                                                                                                                                                                                    +        turn_left()
                                                                                                                                                                                                                    +        play_turn_left()
                                                                                                                                                                                                                    +    sleep(TURN_TIME)
                                                                                                                                                                                                                    +    forward()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                      1
                                                                                                                                                                                                                    +  2
                                                                                                                                                                                                                    +  3
                                                                                                                                                                                                                    +  4
                                                                                                                                                                                                                    +  5
                                                                                                                                                                                                                    +  6
                                                                                                                                                                                                                    +  7
                                                                                                                                                                                                                    +  8
                                                                                                                                                                                                                    +  9
                                                                                                                                                                                                                    + 10
                                                                                                                                                                                                                    + 11
                                                                                                                                                                                                                    + 12
                                                                                                                                                                                                                    + 13
                                                                                                                                                                                                                    + 14
                                                                                                                                                                                                                    + 15
                                                                                                                                                                                                                    + 16
                                                                                                                                                                                                                    + 17
                                                                                                                                                                                                                    + 18
                                                                                                                                                                                                                    + 19
                                                                                                                                                                                                                    + 20
                                                                                                                                                                                                                    + 21
                                                                                                                                                                                                                    + 22
                                                                                                                                                                                                                    + 23
                                                                                                                                                                                                                    + 24
                                                                                                                                                                                                                    + 25
                                                                                                                                                                                                                    + 26
                                                                                                                                                                                                                    + 27
                                                                                                                                                                                                                    + 28
                                                                                                                                                                                                                    + 29
                                                                                                                                                                                                                    + 30
                                                                                                                                                                                                                    + 31
                                                                                                                                                                                                                    + 32
                                                                                                                                                                                                                    + 33
                                                                                                                                                                                                                    + 34
                                                                                                                                                                                                                    + 35
                                                                                                                                                                                                                    + 36
                                                                                                                                                                                                                    + 37
                                                                                                                                                                                                                    + 38
                                                                                                                                                                                                                    + 39
                                                                                                                                                                                                                    + 40
                                                                                                                                                                                                                    + 41
                                                                                                                                                                                                                    + 42
                                                                                                                                                                                                                    + 43
                                                                                                                                                                                                                    + 44
                                                                                                                                                                                                                    + 45
                                                                                                                                                                                                                    + 46
                                                                                                                                                                                                                    + 47
                                                                                                                                                                                                                    + 48
                                                                                                                                                                                                                    + 49
                                                                                                                                                                                                                    + 50
                                                                                                                                                                                                                    + 51
                                                                                                                                                                                                                    + 52
                                                                                                                                                                                                                    + 53
                                                                                                                                                                                                                    + 54
                                                                                                                                                                                                                    + 55
                                                                                                                                                                                                                    + 56
                                                                                                                                                                                                                    + 57
                                                                                                                                                                                                                    + 58
                                                                                                                                                                                                                    + 59
                                                                                                                                                                                                                    + 60
                                                                                                                                                                                                                    + 61
                                                                                                                                                                                                                    + 62
                                                                                                                                                                                                                    + 63
                                                                                                                                                                                                                    + 64
                                                                                                                                                                                                                    + 65
                                                                                                                                                                                                                    + 66
                                                                                                                                                                                                                    + 67
                                                                                                                                                                                                                    + 68
                                                                                                                                                                                                                    + 69
                                                                                                                                                                                                                    + 70
                                                                                                                                                                                                                    + 71
                                                                                                                                                                                                                    + 72
                                                                                                                                                                                                                    + 73
                                                                                                                                                                                                                    + 74
                                                                                                                                                                                                                    + 75
                                                                                                                                                                                                                    + 76
                                                                                                                                                                                                                    + 77
                                                                                                                                                                                                                    + 78
                                                                                                                                                                                                                    + 79
                                                                                                                                                                                                                    + 80
                                                                                                                                                                                                                    + 81
                                                                                                                                                                                                                    + 82
                                                                                                                                                                                                                    + 83
                                                                                                                                                                                                                    + 84
                                                                                                                                                                                                                    + 85
                                                                                                                                                                                                                    + 86
                                                                                                                                                                                                                    + 87
                                                                                                                                                                                                                    + 88
                                                                                                                                                                                                                    + 89
                                                                                                                                                                                                                    + 90
                                                                                                                                                                                                                    + 91
                                                                                                                                                                                                                    + 92
                                                                                                                                                                                                                    + 93
                                                                                                                                                                                                                    + 94
                                                                                                                                                                                                                    + 95
                                                                                                                                                                                                                    + 96
                                                                                                                                                                                                                    + 97
                                                                                                                                                                                                                    + 98
                                                                                                                                                                                                                    + 99
                                                                                                                                                                                                                    +100
                                                                                                                                                                                                                    +101
                                                                                                                                                                                                                    +102
                                                                                                                                                                                                                    +103
                                                                                                                                                                                                                    +104
                                                                                                                                                                                                                    +105
                                                                                                                                                                                                                    +106
                                                                                                                                                                                                                    +107
                                                                                                                                                                                                                    +108
                                                                                                                                                                                                                    +109
                                                                                                                                                                                                                    +110
                                                                                                                                                                                                                    +111
                                                                                                                                                                                                                    +112
                                                                                                                                                                                                                    +113
                                                                                                                                                                                                                    +114
                                                                                                                                                                                                                    +115
                                                                                                                                                                                                                    +116
                                                                                                                                                                                                                    +117
                                                                                                                                                                                                                    +118
                                                                                                                                                                                                                    +119
                                                                                                                                                                                                                    +120
                                                                                                                                                                                                                    +121
                                                                                                                                                                                                                    +122
                                                                                                                                                                                                                    +123
                                                                                                                                                                                                                    +124
                                                                                                                                                                                                                    +125
                                                                                                                                                                                                                    +126
                                                                                                                                                                                                                    +127
                                                                                                                                                                                                                    +128
                                                                                                                                                                                                                    +129
                                                                                                                                                                                                                    +130
                                                                                                                                                                                                                    +131
                                                                                                                                                                                                                    +132
                                                                                                                                                                                                                    +133
                                                                                                                                                                                                                    +134
                                                                                                                                                                                                                    +135
                                                                                                                                                                                                                    +136
                                                                                                                                                                                                                    +137
                                                                                                                                                                                                                    +138
                                                                                                                                                                                                                    +139
                                                                                                                                                                                                                    +140
                                                                                                                                                                                                                    +141
                                                                                                                                                                                                                    +142
                                                                                                                                                                                                                    +143
                                                                                                                                                                                                                    +144
                                                                                                                                                                                                                    +145
                                                                                                                                                                                                                    +146
                                                                                                                                                                                                                    +147
                                                                                                                                                                                                                    +148
                                                                                                                                                                                                                    +149
                                                                                                                                                                                                                    +150
                                                                                                                                                                                                                    +151
                                                                                                                                                                                                                    +152
                                                                                                                                                                                                                    +153
                                                                                                                                                                                                                    +154
                                                                                                                                                                                                                    +155
                                                                                                                                                                                                                    +156
                                                                                                                                                                                                                    +157
                                                                                                                                                                                                                    +158
                                                                                                                                                                                                                    +159
                                                                                                                                                                                                                    +160
                                                                                                                                                                                                                    +161
                                                                                                                                                                                                                    +162
                                                                                                                                                                                                                    +163
                                                                                                                                                                                                                    +164
                                                                                                                                                                                                                    +165
                                                                                                                                                                                                                    +166
                                                                                                                                                                                                                    +167
                                                                                                                                                                                                                    +168
                                                                                                                                                                                                                    +169
                                                                                                                                                                                                                    +170
                                                                                                                                                                                                                    +171
                                                                                                                                                                                                                    +172
                                                                                                                                                                                                                    +173
                                                                                                                                                                                                                    +174
                                                                                                                                                                                                                    +175
                                                                                                                                                                                                                    +176
                                                                                                                                                                                                                    +177
                                                                                                                                                                                                                    +178
                                                                                                                                                                                                                    +179
                                                                                                                                                                                                                    +180
                                                                                                                                                                                                                    +181
                                                                                                                                                                                                                    +182
                                                                                                                                                                                                                    +183
                                                                                                                                                                                                                    # Demo for Maker Pi RP2040 board
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +from machine import Pin,PWM
                                                                                                                                                                                                                    +from time import sleep, sleep_ms
                                                                                                                                                                                                                    +import urandom
                                                                                                                                                                                                                    +import VL53L0X
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# Piezo Buzzer is on GP22
                                                                                                                                                                                                                    +buzzer=PWM(Pin(22))
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# this is the max power level
                                                                                                                                                                                                                    +POWER_LEVEL = 65025
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# Motor Pins are A: 8,9 and B: 10,11
                                                                                                                                                                                                                    +RIGHT_FORWARD_PIN = 8
                                                                                                                                                                                                                    +RIGHT_REVERSE_PIN = 9
                                                                                                                                                                                                                    +LEFT_FORWARD_PIN = 11
                                                                                                                                                                                                                    +LEFT_REVERSE_PIN = 10
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# our PWM objects
                                                                                                                                                                                                                    +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                    +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                    +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                    +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def turn_motor_on(pwm):
                                                                                                                                                                                                                    +   pwm.duty_u16(65025)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def turn_motor_off(pwm):
                                                                                                                                                                                                                    +   pwm.duty_u16(0)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def forward():
                                                                                                                                                                                                                    +    turn_motor_on(right_forward)
                                                                                                                                                                                                                    +    turn_motor_on(left_forward)
                                                                                                                                                                                                                    +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                    +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def reverse():
                                                                                                                                                                                                                    +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                    +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                    +    turn_motor_off(right_forward)
                                                                                                                                                                                                                    +    turn_motor_off(left_forward)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def turn_right():
                                                                                                                                                                                                                    +    turn_motor_on(right_forward)
                                                                                                                                                                                                                    +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                    +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                    +    turn_motor_off(left_forward)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def turn_left():
                                                                                                                                                                                                                    +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                    +    turn_motor_on(left_forward)
                                                                                                                                                                                                                    +    turn_motor_off(right_forward)
                                                                                                                                                                                                                    +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def stop():
                                                                                                                                                                                                                    +    turn_motor_off(right_forward)
                                                                                                                                                                                                                    +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                    +    turn_motor_off(left_forward)
                                                                                                                                                                                                                    +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# Time of flight sensor is on the I2C bus on Grove connector 0
                                                                                                                                                                                                                    +sda=machine.Pin(0) # row one on our standard Pico breadboard
                                                                                                                                                                                                                    +scl=machine.Pin(1) # row two on our standard Pico breadboard
                                                                                                                                                                                                                    +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                    +# print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs
                                                                                                                                                                                                                    +blue_led_pins = [2, 3,  4,  5,  6,  7, 16, 17, 26, 27, 28]
                                                                                                                                                                                                                    +# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]
                                                                                                                                                                                                                    +dist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                    +led_ports = []
                                                                                                                                                                                                                    +delay = .05
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# calibration parameters
                                                                                                                                                                                                                    +zero_dist = 65 # distance measure when an object is about 1/2 cm away
                                                                                                                                                                                                                    +max_dist = 350 # max distance we are able to read
                                                                                                                                                                                                                    +scale_factor = .2
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# create a list of the ports
                                                                                                                                                                                                                    +for i in range(number_leds):
                                                                                                                                                                                                                    +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# Create a VL53L0X object
                                                                                                                                                                                                                    +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# blue up
                                                                                                                                                                                                                    +for i in range(0, number_leds):
                                                                                                                                                                                                                    +    led_ports[i].high()
                                                                                                                                                                                                                    +    time.sleep(delay)
                                                                                                                                                                                                                    +    led_ports[i].low()
                                                                                                                                                                                                                    +# blue down
                                                                                                                                                                                                                    +for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                                    +    led_ports[i].high()
                                                                                                                                                                                                                    +    time.sleep(delay)
                                                                                                                                                                                                                    +    led_ports[i].low()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# get the normalized time-of-flight distance
                                                                                                                                                                                                                    +def get_distance():
                                                                                                                                                                                                                    +    global zero_dist, scale_factor
                                                                                                                                                                                                                    +    tof_distance = tof.read()
                                                                                                                                                                                                                    +    if tof_distance > max_dist:
                                                                                                                                                                                                                    +        return tof_distance
                                                                                                                                                                                                                    +    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance
                                                                                                                                                                                                                    +    if tof_distance < zero_dist:
                                                                                                                                                                                                                    +        zero_dist = tof_distance
                                                                                                                                                                                                                    +    return  int((tof_distance - zero_dist) * scale_factor)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def led_show_dist(in_distance):
                                                                                                                                                                                                                    +    global number_leds
                                                                                                                                                                                                                    +    for led_index in range(0, number_leds):
                                                                                                                                                                                                                    +        if in_distance > dist_scale[led_index]:
                                                                                                                                                                                                                    +            led_ports[led_index].high()
                                                                                                                                                                                                                    +        else:
                                                                                                                                                                                                                    +            led_ports[led_index].low()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def playtone(frequency):
                                                                                                                                                                                                                    +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                    +    buzzer.freq(frequency)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def bequiet():
                                                                                                                                                                                                                    +    buzzer.duty_u16(0)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def play_no_signal():
                                                                                                                                                                                                                    +    playtone(100)
                                                                                                                                                                                                                    +    time.sleep(0.1)
                                                                                                                                                                                                                    +    bequiet()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +def play_turn():
                                                                                                                                                                                                                    +    playtone(500)
                                                                                                                                                                                                                    +    sleep(0.1)
                                                                                                                                                                                                                    +    bequiet()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# start our time-of-flight sensor
                                                                                                                                                                                                                    +tof.start()
                                                                                                                                                                                                                    +valid_distance = 1
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# loop forever
                                                                                                                                                                                                                    +def main():
                                                                                                                                                                                                                    +    global valid_distance
                                                                                                                                                                                                                    +    while True:  
                                                                                                                                                                                                                    +        distance = get_distance()
                                                                                                                                                                                                                    +        if distance > 1000:
                                                                                                                                                                                                                    +            # only print if we used to have a valid distance
                                                                                                                                                                                                                    +            if valid_distance == 1:
                                                                                                                                                                                                                    +                print('no signal')      
                                                                                                                                                                                                                    +            valid_distance = 0
                                                                                                                                                                                                                    +        else:
                                                                                                                                                                                                                    +            print(distance)
                                                                                                                                                                                                                    +            if distance < 30:
                                                                                                                                                                                                                    +                play_turn()
                                                                                                                                                                                                                    +                # back up for 1/2 second
                                                                                                                                                                                                                    +                reverse()
                                                                                                                                                                                                                    +                sleep(0.5)
                                                                                                                                                                                                                    +                turn_right()
                                                                                                                                                                                                                    +                sleep(0.75)
                                                                                                                                                                                                                    +                forward()
                                                                                                                                                                                                                    +            else:
                                                                                                                                                                                                                    +                print('forward')
                                                                                                                                                                                                                    +                forward()
                                                                                                                                                                                                                    +            valid_distance = 1
                                                                                                                                                                                                                    +            led_show_dist(distance)
                                                                                                                                                                                                                    +        sleep(0.05)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# clean up
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup
                                                                                                                                                                                                                    +try:
                                                                                                                                                                                                                    +    main()
                                                                                                                                                                                                                    +except KeyboardInterrupt:
                                                                                                                                                                                                                    +    print('Got ctrl-c')
                                                                                                                                                                                                                    +finally:
                                                                                                                                                                                                                    +    # Optional cleanup code
                                                                                                                                                                                                                    +    print('turning off sound')
                                                                                                                                                                                                                    +    buzzer.duty_u16(0)
                                                                                                                                                                                                                    +    print('powering down all motors')
                                                                                                                                                                                                                    +    stop()
                                                                                                                                                                                                                    +    print('stopping time of flight sensor')
                                                                                                                                                                                                                    +    tof.stop()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                    + Ultrasonic Ping Lab +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                    + Collision Avoidance Ping +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/index.html b/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/index.html new file mode 100644 index 000000000..22379c5a0 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/index.html @@ -0,0 +1,2695 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Collision Avoidance Ping - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + Collision Avoidance Ping + + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                        + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                          + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Assembly + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Collision Avoidance Ping + + + + + + + +
                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            • + + + Robot Parameters + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            • + + + Full Source Code + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            • + + + Experiments + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                        • + + + + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                      • + + + Robot Parameters + + + +
                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                      • + + + Full Source Code + + + +
                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                      • + + + Experiments + + + +
                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                      Maker Pi RP2040 Collision Avoidance Robot With Ping Sensor

                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board.

                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      The board is mounted on a SmartCar Chassis and Grove Connector 4 is used to connect +the ultrasonic ping sensor. Connect the Trigger on white and Echo on yellow. The black should be connected to GND and the Red is connected to the VCC which on the

                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      The robot has an initial mode of 0, which will run the blue LEDs and change colors on the Neopixels. By pressing the on-board button you will start the collision avoidance program.

                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      Robot Parameters

                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      There are four different robot parameters you can adjust. They change the speed and distance before the robot backs up. You can also adjust the time the robots goes into reverse and the time it turns.

                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      1
                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                      +4
                                                                                                                                                                                                                      POWER_LEVEL = 35000 # max is 
                                                                                                                                                                                                                      +TURN_DISTANCE = 20 # distance in cm we decide to turn - try 20
                                                                                                                                                                                                                      +REVERSE_TIME = .4 # how long we backup
                                                                                                                                                                                                                      +TURN_TIME = .4 # how long we turn
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      Full Source Code

                                                                                                                                                                                                                      +
                                                                                                                                                                                                                        1
                                                                                                                                                                                                                      +  2
                                                                                                                                                                                                                      +  3
                                                                                                                                                                                                                      +  4
                                                                                                                                                                                                                      +  5
                                                                                                                                                                                                                      +  6
                                                                                                                                                                                                                      +  7
                                                                                                                                                                                                                      +  8
                                                                                                                                                                                                                      +  9
                                                                                                                                                                                                                      + 10
                                                                                                                                                                                                                      + 11
                                                                                                                                                                                                                      + 12
                                                                                                                                                                                                                      + 13
                                                                                                                                                                                                                      + 14
                                                                                                                                                                                                                      + 15
                                                                                                                                                                                                                      + 16
                                                                                                                                                                                                                      + 17
                                                                                                                                                                                                                      + 18
                                                                                                                                                                                                                      + 19
                                                                                                                                                                                                                      + 20
                                                                                                                                                                                                                      + 21
                                                                                                                                                                                                                      + 22
                                                                                                                                                                                                                      + 23
                                                                                                                                                                                                                      + 24
                                                                                                                                                                                                                      + 25
                                                                                                                                                                                                                      + 26
                                                                                                                                                                                                                      + 27
                                                                                                                                                                                                                      + 28
                                                                                                                                                                                                                      + 29
                                                                                                                                                                                                                      + 30
                                                                                                                                                                                                                      + 31
                                                                                                                                                                                                                      + 32
                                                                                                                                                                                                                      + 33
                                                                                                                                                                                                                      + 34
                                                                                                                                                                                                                      + 35
                                                                                                                                                                                                                      + 36
                                                                                                                                                                                                                      + 37
                                                                                                                                                                                                                      + 38
                                                                                                                                                                                                                      + 39
                                                                                                                                                                                                                      + 40
                                                                                                                                                                                                                      + 41
                                                                                                                                                                                                                      + 42
                                                                                                                                                                                                                      + 43
                                                                                                                                                                                                                      + 44
                                                                                                                                                                                                                      + 45
                                                                                                                                                                                                                      + 46
                                                                                                                                                                                                                      + 47
                                                                                                                                                                                                                      + 48
                                                                                                                                                                                                                      + 49
                                                                                                                                                                                                                      + 50
                                                                                                                                                                                                                      + 51
                                                                                                                                                                                                                      + 52
                                                                                                                                                                                                                      + 53
                                                                                                                                                                                                                      + 54
                                                                                                                                                                                                                      + 55
                                                                                                                                                                                                                      + 56
                                                                                                                                                                                                                      + 57
                                                                                                                                                                                                                      + 58
                                                                                                                                                                                                                      + 59
                                                                                                                                                                                                                      + 60
                                                                                                                                                                                                                      + 61
                                                                                                                                                                                                                      + 62
                                                                                                                                                                                                                      + 63
                                                                                                                                                                                                                      + 64
                                                                                                                                                                                                                      + 65
                                                                                                                                                                                                                      + 66
                                                                                                                                                                                                                      + 67
                                                                                                                                                                                                                      + 68
                                                                                                                                                                                                                      + 69
                                                                                                                                                                                                                      + 70
                                                                                                                                                                                                                      + 71
                                                                                                                                                                                                                      + 72
                                                                                                                                                                                                                      + 73
                                                                                                                                                                                                                      + 74
                                                                                                                                                                                                                      + 75
                                                                                                                                                                                                                      + 76
                                                                                                                                                                                                                      + 77
                                                                                                                                                                                                                      + 78
                                                                                                                                                                                                                      + 79
                                                                                                                                                                                                                      + 80
                                                                                                                                                                                                                      + 81
                                                                                                                                                                                                                      + 82
                                                                                                                                                                                                                      + 83
                                                                                                                                                                                                                      + 84
                                                                                                                                                                                                                      + 85
                                                                                                                                                                                                                      + 86
                                                                                                                                                                                                                      + 87
                                                                                                                                                                                                                      + 88
                                                                                                                                                                                                                      + 89
                                                                                                                                                                                                                      + 90
                                                                                                                                                                                                                      + 91
                                                                                                                                                                                                                      + 92
                                                                                                                                                                                                                      + 93
                                                                                                                                                                                                                      + 94
                                                                                                                                                                                                                      + 95
                                                                                                                                                                                                                      + 96
                                                                                                                                                                                                                      + 97
                                                                                                                                                                                                                      + 98
                                                                                                                                                                                                                      + 99
                                                                                                                                                                                                                      +100
                                                                                                                                                                                                                      +101
                                                                                                                                                                                                                      +102
                                                                                                                                                                                                                      +103
                                                                                                                                                                                                                      +104
                                                                                                                                                                                                                      +105
                                                                                                                                                                                                                      +106
                                                                                                                                                                                                                      +107
                                                                                                                                                                                                                      +108
                                                                                                                                                                                                                      +109
                                                                                                                                                                                                                      +110
                                                                                                                                                                                                                      +111
                                                                                                                                                                                                                      +112
                                                                                                                                                                                                                      +113
                                                                                                                                                                                                                      +114
                                                                                                                                                                                                                      +115
                                                                                                                                                                                                                      +116
                                                                                                                                                                                                                      +117
                                                                                                                                                                                                                      +118
                                                                                                                                                                                                                      +119
                                                                                                                                                                                                                      +120
                                                                                                                                                                                                                      +121
                                                                                                                                                                                                                      +122
                                                                                                                                                                                                                      +123
                                                                                                                                                                                                                      +124
                                                                                                                                                                                                                      +125
                                                                                                                                                                                                                      +126
                                                                                                                                                                                                                      +127
                                                                                                                                                                                                                      +128
                                                                                                                                                                                                                      +129
                                                                                                                                                                                                                      +130
                                                                                                                                                                                                                      +131
                                                                                                                                                                                                                      +132
                                                                                                                                                                                                                      +133
                                                                                                                                                                                                                      +134
                                                                                                                                                                                                                      +135
                                                                                                                                                                                                                      +136
                                                                                                                                                                                                                      +137
                                                                                                                                                                                                                      +138
                                                                                                                                                                                                                      +139
                                                                                                                                                                                                                      +140
                                                                                                                                                                                                                      +141
                                                                                                                                                                                                                      +142
                                                                                                                                                                                                                      +143
                                                                                                                                                                                                                      +144
                                                                                                                                                                                                                      +145
                                                                                                                                                                                                                      +146
                                                                                                                                                                                                                      +147
                                                                                                                                                                                                                      +148
                                                                                                                                                                                                                      +149
                                                                                                                                                                                                                      +150
                                                                                                                                                                                                                      +151
                                                                                                                                                                                                                      +152
                                                                                                                                                                                                                      +153
                                                                                                                                                                                                                      +154
                                                                                                                                                                                                                      +155
                                                                                                                                                                                                                      +156
                                                                                                                                                                                                                      +157
                                                                                                                                                                                                                      +158
                                                                                                                                                                                                                      +159
                                                                                                                                                                                                                      +160
                                                                                                                                                                                                                      +161
                                                                                                                                                                                                                      +162
                                                                                                                                                                                                                      +163
                                                                                                                                                                                                                      +164
                                                                                                                                                                                                                      +165
                                                                                                                                                                                                                      +166
                                                                                                                                                                                                                      +167
                                                                                                                                                                                                                      +168
                                                                                                                                                                                                                      +169
                                                                                                                                                                                                                      +170
                                                                                                                                                                                                                      +171
                                                                                                                                                                                                                      +172
                                                                                                                                                                                                                      +173
                                                                                                                                                                                                                      +174
                                                                                                                                                                                                                      +175
                                                                                                                                                                                                                      +176
                                                                                                                                                                                                                      +177
                                                                                                                                                                                                                      +178
                                                                                                                                                                                                                      +179
                                                                                                                                                                                                                      +180
                                                                                                                                                                                                                      +181
                                                                                                                                                                                                                      +182
                                                                                                                                                                                                                      +183
                                                                                                                                                                                                                      +184
                                                                                                                                                                                                                      +185
                                                                                                                                                                                                                      +186
                                                                                                                                                                                                                      +187
                                                                                                                                                                                                                      +188
                                                                                                                                                                                                                      +189
                                                                                                                                                                                                                      +190
                                                                                                                                                                                                                      +191
                                                                                                                                                                                                                      +192
                                                                                                                                                                                                                      +193
                                                                                                                                                                                                                      +194
                                                                                                                                                                                                                      +195
                                                                                                                                                                                                                      +196
                                                                                                                                                                                                                      +197
                                                                                                                                                                                                                      +198
                                                                                                                                                                                                                      +199
                                                                                                                                                                                                                      +200
                                                                                                                                                                                                                      +201
                                                                                                                                                                                                                      +202
                                                                                                                                                                                                                      +203
                                                                                                                                                                                                                      +204
                                                                                                                                                                                                                      +205
                                                                                                                                                                                                                      +206
                                                                                                                                                                                                                      +207
                                                                                                                                                                                                                      +208
                                                                                                                                                                                                                      +209
                                                                                                                                                                                                                      +210
                                                                                                                                                                                                                      +211
                                                                                                                                                                                                                      +212
                                                                                                                                                                                                                      +213
                                                                                                                                                                                                                      +214
                                                                                                                                                                                                                      +215
                                                                                                                                                                                                                      +216
                                                                                                                                                                                                                      +217
                                                                                                                                                                                                                      +218
                                                                                                                                                                                                                      +219
                                                                                                                                                                                                                      +220
                                                                                                                                                                                                                      +221
                                                                                                                                                                                                                      +222
                                                                                                                                                                                                                      +223
                                                                                                                                                                                                                      +224
                                                                                                                                                                                                                      +225
                                                                                                                                                                                                                      +226
                                                                                                                                                                                                                      +227
                                                                                                                                                                                                                      +228
                                                                                                                                                                                                                      +229
                                                                                                                                                                                                                      +230
                                                                                                                                                                                                                      +231
                                                                                                                                                                                                                      +232
                                                                                                                                                                                                                      +233
                                                                                                                                                                                                                      +234
                                                                                                                                                                                                                      +235
                                                                                                                                                                                                                      +236
                                                                                                                                                                                                                      +237
                                                                                                                                                                                                                      +238
                                                                                                                                                                                                                      +239
                                                                                                                                                                                                                      +240
                                                                                                                                                                                                                      +241
                                                                                                                                                                                                                      +242
                                                                                                                                                                                                                      +243
                                                                                                                                                                                                                      +244
                                                                                                                                                                                                                      +245
                                                                                                                                                                                                                      +246
                                                                                                                                                                                                                      +247
                                                                                                                                                                                                                      +248
                                                                                                                                                                                                                      +249
                                                                                                                                                                                                                      +250
                                                                                                                                                                                                                      +251
                                                                                                                                                                                                                      +252
                                                                                                                                                                                                                      +253
                                                                                                                                                                                                                      +254
                                                                                                                                                                                                                      +255
                                                                                                                                                                                                                      +256
                                                                                                                                                                                                                      +257
                                                                                                                                                                                                                      +258
                                                                                                                                                                                                                      +259
                                                                                                                                                                                                                      +260
                                                                                                                                                                                                                      +261
                                                                                                                                                                                                                      +262
                                                                                                                                                                                                                      +263
                                                                                                                                                                                                                      +264
                                                                                                                                                                                                                      +265
                                                                                                                                                                                                                      +266
                                                                                                                                                                                                                      +267
                                                                                                                                                                                                                      +268
                                                                                                                                                                                                                      +269
                                                                                                                                                                                                                      +270
                                                                                                                                                                                                                      +271
                                                                                                                                                                                                                      +272
                                                                                                                                                                                                                      +273
                                                                                                                                                                                                                      # Demo for Maker Pi RP2040 board using Ping sensor
                                                                                                                                                                                                                      +from machine import Pin, PWM, Timer
                                                                                                                                                                                                                      +import utime
                                                                                                                                                                                                                      +import urandom
                                                                                                                                                                                                                      +from neopixel import Neopixel
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# Adjust these parameters to tune the collision avoidance behavior
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +POWER_LEVEL = 35000
                                                                                                                                                                                                                      +TURN_DISTANCE = 20 # distance we decide to turn - try 20
                                                                                                                                                                                                                      +REVERSE_TIME = .4 # how long we backup
                                                                                                                                                                                                                      +TURN_TIME = .4 # how long we turn
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# startup mode is 0 - motors off and LEDs flashing
                                                                                                                                                                                                                      +# mode 1 is slow
                                                                                                                                                                                                                      +# mode 2 is medium
                                                                                                                                                                                                                      +# mode 3 is fast
                                                                                                                                                                                                                      +mode = 0
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# Use the Grove 4 Connector and put trigger on white and echo on yellow
                                                                                                                                                                                                                      +TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner
                                                                                                                                                                                                                      +ECHO_PIN = 17 # One up from bottom left corner
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# Init HC-SR04P pins
                                                                                                                                                                                                                      +trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
                                                                                                                                                                                                                      +echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                      +slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                                      +def button_pressed_handler(pin):
                                                                                                                                                                                                                      +    global mode, last_time
                                                                                                                                                                                                                      +    new_time = utime.ticks_ms()
                                                                                                                                                                                                                      +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                      +    if (new_time - last_time) > 200:
                                                                                                                                                                                                                      +        # this should be pin.id but it does not work
                                                                                                                                                                                                                      +        if '20' in str(pin):
                                                                                                                                                                                                                      +            mode +=1
                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                      +            mode -=1
                                                                                                                                                                                                                      +        # deal with ends
                                                                                                                                                                                                                      +        if mode > 4: mode = 2
                                                                                                                                                                                                                      +        if mode < 0: mode = 0
                                                                                                                                                                                                                      +        last_time = new_time
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# now we register the handler function when the button is pressed
                                                                                                                                                                                                                      +faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                      +slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# Piezo Buzzer is on GP22
                                                                                                                                                                                                                      +buzzer=PWM(Pin(22))
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +MAX_POWER_LEVEL = 65025
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +MAX_DISTANCE = 100 # ignore anything above this
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# Motor Pins are A: 8,9 and B: 10,11
                                                                                                                                                                                                                      +RIGHT_FORWARD_PIN = 11
                                                                                                                                                                                                                      +RIGHT_REVERSE_PIN = 10
                                                                                                                                                                                                                      +LEFT_FORWARD_PIN = 9
                                                                                                                                                                                                                      +LEFT_REVERSE_PIN = 8
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# our PWM objects
                                                                                                                                                                                                                      +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                      +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                      +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                      +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# returns distance in cm
                                                                                                                                                                                                                      +def ping():
                                                                                                                                                                                                                      +    print('in ping')
                                                                                                                                                                                                                      +    trigger.low()
                                                                                                                                                                                                                      +    utime.sleep_us(2) # Wait 2 microseconds low
                                                                                                                                                                                                                      +    trigger.high()
                                                                                                                                                                                                                      +    utime.sleep_us(5) # Stay high for 5 miroseconds
                                                                                                                                                                                                                      +    trigger.low()
                                                                                                                                                                                                                      +    while echo.value() == 0:
                                                                                                                                                                                                                      +        signaloff = utime.ticks_us()
                                                                                                                                                                                                                      +    print('echo is 1')
                                                                                                                                                                                                                      +    while echo.value() == 1:
                                                                                                                                                                                                                      +        signalon = utime.ticks_us()
                                                                                                                                                                                                                      +    timepassed = signalon - signaloff
                                                                                                                                                                                                                      +    distance = (timepassed * 0.0343) / 2
                                                                                                                                                                                                                      +    print(distance)
                                                                                                                                                                                                                      +    return int(distance)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def turn_motor_on(pwm):
                                                                                                                                                                                                                      +   pwm.duty_u16(65025)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def turn_motor_off(pwm):
                                                                                                                                                                                                                      +   pwm.duty_u16(0)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def forward():
                                                                                                                                                                                                                      +    turn_motor_on(right_forward)
                                                                                                                                                                                                                      +    turn_motor_on(left_forward)
                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def reverse():
                                                                                                                                                                                                                      +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                      +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def turn_right():
                                                                                                                                                                                                                      +    turn_motor_on(right_forward)
                                                                                                                                                                                                                      +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def turn_left():
                                                                                                                                                                                                                      +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                      +    turn_motor_on(left_forward)
                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def stop():
                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs
                                                                                                                                                                                                                      +# remove 16 and 17 since the are used for the ping sensor
                                                                                                                                                                                                                      +blue_led_pins = [0, 1, 2, 3,  4,  5,  6,  7, 26, 27, 28]
                                                                                                                                                                                                                      +# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]
                                                                                                                                                                                                                      +dist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +NUMBER_PIXELS = 2
                                                                                                                                                                                                                      +STATE_MACHINE = 0
                                                                                                                                                                                                                      +NEOPIXEL_PIN = 18
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                      +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB")
                                                                                                                                                                                                                      +strip.brightness(100)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                      +led_ports = []
                                                                                                                                                                                                                      +red = (255, 0, 0)
                                                                                                                                                                                                                      +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                                      +yellow = (255, 150, 0)
                                                                                                                                                                                                                      +green = (0, 255, 0)
                                                                                                                                                                                                                      +blue = (0, 0, 255)
                                                                                                                                                                                                                      +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                                      +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                                      +cyan = (0, 255, 255)
                                                                                                                                                                                                                      +lightgreen = (100, 255, 100)
                                                                                                                                                                                                                      +white = (128, 128, 128) # not too bright
                                                                                                                                                                                                                      +pink = (255, 128, 128)
                                                                                                                                                                                                                      +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')
                                                                                                                                                                                                                      +num_colors = len(color_names)
                                                                                                                                                                                                                      +colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# create a list of the ports
                                                                                                                                                                                                                      +for i in range(number_leds):
                                                                                                                                                                                                                      +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +LED_DELAY = .08
                                                                                                                                                                                                                      +def run_lights():
                                                                                                                                                                                                                      +    for i in range(0, number_leds):
                                                                                                                                                                                                                      +        led_ports[i].high()
                                                                                                                                                                                                                      +        strip.set_pixel(0, colors[i])
                                                                                                                                                                                                                      +        strip.set_pixel(1, colors[i])
                                                                                                                                                                                                                      +        strip.show()
                                                                                                                                                                                                                      +        utime.sleep(LED_DELAY)
                                                                                                                                                                                                                      +        led_ports[i].low()
                                                                                                                                                                                                                      +    # blue down
                                                                                                                                                                                                                      +    for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                                      +        led_ports[i].high()
                                                                                                                                                                                                                      +        strip.set_pixel(0, colors[i])
                                                                                                                                                                                                                      +        strip.set_pixel(1, colors[i])
                                                                                                                                                                                                                      +        strip.show()
                                                                                                                                                                                                                      +        utime.sleep(LED_DELAY)
                                                                                                                                                                                                                      +        led_ports[i].low()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def led_show_dist(in_distance):
                                                                                                                                                                                                                      +    global number_leds
                                                                                                                                                                                                                      +    for led_index in range(0, number_leds):
                                                                                                                                                                                                                      +        if in_distance > dist_scale[led_index]:
                                                                                                                                                                                                                      +            led_ports[led_index].high()
                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                      +            led_ports[led_index].low()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def play_no_signal():
                                                                                                                                                                                                                      +    playnote(100, 0.1)
                                                                                                                                                                                                                      +    sound_off()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def play_turn():
                                                                                                                                                                                                                      +    playnote(500, .1)
                                                                                                                                                                                                                      +    sound_off()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def setfreq(frequency):
                                                                                                                                                                                                                      +    buzzer.freq(frequency)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def playnote(frequency, time):
                                                                                                                                                                                                                      +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                      +    setfreq(frequency)
                                                                                                                                                                                                                      +    utime.sleep(time)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def sound_off():
                                                                                                                                                                                                                      +    buzzer.duty_u16(0)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def rest(time):
                                                                                                                                                                                                                      +    buzzer.duty_u16(0)
                                                                                                                                                                                                                      +    utime.sleep(time)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +def play_startup():
                                                                                                                                                                                                                      +    playnote(600, .2)
                                                                                                                                                                                                                      +    rest(.05)
                                                                                                                                                                                                                      +    playnote(600, .2)
                                                                                                                                                                                                                      +    rest(.05)
                                                                                                                                                                                                                      +    playnote(600, .2)
                                                                                                                                                                                                                      +    rest(.1)
                                                                                                                                                                                                                      +    playnote(800, .4)
                                                                                                                                                                                                                      +    sound_off()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +valid_distance = 1
                                                                                                                                                                                                                      +# loop forever
                                                                                                                                                                                                                      +def main():
                                                                                                                                                                                                                      +    global valid_distance
                                                                                                                                                                                                                      +    print("running main()")
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +    play_startup()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +    while True:
                                                                                                                                                                                                                      +        if mode == 0:
                                                                                                                                                                                                                      +            stop()
                                                                                                                                                                                                                      +            run_lights()
                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                      +            distance = ping()
                                                                                                                                                                                                                      +            print('Distance:', distance)
                                                                                                                                                                                                                      +            if distance > MAX_DISTANCE:
                                                                                                                                                                                                                      +                # only print if we used to have a valid distance
                                                                                                                                                                                                                      +                if valid_distance == 1:
                                                                                                                                                                                                                      +                    print('no signal')      
                                                                                                                                                                                                                      +                valid_distance = 0
                                                                                                                                                                                                                      +            else:
                                                                                                                                                                                                                      +                print(distance)
                                                                                                                                                                                                                      +                if distance < TURN_DISTANCE:
                                                                                                                                                                                                                      +                    play_turn()
                                                                                                                                                                                                                      +                    # back up for a bit
                                                                                                                                                                                                                      +                    reverse()
                                                                                                                                                                                                                      +                    utime.sleep(REVERSE_TIME)
                                                                                                                                                                                                                      +                    # half right and half left turns
                                                                                                                                                                                                                      +                    if urandom.random() < .5:
                                                                                                                                                                                                                      +                        turn_right()
                                                                                                                                                                                                                      +                    else:
                                                                                                                                                                                                                      +                        turn_left()
                                                                                                                                                                                                                      +                    utime.sleep(TURN_TIME)
                                                                                                                                                                                                                      +                    forward()
                                                                                                                                                                                                                      +                else:
                                                                                                                                                                                                                      +                    print('forward')
                                                                                                                                                                                                                      +                    forward()
                                                                                                                                                                                                                      +                valid_distance = 1
                                                                                                                                                                                                                      +                led_show_dist(distance)
                                                                                                                                                                                                                      +            utime.sleep(0.05)
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# clean up
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt
                                                                                                                                                                                                                      +try:
                                                                                                                                                                                                                      +    main()
                                                                                                                                                                                                                      +except KeyboardInterrupt:
                                                                                                                                                                                                                      +    print('Got ctrl-c')
                                                                                                                                                                                                                      +finally:
                                                                                                                                                                                                                      +    # Optional cleanup code
                                                                                                                                                                                                                      +    print('turning off sound')
                                                                                                                                                                                                                      +    buzzer.duty_u16(0)
                                                                                                                                                                                                                      +    print('shutting motors down')
                                                                                                                                                                                                                      +    stop()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +

                                                                                                                                                                                                                      Experiments

                                                                                                                                                                                                                      +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                      1. Adjust the power level and the distance before turning. See how these change the performance of the robot.
                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                      3. Adjust the angle of the ping sensor by gently heating the plexiglass holder. How does this change the robot behavior?
                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                      5. Add additional modes that change the power and the turn distance. You can have one mode for slow, one for medium and one for fast.
                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                      7. Change the Neopixel colors to indicate the distance to an object.
                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                      9. Change the pattern of the blue LEDs to indicate the distance to the object.
                                                                                                                                                                                                                      10. +
                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                      + Collision Avoidance Time-of-Flight +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                      + Ping Servo Meter +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/22-display-spi-ssd1306.py b/kits/maker-pi-rp2040-robot/22-display-spi-ssd1306.py similarity index 100% rename from docs/kits/maker-pi-rp2040-robot/22-display-spi-ssd1306.py rename to kits/maker-pi-rp2040-robot/22-display-spi-ssd1306.py diff --git a/kits/maker-pi-rp2040-robot/23-microswitch-bot/index.html b/kits/maker-pi-rp2040-robot/23-microswitch-bot/index.html new file mode 100644 index 000000000..8f07d11e7 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/23-microswitch-bot/index.html @@ -0,0 +1,2410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroSwitch Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + MicroSwitch Bot + + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                          + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                            + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Assembly + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + MicroSwitch Bot + + + + + + + +
                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                              • + + + Testing Switches + + + +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                              • + + + Sample Collision Avoidance Robot Code + + + +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                          • + + + + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                        • + + + Testing Switches + + + +
                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                        • + + + Sample Collision Avoidance Robot Code + + + +
                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                        MicroSwitch Robot using the Cytron Maker Pi RP2040

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        This robot was inspired by my friend, Michael York.

                                                                                                                                                                                                                        + + +

                                                                                                                                                                                                                        Microswitches can be purchased for under $1. They can be mounted on the front of our robot. When the robot hits a wall in front of it the switch will open (or close) and the robot controller can make the robot go in reverse or turn.

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        In the example below, we attached a stiff wire to the lever of the microswitch.

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        In the example below, we connected three microswitches to the front of our robot.

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        If the left switch is activated, the robot should turn to the right. If the right switch is activated, the robot should go to the left.

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        This image shows how we used two of the Grove connectors to read in the values of the switches.

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        Testing Switches

                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        The following code can be used to test your switches. A line on the console prints out which of the three switches are activated using the pin value() function.

                                                                                                                                                                                                                        +
                                                                                                                                                                                                                         1
                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                        +20
                                                                                                                                                                                                                        +21
                                                                                                                                                                                                                        +22
                                                                                                                                                                                                                        +23
                                                                                                                                                                                                                        +24
                                                                                                                                                                                                                        +25
                                                                                                                                                                                                                        +26
                                                                                                                                                                                                                        +27
                                                                                                                                                                                                                        +28
                                                                                                                                                                                                                        +29
                                                                                                                                                                                                                        from machine import Pin
                                                                                                                                                                                                                        +from time import sleep
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# GPIO is the internal built-in LED
                                                                                                                                                                                                                        +led0 = Pin(0, Pin.OUT)
                                                                                                                                                                                                                        +led1 = Pin(1, Pin.OUT)
                                                                                                                                                                                                                        +led2 = Pin(2, Pin.OUT)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating
                                                                                                                                                                                                                        +middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) 
                                                                                                                                                                                                                        +right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                        +left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                        +    if middle_switch.value(): # if the value changes
                                                                                                                                                                                                                        +        led0.on()
                                                                                                                                                                                                                        +        print('middle')
                                                                                                                                                                                                                        +    else: led0.off()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +    if right_switch.value(): # if the value changes
                                                                                                                                                                                                                        +        led1.on()
                                                                                                                                                                                                                        +        print('right')
                                                                                                                                                                                                                        +    else: led1.off()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +    if left_switch.value(): # if the value changes
                                                                                                                                                                                                                        +        led2.on()
                                                                                                                                                                                                                        +        print('left')
                                                                                                                                                                                                                        +    else: led2.off()
                                                                                                                                                                                                                        +    sleep(.1)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +

                                                                                                                                                                                                                        Sample Collision Avoidance Robot Code

                                                                                                                                                                                                                        +
                                                                                                                                                                                                                          1
                                                                                                                                                                                                                        +  2
                                                                                                                                                                                                                        +  3
                                                                                                                                                                                                                        +  4
                                                                                                                                                                                                                        +  5
                                                                                                                                                                                                                        +  6
                                                                                                                                                                                                                        +  7
                                                                                                                                                                                                                        +  8
                                                                                                                                                                                                                        +  9
                                                                                                                                                                                                                        + 10
                                                                                                                                                                                                                        + 11
                                                                                                                                                                                                                        + 12
                                                                                                                                                                                                                        + 13
                                                                                                                                                                                                                        + 14
                                                                                                                                                                                                                        + 15
                                                                                                                                                                                                                        + 16
                                                                                                                                                                                                                        + 17
                                                                                                                                                                                                                        + 18
                                                                                                                                                                                                                        + 19
                                                                                                                                                                                                                        + 20
                                                                                                                                                                                                                        + 21
                                                                                                                                                                                                                        + 22
                                                                                                                                                                                                                        + 23
                                                                                                                                                                                                                        + 24
                                                                                                                                                                                                                        + 25
                                                                                                                                                                                                                        + 26
                                                                                                                                                                                                                        + 27
                                                                                                                                                                                                                        + 28
                                                                                                                                                                                                                        + 29
                                                                                                                                                                                                                        + 30
                                                                                                                                                                                                                        + 31
                                                                                                                                                                                                                        + 32
                                                                                                                                                                                                                        + 33
                                                                                                                                                                                                                        + 34
                                                                                                                                                                                                                        + 35
                                                                                                                                                                                                                        + 36
                                                                                                                                                                                                                        + 37
                                                                                                                                                                                                                        + 38
                                                                                                                                                                                                                        + 39
                                                                                                                                                                                                                        + 40
                                                                                                                                                                                                                        + 41
                                                                                                                                                                                                                        + 42
                                                                                                                                                                                                                        + 43
                                                                                                                                                                                                                        + 44
                                                                                                                                                                                                                        + 45
                                                                                                                                                                                                                        + 46
                                                                                                                                                                                                                        + 47
                                                                                                                                                                                                                        + 48
                                                                                                                                                                                                                        + 49
                                                                                                                                                                                                                        + 50
                                                                                                                                                                                                                        + 51
                                                                                                                                                                                                                        + 52
                                                                                                                                                                                                                        + 53
                                                                                                                                                                                                                        + 54
                                                                                                                                                                                                                        + 55
                                                                                                                                                                                                                        + 56
                                                                                                                                                                                                                        + 57
                                                                                                                                                                                                                        + 58
                                                                                                                                                                                                                        + 59
                                                                                                                                                                                                                        + 60
                                                                                                                                                                                                                        + 61
                                                                                                                                                                                                                        + 62
                                                                                                                                                                                                                        + 63
                                                                                                                                                                                                                        + 64
                                                                                                                                                                                                                        + 65
                                                                                                                                                                                                                        + 66
                                                                                                                                                                                                                        + 67
                                                                                                                                                                                                                        + 68
                                                                                                                                                                                                                        + 69
                                                                                                                                                                                                                        + 70
                                                                                                                                                                                                                        + 71
                                                                                                                                                                                                                        + 72
                                                                                                                                                                                                                        + 73
                                                                                                                                                                                                                        + 74
                                                                                                                                                                                                                        + 75
                                                                                                                                                                                                                        + 76
                                                                                                                                                                                                                        + 77
                                                                                                                                                                                                                        + 78
                                                                                                                                                                                                                        + 79
                                                                                                                                                                                                                        + 80
                                                                                                                                                                                                                        + 81
                                                                                                                                                                                                                        + 82
                                                                                                                                                                                                                        + 83
                                                                                                                                                                                                                        + 84
                                                                                                                                                                                                                        + 85
                                                                                                                                                                                                                        + 86
                                                                                                                                                                                                                        + 87
                                                                                                                                                                                                                        + 88
                                                                                                                                                                                                                        + 89
                                                                                                                                                                                                                        + 90
                                                                                                                                                                                                                        + 91
                                                                                                                                                                                                                        + 92
                                                                                                                                                                                                                        + 93
                                                                                                                                                                                                                        + 94
                                                                                                                                                                                                                        + 95
                                                                                                                                                                                                                        + 96
                                                                                                                                                                                                                        + 97
                                                                                                                                                                                                                        + 98
                                                                                                                                                                                                                        + 99
                                                                                                                                                                                                                        +100
                                                                                                                                                                                                                        +101
                                                                                                                                                                                                                        +102
                                                                                                                                                                                                                        +103
                                                                                                                                                                                                                        +104
                                                                                                                                                                                                                        +105
                                                                                                                                                                                                                        +106
                                                                                                                                                                                                                        +107
                                                                                                                                                                                                                        +108
                                                                                                                                                                                                                        +109
                                                                                                                                                                                                                        +110
                                                                                                                                                                                                                        +111
                                                                                                                                                                                                                        +112
                                                                                                                                                                                                                        +113
                                                                                                                                                                                                                        +114
                                                                                                                                                                                                                        +115
                                                                                                                                                                                                                        from machine import Pin, PWM
                                                                                                                                                                                                                        +from time import sleep
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# GPIO is the internal built-in LED
                                                                                                                                                                                                                        +led0 = Pin(0, Pin.OUT)
                                                                                                                                                                                                                        +led1 = Pin(1, Pin.OUT)
                                                                                                                                                                                                                        +led2 = Pin(2, Pin.OUT)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating
                                                                                                                                                                                                                        +middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) 
                                                                                                                                                                                                                        +right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                        +left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# Go slow to avoid bending wires
                                                                                                                                                                                                                        +POWER_LEVEL = 25000 # max is 65000
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +# These values depend on motor wiring
                                                                                                                                                                                                                        +RIGHT_FORWARD_PIN = 10
                                                                                                                                                                                                                        +RIGHT_REVERSE_PIN = 11
                                                                                                                                                                                                                        +LEFT_FORWARD_PIN = 9
                                                                                                                                                                                                                        +LEFT_REVERSE_PIN = 8
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                        +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                        +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                        +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def turn_motor_on(pwm):
                                                                                                                                                                                                                        +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def turn_motor_off(pwm):
                                                                                                                                                                                                                        +   pwm.duty_u16(0)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def forward():
                                                                                                                                                                                                                        +    turn_motor_on(right_forward)
                                                                                                                                                                                                                        +    turn_motor_on(left_forward)
                                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def reverse():
                                                                                                                                                                                                                        +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                        +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def turn_right():
                                                                                                                                                                                                                        +    turn_motor_on(right_forward)
                                                                                                                                                                                                                        +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def turn_left():
                                                                                                                                                                                                                        +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                        +    turn_motor_on(left_forward)
                                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def stop():
                                                                                                                                                                                                                        +    turn_motor_off(right_forward)
                                                                                                                                                                                                                        +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                        +    turn_motor_off(left_forward)
                                                                                                                                                                                                                        +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +def main():
                                                                                                                                                                                                                        +    while True:
                                                                                                                                                                                                                        +        if middle_switch.value(): # if the value changes
                                                                                                                                                                                                                        +            print('middle')
                                                                                                                                                                                                                        +            led0.on()
                                                                                                                                                                                                                        +            reverse()
                                                                                                                                                                                                                        +            sleep(1)
                                                                                                                                                                                                                        +            turn_right()
                                                                                                                                                                                                                        +            sleep(.75)
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +        else:
                                                                                                                                                                                                                        +            led0.off()
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +        if right_switch.value(): # if the value changes
                                                                                                                                                                                                                        +            print('right')
                                                                                                                                                                                                                        +            led1.on()
                                                                                                                                                                                                                        +            reverse()
                                                                                                                                                                                                                        +            sleep(.75)
                                                                                                                                                                                                                        +            turn_left()
                                                                                                                                                                                                                        +            sleep(.5)
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +        else:
                                                                                                                                                                                                                        +            led1.off()
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +        if left_switch.value(): # if the value changes
                                                                                                                                                                                                                        +            led2.on()
                                                                                                                                                                                                                        +            print('left')
                                                                                                                                                                                                                        +            reverse()
                                                                                                                                                                                                                        +            sleep(.75)
                                                                                                                                                                                                                        +            turn_right()
                                                                                                                                                                                                                        +            sleep(.5)
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +        else:
                                                                                                                                                                                                                        +            led2.off()
                                                                                                                                                                                                                        +            forward()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +print('middle', middle_switch.value())
                                                                                                                                                                                                                        +print('left', left_switch.value())
                                                                                                                                                                                                                        +print('right', right_switch.value())
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +try:
                                                                                                                                                                                                                        +    main()
                                                                                                                                                                                                                        +except KeyboardInterrupt:
                                                                                                                                                                                                                        +    print('Got ctrl-c')
                                                                                                                                                                                                                        +finally:
                                                                                                                                                                                                                        +    # Optional cleanup code
                                                                                                                                                                                                                        +    print('turning off sound')
                                                                                                                                                                                                                        +    # sound_off()
                                                                                                                                                                                                                        +    print('turning off motors')
                                                                                                                                                                                                                        +    stop()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                        + Time of Flight Sound Lab +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                        + Ultrasonic Ping Lab +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/24-ping-servo-meter/index.html b/kits/maker-pi-rp2040-robot/24-ping-servo-meter/index.html new file mode 100644 index 000000000..3f25b087c --- /dev/null +++ b/kits/maker-pi-rp2040-robot/24-ping-servo-meter/index.html @@ -0,0 +1,3100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Ping Servo Meter - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + Ping Servo Meter + + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                            + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                              + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Assembly + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Ping Servo Meter + + + + + + + +
                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                • + + + Test Servo + + + +
                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                • + + + Main Python Code + + + +
                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                            • + + + + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                          • + + + Test Servo + + + +
                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                          • + + + Main Python Code + + + +
                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                          Cytron Maker Pi RP2040 Ping Servo Meter Bot

                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          This robot works very similar to our standard CoderDojo Collision Avoidance Robot. However it adds a 180 degree servo to show the distance to the object in front of it. It also uses a OLED display to present instructions and display the distance to the object.

                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          This program was contributed by Joe Glenn for the Minneapolis Bakken Museum Droid December event in December 2021.

                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          Test Servo

                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          This program tests the servo by sweeping the angle from 0 to 180 and back.

                                                                                                                                                                                                                          +
                                                                                                                                                                                                                           1
                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                          +28
                                                                                                                                                                                                                          +29
                                                                                                                                                                                                                          +30
                                                                                                                                                                                                                          +31
                                                                                                                                                                                                                          +32
                                                                                                                                                                                                                          +33
                                                                                                                                                                                                                          +34
                                                                                                                                                                                                                          +35
                                                                                                                                                                                                                          +36
                                                                                                                                                                                                                          +37
                                                                                                                                                                                                                          +38
                                                                                                                                                                                                                          +39
                                                                                                                                                                                                                          +40
                                                                                                                                                                                                                          # servo sweep test
                                                                                                                                                                                                                          +# Brown: GND
                                                                                                                                                                                                                          +# Orange/Red : VCC
                                                                                                                                                                                                                          +# Yellow: Signal
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Time for high level (Radio Shack Micro-servo @ 5V)
                                                                                                                                                                                                                          +# 0.5 ms :   0 degree
                                                                                                                                                                                                                          +# 1.0 ms :  45 degree
                                                                                                                                                                                                                          +# 1.5 ms :  90 degree
                                                                                                                                                                                                                          +# 2.0 ms : 135 degree
                                                                                                                                                                                                                          +# 2.5 ms : 180 degree
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +from machine import Pin, PWM
                                                                                                                                                                                                                          +from time import sleep
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +SERVO_PIN = 15
                                                                                                                                                                                                                          +servoPin = PWM(Pin(SERVO_PIN))
                                                                                                                                                                                                                          +servoPin.freq(50)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def servo(degrees):
                                                                                                                                                                                                                          +    if degrees > 180: degrees=180
                                                                                                                                                                                                                          +    if degrees < 0: degrees=0
                                                                                                                                                                                                                          +    maxDuty=8000 # duty*100
                                                                                                                                                                                                                          +    minDuty=2000 # duty*100
                                                                                                                                                                                                                          +    #maxDuty=2000 # test
                                                                                                                                                                                                                          +    #minDuty=8000 # test
                                                                                                                                                                                                                          +    newDuty=minDuty+(maxDuty-minDuty)*(degrees/180)
                                                                                                                                                                                                                          +    servoPin.duty_u16(int(newDuty))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +  for degree in range(0,180,1):
                                                                                                                                                                                                                          +    servo(degree)
                                                                                                                                                                                                                          +    sleep(0.01)
                                                                                                                                                                                                                          +    print("increasing -- "+str(degree))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +  for degree in range(180, 0, -1):
                                                                                                                                                                                                                          +    servo(degree)
                                                                                                                                                                                                                          +    sleep(0.01)
                                                                                                                                                                                                                          +    print("decreasing -- "+str(degree))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +

                                                                                                                                                                                                                          Main Python Code

                                                                                                                                                                                                                          +
                                                                                                                                                                                                                            1
                                                                                                                                                                                                                          +  2
                                                                                                                                                                                                                          +  3
                                                                                                                                                                                                                          +  4
                                                                                                                                                                                                                          +  5
                                                                                                                                                                                                                          +  6
                                                                                                                                                                                                                          +  7
                                                                                                                                                                                                                          +  8
                                                                                                                                                                                                                          +  9
                                                                                                                                                                                                                          + 10
                                                                                                                                                                                                                          + 11
                                                                                                                                                                                                                          + 12
                                                                                                                                                                                                                          + 13
                                                                                                                                                                                                                          + 14
                                                                                                                                                                                                                          + 15
                                                                                                                                                                                                                          + 16
                                                                                                                                                                                                                          + 17
                                                                                                                                                                                                                          + 18
                                                                                                                                                                                                                          + 19
                                                                                                                                                                                                                          + 20
                                                                                                                                                                                                                          + 21
                                                                                                                                                                                                                          + 22
                                                                                                                                                                                                                          + 23
                                                                                                                                                                                                                          + 24
                                                                                                                                                                                                                          + 25
                                                                                                                                                                                                                          + 26
                                                                                                                                                                                                                          + 27
                                                                                                                                                                                                                          + 28
                                                                                                                                                                                                                          + 29
                                                                                                                                                                                                                          + 30
                                                                                                                                                                                                                          + 31
                                                                                                                                                                                                                          + 32
                                                                                                                                                                                                                          + 33
                                                                                                                                                                                                                          + 34
                                                                                                                                                                                                                          + 35
                                                                                                                                                                                                                          + 36
                                                                                                                                                                                                                          + 37
                                                                                                                                                                                                                          + 38
                                                                                                                                                                                                                          + 39
                                                                                                                                                                                                                          + 40
                                                                                                                                                                                                                          + 41
                                                                                                                                                                                                                          + 42
                                                                                                                                                                                                                          + 43
                                                                                                                                                                                                                          + 44
                                                                                                                                                                                                                          + 45
                                                                                                                                                                                                                          + 46
                                                                                                                                                                                                                          + 47
                                                                                                                                                                                                                          + 48
                                                                                                                                                                                                                          + 49
                                                                                                                                                                                                                          + 50
                                                                                                                                                                                                                          + 51
                                                                                                                                                                                                                          + 52
                                                                                                                                                                                                                          + 53
                                                                                                                                                                                                                          + 54
                                                                                                                                                                                                                          + 55
                                                                                                                                                                                                                          + 56
                                                                                                                                                                                                                          + 57
                                                                                                                                                                                                                          + 58
                                                                                                                                                                                                                          + 59
                                                                                                                                                                                                                          + 60
                                                                                                                                                                                                                          + 61
                                                                                                                                                                                                                          + 62
                                                                                                                                                                                                                          + 63
                                                                                                                                                                                                                          + 64
                                                                                                                                                                                                                          + 65
                                                                                                                                                                                                                          + 66
                                                                                                                                                                                                                          + 67
                                                                                                                                                                                                                          + 68
                                                                                                                                                                                                                          + 69
                                                                                                                                                                                                                          + 70
                                                                                                                                                                                                                          + 71
                                                                                                                                                                                                                          + 72
                                                                                                                                                                                                                          + 73
                                                                                                                                                                                                                          + 74
                                                                                                                                                                                                                          + 75
                                                                                                                                                                                                                          + 76
                                                                                                                                                                                                                          + 77
                                                                                                                                                                                                                          + 78
                                                                                                                                                                                                                          + 79
                                                                                                                                                                                                                          + 80
                                                                                                                                                                                                                          + 81
                                                                                                                                                                                                                          + 82
                                                                                                                                                                                                                          + 83
                                                                                                                                                                                                                          + 84
                                                                                                                                                                                                                          + 85
                                                                                                                                                                                                                          + 86
                                                                                                                                                                                                                          + 87
                                                                                                                                                                                                                          + 88
                                                                                                                                                                                                                          + 89
                                                                                                                                                                                                                          + 90
                                                                                                                                                                                                                          + 91
                                                                                                                                                                                                                          + 92
                                                                                                                                                                                                                          + 93
                                                                                                                                                                                                                          + 94
                                                                                                                                                                                                                          + 95
                                                                                                                                                                                                                          + 96
                                                                                                                                                                                                                          + 97
                                                                                                                                                                                                                          + 98
                                                                                                                                                                                                                          + 99
                                                                                                                                                                                                                          +100
                                                                                                                                                                                                                          +101
                                                                                                                                                                                                                          +102
                                                                                                                                                                                                                          +103
                                                                                                                                                                                                                          +104
                                                                                                                                                                                                                          +105
                                                                                                                                                                                                                          +106
                                                                                                                                                                                                                          +107
                                                                                                                                                                                                                          +108
                                                                                                                                                                                                                          +109
                                                                                                                                                                                                                          +110
                                                                                                                                                                                                                          +111
                                                                                                                                                                                                                          +112
                                                                                                                                                                                                                          +113
                                                                                                                                                                                                                          +114
                                                                                                                                                                                                                          +115
                                                                                                                                                                                                                          +116
                                                                                                                                                                                                                          +117
                                                                                                                                                                                                                          +118
                                                                                                                                                                                                                          +119
                                                                                                                                                                                                                          +120
                                                                                                                                                                                                                          +121
                                                                                                                                                                                                                          +122
                                                                                                                                                                                                                          +123
                                                                                                                                                                                                                          +124
                                                                                                                                                                                                                          +125
                                                                                                                                                                                                                          +126
                                                                                                                                                                                                                          +127
                                                                                                                                                                                                                          +128
                                                                                                                                                                                                                          +129
                                                                                                                                                                                                                          +130
                                                                                                                                                                                                                          +131
                                                                                                                                                                                                                          +132
                                                                                                                                                                                                                          +133
                                                                                                                                                                                                                          +134
                                                                                                                                                                                                                          +135
                                                                                                                                                                                                                          +136
                                                                                                                                                                                                                          +137
                                                                                                                                                                                                                          +138
                                                                                                                                                                                                                          +139
                                                                                                                                                                                                                          +140
                                                                                                                                                                                                                          +141
                                                                                                                                                                                                                          +142
                                                                                                                                                                                                                          +143
                                                                                                                                                                                                                          +144
                                                                                                                                                                                                                          +145
                                                                                                                                                                                                                          +146
                                                                                                                                                                                                                          +147
                                                                                                                                                                                                                          +148
                                                                                                                                                                                                                          +149
                                                                                                                                                                                                                          +150
                                                                                                                                                                                                                          +151
                                                                                                                                                                                                                          +152
                                                                                                                                                                                                                          +153
                                                                                                                                                                                                                          +154
                                                                                                                                                                                                                          +155
                                                                                                                                                                                                                          +156
                                                                                                                                                                                                                          +157
                                                                                                                                                                                                                          +158
                                                                                                                                                                                                                          +159
                                                                                                                                                                                                                          +160
                                                                                                                                                                                                                          +161
                                                                                                                                                                                                                          +162
                                                                                                                                                                                                                          +163
                                                                                                                                                                                                                          +164
                                                                                                                                                                                                                          +165
                                                                                                                                                                                                                          +166
                                                                                                                                                                                                                          +167
                                                                                                                                                                                                                          +168
                                                                                                                                                                                                                          +169
                                                                                                                                                                                                                          +170
                                                                                                                                                                                                                          +171
                                                                                                                                                                                                                          +172
                                                                                                                                                                                                                          +173
                                                                                                                                                                                                                          +174
                                                                                                                                                                                                                          +175
                                                                                                                                                                                                                          +176
                                                                                                                                                                                                                          +177
                                                                                                                                                                                                                          +178
                                                                                                                                                                                                                          +179
                                                                                                                                                                                                                          +180
                                                                                                                                                                                                                          +181
                                                                                                                                                                                                                          +182
                                                                                                                                                                                                                          +183
                                                                                                                                                                                                                          +184
                                                                                                                                                                                                                          +185
                                                                                                                                                                                                                          +186
                                                                                                                                                                                                                          +187
                                                                                                                                                                                                                          +188
                                                                                                                                                                                                                          +189
                                                                                                                                                                                                                          +190
                                                                                                                                                                                                                          +191
                                                                                                                                                                                                                          +192
                                                                                                                                                                                                                          +193
                                                                                                                                                                                                                          +194
                                                                                                                                                                                                                          +195
                                                                                                                                                                                                                          +196
                                                                                                                                                                                                                          +197
                                                                                                                                                                                                                          +198
                                                                                                                                                                                                                          +199
                                                                                                                                                                                                                          +200
                                                                                                                                                                                                                          +201
                                                                                                                                                                                                                          +202
                                                                                                                                                                                                                          +203
                                                                                                                                                                                                                          +204
                                                                                                                                                                                                                          +205
                                                                                                                                                                                                                          +206
                                                                                                                                                                                                                          +207
                                                                                                                                                                                                                          +208
                                                                                                                                                                                                                          +209
                                                                                                                                                                                                                          +210
                                                                                                                                                                                                                          +211
                                                                                                                                                                                                                          +212
                                                                                                                                                                                                                          +213
                                                                                                                                                                                                                          +214
                                                                                                                                                                                                                          +215
                                                                                                                                                                                                                          +216
                                                                                                                                                                                                                          +217
                                                                                                                                                                                                                          +218
                                                                                                                                                                                                                          +219
                                                                                                                                                                                                                          +220
                                                                                                                                                                                                                          +221
                                                                                                                                                                                                                          +222
                                                                                                                                                                                                                          +223
                                                                                                                                                                                                                          +224
                                                                                                                                                                                                                          +225
                                                                                                                                                                                                                          +226
                                                                                                                                                                                                                          +227
                                                                                                                                                                                                                          +228
                                                                                                                                                                                                                          +229
                                                                                                                                                                                                                          +230
                                                                                                                                                                                                                          +231
                                                                                                                                                                                                                          +232
                                                                                                                                                                                                                          +233
                                                                                                                                                                                                                          +234
                                                                                                                                                                                                                          +235
                                                                                                                                                                                                                          +236
                                                                                                                                                                                                                          +237
                                                                                                                                                                                                                          +238
                                                                                                                                                                                                                          +239
                                                                                                                                                                                                                          +240
                                                                                                                                                                                                                          +241
                                                                                                                                                                                                                          +242
                                                                                                                                                                                                                          +243
                                                                                                                                                                                                                          +244
                                                                                                                                                                                                                          +245
                                                                                                                                                                                                                          +246
                                                                                                                                                                                                                          +247
                                                                                                                                                                                                                          +248
                                                                                                                                                                                                                          +249
                                                                                                                                                                                                                          +250
                                                                                                                                                                                                                          +251
                                                                                                                                                                                                                          +252
                                                                                                                                                                                                                          +253
                                                                                                                                                                                                                          +254
                                                                                                                                                                                                                          +255
                                                                                                                                                                                                                          +256
                                                                                                                                                                                                                          +257
                                                                                                                                                                                                                          +258
                                                                                                                                                                                                                          +259
                                                                                                                                                                                                                          +260
                                                                                                                                                                                                                          +261
                                                                                                                                                                                                                          +262
                                                                                                                                                                                                                          +263
                                                                                                                                                                                                                          +264
                                                                                                                                                                                                                          +265
                                                                                                                                                                                                                          +266
                                                                                                                                                                                                                          +267
                                                                                                                                                                                                                          +268
                                                                                                                                                                                                                          +269
                                                                                                                                                                                                                          +270
                                                                                                                                                                                                                          +271
                                                                                                                                                                                                                          +272
                                                                                                                                                                                                                          +273
                                                                                                                                                                                                                          +274
                                                                                                                                                                                                                          +275
                                                                                                                                                                                                                          +276
                                                                                                                                                                                                                          +277
                                                                                                                                                                                                                          +278
                                                                                                                                                                                                                          +279
                                                                                                                                                                                                                          +280
                                                                                                                                                                                                                          +281
                                                                                                                                                                                                                          +282
                                                                                                                                                                                                                          +283
                                                                                                                                                                                                                          +284
                                                                                                                                                                                                                          +285
                                                                                                                                                                                                                          +286
                                                                                                                                                                                                                          +287
                                                                                                                                                                                                                          +288
                                                                                                                                                                                                                          +289
                                                                                                                                                                                                                          +290
                                                                                                                                                                                                                          +291
                                                                                                                                                                                                                          +292
                                                                                                                                                                                                                          +293
                                                                                                                                                                                                                          +294
                                                                                                                                                                                                                          +295
                                                                                                                                                                                                                          +296
                                                                                                                                                                                                                          +297
                                                                                                                                                                                                                          +298
                                                                                                                                                                                                                          +299
                                                                                                                                                                                                                          +300
                                                                                                                                                                                                                          +301
                                                                                                                                                                                                                          +302
                                                                                                                                                                                                                          +303
                                                                                                                                                                                                                          +304
                                                                                                                                                                                                                          +305
                                                                                                                                                                                                                          +306
                                                                                                                                                                                                                          +307
                                                                                                                                                                                                                          +308
                                                                                                                                                                                                                          +309
                                                                                                                                                                                                                          +310
                                                                                                                                                                                                                          +311
                                                                                                                                                                                                                          +312
                                                                                                                                                                                                                          +313
                                                                                                                                                                                                                          +314
                                                                                                                                                                                                                          +315
                                                                                                                                                                                                                          +316
                                                                                                                                                                                                                          +317
                                                                                                                                                                                                                          +318
                                                                                                                                                                                                                          +319
                                                                                                                                                                                                                          +320
                                                                                                                                                                                                                          +321
                                                                                                                                                                                                                          +322
                                                                                                                                                                                                                          +323
                                                                                                                                                                                                                          +324
                                                                                                                                                                                                                          +325
                                                                                                                                                                                                                          +326
                                                                                                                                                                                                                          +327
                                                                                                                                                                                                                          +328
                                                                                                                                                                                                                          +329
                                                                                                                                                                                                                          +330
                                                                                                                                                                                                                          +331
                                                                                                                                                                                                                          +332
                                                                                                                                                                                                                          +333
                                                                                                                                                                                                                          +334
                                                                                                                                                                                                                          +335
                                                                                                                                                                                                                          +336
                                                                                                                                                                                                                          +337
                                                                                                                                                                                                                          +338
                                                                                                                                                                                                                          +339
                                                                                                                                                                                                                          +340
                                                                                                                                                                                                                          +341
                                                                                                                                                                                                                          +342
                                                                                                                                                                                                                          +343
                                                                                                                                                                                                                          +344
                                                                                                                                                                                                                          +345
                                                                                                                                                                                                                          +346
                                                                                                                                                                                                                          +347
                                                                                                                                                                                                                          +348
                                                                                                                                                                                                                          +349
                                                                                                                                                                                                                          +350
                                                                                                                                                                                                                          +351
                                                                                                                                                                                                                          +352
                                                                                                                                                                                                                          +353
                                                                                                                                                                                                                          +354
                                                                                                                                                                                                                          +355
                                                                                                                                                                                                                          +356
                                                                                                                                                                                                                          +357
                                                                                                                                                                                                                          +358
                                                                                                                                                                                                                          +359
                                                                                                                                                                                                                          +360
                                                                                                                                                                                                                          +361
                                                                                                                                                                                                                          +362
                                                                                                                                                                                                                          +363
                                                                                                                                                                                                                          +364
                                                                                                                                                                                                                          +365
                                                                                                                                                                                                                          +366
                                                                                                                                                                                                                          +367
                                                                                                                                                                                                                          +368
                                                                                                                                                                                                                          +369
                                                                                                                                                                                                                          +370
                                                                                                                                                                                                                          +371
                                                                                                                                                                                                                          +372
                                                                                                                                                                                                                          +373
                                                                                                                                                                                                                          +374
                                                                                                                                                                                                                          +375
                                                                                                                                                                                                                          +376
                                                                                                                                                                                                                          +377
                                                                                                                                                                                                                          +378
                                                                                                                                                                                                                          +379
                                                                                                                                                                                                                          +380
                                                                                                                                                                                                                          +381
                                                                                                                                                                                                                          +382
                                                                                                                                                                                                                          +383
                                                                                                                                                                                                                          +384
                                                                                                                                                                                                                          +385
                                                                                                                                                                                                                          +386
                                                                                                                                                                                                                          +387
                                                                                                                                                                                                                          +388
                                                                                                                                                                                                                          +389
                                                                                                                                                                                                                          +390
                                                                                                                                                                                                                          +391
                                                                                                                                                                                                                          +392
                                                                                                                                                                                                                          +393
                                                                                                                                                                                                                          +394
                                                                                                                                                                                                                          +395
                                                                                                                                                                                                                          +396
                                                                                                                                                                                                                          +397
                                                                                                                                                                                                                          +398
                                                                                                                                                                                                                          +399
                                                                                                                                                                                                                          +400
                                                                                                                                                                                                                          +401
                                                                                                                                                                                                                          +402
                                                                                                                                                                                                                          +403
                                                                                                                                                                                                                          +404
                                                                                                                                                                                                                          +405
                                                                                                                                                                                                                          +406
                                                                                                                                                                                                                          +407
                                                                                                                                                                                                                          +408
                                                                                                                                                                                                                          +409
                                                                                                                                                                                                                          +410
                                                                                                                                                                                                                          +411
                                                                                                                                                                                                                          +412
                                                                                                                                                                                                                          +413
                                                                                                                                                                                                                          +414
                                                                                                                                                                                                                          +415
                                                                                                                                                                                                                          +416
                                                                                                                                                                                                                          +417
                                                                                                                                                                                                                          +418
                                                                                                                                                                                                                          +419
                                                                                                                                                                                                                          +420
                                                                                                                                                                                                                          +421
                                                                                                                                                                                                                          +422
                                                                                                                                                                                                                          +423
                                                                                                                                                                                                                          +424
                                                                                                                                                                                                                          +425
                                                                                                                                                                                                                          +426
                                                                                                                                                                                                                          +427
                                                                                                                                                                                                                          +428
                                                                                                                                                                                                                          +429
                                                                                                                                                                                                                          +430
                                                                                                                                                                                                                          +431
                                                                                                                                                                                                                          +432
                                                                                                                                                                                                                          +433
                                                                                                                                                                                                                          +434
                                                                                                                                                                                                                          +435
                                                                                                                                                                                                                          +436
                                                                                                                                                                                                                          +437
                                                                                                                                                                                                                          +438
                                                                                                                                                                                                                          +439
                                                                                                                                                                                                                          +440
                                                                                                                                                                                                                          +441
                                                                                                                                                                                                                          +442
                                                                                                                                                                                                                          +443
                                                                                                                                                                                                                          +444
                                                                                                                                                                                                                          +445
                                                                                                                                                                                                                          +446
                                                                                                                                                                                                                          +447
                                                                                                                                                                                                                          +448
                                                                                                                                                                                                                          +449
                                                                                                                                                                                                                          +450
                                                                                                                                                                                                                          +451
                                                                                                                                                                                                                          +452
                                                                                                                                                                                                                          +453
                                                                                                                                                                                                                          # Demo for Maker Pi RP2040 board using Ping sensor, servo and i2c display
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +from machine import Pin, PWM, Timer
                                                                                                                                                                                                                          +import utime
                                                                                                                                                                                                                          +import urandom
                                                                                                                                                                                                                          +from ssd1306 import SSD1306_I2C
                                                                                                                                                                                                                          +from neopixel import Neopixel
                                                                                                                                                                                                                          +from machine import Pin, I2C
                                                                                                                                                                                                                          +from ssd1306 import SSD1306_I2C
                                                                                                                                                                                                                          +import framebuf
                                                                                                                                                                                                                          +import math
                                                                                                                                                                                                                          +import utime
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Ping Sensor
                                                                                                                                                                                                                          +# Use the Grove 4 Connector and put trigger on white and echo on yellow
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +PING_TRIGGER_PIN = 7 # GP7
                                                                                                                                                                                                                          +PING_ECHO_PIN = 28 # GP28
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# i2c OLED 128x32
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +OLED_SDA_PIN = 26 # GP26
                                                                                                                                                                                                                          +OLED_SCL_PIN = 27 # GP27
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Servo
                                                                                                                                                                                                                          +# GND: Brown
                                                                                                                                                                                                                          +# VCC: Orange/Red
                                                                                                                                                                                                                          +# GP15 Yellow: Signal
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Time for high level (Radio Shack Micro-servo @ 5V)
                                                                                                                                                                                                                          +# 0.5 ms :   0 degree
                                                                                                                                                                                                                          +# 1.0 ms :  45 degree
                                                                                                                                                                                                                          +# 1.5 ms :  90 degree
                                                                                                                                                                                                                          +# 2.0 ms : 135 degree
                                                                                                                                                                                                                          +# 2.5 ms : 180 degree
                                                                                                                                                                                                                          +SERVO_PIN = 15
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# IQR Pins
                                                                                                                                                                                                                          +FASTER_PIN = 20
                                                                                                                                                                                                                          +SLOWER_PIN = 21
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# built-in Buzzer
                                                                                                                                                                                                                          +BUZZER_PIN = 22
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Adjust these parameters to tune the collision avoidance behavior
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +POWER_LEL = 35000
                                                                                                                                                                                                                          +TURN_DISTANCE = 20 # distance we decide to turn - try 20
                                                                                                                                                                                                                          +REVERSE_TIME = .4 # how long we backup
                                                                                                                                                                                                                          +TURN_TIME = .4 # how long we turn
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# startup mode is 0 - motors off and LEDs flashing
                                                                                                                                                                                                                          +# mode 1 is slow
                                                                                                                                                                                                                          +# mode 2 is medium
                                                                                                                                                                                                                          +# mode 3 is fast
                                                                                                                                                                                                                          +mode = 0
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Init HC-SR04P pins
                                                                                                                                                                                                                          +trigger = Pin(PING_TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
                                                                                                                                                                                                                          +echo = Pin(PING_ECHO_PIN, Pin.IN) # get the delay interval back
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +faster_pin = machine.Pin(FASTER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                          +slower_pin = machine.Pin(SLOWER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# DISPLAY STUFF
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Display Image & text on I2C driven ssd1306 OLED display 
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +WIDTH  = 128 # oled display width
                                                                                                                                                                                                                          +HEIGHT = 32  # oled display height
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Explicit Method
                                                                                                                                                                                                                          +sda=machine.Pin(OLED_SDA_PIN)
                                                                                                                                                                                                                          +scl=machine.Pin(OLED_SCL_PIN)
                                                                                                                                                                                                                          +i2c=machine.I2C(1,sda=sda, scl=scl, freq=40000) # 400k is too fast and has issues
                                                                                                                                                                                                                          +print( 'i2c={:02X}'.format( i2c.scan()[0] ) )
                                                                                                                                                                                                                          +#print(help(i2c))
                                                                                                                                                                                                                          +#print(help(i2c.init))
                                                                                                                                                                                                                          +#print(help(i2c.scan))
                                                                                                                                                                                                                          +#print(help(i2c.start))
                                                                                                                                                                                                                          +#print(help(i2c.stop))
                                                                                                                                                                                                                          +#print(help(i2c.readinto))
                                                                                                                                                                                                                          +#print(help(i2c.write))
                                                                                                                                                                                                                          +#print(help(i2c.readfrom))
                                                                                                                                                                                                                          +#print(help(i2c.readfrom_into))
                                                                                                                                                                                                                          +#print(help(i2c.writeto))
                                                                                                                                                                                                                          +#print(help(i2c.writevto))
                                                                                                                                                                                                                          +#print(help(i2c.readfrom_mem))
                                                                                                                                                                                                                          +#print(help(i2c.readfrom_mem_into))
                                                                                                                                                                                                                          +#print(help(i2c.writeto_mem))
                                                                                                                                                                                                                          +#exit
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +oled = SSD1306_I2C(128, 32, i2c)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Raspberry Pi logo as 32x32 bytearray
                                                                                                                                                                                                                          +buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Load the raspberry pi logo into the framebuffer (the image is 32x32)
                                                                                                                                                                                                                          +fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def blk():
                                                                                                                                                                                                                          +    oled.fill(0)
                                                                                                                                                                                                                          +    oled.show()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def horiz(l,t,r,c):  # left, right , top
                                                                                                                                                                                                                          +    n = r-l+1        # Horizontal line
                                                                                                                                                                                                                          +    for i in range(n):
                                                                                                                                                                                                                          +        oled.pixel(l + i, t, c)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def vert(l,t,b,c):   # left, top, bottom
                                                                                                                                                                                                                          +    n = b-t+1        # Vertical line
                                                                                                                                                                                                                          +    for i in range(n):
                                                                                                                                                                                                                          +        oled.pixel(l, t+i,c)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def box(l,t,r,b,c):  # left, top, right, bottom
                                                                                                                                                                                                                          +    horiz(l,t,r,c)   # Hollow rectangle
                                                                                                                                                                                                                          +    horiz(l,b,r,c)
                                                                                                                                                                                                                          +    vert(l,t,b,c)
                                                                                                                                                                                                                          +    vert(r,t,b,c)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def ring2(cx,cy,r,c):   # Centre (x,y), radius, colour
                                                                                                                                                                                                                          +    for angle in range(0, 90, 2):  # 0 to 90 degrees in 2s
                                                                                                                                                                                                                          +        y3=int(r*math.sin(math.radians(angle)))
                                                                                                                                                                                                                          +        x3=int(r*math.cos(math.radians(angle)))
                                                                                                                                                                                                                          +        oled.pixel(cx-x3,cy+y3,c)  # 4 quadrants
                                                                                                                                                                                                                          +        oled.pixel(cx-x3,cy-y3,c)
                                                                                                                                                                                                                          +        oled.pixel(cx+x3,cy+y3,c)
                                                                                                                                                                                                                          +        oled.pixel(cx+x3,cy-y3,c)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#print(help(oled.text()))
                                                                                                                                                                                                                          +#print(help())
                                                                                                                                                                                                                          +#help('modules')
                                                                                                                                                                                                                          +#help(oled)
                                                                                                                                                                                                                          +#help(oled.text)
                                                                                                                                                                                                                          +#help(framebuf.FrameBuffer)
                                                                                                                                                                                                                          +#help(framebuf.FrameBuffer.help())
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Clear the oled display in case it has junk on it.
                                                                                                                                                                                                                          +oled.fill(0) # Black
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Blit the image from the framebuffer to the oled display
                                                                                                                                                                                                                          +oled.blit(fb, 96, 0)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Basic stuff
                                                                                                                                                                                                                          +oled.text("Raspberry Pi",5,5)
                                                                                                                                                                                                                          +oled.text("RP2040",5,15)
                                                                                                                                                                                                                          +oled.text("press GP21",5,25)
                                                                                                                                                                                                                          +oled.pixel(10,60,1)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#ring2(50,43,20,1)  # Empty circle             
                                                                                                                                                                                                                          +# Finally update the oled display so the image & text is displayed
                                                                                                                                                                                                                          +oled.show()
                                                                                                                                                                                                                          +utime.sleep(1)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +#
                                                                                                                                                                                                                          +# Back to the motor control stuff. (sorry... i'm soppy today)
                                                                                                                                                                                                                          +# 
                                                                                                                                                                                                                          +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                                          +def button_pressed_handler(pin):
                                                                                                                                                                                                                          +    global mode, last_time
                                                                                                                                                                                                                          +    new_time = utime.ticks_ms()
                                                                                                                                                                                                                          +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                          +    if (new_time - last_time) > 200:
                                                                                                                                                                                                                          +        # this should be pin.id but it does not work
                                                                                                                                                                                                                          +        if '21' in str(pin):
                                                                                                                                                                                                                          +            mode +=1
                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                          +            mode -=1
                                                                                                                                                                                                                          +        # deal with ends
                                                                                                                                                                                                                          +        if mode > 4: mode = 2
                                                                                                                                                                                                                          +        if mode < 0: mode = 0
                                                                                                                                                                                                                          +        last_time = new_time
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# now we register the handler function when the button is pressed
                                                                                                                                                                                                                          +faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                          +slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Piezo Buzzer is on GP22
                                                                                                                                                                                                                          +buzzer=PWM(Pin(BUZZER_PIN))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +MAX_POWER_LEVEL = 65025
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +MAX_DISTANCE = 100 # ignore anything above this
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# Motor Pins are A: 8,9 and B: 10,11
                                                                                                                                                                                                                          +RIGHT_FORWARD_PIN = 11 # this must be wired backword?
                                                                                                                                                                                                                          +RIGHT_REVERSE_PIN = 10 
                                                                                                                                                                                                                          +LEFT_FORWARD_PIN = 9
                                                                                                                                                                                                                          +LEFT_REVERSE_PIN = 8
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# our PWM objects
                                                                                                                                                                                                                          +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                          +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                          +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                          +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# returns distance in cm
                                                                                                                                                                                                                          +def ping():
                                                                                                                                                                                                                          +    #print('in ping')
                                                                                                                                                                                                                          +    trigger.low()
                                                                                                                                                                                                                          +    utime.sleep_us(2) # Wait 2 microseconds low
                                                                                                                                                                                                                          +    trigger.high()
                                                                                                                                                                                                                          +    utime.sleep_us(5) # Stay high for 5 miroseconds
                                                                                                                                                                                                                          +    trigger.low()
                                                                                                                                                                                                                          +    while echo.value() == 0:
                                                                                                                                                                                                                          +        signaloff = utime.ticks_us()
                                                                                                                                                                                                                          +    #print('echo is 1')
                                                                                                                                                                                                                          +    while echo.value() == 1:
                                                                                                                                                                                                                          +        signalon = utime.ticks_us()
                                                                                                                                                                                                                          +    timepassed = signalon - signaloff
                                                                                                                                                                                                                          +    distance = (timepassed * 0.0343) / 2
                                                                                                                                                                                                                          +    print(distance)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +    return int(distance)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def turn_motor_on(pwm):
                                                                                                                                                                                                                          +   #pwm.duty_u16(65025)
                                                                                                                                                                                                                          +   pwm.duty_u16(16000)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def turn_motor_off(pwm):
                                                                                                                                                                                                                          +   pwm.duty_u16(0)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def forward():
                                                                                                                                                                                                                          +    turn_motor_on(right_forward)
                                                                                                                                                                                                                          +    turn_motor_on(left_forward)
                                                                                                                                                                                                                          +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                          +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def reverse():
                                                                                                                                                                                                                          +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                          +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                          +    turn_motor_off(right_forward)
                                                                                                                                                                                                                          +    turn_motor_off(left_forward)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def turn_right():
                                                                                                                                                                                                                          +    turn_motor_on(right_forward)
                                                                                                                                                                                                                          +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                          +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                          +    turn_motor_off(left_forward)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def turn_left():
                                                                                                                                                                                                                          +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                          +    turn_motor_on(left_forward)
                                                                                                                                                                                                                          +    turn_motor_off(right_forward)
                                                                                                                                                                                                                          +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def stop():
                                                                                                                                                                                                                          +    turn_motor_off(right_forward)
                                                                                                                                                                                                                          +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                          +    turn_motor_off(left_forward)
                                                                                                                                                                                                                          +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs
                                                                                                                                                                                                                          +blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28]
                                                                                                                                                                                                                          +blue_led_pins.remove(PING_TRIGGER_PIN)
                                                                                                                                                                                                                          +blue_led_pins.remove(PING_ECHO_PIN)
                                                                                                                                                                                                                          +blue_led_pins.remove(OLED_SDA_PIN)
                                                                                                                                                                                                                          +blue_led_pins.remove(OLED_SCL_PIN)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]
                                                                                                                                                                                                                          +dist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +NUMBER_PIXELS = 2
                                                                                                                                                                                                                          +STATE_MACHINE = 0
                                                                                                                                                                                                                          +NEOPIXEL_PIN = 18
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                          +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB")
                                                                                                                                                                                                                          +strip.brightness(100)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                          +led_ports = []
                                                                                                                                                                                                                          +red = (255, 0, 0)
                                                                                                                                                                                                                          +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                                          +yellow = (255, 150, 0)
                                                                                                                                                                                                                          +green = (0, 255, 0)
                                                                                                                                                                                                                          +blue = (0, 0, 255)
                                                                                                                                                                                                                          +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                                          +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                                          +cyan = (0, 255, 255)
                                                                                                                                                                                                                          +lightgreen = (100, 255, 100)
                                                                                                                                                                                                                          +white = (128, 128, 128) # not too bright
                                                                                                                                                                                                                          +pink = (255, 128, 128)
                                                                                                                                                                                                                          +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')
                                                                                                                                                                                                                          +num_colors = len(color_names)
                                                                                                                                                                                                                          +colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# create a list of the ports
                                                                                                                                                                                                                          +for i in range(number_leds):
                                                                                                                                                                                                                          +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +LED_DELAY = .08
                                                                                                                                                                                                                          +def run_lights():
                                                                                                                                                                                                                          +    for i in range(0, number_leds):
                                                                                                                                                                                                                          +        led_ports[i].high()
                                                                                                                                                                                                                          +        strip.set_pixel(0, colors[i])
                                                                                                                                                                                                                          +        strip.set_pixel(1, colors[i])
                                                                                                                                                                                                                          +        strip.show()
                                                                                                                                                                                                                          +        utime.sleep(LED_DELAY)
                                                                                                                                                                                                                          +        led_ports[i].low()
                                                                                                                                                                                                                          +    # blue down
                                                                                                                                                                                                                          +    for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                                          +        led_ports[i].high()
                                                                                                                                                                                                                          +        strip.set_pixel(0, colors[i])
                                                                                                                                                                                                                          +        strip.set_pixel(1, colors[i])
                                                                                                                                                                                                                          +        strip.show()
                                                                                                                                                                                                                          +        utime.sleep(LED_DELAY)
                                                                                                                                                                                                                          +        led_ports[i].low()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def led_show_dist(in_distance):
                                                                                                                                                                                                                          +    global number_leds
                                                                                                                                                                                                                          +    for led_index in range(0, number_leds):
                                                                                                                                                                                                                          +        if in_distance > dist_scale[led_index]:
                                                                                                                                                                                                                          +            led_ports[led_index].high()
                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                          +            led_ports[led_index].low()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def play_no_signal():
                                                                                                                                                                                                                          +    playnote(100, 0.1)
                                                                                                                                                                                                                          +    sound_off()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def play_turn():
                                                                                                                                                                                                                          +    playnote(500, .1)
                                                                                                                                                                                                                          +    sound_off()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def setfreq(frequency):
                                                                                                                                                                                                                          +    buzzer.freq(frequency)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def playnote(frequency, time):
                                                                                                                                                                                                                          +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                          +    setfreq(frequency)
                                                                                                                                                                                                                          +    utime.sleep(time)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def sound_off():
                                                                                                                                                                                                                          +    buzzer.duty_u16(0)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def rest(time):
                                                                                                                                                                                                                          +    buzzer.duty_u16(0)
                                                                                                                                                                                                                          +    utime.sleep(time)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def play_startup():
                                                                                                                                                                                                                          +    playnote(600, .2)
                                                                                                                                                                                                                          +    rest(.05)
                                                                                                                                                                                                                          +    playnote(600, .2)
                                                                                                                                                                                                                          +    rest(.05)
                                                                                                                                                                                                                          +    playnote(600, .2)
                                                                                                                                                                                                                          +    rest(.1)
                                                                                                                                                                                                                          +    playnote(800, .4)
                                                                                                                                                                                                                          +    sound_off()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def servo(degrees):
                                                                                                                                                                                                                          +    if degrees > 180: degrees=180
                                                                                                                                                                                                                          +    if degrees < 0: degrees=0
                                                                                                                                                                                                                          +    maxDuty=8000 # duty*100
                                                                                                                                                                                                                          +    minDuty=2000 # duty*100
                                                                                                                                                                                                                          +    #maxDuty=2000 # test
                                                                                                                                                                                                                          +    #minDuty=8000 # test
                                                                                                                                                                                                                          +    newDuty=minDuty+(maxDuty-minDuty)*(degrees/180)
                                                                                                                                                                                                                          +    servoPin.duty_u16(int(newDuty))
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +servoPin = PWM(Pin(SERVO_PIN))
                                                                                                                                                                                                                          +servoPin.freq(50)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +valid_distance = 1
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +def main():
                                                                                                                                                                                                                          +    global valid_distance
                                                                                                                                                                                                                          +    print("running main()")
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +    play_startup()
                                                                                                                                                                                                                          +    oled_count=0 # repeat every
                                                                                                                                                                                                                          +    oled_count_max=0 # times through loop
                                                                                                                                                                                                                          +    servo_count=0 
                                                                                                                                                                                                                          +    servo_count_max=0 # when to update
                                                                                                                                                                                                                          +    servo_degrees = 0
                                                                                                                                                                                                                          +    servo(servo_degrees) # start in that pos
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +    # loop forever
                                                                                                                                                                                                                          +    while True:
                                                                                                                                                                                                                          +        if mode == 0:
                                                                                                                                                                                                                          +            stop()
                                                                                                                                                                                                                          +            run_lights()
                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                          +            distance = ping()
                                                                                                                                                                                                                          +            print('Distance:', distance)
                                                                                                                                                                                                                          +            oled_count += 1
                                                                                                                                                                                                                          +            if oled_count > oled_count_max:
                                                                                                                                                                                                                          +                oled.fill(0) # Black
                                                                                                                                                                                                                          +                oled.text("Distance:",5,5)
                                                                                                                                                                                                                          +                oled.text("{:f}".format(distance),5,15)
                                                                                                                                                                                                                          +                oled.show()
                                                                                                                                                                                                                          +                oled_count = 0
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +            servo_count += 1
                                                                                                                                                                                                                          +            if servo_count > servo_count_max:
                                                                                                                                                                                                                          +                if distance > MAX_DISTANCE:
                                                                                                                                                                                                                          +                    servo_degrees = 0
                                                                                                                                                                                                                          +                else:
                                                                                                                                                                                                                          +                    servo_degrees = 180-distance/MAX_DISTANCE*180
                                                                                                                                                                                                                          +                servo(servo_degrees)
                                                                                                                                                                                                                          +                servo_count = 0
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +            if distance > MAX_DISTANCE:
                                                                                                                                                                                                                          +                # only print if we used to have a valid distance
                                                                                                                                                                                                                          +                if valid_distance == 1:
                                                                                                                                                                                                                          +                    print('no signal')      
                                                                                                                                                                                                                          +                valid_distance = 0
                                                                                                                                                                                                                          +            else:
                                                                                                                                                                                                                          +                print(distance)
                                                                                                                                                                                                                          +                #note=distance*10
                                                                                                                                                                                                                          +                #playnote(note, .025)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +                if distance < TURN_DISTANCE:
                                                                                                                                                                                                                          +                    play_turn()
                                                                                                                                                                                                                          +                    # back up for a bit
                                                                                                                                                                                                                          +                    reverse()
                                                                                                                                                                                                                          +                    utime.sleep(REVERSE_TIME)
                                                                                                                                                                                                                          +                    # half right and half left turns
                                                                                                                                                                                                                          +                    if urandom.random() < .5:
                                                                                                                                                                                                                          +                        turn_right()
                                                                                                                                                                                                                          +                    else:
                                                                                                                                                                                                                          +                        turn_left()
                                                                                                                                                                                                                          +                    utime.sleep(TURN_TIME)
                                                                                                                                                                                                                          +                    forward()
                                                                                                                                                                                                                          +                else:
                                                                                                                                                                                                                          +                    print('forward')
                                                                                                                                                                                                                          +                    forward()
                                                                                                                                                                                                                          +                valid_distance = 1
                                                                                                                                                                                                                          +                led_show_dist(distance)
                                                                                                                                                                                                                          +            utime.sleep(0.05)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# clean up
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt
                                                                                                                                                                                                                          +try:
                                                                                                                                                                                                                          +    main()
                                                                                                                                                                                                                          +except KeyboardInterrupt:
                                                                                                                                                                                                                          +    print('Got ctrl-c')
                                                                                                                                                                                                                          +except Exception as e: print(e)
                                                                                                                                                                                                                          +finally:
                                                                                                                                                                                                                          +    # Optional cleanup code
                                                                                                                                                                                                                          +    print('turning off sound')
                                                                                                                                                                                                                          +    buzzer.duty_u16(0)
                                                                                                                                                                                                                          +    print('shutting motors down')
                                                                                                                                                                                                                          +    stop()
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                          + Collision Avoidance Ping +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                          + Line Follower +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040-robot/25-line-follower/index.html b/kits/maker-pi-rp2040-robot/25-line-follower/index.html new file mode 100644 index 000000000..52397cd7d --- /dev/null +++ b/kits/maker-pi-rp2040-robot/25-line-follower/index.html @@ -0,0 +1,2405 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Line Follower - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + Line Follower + + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                              + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Assembly + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Line Follower + + + + + + + +
                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                  • + + + Parts List + + + +
                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                  • + + + IR Sensors + + + +
                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                  • + + + Full Source Code + + + +
                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                              • + + + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                            • + + + Parts List + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            • + + + IR Sensors + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            • + + + Full Source Code + + + +
                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                            Line Follower Robot

                                                                                                                                                                                                                            + + +

                                                                                                                                                                                                                            Line following robot projects is a favorite project for our students. They teach the students the concept of +feedback to keep a robot following a line on a track or on the floor. They are not easy to get working +and require careful calibration of the sensor sensitivity and carefully adjusting the right and left motor +power to keep the robot on track. Once the student gets the robot working it is a time for celebration!

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            The total cost of the kit is about $20.

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            Parts List

                                                                                                                                                                                                                            + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            Part NameDescriptionPriceLink
                                                                                                                                                                                                                            Cytron BoardMain board with RP2040 and motor driver. Kits come with Grove connectors and a screwdriver.$12
                                                                                                                                                                                                                            SmartCar ChassisSmartCar chassis with wheels and 4 AA battery pack
                                                                                                                                                                                                                            IR Sensors (2)Low cost IR light sensors$1
                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            IR Sensors

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            We can purchase IR sensors on eBay for about $1 each in quantity 10. +The sensors send a digital 0/1 signal to the microcontroller depending on if they are over the line. +Our job is to write some MicroPython code to keep the robot following the line. +Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room.

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room. Some +of our rooms have a white floor with a black line and some +of our rooms have a dark floor with a white line. You may have to +adjust both the trim potentiometer and the logic of the code for different situations.

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            Use the Grove connectors to hook up the IR sensors. I used the red (VCC), black (GDN) and white wires (Data) and +I just cut off the yellow wires to keep them out of the way. I then connected the Grove connectors +to ports 2 and 3 of the Cytron board.

                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            I connected the motors to the MOTOR 1 and MOTOR 2 headers with a screwdriver and I hooked +the battery wires up to the power header of the board.

                                                                                                                                                                                                                            +
                                                                                                                                                                                                                             1
                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                            +17
                                                                                                                                                                                                                            +18
                                                                                                                                                                                                                            from machine import Pin
                                                                                                                                                                                                                            +from utime import sleep
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +RIGHT_SENSOR_PIN = 2
                                                                                                                                                                                                                            +LEFT_SENSOR_PIN = 4
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +right_sensor = Pin(RIGHT_SENSOR_PIN)
                                                                                                                                                                                                                            +left_sensor = Pin(LEFT_SENSOR_PIN)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +while True:
                                                                                                                                                                                                                            +    r = right_sensor.value()
                                                                                                                                                                                                                            +    l = left_sensor.value()
                                                                                                                                                                                                                            +    print("r", r, "l=", l)
                                                                                                                                                                                                                            +    if r == 0:
                                                                                                                                                                                                                            +        print("right over white")
                                                                                                                                                                                                                            +    if l == 0:
                                                                                                                                                                                                                            +        print("left over white")
                                                                                                                                                                                                                            +    sleep(.2)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +

                                                                                                                                                                                                                            Full Source Code

                                                                                                                                                                                                                            +
                                                                                                                                                                                                                             1
                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                            +17
                                                                                                                                                                                                                            +18
                                                                                                                                                                                                                            +19
                                                                                                                                                                                                                            +20
                                                                                                                                                                                                                            +21
                                                                                                                                                                                                                            +22
                                                                                                                                                                                                                            +23
                                                                                                                                                                                                                            +24
                                                                                                                                                                                                                            +25
                                                                                                                                                                                                                            +26
                                                                                                                                                                                                                            +27
                                                                                                                                                                                                                            +28
                                                                                                                                                                                                                            +29
                                                                                                                                                                                                                            +30
                                                                                                                                                                                                                            +31
                                                                                                                                                                                                                            +32
                                                                                                                                                                                                                            +33
                                                                                                                                                                                                                            +34
                                                                                                                                                                                                                            +35
                                                                                                                                                                                                                            +36
                                                                                                                                                                                                                            +37
                                                                                                                                                                                                                            +38
                                                                                                                                                                                                                            +39
                                                                                                                                                                                                                            +40
                                                                                                                                                                                                                            +41
                                                                                                                                                                                                                            +42
                                                                                                                                                                                                                            +43
                                                                                                                                                                                                                            +44
                                                                                                                                                                                                                            +45
                                                                                                                                                                                                                            +46
                                                                                                                                                                                                                            +47
                                                                                                                                                                                                                            +48
                                                                                                                                                                                                                            +49
                                                                                                                                                                                                                            +50
                                                                                                                                                                                                                            +51
                                                                                                                                                                                                                            +52
                                                                                                                                                                                                                            +53
                                                                                                                                                                                                                            +54
                                                                                                                                                                                                                            +55
                                                                                                                                                                                                                            +56
                                                                                                                                                                                                                            +57
                                                                                                                                                                                                                            +58
                                                                                                                                                                                                                            +59
                                                                                                                                                                                                                            +60
                                                                                                                                                                                                                            +61
                                                                                                                                                                                                                            +62
                                                                                                                                                                                                                            +63
                                                                                                                                                                                                                            +64
                                                                                                                                                                                                                            +65
                                                                                                                                                                                                                            +66
                                                                                                                                                                                                                            +67
                                                                                                                                                                                                                            +68
                                                                                                                                                                                                                            +69
                                                                                                                                                                                                                            +70
                                                                                                                                                                                                                            +71
                                                                                                                                                                                                                            +72
                                                                                                                                                                                                                            +73
                                                                                                                                                                                                                            +74
                                                                                                                                                                                                                            +75
                                                                                                                                                                                                                            +76
                                                                                                                                                                                                                            +77
                                                                                                                                                                                                                            +78
                                                                                                                                                                                                                            +79
                                                                                                                                                                                                                            +80
                                                                                                                                                                                                                            +81
                                                                                                                                                                                                                            +82
                                                                                                                                                                                                                            +83
                                                                                                                                                                                                                            +84
                                                                                                                                                                                                                            +85
                                                                                                                                                                                                                            +86
                                                                                                                                                                                                                            +87
                                                                                                                                                                                                                            +88
                                                                                                                                                                                                                            +89
                                                                                                                                                                                                                            +90
                                                                                                                                                                                                                            +91
                                                                                                                                                                                                                            +92
                                                                                                                                                                                                                            +93
                                                                                                                                                                                                                            +94
                                                                                                                                                                                                                            from machine import Pin, PWM
                                                                                                                                                                                                                            +from time import sleep
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +# sensor setup
                                                                                                                                                                                                                            +RIGHT_SENSOR_PIN = 2
                                                                                                                                                                                                                            +LEFT_SENSOR_PIN = 4
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +right_sensor = Pin(RIGHT_SENSOR_PIN)
                                                                                                                                                                                                                            +left_sensor = Pin(LEFT_SENSOR_PIN)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +# speaker pin on the Cytron Maker Pi RP2040
                                                                                                                                                                                                                            +SPEAKER_PIN = 22
                                                                                                                                                                                                                            +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                            +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                            +# set the duty cycle
                                                                                                                                                                                                                            +speaker.duty_u16(1000)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +# Motor setup
                                                                                                                                                                                                                            +RIGHT_FORWARD_PIN = 11
                                                                                                                                                                                                                            +RIGHT_REVERSE_PIN =10
                                                                                                                                                                                                                            +LEFT_FORWARD_PIN = 8
                                                                                                                                                                                                                            +LEFT_REVERSE_PIN = 9
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                            +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                            +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                            +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +MAX_POWER_LEVEL = 65025
                                                                                                                                                                                                                            +QUARTER_POWER = 65025 >> 2
                                                                                                                                                                                                                            +SLOW_DRIVE_POWER = 16000
                                                                                                                                                                                                                            +BOOST_LEVEL = 15000
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +# while True:
                                                                                                                                                                                                                            +def spin_wheel(pwm):
                                                                                                                                                                                                                            +    pwm.duty_u16(SLOW_DRIVE_POWER)
                                                                                                                                                                                                                            +    sleep(2)
                                                                                                                                                                                                                            +    pwm.duty_u16(0)
                                                                                                                                                                                                                            +    sleep(1)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +def forward():
                                                                                                                                                                                                                            +    right_forward.duty_u16(SLOW_DRIVE_POWER)
                                                                                                                                                                                                                            +    right_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    left_forward.duty_u16(SLOW_DRIVE_POWER)
                                                                                                                                                                                                                            +    left_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    speaker.duty_u16(0)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +def right():
                                                                                                                                                                                                                            +    right_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL)
                                                                                                                                                                                                                            +    right_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    left_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL)
                                                                                                                                                                                                                            +    left_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    speaker.duty_u16(1000)
                                                                                                                                                                                                                            +    speaker.freq(800)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +def left():
                                                                                                                                                                                                                            +    right_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL)
                                                                                                                                                                                                                            +    right_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    left_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL)
                                                                                                                                                                                                                            +    left_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    speaker.duty_u16(1000)
                                                                                                                                                                                                                            +    speaker.freq(1000)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +def stop():
                                                                                                                                                                                                                            +    right_forward.duty_u16(0)
                                                                                                                                                                                                                            +    right_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    left_forward.duty_u16(0)
                                                                                                                                                                                                                            +    left_reverse.duty_u16(0)
                                                                                                                                                                                                                            +    speaker.duty_u16(0)
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +def main():
                                                                                                                                                                                                                            +    while True:
                                                                                                                                                                                                                            +        r = right_sensor.value()
                                                                                                                                                                                                                            +        l = left_sensor.value()
                                                                                                                                                                                                                            +        if r == 0 and l == 1:
                                                                                                                                                                                                                            +            print("right over white - turning left")
                                                                                                                                                                                                                            +            right()
                                                                                                                                                                                                                            +        if l == 0:
                                                                                                                                                                                                                            +            print("left over white")
                                                                                                                                                                                                                            +            left()
                                                                                                                                                                                                                            +        else:
                                                                                                                                                                                                                            +            forward()
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +# end of main()
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +try:
                                                                                                                                                                                                                            +    main()
                                                                                                                                                                                                                            +except KeyboardInterrupt:
                                                                                                                                                                                                                            +    print('Got ctrl-c')
                                                                                                                                                                                                                            +finally:
                                                                                                                                                                                                                            +    # Cleanup code
                                                                                                                                                                                                                            +    print('Cleaning up')
                                                                                                                                                                                                                            +    print('Powering down all motors now.')
                                                                                                                                                                                                                            +    stop()
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                            + Ping Servo Meter +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                            + Introduction +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040-robot/Kit-Contents-Checklist.pptx b/kits/maker-pi-rp2040-robot/Kit-Contents-Checklist.pptx similarity index 100% rename from docs/kits/maker-pi-rp2040-robot/Kit-Contents-Checklist.pptx rename to kits/maker-pi-rp2040-robot/Kit-Contents-Checklist.pptx diff --git a/kits/maker-pi-rp2040-robot/index.html b/kits/maker-pi-rp2040-robot/index.html new file mode 100644 index 000000000..ccd5b4285 --- /dev/null +++ b/kits/maker-pi-rp2040-robot/index.html @@ -0,0 +1,2091 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + Introduction + + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                                  + + + + + Maker Pi RP2040 Robot + + + + + + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Assembly + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Motor Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Up/Down Motor Speed Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Square Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Servo Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Scanner Test + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Time of Flight Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Time of Flight Sound Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + MicroSwitch Bot + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Ultrasonic Ping Lab + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Collision Avoidance Time-of-Flight + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Collision Avoidance Ping + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Ping Servo Meter + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Line Follower + + + + +
                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                • + + + + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                              • + + + Base Cytron Maker Pi RP2040 Robot Kit + + + +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                              • + + + Sample Parts List + + + +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                              • + + + Demo with OLED Display + + + +
                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                              Cytron Maker Pi RP2040 Collision Avoidance Robot

                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              We have been working on designing a run robot that can be used to teach computational thinking since 2014. We have gone through many generations, and now we think we have a fantastic design that is powerful, flexible, extendible and inexpensive. We love this robot because:

                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                              1. The cost of parts is under $20.00 US
                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                              3. It is programmed with Python
                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                              5. It has plenty of power - with 264K RAM it has the ability to run complex programs
                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                              7. The design is flexible and it is easy to add displays and other sensors
                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Base Cytron Maker Pi RP2040 Robot Kit

                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Maker Pi RP2040 Top View +This version uses the time-of-flight sensor.

                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              The robot can be built ia a few hours using a screwdriver and soldering four wires onto the motors.

                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Sample Parts List

                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Cytron Ping Kit Parts

                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                              1. Cytron Maker Pi RP2040 board (includes Grove connectors, screwdriver and feet) Cytron DigiKey Amazon Adafruit YouTube Video
                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                              3. 2 Wheel Drive Smart Car Kit: Chassis Main board (acrylic), 2x DC Motors with wires soldered, 2x wheels, 4x AA Battery Case: Cytron Amazon eBay
                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                              5. Distance Sensor (Time-of-flight or Ultrasonic ping): Cytron ebay Amazon
                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                              7. Ping sensor mount
                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                              9. 2x M3 6 mm screws and nuts
                                                                                                                                                                                                                              10. +
                                                                                                                                                                                                                              11. 4x M3 10 mm screes and nuts
                                                                                                                                                                                                                              12. +
                                                                                                                                                                                                                              13. Micro USB cable
                                                                                                                                                                                                                              14. +
                                                                                                                                                                                                                              15. 4x AA batteries
                                                                                                                                                                                                                              16. +
                                                                                                                                                                                                                              +

                                                                                                                                                                                                                              Demo with OLED Display

                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                              1. Cytron Maker Pi RP2040 robotics board ($10)
                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                              3. SmartCar kit ($9)
                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                              5. Time-of-flight sensor (4)
                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                              7. Optional OLED SPI 2.24" SSD1606 display ($18)
                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                              + Up/Down Mode Lab +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                              + Assembly +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/01-getting-started/index.html b/kits/maker-pi-rp2040/01-getting-started/index.html new file mode 100644 index 000000000..029870b9f --- /dev/null +++ b/kits/maker-pi-rp2040/01-getting-started/index.html @@ -0,0 +1,1984 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Getting Started - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + Getting Started + + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                                  + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                    + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                      + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Getting Started + + + + + + + +
                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                      • + + + Purchasing + + + +
                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                      • + + + Install the MicroPython Runtime Library + + + +
                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                      • + + + Get Familiar with your IDE (Thonny) and the Basic Programs + + + +
                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                  • + + + + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                • + + + Purchasing + + + +
                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                • + + + Install the MicroPython Runtime Library + + + +
                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                • + + + Get Familiar with your IDE (Thonny) and the Basic Programs + + + +
                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                Getting Started

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Purchasing

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                The retail list price is $9.99. Thie Cytron Maker Pi RP2040 kit includes 3 Grove connectors, screwdriver and feet) Cytron

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Here are some online retailers that seel this kit:

                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                • DigiKey
                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                • Amazon
                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                • Adafruit
                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                There is also a YouTube Video that demonstrates the features of the board.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Install the MicroPython Runtime Library

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                The Maker Pi RP2040 comes with an incompatible CircuitPython run-time. Our first step is to re-initialize the board with the Raspberry Pi flash_nuke.uf2 runtime. We can then load the latest MicroPython libraries. When we wrote these labs we were using MicroPython version 1.7 that was released in September of 2021.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                To install MicroPython you mush hold down the BOTSEL button on the main board while you turn on the board using the on-board power switch. This will make the board look like a USB drive. You can then just drag the flash-nuke file onto the drive and the board will be initialized. Make sure to power the board off and back on.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                You can now repeat this process with the Raspberry Pi MicroPython Runtime. Just remember to press and hold down the BOTSEL before you turn on the board and reboot after the image has been copied to the microcontroller.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                If you have never used MicroPython, the Raspberry Pi Foundation has a nice Getting Started Guide that can be helpful.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Get Familiar with your IDE (Thonny) and the Basic Programs

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                There are many Integrated Development Environments (IDEs) that work with the Raspberry Pi RP2040 chip. The one you chose just should support MicroPython and be able to upload and run new programs. Once you turn on the board you should be able to configure Thonny to use the Raspberry Pi MicroPython interface. When you press the Stop/Reset button you should see the MicroPython REPL prompt.

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Test the Motor Connections

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Use the Motor Connection Lab

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                Getting Help

                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                MicroPython on the RP2040 is the most powerful low-cost system on the market today. With 264K of RAM, it will take a LOT of work to run out of memory. But with all things new, there is a lock of good documentation, drivers and sample code. To help you along, we suggest the following resources:

                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                1. The MicroPython Raspsberry Pi Forum. Be sure use the search to check for prior questions. +2.
                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                + Introduction +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                + Blue LED Lab +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/02-blue-led-lab/index.html b/kits/maker-pi-rp2040/02-blue-led-lab/index.html new file mode 100644 index 000000000..679d952ab --- /dev/null +++ b/kits/maker-pi-rp2040/02-blue-led-lab/index.html @@ -0,0 +1,2017 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Blue LED Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + Blue LED Lab + + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                    + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                      + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + Blue LED Lab + + + + + + + +
                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                        • + + + Blink First Blue LED + + + +
                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                        • + + + Running Lights on All LEDs + + + +
                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                    • + + + + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                  • + + + Blink First Blue LED + + + +
                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                  • + + + Running Lights on All LEDs + + + +
                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                  Blue LED Lab

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Once you have the MicroPython runtime installed and your IDE setup, this board is easy to program!

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Let's take a look at the classic "Blink" program that turns a single LED on and off every second.

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Blink First Blue LED

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  The Maker Pi RP2040 has a row of 13 small blue LEDs that monitor the digital input/output of 13 of the GPIO signals. If you set any of the output pins to be HIGH, the LED will be on. If you set the pin to be LOW, the blue LED will be off. These LEDs make it easy for you to view the state of your GPIO pins and can help debugging your programs.

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Just remember that if you are using the pins for communication, you can't use the LEDs for other purposes.

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Here is a small program that will blink the first blue LED:

                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                  +4
                                                                                                                                                                                                                                  +5
                                                                                                                                                                                                                                  +6
                                                                                                                                                                                                                                  +7
                                                                                                                                                                                                                                  +8
                                                                                                                                                                                                                                  import machine
                                                                                                                                                                                                                                  +import time
                                                                                                                                                                                                                                  +# setup the first LED as an output signal
                                                                                                                                                                                                                                  +first_led = machine.Pin(0, machine.Pin.OUT)
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                  +    first_led.toggle()
                                                                                                                                                                                                                                  +    time.sleep(1)
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Note that the first four lines are the "setup" of the program. These lines will only run once when the program starts. The code indented after the while True: line will continue to run until the device is reset or powered down.

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Running Lights on All LEDs

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Here is a demo using the 13 nice blue LEDs used to show the status of the pins.

                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  Maker Pi RP2040 LED Demo

                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                  import machine
                                                                                                                                                                                                                                  +import time
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs
                                                                                                                                                                                                                                  +blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]
                                                                                                                                                                                                                                  +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                                  +led_ports = []
                                                                                                                                                                                                                                  +delay = .05
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +# create a list of the ports
                                                                                                                                                                                                                                  +for i in range(number_leds):
                                                                                                                                                                                                                                  +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +# loop forever
                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                  +    # blue up
                                                                                                                                                                                                                                  +    for i in range(0, number_leds):
                                                                                                                                                                                                                                  +        led_ports[i].high()
                                                                                                                                                                                                                                  +        time.sleep(delay)
                                                                                                                                                                                                                                  +        led_ports[i].low()
                                                                                                                                                                                                                                  +    # blue down
                                                                                                                                                                                                                                  +    for i in range(number_leds - 1, 0, -1):
                                                                                                                                                                                                                                  +        led_ports[i].high()
                                                                                                                                                                                                                                  +        time.sleep(delay)
                                                                                                                                                                                                                                  +        led_ports[i].low()
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                  This demo uses a list of all the 13 digital I/O ports. For each port it sets the port to be a digital output. In the main loop it then goes up and down the strip of LEDs, turning each one on for 1/20th of a second (.05 seconds).

                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                  + Getting Started +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                  + NeoPixel Lab +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/03-neopixel-lab/index.html b/kits/maker-pi-rp2040/03-neopixel-lab/index.html new file mode 100644 index 000000000..fd40d460d --- /dev/null +++ b/kits/maker-pi-rp2040/03-neopixel-lab/index.html @@ -0,0 +1,2114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + NeoPixel Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + NeoPixel Lab + + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                      + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                        + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + NeoPixel Lab + + + + + + + +
                                                                                                                                                                                                                                          + + + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                          • + + + NeoPixel Demo Lab + + + +
                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                          • + + + NeoPixel Setup + + + +
                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                          • + + + NeoPixel Blink Lab + + + +
                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                          • + + + Setting up the NeoPixel Library + + + +
                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                      • + + + + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    + + + + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                    • + + + NeoPixel Demo Lab + + + +
                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                    • + + + NeoPixel Setup + + + +
                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                    • + + + NeoPixel Blink Lab + + + +
                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                    • + + + Setting up the NeoPixel Library + + + +
                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                    NeoPixel Lab

                                                                                                                                                                                                                                    + +

                                                                                                                                                                                                                                    NeoPixel Demo Lab

                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                    The Maker Pi RP2040 comes with two built-in NeoPixels. Each NeoPixel has a red, green and blue LED inside it. Each of these LEDs can be set to any one of 256 values from 0 (off) to 255 (brightest value).

                                                                                                                                                                                                                                    + + +

                                                                                                                                                                                                                                    NeoPixel Setup

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                    +5
                                                                                                                                                                                                                                    +6
                                                                                                                                                                                                                                    +7
                                                                                                                                                                                                                                    +8
                                                                                                                                                                                                                                    from neopixel import Neopixel
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +NUMBER_PIXELS = 2
                                                                                                                                                                                                                                    +STATE_MACHINE = 0
                                                                                                                                                                                                                                    +LED_PIN = 18
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                                    +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                    NeoPixel Blink Lab

                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                    In this lab, we will turn the first NeoPixel element on red for 1/2 second and then turn it off for 1/2 second. We repeat this until the program is terminated.

                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                    Setting up the NeoPixel Library

                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                    We will be calling a NeoPixel driver in the /lib directory. We initiaze our NeoPixel strip by calling the init method all Neopixel() and pass it three parameters:

                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                    1. The number of pixels in the strip (in our case there are just two)
                                                                                                                                                                                                                                    2. +
                                                                                                                                                                                                                                    3. The state machine (in our case 0)
                                                                                                                                                                                                                                    4. +
                                                                                                                                                                                                                                    5. The LED PIN (in our case this is GP18)
                                                                                                                                                                                                                                    6. +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                    from utime import sleep
                                                                                                                                                                                                                                    +# We are using https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                                                                    +from neopixel import Neopixel
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +NUMBER_PIXELS = 2
                                                                                                                                                                                                                                    +STATE_MACHINE = 0
                                                                                                                                                                                                                                    +LED_PIN = 18
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                                    +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                    +    # turn on first pixel red for 1/2 second
                                                                                                                                                                                                                                    +    strip.set_pixel(0, (255, 0, 0))
                                                                                                                                                                                                                                    +    strip.show()
                                                                                                                                                                                                                                    +    sleep(.5)   
                                                                                                                                                                                                                                    +    strip.set_pixel(0, (0, 0, 0)) # turn all colors off
                                                                                                                                                                                                                                    +    strip.show()
                                                                                                                                                                                                                                    +    sleep(.5)
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                    +20
                                                                                                                                                                                                                                    +21
                                                                                                                                                                                                                                    +22
                                                                                                                                                                                                                                    +23
                                                                                                                                                                                                                                    +24
                                                                                                                                                                                                                                    +25
                                                                                                                                                                                                                                    +26
                                                                                                                                                                                                                                    +27
                                                                                                                                                                                                                                    +28
                                                                                                                                                                                                                                    +29
                                                                                                                                                                                                                                    +30
                                                                                                                                                                                                                                    +31
                                                                                                                                                                                                                                    +32
                                                                                                                                                                                                                                    +33
                                                                                                                                                                                                                                    +34
                                                                                                                                                                                                                                    +35
                                                                                                                                                                                                                                    +36
                                                                                                                                                                                                                                    import time
                                                                                                                                                                                                                                    +# We are using https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                                                                    +from neopixel import Neopixel
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +NUMBER_PIXELS = 2
                                                                                                                                                                                                                                    +STATE_MACHINE = 0
                                                                                                                                                                                                                                    +LED_PIN = 18
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                                    +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +# Color RGB values
                                                                                                                                                                                                                                    +red = (255, 0, 0)
                                                                                                                                                                                                                                    +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                                                    +yellow = (255, 150, 0)
                                                                                                                                                                                                                                    +green = (0, 255, 0)
                                                                                                                                                                                                                                    +blue = (0, 0, 255)
                                                                                                                                                                                                                                    +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                                                    +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                                                    +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')
                                                                                                                                                                                                                                    +num_colors = len(color_names)
                                                                                                                                                                                                                                    +colors = (red, orange, yellow, green, blue, indigo, violet)
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +# set to be 1 to 100 for percent brightness
                                                                                                                                                                                                                                    +strip.brightness(100)
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +color_index = 0
                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                    +    for color in colors:
                                                                                                                                                                                                                                    +        for i in range(NUMBER_PIXELS):
                                                                                                                                                                                                                                    +            print(i, color_names[color_index])
                                                                                                                                                                                                                                    +            strip.set_pixel(i, color)
                                                                                                                                                                                                                                    +            strip.show()
                                                                                                                                                                                                                                    +            time.sleep(1)
                                                                                                                                                                                                                                    +        color_index += 1
                                                                                                                                                                                                                                    +        if color_index >= num_colors: color_index = 0
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                    + Blue LED Lab +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                    + Button Lab +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/04-button-lab/index.html b/kits/maker-pi-rp2040/04-button-lab/index.html new file mode 100644 index 000000000..28a6be307 --- /dev/null +++ b/kits/maker-pi-rp2040/04-button-lab/index.html @@ -0,0 +1,2194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Button Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + Button Lab + + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                        + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                          + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Button Lab + + + + + + + +
                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                            • + + + Making the Buttons Change the NeoPixel Color + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                        • + + + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                      • + + + Making the Buttons Change the NeoPixel Color + + + +
                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                      Two Button Press

                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      We learned how to write code to monitor a button press in the Button Lab.

                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      Recall we talked about how to remove the "debounce noise" when a button is pressed by adding a timer to make sure we had a clean transition (debouncing the switch):

                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      Debounce Transition

                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      We did this by waiting for the transition to settle down to its new state.

                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                      import utime
                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +button_presses = 0 # the count of times the button has been pressed
                                                                                                                                                                                                                                      +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +builtin_led = machine.Pin(25, Pin.OUT)
                                                                                                                                                                                                                                      +# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail
                                                                                                                                                                                                                                      +faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                      +slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                                                      +def button_pressed_handler(pin):
                                                                                                                                                                                                                                      +    global button_presses, last_time
                                                                                                                                                                                                                                      +    new_time = utime.ticks_ms()
                                                                                                                                                                                                                                      +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                                      +    if (new_time - last_time) > 200:
                                                                                                                                                                                                                                      +        # this should be pin.id but it does not work
                                                                                                                                                                                                                                      +        if '20' in str(pin):
                                                                                                                                                                                                                                      +            button_presses +=1
                                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                                      +            button_presses -=1
                                                                                                                                                                                                                                      +        last_time = new_time
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# now we register the handler function when the button is pressed
                                                                                                                                                                                                                                      +faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                      +slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# This is for only printing when a new button press count value happens
                                                                                                                                                                                                                                      +old_presses = 0
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                      +    # only print on change in the button_presses value
                                                                                                                                                                                                                                      +    if button_presses != old_presses:
                                                                                                                                                                                                                                      +        print(button_presses)
                                                                                                                                                                                                                                      +        builtin_led.toggle()
                                                                                                                                                                                                                                      +        old_presses = button_presses
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      Making the Buttons Change the NeoPixel Color

                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                      In this lab, we will combine the button press lab with our NeoPixel lab to allow you to change the NeoPixel colors if a button on the board is pressed. Each button will control the color of one of the pixels.

                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                      +41
                                                                                                                                                                                                                                      +42
                                                                                                                                                                                                                                      +43
                                                                                                                                                                                                                                      +44
                                                                                                                                                                                                                                      +45
                                                                                                                                                                                                                                      +46
                                                                                                                                                                                                                                      +47
                                                                                                                                                                                                                                      +48
                                                                                                                                                                                                                                      +49
                                                                                                                                                                                                                                      +50
                                                                                                                                                                                                                                      +51
                                                                                                                                                                                                                                      +52
                                                                                                                                                                                                                                      +53
                                                                                                                                                                                                                                      +54
                                                                                                                                                                                                                                      +55
                                                                                                                                                                                                                                      +56
                                                                                                                                                                                                                                      +57
                                                                                                                                                                                                                                      +58
                                                                                                                                                                                                                                      +59
                                                                                                                                                                                                                                      +60
                                                                                                                                                                                                                                      +61
                                                                                                                                                                                                                                      +62
                                                                                                                                                                                                                                      +63
                                                                                                                                                                                                                                      +64
                                                                                                                                                                                                                                      +65
                                                                                                                                                                                                                                      +66
                                                                                                                                                                                                                                      +67
                                                                                                                                                                                                                                      +68
                                                                                                                                                                                                                                      +69
                                                                                                                                                                                                                                      +70
                                                                                                                                                                                                                                      +71
                                                                                                                                                                                                                                      +72
                                                                                                                                                                                                                                      +73
                                                                                                                                                                                                                                      +74
                                                                                                                                                                                                                                      +75
                                                                                                                                                                                                                                      +76
                                                                                                                                                                                                                                      +77
                                                                                                                                                                                                                                      +78
                                                                                                                                                                                                                                      +79
                                                                                                                                                                                                                                      +80
                                                                                                                                                                                                                                      +81
                                                                                                                                                                                                                                      +82
                                                                                                                                                                                                                                      +83
                                                                                                                                                                                                                                      +84
                                                                                                                                                                                                                                      +85
                                                                                                                                                                                                                                      +86
                                                                                                                                                                                                                                      +87
                                                                                                                                                                                                                                      +88
                                                                                                                                                                                                                                      +89
                                                                                                                                                                                                                                      +90
                                                                                                                                                                                                                                      +91
                                                                                                                                                                                                                                      +92
                                                                                                                                                                                                                                      +93
                                                                                                                                                                                                                                      # press buttons to change the color of the NeoPixels
                                                                                                                                                                                                                                      +import utime
                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                      +from neopixel import Neopixel
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +NUMBER_PIXELS = 2
                                                                                                                                                                                                                                      +STATE_MACHINE = 0
                                                                                                                                                                                                                                      +LED_PIN = 18
                                                                                                                                                                                                                                      +BUTTON_A_PIN = 20
                                                                                                                                                                                                                                      +BUTTON_B_PIN = 21
                                                                                                                                                                                                                                      +# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler
                                                                                                                                                                                                                                      +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                                      +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB")
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# Color RGB values
                                                                                                                                                                                                                                      +red = (255, 0, 0)
                                                                                                                                                                                                                                      +orange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                                                      +yellow = (255, 150, 0)
                                                                                                                                                                                                                                      +green = (0, 255, 0)
                                                                                                                                                                                                                                      +blue = (0, 0, 255)
                                                                                                                                                                                                                                      +cyan = (0, 255, 255)
                                                                                                                                                                                                                                      +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                                                      +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                                                      +white = (255, 255, 255)
                                                                                                                                                                                                                                      +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white')
                                                                                                                                                                                                                                      +num_colors = len(color_names)
                                                                                                                                                                                                                                      +colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# color index into colors list
                                                                                                                                                                                                                                      +neopixel_a = 0
                                                                                                                                                                                                                                      +neopixel_b = 0
                                                                                                                                                                                                                                      +# set to be 1 to 100 for percent brightness
                                                                                                                                                                                                                                      +strip.brightness(100)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +button_presses = 0 # the count of times the button has been pressed
                                                                                                                                                                                                                                      +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail
                                                                                                                                                                                                                                      +button_a = machine.Pin(BUTTON_A_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                      +button_b = machine.Pin(BUTTON_B_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                                                      +def button_pressed_handler(pin):
                                                                                                                                                                                                                                      +    global button_presses, last_time, num_colors, neopixel_a, neopixel_b
                                                                                                                                                                                                                                      +    new_time = utime.ticks_ms()
                                                                                                                                                                                                                                      +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                                      +    if (new_time - last_time) > 200:
                                                                                                                                                                                                                                      +        # this should be pin.id but it does not work
                                                                                                                                                                                                                                      +        button_presses += 1
                                                                                                                                                                                                                                      +        if '20' in str(pin):
                                                                                                                                                                                                                                      +            neopixel_a +=1
                                                                                                                                                                                                                                      +            if neopixel_a > num_colors - 1:
                                                                                                                                                                                                                                      +                neopixel_a = 0 
                                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                                      +            neopixel_b +=1
                                                                                                                                                                                                                                      +            if neopixel_b > num_colors - 1:
                                                                                                                                                                                                                                      +                neopixel_b = 0 
                                                                                                                                                                                                                                      +        last_time = new_time
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# now we register the handler function when the button is pressed
                                                                                                                                                                                                                                      +button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                      +button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +# This is for only printing when a new button press count value happens
                                                                                                                                                                                                                                      +old_presses = 0
                                                                                                                                                                                                                                      +print('Running NeoPixel Button Lab')
                                                                                                                                                                                                                                      +strip.set_pixel(0, (4,5,5))
                                                                                                                                                                                                                                      +strip.set_pixel(1, (4,5,5))
                                                                                                                                                                                                                                      +strip.show()
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +def main():
                                                                                                                                                                                                                                      +    global button_presses, old_presses, colors, neopixel_a, neopixel_b
                                                                                                                                                                                                                                      +    while True:
                                                                                                                                                                                                                                      +        # only print on change in the button_presses value
                                                                                                                                                                                                                                      +        if button_presses != old_presses:
                                                                                                                                                                                                                                      +            print(button_presses)
                                                                                                                                                                                                                                      +            print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a)
                                                                                                                                                                                                                                      +            print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b)
                                                                                                                                                                                                                                      +            strip.set_pixel(0, colors[neopixel_a])
                                                                                                                                                                                                                                      +            strip.set_pixel(1, colors[neopixel_b])
                                                                                                                                                                                                                                      +            strip.show()
                                                                                                                                                                                                                                      +            old_presses = button_presses
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +try:
                                                                                                                                                                                                                                      +    main()
                                                                                                                                                                                                                                      +except KeyboardInterrupt:
                                                                                                                                                                                                                                      +    print('Got ctrl-c')
                                                                                                                                                                                                                                      +finally:
                                                                                                                                                                                                                                      +    # Cleanup code
                                                                                                                                                                                                                                      +    print('Turning off NeoPixels')
                                                                                                                                                                                                                                      +    strip.set_pixel(0, (0,0,0))
                                                                                                                                                                                                                                      +    strip.set_pixel(1, (0,0,0))
                                                                                                                                                                                                                                      +    strip.show()
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                      + NeoPixel Lab +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                      + Sound Lab +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/05-sound-lab/index.html b/kits/maker-pi-rp2040/05-sound-lab/index.html new file mode 100644 index 000000000..2fd755186 --- /dev/null +++ b/kits/maker-pi-rp2040/05-sound-lab/index.html @@ -0,0 +1,1945 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Sound Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + Sound Lab + + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                          + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                            + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + Sound Lab + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                          • + + + + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                        Play Mario on MicroPython

                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                        This program will play the theme music from the Mario video game.

                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                                        +20
                                                                                                                                                                                                                                        +21
                                                                                                                                                                                                                                        +22
                                                                                                                                                                                                                                        +23
                                                                                                                                                                                                                                        +24
                                                                                                                                                                                                                                        +25
                                                                                                                                                                                                                                        +26
                                                                                                                                                                                                                                        +27
                                                                                                                                                                                                                                        +28
                                                                                                                                                                                                                                        +29
                                                                                                                                                                                                                                        +30
                                                                                                                                                                                                                                        +31
                                                                                                                                                                                                                                        +32
                                                                                                                                                                                                                                        +33
                                                                                                                                                                                                                                        +34
                                                                                                                                                                                                                                        +35
                                                                                                                                                                                                                                        +36
                                                                                                                                                                                                                                        +37
                                                                                                                                                                                                                                        +38
                                                                                                                                                                                                                                        +39
                                                                                                                                                                                                                                        from machine import Pin, PWM
                                                                                                                                                                                                                                        +from utime import sleep
                                                                                                                                                                                                                                        +buzzer = PWM(Pin(22))
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +tones = {
                                                                                                                                                                                                                                        +"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46,
                                                                                                                                                                                                                                        +"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65,
                                                                                                                                                                                                                                        +"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98,
                                                                                                                                                                                                                                        +"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139,
                                                                                                                                                                                                                                        +"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185,
                                                                                                                                                                                                                                        +"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311,
                                                                                                                                                                                                                                        +"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698,
                                                                                                                                                                                                                                        +"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661,
                                                                                                                                                                                                                                        +"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520,
                                                                                                                                                                                                                                        +"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978
                                                                                                                                                                                                                                        +}
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"]
                                                                                                                                                                                                                                        +mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6",
                                                                                                                                                                                                                                        +         0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7",
                                                                                                                                                                                                                                        +         0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0,
                                                                                                                                                                                                                                        +         "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0]
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +def playtone(frequency):
                                                                                                                                                                                                                                        +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                                        +    buzzer.freq(frequency)
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +def bequiet():
                                                                                                                                                                                                                                        +    buzzer.duty_u16(0)
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +def playsong(mysong):
                                                                                                                                                                                                                                        +    for i in range(len(mysong)):
                                                                                                                                                                                                                                        +        if (mysong[i] == "P" or mysong[i] == 0 ):
                                                                                                                                                                                                                                        +            bequiet()
                                                                                                                                                                                                                                        +        else:
                                                                                                                                                                                                                                        +            playtone(tones[mysong[i]])
                                                                                                                                                                                                                                        +        sleep(0.3)
                                                                                                                                                                                                                                        +    bequiet()
                                                                                                                                                                                                                                        +playsong(mario)
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                        + Button Lab +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                        + Up/Down Mode Lab +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/06-up-down-lab/index.html b/kits/maker-pi-rp2040/06-up-down-lab/index.html new file mode 100644 index 000000000..0f827f9d6 --- /dev/null +++ b/kits/maker-pi-rp2040/06-up-down-lab/index.html @@ -0,0 +1,2159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Up/Down Mode Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + Up/Down Mode Lab + + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                            + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                                              + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Up/Down Mode Lab + + + + + + + +
                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                • + + + Full Program + + + +
                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                            • + + + + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                          • + + + Full Program + + + +
                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                          Up Down Mode Lab

                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                          In this lab, we will combine the two buttons with the blue LEDs, the NeoPixels and the buzzer labs. The +We will make the LED, NeoPixels and sound all change for each button press. You will be able to up +and down the color spectrum and the sound frequency.

                                                                                                                                                                                                                                          + + +

                                                                                                                                                                                                                                          We will start with the material from our button lab. We will create two functions that will be triggered by the +two buttons. One will increment a counter (add one) and the other will decrement the counter (subtract 1). By pressing one of the two buttons you will cycle through the modes of the program.

                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                          Mode Cycle Diagram

                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                          The diagram has eight different modes. The default mode is usually mode=0. When you press the left button the mode will increase by one. The NeoPixels will change from red to orange. Pressing the left button will increase the mode by one going to the orange mode. Pressing the right button will subtract one from the mode going from mode 1 (orange) back to model 0 (red).

                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                          Within our Interrupt Request Handler (IRQ) function we will also have to add two lines to deal with the wrap around logic like this:

                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          1
                                                                                                                                                                                                                                          +2
                                                                                                                                                                                                                                          +3
                                                                                                                                                                                                                                                  # wrap around to first mode
                                                                                                                                                                                                                                          +        if mode >= mode_count: mode = 0
                                                                                                                                                                                                                                          +        if mode < 0: mode = mode_count - 1
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                          Full Program

                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                          +  2
                                                                                                                                                                                                                                          +  3
                                                                                                                                                                                                                                          +  4
                                                                                                                                                                                                                                          +  5
                                                                                                                                                                                                                                          +  6
                                                                                                                                                                                                                                          +  7
                                                                                                                                                                                                                                          +  8
                                                                                                                                                                                                                                          +  9
                                                                                                                                                                                                                                          + 10
                                                                                                                                                                                                                                          + 11
                                                                                                                                                                                                                                          + 12
                                                                                                                                                                                                                                          + 13
                                                                                                                                                                                                                                          + 14
                                                                                                                                                                                                                                          + 15
                                                                                                                                                                                                                                          + 16
                                                                                                                                                                                                                                          + 17
                                                                                                                                                                                                                                          + 18
                                                                                                                                                                                                                                          + 19
                                                                                                                                                                                                                                          + 20
                                                                                                                                                                                                                                          + 21
                                                                                                                                                                                                                                          + 22
                                                                                                                                                                                                                                          + 23
                                                                                                                                                                                                                                          + 24
                                                                                                                                                                                                                                          + 25
                                                                                                                                                                                                                                          + 26
                                                                                                                                                                                                                                          + 27
                                                                                                                                                                                                                                          + 28
                                                                                                                                                                                                                                          + 29
                                                                                                                                                                                                                                          + 30
                                                                                                                                                                                                                                          + 31
                                                                                                                                                                                                                                          + 32
                                                                                                                                                                                                                                          + 33
                                                                                                                                                                                                                                          + 34
                                                                                                                                                                                                                                          + 35
                                                                                                                                                                                                                                          + 36
                                                                                                                                                                                                                                          + 37
                                                                                                                                                                                                                                          + 38
                                                                                                                                                                                                                                          + 39
                                                                                                                                                                                                                                          + 40
                                                                                                                                                                                                                                          + 41
                                                                                                                                                                                                                                          + 42
                                                                                                                                                                                                                                          + 43
                                                                                                                                                                                                                                          + 44
                                                                                                                                                                                                                                          + 45
                                                                                                                                                                                                                                          + 46
                                                                                                                                                                                                                                          + 47
                                                                                                                                                                                                                                          + 48
                                                                                                                                                                                                                                          + 49
                                                                                                                                                                                                                                          + 50
                                                                                                                                                                                                                                          + 51
                                                                                                                                                                                                                                          + 52
                                                                                                                                                                                                                                          + 53
                                                                                                                                                                                                                                          + 54
                                                                                                                                                                                                                                          + 55
                                                                                                                                                                                                                                          + 56
                                                                                                                                                                                                                                          + 57
                                                                                                                                                                                                                                          + 58
                                                                                                                                                                                                                                          + 59
                                                                                                                                                                                                                                          + 60
                                                                                                                                                                                                                                          + 61
                                                                                                                                                                                                                                          + 62
                                                                                                                                                                                                                                          + 63
                                                                                                                                                                                                                                          + 64
                                                                                                                                                                                                                                          + 65
                                                                                                                                                                                                                                          + 66
                                                                                                                                                                                                                                          + 67
                                                                                                                                                                                                                                          + 68
                                                                                                                                                                                                                                          + 69
                                                                                                                                                                                                                                          + 70
                                                                                                                                                                                                                                          + 71
                                                                                                                                                                                                                                          + 72
                                                                                                                                                                                                                                          + 73
                                                                                                                                                                                                                                          + 74
                                                                                                                                                                                                                                          + 75
                                                                                                                                                                                                                                          + 76
                                                                                                                                                                                                                                          + 77
                                                                                                                                                                                                                                          + 78
                                                                                                                                                                                                                                          + 79
                                                                                                                                                                                                                                          + 80
                                                                                                                                                                                                                                          + 81
                                                                                                                                                                                                                                          + 82
                                                                                                                                                                                                                                          + 83
                                                                                                                                                                                                                                          + 84
                                                                                                                                                                                                                                          + 85
                                                                                                                                                                                                                                          + 86
                                                                                                                                                                                                                                          + 87
                                                                                                                                                                                                                                          + 88
                                                                                                                                                                                                                                          + 89
                                                                                                                                                                                                                                          + 90
                                                                                                                                                                                                                                          + 91
                                                                                                                                                                                                                                          + 92
                                                                                                                                                                                                                                          + 93
                                                                                                                                                                                                                                          + 94
                                                                                                                                                                                                                                          + 95
                                                                                                                                                                                                                                          + 96
                                                                                                                                                                                                                                          + 97
                                                                                                                                                                                                                                          + 98
                                                                                                                                                                                                                                          + 99
                                                                                                                                                                                                                                          +100
                                                                                                                                                                                                                                          +101
                                                                                                                                                                                                                                          +102
                                                                                                                                                                                                                                          +103
                                                                                                                                                                                                                                          +104
                                                                                                                                                                                                                                          +105
                                                                                                                                                                                                                                          +106
                                                                                                                                                                                                                                          +107
                                                                                                                                                                                                                                          +108
                                                                                                                                                                                                                                          +109
                                                                                                                                                                                                                                          +110
                                                                                                                                                                                                                                          # Mode Up/Down Lab
                                                                                                                                                                                                                                          +# Change a mode using the buttons on the Maker Pi RP2040 board
                                                                                                                                                                                                                                          +# Changes the NeoPixel color and the blue GPIO status LEDs
                                                                                                                                                                                                                                          +import time
                                                                                                                                                                                                                                          +from machine import Pin, PWM
                                                                                                                                                                                                                                          +# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel
                                                                                                                                                                                                                                          +from neopixel import Neopixel
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +BUZZER_PORT = 22
                                                                                                                                                                                                                                          +buzzer = PWM(Pin(BUZZER_PORT))
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +NUMBER_PIXELS = 2
                                                                                                                                                                                                                                          +STATE_MACHINE = 0
                                                                                                                                                                                                                                          +NEOPIXEL_PIN = 18
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB
                                                                                                                                                                                                                                          +strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB")
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# have up to 13 that we can use
                                                                                                                                                                                                                                          +blue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]
                                                                                                                                                                                                                                          +number_leds = len(blue_led_pins)
                                                                                                                                                                                                                                          +led_ports = []
                                                                                                                                                                                                                                          +# create a list of the port pin object instances
                                                                                                                                                                                                                                          +for i in range(number_leds):
                                                                                                                                                                                                                                          +   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# Color RGB values as tuples - needs some Gamma corrections
                                                                                                                                                                                                                                          +red = (255, 0, 0)
                                                                                                                                                                                                                                          +orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow
                                                                                                                                                                                                                                          +yellow = (255, 150, 0)
                                                                                                                                                                                                                                          +green = (0, 255, 0)
                                                                                                                                                                                                                                          +blue = (0, 0, 255)
                                                                                                                                                                                                                                          +indigo = (75, 0, 130) # purple?
                                                                                                                                                                                                                                          +violet = (138, 43, 226) # mostly pink
                                                                                                                                                                                                                                          +cyan = (0, 255, 255)
                                                                                                                                                                                                                                          +lightgreen = (100, 255, 100)
                                                                                                                                                                                                                                          +white = (128, 128, 128) # not too bright
                                                                                                                                                                                                                                          +color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')
                                                                                                                                                                                                                                          +num_colors = len(color_names)
                                                                                                                                                                                                                                          +colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# set to be 1 to 100 for percent brightness
                                                                                                                                                                                                                                          +strip.brightness(100)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +mode = 0 # the default mode on powerup and reset
                                                                                                                                                                                                                                          +mode_count = len(color_names)
                                                                                                                                                                                                                                          +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +builtin_led = machine.Pin(25, Pin.OUT)
                                                                                                                                                                                                                                          +# Give our pins some logical names
                                                                                                                                                                                                                                          +next_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                          +previous_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# This function gets called every time the button is pressed.  The parameter "pin" is not used.
                                                                                                                                                                                                                                          +def button_pressed_handler(pin):
                                                                                                                                                                                                                                          +    global mode, last_time
                                                                                                                                                                                                                                          +    new_time = time.ticks_ms()
                                                                                                                                                                                                                                          +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                                          +    if (new_time - last_time) > 200:
                                                                                                                                                                                                                                          +        # this should be pin.id but it does not work
                                                                                                                                                                                                                                          +        if '20' in str(pin):
                                                                                                                                                                                                                                          +            mode +=1
                                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                                          +            mode -=1
                                                                                                                                                                                                                                          +        # wrap around to first mode
                                                                                                                                                                                                                                          +        if mode >= mode_count: mode = 0
                                                                                                                                                                                                                                          +        if mode < 0: mode = mode_count - 1
                                                                                                                                                                                                                                          +        last_time = new_time
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +def set_blue_led_mode(mode):
                                                                                                                                                                                                                                          +    global num_colors
                                                                                                                                                                                                                                          +    for i in range(0, num_colors):
                                                                                                                                                                                                                                          +        if i == mode:
                                                                                                                                                                                                                                          +            led_ports[i].high()
                                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                                          +            led_ports[i].low()
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# Register the handler function when either button is pressed
                                                                                                                                                                                                                                          +next_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                          +previous_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +#  Note the non-linear increases in frequency - note that some are louder
                                                                                                                                                                                                                                          +tone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]
                                                                                                                                                                                                                                          +def playtone(frequency):
                                                                                                                                                                                                                                          +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                                          +    buzzer.freq(frequency)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +def bequiet():
                                                                                                                                                                                                                                          +    buzzer.duty_u16(0)
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +# This is for only printing when a new button press count value happens
                                                                                                                                                                                                                                          +old_mode = -1
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +print('found ', mode_count, ' modes.')
                                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                                          +    # only print on change in the button_presses value
                                                                                                                                                                                                                                          +    if mode != old_mode:
                                                                                                                                                                                                                                          +        print('new mode:', mode, color_names[mode], tone_freq[mode])
                                                                                                                                                                                                                                          +        # get the color mode
                                                                                                                                                                                                                                          +        color = colors[mode]
                                                                                                                                                                                                                                          +        strip.set_pixel(0, color)
                                                                                                                                                                                                                                          +        strip.set_pixel(1, color)
                                                                                                                                                                                                                                          +        strip.show()
                                                                                                                                                                                                                                          +        set_blue_led_mode(mode)
                                                                                                                                                                                                                                          +        playtone(tone_freq[mode])
                                                                                                                                                                                                                                          +        time.sleep(.2)
                                                                                                                                                                                                                                          +        bequiet()
                                                                                                                                                                                                                                          +        old_mode = mode
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                          + Sound Lab +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                          + Introduction +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/kits/maker-pi-rp2040/index.html b/kits/maker-pi-rp2040/index.html new file mode 100644 index 000000000..4783130b2 --- /dev/null +++ b/kits/maker-pi-rp2040/index.html @@ -0,0 +1,2068 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + Introduction + + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                                              + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                + + + + + Maker Pi RP2040 + + + + + + + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Blue LED Lab + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + NeoPixel Lab + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Button Lab + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Sound Lab + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Up/Down Mode Lab + + + + +
                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                              • + + + + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                            • + + + Features + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + List of Labs + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                              • + + + Part 1: No Accessories Required Labs + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + Part 2: Motor and Servo Labs + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + Part 3: Sensor Labs + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + Part 4: Collision Avoidance Robot + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + Basis for a Low-Cost Robot Kit + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + Clearly Labeled Pin Numbers + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + Removing the Default CircuitPython + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + Flash Nuke + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + Easy Motor Testing Buttons + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                            Maker Pi RP2040 MicroPython Robotics Kit

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            The Maker Pi PR2040 kit from Cytron Technologies is a $9.90 US kit that is designed to simplify learning robotics using the RP2040 chip. It became available in April of 2021, but demand has been very high and it is out-of-stock on many retailers sites. We can understand this. The Maker Pi PR2040 is the most powerful robotics board we have ever seen for under $10!

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Maker Pi RP2040 Kit

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            The photo above is our base robot kit. It includes the Maker Pi RP2040 board mounted on a standards Smart Car chassis. The image above shows the Time-of-flight distance sensor mounted in the front below the chassis. Note that the batteries are mounted on the bottom of the robot.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Below is the top view of the Cytron Maker Pi RP2040 robotics board.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Maker Pi RP2040 Top View

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Features

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            All our robots are built around a RP2040 and a motor driver with a few low-cost sensors and displays. With the exception of the OLED display, this board packs in a huge number of features for a low cost of $9.90.

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            • Power status LED (green)
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • On/off switch
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 13 blue LEDs to show status on GP pins 0,1,2,3,4,5,6,16,17,26,27 and 28
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 2 WS2812B RGB LEDs connected to GP18
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • LiPo Battery Connector
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Micro USB Port (use for powering and programming)
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Reset button
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Boot button
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Momentary press buttons on ports GP20 and GP21
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 2 Motor drivers. Motor A is controlled by GP8 and GP10 and motor B is controlled by GP9 and GP11.
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 4 motor test buttons for testing motors A and B, forward and backward
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 4 red motor status LEDs buttons for displaying motors A and B, forward and backward
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 7 Grove Ports on GPs 1:0,1; 2:2,3; 3:4,5; 4:16,17; 5:6,26; 6:26,27 and 7:7,28
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 4 servo connectors on ports GP12, GP13, GP14 and GP15
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Piezo buzzer on port GP22
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • On/Off switch on GP22 which can be used to mute the sound
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Phillips head screwdriver that works on the header pins - really convenient for students!
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 4 Grove Connectors
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Rubber mounting feet
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Pins numbers clearly labeled both on top and bottom of the board
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Large area on bottom of the board for students to write their name
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            List of Labs

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Part 1: No Accessories Required Labs

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            These labs don't need anything except the Maker Pi RP2040 board.

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            1. Blue LED Lab - make the blue GPIO status LEDs show cool patterns
                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                            3. NeoPixel Lab - make the two NeoPixel each display many colors
                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                            5. Button Lab - make the two buttons change the state of system
                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                            7. Sound Lab - make the Piezoelectric Buzzer create sounds
                                                                                                                                                                                                                                            8. +
                                                                                                                                                                                                                                            9. Up Down Mode Lab - make the buttons change the LEDs, NeoPixels and Sound
                                                                                                                                                                                                                                            10. +
                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Part 2: Motor and Servo Labs

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            These labs require additional parts such as DC hobby motors and servos

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            1. Motor Connection Lab - make two motors turn forward and in reverse
                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                            3. Up/Down Motor Speed Lab - change the speed as you change the mode
                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                            5. Servo Lab - control the direction of a 108% servo motor. Calibrate the end angles and sweep the direction back and forth.
                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Part 3: Sensor Labs

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            There are literally hundreds of sensors that have Grove connectors on them. In addition, we can purchase Grove connectors for as low as 30 cents each. Any other sensors with male pins can be easily connected with these 38 cent connectors with female Dupont jumper connectors. Classrooms with a large collection of these sensors can allow students to try new sensors and outputs without needing a breadboard or soldering. We will focus initially on two sensors we will use for our collision avoidance robot. We prefer the Time-of-Flight sensor because it uses a standard I2C interface and thus could share the I2C bus with other devices.

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            1. Time of Flight Distance Sensor Lab - measure the distance to an object
                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                            3. Ultrasonic Ping Distance Sensor - the classic low-cost ultrasonic distance sensor but now it works on a 3.3 volt power! (TBD)
                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                            5. Time of Flight Sound Lab - sound pitch changes with distance
                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Part 4: Collision Avoidance Robot

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            1. Collision Avoidance Robot - this lab joins our motor and sensor labs with a SmartCar chassis to create a robot that avoids collisions.
                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                            3. Collision Robot with Modes - TBD
                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                            5. Adjustable Collision Avoidance - the adjusta bot! TBD
                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                            7. Adding a display
                                                                                                                                                                                                                                            8. +
                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Basis for a Low-Cost Robot Kit

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            When this kit is combined with a standard 2 Wheel Drive Smart Car Chassis and a distance sensor it becomes a great low-cost way of getting started with Python and robots.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Clearly Labeled Pin Numbers

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            One of the biggest disadvantages of the Raspberry Pi Pico is the fact that pin labels are NOT visible when it is mounted on a breadboard. We have to take the Pico out of the breadboard to read the pin numbers on the bottom of the board. A much better design would be to follow the best practices and put the labels on the top of the board where they are visible. This is clearly done on the Maker Pi RP2040 board!

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Maker Pi RP2040 Pin Labels

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Note the pin labels, GND, 3.3V, GP0 and GP1 are clearly printed on the top of the board.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Maker Pi Bottom View

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Note the circuit in the upper right corner displays how you can use the analog input port to read the battery level of the robot.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Removing the Default CircuitPython

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Cytron Technologies has a wonderful YouTube videos on how to program the Maker Pi RP2040 using MicroPython. Unfortunately, this board does NOT come with our standard MicroPython loaded! :-O It uses the non-standard Adafruit CircuitPython that is incompatible with most MicroPython programs being used today. This is a sad state of affairs that confuses our students and makes it difficult to share code and libraries for MicroPython. According to Google trends, over the last 12 months for worldwide searches, MicroPython has almost five time the interest of CircuitPython. Preloading the board with CircuitPython sends a very confusing message to the marketplace.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Flash Nuke

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            I want to make sure that my RP2040 was starting out with a clean image. I downloaded the flash_nuke.uf2 file to remove the default CircuitPython runtime and all the related files.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Note that the board must be fully powered down after this load for it to work. I had 4 AA batteries connected to the VIN screw headers, so it was not resetting correctly and the reset was not working until I disconnected the batteries.

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            The latests MicroPython runtimes are here

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            Easy Motor Testing Buttons

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            One of the things I love about this board is how incredibly easy it is for students to test their motors. The board provides four very convenient motor test buttons right on the board. By pressing each one you can make both motors go forward and backwards. This is a great way for students to learn about how we can generate PWM signals to simulate these four buttons. Whoever design this board clearly had their students in mind!

                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                            References

                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                            • Link on Box
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • GitHub Link
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Cytron Maker Pi RP2040 Product Page
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Cytron Maker Pi RP2040 Datasheet on Google Docs
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Digi-Key Cytron Maker Pi RP2040 reseller
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Amazon Listing - no availability as of Aug. 15th 2021
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Adafruit Cytron Maker Pi RP2040 reseller - out of stock as of Aug. 15th 2021
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • 1300 mah battery
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Ultrasonic Sensor Video on YouTube
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            • Circuit Schematic
                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                            + Introduction +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                            + Getting Started +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/docs/kits/maker-pi-rp2040/maker-pi-rp2040-schematic.pdf b/kits/maker-pi-rp2040/maker-pi-rp2040-schematic.pdf similarity index 100% rename from docs/kits/maker-pi-rp2040/maker-pi-rp2040-schematic.pdf rename to kits/maker-pi-rp2040/maker-pi-rp2040-schematic.pdf diff --git a/kits/microbit/index.html b/kits/microbit/index.html new file mode 100644 index 000000000..4691882ee --- /dev/null +++ b/kits/microbit/index.html @@ -0,0 +1,1963 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroBit - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + MicroBit + + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + MicroBit + + + + + + + +
                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                  • + + + Side-By-Side Comparision + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + Sample Sources + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + Microcenter + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + SparkFun + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                • + + + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                              • + + + Side-By-Side Comparision + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + Sample Sources + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + Microcenter + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + SparkFun + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                              MicroBit

                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              Although the BBC MicroBit is a good educational product for learning MicroPython, we don't use it in our MicroPython courses for the following reason:

                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                              1. Price - The current price on sites like Amazon is around $22. We can get the Raspberry Pi Pico for $4.
                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                              3. Availability - MicroBits have not been available due to shortages of chips that it needs.
                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                              5. Memory - The MicroBit only has 32KB of RAM. The Pico has 256K. We need this extra RAM for our OLED display labs.
                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                              7. Breadboard - We use simple, standardized, easy-to-upgrade breadboards in our classes. This makes it easy to upgrade our microcontrollers and promotes higher sustainability. We also believe that teaching breadboarding skills is critical for future projects.
                                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                                              9. Expandability - we like the ability to expand our base labs to include many low costs sensors
                                                                                                                                                                                                                                              10. +
                                                                                                                                                                                                                                              11. Multi-Core - we want to be able to teach multi-core coding in our classrooms. Because the MicroBit only has a single core this is not possible on the MicroBit. The Raspberry Pi Pico has two cores. Many projects use one core for monitoring the sensors and another core for doing analysis and updating the display.
                                                                                                                                                                                                                                              12. +
                                                                                                                                                                                                                                              13. Pulse Width Modulation Channels - The MicroBit only has 3 PWM channels. We need a minimum of 4 to drive our robots.
                                                                                                                                                                                                                                              14. +
                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              Side-By-Side Comparision

                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              Feature NameMicroBit v2Raspberry Pi PicoNotes
                                                                                                                                                                                                                                              Price$22$4The Pico "W" with wireless is $6
                                                                                                                                                                                                                                              BreadboardNoYesAllows us to teach breadboarding skills
                                                                                                                                                                                                                                              RAM32MB256MBWe need around 100MB to support our 128x64 OLED frame buffers
                                                                                                                                                                                                                                              Flash2MB512MBWe use extra flash to store hundreds of programs, images and sounds
                                                                                                                                                                                                                                              SensorsTemp,Accelerometers,Compass,Light,TouchTempFor about $5 we can add these sensors to the Pico
                                                                                                                                                                                                                                              ProcessorARM Cortex-M4Dual-core Arm Cortex-M0+The M4 has better support for DSP and floating point
                                                                                                                                                                                                                                              LEDs251We use 8X8 LEDs and NeoPixels in our labs to create similar displays
                                                                                                                                                                                                                                              Block ProgrammingMicrosoft MakeCodeBIPESBlock coding is great for younger students that don't have strong keyboarding skills
                                                                                                                                                                                                                                              GPIOs2026This has not been a concern. None of our labs need over 20 GPIOs
                                                                                                                                                                                                                                              ADCs53Also not a concern. None of our labs need more that 3 Analog to Digital converters that run concurrently
                                                                                                                                                                                                                                              Serial Bus1 I2C, 1 SPI2x UART, 2x I2C, 2x SPI, up to 16 PWM channels
                                                                                                                                                                                                                                              Pulse Width Modulation316We need 4 PWM to drive our robots (a forward and back for each motor)
                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              Sample Sources

                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              Microcenter

                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                              • MicroCenter MicroBit Go Bundle for $22.92 - includes USB cable and battery pack
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              SparkFun

                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                              • Pico for $3.99
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              • Microbit for $22
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              • Breakout Board for Breadboards $7
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              References

                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                              • Cytron
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              • Pico:ed V2 - a RP2040 in MicroBit Form Factor
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              • Pico:ed $12
                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                              + Buttons +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                              + RFID RC522 +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/kits/neopixel/01-getting-started/index.html b/kits/neopixel/01-getting-started/index.html new file mode 100644 index 000000000..ad0056810 --- /dev/null +++ b/kits/neopixel/01-getting-started/index.html @@ -0,0 +1,1825 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Getting Started - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + Getting Started + + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                                                  + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                                    + + + + + NeoPixel + + + + + + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                      + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + Getting Started + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Simple Patterns + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Buttons + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Rotary Neopixel + + + + +
                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                                  • + + + + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                Getting Started with the NeoPixel Kit

                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                Your kit should have several parts. Place them all on a table and hook them up. When you power on the kit with your USB cable the default main.py program will be running.

                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                + Introduction +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                + Simple Patterns +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/kits/neopixel/02-simple-patterns/index.html b/kits/neopixel/02-simple-patterns/index.html new file mode 100644 index 000000000..fa2f4e0c6 --- /dev/null +++ b/kits/neopixel/02-simple-patterns/index.html @@ -0,0 +1,1919 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Simple Patterns - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + Simple Patterns + + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                                    + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                                      + + + + + NeoPixel + + + + + + + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + Simple Patterns + + + + + + + +
                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                        • + + + Blink + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        • + + + Wipe + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        • + + + Move Pixel + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Buttons + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Rotary Neopixel + + + + +
                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                                    • + + + + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                  • + + + Blink + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + Wipe + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  • + + + Move Pixel + + + +
                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                  NeoPixel Simple Patterns

                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                  Blink

                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                  Wipe

                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                  Move Pixel

                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                  + Getting Started +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                  + Buttons +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/kits/neopixel/03-buttons/index.html b/kits/neopixel/03-buttons/index.html new file mode 100644 index 000000000..00c26d578 --- /dev/null +++ b/kits/neopixel/03-buttons/index.html @@ -0,0 +1,1985 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Buttons - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + Buttons + + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                                      + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                                        + + + + + NeoPixel + + + + + + + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Simple Patterns + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Buttons + + + + + + + +
                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                          • + + + Review of Button Basics + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Working with Two Buttons + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Changing Color With Buttons + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Using Modes + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Changing Patterns With Buttons + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Changing Color and Pattern + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Rotary Neopixel + + + + +
                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                                      • + + + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                    • + + + Review of Button Basics + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    • + + + Working with Two Buttons + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    • + + + Changing Color With Buttons + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    • + + + Using Modes + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    • + + + Changing Patterns With Buttons + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    • + + + Changing Color and Pattern + + + +
                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                    NeoPixel Button Lab

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Review of Button Basics

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Button Basics

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Working with Two Buttons

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Changing Color With Buttons

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Using Modes

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Our LED kit can run a single "main" loop forever. But we often want to have the main loop run a different subprogram. Each subprogram can be triggered by pressing a button. The button will update a variable and the main loop will use this variable to redirect the main to the appropriate function.

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    The mode variable is traditionally used to store the current subprogram being run. You are not limited to a single mode. You can also have modes within modes.

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Mode Cycle Diagram

                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                    1. Using a buttons to advance a mode
                                                                                                                                                                                                                                                    2. +
                                                                                                                                                                                                                                                    3. Using a two buttons to move to the next and previous mode
                                                                                                                                                                                                                                                    4. +
                                                                                                                                                                                                                                                    5. Using two modes - one mode or each button
                                                                                                                                                                                                                                                    6. +
                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Changing Patterns With Buttons

                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                    Changing Color and Pattern

                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                    + Simple Patterns +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                    + MicroBit +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/kits/neopixel/04-rotary-neopixel/index.html b/kits/neopixel/04-rotary-neopixel/index.html new file mode 100644 index 000000000..279466406 --- /dev/null +++ b/kits/neopixel/04-rotary-neopixel/index.html @@ -0,0 +1,1290 @@ + + + + + + + + + + + + + + + + + + + + + + + Rotary NeoPixel - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + Rotary NeoPixel + + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                      Rotary NeoPixel

                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                      In this lab, we use a rotary encoder to change which pixel is turned on. +Turning the knob will appear to move the pixel.

                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/kits/neopixel/index.html b/kits/neopixel/index.html new file mode 100644 index 000000000..f5d07f818 --- /dev/null +++ b/kits/neopixel/index.html @@ -0,0 +1,1866 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + Introduction + + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                          + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                                            + + + + + NeoPixel + + + + + + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Getting Started + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Simple Patterns + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Buttons + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Rotary Neopixel + + + + +
                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                                          • + + + + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                        • + + + Sample Labs + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        • + + + Getting Started + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        • + + + + + + +
                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                        NeoPixel Kit

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        NeoPixel Kit

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        This is a low-cost (under $10) kit that we use in many of our classes. It contains the following parts:

                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                        1. Raspberry Pi Pico ($4)
                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                        3. 1/2 size breadboard ($2)
                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                        5. LED Strip (WS2811b) ($3) - these come in many lengths from 8 to 60 pixels
                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                        7. Two momentary push buttons (20 cents)
                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                        9. USB cable (Micro-B to A)
                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        These lessons will assume you have these parts and can connect up to the Pico to your laptop using a USB cable. If you have a Mac with a USB-C connector you may need to provide a USB-C to USB-A adaptor.

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        Sample Labs

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        We start with the sample code in the Basics/NeoPixel area.

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        We then show how you can load full programs. Here is the source code:

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        NeoPixel Samples Source Code

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        Getting Started

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        Getting Started Lab

                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                        + Larson Scanner Pumpkin +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                        + Getting Started +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/kits/rfid-rc522/index.html b/kits/rfid-rc522/index.html new file mode 100644 index 000000000..d25872422 --- /dev/null +++ b/kits/rfid-rc522/index.html @@ -0,0 +1,1960 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + RFID RC522 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + RFID RC522 + + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                                            + + + + + Project Kits + + + + + + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi RP2040 Robot + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Maker Pi Pico + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Maker Nano RP2040 + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Larson Scanner + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + NeoPixel + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + MicroBit + + + + +
                                                                                                                                                                                                                                                            • + + + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                          • + + + Pinout + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                            • + + + Wires at the RC522 + + + +
                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                            • + + + Wires at the Pico + + + +
                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Config File + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + Reader + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                          RFIG Reader RC-522

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          The RC-522 is a popular RFID reader that has strong support in the MicroPython +community.

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Pinout

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          NAMEPICO GPIOCOLOR
                                                                                                                                                                                                                                                          SDA1Yellow
                                                                                                                                                                                                                                                          SCK2Orange
                                                                                                                                                                                                                                                          MOSI4Purple
                                                                                                                                                                                                                                                          MISO3Blue
                                                                                                                                                                                                                                                          IRQ7Brown
                                                                                                                                                                                                                                                          GNDGNDBlack
                                                                                                                                                                                                                                                          RST0Green
                                                                                                                                                                                                                                                          3.3V3.3v OutRed
                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Wires at the RC522

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Wires at the Pico

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Config File

                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Place this in the config.py

                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                          # reader = MFRC522(spi_id=0, sck=2, miso=4, mosi=3, cs=1, rst=0)
                                                                                                                                                                                                                                                          +SPI_ID = 0
                                                                                                                                                                                                                                                          +RESET_PIN = 0 # Green OUT
                                                                                                                                                                                                                                                          +SDA_PIN = 1 # Yellow OUT but used a Chip Select CS 
                                                                                                                                                                                                                                                          +SCK_PIN = 2 # Orange OUT clock going from Pico to RC522
                                                                                                                                                                                                                                                          +MISO_PIN = 3 # Blue 
                                                                                                                                                                                                                                                          +MOSI_PIN = 4 # Purple
                                                                                                                                                                                                                                                          +IRQ_PIN = 7 # Brown, OUT but not used in the reader demo
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +# GND is Black
                                                                                                                                                                                                                                                          +# Red goes to 3.3v out
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          Reader

                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                                                          +28
                                                                                                                                                                                                                                                          +29
                                                                                                                                                                                                                                                          +30
                                                                                                                                                                                                                                                          +31
                                                                                                                                                                                                                                                          +32
                                                                                                                                                                                                                                                          +33
                                                                                                                                                                                                                                                          +34
                                                                                                                                                                                                                                                          +35
                                                                                                                                                                                                                                                          +36
                                                                                                                                                                                                                                                          +37
                                                                                                                                                                                                                                                          +38
                                                                                                                                                                                                                                                          +39
                                                                                                                                                                                                                                                          +40
                                                                                                                                                                                                                                                          +41
                                                                                                                                                                                                                                                          +42
                                                                                                                                                                                                                                                          +43
                                                                                                                                                                                                                                                          +44
                                                                                                                                                                                                                                                          +45
                                                                                                                                                                                                                                                          from mfrc522 import MFRC522
                                                                                                                                                                                                                                                          +import utime
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +def uidToString(uid):
                                                                                                                                                                                                                                                          +    mystring = ""
                                                                                                                                                                                                                                                          +    for i in uid:
                                                                                                                                                                                                                                                          +        mystring = "%02X" % i + mystring
                                                                                                                                                                                                                                                          +    return mystring
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +print("")
                                                                                                                                                                                                                                                          +print("Please place card on reader")
                                                                                                                                                                                                                                                          +print("")
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +PreviousCard = [0]
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +try:
                                                                                                                                                                                                                                                          +    while True:
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +        reader.init()
                                                                                                                                                                                                                                                          +        (stat, tag_type) = reader.request(reader.REQIDL)
                                                                                                                                                                                                                                                          +        #print('request stat:',stat,' tag_type:',tag_type)
                                                                                                                                                                                                                                                          +        if stat == reader.OK:
                                                                                                                                                                                                                                                          +            (stat, uid) = reader.SelectTagSN()
                                                                                                                                                                                                                                                          +            if uid == PreviousCard:
                                                                                                                                                                                                                                                          +                continue
                                                                                                                                                                                                                                                          +            if stat == reader.OK:
                                                                                                                                                                                                                                                          +                print("Card detected {}  uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid)))
                                                                                                                                                                                                                                                          +                defaultKey = [255,255,255,255,255,255]
                                                                                                                                                                                                                                                          +                reader.MFRC522_DumpClassic1K(uid, Start=0, End=64, keyA=defaultKey)
                                                                                                                                                                                                                                                          +                print("Done")
                                                                                                                                                                                                                                                          +                PreviousCard = uid
                                                                                                                                                                                                                                                          +            else:
                                                                                                                                                                                                                                                          +                pass
                                                                                                                                                                                                                                                          +        else:
                                                                                                                                                                                                                                                          +            PreviousCard=[0]
                                                                                                                                                                                                                                                          +        utime.sleep_ms(50)                
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +except KeyboardInterrupt:
                                                                                                                                                                                                                                                          +    pass
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                          References

                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                          • How To Electronics: Using RC522 RFID Reader Module with Raspberry Pi Pico
                                                                                                                                                                                                                                                          • +
                                                                                                                                                                                                                                                          • Dan J Perron Driver
                                                                                                                                                                                                                                                          • +
                                                                                                                                                                                                                                                          • Microcontrollers Lab Tutorial
                                                                                                                                                                                                                                                          • +
                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                          + MicroBit +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                          + Introduction +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/docs/kits/rfid-rc522/pico-wires.png b/kits/rfid-rc522/pico-wires.png similarity index 100% rename from docs/kits/rfid-rc522/pico-wires.png rename to kits/rfid-rc522/pico-wires.png diff --git a/docs/kits/rfid-rc522/rc522-pinout.png b/kits/rfid-rc522/rc522-pinout.png similarity index 100% rename from docs/kits/rfid-rc522/rc522-pinout.png rename to kits/rfid-rc522/rc522-pinout.png diff --git a/docs/kits/rfid-rc522/rc522-wires.png b/kits/rfid-rc522/rc522-wires.png similarity index 100% rename from docs/kits/rfid-rc522/rc522-wires.png rename to kits/rfid-rc522/rc522-wires.png diff --git a/micropython.code-workspace b/micropython.code-workspace deleted file mode 100644 index 0329da33b..000000000 --- a/micropython.code-workspace +++ /dev/null @@ -1,91 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ], - "settings": { - "cSpell.words": [ - "Adafruit", - "Ampy", - "Barchart", - "baudrate", - "bequiet", - "bitstream", - "BOTSEL", - "breadboarding", - "circuitpython", - "codehilite", - "coderdojo", - "Creary", - "Cylon", - "Cytron", - "Datasheet", - "debouncing", - "debuggings", - "Dupont", - "elif", - "Framebuffers", - "GPIO", - "hline", - "hyperparameters", - "ISRs", - "kiloohms", - "LEDs", - "linenums", - "LPCM", - "megaohms", - "Michaels", - "Micheals", - "Microcenter", - "microcontroller", - "Microcontroller", - "Micropython", - "microsite", - "microswitch", - "milliamps", - "minicom", - "mosi", - "mpremote", - "Neopixel", - "NEOPIXEL", - "neopixels", - "numpy", - "oled", - "OLED", - "OLEDs", - "outliner", - "Perron's", - "Phillips", - "photoresistor", - "Photosensor", - "pico", - "Piezo", - "pinout", - "playtone", - "pymdownx", - "Relu", - "REPL", - "RGBC", - "RPEL", - "Rshell", - "saleae", - "solderless", - "SSID", - "Stackable", - "superfences", - "Teachman", - "Thonny", - "transformative", - "TTGO", - "UART", - "urandom", - "utime", - "vals", - "Vilros", - "vline", - "waveshare" - ], - "editor.fontSize": 10 - } -} diff --git a/misc/30-colophon/index.html b/misc/30-colophon/index.html new file mode 100644 index 000000000..358f26248 --- /dev/null +++ b/misc/30-colophon/index.html @@ -0,0 +1,1335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Colophon - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + Colophon + + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + +
                                                                                                                                                                                                                                                            • + + + + + + + + + + + + Colophon + + + + + +
                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                            Colophon

                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                            We are mostly a group of unpaid volunteers without a large budget for distributed content management software. However, we still want to provide a great user experience for both our mentors and our students. So we use free open-source tools whenever we can. Here is how we built this site.

                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                            • Our content language is Markdown.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • We use Python Markdown to parse our content.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • We convert Markdown to HTML with mkdocs.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • Our user interface theme isMkdocs Material. We use an extensive number of Material user interface components.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • Our software version control system is git
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • Our site is hosted on GitHub page.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • We use standard code highlighting provided by the mkdocs codehilite extension.
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            • Our BY-NC-SA content license agreement is created by Creative Commons
                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                            We wish to acknowledge the work of everyone that contributes to open-source projects. Without these systems this work would not be possible.

                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                            If you would like to contribute lesson we welcome your contribution as a git pull request. You can read our CoderDojo Twin CitiesAuthoring Guide if you would like to help out.

                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                            + Contact +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/misc/contact/index.html b/misc/contact/index.html new file mode 100644 index 000000000..a45d0e9d8 --- /dev/null +++ b/misc/contact/index.html @@ -0,0 +1,1438 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Contact - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + Contact + + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Contact + + + + + + + +
                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                • + + + General Code Savvy Contact + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Contact for CoderDojo Twin Cities + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Specific questions on this repository + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                              • + + + General Code Savvy Contact + + + +
                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                              • + + + Contact for CoderDojo Twin Cities + + + +
                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                              • + + + Specific questions on this repository + + + +
                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                              Cybersecurity for Kids Contacts

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              General Code Savvy Contact

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              kidscode@codesavvy.org

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              Contact for CoderDojo Twin Cities

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              hello@coderdojotc.org

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              Specific questions on this repository

                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                              Dan McCreary

                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                              + Contributing +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                              + Colophon +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/misc/contributing/index.html b/misc/contributing/index.html new file mode 100644 index 000000000..7fc9cfee1 --- /dev/null +++ b/misc/contributing/index.html @@ -0,0 +1,1515 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Contributing - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + Contributing + + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Contributing + + + + + + + +
                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                  • + + + Contribution License + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Ways to Contribute + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Teaching Suggestions + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Lesson Structure + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Resources + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                • + + + Contribution License + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Ways to Contribute + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Teaching Suggestions + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Lesson Structure + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                • + + + Resources + + + +
                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                MicroPython Book Contributing Guide

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                The goal of this microsite is to provide MicroPython content to STEM educational programs around the world. We value inclusion and we love low-cost projects that promote STEM instruction in communities that don't have large budgets. We value a focus on instructional design that teaches computational thinking and uses evidence of the effective delivery of this content to underprivileged communities.

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                We welcome anyone that would like to add content to this microsite with the following guidelines:

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Contribution License

                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                1. Your content must be your own original content. We discourage copying bulk content from other sites without clear understanding of the copyrights that govern this content. We put a special focus on image attribution. Any images added must clearly state that the images are original content created by the author.
                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                3. You must agree to license your new original content to allow other teachers and mentors to reuse this content in their classrooms free of charge. We use Creative Commons Licenses Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) for all content in this microsite and other microsites managed by CoderDojo Twin Cities.
                                                                                                                                                                                                                                                                4. +
                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Under these terms teachers and mentors are free to:

                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • Share — copy and redistribute the material in any medium or format
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                • Adapt — remix, transform, and build upon the material
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                The licensor cannot revoke these freedoms as long as you follow the license terms. +Under the following terms:

                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • +

                                                                                                                                                                                                                                                                  Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                • +

                                                                                                                                                                                                                                                                  NonCommercial — You may not use the material for commercial purposes.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                • +

                                                                                                                                                                                                                                                                  ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                • +

                                                                                                                                                                                                                                                                  No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                • +
                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Ways to Contribute

                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                1. Start out by helping us proof-read our content and help us find typos, spelling, lack-of clarity, and missing content. As you learn the style of our lessons you will be better able to contribute new lessons that have a similar style
                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                3. You may submit pull requests to this site of if you are not familiar with this process, you can add a link to your content in an issue.
                                                                                                                                                                                                                                                                4. +
                                                                                                                                                                                                                                                                5. You may add an issue to our issues board here
                                                                                                                                                                                                                                                                6. +
                                                                                                                                                                                                                                                                7. You are welcome to participate by looking for open tasks and using GitHub workflows to take on tasks to completion.
                                                                                                                                                                                                                                                                8. +
                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Teaching Suggestions

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Avoid too much focus on building games that don't promote teaching computational thinking skills. Simple remote control robots might be fun, but sometime the fun of driving a robot around gets in the way of learning new concepts.

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Lesson Structure

                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                1. Try to begin each section or lesson with a kid-friendly image. This help readers quickly recall if they have visited this page before.
                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                3. If if it not obvious, include any prior knowledge that is required to understand a lesson in an Intended Audience or Prerequsites section.
                                                                                                                                                                                                                                                                4. +
                                                                                                                                                                                                                                                                5. Try to keep the introductory lessons in a section short and small. After you have introduce the core concepts you can integrate concepts from other areas.
                                                                                                                                                                                                                                                                6. +
                                                                                                                                                                                                                                                                7. Add a "Further Explorations" section to the end of each lesson +Include references to other sites or wikipedia articles that can be explored further.
                                                                                                                                                                                                                                                                8. +
                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Resources

                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                Please see our page on Teaching Computational Thinking.

                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                + References +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                + Contact +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/misc/glossary/index.html b/misc/glossary/index.html new file mode 100644 index 000000000..134a7cf5a --- /dev/null +++ b/misc/glossary/index.html @@ -0,0 +1,1977 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Glossary - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + Glossary + + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Glossary + + + + + + + +
                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                    • + + + Ampy + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Analog to Digital Converter + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Blit + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + BOOTSEL + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Castellated Edge + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Dupont Connectors + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + ESP32 + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Formatted Strings + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Framebuffer + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Interrupts + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + I2C + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + MicroPython + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + MPG Shell + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + OLED Display + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Raspberry Pi Foundation + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Raspberry Pi Pico + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Pico Pinout Diagram + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + PWM + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + RP2040 chip + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + rshell + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + SPI + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Thonny + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + UF2 File + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + Unicorn + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    • + + + See Also + + + +
                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                  • + + + Ampy + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Analog to Digital Converter + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Blit + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + BOOTSEL + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Castellated Edge + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Dupont Connectors + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + ESP32 + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Formatted Strings + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Framebuffer + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Interrupts + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + I2C + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + MicroPython + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + MPG Shell + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + OLED Display + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Raspberry Pi Foundation + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Raspberry Pi Pico + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Pico Pinout Diagram + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + PWM + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + RP2040 chip + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + rshell + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + SPI + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Thonny + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + UF2 File + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + Unicorn + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  • + + + See Also + + + +
                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                  Micropython Glossary of Terms

                                                                                                                                                                                                                                                                  + + +

                                                                                                                                                                                                                                                                  Ampy

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  An obsolete MicroPython support tool created by Adafruit but no longer supported.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Check out other MicroPython tools like rshell or mpfshell for more advanced interaction with boards.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Analog to Digital Converter

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A component that takes an analogue signal and changes it to a digital one.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Every ADC has two parameters, its resolution, measured in digital bits, and its channels, or how many analogue signals it can accept and convert at once.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Also know as: ADC
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Blit

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A special form of copy operation; it copies a rectangular area of pixels from one framebuffer to another. It is used in MicroPython when doing drawing to a display such as an OLED display.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  BOOTSEL

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A button on the pico that when pressed during power up will allow you to mount the device as a USB drive. You can then drag-and-drop any uf2 image file to reset or update the runtime libraries.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Also known as: Boot Selection
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Castellated Edge

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Plated through holes or vias located in the edges of a printed circuit board that make it easier to solder onto another circuit board.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The word "Castellated" means having grooves or slots on an edge and is derived from the turrets of a castle.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Dupont Connectors

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Pre-made low-cost used and used to connect breadboards to hardware such as sensors and displays.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The connectors are available in male and female ends and are typically sold in lengths of 10 or 20cm. They have a with a 2.54mm (100mill) pitch so they are easy to align with our standard breadboards. They are typically sold in a ribbon of mixed colors for around $2.00 US for 40 connectors.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Also known as: Jumper Wires
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Sample eBay Search for Jumper Wires
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  ESP32

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Typical costs for the ESP32 is are around $10 US on eBay.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Sample on eBay $5
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Sample on Amazon $11
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Sample on Sparkfun $21
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • ESP32 Quick Reference
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Sample eBay Search for ESP32 from $5 to $20
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Formatted Strings

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The ability to use a simplified syntax to format strings by added the letter "f" before the string. Values within curly braces are formatted from variables.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                  name = "Lisa"
                                                                                                                                                                                                                                                                  +age = 12
                                                                                                                                                                                                                                                                  +f"Hello, {name}. You are {age}."
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  returns

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                  Hello, Lisa. You are 12.
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Formatted string support was added to MicroPython in release 1.17. Most formats work except the date and time formats. For these we must write our own formatting functions.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Also known as: f-strings
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Also known as: Literal String Interpolation
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • From Python Enhancement Proposal: PEP 498
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Official Python documentation on string formatting
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • Link to Formatted Strings Docs: formatted strings
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • PyFormat library for formatting strings: PyFormat.info
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Framebuffer

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A region of your microcontroller RAM that stores a bitmap image of your display.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  For a 128X64 monochrome display this would be 128 * 64 = 8,192 bits or 1,024 bytes (1K). Color displays must store up to 8 bytes per color for each color (red, green and blue).

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Wikipedia page on Framebuffer
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • MicroPython Documentation on FrameBuffer +]
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Interrupts

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A type of signal used to pause a program and execute a different program. We +use interrupts to pause our program and execute a different program when a +button is pressed.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  I2C

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A communications protocol common in microcontroller-based systems, particularly for interfacing with sensors, memory devices and liquid crystal displays.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  I2C is similar to SPI, it's a synchronous protocol because it uses a clock line.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Also Known as: Inter-integrated Circuit
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  • See also: SPI
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  MicroPython

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A set of Python libraries and tools developed specifically for microcontrollers.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  MicroPython was originally developed by Damien George and first released in 2014. It includes many of the features of mainstream Python, while adding a range of new ones designed to take advantage of the facilities available on Raspberry Pi Pico and other microcontroller boards like the ESP32.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • See also: CircuitPython
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  MPG Shell

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A simple MicroPython shell based file explorer for ESP8266 and WiPy MicroPython based devices.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The shell is a helper for up/downloading files to the ESP8266 (over serial line and Websockets) and WiPy (serial line and telnet). It basically offers commands to list and upload/download files on the flash FS of the device.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  GitHub Repo for MPFShell

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  OLED Display

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  OLED (Organic polymer light emitting diode) dispays are small but bright displays with high contrast, low power and a wide viewing angle. We use these displays throughout our labs. The small displays are around 1" (diagonal) and only cost around $4 to $5. Larger 2.24" displays cost around $20. These displays work both with 4-wire I2C and 7-wire SPI connections.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Typical chips that control the OLED include the SSD1306 driver chips.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • See: Graph Displays
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Raspberry Pi Foundation

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The company that builds the Raspberry Pi hardware and provides some software.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Raspberry Pi Pico

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A microcontroller designed by the Raspberry Pi foundation for doing real-time control systems.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The Pico was introduced in 2020 with a retail list price of $4. It was a key development because it used a custom chip that had 100 times the RAM of an Arduino Nano.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Pico Pinout Diagram

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The Pico pinout diagram shows you the ways that each Pin can be used. Different colors are used for GPIO numbers, I2C, and SPI interfaces.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Pinout PDF
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  PWM

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A type of output signal used to control items with continuous values. For example, we use PWM to control the brightness of a light or the speed of a motor. We use pulse-width modulation (PWM) to control the speed of our DC motors.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  RP2040 chip

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A custom chip created by the Raspberry Pi Foundation to power the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  rshell

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A MicroPython shell that runs on the host and uses MicroPython's raw-REPL to send python snippets to the pyboard in order to get filesystem information, and to copy files to and from MicroPython's filesystem.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  It also has the ability to invoke the regular REPL, so rshell can be used as a terminal emulator as well.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Note: With rshell you can disable USB Mass Storage and still copy files into and out of your pyboard.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  RShell GitHub Repo

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  SPI

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  An interface bus commonly used to send data between microcontrollers and small peripherals such as sensors, displays and SD cards. SPI uses separate clock and data lines, along with a select line to choose the device you wish to talk to.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Also known as: Serial Peripheral Interface +See also: I2C

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Thonny

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  A lightweight Python IDE ideal for writing simple Python programs for first time users.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Thonny runs on Mac, Windows and Linux.

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Thonny web site
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  UF2 File

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The file that must be uploaded into the Raspberry Pi Pico folder to allow it to be used.

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  The file name format looks like this:

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  Unicorn

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  MicroPython on Unicorn is completely open source Micropython emulator

                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                  • Github Repo: https://github.com/micropython/micropython-unicorn
                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  See Also

                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                  MicroPython.org Glossary

                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                  + Breadboard +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                  + References +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/misc/mermaid-test/index.html b/misc/mermaid-test/index.html new file mode 100644 index 000000000..d8a6a6230 --- /dev/null +++ b/misc/mermaid-test/index.html @@ -0,0 +1,1302 @@ + + + + + + + + + + + + + + + + + + + + + + + Mermaid test - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + Mermaid test + + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                    Mermaid test

                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                                                    +5
                                                                                                                                                                                                                                                                    +6
                                                                                                                                                                                                                                                                    +7
                                                                                                                                                                                                                                                                    graph LR
                                                                                                                                                                                                                                                                    +    p[Pico] -->|ADC_VREF 36 row=6| pos(Positive)
                                                                                                                                                                                                                                                                    +    p[Pico] -->|AGND 33 row=8| neg(Negative)
                                                                                                                                                                                                                                                                    +    p[Pico] -->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)
                                                                                                                                                                                                                                                                    +    pos(Positive) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                    +    neg(Negative) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                    +    tap(Center Tap) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                    graph LR
                                                                                                                                                                                                                                                                    +MyApp --> DB(<font color=white>fa:fa-database MySQL)
                                                                                                                                                                                                                                                                    +style DB fill:#00758f
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/misc/projects/index.html b/misc/projects/index.html new file mode 100644 index 000000000..bc4efc934 --- /dev/null +++ b/misc/projects/index.html @@ -0,0 +1,1362 @@ + + + + + + + + + + + + + + + + + + + + + + + CoderDojo MicroPython Projects - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + CoderDojo MicroPython Projects + + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                      • + + + Projects that a In Development + + + +
                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                      CoderDojo MicroPython Projects

                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                      Projects are groups lesson plans that need to work together and frequently build on other projects. Key project areas include:

                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                      1. Sensors - find low cost sensors and create a lesson around them
                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                      3. Robot Extensions - build extensions to our Base robot
                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                      5. Sound and Music - add labs that generate sound and play music
                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                      7. OLED Displays and Graphics - leverage the new low-cost OLED displays
                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                      9. Debugging - build lesson plans to help student learn how to debug MicroPython programs and use logic analyzers
                                                                                                                                                                                                                                                                      10. +
                                                                                                                                                                                                                                                                      11. Advanced Labs - using multiple cores, programming the IP processors, integrating C and assembly code
                                                                                                                                                                                                                                                                      12. +
                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                      Projects that a In Development

                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                      Please connect with Dan McCreary if you are interested in helping out with these projects.

                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      NameStatusDescription
                                                                                                                                                                                                                                                                      Ping HC-SR0450%)Create an OLED ping lab
                                                                                                                                                                                                                                                                      Motion Sensor0%Create a lesson that uses a motion sensor. Use an OLED to display motion vs. time
                                                                                                                                                                                                                                                                      Photosensor0%Create a lesson that will monitor light on a photo sensor
                                                                                                                                                                                                                                                                      DS18B Temp Sensor0%Create a lesson that will read and display a waterproof temperature sensor
                                                                                                                                                                                                                                                                      JoyStick0%Create a lesson that will read the X, Y and button of a JoyStick
                                                                                                                                                                                                                                                                      OLED JoyStick0%Use a Joystick to move a ball around an OLED and paint pixels
                                                                                                                                                                                                                                                                      OLED Game of Life0%Write a Game of Life with an OLED. Add a Joystick to paint initial conditions
                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/misc/references/index.html b/misc/references/index.html new file mode 100644 index 000000000..ec4fa448f --- /dev/null +++ b/misc/references/index.html @@ -0,0 +1,1605 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + References - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + References + + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + References + + + + + + + +
                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                          • + + + Micropython References + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Pico References + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Components + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Components References + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Variations of the the Raspberry Pi Pico + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Open-Source References + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Coding General + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Getting Started Videos + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Snake Game + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Turing the Raspberry Pi Pico into a Logic Analyzer + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                        • + + + Micropython References + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Pico References + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Components + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Components References + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Variations of the the Raspberry Pi Pico + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Open-Source References + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Coding General + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Getting Started Videos + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Snake Game + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        • + + + Turing the Raspberry Pi Pico into a Logic Analyzer + + + +
                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                        References for MicroPython

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Micropython References

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        1. MicroPython Forum - a good place to ask questions about MicroPython. Mostly for hard core developers.
                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                        3. MicroPython.org site - We would not recommend the PyBoard for beginners. They are over 10x more expensive than the the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                        5. Spider Maf Github Repo
                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Pico References

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        1. MicroPython Firmware for the Raspberry Pi Pico - You will want to bookmark this site. It has the firmware required to run MicroPython on your Raspberry Pi Pico. As of March 2021, they are fixing bugs weekly, so you will want to make sure your firmware is current.
                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                        3. Pico Launch Video on YouTube
                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                        5. Raspberry Pi Web Site Project Search
                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                        7. Pico Data Sheet - you will only need this for detailed information on how to use the Pico hardware.
                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                        9. Meet Raspberry Silicon: Raspberry Pi Pico now on sale at $4 - The original Raspberry Pi Pico announcement.
                                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                                        11. The journey to Raspberry Silicon - blog by Liam Fraser - Feb. 8th 2021. Nice story of how the Raspberry Pi Foundation created the custom silicon chip.
                                                                                                                                                                                                                                                                        12. +
                                                                                                                                                                                                                                                                        13. TensorFlow Lite Micro for the Pico
                                                                                                                                                                                                                                                                        14. +
                                                                                                                                                                                                                                                                        15. Pico Invaders Video
                                                                                                                                                                                                                                                                        16. +
                                                                                                                                                                                                                                                                        17. YouTube video of Raspberry Pi driving a full color VGA screen - Full-speed high-fidelity BBC Micro emulation on a (slightly) overclocked Raspberry Pi Pico
                                                                                                                                                                                                                                                                        18. +
                                                                                                                                                                                                                                                                        19. Raspberry Pi RP2040: Our Microcontroller for the Masses - James Adams, COO and Director of Hardware, Raspberry Pi
                                                                                                                                                                                                                                                                        20. +
                                                                                                                                                                                                                                                                        21. ARM Blueprint post on TinyML - nice review of the Tiny Machine Learning possible on the ARM processor.
                                                                                                                                                                                                                                                                        22. +
                                                                                                                                                                                                                                                                        23. Google TensorFlow engineer talking about how ARM and Google are working together on TinyML - short 60 second video clip of Google TensorFlow engineer Ian Nappier talking about how they are working with ARM to create a standard TinyML library for all ARM processors to use.
                                                                                                                                                                                                                                                                        24. +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Components

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Comparison of RP2040 Boards

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Components References

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        1. 2.42" OLED Display from DIY More
                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Variations of the the Raspberry Pi Pico

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        1. WeAct RP2040 board adds 16MB flash, USB-C port to Raspberry Pi Pico form factor - JULY 13, 2022 BY JEAN-LUC AUFRANC (CNXSOFT) - CNX SOFTWARE – EMBEDDED SYSTEMS NEWS
                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Open-Source References

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        1. Open Source Guide
                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Coding General

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        • Sam Altman on Coding
                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Getting Started Videos

                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                        • Raspberry Pi Pico W LESSON 1: Write Your First Program for Absolute Beginners by Paul McWhorter. A nice gentle introduction to getting started with Thonny on the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Snake Game

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Micropython Snake Game

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Turing the Raspberry Pi Pico into a Logic Analyzer

                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                        Make a 100MHz 24 Channel Logic Analyzer from your favorite Raspberry Pi Pico - In this video you will learn how to setup the Raspberry Pi Pico so it can be used as a 24 channel signal analyzer. You will also see some examples using the signal analyzer decoding some different protocols like a UART, I2C-bus and 1-wire.

                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                        + Glossary +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                        + Contributing +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/misc/upip/index.html b/misc/upip/index.html new file mode 100644 index 000000000..e69c236c3 --- /dev/null +++ b/misc/upip/index.html @@ -0,0 +1,1326 @@ + + + + + + + + + + + + + + + + + + + + + + + MicroPython PIP (UPIP) - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + MicroPython PIP (UPIP) + + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                          • + + + Install UPIP From Thonny Package Manager + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          • + + + Install A Package + + + +
                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                          MicroPython PIP (UPIP)

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          MicroPython also has a package manager that can be run directly on the microcontoller.

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          Install UPIP From Thonny Package Manager

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          Thonny UPIP Search

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          Thonny UPIP Search

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          Install A Package

                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                          Connecting to WiFi Network Name: anndan-2.4 +Waiting for connection... +1.2.3.4.Connect Time: 4641 +Ping the following address: 10.0.0.49 +Installing to: /lib/ +Warning: micropython.org SSL certificate is not validated +Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz

                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml deleted file mode 100755 index f46aa4af3..000000000 --- a/mkdocs.yml +++ /dev/null @@ -1,255 +0,0 @@ -site_name: 'MicroPython for Kids' -nav: - - CoderDojo Mentor Resources: https://coderdojotc.github.io/CoderDojoTC/ - - MicroPython Home: index.md - - Introduction: - - About This Site: intro/01-about.md - - Physical Computing: intro/02-physical-computing.md - - Microcontrollers: intro/03-microcontrollers.md - - Getting Started: - - Introduction: getting-started/01-intro.md - - Solderless Breadboards: getting-started/02-breadboards.md - - Boards: getting-started/02-boards.md - - Displays: getting-started/10-displays.md - - Sourcing Parts: getting-started/03-suggested-parts.md - - Raspberry Pi Pico: getting-started/02-pi-pico.md - - ESP32: getting-started/02-esp32.md - - Powering Your Projects: getting-started/04-power.md - - Thonny IDE: getting-started/02c-thonny.md - - VS Code IDE: getting-started/02d-vscode.md - - MicroPython Libraries: getting-started/01b-libraries.md - - Basic Examples: - - Introduction: basics/01-intro.md - - Blink: basics/03-blink.md - - Fade In and Out: basics/04-fade-in-and-out.md - - Buttons: basics/03-button.md - - Potentiometer: basics/03-potentiometer.md - - Motor: basics/04-motor.md - - Servo: basics/04-servo.md - - NeoPixel: basics/05-neopixel.md - - Wireless: basics/06-wireless.md - - Sensors: - - Introduction: sensors/01-intro.md - - Photosensor: sensors/02-photosensor.md - - Ping Distance: sensors/03-ping.md - - IR Distance Sensor: sensors/08-ir-distance-sensor.md - - Temp and Humidity: sensors/04-temp-dht11.md - - Temperature: sensors/05-temp-dsb20.md - - Temp, Humidity, Pres: sensors/06-bme280.md - - DH11 Temp and Humidity: sensors/dht11-temp-humidity.md - - Potentiometer: sensors/02-pot.md - - Environmental Sensor: sensors/06-bme280.md - - Accelerometer Compass: sensors/06-accelerometer-compass.md - - Time of Flight Distance: sensors/07-VL53L0X_GY.md - - Rotary Encoder: sensors/10-rotary-encoder.md - - Compass: sensors/11-compass.md - - Gesture: sensors/13-gesture.md - - Motors and Servos: - - Introduction: motors/01-intro.md - - Transistor Lab: motors/02-transistor.md - - H-Bridge: motors/03-h-bridge.md - - L293D Chip: motors/04-l293d.md - - Controller Board: motors/05-controller-board.md - - Servos: motors/06-servos.md - - Stepper Motors: motors/07-stepper-motors.md - - Displays - Non-Graphical: - - Introduction: displays/non-graph/01-intro.md - - 7 Segment Display: displays/non-graph/seven-segment.md - - 10 Bar LEDs: displays/non-graph/03-10-bar-leds.md - - 8x8 LED Matrix: displays/non-graph/04-8x8-led-matrix.md - - Character LCD: displays/non-graph/10-character-lcd-display.md - - 4 Digit LED: displays/non-graph/05-4-digit.md - - Displays Graphical: - - Introduction: displays/graph/01-intro.md - - Wiring Harness: displays/graph/19-wiring-harness.md - - Graphic LCD: displays/graph/15-cu1609c-led.md - - Basic Drawing: displays/graph/03-basic-drawing.md - - Drawing with Bitmaps: displays/graph/03-bitmaps.md - - Custom Drawing Functions: displays/graph/04-extended-drawing-functions.md - - Color LCD ST7789V: displays/graph/14-lcd-st7789V.md - - Timing Draw Speed: displays/graph/05-timing-draw-speed.md - - TFT ILI9341: displays/graph/16-tft-ili9341.md - - LCD Waveshare: displays/graph/11-lcd-waveshare.md - - E-Paper: displays/graph/12-e-paper-display.md - - OLED Setup: displays/graph/02-oled-setup.md - - OLED SSD1306 I2C: displays/graph/11-oled-ssd1306-i2c.md - - OLED SSD1306 SPI V1: displays/graph/12-oled-ssd1306-spi-v1.md - - OLED SSD1306 SPI V2: displays/graph/11-oled-ssd1306-spi.md - - OLED SH1106 I2C Example: displays/graph/11-oled-sh1106-i2c.md - - OLED SSD 1352: displays/graph/17-ssd1352.md - - OLED Bounce: displays/graph/10-oled-bounce.md - - OLED Pot: displays/graph/12-oled-pot.md - - OLED Ping: displays/graph/11-oled-ping.md - - OLED Pong: displays/graph/11-pong.md - - OLED Pixel Draw: displays/graph/13-pixel-draw.md - - OLED Patterns: displays/graph/15-oled-patterns.md - - Random Hearts: displays/graph/14-random-hearts.md - - NeoPixel Matrix: displays/graph/18-neopixel-matrix.md - - OLED References: displays/graph/40-oled-references.md - - Sound and Music: - - Introduction: sound/index.md - - Playing a Tone: sound/02-play-tone.md - - Playing Three Tones: sound/03-play-three-tones.md - - Playing a Scale: sound/04-play-scale.md - - Play Mario: sound/05-play-mario.md - - Eight Key Piano: sound/06-eight-key-piano.md - - Playing Audio File: sound/07-play-audio-file.md - - Converting Audio Files: sound/09-converting-mp3-to-wav.md - - Wireless: - - Introduction: wireless/01-intro.md - - Connecting to WiFi: wireless/02-connecting-to-wifi.md - - HTTP GET: wireless/03-http-get.md - - Web Server: wireless/04-web-server.md - - Web Server NeoPixel: wireless/07-web-server-rgb-neopixels.md - - MAC Address: wireless/05-mac-address.md - - UPIP: wireless/06-upip.md - - Get Weather Forecast: wireless/08-get-weather.md - - Display Forecast on OLED: wireless/09-get-weather-display.md - - WiFi Clock: wireless/10-wifi-clock.md - - Advanced Labs: wireless/11-advanced-labs.md - - With Display: wireless/20-display.md - - Robots: - - Introduction: robots/index.md - - Base Bot: robots/02-base-bot.md - - Rainbow Bot: robots/03-rainbow-bot.md - - Face Bot: robots/04-face-bot.md - - Ajusta Bot: robots/05-ajusta-bot.md - # - Servo Bot: robots/05-servo-bot.md - - IR Sensor Bot: robots/03-ir-sensor-bot.md - - FAQs: robots/20-faqs.md - - Advanced Labs: - - Introduction: advanced-labs/index.md - - Internal Temperature: advanced-labs/03-internal-temperature.md - - Interrupt Handlers: advanced-labs/02-interrupt-handlers.md - - Timing Functions: advanced-labs/03-timing-functions.md - - Conda Environment Setup: advanced-labs/04-conda-env.md - - OS Functions: advanced-labs/05-os-functions.md - - I2C Scanner: advanced-labs/06-i2c.md - - Frame Buffer: advanced-labs/07-framebuffer.md - - Minicom: advanced-labs/08-minicom.md - - SD Card Reader: advanced-labs/09-micro-sd-card-reader.md - - Converting CircuitPython: advanced-labs/10-converting-circuitpython-to-micropython.md - - MicroPython Remote: advanced-labs/11-mpremote.md - - Rshell: advanced-labs/11-rshell.md - - Timers: advanced-labs/13-timers.md - - Memory Management: advanced-labs/14-memory-management.md - - TinyML: advanced-labs/20-tinyml.md - - String Formatting: advanced-labs/12-string-formatting.md - - Operating System: advanced-labs/11-os.md - - Measuring Battery Voltage: advanced-labs/15-measuring-vsys.md - - File System: advanced-labs/17-file-system.md - - Spectrum Analyzer: - - Introduction: advanced-labs/30-spectrum-analyzer/index.md - - Test Incomming: advanced-labs/30-spectrum-analyzer/01-test-incoming-sound.md - - Gain Pot: advanced-labs/30-spectrum-analyzer/02-gain-pot.md - - Display Scroll: advanced-labs/30-spectrum-analyzer/display-scroll.md - - Debugging: - - Debugging Python: debugging/28-debugging-python.md - - Debugging I2C: debugging/29a-debugging-i2c.md - - Debugging SPI: debugging/29-debugging-spi.md - - Project Kits: - - Introduction: kits/01-intro.md - - Maker Pi RP2040: - - Introduction: kits/maker-pi-rp2040/index.md - - Getting Started: kits/maker-pi-rp2040/01-getting-started.md - - Blue LED Lab: kits/maker-pi-rp2040/02-blue-led-lab.md - - NeoPixel Lab: kits/maker-pi-rp2040/03-neopixel-lab.md - - Button Lab: kits/maker-pi-rp2040/04-button-lab.md - - Sound Lab: kits/maker-pi-rp2040/05-sound-lab.md - - Up/Down Mode Lab: kits/maker-pi-rp2040/06-up-down-lab.md - - Maker Pi RP2040 Robot: - - Introduction: kits/maker-pi-rp2040-robot/index.md - - Assembly: kits/maker-pi-rp2040-robot/02-assembly.md - - Motor Lab: kits/maker-pi-rp2040-robot/07-motor-connection-lab.md - - Up/Down Motor Speed Lab: kits/maker-pi-rp2040-robot/06-up-down-motor-lab.md - - Square Lab: kits/maker-pi-rp2040-robot/07b-drive-square-lab.md - - Servo Lab: kits/maker-pi-rp2040-robot/08-servo-lab.md - - Scanner Test: kits/maker-pi-rp2040-robot/09-i2c-scanner-test.md - - Time of Flight Lab: kits/maker-pi-rp2040-robot/10-time-of-flight-lab.md - - Time of Flight Sound Lab: kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab.md - - MicroSwitch Bot: kits/maker-pi-rp2040-robot/23-microswitch-bot.md - - Ultrasonic Ping Lab: kits/maker-pi-rp2040-robot/11-ping-lab.md - - Collision Avoidance Time-of-Flight: kits/maker-pi-rp2040-robot/20-collision-avoidance-robot.md - - Collision Avoidance Ping: kits/maker-pi-rp2040-robot/21-collision-avoidance-ping.md - - Ping Servo Meter: kits/maker-pi-rp2040-robot/24-ping-servo-meter.md - - Line Follower: kits/maker-pi-rp2040-robot/25-line-follower.md - - Maker Pi Pico: - - Introduction: kits/maker-pi-pico/index.md - - Running Lights: kits/maker-pi-pico/02-running-lights.md - - SD Card Reader: kits/maker-pi-pico/09-micro-sd-card-reader.md - - Maker Nano RP2040: - - Intro: kits/kits/maker-nano-rp2040/01-intro.md - - Larson Scanner: - - kits/larson-scanner/01-intro.md - - NeoPixel: - - Introduction: kits/neopixel/index.md - - Getting Started: kits/neopixel/01-getting-started.md - - Simple Patterns: kits/neopixel/02-simple-patterns.md - - Buttons: kits/neopixel/03-buttons.md - - Rotary Neopixel: projects/03-notary-neopixel.md - - MicroBit: kits/microbit.md - - RFID RC522: kits/rfid-rc522/index.md - # - Project Ideas: misc/projects.md - - - Sims: - - Introduction: sims/index.md - - Knowledge Graphs: - - Introduction: sims/knowledge-graphs/index.md - - Concept Enumeration: sims/knowledge-graphs/concept-enumeration.md - - Concept Dependency: sims/knowledge-graphs/concept-dependency.md - - Concept Taxonomy: sims/knowledge-graphs/concept-taxonomy.md - - Graph Demo: sims/knowledge-graphs/graph/index.md - - Breadboard: sims/breadboard/index.md - - - Glossary: misc/glossary.md - - References: misc/references.md - - Contributing: misc/contributing.md - - Contact: misc/contact.md - - Colophon: misc/30-colophon.md - # - Render Test: misc/mermaid-test.md - -site_description: 'Resources for teaching MicroPython to CoderDojo Twin Cities students. All content licensed Creative Commons ShareAlike Attribution Noncommercial' -site_author: 'Dan McCreary' -repo_name: 'GitHub Repo' -repo_url: 'https://github.com/CoderDojoTC/micropython' - -# CoderDojo Microsite Standards from here down -edit_uri: 'blob/master/docs' -theme: - # should be name: material - name: material - logo: img/coderdojo-logo.png - icon: - previous: fontawesome/solid/angle-left - next: fontawesome/solid/angle-right - palette: - primary: '#642580' - accent: '#41BAC1' - # custom_dir: 'theme' - include_sidebar: true - features: - - content.code.copy - - navigation.expand - - navigation.path - - navigation.prune - - navigation.indexes - - toc.follow - - navigation.top - # this adds the prev and next icons in the footer - - navigation.footer -plugins: - - search - # - mermaid2 - takes too long to build - use a screen image for now -markdown_extensions: - - admonition - - pymdownx.details - - pymdownx.superfences - - attr_list - - pymdownx.highlight: - linenums: true - -extra: - analytics: - provider: google - # https://analytics.google.com/analytics/web/#/a1420179p349994530/admin/streams/table/4433129821 - property: G-DS16K4YVRR diff --git a/motors/01-intro/index.html b/motors/01-intro/index.html new file mode 100644 index 000000000..05186546a --- /dev/null +++ b/motors/01-intro/index.html @@ -0,0 +1,1658 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + Introduction + + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                • + + + Motor Types + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + Outline of Labs + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + Lab 1: Using and Transistor to Control a Motor + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + Theory: What is an H-Bridge Circuit? + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + Lab 2: Controlling a Motor Speed with the L293 H-Bridge Chip + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + Lab 3: Changing Motor Direction + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                            • + + + Motor Types + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            • + + + Outline of Labs + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            • + + + Lab 1: Using and Transistor to Control a Motor + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            • + + + Theory: What is an H-Bridge Circuit? + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            • + + + Lab 2: Controlling a Motor Speed with the L293 H-Bridge Chip + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            • + + + Lab 3: Changing Motor Direction + + + +
                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                            Using MicroPython to Control Motors and Servos

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Controlling motors are one of the funnest ways to learn how to program! They give us quick hand-on feedback on what are programs are doing. Motors are used in almost all our robot project. Robots are used in many STEM courses and coding clubs around the world. Programs like the AI Racing League allow students to learn topics like Machine Learning, Computer Vision and AI. These programs all depend on our understanding of how motors work and how to control them.

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Geared DC Hobby Motor and Wheel

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Motor Types

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            There are three types of motors we will learn how to control:

                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                            1. DC Motors
                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                            3. Servos
                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                            5. Stepper Motors
                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Outline of Labs

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Lab 1: Using and Transistor to Control a Motor

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            In this lab we will use MicroPython to turn a motor on and off. We will use the digital output from the Raspberry Pi Pico to control a transistor as a switch to control the current to a motor. We will also learn how to use a diode to to protect the transistor from flyback current.

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Theory: What is an H-Bridge Circuit?

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            This lab shows a sample circuit with four switches arranged in the shape of the letter "H" with the motor at the center of the letter. By closing switches in opposite corners we can make the motor reverse direction.

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Lab 2: Controlling a Motor Speed with the L293 H-Bridge Chip

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            In this lab we will use a PWM signal to control the speed of a motor.

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            Lab 3: Changing Motor Direction

                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                            In this lab we will make a motor go both forward and backward and change the speed.

                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                                            + Gesture +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                                                            + Transistor Lab +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/motors/02-transistor/index.html b/motors/02-transistor/index.html new file mode 100644 index 000000000..c197cd842 --- /dev/null +++ b/motors/02-transistor/index.html @@ -0,0 +1,1687 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Transistor Lab - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + Transistor Lab + + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Transistor Lab + + + + + + + +
                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                  • + + + Power Requirements for Motors + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + Basic Transistor Circuit + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + PWM Control + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                    • + + + PWM Frequency + + + +
                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + Sample Coder + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                              • + + + Power Requirements for Motors + + + +
                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                              • + + + Basic Transistor Circuit + + + +
                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                              • + + + PWM Control + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                • + + + PWM Frequency + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                              • + + + Sample Coder + + + +
                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                              Using an Transistor to Control a Motor

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Power Requirements for Motors

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Motors need about 200 milliamps to work. But a microcontroller like the Raspberry Pi Pico only can switch about 18 milliamps. So we need a way to control more power.

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the Raspberry Pi Pico Datasheet Table 5. The solution is to either use the digital output signal to turn on and off a switch such as a transistor of to use a motor driver chip such as an L293D chip.

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Basic Transistor Circuit

                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                              1. Transistor NPN 2222A
                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                              3. Diode: 1N1448
                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                              5. Motor: 3-6 volt hobby motor
                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Motor Circuit

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              PWM Control

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              PWM Frequency

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms)

                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              Sample Coder

                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                              +4
                                                                                                                                                                                                                                                                              +5
                                                                                                                                                                                                                                                                              +6
                                                                                                                                                                                                                                                                              +7
                                                                                                                                                                                                                                                                              +8
                                                                                                                                                                                                                                                                              import machine
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +# set the 7th from the bottom on right as our motor pin
                                                                                                                                                                                                                                                                              +motor_pin = machine.Pin(21, machine.Pin.OUT)
                                                                                                                                                                                                                                                                              +# allocate a PWM object for controlling the motor speed
                                                                                                                                                                                                                                                                              +motor_pwm = machine.PWM(motor_pin)
                                                                                                                                                                                                                                                                              +motor_pwm.freq(50) # 50 hertz
                                                                                                                                                                                                                                                                              +motor_pwm.duty(51)
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                              References

                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                              1. Sparkfun Motor Lab from SIK Kit
                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                              3. Nick Zoic MicroPython Motor Control Tutorial
                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                              + Introduction +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                              + H-Bridge +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/motors/03-h-bridge/index.html b/motors/03-h-bridge/index.html new file mode 100644 index 000000000..6779fa2ff --- /dev/null +++ b/motors/03-h-bridge/index.html @@ -0,0 +1,1579 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + H-Bridge - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + H-Bridge + + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + H-Bridge + + + + + + + +
                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                    • + + + H-Bridge Circuit Operation + + + +
                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                • + + + H-Bridge Circuit Operation + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                H-Bridge Circuits

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                H-Bridge circuits are use to drive a motor both forward and backward. The circuit is called an "H-Bridge" because the arrangement of the switches around a motor form the letter "H".

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                H-Bridge Circuit

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                H-Bridge Circuit Operation

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                If you connect a 5 volt power supply to a motor you will turn the motor in a specific direction such as clockwise. If you reverse the connections to the motor, the motor will turn the opposite direction such as counter-clockwise.

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                In order to turn on the motor, switches 1 and 4 must be closed to allow current to flow through the motor. Switches 2 and 3 must be turned off.

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                To reverse the motor direction you must open switches 1 and 4 and close switches 2 and three in the upper right and lower left portion of the diagram.

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                H-Bridge Circuit

                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                References

                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                1. Wikipedia Page on H-Bridge Circuits
                                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                + Transistor Lab +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                + L293D Chip +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/motors/04-l293d/index.html b/motors/04-l293d/index.html new file mode 100644 index 000000000..e25951732 --- /dev/null +++ b/motors/04-l293d/index.html @@ -0,0 +1,1614 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + L293D Chip - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + L293D Chip + + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + L293D Chip + + + + + + + +
                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                      • + + + What is an H-Bridge? + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      • + + + The L293D Circuit + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      • + + + Sample Program + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                  • + + + What is an H-Bridge? + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + The L293D Circuit + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + Sample Program + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                  Controlling a Motor with the L293D Motor Controller Chip

                                                                                                                                                                                                                                                                                  + + +

                                                                                                                                                                                                                                                                                  What is an H-Bridge?

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  The L293D Circuit

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  The L293D motor driver IC has two power input pins viz. ‘Vcc1’ and ‘Vcc2’.

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  Vcc1 is used for driving the internal logic circuitry which should be 5V.

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  From Vcc2 pin the H-Bridge gets its power for driving the motors which can be 4.5V to 36V. And they both sink to a common ground named GND.

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  Sample Program

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  References

                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                  Last Minute Engineer L293D DC Motor Tutorial (Arduino version)

                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                  + H-Bridge +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                  + Controller Board +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/motors/05-controller-board/index.html b/motors/05-controller-board/index.html new file mode 100644 index 000000000..7730db9fe --- /dev/null +++ b/motors/05-controller-board/index.html @@ -0,0 +1,1487 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Controller Board - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + Controller Board + + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + Controller Board + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                    Controller Board

                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                    + L293D Chip +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                    + Servos +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/motors/06-servos/index.html b/motors/06-servos/index.html new file mode 100644 index 000000000..9335caddf --- /dev/null +++ b/motors/06-servos/index.html @@ -0,0 +1,1607 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Servos - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + Servos + + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Servos + + + + + + + +
                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                          • + + + Types of Servos + + + +
                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                          • + + + Servo Connections + + + +
                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                          • + + + references + + + +
                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Stepper Motors + + + + +
                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                      • + + + Types of Servos + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      • + + + Servo Connections + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      • + + + references + + + +
                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                      Controlling a Servo Motor with MicroPython

                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      Types of Servos

                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      Although there are may types of servos you can purchase, in our labs there are two main types of servos that we use:

                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                      1. SG90 Micro Servo, 9 grams, 180 degree, plastic gears - $4
                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                      3. MG90S Micro Servo, 9 grams, 180 degree, metal gears - $5
                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      There are other variations that have 360 degree or continuous rotation servos.

                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      Servo Connections

                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      Almost all servos have a three pin connector that are spaced 1/10th of an inch apart so they will work with our breadboards.

                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                      1. Ground (black or brown wire)
                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                      3. 5 volt power (always red)
                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                      5. Data (orange or yellow)
                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                      references

                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                      1. SparkFun Servos Page
                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                      3. SparkFun Category for Servos
                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                      5. eBay Servo Plastic Servo
                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                      7. eBay Servo Metal Gear Servo
                                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                      + Controller Board +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                      + Stepper Motors +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/motors/07-stepper-motors/index.html b/motors/07-stepper-motors/index.html new file mode 100644 index 000000000..3755c7e9b --- /dev/null +++ b/motors/07-stepper-motors/index.html @@ -0,0 +1,1627 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Stepper Motors - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + Stepper Motors + + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Transistor Lab + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + H-Bridge + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + L293D Chip + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Controller Board + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Servos + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Stepper Motors + + + + + + + +
                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                            • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                        • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                        Controlling a Stepper Motor with MicroPython

                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                        Stepper Motor

                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                        Stepper motors are specialized motors that precisely control the angle of rotation of the shaft of a motor. They are often used to carefully position items that move along an axis. For example you can use stepper motors to control the position the printing head of a 3D printer. Stepper motors are also quite a bit more expensive than our DC hobby motors and mini servos, so we don't use them frequently in our classes.

                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                        Sample Code

                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                                                                                        +20
                                                                                                                                                                                                                                                                                        +21
                                                                                                                                                                                                                                                                                        +22
                                                                                                                                                                                                                                                                                        +23
                                                                                                                                                                                                                                                                                        +24
                                                                                                                                                                                                                                                                                        +25
                                                                                                                                                                                                                                                                                        # Code example from YoungWorks blog on how to use a stepper motor
                                                                                                                                                                                                                                                                                        +# https://www.youngwonks.com/blog/How-to-use-a-stepper-motor-with-the-Raspberry-Pi-Pico
                                                                                                                                                                                                                                                                                        +from machine import Pin
                                                                                                                                                                                                                                                                                        +import utime
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +pins = [
                                                                                                                                                                                                                                                                                        +    Pin(15, Pin.Out),
                                                                                                                                                                                                                                                                                        +    Pin(14, Pin.Out),
                                                                                                                                                                                                                                                                                        +    Pin(16, Pin.Out),
                                                                                                                                                                                                                                                                                        +    Pin(17, Pin.Out),
                                                                                                                                                                                                                                                                                        +]
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +# one hot encoding vectors
                                                                                                                                                                                                                                                                                        +full_step_sequence = [
                                                                                                                                                                                                                                                                                        +    [1.0.0.0],
                                                                                                                                                                                                                                                                                        +    [0.1.0.0],
                                                                                                                                                                                                                                                                                        +    [0.0.1.0],
                                                                                                                                                                                                                                                                                        +    [0.0.0.1]
                                                                                                                                                                                                                                                                                        +]
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                                                                                        +    for step in full_step_sequence:
                                                                                                                                                                                                                                                                                        +        for i in rang(len(pins)):
                                                                                                                                                                                                                                                                                        +            pins[i].value(step[i])
                                                                                                                                                                                                                                                                                        +            utime.sleep(0.001)
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                        References

                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                        1. Wikipedia Page on Stepper Motors
                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                        3. Raspberry Pi L293D Example
                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                        5. Young Wonks Stepper Motor Example with a
                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                        + Servos +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                        + Introduction +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/numpy/01-intro.md b/numpy/01-intro.md deleted file mode 100644 index 43631343b..000000000 --- a/numpy/01-intro.md +++ /dev/null @@ -1,5 +0,0 @@ -# Numerical Analysis With MicroPython - -ULAB is a implementation of Python that runs in MicroPython. - -[Intro to ULAB](https://micropython-ulab.readthedocs.io/en/latest/ulab-intro.html) \ No newline at end of file diff --git a/pico-images/RPI_PICO_W-20240105-v1.22.1.uf2 b/pico-images/RPI_PICO_W-20240105-v1.22.1.uf2 deleted file mode 100644 index 38c833be1..000000000 Binary files a/pico-images/RPI_PICO_W-20240105-v1.22.1.uf2 and /dev/null differ diff --git a/pico-images/flash_nuke.uf2 b/pico-images/flash_nuke.uf2 deleted file mode 100644 index 31291e64c..000000000 Binary files a/pico-images/flash_nuke.uf2 and /dev/null differ diff --git a/presentations/Badge-Template.pptx b/presentations/Badge-Template.pptx deleted file mode 100644 index d1861afc9..000000000 Binary files a/presentations/Badge-Template.pptx and /dev/null differ diff --git a/presentations/Batteries-Dialog-11th-Grade.docx b/presentations/Batteries-Dialog-11th-Grade.docx deleted file mode 100644 index 6789cf493..000000000 Binary files a/presentations/Batteries-Dialog-11th-Grade.docx and /dev/null differ diff --git a/presentations/Batteries-Dialog-5th-Grade.docx b/presentations/Batteries-Dialog-5th-Grade.docx deleted file mode 100644 index 785b58ba9..000000000 Binary files a/presentations/Batteries-Dialog-5th-Grade.docx and /dev/null differ diff --git a/presentations/Circuit-Diagrams.pptx b/presentations/Circuit-Diagrams.pptx deleted file mode 100644 index 71aa5dd9d..000000000 Binary files a/presentations/Circuit-Diagrams.pptx and /dev/null differ diff --git a/presentations/Corral-Sponsors.pptx b/presentations/Corral-Sponsors.pptx deleted file mode 100644 index b294c4c0e..000000000 Binary files a/presentations/Corral-Sponsors.pptx and /dev/null differ diff --git a/presentations/Cytron-Nano-RP2040-Figures [Autosaved].pptx b/presentations/Cytron-Nano-RP2040-Figures [Autosaved].pptx deleted file mode 100644 index 7d2122580..000000000 Binary files a/presentations/Cytron-Nano-RP2040-Figures [Autosaved].pptx and /dev/null differ diff --git a/presentations/Display-Board-Back.docx b/presentations/Display-Board-Back.docx deleted file mode 100644 index d569a36c3..000000000 Binary files a/presentations/Display-Board-Back.docx and /dev/null differ diff --git a/presentations/Figures.pptx b/presentations/Figures.pptx deleted file mode 100644 index f09c5f2d3..000000000 Binary files a/presentations/Figures.pptx and /dev/null differ diff --git a/presentations/General-FIgures.pptx b/presentations/General-FIgures.pptx deleted file mode 100644 index 1aba3c023..000000000 Binary files a/presentations/General-FIgures.pptx and /dev/null differ diff --git a/presentations/Intro-Sign.pptx b/presentations/Intro-Sign.pptx deleted file mode 100644 index 2781527b1..000000000 Binary files a/presentations/Intro-Sign.pptx and /dev/null differ diff --git a/presentations/Journey-Map.pptx b/presentations/Journey-Map.pptx deleted file mode 100644 index 6fdbb3987..000000000 Binary files a/presentations/Journey-Map.pptx and /dev/null differ diff --git a/presentations/LEDs-and-Displays.pptx b/presentations/LEDs-and-Displays.pptx deleted file mode 100644 index 49fb7293f..000000000 Binary files a/presentations/LEDs-and-Displays.pptx and /dev/null differ diff --git a/presentations/MicroController-Board-Back.docx b/presentations/MicroController-Board-Back.docx deleted file mode 100644 index 798b1b478..000000000 Binary files a/presentations/MicroController-Board-Back.docx and /dev/null differ diff --git a/presentations/Micropython-pitch-deck.pptx b/presentations/Micropython-pitch-deck.pptx deleted file mode 100644 index 69ce69c82..000000000 Binary files a/presentations/Micropython-pitch-deck.pptx and /dev/null differ diff --git a/presentations/Microsite-Journey-Map.pptx b/presentations/Microsite-Journey-Map.pptx deleted file mode 100644 index 19e8041e0..000000000 Binary files a/presentations/Microsite-Journey-Map.pptx and /dev/null differ diff --git a/presentations/PWM-five-minutes.docx b/presentations/PWM-five-minutes.docx deleted file mode 100644 index 90143f19f..000000000 Binary files a/presentations/PWM-five-minutes.docx and /dev/null differ diff --git a/presentations/Physical-Computing.pptx b/presentations/Physical-Computing.pptx deleted file mode 100644 index 4c5a128a2..000000000 Binary files a/presentations/Physical-Computing.pptx and /dev/null differ diff --git a/presentations/Pico-Pin-Layout.pptx b/presentations/Pico-Pin-Layout.pptx deleted file mode 100644 index 2162c0b8e..000000000 Binary files a/presentations/Pico-Pin-Layout.pptx and /dev/null differ diff --git a/presentations/Robot-Badge-Checklist-23.pptx b/presentations/Robot-Badge-Checklist-23.pptx deleted file mode 100644 index e6728153b..000000000 Binary files a/presentations/Robot-Badge-Checklist-23.pptx and /dev/null differ diff --git a/presentations/Robot-Badge-Checklist.pptx b/presentations/Robot-Badge-Checklist.pptx deleted file mode 100644 index 260dde372..000000000 Binary files a/presentations/Robot-Badge-Checklist.pptx and /dev/null differ diff --git a/presentations/Robot-Batteries.pptx b/presentations/Robot-Batteries.pptx deleted file mode 100644 index eedc4bcb2..000000000 Binary files a/presentations/Robot-Batteries.pptx and /dev/null differ diff --git a/presentations/Robot-Certificate-FIgures-v2.pptx b/presentations/Robot-Certificate-FIgures-v2.pptx deleted file mode 100644 index 802540d19..000000000 Binary files a/presentations/Robot-Certificate-FIgures-v2.pptx and /dev/null differ diff --git a/presentations/Robot-Certificate-FIgures-v3.pptx b/presentations/Robot-Certificate-FIgures-v3.pptx deleted file mode 100644 index 7d8640f6f..000000000 Binary files a/presentations/Robot-Certificate-FIgures-v3.pptx and /dev/null differ diff --git a/presentations/Robot-Lab-Signs.pptx b/presentations/Robot-Lab-Signs.pptx deleted file mode 100644 index cafe36501..000000000 Binary files a/presentations/Robot-Lab-Signs.pptx and /dev/null differ diff --git a/presentations/Robot-MicroControllers-Poster.pptx b/presentations/Robot-MicroControllers-Poster.pptx deleted file mode 100644 index 84dba2504..000000000 Binary files a/presentations/Robot-MicroControllers-Poster.pptx and /dev/null differ diff --git a/presentations/Robot-Sensors-Poster.pptx b/presentations/Robot-Sensors-Poster.pptx deleted file mode 100644 index 6882b1185..000000000 Binary files a/presentations/Robot-Sensors-Poster.pptx and /dev/null differ diff --git a/presentations/Robot_Figures.pptx b/presentations/Robot_Figures.pptx deleted file mode 100644 index d954e122a..000000000 Binary files a/presentations/Robot_Figures.pptx and /dev/null differ diff --git a/presentations/Sensor-Board-Back.docx b/presentations/Sensor-Board-Back.docx deleted file mode 100644 index 914cb8b8f..000000000 Binary files a/presentations/Sensor-Board-Back.docx and /dev/null differ diff --git a/presentations/We-Love-AI.pptx b/presentations/We-Love-AI.pptx deleted file mode 100644 index 6704b0f59..000000000 Binary files a/presentations/We-Love-AI.pptx and /dev/null differ diff --git a/presentations/badge-labels-2X5.pptx b/presentations/badge-labels-2X5.pptx deleted file mode 100644 index d1f76d02f..000000000 Binary files a/presentations/badge-labels-2X5.pptx and /dev/null differ diff --git a/presentations/dodge-badge-labels-2X5.pptx b/presentations/dodge-badge-labels-2X5.pptx deleted file mode 100644 index 2bb021a9e..000000000 Binary files a/presentations/dodge-badge-labels-2X5.pptx and /dev/null differ diff --git a/presentations/qr-codes.pptx b/presentations/qr-codes.pptx deleted file mode 100644 index bfef53fbf..000000000 Binary files a/presentations/qr-codes.pptx and /dev/null differ diff --git a/presentations/source-code.pptx b/presentations/source-code.pptx deleted file mode 100644 index ea6195d5c..000000000 Binary files a/presentations/source-code.pptx and /dev/null differ diff --git a/projects/01-intro/index.html b/projects/01-intro/index.html new file mode 100644 index 000000000..98c1e3bd6 --- /dev/null +++ b/projects/01-intro/index.html @@ -0,0 +1,1318 @@ + + + + + + + + + + + + + + + + + + + + + + + MicroPython Projects - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + MicroPython Projects + + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                          • + + + RGB Box for Kids + + + +
                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                          • + + + Alarm Clock + + + +
                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                          MicroPython Projects

                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                          RGB Box for Kids

                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                          This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors.

                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                          Alarm Clock

                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                          https://github.com/wahlencraft/pico-alarm-clock

                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/projects/02-rgb-box/index.html b/projects/02-rgb-box/index.html new file mode 100644 index 000000000..1cf841122 --- /dev/null +++ b/projects/02-rgb-box/index.html @@ -0,0 +1,1439 @@ + + + + + + + + + + + + + + + + + + + + + + + Raspberry Pi RGB Box - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + Raspberry Pi RGB Box + + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                            • + + + Related Labs + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + Required Tools + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + Parts List + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + Circuit Diagram + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + Assembly + + + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                              • + + + Test the NeoPixel Connection + + + +
                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                            Raspberry Pi RGB Box

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            RGB Box

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors. We use this at many science fairs or demonstration projects that has kids as young as three years old! As the kids learn to adjust the knobs, we say "Hey, your a programmer!".

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Related Labs

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Before you do this project, it is a good idea to get familiar with the Potentiometer lab. This lab will show you how to hook up a single potentiometer to the Raspberry Pi Pico and read it's values.

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Required Tools

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Although we will be using a solderless breadboard to connect the components, we use a hot-glue gun to make sure the wires don't get dislocated when the box gets bumped around.

                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                            1. Soldering iron (unless you have pre-solders potentiometers)
                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                            3. Hot glue gun (for securing the wires to the breadboard)
                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                            5. Drill (for putting a hole in the box)
                                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Parts List

                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                            1. Raspberry Pi Pico with headers ($4)
                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                            3. 1/2 size breadboard ($2)
                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                            5. Three 10K linear potentiometers ($2)
                                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                                            7. LED strip with 10 NeoPixels ($2)
                                                                                                                                                                                                                                                                                            8. +
                                                                                                                                                                                                                                                                                            9. Battery case with 3 AA batteries (2)
                                                                                                                                                                                                                                                                                            10. +
                                                                                                                                                                                                                                                                                            11. 22-gauge solid hookup wire
                                                                                                                                                                                                                                                                                            12. +
                                                                                                                                                                                                                                                                                            13. Power switch (optional) (50 cents)
                                                                                                                                                                                                                                                                                            14. +
                                                                                                                                                                                                                                                                                            15. Clear plastic box (4)
                                                                                                                                                                                                                                                                                            16. +
                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            With a bit of clever shopping, you can get the total part costs: under about $15. If you purchase the parts in Quantity 10+ you can get the costs under $10/kit.

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Circuit Diagram

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            TBD

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Assembly

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Solder six-inches of hookup wire to each of the three pins on the three potentiometers.

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Potentiometer Hookups

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Sample Code

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Test the NeoPixel Connection

                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            Our first step will be to verify we have the NeoPixel strip connected correctly and that we have the right configuration. There are two items you might have to change:

                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                            1. The pin number connected to the data wire of the LED strip
                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                            3. The number of pixels
                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            We use two Python variables to configure +

                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                            NEOPIXEL_PIN = 0
                                                                                                                                                                                                                                                                                            +NUMBER_PIXELS = 10
                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                             1
                                                                                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                                                                                            +17
                                                                                                                                                                                                                                                                                            import machine, neopixel
                                                                                                                                                                                                                                                                                            +from utime import sleep
                                                                                                                                                                                                                                                                                            +from neopixel import Neopixel
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +NEOPIXEL_PIN = 0
                                                                                                                                                                                                                                                                                            +NUMBER_PIXELS = 10
                                                                                                                                                                                                                                                                                            +strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB")
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +print('flashing pixel 0 red')
                                                                                                                                                                                                                                                                                            +delay=.3
                                                                                                                                                                                                                                                                                            +while True:
                                                                                                                                                                                                                                                                                            +    strip.set_pixel(0, (255,0,0)) // turn pixel 0 red
                                                                                                                                                                                                                                                                                            +    strip.show()
                                                                                                                                                                                                                                                                                            +    sleep(delay)
                                                                                                                                                                                                                                                                                            +    strip.set_pixel(0, (0,0,0)) // turn pixel 0 off
                                                                                                                                                                                                                                                                                            +    strip.show()
                                                                                                                                                                                                                                                                                            +    sleep(delay)
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/projects/03-neopixel-strip-two-buttons/index.html b/projects/03-neopixel-strip-two-buttons/index.html new file mode 100644 index 000000000..4e6844a2d --- /dev/null +++ b/projects/03-neopixel-strip-two-buttons/index.html @@ -0,0 +1,1411 @@ + + + + + + + + + + + + + + + + + + + + + + + NeoPixel Two Button Kit - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + NeoPixel Two Button Kit + + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                              • + + + Contents + + + +
                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                              • + + + Background + + + +
                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                              • + + + Labs + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                • + + + Blink + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                • + + + Move + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                • + + + Fade In and Out + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                              NeoPixel Two Button Kit

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              This is a low-cost (around $10) kit that is used for hackathons and activities such as a Halloween costume contest.

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Contents

                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico with Headers
                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                              3. Breadboard
                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                              5. NeoPixel Strip (ideally a 1 meter strip with 60 pixels)
                                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                                              7. Two momentary push buttons
                                                                                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Background

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              See the Basic Example for the NeoPixel Strip lab.

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Labs

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              We supply a small set of "getting started" labs to demonstrate how +to program colors on the LED strip and give the perception of +motion up and down the strip.

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Blink

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Move

                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                              Fade In and Out

                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                              +18
                                                                                                                                                                                                                                                                                              +19
                                                                                                                                                                                                                                                                                              from neopixel import NeoPixel
                                                                                                                                                                                                                                                                                              +from time import sleep
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +NUMBER_PIXELS = 60
                                                                                                                                                                                                                                                                                              +LED_PIN = 0
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +strip = NeoPixel(machine.Pin(LED_PIN), NUMBER_PIXELS)
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +delay = .005
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +while True:
                                                                                                                                                                                                                                                                                              +    for i in range(0, 255):
                                                                                                                                                                                                                                                                                              +        strip[0] = (i,0,0) # red=255, green and blue are 0
                                                                                                                                                                                                                                                                                              +        strip.write() # send the data from RAM down the wire
                                                                                                                                                                                                                                                                                              +        sleep(delay) # keep on 1/10 of a second
                                                                                                                                                                                                                                                                                              +    for i in range(255, 0, -1):
                                                                                                                                                                                                                                                                                              +        strip[0] = (i,0,0) # red=255, green and blue are 0
                                                                                                                                                                                                                                                                                              +        strip.write() # send the data from RAM down the wire
                                                                                                                                                                                                                                                                                              +        sleep(delay) # keep on 1/10 of a second
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/projects/03-rotary-neopixel/index.html b/projects/03-rotary-neopixel/index.html new file mode 100644 index 000000000..b4deac847 --- /dev/null +++ b/projects/03-rotary-neopixel/index.html @@ -0,0 +1,1574 @@ + + + + + + + + + + + + + + + + + + + + + + + Rotary NeoPixel - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + Rotary NeoPixel + + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                • + + + Full Source Code + + + +
                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                Rotary NeoPixel

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                This project has a rotary encoder and a button. Spinning the rotary encoder changes the pixel index. Pressing the knob of the encoder changes the color. Pressing the button changes the pattern.

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                Circuit

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                We connect the two ends of the rotary (A and B) to pins 14 and 15. We connect the center pin to the 3.3v rail of the breadboard.

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                Next, we connect the rotary button and the other button to pins 16 and 17 and to the 3.3v rail.

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                All the buttons use PULL.DOWN option when they are configured.

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                Sample Code

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                We use the rotary.py library

                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                +6
                                                                                                                                                                                                                                                                                                +7
                                                                                                                                                                                                                                                                                                from machine import Pin
                                                                                                                                                                                                                                                                                                +from rotary import Rotary
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +ENCODER_A = 15
                                                                                                                                                                                                                                                                                                +ENCODER_B = 14
                                                                                                                                                                                                                                                                                                +SWITCH = 17
                                                                                                                                                                                                                                                                                                +rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                You can change the order of A and B to match the turn direction.

                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                Full Source Code

                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                +  2
                                                                                                                                                                                                                                                                                                +  3
                                                                                                                                                                                                                                                                                                +  4
                                                                                                                                                                                                                                                                                                +  5
                                                                                                                                                                                                                                                                                                +  6
                                                                                                                                                                                                                                                                                                +  7
                                                                                                                                                                                                                                                                                                +  8
                                                                                                                                                                                                                                                                                                +  9
                                                                                                                                                                                                                                                                                                + 10
                                                                                                                                                                                                                                                                                                + 11
                                                                                                                                                                                                                                                                                                + 12
                                                                                                                                                                                                                                                                                                + 13
                                                                                                                                                                                                                                                                                                + 14
                                                                                                                                                                                                                                                                                                + 15
                                                                                                                                                                                                                                                                                                + 16
                                                                                                                                                                                                                                                                                                + 17
                                                                                                                                                                                                                                                                                                + 18
                                                                                                                                                                                                                                                                                                + 19
                                                                                                                                                                                                                                                                                                + 20
                                                                                                                                                                                                                                                                                                + 21
                                                                                                                                                                                                                                                                                                + 22
                                                                                                                                                                                                                                                                                                + 23
                                                                                                                                                                                                                                                                                                + 24
                                                                                                                                                                                                                                                                                                + 25
                                                                                                                                                                                                                                                                                                + 26
                                                                                                                                                                                                                                                                                                + 27
                                                                                                                                                                                                                                                                                                + 28
                                                                                                                                                                                                                                                                                                + 29
                                                                                                                                                                                                                                                                                                + 30
                                                                                                                                                                                                                                                                                                + 31
                                                                                                                                                                                                                                                                                                + 32
                                                                                                                                                                                                                                                                                                + 33
                                                                                                                                                                                                                                                                                                + 34
                                                                                                                                                                                                                                                                                                + 35
                                                                                                                                                                                                                                                                                                + 36
                                                                                                                                                                                                                                                                                                + 37
                                                                                                                                                                                                                                                                                                + 38
                                                                                                                                                                                                                                                                                                + 39
                                                                                                                                                                                                                                                                                                + 40
                                                                                                                                                                                                                                                                                                + 41
                                                                                                                                                                                                                                                                                                + 42
                                                                                                                                                                                                                                                                                                + 43
                                                                                                                                                                                                                                                                                                + 44
                                                                                                                                                                                                                                                                                                + 45
                                                                                                                                                                                                                                                                                                + 46
                                                                                                                                                                                                                                                                                                + 47
                                                                                                                                                                                                                                                                                                + 48
                                                                                                                                                                                                                                                                                                + 49
                                                                                                                                                                                                                                                                                                + 50
                                                                                                                                                                                                                                                                                                + 51
                                                                                                                                                                                                                                                                                                + 52
                                                                                                                                                                                                                                                                                                + 53
                                                                                                                                                                                                                                                                                                + 54
                                                                                                                                                                                                                                                                                                + 55
                                                                                                                                                                                                                                                                                                + 56
                                                                                                                                                                                                                                                                                                + 57
                                                                                                                                                                                                                                                                                                + 58
                                                                                                                                                                                                                                                                                                + 59
                                                                                                                                                                                                                                                                                                + 60
                                                                                                                                                                                                                                                                                                + 61
                                                                                                                                                                                                                                                                                                + 62
                                                                                                                                                                                                                                                                                                + 63
                                                                                                                                                                                                                                                                                                + 64
                                                                                                                                                                                                                                                                                                + 65
                                                                                                                                                                                                                                                                                                + 66
                                                                                                                                                                                                                                                                                                + 67
                                                                                                                                                                                                                                                                                                + 68
                                                                                                                                                                                                                                                                                                + 69
                                                                                                                                                                                                                                                                                                + 70
                                                                                                                                                                                                                                                                                                + 71
                                                                                                                                                                                                                                                                                                + 72
                                                                                                                                                                                                                                                                                                + 73
                                                                                                                                                                                                                                                                                                + 74
                                                                                                                                                                                                                                                                                                + 75
                                                                                                                                                                                                                                                                                                + 76
                                                                                                                                                                                                                                                                                                + 77
                                                                                                                                                                                                                                                                                                + 78
                                                                                                                                                                                                                                                                                                + 79
                                                                                                                                                                                                                                                                                                + 80
                                                                                                                                                                                                                                                                                                + 81
                                                                                                                                                                                                                                                                                                + 82
                                                                                                                                                                                                                                                                                                + 83
                                                                                                                                                                                                                                                                                                + 84
                                                                                                                                                                                                                                                                                                + 85
                                                                                                                                                                                                                                                                                                + 86
                                                                                                                                                                                                                                                                                                + 87
                                                                                                                                                                                                                                                                                                + 88
                                                                                                                                                                                                                                                                                                + 89
                                                                                                                                                                                                                                                                                                + 90
                                                                                                                                                                                                                                                                                                + 91
                                                                                                                                                                                                                                                                                                + 92
                                                                                                                                                                                                                                                                                                + 93
                                                                                                                                                                                                                                                                                                + 94
                                                                                                                                                                                                                                                                                                + 95
                                                                                                                                                                                                                                                                                                + 96
                                                                                                                                                                                                                                                                                                + 97
                                                                                                                                                                                                                                                                                                + 98
                                                                                                                                                                                                                                                                                                + 99
                                                                                                                                                                                                                                                                                                +100
                                                                                                                                                                                                                                                                                                +101
                                                                                                                                                                                                                                                                                                +102
                                                                                                                                                                                                                                                                                                +103
                                                                                                                                                                                                                                                                                                +104
                                                                                                                                                                                                                                                                                                +105
                                                                                                                                                                                                                                                                                                +106
                                                                                                                                                                                                                                                                                                +107
                                                                                                                                                                                                                                                                                                +108
                                                                                                                                                                                                                                                                                                +109
                                                                                                                                                                                                                                                                                                +110
                                                                                                                                                                                                                                                                                                +111
                                                                                                                                                                                                                                                                                                +112
                                                                                                                                                                                                                                                                                                +113
                                                                                                                                                                                                                                                                                                +114
                                                                                                                                                                                                                                                                                                from machine import Pin
                                                                                                                                                                                                                                                                                                +from rotary import Rotary
                                                                                                                                                                                                                                                                                                +from utime import sleep, ticks_ms
                                                                                                                                                                                                                                                                                                +from neopixel import NeoPixel
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +NEOPIXEL_PIN = 0
                                                                                                                                                                                                                                                                                                +NUMBER_PIXELS = 12
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch.
                                                                                                                                                                                                                                                                                                +ENCODER_A = 15
                                                                                                                                                                                                                                                                                                +ENCODER_B = 14
                                                                                                                                                                                                                                                                                                +SWITCH = 17
                                                                                                                                                                                                                                                                                                +rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                +mode = 0 # mode to display
                                                                                                                                                                                                                                                                                                +mode_names = ['dot', 'hole', 'compare', 'chase', 'rainbow']
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +button_presses = 0 # the count of times the button has been pressed
                                                                                                                                                                                                                                                                                                +last_time = 0 # the last time we pressed the button
                                                                                                                                                                                                                                                                                                +def button_pressed_handler(pin):
                                                                                                                                                                                                                                                                                                +    global button_presses, last_time, mode
                                                                                                                                                                                                                                                                                                +    new_time = ticks_ms()
                                                                                                                                                                                                                                                                                                +    # if it has been more that 1/5 of a second since the last event, we have a new event
                                                                                                                                                                                                                                                                                                +    if (new_time - last_time) > 200: 
                                                                                                                                                                                                                                                                                                +        mode +=1
                                                                                                                                                                                                                                                                                                +        last_time = new_time
                                                                                                                                                                                                                                                                                                +    # make mode 0 or 1
                                                                                                                                                                                                                                                                                                +    mode = mode % 5
                                                                                                                                                                                                                                                                                                +    print('mode=', mode, mode_names[mode])
                                                                                                                                                                                                                                                                                                +# now we register the handler function when the button is pressed
                                                                                                                                                                                                                                                                                                +button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +val = 0 # value of the LED strip index set by the rotary know
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +red = (255, 0, 0)
                                                                                                                                                                                                                                                                                                +orange = (140, 60, 0)
                                                                                                                                                                                                                                                                                                +yellow = (255, 255, 0)
                                                                                                                                                                                                                                                                                                +green = (0, 255, 0)
                                                                                                                                                                                                                                                                                                +blue = (0, 0, 255)
                                                                                                                                                                                                                                                                                                +cyan = (0, 255, 255)
                                                                                                                                                                                                                                                                                                +indigo = (75, 0, 130)
                                                                                                                                                                                                                                                                                                +violet = (138, 43, 226)
                                                                                                                                                                                                                                                                                                +white = (128, 128, 128)
                                                                                                                                                                                                                                                                                                +colors = (red, orange, yellow, green, blue, cyan, indigo, violet)
                                                                                                                                                                                                                                                                                                +color_count = len(colors)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +# this function is called whenever the rotory is changed
                                                                                                                                                                                                                                                                                                +def rotary_changed(change):
                                                                                                                                                                                                                                                                                                +    global val, button_press, color_index
                                                                                                                                                                                                                                                                                                +    if change == Rotary.ROT_CW:
                                                                                                                                                                                                                                                                                                +        val = val + 1
                                                                                                                                                                                                                                                                                                +    elif change == Rotary.ROT_CCW:
                                                                                                                                                                                                                                                                                                +        val = val - 1      
                                                                                                                                                                                                                                                                                                +    elif change == Rotary.SW_PRESS:
                                                                                                                                                                                                                                                                                                +        print('PRESS')
                                                                                                                                                                                                                                                                                                +        # button_press = 1
                                                                                                                                                                                                                                                                                                +    elif change == Rotary.SW_RELEASE:
                                                                                                                                                                                                                                                                                                +        print('RELEASE')
                                                                                                                                                                                                                                                                                                +        color_index += 1
                                                                                                                                                                                                                                                                                                +        color_index = color_index % (color_count - 1)
                                                                                                                                                                                                                                                                                                +    val = val % NUMBER_PIXELS
                                                                                                                                                                                                                                                                                                +    print(val) 
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +rotary.add_handler(rotary_changed)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +color_index = 0
                                                                                                                                                                                                                                                                                                +color = red
                                                                                                                                                                                                                                                                                                +while True:
                                                                                                                                                                                                                                                                                                +    if mode == 0:
                                                                                                                                                                                                                                                                                                +        for i in range(0, NUMBER_PIXELS):
                                                                                                                                                                                                                                                                                                +            if i == val:
                                                                                                                                                                                                                                                                                                +                strip[i] = color
                                                                                                                                                                                                                                                                                                +            else:
                                                                                                                                                                                                                                                                                                +                strip[i] = (0,0,0)
                                                                                                                                                                                                                                                                                                +    elif mode == 1:
                                                                                                                                                                                                                                                                                                +        for i in range(0, NUMBER_PIXELS):
                                                                                                                                                                                                                                                                                                +            if i == val:
                                                                                                                                                                                                                                                                                                +                strip[i] = (0,0,0)
                                                                                                                                                                                                                                                                                                +            else:
                                                                                                                                                                                                                                                                                                +                strip[i] = color
                                                                                                                                                                                                                                                                                                +    elif mode == 2:
                                                                                                                                                                                                                                                                                                +        for i in range(0, NUMBER_PIXELS):
                                                                                                                                                                                                                                                                                                +            if i > val:
                                                                                                                                                                                                                                                                                                +                strip[i] = (0,0,0)
                                                                                                                                                                                                                                                                                                +            else:
                                                                                                                                                                                                                                                                                                +                strip[i] = color
                                                                                                                                                                                                                                                                                                +    elif mode == 3:
                                                                                                                                                                                                                                                                                                +        for i in range(0, NUMBER_PIXELS):
                                                                                                                                                                                                                                                                                                +            if (i-val) % 3:
                                                                                                                                                                                                                                                                                                +                strip[i] = (0,0,0)
                                                                                                                                                                                                                                                                                                +            else:
                                                                                                                                                                                                                                                                                                +                strip[i] = color    
                                                                                                                                                                                                                                                                                                +    elif mode == 4:
                                                                                                                                                                                                                                                                                                +        # if the val + offset is larger than the number of pixels we need to do a modulo
                                                                                                                                                                                                                                                                                                +        strip[val     % (NUMBER_PIXELS)] = violet
                                                                                                                                                                                                                                                                                                +        strip[(val+1) % (NUMBER_PIXELS)] = indigo
                                                                                                                                                                                                                                                                                                +        strip[(val+2) % (NUMBER_PIXELS)] = blue
                                                                                                                                                                                                                                                                                                +        strip[(val+3) % (NUMBER_PIXELS)] = green
                                                                                                                                                                                                                                                                                                +        strip[(val+4) % (NUMBER_PIXELS)] = yellow
                                                                                                                                                                                                                                                                                                +        strip[(val+5) % (NUMBER_PIXELS)] = orange
                                                                                                                                                                                                                                                                                                +        strip[(val+6) % (NUMBER_PIXELS)] = red
                                                                                                                                                                                                                                                                                                +        # turn off the rest
                                                                                                                                                                                                                                                                                                +        strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0)
                                                                                                                                                                                                                                                                                                +        strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0)
                                                                                                                                                                                                                                                                                                +        strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0)
                                                                                                                                                                                                                                                                                                +        strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0)
                                                                                                                                                                                                                                                                                                +        strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0)
                                                                                                                                                                                                                                                                                                +    strip.write()
                                                                                                                                                                                                                                                                                                +    # print('color index', color_index)
                                                                                                                                                                                                                                                                                                +    color = colors[color_index]
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index da1fc5f53..000000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -certifi==2021.5.30 -click==8.0.1 -numpy==1.24.2 -plotly==5.13.0 -pyserial==3.5 -python-dotenv==0.19.0 -pyudev==0.22.0 -rshell==0.0.30 -six==1.16.0 -tenacity==8.2.1 \ No newline at end of file diff --git a/robots/02-base-bot/index.html b/robots/02-base-bot/index.html new file mode 100644 index 000000000..1e1f33872 --- /dev/null +++ b/robots/02-base-bot/index.html @@ -0,0 +1,2590 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Base Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + Base Bot + + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                                                                                    + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Base Bot + + + + + + + +
                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + + + Base Robot Design + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Video + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Connection Diagram + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Power Regulation + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Hardware Description + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                        • + + + Two Wheel Drive Smart Car Chassis + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Motor Driver + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Software + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                        • + + + Time-of-Flight Distance Sensor + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Testing the Sensor Connections with the I2C Scanner + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Download the VL53L0X Driver + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Time-of-Flight Sensor Test + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Motor Drive Test + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Sample Drive and Turn Functions + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Turning Logic + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Test Motor Connections + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Drive Functions + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Stop All Motors Program + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Collision Avoidance Logic + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Final Program + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + More To Explore Labs + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                  • + + + Base Robot Design + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Video + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Connection Diagram + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Power Regulation + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Hardware Description + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                    • + + + Two Wheel Drive Smart Car Chassis + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Motor Driver + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Software + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                    • + + + Time-of-Flight Distance Sensor + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Testing the Sensor Connections with the I2C Scanner + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Download the VL53L0X Driver + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Time-of-Flight Sensor Test + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Motor Drive Test + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Sample Drive and Turn Functions + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Turning Logic + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Test Motor Connections + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Drive Functions + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Stop All Motors Program + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Collision Avoidance Logic + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + Final Program + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  • + + + More To Explore Labs + + + +
                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                  Raspberry Pi Pico Micropython Base Robot

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  This lesson describes our base robot kit in the CoderDojo Twin Cities coding club. This robot is programmed entirely in Python to be consistent with our Python Courses.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Base Robot Design

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Our goal is to build a robotics platform for teaching computational thinking. Here are our main design goals:

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                  1. Low cost (under $25) so that most students can afford their own robot
                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                  3. Open platform to make it easy to upgrade (sustainably)
                                                                                                                                                                                                                                                                                                  4. +
                                                                                                                                                                                                                                                                                                  5. Interchangeable parts
                                                                                                                                                                                                                                                                                                  6. +
                                                                                                                                                                                                                                                                                                  7. Minimal amount of soldering
                                                                                                                                                                                                                                                                                                  8. +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Video

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Here is a video of the collision avoidance robot in action:

                                                                                                                                                                                                                                                                                                  + + +

                                                                                                                                                                                                                                                                                                  YouTube Video

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Note that the forward-speed and distance-before-you-turn can be adjusted. You can see I didn't quite get the distance right and the robot bumps into some of the barriers.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Connection Diagram

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Here is a connection diagram of the base robot.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Power Regulation

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Note that the power comes from the battery at 6 volts and is connected to the input voltage of the motor controller board. The motor controller has a voltage regulator that converts any input voltage from 6 to 12 volts down to 5 volts. The output voltage of the motor controller is then connected to the power rail on the left, which is in turn connected to the VSYS input to the Pico. The Pico, in turn, has another voltage regulator that drop the input from VSYS down to 3.3 volts on the 3.3V OUT pin. This voltage is then used to power the distance sensor.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  One of the downsides to this design is that as the batteries get low, once they drop below around 5 volts the double voltage drops cause the 3.3 OUT to become too low and the sensor becomes unreliable. A better design would be to find a motor controller that produces a stable 3.3 volts as the batteries slowly run down. Let us know if you can find one of these designs that cost under $2.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Hardware Description

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Here is a summary of some of the parts we use in this robot and their approximate prices as of June 2021. Some parts come from China so you might need to wait 2-3 weeks for them to arrive.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Here is a Google sheet with these parts:

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Detailed Parts List Google Sheet

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Two Wheel Drive Smart Car Chassis

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Our cars all use a standard Two Wheel Drive (2WD) SmartCar Chassis that is available in many retail outlets online.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                  • $5 Cytron 2WD Smart Car Chassis
                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                  • YouTube Video of Assembly - note that he does not remove the backing paper on the Plexiglass and he mounts the battery on the top. We like ours on the bottom.
                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Motor Driver

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Software

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  All software is written in MicroPython.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Time-of-Flight Distance Sensor

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  We are using the VL53L0X time-of-flight distance sensor. This works on an I2C bus. After you have hooked up the Power (VCC to the 3.3 rail and GND) you must hook up the I2C data and clock.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                                                  sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top
                                                                                                                                                                                                                                                                                                  +scl=machine.Pin(17) # One up from the lower right corner of the Pico
                                                                                                                                                                                                                                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Many of our older robots used the ultrasonic ping sensors. The are unreliable with voltage drops as our batteries wear down.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Testing the Sensor Connections with the I2C Scanner

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                                                  +4
                                                                                                                                                                                                                                                                                                  +5
                                                                                                                                                                                                                                                                                                  import machine
                                                                                                                                                                                                                                                                                                  +sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top
                                                                                                                                                                                                                                                                                                  +scl=machine.Pin(17) # One up from the lower right corner of the Pico
                                                                                                                                                                                                                                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl)
                                                                                                                                                                                                                                                                                                  +print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  You should see a decimal number returned. By default the I2C address is 41 (decimal) or x29 (hexadecimal).

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Download the VL53L0X Driver

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  You will need to add a VL53L0X driver file to the file system on the pico.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  We have a copy here: https://raw.githubusercontent.com/CoderDojoTC/micropython/main/src/drivers/VL53L0X.py

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Time-of-Flight Sensor Test

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Once the driver file is loaded we are ready to test the time-of-flight distance sensor.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  import time
                                                                                                                                                                                                                                                                                                  +from machine import Pin
                                                                                                                                                                                                                                                                                                  +from machine import I2C
                                                                                                                                                                                                                                                                                                  +import VL53L0X
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +sda=machine.Pin(16) # row one on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                  +scl=machine.Pin(17) # row two on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# Create a VL53L0X object
                                                                                                                                                                                                                                                                                                  +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                                                                                                  +tof.start() # startup the sensor
                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                  +# Start ranging
                                                                                                                                                                                                                                                                                                  +    dist = tof.read()
                                                                                                                                                                                                                                                                                                  +    print(dist)
                                                                                                                                                                                                                                                                                                  +    time.sleep(.1)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  When you run this program a sequence of integers will appear in the console. The numbers usually will range from around 30 if there is an object directly in front of the sensor to a number around 1,300 for a object that is about 1.3 meters away from the sensor. There is a 1/10th of a second pause between each measurement. This can be changed in the last line of the program.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Motor Drive Test

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  After we have the four wires connected to the motor driver, we need to make sure we get the right wires to the right motors and motor directions. This program will help you debug this.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                  +import time # sleep
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +POWER_LEVEL = 65025
                                                                                                                                                                                                                                                                                                  +# lower right pins with USB on top
                                                                                                                                                                                                                                                                                                  +RIGHT_FORWARD_PIN = 21
                                                                                                                                                                                                                                                                                                  +RIGHT_REVERSE_PIN = 20
                                                                                                                                                                                                                                                                                                  +LEFT_FORWARD_PIN = 18
                                                                                                                                                                                                                                                                                                  +LEFT_REVERSE_PIN = 19
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def spin_wheel(pwm):
                                                                                                                                                                                                                                                                                                  +        pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                  +        time.sleep(3)
                                                                                                                                                                                                                                                                                                  +        pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +        time.sleep(2)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                  +    print('right forward')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(right_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('right reverse')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(right_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('left foward')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('left_reverse')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  One thing to remember is that the "Right" refers to our orientation from the rear of the car or if we were sitting inside the car. If the robot is facing you with the sensor in the front, it is the wheel on the left that we call the "RIGHT" wheel. Very confusing! Using this naming convention will pay of as we are walking behind larger robots.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Sample Drive and Turn Functions

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  We will need a set of function to drive our robot:

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                  1. Forward: both wheels going forward
                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                  3. Reverse: both wheels going in reverse
                                                                                                                                                                                                                                                                                                  4. +
                                                                                                                                                                                                                                                                                                  5. Turn Right: The right wheel turning backward and the left going forward
                                                                                                                                                                                                                                                                                                  6. +
                                                                                                                                                                                                                                                                                                  7. Turn Left: The left wheel turning backward and the right wheel going forward
                                                                                                                                                                                                                                                                                                  8. +
                                                                                                                                                                                                                                                                                                  9. Stop: all motors off
                                                                                                                                                                                                                                                                                                  10. +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Our challenge is for each of these operations we must change the value of all four PWM signals. We can never have a motor be going both forward and reverse. Here are some sample drive functions:

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                  +35
                                                                                                                                                                                                                                                                                                  def turn_motor_on(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_motor_off(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def forward():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def reverse():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_right():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_left():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def stop():
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Turning Logic

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  while True:
                                                                                                                                                                                                                                                                                                  +    dist = read_sensor() 
                                                                                                                                                                                                                                                                                                  +    if dist < TURN_THRESHOLD:
                                                                                                                                                                                                                                                                                                  +        print('object detected')
                                                                                                                                                                                                                                                                                                  +        reverse()
                                                                                                                                                                                                                                                                                                  +        sleep(BACKUP_TIME)
                                                                                                                                                                                                                                                                                                  +        turn_right()
                                                                                                                                                                                                                                                                                                  +        sleep(TURN_TIME)
                                                                                                                                                                                                                                                                                                  +    else:
                                                                                                                                                                                                                                                                                                  +        forward()
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Test Motor Connections

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                  +import time # sleep
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +POWER_LEVEL = 65025 # usually a number from 30,000 to max of 65,025
                                                                                                                                                                                                                                                                                                  +# lower right pins with USB on top
                                                                                                                                                                                                                                                                                                  +RIGHT_FORWARD_PIN = 21
                                                                                                                                                                                                                                                                                                  +RIGHT_REVERSE_PIN = 20
                                                                                                                                                                                                                                                                                                  +LEFT_FORWARD_PIN = 18
                                                                                                                                                                                                                                                                                                  +LEFT_REVERSE_PIN = 19
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def spin_wheel(pwm):
                                                                                                                                                                                                                                                                                                  +        pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                  +        time.sleep(3)
                                                                                                                                                                                                                                                                                                  +        pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +        time.sleep(2)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                  +    print('right forward')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(right_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('right reverse')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(right_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('left foward')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    print('left_reverse')
                                                                                                                                                                                                                                                                                                  +    spin_wheel(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  After you load this program, watch which wheels turn and in what direction.

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Drive Functions

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  We will define Python functions for forward, reverse, turn right and turn left.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                  +35
                                                                                                                                                                                                                                                                                                  +36
                                                                                                                                                                                                                                                                                                  +37
                                                                                                                                                                                                                                                                                                  POWER_LEVEL = 65025
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_motor_on(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_motor_off(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def forward():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def reverse():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_right():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_left():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def stop():
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Stop All Motors Program

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  One other thing to remember is that the PWM signals continue to be generated even after the main loop has stopped. This is because on the Pico, the four PWM signals are being continuously generated by an independent processors. To stop the motors you must run a separate stop program like this:

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  stop-all-motors.py:

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                  +from time import sleep
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# lower right pins with USB on top
                                                                                                                                                                                                                                                                                                  +RIGHT_FORWARD_PIN = 19
                                                                                                                                                                                                                                                                                                  +RIGHT_REVERSE_PIN = 21
                                                                                                                                                                                                                                                                                                  +LEFT_FORWARD_PIN = 18
                                                                                                                                                                                                                                                                                                  +LEFT_REVERSE_PIN = 20
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +right_forward.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +right_reverse.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +left_forward.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +left_reverse.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  This can be frustrating at times when you can't find the stop program. I like to bring the stop program up in a separate tab when I am writing robot motor code.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  To

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  figure out how to write an interrup handler so that when the IDE STOP function is pressed the stop motors (and speaker) are stopped.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Collision Avoidance Logic

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Final Program

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  To get this to work on battery power up you must name the program main.py and save it on the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Note

                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  Make sure you have the VL53L0X distance sensor driver installed.

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                  +35
                                                                                                                                                                                                                                                                                                  +36
                                                                                                                                                                                                                                                                                                  +37
                                                                                                                                                                                                                                                                                                  +38
                                                                                                                                                                                                                                                                                                  +39
                                                                                                                                                                                                                                                                                                  +40
                                                                                                                                                                                                                                                                                                  +41
                                                                                                                                                                                                                                                                                                  +42
                                                                                                                                                                                                                                                                                                  +43
                                                                                                                                                                                                                                                                                                  +44
                                                                                                                                                                                                                                                                                                  +45
                                                                                                                                                                                                                                                                                                  +46
                                                                                                                                                                                                                                                                                                  +47
                                                                                                                                                                                                                                                                                                  +48
                                                                                                                                                                                                                                                                                                  +49
                                                                                                                                                                                                                                                                                                  +50
                                                                                                                                                                                                                                                                                                  +51
                                                                                                                                                                                                                                                                                                  +52
                                                                                                                                                                                                                                                                                                  +53
                                                                                                                                                                                                                                                                                                  +54
                                                                                                                                                                                                                                                                                                  +55
                                                                                                                                                                                                                                                                                                  +56
                                                                                                                                                                                                                                                                                                  +57
                                                                                                                                                                                                                                                                                                  +58
                                                                                                                                                                                                                                                                                                  +59
                                                                                                                                                                                                                                                                                                  +60
                                                                                                                                                                                                                                                                                                  +61
                                                                                                                                                                                                                                                                                                  +62
                                                                                                                                                                                                                                                                                                  +63
                                                                                                                                                                                                                                                                                                  +64
                                                                                                                                                                                                                                                                                                  +65
                                                                                                                                                                                                                                                                                                  +66
                                                                                                                                                                                                                                                                                                  +67
                                                                                                                                                                                                                                                                                                  +68
                                                                                                                                                                                                                                                                                                  +69
                                                                                                                                                                                                                                                                                                  +70
                                                                                                                                                                                                                                                                                                  +71
                                                                                                                                                                                                                                                                                                  +72
                                                                                                                                                                                                                                                                                                  +73
                                                                                                                                                                                                                                                                                                  +74
                                                                                                                                                                                                                                                                                                  +75
                                                                                                                                                                                                                                                                                                  +76
                                                                                                                                                                                                                                                                                                  +77
                                                                                                                                                                                                                                                                                                  +78
                                                                                                                                                                                                                                                                                                  +79
                                                                                                                                                                                                                                                                                                  +80
                                                                                                                                                                                                                                                                                                  +81
                                                                                                                                                                                                                                                                                                  +82
                                                                                                                                                                                                                                                                                                  +83
                                                                                                                                                                                                                                                                                                  +84
                                                                                                                                                                                                                                                                                                  +85
                                                                                                                                                                                                                                                                                                  +86
                                                                                                                                                                                                                                                                                                  +87
                                                                                                                                                                                                                                                                                                  +88
                                                                                                                                                                                                                                                                                                  +89
                                                                                                                                                                                                                                                                                                  +90
                                                                                                                                                                                                                                                                                                  +91
                                                                                                                                                                                                                                                                                                  +92
                                                                                                                                                                                                                                                                                                  +93
                                                                                                                                                                                                                                                                                                  +94
                                                                                                                                                                                                                                                                                                  +95
                                                                                                                                                                                                                                                                                                  +96
                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                  +from utime import sleep
                                                                                                                                                                                                                                                                                                  +import VL53L0X
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# used to blink the onboard LED
                                                                                                                                                                                                                                                                                                  +led_onboard = machine.Pin(25, machine.Pin.OUT)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# driving parameters
                                                                                                                                                                                                                                                                                                  +POWER_LEVEL = 65025 # use a value from 20000 to 65025
                                                                                                                                                                                                                                                                                                  +TURN_THRESHOLD = 400 # 25 cm
                                                                                                                                                                                                                                                                                                  +TURN_TIME = .25 # seconds of turning
                                                                                                                                                                                                                                                                                                  +BACKUP_TIME = .75 # seconds of backing up if obstacle detected
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# Motor pins to the L293 H-Bridge
                                                                                                                                                                                                                                                                                                  +RIGHT_FORWARD_PIN = 21
                                                                                                                                                                                                                                                                                                  +RIGHT_REVERSE_PIN = 20
                                                                                                                                                                                                                                                                                                  +LEFT_FORWARD_PIN = 18
                                                                                                                                                                                                                                                                                                  +LEFT_REVERSE_PIN = 19
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# setup the PWM objects
                                                                                                                                                                                                                                                                                                  +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                  +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +sda=machine.Pin(16) # row one on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                  +scl=machine.Pin(17) # row two on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                  +i2c=machine.I2C(0, sda=sda, scl=scl)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +# Create a VL53L0X object
                                                                                                                                                                                                                                                                                                  +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_motor_on(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_motor_off(pwm):
                                                                                                                                                                                                                                                                                                  +   pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def forward():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def reverse():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_right():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def turn_left():
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def stop():
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                  +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +def read_sensor_avg():
                                                                                                                                                                                                                                                                                                  +    total = 0
                                                                                                                                                                                                                                                                                                  +    for i in range(10):
                                                                                                                                                                                                                                                                                                  +        total = total + tof.read()
                                                                                                                                                                                                                                                                                                  +        sleep(.01)
                                                                                                                                                                                                                                                                                                  +    return int(total/10)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +tof.start() # startup the sensor
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                  +    dist = read_sensor_avg();
                                                                                                                                                                                                                                                                                                  +    print(dist)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +    if dist < TURN_THRESHOLD:
                                                                                                                                                                                                                                                                                                  +        print('object detected')
                                                                                                                                                                                                                                                                                                  +        reverse()
                                                                                                                                                                                                                                                                                                  +        sleep(BACKUP_TIME)
                                                                                                                                                                                                                                                                                                  +        led_onboard.high()
                                                                                                                                                                                                                                                                                                  +        turn_right()
                                                                                                                                                                                                                                                                                                  +        sleep(TURN_TIME)
                                                                                                                                                                                                                                                                                                  +    else:
                                                                                                                                                                                                                                                                                                  +        if dist > 1300:
                                                                                                                                                                                                                                                                                                  +            print('no signal')
                                                                                                                                                                                                                                                                                                  +            led_onboard.low()
                                                                                                                                                                                                                                                                                                  +        else:
                                                                                                                                                                                                                                                                                                  +            print('Go forward')
                                                                                                                                                                                                                                                                                                  +            led_onboard.high()
                                                                                                                                                                                                                                                                                                  +        forward()
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                  More To Explore Labs

                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                  1. Can you change the hard-coded parameters at the begging of the program? What happens when you make the POWER_LEVEL go too high and the TURN_THRESHOLD too low?
                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                  3. What is the lowest POWER_LEVEL that will allow the robot to move? What if you changed the power from 6 volts to be 9 volts by adding two more AA batteries?
                                                                                                                                                                                                                                                                                                  4. +
                                                                                                                                                                                                                                                                                                  5. Can you randomly turn right or left if you encounter and object? Note you will need to import the random library and generate a random number between 0 and 2 with the random.randint(0,2) function.
                                                                                                                                                                                                                                                                                                  6. +
                                                                                                                                                                                                                                                                                                  7. How would you design a robot that you could adjust the parameters? What parameters would you change? What would their valid ranges be?
                                                                                                                                                                                                                                                                                                  8. +
                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                  + Introduction +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                  + Rainbow Bot +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/robots/03-ir-sensor-bot/index.html b/robots/03-ir-sensor-bot/index.html new file mode 100644 index 000000000..cae38ab1e --- /dev/null +++ b/robots/03-ir-sensor-bot/index.html @@ -0,0 +1,1969 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + IR Sensor Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + IR Sensor Bot + + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                                                                                      + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + IR Sensor Bot + + + + + + + +
                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                        • + + + Purchasing IR Distance Sensors + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Connecting the IR Sensors + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Connecting the Speaker + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Drive Logic + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                    • + + + Purchasing IR Distance Sensors + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Connecting the IR Sensors + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Connecting the Speaker + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Drive Logic + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                    IR Collision Avoidance Bot

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Instead of our time-of-flight sensor used in our base robot, this robot uses three low-cost IR distance sensors.

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Purchasing IR Distance Sensors

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    IR Distance Sensor

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Connecting the IR Sensors

                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                                                                                    # connections to the three IR distance sensors
                                                                                                                                                                                                                                                                                                    +left = Pin(8, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +center = Pin(7, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +right = Pin(6, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Connecting the Speaker

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    This robot has an optional speaker connected to GPIO Pin 21. This allows us to "hear" what signals are coming into the robot It will generate a different tone if the left, center or right sensor is detecting an object and an different tone for going straight, reversing and turning.

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    The speaker is a small buzzer or a Piezoelectric speaker that can be purchased for around $1. It has one wire connected to the GPIO pin and the other connected to any GND pin or GND rail on the breadboard.

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Here are the lines related to setting up the speaker code. +

                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                    SPEAKER_PIN = 21
                                                                                                                                                                                                                                                                                                    +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                    +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Drive Logic

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    The three IR sensors go LOW if there is an item in front of them. So the statement:

                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                    center.value()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    will normally be HIGH if there is nothing in front of the robot.

                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Our main logic look will look like the following:

                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                                                                                    +5
                                                                                                                                                                                                                                                                                                    +6
                                                                                                                                                                                                                                                                                                    +7
                                                                                                                                                                                                                                                                                                    +8
                                                                                                                                                                                                                                                                                                    +9
                                                                                                                                                                                                                                                                                                    while True:
                                                                                                                                                                                                                                                                                                    +    if left.value()==0:
                                                                                                                                                                                                                                                                                                    +        turn_right()
                                                                                                                                                                                                                                                                                                    +    if center.value()==0:
                                                                                                                                                                                                                                                                                                    +        reverse()
                                                                                                                                                                                                                                                                                                    +    if right.value()==0:
                                                                                                                                                                                                                                                                                                    +        turn_left()
                                                                                                                                                                                                                                                                                                    +    if left.value() and center.value() and right.value():
                                                                                                                                                                                                                                                                                                    +        forward()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Full Program

                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                    +  2
                                                                                                                                                                                                                                                                                                    +  3
                                                                                                                                                                                                                                                                                                    +  4
                                                                                                                                                                                                                                                                                                    +  5
                                                                                                                                                                                                                                                                                                    +  6
                                                                                                                                                                                                                                                                                                    +  7
                                                                                                                                                                                                                                                                                                    +  8
                                                                                                                                                                                                                                                                                                    +  9
                                                                                                                                                                                                                                                                                                    + 10
                                                                                                                                                                                                                                                                                                    + 11
                                                                                                                                                                                                                                                                                                    + 12
                                                                                                                                                                                                                                                                                                    + 13
                                                                                                                                                                                                                                                                                                    + 14
                                                                                                                                                                                                                                                                                                    + 15
                                                                                                                                                                                                                                                                                                    + 16
                                                                                                                                                                                                                                                                                                    + 17
                                                                                                                                                                                                                                                                                                    + 18
                                                                                                                                                                                                                                                                                                    + 19
                                                                                                                                                                                                                                                                                                    + 20
                                                                                                                                                                                                                                                                                                    + 21
                                                                                                                                                                                                                                                                                                    + 22
                                                                                                                                                                                                                                                                                                    + 23
                                                                                                                                                                                                                                                                                                    + 24
                                                                                                                                                                                                                                                                                                    + 25
                                                                                                                                                                                                                                                                                                    + 26
                                                                                                                                                                                                                                                                                                    + 27
                                                                                                                                                                                                                                                                                                    + 28
                                                                                                                                                                                                                                                                                                    + 29
                                                                                                                                                                                                                                                                                                    + 30
                                                                                                                                                                                                                                                                                                    + 31
                                                                                                                                                                                                                                                                                                    + 32
                                                                                                                                                                                                                                                                                                    + 33
                                                                                                                                                                                                                                                                                                    + 34
                                                                                                                                                                                                                                                                                                    + 35
                                                                                                                                                                                                                                                                                                    + 36
                                                                                                                                                                                                                                                                                                    + 37
                                                                                                                                                                                                                                                                                                    + 38
                                                                                                                                                                                                                                                                                                    + 39
                                                                                                                                                                                                                                                                                                    + 40
                                                                                                                                                                                                                                                                                                    + 41
                                                                                                                                                                                                                                                                                                    + 42
                                                                                                                                                                                                                                                                                                    + 43
                                                                                                                                                                                                                                                                                                    + 44
                                                                                                                                                                                                                                                                                                    + 45
                                                                                                                                                                                                                                                                                                    + 46
                                                                                                                                                                                                                                                                                                    + 47
                                                                                                                                                                                                                                                                                                    + 48
                                                                                                                                                                                                                                                                                                    + 49
                                                                                                                                                                                                                                                                                                    + 50
                                                                                                                                                                                                                                                                                                    + 51
                                                                                                                                                                                                                                                                                                    + 52
                                                                                                                                                                                                                                                                                                    + 53
                                                                                                                                                                                                                                                                                                    + 54
                                                                                                                                                                                                                                                                                                    + 55
                                                                                                                                                                                                                                                                                                    + 56
                                                                                                                                                                                                                                                                                                    + 57
                                                                                                                                                                                                                                                                                                    + 58
                                                                                                                                                                                                                                                                                                    + 59
                                                                                                                                                                                                                                                                                                    + 60
                                                                                                                                                                                                                                                                                                    + 61
                                                                                                                                                                                                                                                                                                    + 62
                                                                                                                                                                                                                                                                                                    + 63
                                                                                                                                                                                                                                                                                                    + 64
                                                                                                                                                                                                                                                                                                    + 65
                                                                                                                                                                                                                                                                                                    + 66
                                                                                                                                                                                                                                                                                                    + 67
                                                                                                                                                                                                                                                                                                    + 68
                                                                                                                                                                                                                                                                                                    + 69
                                                                                                                                                                                                                                                                                                    + 70
                                                                                                                                                                                                                                                                                                    + 71
                                                                                                                                                                                                                                                                                                    + 72
                                                                                                                                                                                                                                                                                                    + 73
                                                                                                                                                                                                                                                                                                    + 74
                                                                                                                                                                                                                                                                                                    + 75
                                                                                                                                                                                                                                                                                                    + 76
                                                                                                                                                                                                                                                                                                    + 77
                                                                                                                                                                                                                                                                                                    + 78
                                                                                                                                                                                                                                                                                                    + 79
                                                                                                                                                                                                                                                                                                    + 80
                                                                                                                                                                                                                                                                                                    + 81
                                                                                                                                                                                                                                                                                                    + 82
                                                                                                                                                                                                                                                                                                    + 83
                                                                                                                                                                                                                                                                                                    + 84
                                                                                                                                                                                                                                                                                                    + 85
                                                                                                                                                                                                                                                                                                    + 86
                                                                                                                                                                                                                                                                                                    + 87
                                                                                                                                                                                                                                                                                                    + 88
                                                                                                                                                                                                                                                                                                    + 89
                                                                                                                                                                                                                                                                                                    + 90
                                                                                                                                                                                                                                                                                                    + 91
                                                                                                                                                                                                                                                                                                    + 92
                                                                                                                                                                                                                                                                                                    + 93
                                                                                                                                                                                                                                                                                                    + 94
                                                                                                                                                                                                                                                                                                    + 95
                                                                                                                                                                                                                                                                                                    + 96
                                                                                                                                                                                                                                                                                                    + 97
                                                                                                                                                                                                                                                                                                    + 98
                                                                                                                                                                                                                                                                                                    + 99
                                                                                                                                                                                                                                                                                                    +100
                                                                                                                                                                                                                                                                                                    +101
                                                                                                                                                                                                                                                                                                    +102
                                                                                                                                                                                                                                                                                                    +103
                                                                                                                                                                                                                                                                                                    +104
                                                                                                                                                                                                                                                                                                    +105
                                                                                                                                                                                                                                                                                                    +106
                                                                                                                                                                                                                                                                                                    +107
                                                                                                                                                                                                                                                                                                    +108
                                                                                                                                                                                                                                                                                                    +109
                                                                                                                                                                                                                                                                                                    +110
                                                                                                                                                                                                                                                                                                    +111
                                                                                                                                                                                                                                                                                                    +112
                                                                                                                                                                                                                                                                                                    +113
                                                                                                                                                                                                                                                                                                    +114
                                                                                                                                                                                                                                                                                                    +115
                                                                                                                                                                                                                                                                                                    +116
                                                                                                                                                                                                                                                                                                    +117
                                                                                                                                                                                                                                                                                                    +118
                                                                                                                                                                                                                                                                                                    +119
                                                                                                                                                                                                                                                                                                    +120
                                                                                                                                                                                                                                                                                                    +121
                                                                                                                                                                                                                                                                                                    +122
                                                                                                                                                                                                                                                                                                    +123
                                                                                                                                                                                                                                                                                                    +124
                                                                                                                                                                                                                                                                                                    +125
                                                                                                                                                                                                                                                                                                    +126
                                                                                                                                                                                                                                                                                                    +127
                                                                                                                                                                                                                                                                                                    +128
                                                                                                                                                                                                                                                                                                    +129
                                                                                                                                                                                                                                                                                                    +130
                                                                                                                                                                                                                                                                                                    +131
                                                                                                                                                                                                                                                                                                    +132
                                                                                                                                                                                                                                                                                                    +133
                                                                                                                                                                                                                                                                                                    +134
                                                                                                                                                                                                                                                                                                    +135
                                                                                                                                                                                                                                                                                                    +136
                                                                                                                                                                                                                                                                                                    +137
                                                                                                                                                                                                                                                                                                    +138
                                                                                                                                                                                                                                                                                                    +139
                                                                                                                                                                                                                                                                                                    +140
                                                                                                                                                                                                                                                                                                    +141
                                                                                                                                                                                                                                                                                                    +142
                                                                                                                                                                                                                                                                                                    +143
                                                                                                                                                                                                                                                                                                    +144
                                                                                                                                                                                                                                                                                                    +145
                                                                                                                                                                                                                                                                                                    +146
                                                                                                                                                                                                                                                                                                    +147
                                                                                                                                                                                                                                                                                                    +148
                                                                                                                                                                                                                                                                                                    +149
                                                                                                                                                                                                                                                                                                    +150
                                                                                                                                                                                                                                                                                                    +151
                                                                                                                                                                                                                                                                                                    +152
                                                                                                                                                                                                                                                                                                    +153
                                                                                                                                                                                                                                                                                                    +154
                                                                                                                                                                                                                                                                                                    +155
                                                                                                                                                                                                                                                                                                    from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                    +from utime import sleep
                                                                                                                                                                                                                                                                                                    +import ssd1306
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +# Motor pins to the L293 H-Bridge
                                                                                                                                                                                                                                                                                                    +RIGHT_FORWARD_PIN = 17
                                                                                                                                                                                                                                                                                                    +RIGHT_REVERSE_PIN = 16
                                                                                                                                                                                                                                                                                                    +LEFT_FORWARD_PIN = 18
                                                                                                                                                                                                                                                                                                    +LEFT_REVERSE_PIN = 19
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                    +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                    +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                    +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +# connections to the three IR distance sensors
                                                                                                                                                                                                                                                                                                    +left = Pin(8, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +center = Pin(7, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +right = Pin(6, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +SPEAKER_PIN = 21
                                                                                                                                                                                                                                                                                                    +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                    +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +WIDTH  = 128
                                                                                                                                                                                                                                                                                                    +HEIGHT = 64
                                                                                                                                                                                                                                                                                                    +CS = machine.Pin(1)
                                                                                                                                                                                                                                                                                                    +SCL = machine.Pin(2)
                                                                                                                                                                                                                                                                                                    +SDA = machine.Pin(3)
                                                                                                                                                                                                                                                                                                    +DC = machine.Pin(4)
                                                                                                                                                                                                                                                                                                    +RES = machine.Pin(5)
                                                                                                                                                                                                                                                                                                    +spi=machine.SPI(0, sck=SCL, mosi=SDA)
                                                                                                                                                                                                                                                                                                    +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def turn_motor_on(pwm):
                                                                                                                                                                                                                                                                                                    +   pwm.duty_u16(65025)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def turn_motor_off(pwm):
                                                                                                                                                                                                                                                                                                    +   pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def forward():
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def reverse():
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def turn_right():
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def turn_left():
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                    +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def sound_off():
                                                                                                                                                                                                                                                                                                    +    speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def left_tone():
                                                                                                                                                                                                                                                                                                    +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(700) # 1 Kilohertz
                                                                                                                                                                                                                                                                                                    +    sleep(.5) # wait a 1/4 second
                                                                                                                                                                                                                                                                                                    +    sound_off()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def center_tone():
                                                                                                                                                                                                                                                                                                    +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(900)
                                                                                                                                                                                                                                                                                                    +    sleep(.5)
                                                                                                                                                                                                                                                                                                    +    sound_off()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def right_tone():
                                                                                                                                                                                                                                                                                                    +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(600)
                                                                                                                                                                                                                                                                                                    +    sleep(.5)
                                                                                                                                                                                                                                                                                                    +    sound_off()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def forward_tone():
                                                                                                                                                                                                                                                                                                    +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(400)
                                                                                                                                                                                                                                                                                                    +    sleep(.1)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(900)
                                                                                                                                                                                                                                                                                                    +    sleep(.1)
                                                                                                                                                                                                                                                                                                    +    speaker.freq(1200)
                                                                                                                                                                                                                                                                                                    +    sleep(.1)
                                                                                                                                                                                                                                                                                                    +    sound_off()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +def update_oled():
                                                                                                                                                                                                                                                                                                    +    oled.fill(0)
                                                                                                                                                                                                                                                                                                    +    oled.text("CoderDojo Rocks!", 0, 0, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    oled.text("Left:", 0, 10, 1)
                                                                                                                                                                                                                                                                                                    +    oled.text(str(left.value()), 50, 10, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    oled.text("Center:", 0, 20, 1)
                                                                                                                                                                                                                                                                                                    +    oled.text(str(center.value()), 60, 20, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    oled.text("Right:", 0, 30, 1)
                                                                                                                                                                                                                                                                                                    +    oled.text(str(right.value()), 55, 30, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    BAR_WIDTH = 40
                                                                                                                                                                                                                                                                                                    +    BAR_HEIGHT = 20
                                                                                                                                                                                                                                                                                                    +    if left.value():
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                    +    else:
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    if center.value():
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                    +    else:
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    if right.value():
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                    +    else:
                                                                                                                                                                                                                                                                                                    +        oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    oled.show()
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +# 0=stopped, 1=forward, 2=turing right, 3=turning left
                                                                                                                                                                                                                                                                                                    +drive_state = 0
                                                                                                                                                                                                                                                                                                    +counter = 0
                                                                                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                                                                                    +    if left.value()==0:
                                                                                                                                                                                                                                                                                                    +        print('Left')
                                                                                                                                                                                                                                                                                                    +        #left_tone()
                                                                                                                                                                                                                                                                                                    +        turn_right()
                                                                                                                                                                                                                                                                                                    +        update_oled()
                                                                                                                                                                                                                                                                                                    +        drive_state = 2
                                                                                                                                                                                                                                                                                                    +    if center.value()==0:
                                                                                                                                                                                                                                                                                                    +        print('Center')
                                                                                                                                                                                                                                                                                                    +        center_tone()
                                                                                                                                                                                                                                                                                                    +        reverse()
                                                                                                                                                                                                                                                                                                    +        update_oled()
                                                                                                                                                                                                                                                                                                    +        drive_state = 0
                                                                                                                                                                                                                                                                                                    +    if right.value()==0:
                                                                                                                                                                                                                                                                                                    +        print('Right')
                                                                                                                                                                                                                                                                                                    +        #right_tone()
                                                                                                                                                                                                                                                                                                    +        turn_left()
                                                                                                                                                                                                                                                                                                    +        update_oled()
                                                                                                                                                                                                                                                                                                    +        drive_state = 3
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +    # if (left.value()==1) and (center.value()==1) and (right.value()==1):
                                                                                                                                                                                                                                                                                                    +    if left.value() and center.value() and right.value():
                                                                                                                                                                                                                                                                                                    +        print('Go forward!')    
                                                                                                                                                                                                                                                                                                    +        drive_state = 1
                                                                                                                                                                                                                                                                                                    +        # forward_tone()
                                                                                                                                                                                                                                                                                                    +        forward()
                                                                                                                                                                                                                                                                                                    +        update_oled()
                                                                                                                                                                                                                                                                                                    +    print("counter: ", counter)
                                                                                                                                                                                                                                                                                                    +    counter += 1
                                                                                                                                                                                                                                                                                                    +    sleep(.25)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                    Pins GP6, 7, 8 and 9

                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                                    + Ajusta Bot +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                                    + FAQs +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/robots/03-rainbow-bot/index.html b/robots/03-rainbow-bot/index.html new file mode 100644 index 000000000..6dc8422bd --- /dev/null +++ b/robots/03-rainbow-bot/index.html @@ -0,0 +1,2275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Rainbow Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + Rainbow Bot + + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                                                                                        + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Rainbow Bot + + + + + + + +
                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                          • + + + Part 1: Ordering The LED Strip + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Connecting the LED Strips + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Adding a Standoff + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Upgrading to 9 Volt Power + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + 72 Pixel Configuration + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Part 2: Making The Connections + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Part 3: Adding the Neopixel Library + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Part 4: Testing Your Code + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Functions For Drawing on Matrix + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + Full Source Code + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                      • + + + Part 1: Ordering The LED Strip + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Connecting the LED Strips + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Adding a Standoff + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Upgrading to 9 Volt Power + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + 72 Pixel Configuration + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Part 2: Making The Connections + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Part 3: Adding the Neopixel Library + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Part 4: Testing Your Code + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Functions For Drawing on Matrix + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + Full Source Code + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                      Rainbow Bot

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Rainbow Bot Cover Image

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      This robot takes our base robot and adds an LED strip arranged in a 12X6 pixel grid to display colors and patterns based on what the robot is doing or thinking about.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      We use the same materials as our Base Robot but we add a low-cost addressable LED strips that are easy to hook up with just power, ground and data wires added to our breadboard. The LED is known as an addressable LED strip since you can individually program each LED. The standard is called the WS-2812B LED strip and is often called a NeoPixel LED strip (The Adafruit Term). We also used a Python library called a Neopixel micropython library, although the library is not created or maintained by Adafruit.

                                                                                                                                                                                                                                                                                                      + + +

                                                                                                                                                                                                                                                                                                      LED Strip Pico Connections

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Of course, you can also add longer LED strips and program the patterns in interesting ways.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Part 1: Ordering The LED Strip

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      The LED strips come in a variety of lengths, density and packing. We use the 1 meter long strips that have 60 pixels/meter. These strips are easy to cut apart and solder. We like the black backgrounds but they also come with white. The LED strips come with three packaging options:

                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                      1. No waterproofing - these are fine for our indoor robots
                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                      3. Waterproofing with the strips coated in silicon rubber called IP65 waterproofing
                                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                                      5. Waterproofing with the strips encased in a flexible rubber sleeve
                                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      The waterproofing options tend to be a little more expensive but can also provide a bit more protection for the components on the strips. Waterproofing keeps moisture and dust out of the circuits, but does not mean that they can be submerged under water.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      A sample place to purchase them is here

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      We can take a $3 strip of 60 LEDs and cut them up into six segments of 10 LEDs each for a cost of around 50 cents per strip. We solder stranded wire to the segments and then put 22 gauge solid wire to make them easy to put in the breadboards.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Connecting the LED Strips

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Adding a Standoff

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Upgrading to 9 Volt Power

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Our base robot only needed power for the motors. This robot has 72 RGB LEDs so it might draw more power. So we upgraded the 6 volt battery pack with 4 AA batteries to two packs of 3 batteries for a total of 9 volts. This allows the robot to continue to run even when the batteries are partially drained. The battery packs must be wired in series to deliver the full 9 volts to the input of the motor controller where it powers the motors and also runs though a voltage regulator to power the reset of the robot.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      72 Pixel Configuration

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Here is the top view of the LEDs shining through the clear plexiglass.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      You can see the individual LEDs in this configuration. By adding a small space between the plexiglass and a diffusion layer you can get a much more uniform color distribution over the top surface of the robot.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Part 2: Making The Connections

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      The LED strips use 5 volts of power and have a GND and a data connector. To make the connections we connect the center pin to Pin 0 (upper left corner of the Pico), the GND to the ground rail and the 5 volt to the 5 volt power rail.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Part 3: Adding the Neopixel Library

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Part 4: Testing Your Code

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      In our first test, we will just make the first pixel on the LED strip blink bright red.

                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                      import machine, neopixel, time
                                                                                                                                                                                                                                                                                                      +# Set the pin number and number of pixels
                                                                                                                                                                                                                                                                                                      +LED_PIN = machine.Pin(4)
                                                                                                                                                                                                                                                                                                      +NUMBER_PIXELS = 12
                                                                                                                                                                                                                                                                                                      +np = neopixel.NeoPixel(LED_PIN, NUMBER_PIXELS)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# blink the first pixel red
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                      +    np[0] = (255, 0, 0)
                                                                                                                                                                                                                                                                                                      +    np.write()
                                                                                                                                                                                                                                                                                                      +    time.sleep(1)
                                                                                                                                                                                                                                                                                                      +    np[0] = (0, 0, 0)
                                                                                                                                                                                                                                                                                                      +    np.write()
                                                                                                                                                                                                                                                                                                      +    time.sleep(1)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Functions For Drawing on Matrix

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      The numbering of the pixels is a bit odd. The first 12 are 0 to 11, but the second 12 pixels are in reverse order, so the second row counts from 23 down to 13. Here are some functions that demonstrate this:

                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                                                                                      +41
                                                                                                                                                                                                                                                                                                      +42
                                                                                                                                                                                                                                                                                                      +43
                                                                                                                                                                                                                                                                                                      +44
                                                                                                                                                                                                                                                                                                      +45
                                                                                                                                                                                                                                                                                                      +46
                                                                                                                                                                                                                                                                                                      +47
                                                                                                                                                                                                                                                                                                      +48
                                                                                                                                                                                                                                                                                                      +49
                                                                                                                                                                                                                                                                                                      +50
                                                                                                                                                                                                                                                                                                      +51
                                                                                                                                                                                                                                                                                                      +52
                                                                                                                                                                                                                                                                                                      +53
                                                                                                                                                                                                                                                                                                      +54
                                                                                                                                                                                                                                                                                                      +55
                                                                                                                                                                                                                                                                                                      +56
                                                                                                                                                                                                                                                                                                      +57
                                                                                                                                                                                                                                                                                                      +58
                                                                                                                                                                                                                                                                                                      +59
                                                                                                                                                                                                                                                                                                      +60
                                                                                                                                                                                                                                                                                                      +61
                                                                                                                                                                                                                                                                                                      +62
                                                                                                                                                                                                                                                                                                      +63
                                                                                                                                                                                                                                                                                                      +64
                                                                                                                                                                                                                                                                                                      +65
                                                                                                                                                                                                                                                                                                      +66
                                                                                                                                                                                                                                                                                                      +67
                                                                                                                                                                                                                                                                                                      +68
                                                                                                                                                                                                                                                                                                      +69
                                                                                                                                                                                                                                                                                                      +70
                                                                                                                                                                                                                                                                                                      import time
                                                                                                                                                                                                                                                                                                      +from neopixel import Neopixel
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +numpix = 72
                                                                                                                                                                                                                                                                                                      +strip = Neopixel(numpix, 0, 0, "GRB")
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +red = (255, 0, 0)
                                                                                                                                                                                                                                                                                                      +orange = (255, 150, 0)
                                                                                                                                                                                                                                                                                                      +yellow = (255, 255, 0)
                                                                                                                                                                                                                                                                                                      +green = (0, 255, 0)
                                                                                                                                                                                                                                                                                                      +blue = (0, 0, 255)
                                                                                                                                                                                                                                                                                                      +indigo = (75, 0, 130)
                                                                                                                                                                                                                                                                                                      +violet = (138, 43, 226)
                                                                                                                                                                                                                                                                                                      +colors = (red, orange, yellow, green, blue, indigo, violet)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +strip.brightness(255)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def color_wipe():
                                                                                                                                                                                                                                                                                                      +    for color in colors:
                                                                                                                                                                                                                                                                                                      +        for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i, color)
                                                                                                                                                                                                                                                                                                      +            strip.show()
                                                                                                                                                                                                                                                                                                      +            time.sleep(0.01)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def color_wipe_2():
                                                                                                                                                                                                                                                                                                      +    for color in colors:
                                                                                                                                                                                                                                                                                                      +        for i in range(12):
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+12, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+24, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+36, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+48, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+60, color)
                                                                                                                                                                                                                                                                                                      +            strip.show()
                                                                                                                                                                                                                                                                                                      +            time.sleep(0.01)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def color_wipe_3():
                                                                                                                                                                                                                                                                                                      +    for color in colors:
                                                                                                                                                                                                                                                                                                      +        for i in range(12):
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(23-i, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(i+24, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(47-i, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(48+i, color)
                                                                                                                                                                                                                                                                                                      +            strip.set_pixel(71-i, color)
                                                                                                                                                                                                                                                                                                      +            strip.show()
                                                                                                                                                                                                                                                                                                      +            time.sleep(0.3)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# offset is the color to start (0 to 6)
                                                                                                                                                                                                                                                                                                      +# dir is 1 for forward and -1 for reverse
                                                                                                                                                                                                                                                                                                      +def color_wipe_4(offset, dir):
                                                                                                                                                                                                                                                                                                      +    for i in range(12):
                                                                                                                                                                                                                                                                                                      +        if dir == 1:
                                                                                                                                                                                                                                                                                                      +            this_color = colors[ ((i-offset) %7 )]
                                                                                                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                                                                                                      +            this_color = colors[ ((i+offset) %7 )]
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(23-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(i+24, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(47-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(48+i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(71-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.show()
                                                                                                                                                                                                                                                                                                      +        # time.sleep(0.01)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                      +    for counter in range(100):
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter %7, 1)
                                                                                                                                                                                                                                                                                                      +    for counter in range(100):
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter%7, -1)  
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Full Source Code

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      We now combine the motor controls, the distance sensor and the LED functions so that a moving rainbow pattern moves from to back as the robot moves forward. If the robot encounters an obstacle, the robot will backup and change the direction of the rainbow. After it backs up a bit it will turn and move forward again.

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      main.py +

                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                      +  2
                                                                                                                                                                                                                                                                                                      +  3
                                                                                                                                                                                                                                                                                                      +  4
                                                                                                                                                                                                                                                                                                      +  5
                                                                                                                                                                                                                                                                                                      +  6
                                                                                                                                                                                                                                                                                                      +  7
                                                                                                                                                                                                                                                                                                      +  8
                                                                                                                                                                                                                                                                                                      +  9
                                                                                                                                                                                                                                                                                                      + 10
                                                                                                                                                                                                                                                                                                      + 11
                                                                                                                                                                                                                                                                                                      + 12
                                                                                                                                                                                                                                                                                                      + 13
                                                                                                                                                                                                                                                                                                      + 14
                                                                                                                                                                                                                                                                                                      + 15
                                                                                                                                                                                                                                                                                                      + 16
                                                                                                                                                                                                                                                                                                      + 17
                                                                                                                                                                                                                                                                                                      + 18
                                                                                                                                                                                                                                                                                                      + 19
                                                                                                                                                                                                                                                                                                      + 20
                                                                                                                                                                                                                                                                                                      + 21
                                                                                                                                                                                                                                                                                                      + 22
                                                                                                                                                                                                                                                                                                      + 23
                                                                                                                                                                                                                                                                                                      + 24
                                                                                                                                                                                                                                                                                                      + 25
                                                                                                                                                                                                                                                                                                      + 26
                                                                                                                                                                                                                                                                                                      + 27
                                                                                                                                                                                                                                                                                                      + 28
                                                                                                                                                                                                                                                                                                      + 29
                                                                                                                                                                                                                                                                                                      + 30
                                                                                                                                                                                                                                                                                                      + 31
                                                                                                                                                                                                                                                                                                      + 32
                                                                                                                                                                                                                                                                                                      + 33
                                                                                                                                                                                                                                                                                                      + 34
                                                                                                                                                                                                                                                                                                      + 35
                                                                                                                                                                                                                                                                                                      + 36
                                                                                                                                                                                                                                                                                                      + 37
                                                                                                                                                                                                                                                                                                      + 38
                                                                                                                                                                                                                                                                                                      + 39
                                                                                                                                                                                                                                                                                                      + 40
                                                                                                                                                                                                                                                                                                      + 41
                                                                                                                                                                                                                                                                                                      + 42
                                                                                                                                                                                                                                                                                                      + 43
                                                                                                                                                                                                                                                                                                      + 44
                                                                                                                                                                                                                                                                                                      + 45
                                                                                                                                                                                                                                                                                                      + 46
                                                                                                                                                                                                                                                                                                      + 47
                                                                                                                                                                                                                                                                                                      + 48
                                                                                                                                                                                                                                                                                                      + 49
                                                                                                                                                                                                                                                                                                      + 50
                                                                                                                                                                                                                                                                                                      + 51
                                                                                                                                                                                                                                                                                                      + 52
                                                                                                                                                                                                                                                                                                      + 53
                                                                                                                                                                                                                                                                                                      + 54
                                                                                                                                                                                                                                                                                                      + 55
                                                                                                                                                                                                                                                                                                      + 56
                                                                                                                                                                                                                                                                                                      + 57
                                                                                                                                                                                                                                                                                                      + 58
                                                                                                                                                                                                                                                                                                      + 59
                                                                                                                                                                                                                                                                                                      + 60
                                                                                                                                                                                                                                                                                                      + 61
                                                                                                                                                                                                                                                                                                      + 62
                                                                                                                                                                                                                                                                                                      + 63
                                                                                                                                                                                                                                                                                                      + 64
                                                                                                                                                                                                                                                                                                      + 65
                                                                                                                                                                                                                                                                                                      + 66
                                                                                                                                                                                                                                                                                                      + 67
                                                                                                                                                                                                                                                                                                      + 68
                                                                                                                                                                                                                                                                                                      + 69
                                                                                                                                                                                                                                                                                                      + 70
                                                                                                                                                                                                                                                                                                      + 71
                                                                                                                                                                                                                                                                                                      + 72
                                                                                                                                                                                                                                                                                                      + 73
                                                                                                                                                                                                                                                                                                      + 74
                                                                                                                                                                                                                                                                                                      + 75
                                                                                                                                                                                                                                                                                                      + 76
                                                                                                                                                                                                                                                                                                      + 77
                                                                                                                                                                                                                                                                                                      + 78
                                                                                                                                                                                                                                                                                                      + 79
                                                                                                                                                                                                                                                                                                      + 80
                                                                                                                                                                                                                                                                                                      + 81
                                                                                                                                                                                                                                                                                                      + 82
                                                                                                                                                                                                                                                                                                      + 83
                                                                                                                                                                                                                                                                                                      + 84
                                                                                                                                                                                                                                                                                                      + 85
                                                                                                                                                                                                                                                                                                      + 86
                                                                                                                                                                                                                                                                                                      + 87
                                                                                                                                                                                                                                                                                                      + 88
                                                                                                                                                                                                                                                                                                      + 89
                                                                                                                                                                                                                                                                                                      + 90
                                                                                                                                                                                                                                                                                                      + 91
                                                                                                                                                                                                                                                                                                      + 92
                                                                                                                                                                                                                                                                                                      + 93
                                                                                                                                                                                                                                                                                                      + 94
                                                                                                                                                                                                                                                                                                      + 95
                                                                                                                                                                                                                                                                                                      + 96
                                                                                                                                                                                                                                                                                                      + 97
                                                                                                                                                                                                                                                                                                      + 98
                                                                                                                                                                                                                                                                                                      + 99
                                                                                                                                                                                                                                                                                                      +100
                                                                                                                                                                                                                                                                                                      +101
                                                                                                                                                                                                                                                                                                      +102
                                                                                                                                                                                                                                                                                                      +103
                                                                                                                                                                                                                                                                                                      +104
                                                                                                                                                                                                                                                                                                      +105
                                                                                                                                                                                                                                                                                                      +106
                                                                                                                                                                                                                                                                                                      +107
                                                                                                                                                                                                                                                                                                      +108
                                                                                                                                                                                                                                                                                                      +109
                                                                                                                                                                                                                                                                                                      +110
                                                                                                                                                                                                                                                                                                      +111
                                                                                                                                                                                                                                                                                                      +112
                                                                                                                                                                                                                                                                                                      +113
                                                                                                                                                                                                                                                                                                      +114
                                                                                                                                                                                                                                                                                                      +115
                                                                                                                                                                                                                                                                                                      +116
                                                                                                                                                                                                                                                                                                      +117
                                                                                                                                                                                                                                                                                                      +118
                                                                                                                                                                                                                                                                                                      +119
                                                                                                                                                                                                                                                                                                      +120
                                                                                                                                                                                                                                                                                                      +121
                                                                                                                                                                                                                                                                                                      +122
                                                                                                                                                                                                                                                                                                      +123
                                                                                                                                                                                                                                                                                                      +124
                                                                                                                                                                                                                                                                                                      +125
                                                                                                                                                                                                                                                                                                      +126
                                                                                                                                                                                                                                                                                                      +127
                                                                                                                                                                                                                                                                                                      +128
                                                                                                                                                                                                                                                                                                      +129
                                                                                                                                                                                                                                                                                                      +130
                                                                                                                                                                                                                                                                                                      +131
                                                                                                                                                                                                                                                                                                      +132
                                                                                                                                                                                                                                                                                                      +133
                                                                                                                                                                                                                                                                                                      +134
                                                                                                                                                                                                                                                                                                      +135
                                                                                                                                                                                                                                                                                                      +136
                                                                                                                                                                                                                                                                                                      +137
                                                                                                                                                                                                                                                                                                      +138
                                                                                                                                                                                                                                                                                                      +139
                                                                                                                                                                                                                                                                                                      +140
                                                                                                                                                                                                                                                                                                      +141
                                                                                                                                                                                                                                                                                                      +142
                                                                                                                                                                                                                                                                                                      +143
                                                                                                                                                                                                                                                                                                      +144
                                                                                                                                                                                                                                                                                                      +145
                                                                                                                                                                                                                                                                                                      +146
                                                                                                                                                                                                                                                                                                      +147
                                                                                                                                                                                                                                                                                                      +148
                                                                                                                                                                                                                                                                                                      +149
                                                                                                                                                                                                                                                                                                      +150
                                                                                                                                                                                                                                                                                                      +151
                                                                                                                                                                                                                                                                                                      +152
                                                                                                                                                                                                                                                                                                      +153
                                                                                                                                                                                                                                                                                                      +154
                                                                                                                                                                                                                                                                                                      +155
                                                                                                                                                                                                                                                                                                      +156
                                                                                                                                                                                                                                                                                                      +157
                                                                                                                                                                                                                                                                                                      +158
                                                                                                                                                                                                                                                                                                      +159
                                                                                                                                                                                                                                                                                                      +160
                                                                                                                                                                                                                                                                                                      +161
                                                                                                                                                                                                                                                                                                      +162
                                                                                                                                                                                                                                                                                                      +163
                                                                                                                                                                                                                                                                                                      +164
                                                                                                                                                                                                                                                                                                      +165
                                                                                                                                                                                                                                                                                                      +166
                                                                                                                                                                                                                                                                                                      +167
                                                                                                                                                                                                                                                                                                      +168
                                                                                                                                                                                                                                                                                                      +169
                                                                                                                                                                                                                                                                                                      +170
                                                                                                                                                                                                                                                                                                      +171
                                                                                                                                                                                                                                                                                                      from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                      +from time import sleep
                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                      +from machine import I2C
                                                                                                                                                                                                                                                                                                      +import VL53L0X
                                                                                                                                                                                                                                                                                                      +from neopixel import Neopixel
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# Motor Code
                                                                                                                                                                                                                                                                                                      +# lower right pins with USB on top
                                                                                                                                                                                                                                                                                                      +RIGHT_FORWARD_PIN = 19
                                                                                                                                                                                                                                                                                                      +RIGHT_REVERSE_PIN = 18
                                                                                                                                                                                                                                                                                                      +LEFT_FORWARD_PIN = 20
                                                                                                                                                                                                                                                                                                      +LEFT_REVERSE_PIN = 21
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +right_forward = PWM(Pin(RIGHT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                      +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                      +left_forward = PWM(Pin(LEFT_FORWARD_PIN))
                                                                                                                                                                                                                                                                                                      +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# Sensor Code
                                                                                                                                                                                                                                                                                                      +sda=machine.Pin(16)
                                                                                                                                                                                                                                                                                                      +scl=machine.Pin(17)
                                                                                                                                                                                                                                                                                                      +i2c=machine.I2C(0, sda=sda, scl=scl)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# Create a VL53L0X object
                                                                                                                                                                                                                                                                                                      +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                                                                                                      +tof.start() # startup the sensor
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# used to blink the onboard LED
                                                                                                                                                                                                                                                                                                      +led_onboard = machine.Pin(25, machine.Pin.OUT)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# LED Code
                                                                                                                                                                                                                                                                                                      +numpix = 72
                                                                                                                                                                                                                                                                                                      +strip = Neopixel(numpix, 0, 0, "GRB")
                                                                                                                                                                                                                                                                                                      +# we turn the brightness way down to not oversaturate the brightness in the video
                                                                                                                                                                                                                                                                                                      +strip.brightness(20)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# driving parameters
                                                                                                                                                                                                                                                                                                      +POWER_LEVEL = 30000 # use a value from 20000 to 65025
                                                                                                                                                                                                                                                                                                      +TURN_THRESHOLD = 400 # 25 cm
                                                                                                                                                                                                                                                                                                      +TURN_TIME = .25 # seconds of turning
                                                                                                                                                                                                                                                                                                      +BACKUP_TIME = .75 # seconds of backing up if obstacle detected
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +red = (255, 0, 0)
                                                                                                                                                                                                                                                                                                      +orange = (255, 165, 0)
                                                                                                                                                                                                                                                                                                      +yellow = (255, 255, 0)
                                                                                                                                                                                                                                                                                                      +green = (0, 255, 0)
                                                                                                                                                                                                                                                                                                      +blue = (0, 0, 255)
                                                                                                                                                                                                                                                                                                      +indigo = (75, 0, 130)
                                                                                                                                                                                                                                                                                                      +violet = (138, 43, 226)
                                                                                                                                                                                                                                                                                                      +colors = (red, orange, yellow, green, blue, indigo, violet)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def turn_motor_on(pwm):
                                                                                                                                                                                                                                                                                                      +   pwm.duty_u16(POWER_LEVEL)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def turn_motor_off(pwm):
                                                                                                                                                                                                                                                                                                      +   pwm.duty_u16(0)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def forward():
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                      +    #for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +    #    strip.set_pixel(i, green)
                                                                                                                                                                                                                                                                                                      +    #strip.show()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def reverse():
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                      +    #for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +    #    strip.set_pixel(i, red)
                                                                                                                                                                                                                                                                                                      +    #strip.show()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def turn_right():
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(right_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(left_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                      +    #for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +    #    strip.set_pixel(i, blue)
                                                                                                                                                                                                                                                                                                      +    #strip.show()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def turn_left():
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(right_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_on(left_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                      +    #for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +    #    strip.set_pixel(i, yellow)
                                                                                                                                                                                                                                                                                                      +    #strip.show()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def stop():
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(right_reverse)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_forward)
                                                                                                                                                                                                                                                                                                      +    turn_motor_off(left_reverse)
                                                                                                                                                                                                                                                                                                      +    for i in range(numpix):
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(i, violet)
                                                                                                                                                                                                                                                                                                      +    strip.show()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +def read_sensor_avg():
                                                                                                                                                                                                                                                                                                      +    total = 0
                                                                                                                                                                                                                                                                                                      +    for i in range(10):
                                                                                                                                                                                                                                                                                                      +        total = total + tof.read()
                                                                                                                                                                                                                                                                                                      +        sleep(.01)
                                                                                                                                                                                                                                                                                                      +    return int(total/10)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +# offset is the color to start (0 to 6)
                                                                                                                                                                                                                                                                                                      +# dir is 1 for forward and -1 for reverse
                                                                                                                                                                                                                                                                                                      +def color_wipe_4(offset, dir):
                                                                                                                                                                                                                                                                                                      +    for i in range(12):
                                                                                                                                                                                                                                                                                                      +        if dir == 1:
                                                                                                                                                                                                                                                                                                      +            this_color = colors[ ((i-offset) %7 )]
                                                                                                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                                                                                                      +            this_color = colors[ ((i+offset) %7 )]
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(23-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(i+24, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(47-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(48+i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.set_pixel(71-i, this_color)
                                                                                                                                                                                                                                                                                                      +        strip.show()
                                                                                                                                                                                                                                                                                                      +        # time.sleep(0.01)
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +counter = 0
                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                      +    dist = read_sensor_avg() 
                                                                                                                                                                                                                                                                                                      +    if dist < TURN_THRESHOLD:
                                                                                                                                                                                                                                                                                                      +        print('object detected')
                                                                                                                                                                                                                                                                                                      +        reverse()
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        turn_right()
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, -1)
                                                                                                                                                                                                                                                                                                      +        sleep(.1)
                                                                                                                                                                                                                                                                                                      +        counter += 1        
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +    else:
                                                                                                                                                                                                                                                                                                      +        forward()
                                                                                                                                                                                                                                                                                                      +        color_wipe_4(counter % 7, 1)
                                                                                                                                                                                                                                                                                                      +    counter += 1
                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      Rainbow Bot Source Code

                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                      References

                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                      1. Micropython NeoPixel Library
                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                      + Base Bot +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                      + Face Bot +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/robots/04-face-bot/index.html b/robots/04-face-bot/index.html new file mode 100644 index 000000000..01e505178 --- /dev/null +++ b/robots/04-face-bot/index.html @@ -0,0 +1,1485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Face Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + Face Bot + + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                                                                          + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + Face Bot + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                        MicroPython FaceBot

                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                        This lesson will allow you to draw simple faces on the display on the front of our robots. The faces can reflect the emotions of your robot. We are inspired by the faces on the

                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                        Cozmo Faces

                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                        + Rainbow Bot +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                        + Ajusta Bot +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/robots/05-ajusta-bot/index.html b/robots/05-ajusta-bot/index.html new file mode 100644 index 000000000..a079364ef --- /dev/null +++ b/robots/05-ajusta-bot/index.html @@ -0,0 +1,1484 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Ajusta Bot - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + Ajusta Bot + + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                                                                                            + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + Ajusta Bot + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                          Adjusta Bot

                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                          This robot uses buttons and a rotary encoder to allow the user to reprogram the Pico and adjust the collision avoidance parameters.

                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                                                                          + Face Bot +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                                                                          + IR Sensor Bot +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/robots/20-faqs/index.html b/robots/20-faqs/index.html new file mode 100644 index 000000000..6adcaeaf5 --- /dev/null +++ b/robots/20-faqs/index.html @@ -0,0 +1,1582 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FAQs - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + FAQs + + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                                                                                                              + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + FAQs + + + + + + + +
                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                • + + + Why a two-motor three wheel robot, not four motor four wheel robot? + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Why do we use the L293D vs L298N Motor Driver? + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Why don't we just create a remote control robot car? + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                            • + + + Why a two-motor three wheel robot, not four motor four wheel robot? + + + +
                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                            • + + + Why do we use the L293D vs L298N Motor Driver? + + + +
                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                            • + + + Why don't we just create a remote control robot car? + + + +
                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                            Robots Frequently Asked Questions

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            Why a two-motor three wheel robot, not four motor four wheel robot?

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            We evaluated both the two-motor three wheel robot and the four motor four wheel robots and found that we could achieve all our learning objectives with the two-motor three wheel version. The kits are lower cost, have a simpler assembly process and have plenty of power for our projects.

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            Why do we use the L293D vs L298N Motor Driver?

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            Both of these popular motor driver chips are commonly used in robot kits. Our focus is teaching the principals of computational thinking using low-cost parts. Since the L293D is lower cost and has plenty of power for our two-motor robots we chose that. There is a detailed side-by-side comparison [here] +(https://www.etechnophiles.com/l293d-vs-l298n-motor-driver-differences-specifications-and-pinouts/)

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            Why don't we just create a remote control robot car?

                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                            Remote control cars are very fun to play with. But we find that it often detracts from our mission of learning how to code. So we try to minimize the time students spend just driving their cars around our tracks.

                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                                                                            + IR Sensor Bot +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                                                                                            + Introduction +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/robots/index.html b/robots/index.html new file mode 100644 index 000000000..39f06933c --- /dev/null +++ b/robots/index.html @@ -0,0 +1,1573 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + Introduction + + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                                                                                + + + + + Robots + + + + + + + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Base Bot + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Rainbow Bot + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Face Bot + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Ajusta Bot + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + IR Sensor Bot + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + FAQs + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                              • + + + Robot Journey Map + + + +
                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                              • + + + Parts + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                • + + + Chassis + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Sensors + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Motor Controllers + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                              Introduction to MicroPython Robots

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Robots are the most powerful learning machines in our curriculum. They allow our students to control motion with their own programs. Not only are they incredibly fun for our students, our students learn computational thinking and enable them to quickly proceed to our advanced AI Racing League projects.

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              The Raspberry Pi Pico and the Maker Pi RP2040 components have truly been transformative for our clubs. Instead of being trapped in the 2K RAM on our Arduino systems and being forced to learn "C", our students are programming in their favorite Python language!

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Robot Journey Map

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              This section of the course takes you on a tour of our base $25 collision avoidance robots. It then builds on this robot by adding an OLED display, programming controls and servos. Here is a Journey Map of these lessons:

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Robot Journey Map

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Note that the $25 price assumes you purchase low-cost parts from suppliers like eBay. You can lower the cost per robot by purchasing the parts in higher quantities for classroom use. You can also purchase older Arduino robot kits and upgrade the processors to use the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              This section only covers using the Raspberry Pi Pico robots with external motor drivers. We now have +many additional robot lessons that use the Cytron Maker Pi RP2040 robotics board. These robots are still low-cost ($20) but have much more integrated power and are easier for +younger students to use since they don't require any breadboards or soldering.

                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Our base robot is a collision avoidance robot that is ideal for teaching beginning robotics principles. The robots have one or more distance sensors on the front and will continue to move forward until they get near an object in front of them. They then will reverse and turn in another direction. We test our robots on the floor in a "Robot Corral" that has six-inch high walls. Students can adjust various parameters to allow the robot to navigate around the corral without colliding with the walls.

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Robot Journey Map

                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              1. +

                                                                                                                                                                                                                                                                                                                Base Bot - This is the foundational robot that the other projects are built on. The base includes a standard Smart Car chassis, two DC hobby motors, a battery pack and wheels. On top of the chassis we add a breadboard, jumpers, a motor controller, a distance sensor, and our $4 Raspberry Pi microcontroller.

                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                                              3. +

                                                                                                                                                                                                                                                                                                                Rainbow Bot This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red.

                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                                              5. +

                                                                                                                                                                                                                                                                                                                IR Sensor Bot This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red.

                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                                                              7. +

                                                                                                                                                                                                                                                                                                                Face Bot - We extend the Base Bot by adding a $4 128x64 OLED display. This allows students to see the values of the distance sensor and to hear a sound when a key event occurs.

                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                                                                                                              9. +

                                                                                                                                                                                                                                                                                                                Adjustable Parameter Bot - We extend the face-bot to add some buttons and knobs to allow our users to change the collision avoidance parameters such as forward speed and turning threshold distance.

                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              10. +
                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Parts

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Our beginning Base Bot

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Chassis

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              SmartCar Chassis

                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Sensors

                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              • Ping Ultrasonic Distance Sensor
                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                              • IR sensors
                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Motor Controllers

                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                              + With Display +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                              + Base Bot +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json new file mode 100644 index 000000000..8ae51e8ae --- /dev/null +++ b/search/search_index.json @@ -0,0 +1 @@ +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"CoderDojo Twin Cities Micropython","text":"

                                                                                                                                                                                                                                                                                                              This website and GitHub repository are for sharing resources to teach MicroPython to students in 5th to 12th grades (10-18 years old). The course assumes that either a mentor, teacher or students have access to at least one microcontroller such as the $4 Raspberry Pi Pico or the $10 ESP32. Students should also have access to some low-cost sensors (buttons, potentiometers, ultrasonic distance sensor) and displays such as LEDs or OLED displays.

                                                                                                                                                                                                                                                                                                              If you are looking for a specific topic, please remember to use the search function in the upper right of the website. The website is best displayed on a wide screen to see the navigation bar on the left although the website also works on the small screens of mobile phones and tablets.

                                                                                                                                                                                                                                                                                                              "},{"location":"#course-outline","title":"Course Outline","text":"

                                                                                                                                                                                                                                                                                                              You can use the navigation area on the left side panel to navigate to different parts of the website. Here is a high-level overview of the main sections of the site.

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-1-introduction-to-physical-computing","title":"Section 1: Introduction to Physical Computing","text":"

                                                                                                                                                                                                                                                                                                              This part is a high-level overview of what MicroPython is and why is has become the most popular way to do physical computing, program microcontrollers and build robots. We also discuss the different types of microcontrollers available, their price and features and how to purchase them independently or in kits.

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-2-getting-started-with-micropython","title":"Section 2: Getting Started with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This part will help you get started programming MicroPython on your microcontroller and learn how to hook up parts on a solderless breadboard. We discuss the need for a desktop Integrated Development Environment (IDE) and how to get started writing simple programs

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-3-basic-examples","title":"Section 3: Basic Examples","text":"

                                                                                                                                                                                                                                                                                                              These ten lessons are the foundations for learning MicroPython. They include learning how to blink one or more LEDs, monitor for button presses, fade LEDs in and out using PWM signals, read analog values from potentiometers, read light sensors, turn motors and servos and display rainbow patterns on a NeoPixel strip. Many other labs are variations of these 10 labs.

                                                                                                                                                                                                                                                                                                              Introduction to Basic MicroPython Examples

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-4-sensors","title":"Section 4: Sensors","text":"

                                                                                                                                                                                                                                                                                                              This section will give you more examples of how to use different types of sensors such as heat sensors, current sensors, rotary encoders, accelerometers, gesture sensors, and magnetic field sensors.

                                                                                                                                                                                                                                                                                                              Reading Sensors with MicroPython

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-5-motors-and-robots","title":"Section 5: Motors and Robots","text":"

                                                                                                                                                                                                                                                                                                              This is our student's favorite part of this site! Once you can make a motor go forward and reverse, you are close to being able to make a robot move. We walk you through the basics of using a simple transistor to control a motor, to using simple motor controllers like the L293D chips.

                                                                                                                                                                                                                                                                                                              Introduction to Motors and Robots with MicroPython

                                                                                                                                                                                                                                                                                                              Note that we have many other advanced labs that use our $11 Cytron Maker Pi RP2040 Kits. These incredible boards have everything integrated to build robots with lights and sounds.

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-6-displays","title":"Section 6: Displays","text":"

                                                                                                                                                                                                                                                                                                              This section shows you how to use many different types of displays, from simple 7-segment digital displays to complex OLED graphic displays. On the old 2K Arduino controllers these graphics labs used to be hard, but now we have 264K of RAM on the Raspberry Pi RP2040 microcontrollers. Now these labs are easy!

                                                                                                                                                                                                                                                                                                              • Simple Character Displays
                                                                                                                                                                                                                                                                                                              • Graphical Displays
                                                                                                                                                                                                                                                                                                              "},{"location":"#section-7-sound-and-music","title":"Section 7: Sound and Music","text":"

                                                                                                                                                                                                                                                                                                              Having powerful microcontrollers allows us to generate complex sounds, play tones and even playback recoded sound effects.

                                                                                                                                                                                                                                                                                                              Introduction to Sound and Music with MicroPython

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-8-advanced-labs","title":"Section 8: Advanced Labs","text":"

                                                                                                                                                                                                                                                                                                              We have now covered all the things you need to build hundreds of projects. This section contains deeper dives into other topics such as how to use the MicroPython Remote ```pmremote`````` tools to automate the loading of software onto your microcontroller.

                                                                                                                                                                                                                                                                                                              Advanced Topics

                                                                                                                                                                                                                                                                                                              "},{"location":"#section-9-kits","title":"Section 9: Kits","text":"

                                                                                                                                                                                                                                                                                                              This section contains detailed steps to use the popular educational kits that are now integrating MicroPython and the RP2040 microcontroller. There are many kits and these lessons contain full working programs to build complex projects like a collision avoidance robot with OLED displays.

                                                                                                                                                                                                                                                                                                              MicroPython Kits

                                                                                                                                                                                                                                                                                                              "},{"location":"#related-and-reference-material","title":"Related and Reference Material","text":"

                                                                                                                                                                                                                                                                                                              Lastly, we have a large glossary of terms, contact information and references to other websites that might be useful in your projects. Many of our more advanced projects have been moved into separate websites. Here are a few of these sites:

                                                                                                                                                                                                                                                                                                              1. Moving Rainbow - focus on a full curriculum around using LED strips to make displays and costumes.
                                                                                                                                                                                                                                                                                                              2. Robot Faces and have been moved into their own repositories.
                                                                                                                                                                                                                                                                                                              3. Clocks and Watches - dozens of examples that just focus on creating clock and watch projects. These projects use the Pico \"W\" and the new low-cost SmartWatch displays.
                                                                                                                                                                                                                                                                                                              4. Robot Day - details of building a single-day event to promote STEM at your school using collision avoidance robots.
                                                                                                                                                                                                                                                                                                              5. Beginning Electronics
                                                                                                                                                                                                                                                                                                              6. AI Racing League - this site moves from MicroPython on the Raspberry Pi Pico to full Python on Raspberry Pi single-board computers. It is designed for students who have mastered many of our programming labs and want more challenging projects involving data literacy, machine learning and computer vision.
                                                                                                                                                                                                                                                                                                              "},{"location":"#glossary-of-terms","title":"Glossary of Terms","text":"

                                                                                                                                                                                                                                                                                                              Glossary of MicroPython Terms

                                                                                                                                                                                                                                                                                                              "},{"location":"#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              This is an annotated list of other on-line resources to help you learn MicroPython and use microcontrollers.

                                                                                                                                                                                                                                                                                                              Micropython References - links to other useful sites.

                                                                                                                                                                                                                                                                                                              If you have suggestions for additional references projects, please let us know!

                                                                                                                                                                                                                                                                                                              "},{"location":"#contact","title":"Contact","text":"

                                                                                                                                                                                                                                                                                                              Contact

                                                                                                                                                                                                                                                                                                              "},{"location":"status/","title":"Status of MicroPython Labs","text":""},{"location":"status/#project-boxes","title":"Project Boxes","text":""},{"location":"status/#10-element-led-box","title":"10 Element LED Box","text":"
                                                                                                                                                                                                                                                                                                              1. Box finished
                                                                                                                                                                                                                                                                                                              2. Video done
                                                                                                                                                                                                                                                                                                              "},{"location":"status/#time-of-flight-distance-sensor-display-box","title":"Time of Flight Distance Sensor Display Box","text":"
                                                                                                                                                                                                                                                                                                              1. Box finished
                                                                                                                                                                                                                                                                                                              2. TODO: Video
                                                                                                                                                                                                                                                                                                              "},{"location":"status/#pot-display-box","title":"Pot Display Box","text":"
                                                                                                                                                                                                                                                                                                              1. Box finsished
                                                                                                                                                                                                                                                                                                              2. Video finished
                                                                                                                                                                                                                                                                                                              "},{"location":"status/#compass-lab-box","title":"Compass Lab Box","text":"
                                                                                                                                                                                                                                                                                                              1. Box finished
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/","title":"Advanced Labs","text":"

                                                                                                                                                                                                                                                                                                              This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects.

                                                                                                                                                                                                                                                                                                              Topics include:

                                                                                                                                                                                                                                                                                                              1. Writing Interrupt Handlers
                                                                                                                                                                                                                                                                                                              2. Monitoring the internal temperature of your RP2040 CPU
                                                                                                                                                                                                                                                                                                              3. Timing the speed of functions for performance optimization
                                                                                                                                                                                                                                                                                                              4. Setting up a Conda virtual Python development environment
                                                                                                                                                                                                                                                                                                              5. Using operating system functions such as listing files on the file system
                                                                                                                                                                                                                                                                                                              6. Scanning for I2C devices
                                                                                                                                                                                                                                                                                                              7. Using a framebuffer
                                                                                                                                                                                                                                                                                                              8. Using the minicom tool to move files to and from you PC from your microcontroller
                                                                                                                                                                                                                                                                                                              9. Reading files from a SD card
                                                                                                                                                                                                                                                                                                              10. Converting CircuitPython code and drivers to MicroPython
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Wokwi ESP32 Simulator for the Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/01-intro/","title":"Advanced Labs","text":"

                                                                                                                                                                                                                                                                                                              This section includes some advanced topics that might be useful for helping you create and debug MicroPython projects.

                                                                                                                                                                                                                                                                                                              Topics include:

                                                                                                                                                                                                                                                                                                              1. Writing Interrupt Handlers
                                                                                                                                                                                                                                                                                                              2. Monitoring the internal temperature of your RP2040 CPU
                                                                                                                                                                                                                                                                                                              3. Timing the speed of functions for performance optimization
                                                                                                                                                                                                                                                                                                              4. Setting up a Conda virtual Python development environment
                                                                                                                                                                                                                                                                                                              5. Using operating system functions such as listing files on the file system
                                                                                                                                                                                                                                                                                                              6. Scanning for I2C devices
                                                                                                                                                                                                                                                                                                              7. Using a framebuffer
                                                                                                                                                                                                                                                                                                              8. Using the minicom tool to move files to and from you PC from your microcontroller
                                                                                                                                                                                                                                                                                                              9. Reading files from a SD card
                                                                                                                                                                                                                                                                                                              10. Converting CircuitPython code and drivers to MicroPython
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/","title":"Interrupt Handlers in MicroPython","text":""},{"location":"advanced-labs/02-interrupt-handlers/#what-is-an-interrupt-handler","title":"What is an Interrupt Handler?","text":"

                                                                                                                                                                                                                                                                                                              An Interrupt Handler (also called an ISR for Interrupt Service Request) is a special Python function that is called when specific events occur such as a button being pressed. ISRs are the preferred way to detect external events, as opposed to polling methods that are inconsistent and inefficient. However, they are a bit tricky to setup and debug. So a good design should be as simple as possible and avoid using complex features unless you really know you need them.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/#polling-vs-interrupt-handlers","title":"Polling vs. Interrupt Handlers","text":"

                                                                                                                                                                                                                                                                                                              So why are ISRs so important? Let's illustrate this is a story.

                                                                                                                                                                                                                                                                                                              Imagine you have 10 friends each with a button at their home. In the polling method you would need to drive to each of their houses and ask them \"Is the button get pressed\"? You would have to do this frequently in case the button was pressed and released too quickly. This is a slow and painful process and takes a lot of CPU cycles.

                                                                                                                                                                                                                                                                                                              An interrupt handler on the other hand has each friend tell you directly if their button has been pressed. The messages are quick and efficient. They don't use a lot of extra CPU power and the results get handled quickly.

                                                                                                                                                                                                                                                                                                              However, there are specific rules about what we can and can't do within an ISR function. They need to be quick and efficient. We can't wonder off and do crazy things like printing debugging lines within a good ISR. Our job is typically update a global value and finish ASAP. A good ISR should be as efficient as possible.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/#simple-button-press-isr-example","title":"Simple Button Press ISR Example","text":"

                                                                                                                                                                                                                                                                                                              This is our first ISR example. It has several parts:

                                                                                                                                                                                                                                                                                                              1. import statements - (pretty standard but we have to add the import micropython)
                                                                                                                                                                                                                                                                                                              2. global variables - we will update these to communicate the result of our ISR
                                                                                                                                                                                                                                                                                                              3. the callback function - this is the function will be automatically called on a pin event
                                                                                                                                                                                                                                                                                                              4. the button defintion - this is where we indicate what pin and the PULL_DOWN value
                                                                                                                                                                                                                                                                                                              5. the irq handler - this is where we associate the event with the callback function
                                                                                                                                                                                                                                                                                                              6. the main loop - here we only print the button press count if it has changed
                                                                                                                                                                                                                                                                                                              # Use an interrupt function count the number of times a button has been pressed\nfrom machine import Pin\nimport micropython\nimport time\n\n# global value\nbutton_pressed_count = 0\n\n# Interrupt Service Routine for Button Pressed Events - with no debounce\ndef button1_pressed(change):\n    global button_pressed_count\n    button_pressed_count += 1\n\n# we define button1 as being connected to GP14 and to use the internal Pico PULL_DOWN resistor\nbutton1 = Pin(14, Pin.IN, Pin.PULL_DOWN)\n\n# here is how we associate the falling value on the input pin with the callback function\nbutton1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING)\n\nbutton_pressed_count_old = 0\nwhile True:\n    if button_pressed_count_old != button_pressed_count:\n       print('Button 1 value:', button_pressed_count)\n       button_pressed_count_old = button_pressed_count\n

                                                                                                                                                                                                                                                                                                              Now if you run this program, you will see that it prints to the Terminal each time the button is pressed and it also tells us how many times the button has been pressed.

                                                                                                                                                                                                                                                                                                              example output:

                                                                                                                                                                                                                                                                                                              Button 1 value: 1\nButton 1 value: 2\nButton 1 value: 3\nButton 1 value: 4\nButton 1 value: 5\nButton 1 value: 6\nButton 1 value: 8\nButton 1 value: 9\nButton 1 value: 10\nButton 1 value: 11\nButton 1 value: 12\nButton 1 value: 13\nButton 1 value: 14\nButton 1 value: 15\nButton 1 value: 16\nButton 1 value: 17\nButton 1 value: 18\nButton 1 value: 19\nButton 1 value: 20\nButton 1 value: 21\n

                                                                                                                                                                                                                                                                                                              But if you are careful, you will note something slightly unexpected might happen. I the example above, I actually only pressed the button about 10 times. But the button value is 21! What could be going on here? Could there be a bug in the code?

                                                                                                                                                                                                                                                                                                              The answer is that buttons are not perfect on/off switches. They are essentially noisy on/off devices that may go through a transition of off/on/off/on each time we press the button.

                                                                                                                                                                                                                                                                                                              As a switch goes from open to closed, it moves from a stable state, through an unstable transition state and then it finally arrives at a new stable state. This is illustrated in the drawing below.

                                                                                                                                                                                                                                                                                                              We can reduce this \"noise\" with a small capacitor next to the button. The capacitor will quickly absorb the energy of the button transition and it will \"smooth\" out the spikes. This will give us a more consistent readout of the number of button presses and avoid accidental \"double presses\" that were not intended.

                                                                                                                                                                                                                                                                                                              However, we can also get a clean signal by using software. The key is when we first detect that a transition may be happening we \"stop listening\" for a short period of time until we are confident that the unstable transition state is over. This is typically around 20 milliseconds, but there may be a few stray signals left. Since we may not have to detect changes more frequently than 5 presses per second, we can go to sleep in our ISR for up to 200 milliseconds. This will give us a nice stable reading from the button.

                                                                                                                                                                                                                                                                                                              These are general rules but for our breadboard mounted momentary switches, the values are appropriate.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/#debounced-version-of-a-button-press-detection","title":"Debounced Version of a Button Press Detection","text":"

                                                                                                                                                                                                                                                                                                              Now let's show you the code that does the hard work of debouncing a signal from a button or switch.

                                                                                                                                                                                                                                                                                                              In this example, our ISR is called button_pressed_handler(pin). As soon as it is called, it checks the number of milliseconds since it was last called. If the time difference is under 200 milliseconds we are good to go and we update the button_presses global variable. If we are under the 200 millisecond window, we might be in that transition state and we don't do anything.

                                                                                                                                                                                                                                                                                                              new_time = utime.ticks_ms()\n# if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200: \n        button_presses +=1\n        last_time = new_time\n

                                                                                                                                                                                                                                                                                                              The net effect is that the presses variable will ONLY be incremented once, and not multiple times during the transition. Here is the full code:

                                                                                                                                                                                                                                                                                                              import utime\nfrom machine import Pin\n\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n\nbutton_presses = 0 # the count of times the button has been pressed\nlast_time = 0 # the last time we pressed the button\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n# the lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail\nbutton_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# this function gets called every time the button is pressed\ndef button_pressed_handler(pin):\n    global button_presses, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200: \n        button_presses +=1\n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nbutton_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# This is for only printing when a new button press count value happens\nold_presses = 0\nwhile True:\n    # only print on change in the button_presses value\n    if button_presses != old_presses:\n        print(button_presses)\n        builtin_led.toggle()\n        old_presses = button_presses\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/#isr-with-deactivation","title":"ISR with Deactivation","text":"

                                                                                                                                                                                                                                                                                                              Although there are benefits to the simplicity of the code above, some microcontrollers developers suggest that you simply deactivate the IRQ during the debounce sleep. This makes sense since there is two small calculation of the time differences (a subtraction and a compare operation) that do not need to be performed.

                                                                                                                                                                                                                                                                                                              The key lines we add are a deactivate of the IRQ, a sleep for 200 milliseconds and a re-enable of the IRQ after the sleep. Both approaches have worked for me and I will let you decide the tradeoffs.

                                                                                                                                                                                                                                                                                                              import machine, utime\n\n# the lower right coner has a wire that goes throuh\ncount_input = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)\npresses = 0\n\ndef count_handler(pin):\n    global presses\n    # disable the IRQ during our debounce check\n    count_input.irq(handler=None)\n    presses +=1\n    # debounce time - we ignore any activity diring this period \n    utime.sleep_ms(200)\n    # re-enable the IRQ\n    count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler)\n\ncount_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = count_handler)\n\nold_presses = 0\nwhile True:\n    # only print on change\n    if presses != old_presses:\n        if presses > old_presses + 1:\n            print('double counting in irq.  Fixing...')\n            presses = old_presses + 1\n        print(presses)\n        old_presses = presses\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/02-interrupt-handlers/#debounce-without-disabling-the-irq","title":"Debounce Without Disabling the IRQ","text":""},{"location":"advanced-labs/02-interrupt-handlers/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython Documentation on Interrupt Handlers
                                                                                                                                                                                                                                                                                                              2. A Guide to Debouncing by Jack G. Ganssle - this is an excellent reference if you want to know how long to set the debounce intervals for various types of switches. It has lots of transition plots and shows the incredible variation in transition states of switches. In the Summary of the final page, Jack suggest that most low-cost switch denouncers should use a debounce period of between 20 and 50 milliseconds if the users want a fast response.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-internal-temperature/","title":"Using the Builtin Temperature Sensor","text":"

                                                                                                                                                                                                                                                                                                              The Raspberry Pi Pico has an internal temperature sensor that can be access using machine.ADC(4). This might be useful to see if your RP2040 CPY is running \"hot\" and might benefit from a cooling fan.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-internal-temperature/#reading-the-temperature","title":"Reading the temperature","text":"
                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nsensor_temp = machine.ADC(4)\nwhile True:\n   reading = sensor_temp.read_u16() * conversion_factor\n   temperature = 27 - (reading - 0.706)/0.001721\n   print(temperature)\n   print('\\n')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-internal-temperature/#logging-the-temperature","title":"Logging the Temperature","text":"
                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nsensor_temp = machine.ADC(machine.ADC.CORE_TEMP)\nconversion_factor = 3.3 / (65535)\nfile = open(\"temps.txt\", \"w\")\nwhile True:\n   reading = sensor_temp.read_u16() * conversion_factor\n   temperature = 27 - (reading - 0.706)/0.001721\n   file.write(str(temperature))\n   file.flush()\n   utime.sleep(10)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-timing-functions/","title":"Timing Functions","text":"

                                                                                                                                                                                                                                                                                                              We often need to calculate how much time has elapsed since an event occurred. To to this we can use the ticks functions in the MicroPython utime library.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-timing-functions/#microsecond-timer","title":"Microsecond Timer","text":"

                                                                                                                                                                                                                                                                                                              There are one million microseconds in a single second. The utime library allows us to count the number of microseconds that have elapsed since the processor was powered up.

                                                                                                                                                                                                                                                                                                              The following example times the sleep function and measures the difference in the number of clock ticks in microseconds between the two events.

                                                                                                                                                                                                                                                                                                              import machine, utime\n\nstart_time = utime.ticks_us()\n# sleep for 1 second\nutime.sleep(1)\nend_time = utime.ticks_us()\n\nwhile True:\n    print(\"Start Time:\", start_time)\n    print(\"End Time:\", end_time)\n    print(\"Delta Time:\", end_time - start_time)\n    print(\"\")\n

                                                                                                                                                                                                                                                                                                              results:

                                                                                                                                                                                                                                                                                                              Start Time: 403122147\nEnd Time: 404122241\nDelta Time: 1000094\n\nStart Time: 403122147\nEnd Time: 404122241\nDelta Time: 1000096\n

                                                                                                                                                                                                                                                                                                              You will note that the difference between the start and end time should be one million microseconds. However, the run-time libraries on the pico have some variability, so you will see the actual time vary by a few microseconds. Most of the time you can use milliseconds to compare time intervals.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/03-timing-functions/#millisecond-timer","title":"Millisecond Timer","text":"
                                                                                                                                                                                                                                                                                                              import machine, utime\n\nstart_time = utime.ticks_ms()\nutime.sleep(1)\nend_time = utime.ticks_ms()\n\nwhile True:\n    print(\"Start Time:\", start_time)\n    print(\"End Time:\", end_time)\n    print(\"Delta Time:\", end_time - start_time)\n    print(\"\")\n

                                                                                                                                                                                                                                                                                                              results:

                                                                                                                                                                                                                                                                                                              Start Time: 855845\nEnd Time: 856845\nDelta Time: 1000\n\nStart Time: 858031\nEnd Time: 859032\nDelta Time: 1001\n

                                                                                                                                                                                                                                                                                                              These results are almost always 1000 with an occasional 1001 value.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/04-conda-env/","title":"Creating a Conda Environment for MicroPython","text":"

                                                                                                                                                                                                                                                                                                              Conda is a powerful tool for building consistent and stable Python environments. These environments include all the Python libraries that you need to be a productive MicroPython developer. Using Conda allows you to keep each of your Python projects cleanly separated. This may not be important on your 2nd or 3rd Python project, but as you do more Python projects you will benefit from isolated environments that each have their own versions of each Python libraries that will not conflict with each other.

                                                                                                                                                                                                                                                                                                              One other important fact to remember is that if you use a conda virtual environment you should never need to use sudo (root) to install Python libraries. This means your installation scripts are more secure and less likely to introduce security problems and accidentally remove libraries that other projects depend on.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/04-conda-env/#getting-started","title":"Getting Started","text":"

                                                                                                                                                                                                                                                                                                              To get started, it is best to go directly to the Conda web site and follow the installation instructions for you specific version of your operating system. There are many variations of installation not just for Windows, Mac and Linux, but each version my had different steps required.

                                                                                                                                                                                                                                                                                                              Once you can open a terminal and type in conda --version you have successfully installed Conda. For this document we have used conda:

                                                                                                                                                                                                                                                                                                              conda --version\n

                                                                                                                                                                                                                                                                                                              which returns:

                                                                                                                                                                                                                                                                                                              conda 4.10.1\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/04-conda-env/#creating-your-conda-environment","title":"Creating Your Conda Environment","text":"

                                                                                                                                                                                                                                                                                                              Our fist job is to create a desktop environment that allows us to run Python programs that support the MicroPython development process.

                                                                                                                                                                                                                                                                                                              conda create -n micropython python=3\n
                                                                                                                                                                                                                                                                                                              conda activate micropython\n

                                                                                                                                                                                                                                                                                                              After this your prompt should now show that you are in the micropython environment.

                                                                                                                                                                                                                                                                                                              This process may take about five minutes, since all the most current libraries must be downloaded onto your desktop. Once this process finsihes you must remember to deactivate your current conda environment (if you have one and then activate your new micropython environment.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/04-conda-env/#references","title":"References","text":""},{"location":"advanced-labs/04-conda-env/#raspberry-pi-pico-forum-on-micropython-site","title":"Raspberry Pi Pico Forum on MicroPython Site","text":"

                                                                                                                                                                                                                                                                                                              MicroPython Pico Forum

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/04-conda-env/#micropython-pycopy-pycopy","title":"MicroPython PyCopy (pycopy)","text":"

                                                                                                                                                                                                                                                                                                              MicroPython PyCopy

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/05-os-functions/","title":"Raspberry Pi Pico OS Functions","text":"

                                                                                                                                                                                                                                                                                                              In the Thonny tool, open the Terminal. At the REPL prompt type:

                                                                                                                                                                                                                                                                                                              help()

                                                                                                                                                                                                                                                                                                              which returns

                                                                                                                                                                                                                                                                                                              help()\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              Welcome to MicroPython!\n\nFor online help please visit https://micropython.org/help/.\n\nFor access to the hardware use the 'machine' module.  RP2 specific commands\nare in the 'rp2' module.\n\nQuick overview of some objects:\n  machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n  machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n    methods: init(..), value([v]), high(), low(), irq(handler)\n  machine.ADC(pin) -- make an analog object from a pin\n    methods: read_u16()\n  machine.PWM(pin) -- make a PWM object from a pin\n    methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])\n  machine.I2C(id) -- create an I2C object (id=0,1)\n    methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n             readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n  machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)\n    methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n  machine.Timer(freq, callback) -- create a software timer object\n    eg: machine.Timer(freq=1, callback=lambda t:print(t))\n\nPins are numbered 0-29, and 26-29 have ADC capabilities\nPin IO modes are: Pin.IN, Pin.OUT, Pin.ALT\nPin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN\n\nUseful control commands:\n  CTRL-C -- interrupt a running program\n  CTRL-D -- on a blank line, do a soft reset of the board\n  CTRL-E -- on a blank line, enter paste mode\n\nFor further help on a specific object, type help(obj)\nFor a list of available modules, type help('modules')\n

                                                                                                                                                                                                                                                                                                              followed by

                                                                                                                                                                                                                                                                                                              help(modules)

                                                                                                                                                                                                                                                                                                              help('modules')\n__main__          gc                uasyncio/funcs    uos\n_boot             machine           uasyncio/lock     urandom\n_onewire          math              uasyncio/stream   ure\n_rp2              micropython       ubinascii         uselect\n_thread           onewire           ucollections      ustruct\n_uasyncio         rp2               uctypes           usys\nbuiltins          uarray            uerrno            utime\ncmath             uasyncio/__init__ uhashlib          uzlib\nds18x20           uasyncio/core     uio\nframebuf          uasyncio/event    ujson\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/05-os-functions/#os-functions","title":"OS Functions","text":"
                                                                                                                                                                                                                                                                                                              import os\nprint(dir(os))\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              ['__class__', '__name__', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', 'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', 'umount', 'uname', 'urandom']\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/05-os-functions/#real-time-clock","title":"Real Time Clock","text":"
                                                                                                                                                                                                                                                                                                              from machine import RTC\n\nrtc = RTC()\nrtc.datetime((2017, 8, 23, 2, 12, 48, 0, 0)) # set a specific date and time\nrtc.datetime() # get date and time\n

                                                                                                                                                                                                                                                                                                              See MicroPython Real Time Clock

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/06-i2c/","title":"Raspberry Pi Pico I2C","text":"

                                                                                                                                                                                                                                                                                                              The Pico has two I2C hardware controllers. Each controller can talk to multiple IIC devices as long as all the devices communicating on each controller have distinct addresses.

                                                                                                                                                                                                                                                                                                              1. I2C0 SDA are on GPIOs 0, 4, 8, 12, 16 and 20
                                                                                                                                                                                                                                                                                                              2. I2C0 SCL are on GPIOs 1, 5, 9, 13, 17 and 21
                                                                                                                                                                                                                                                                                                              3. I2C1 SDA are on GPIOs 2, 6, 10, 14, 18 and 26
                                                                                                                                                                                                                                                                                                              4. I2C1 SCL are on GPIOs 3, 7, 11, 15, 19 and 27
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/06-i2c/#i2c-scanner-for-i2c-0","title":"I2C Scanner for I2C 0","text":"
                                                                                                                                                                                                                                                                                                              import machine\n\nI2C_SDA_PIN = 0\nI2C_SCL_PIN = 1\ni2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)\n\nprint('Scanning I2C bus.')\ndevices = i2c.scan() # this returns a list of devices\n\ndevice_count = len(devices)\n\nif device_count == 0:\n    print('No i2c device found.')\nelse:\n    print(device_count, 'devices found.')\n\nfor device in devices:\n    print('Decimal address:', device, \", Hex address: \", hex(device))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/06-i2c/#i2c-scanner-for-both-i2c-0-and-1","title":"I2C Scanner for Both I2C 0 and 1","text":"
                                                                                                                                                                                                                                                                                                              import machine\n\nI2C0_SDA_PIN = 0\nI2C0_SCL_PIN = 1\nI2C1_SDA_PIN = 2\nI2C1_SCL_PIN = 3\ni2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000)\ni2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000)\n\nprint('Scanning I2C bus 0.')\ndevices = i2c0.scan() # this returns a list of devices\n\ndevice_count = len(devices)\n\nif device_count == 0:\n    print('No i2c device found on bus 0.')\nelse:\n    print(device_count, 'devices found.')\n\nfor device in devices:\n    print('Decimal address:', device, \", Hex address: \", hex(device))\n\nprint('Scanning I2C bus 1.')\ndevices = i2c1.scan() # this returns a list of devices\n\ndevice_count = len(devices)\n\nif device_count == 0:\n    print('No i2c device found on bus 1.')\nelse:\n    print(device_count, 'devices found.')\n\nfor device in devices:\n    print('Decimal address:', device, \", Hex address: \", hex(device))\n

                                                                                                                                                                                                                                                                                                              Results for both a OLED display on I2C 0 and a time-of-flight sensor on I2C 1

                                                                                                                                                                                                                                                                                                              Scanning I2C bus 0.\n1 devices found.\nDecimal address: 60 , Hex address:  0x3c\nScanning I2C bus 1.\n1 devices found.\nDecimal address: 41 , Hex address:  0x29\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/06-i2c/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Article on Hackster.io
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/07-framebuffer/","title":"Framebuffers in MicroPython","text":""},{"location":"advanced-labs/07-framebuffer/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              MicroPython.org docs on framebuf

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/08-minicom/","title":"Minicom","text":""},{"location":"advanced-labs/08-minicom/#installation","title":"Installation","text":""},{"location":"advanced-labs/08-minicom/#installation-on-a-mac","title":"Installation on a Mac","text":"
                                                                                                                                                                                                                                                                                                              brew install minicom\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/08-minicom/#installation-on-linux-raspberry-pi-os","title":"Installation on Linux (Raspberry Pi OS)","text":"
                                                                                                                                                                                                                                                                                                              sudo apt install minicom\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/08-minicom/#verification-of-installation","title":"Verification of Installation","text":"
                                                                                                                                                                                                                                                                                                              which minicom\n
                                                                                                                                                                                                                                                                                                              /usr/local/bin/minicom\n
                                                                                                                                                                                                                                                                                                              minicom --version\n
                                                                                                                                                                                                                                                                                                              minicom version 2.8 (compiled Jan  4 2021)\n
                                                                                                                                                                                                                                                                                                              minicom --help\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              Usage: minicom [OPTION]... [configuration]\nA terminal program for Linux and other unix-like systems.\n\n  -b, --baudrate         : set baudrate (ignore the value from config)\n  -D, --device           : set device name (ignore the value from config)\n  -s, --setup            : enter setup mode\n  -o, --noinit           : do not initialize modem & lockfiles at startup\n  -m, --metakey          : use meta or alt key for commands\n  -M, --metakey8         : use 8bit meta key for commands\n  -l, --ansi             : literal; assume screen uses non IBM-PC character set\n  -L, --iso              : don't assume screen uses ISO8859\n  -w, --wrap             : Linewrap on\n  -H, --displayhex       : display output in hex\n  -z, --statline         : try to use terminal's status line\n  -7, --7bit             : force 7bit mode\n  -8, --8bit             : force 8bit mode\n  -c, --color=on/off     : ANSI style color usage on or off\n  -a, --attrib=on/off    : use reverse or highlight attributes on or off\n  -t, --term=TERM        : override TERM environment variable\n  -S, --script=SCRIPT    : run SCRIPT at startup\n  -d, --dial=ENTRY       : dial ENTRY from the dialing directory\n  -p, --ptty=TTYP        : connect to pseudo terminal\n  -C, --capturefile=FILE : start capturing to FILE\n  --capturefile-buffer-mode=MODE : set buffering mode of capture file\n  -F, --statlinefmt      : format of status line\n  -R, --remotecharset    : character set of communication partner\n  -v, --version          : output version information and exit\n  -h, --help             : show help\n  configuration          : configuration file to use\n\nThese options can also be specified in the MINICOM environment variable.\nThis variable is currently unset.\nThe configuration directory for the access file and the configurations\nis compiled to /usr/local/Cellar/minicom/2.8/etc.\n\nReport bugs to <minicom-devel@lists.alioth.debian.org>.\n

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/08-minicom/#references","title":"References","text":""},{"location":"advanced-labs/09-micro-sd-card-reader/","title":"Micro SD Card Reader","text":"

                                                                                                                                                                                                                                                                                                              Secure Digital (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices.

                                                                                                                                                                                                                                                                                                              On Microcontrollers SD cards are usually access through an SPI interface although there are also devices that use I2C interfaces.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/09-micro-sd-card-reader/#maker-pi-pico-connections","title":"Maker Pi Pico Connections","text":"GPIO Pin SD Mode SPI Mode GP10 CLK SCK GP11 CMD SDI GP12 DAT0 SD0 GP13 DAT1 X GP14 DAT2 X GP15 CD/DAT3 CSn"},{"location":"advanced-labs/09-micro-sd-card-reader/#maker-pi-pico-example-code","title":"Maker Pi Pico Example Code","text":""},{"location":"advanced-labs/09-micro-sd-card-reader/#pin-definitions","title":"Pin Definitions","text":"
                                                                                                                                                                                                                                                                                                              # SD Mode Definitions\nSDCARD_CLK = 10\nSDCARD_CMD = 11\nSDCARD_DAT0 = 12\nSDCARD_DAT1 = 13\nSDCARD_DAT2 = 14\nSDCARD_CD_DAT3 = 15\n\n# SPI Mode Definitions\nSDCARD_SCK = 10\nSDCARD_SDI = 11\nSDCARD_SD0 = 12\nSDCARD_X1 = 13\nSDCARD_X2 = 14\nSDCARD_CS = 15\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/09-micro-sd-card-reader/#sample-code-for-spi-mode","title":"Sample Code for SPI Mode","text":"
                                                                                                                                                                                                                                                                                                              import machine, os, sdcard\n\n# Assign chip select (CS) pin (and start it high)\ncs = machine.Pin(15, machine.Pin.OUT)\n# Intialize SPI peripheral (start with 1 MHz)\nspi = machine.SPI(1,\n                  baudrate=1000000,\n                  polarity=0,\n                  phase=0,\n                  bits=8,\n                  firstbit=machine.SPI.MSB,\n                  sck=machine.Pin(10),\n                  mosi=machine.Pin(11),\n                  miso=machine.Pin(12))\n# Initialize SD card\nsd = sdcard.SDCard(spi, cs)\n\n# OR this simpler initialization code should works on Maker Pi Pico too...\n#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))\n\nos.mount(sd, '/sd')\n# check the content\nos.listdir('/sd')\n\n# try some standard file operations\nfile = open('/sd/test.txt', 'w')\nfile.write('Testing SD card on Maker Pi Pico')\nfile.close()\nfile = open('/sd/test.txt', 'r')\ndata = file.read()\nprint(data)\nfile.close()\n

                                                                                                                                                                                                                                                                                                              Results:

                                                                                                                                                                                                                                                                                                              Testing SD card on Maker Pi Pico\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/09-micro-sd-card-reader/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython sdcard.py driver - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266
                                                                                                                                                                                                                                                                                                              2. MicroPython.org Documentation
                                                                                                                                                                                                                                                                                                              3. Raspberry Pi Pico Forum
                                                                                                                                                                                                                                                                                                              4. YouTube Video by Shawn Hymel
                                                                                                                                                                                                                                                                                                              5. Cytron Maker Pi Pico Datasheet
                                                                                                                                                                                                                                                                                                              6. SparkFun microSD Transflash Breakout - $4.75 - pins are labeled CD, DO, GND, SCK, VCC, DI and CS
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/10-converting-circuitpython-to-micropython/","title":"Converting CircuitPython to MicroPython","text":"

                                                                                                                                                                                                                                                                                                              MicroPython was created in by Australian programmer Damian George in May of 2014. Although Adafruit originally supported MicroPython, in July 2017 Adafruit created a fork of MicroPython and called it CircuitPython. We can only speculate why this decisive action was taken, but the result is it divided the community into two incompatible branches and it doubled the amount of work needed to be done to introduce a new device to the Python community. Unfortunately, the consequence is that many programs written in CircuitPython are difficult to port to MicroPython.

                                                                                                                                                                                                                                                                                                              Today, according to Google Trends, MicroPython is still four more popular than CircuitPython when we look at worldwide web search comparisons. However, in the US, the popularity is more equal. Although the claim was that CircuitPython was done for \"simplicity\" there is little evidence that CircuitPython programs are smaller or easier to maintain than MicroPython.

                                                                                                                                                                                                                                                                                                              The one thing is clear, CircuitPython has lots of drivers for unusual hardware devices. If you find a driver you need in MicroPython you will need to convert it to MicroPython. This is usually done manually on a line-by-line basis.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/10-converting-circuitpython-to-micropython/#setting-up-a-circuitpython-virtual-environment","title":"Setting up a CircuitPython Virtual Environment","text":"

                                                                                                                                                                                                                                                                                                              Because MicroPython and CircuitPython are incompatible, it is important that you don't intermix your Python libraries.

                                                                                                                                                                                                                                                                                                              Here is how we setup a virtual environment for CircuitPython using Conda.

                                                                                                                                                                                                                                                                                                              conda create -n circuitpython python=3\nconda activate circuitpython\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/10-converting-circuitpython-to-micropython/#installing-the-ssd1306-circuitpython-library","title":"Installing the SSD1306 CircuitPython Library","text":"

                                                                                                                                                                                                                                                                                                              Per Directions Here

                                                                                                                                                                                                                                                                                                              pip3 install adafruit-circuitpython-ssd1306\n
                                                                                                                                                                                                                                                                                                              pip3 install adafruit-circuitpython-displayio-ssd1306\n

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              ERROR: Could not find a version that satisfies the requirement adafruit-circuitpython-displayio-ssd1306 ERROR: No matching distribution found for adafruit-circuitpython-displayio-ssd1306

                                                                                                                                                                                                                                                                                                              Successfully installed Adafruit-Blinka-6.3.2 Adafruit-PlatformDetect-3.2.0 Adafruit-PureIO-1.1.8 adafruit-circuitpython-busdevice-5.0.6 adafruit-circuitpython-framebuf-1.4.6 adafruit-circuitpython-ssd1306-2.11.1 pyftdi-0.52.9 pyserial-3.5 pyusb-1.1.1\n
                                                                                                                                                                                                                                                                                                              # Basic example of clearing and drawing pixels on a SSD1306 OLED display.\n# This example and library is meant to work with Adafruit CircuitPython API.\n# Author: Tony DiCola\n# License: Public Domain\n\n# Import all board pins.\nfrom board import SCL, SDA\nimport busio\n\n# Import the SSD1306 module.\nimport adafruit_ssd1306\n\n\n# Create the I2C interface.\ni2c = busio.I2C(SCL, SDA)\n\n# Create the SSD1306 OLED class.\n# The first two parameters are the pixel width and pixel height.  Change these\n# to the right size for your display!\ndisplay = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)\n# Alternatively you can change the I2C address of the device with an addr parameter:\n#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31)\n\n# Clear the display.  Always call show after changing pixels to make the display\n# update visible!\ndisplay.fill(0)\n\ndisplay.show()\n\n# Set a pixel in the origin 0,0 position.\ndisplay.pixel(0, 0, 1)\n# Set a pixel in the middle 64, 16 position.\ndisplay.pixel(64, 16, 1)\n# Set a pixel in the opposite 127, 31 position.\ndisplay.pixel(127, 31, 1)\ndisplay.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/10-converting-circuitpython-to-micropython/#using-chatgpt-to-convert-circuitpython-to-micropython","title":"Using ChatGPT to convert CircuitPython to MicroPython","text":"

                                                                                                                                                                                                                                                                                                              ChatGPT does a good job of automatically converting CircuitPython to MicroPython. In your prompt you just add the following instruction:

                                                                                                                                                                                                                                                                                                              Convert the following CircuitPython code to MicroPython:\n

                                                                                                                                                                                                                                                                                                              An example of this working with the basic blink example is shown below:

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/10-converting-circuitpython-to-micropython/#trend-analysis","title":"Trend analysis","text":"

                                                                                                                                                                                                                                                                                                              As of March 2021, MicroPython is about two to four times more popular than CircuitPython.

                                                                                                                                                                                                                                                                                                              Google Worldwide Search Trends

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/","title":"MicroPython Remote","text":"

                                                                                                                                                                                                                                                                                                              MicroPython now has a standard format for all remote access. The program is called mpremote. There is ample documentation on the site, and there is a higher chance it will include the latest features.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#why-use-micropython-remote","title":"Why Use MicroPython Remote","text":"

                                                                                                                                                                                                                                                                                                              There are three main reasons to use mpremote:

                                                                                                                                                                                                                                                                                                              1. Setting up a new device with many device drivers, data files and code.
                                                                                                                                                                                                                                                                                                              2. Automatically updating software to get new versions and fix bugs such as security patches.
                                                                                                                                                                                                                                                                                                              3. Moving data back and forth from your Pico to and from your host computer or a cloud server on the internet,
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#list-of-commands","title":"List of Commands","text":"

                                                                                                                                                                                                                                                                                                              A partial list of the most frequently used commands are:

                                                                                                                                                                                                                                                                                                              1. connect - connect to a remote device
                                                                                                                                                                                                                                                                                                              2. disconnect - disconnect from a remote device
                                                                                                                                                                                                                                                                                                              3. resume - maintain existing interpreter state for subsequent commands. Useful for multiple REPL commands without soft resets between the commands.
                                                                                                                                                                                                                                                                                                              4. soft_reset - perform a soft-reset of the device which will clear out the Python heap and restart the interpreter.
                                                                                                                                                                                                                                                                                                              5. repl - enter the line-at-time REPL Python interpreter loop on the connected device.
                                                                                                                                                                                                                                                                                                              6. eval - evaluate a string you give as a parameter on the pico using the MicroPython interpreter.
                                                                                                                                                                                                                                                                                                              7. exec - execute a string and potentially run it in the background.
                                                                                                                                                                                                                                                                                                              8. run - run a script from the local filesystem on the Pico
                                                                                                                                                                                                                                                                                                              9. fs - file system commands like copy, move, rename. Examples below.
                                                                                                                                                                                                                                                                                                              10. df - print size/used/free statistics for teach of the device filesystems
                                                                                                                                                                                                                                                                                                              11. edit - edit a file locally. This will copy the file to your local file systems, launch your $EDITOR program and then copy the file back to the Pico.
                                                                                                                                                                                                                                                                                                              12. mip - intaller. Like pip but it runs on the pico. It install packages from micropython-lib (or GitHub) using the mip tool. This can be useful if you want to automatically upgrade your software and restart the device. If you have a wireless Pico \"W\" you can get new software directly from the Internet without ever needing a hardline to the Pico.
                                                                                                                                                                                                                                                                                                              13. mount - mount the local directory on your PC onto the remote device (the Pico). This will allow you to use local files directly from your MicroPython code.
                                                                                                                                                                                                                                                                                                              14. unmount - unmount a local directory. This happens automatically when mpremote terminates.
                                                                                                                                                                                                                                                                                                              15. rtc - get or set the real-time clock - useful if you want to keep clocks in sync
                                                                                                                                                                                                                                                                                                              16. sleep - (delay) n seconds before executing the next command
                                                                                                                                                                                                                                                                                                              17. reset - hard reset the device. It will then rerun the main.py if it finds it.
                                                                                                                                                                                                                                                                                                              18. bootloader - This will make the device enter its bootloader mode so it can get an new uf2 file. Useful if you need to upgrade to a new version of MicroPython.

                                                                                                                                                                                                                                                                                                              Note that you can only be connected to one remote device at a time to use many commands.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#installing","title":"Installing","text":"

                                                                                                                                                                                                                                                                                                              The first time:

                                                                                                                                                                                                                                                                                                              pip install --user mpremote\n
                                                                                                                                                                                                                                                                                                              pip install --upgrade --user mpremote\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#install-log","title":"Install Log","text":"

                                                                                                                                                                                                                                                                                                              I use conda and you can see that it found the mpremote package version 1.20.0

                                                                                                                                                                                                                                                                                                              Requirement already satisfied: mpremote in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (1.20.0)\nRequirement already satisfied: pyserial>=3.3 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (3.5)\nRequirement already satisfied: importlib-metadata>=1.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from mpremote) (4.8.3)\nRequirement already satisfied: zipp>=0.5 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.4.0)\nRequirement already satisfied: typing-extensions>=3.6.4 in /Users/dan/opt/miniconda3/envs/mkdocs/lib/python3.6/site-packages (from importlib-metadata>=1.4->mpremote) (3.7.4.3)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#testing-the-version","title":"Testing the Version","text":"

                                                                                                                                                                                                                                                                                                              The version of mpremote is not yet working, but eventually, it will be used like this:

                                                                                                                                                                                                                                                                                                              $ mpremote --version\n
                                                                                                                                                                                                                                                                                                              mpremote 0.0.0-unknown\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#getting-help","title":"Getting Help","text":"
                                                                                                                                                                                                                                                                                                              $ mpremote --help\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#help-results","title":"Help Results","text":"
                                                                                                                                                                                                                                                                                                              mpremote -- MicroPython remote control\nSee https://docs.micropython.org/en/latest/reference/mpremote.html\n\nList of commands:\n  connect     connect to given device\n  disconnect  disconnect current device\n  edit        edit files on the device\n  eval        evaluate and print the string\n  exec        execute the string\n  fs          execute filesystem commands on the device\n  help        print help and exit\n  mip         install packages from micropython-lib or third-party sources\n  mount       mount local directory on device\n  repl        connect to given device\n  resume      resume a previous mpremote session (will not auto soft-reset)\n  run         run the given local script\n  soft-reset  perform a soft-reset of the device\n  umount      unmount the local directory\n  version     print version and exit\n\nList of shortcuts:\n  --help      \n  --version   \n  a0          connect to serial port \"/dev/ttyACM0\"\n  a1          connect to serial port \"/dev/ttyACM1\"\n  a2          connect to serial port \"/dev/ttyACM2\"\n  a3          connect to serial port \"/dev/ttyACM3\"\n  bootloader  make the device enter its bootloader\n  c0          connect to serial port \"COM0\"\n  c1          connect to serial port \"COM1\"\n  c2          connect to serial port \"COM2\"\n  c3          connect to serial port \"COM3\"\n  cat         \n  cp          \n  devs        list available serial ports\n  df          \n  ls          \n  mkdir       \n  reset       reset the device after delay\n  rm          \n  rmdir       \n  setrtc      \n  touch       \n  u0          connect to serial port \"/dev/ttyUSB0\"\n  u1          connect to serial port \"/dev/ttyUSB1\"\n  u2          connect to serial port \"/dev/ttyUSB2\"\n  u3          connect to serial port \"/dev/ttyUSB3\"```\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#examples-of-file-system-commands","title":"Examples of File System Commands","text":"

                                                                                                                                                                                                                                                                                                              Here is the syntax of the copy file command:

                                                                                                                                                                                                                                                                                                              mpremote fs cp main.py :main.py\n

                                                                                                                                                                                                                                                                                                              This copies the local file \"main.py\" to your pico. The colon \":\" is the root of the pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#setting-up-a-unix-alias","title":"Setting Up a UNIX Alias","text":"

                                                                                                                                                                                                                                                                                                              If you get tired of typing \"mpremote fs cp\" you can create an command-line alias called \"pcp\" for Pico Copy:

                                                                                                                                                                                                                                                                                                              alias pcp='mpremote fs cp'\n

                                                                                                                                                                                                                                                                                                              The copy command the becomes simply:

                                                                                                                                                                                                                                                                                                              pcp main.py :main.py\n

                                                                                                                                                                                                                                                                                                              If you place this line in your .bashrc or similar shell startup it saves you a lot of typing.

                                                                                                                                                                                                                                                                                                              File systems examples include:

                                                                                                                                                                                                                                                                                                              1. cat <file..> to show the contents of a file or files on the device
                                                                                                                                                                                                                                                                                                              2. ls to list the current directory
                                                                                                                                                                                                                                                                                                              3. ls <dirs...> to list the given directories
                                                                                                                                                                                                                                                                                                              4. cp [-r] <src...> <dest> to copy files
                                                                                                                                                                                                                                                                                                              5. rm <src...> to remove files on the device
                                                                                                                                                                                                                                                                                                              6. mkdir <dirs...> to create directories on the device
                                                                                                                                                                                                                                                                                                              7. rmdir <dirs...> to remove directories on the device
                                                                                                                                                                                                                                                                                                              8. touch <file..> to create the files (if they don\u2019t already exist)
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-mpremote/#creating-deployment-scripts","title":"Creating Deployment Scripts","text":"

                                                                                                                                                                                                                                                                                                              For large classrooms that teach MicroPython using kits, we recommend that you arrange all the mkdir and copy (cp) file shell commands in a single UNIX shell script for consistency.

                                                                                                                                                                                                                                                                                                              Here are the steps:

                                                                                                                                                                                                                                                                                                              1. Update the Pico with a new image
                                                                                                                                                                                                                                                                                                              2. Make a /lib directory using the mkdir
                                                                                                                                                                                                                                                                                                              3. Copy all the drivers for your projects to /lib directory. The drivers you use will be dependent on the hardware you use. For example if your kit has a display you might need to load the ssd1306.py display driver into the /lib directory.
                                                                                                                                                                                                                                                                                                              4. Copy the default startup program to the /main.py
                                                                                                                                                                                                                                                                                                              5. Have a sequence of \"labs\" that start with numbers such as 01_blink.py, 02_button.py etc.

                                                                                                                                                                                                                                                                                                              If you follow these steps, then when the students connect to the Pico using Thonny they will see all the labs in the right order from simple to the most complex.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-os/","title":"Sample MicroPython OS functions","text":"

                                                                                                                                                                                                                                                                                                              MicroPython provides a small list of os functions that allow you to manipulate files on the local filesystem of a MicroController.

                                                                                                                                                                                                                                                                                                              These functions for filesystem access, and mounting, terminal redirection and duplication, and the uname and urandom functions.

                                                                                                                                                                                                                                                                                                              These commands include:

                                                                                                                                                                                                                                                                                                              • uname - get system information such as the release of the runtime and machine type
                                                                                                                                                                                                                                                                                                              • listdir - list directory
                                                                                                                                                                                                                                                                                                              • ilistdir - list all files including low-level i-node statistics
                                                                                                                                                                                                                                                                                                              • getcwd - get current working directory
                                                                                                                                                                                                                                                                                                              • chdir - change directory
                                                                                                                                                                                                                                                                                                              • mkdir -
                                                                                                                                                                                                                                                                                                              • mount/umount - mount or unmount a remote directory as a local file system
                                                                                                                                                                                                                                                                                                              • remove - remove a file
                                                                                                                                                                                                                                                                                                              • stat - get statistics about a file or directory
                                                                                                                                                                                                                                                                                                              • rmdir - remove a directory
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-os/#uname-getting-system-information","title":"UName: Getting System Information","text":"
                                                                                                                                                                                                                                                                                                              import os\nuname = os.uname()\nprint(uname)\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              (\n   sysname='rp2',\n   nodename='rp2',\n   release='1.19.1',\n   version='v1.19.1-88-g74e33e714 on 2022-06-30 (GNU 11.2.0 MinSizeRel)',\n   machine='Raspberry Pi Pico W with RP2040'\n)\n

                                                                                                                                                                                                                                                                                                              Thonny does not easily allow you to delete files. To do this you will need to use the \"os\" functions.

                                                                                                                                                                                                                                                                                                              import os\nos.listdir()\nos.remove('myfile')\nos.listdir()\n

                                                                                                                                                                                                                                                                                                              To find out all the os functions use:

                                                                                                                                                                                                                                                                                                              import os\nprint(dir(os))\n``\n\nReturns\n
                                                                                                                                                                                                                                                                                                              ['class', 'name', 'remove', 'VfsFat', 'VfsLfs2', 'chdir', 'getcwd', 'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs', 'umount', 'uname', 'urandom']`

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-os/#percent-storage-full-and-free-ram","title":"Percent Storage Full and Free RAM","text":"
                                                                                                                                                                                                                                                                                                              import gc\nimport os\n\ndef df():\n  s = os.statvfs('//')\n  return ('{0} MB'.format((s[0]*s[3])/1048576))\n\ndef free(full=False):\n  F = gc.mem_free()\n  A = gc.mem_alloc()\n  T = F+A\n  P = '{0:.2f}%'.format(F/T*100)\n  if not full: return P\n  else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))\n\ndef free-gc(full=False):\n  gc.collect()\n  F = gc.mem_free()\n  A = gc.mem_alloc()\n  T = F+A\n  P = '{0:.2f}%'.format(F/T*100)\n  if not full: return P\n  else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))\n\nprint(df())\n\nprint(free())\n\nprint(free-gc())\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-os/#machine-clock-frequency","title":"Machine Clock frequency","text":"
                                                                                                                                                                                                                                                                                                              print('Machine Clock Frequency:', '{:,} MHz'.format(machine.freq()/1000000))\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              Machine Clock Frequency: 125 MHz\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-os/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              https://www.youtube.com/watch?v=jnSX8ZMmHZ4

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/","title":"Using rshell on the Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              MicroPython now has standardized file transfers with the new \"MicroPython Remote\" or mpremote commands. See the mpremote docs for details. We will be updating all our documentation to use this standard. This page is mostly for older systems.

                                                                                                                                                                                                                                                                                                              Using an IDE such as Thonny you can copy many files at a time to the Raspberry Pi Pico by using the GUI.

                                                                                                                                                                                                                                                                                                              However, this process becomes error prone if you want to copy a large number of files. To do this we will use the \"remote shell\" program from the command line. In our classes we often want to copy a dozen or more files to a new robot for student to try out.

                                                                                                                                                                                                                                                                                                              Rshell was written by David Hyland. The source code and installations are documented on Dave's GitHub repository here: https://github.com/dhylands/rshell. Dave added support for the Raspberry Pi Pico in release 0.0.30 in March of 2021.

                                                                                                                                                                                                                                                                                                              Rshell's primary use is to to get filesystem information on the pico (ls), and to copy files to and from MicroPython's filesystem. It can also be used as a terminal to run interactive REPL commands.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#conda-setup","title":"Conda Setup","text":"

                                                                                                                                                                                                                                                                                                              If you are new to Python and you don't have any previous virtual environments set up you can skip this step. Experienced Python developers have many different environments that they want to keep separated due to library incompatibility issues. Here is how to create a new Python Conda environment that keeps your rshell libraries separated.

                                                                                                                                                                                                                                                                                                              conda create -n pico python=3\nconda deactivate\nconda activate pico\n

                                                                                                                                                                                                                                                                                                              Your prompt should now indicate you are in the pico environment.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#install-rshell-in-your-pico-environment","title":"Install rshell in your pico environment","text":"

                                                                                                                                                                                                                                                                                                              We will now use the standard pip installer tool to install the rshell command.

                                                                                                                                                                                                                                                                                                              python -m pip install rshell\n

                                                                                                                                                                                                                                                                                                              You can check that rshell has been correctly installed in your command PATH by running the UNIX which command.

                                                                                                                                                                                                                                                                                                              which rshell\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#running-shell","title":"Running shell","text":"

                                                                                                                                                                                                                                                                                                              Rshell communicates with the Pico through the USB port. When you plug in the Pico you should see a new file created in the UNIX /dev directory. It typically begins with the letters /dev/cu.modem. One way to test this is to unlpug the pico and run the following command:

                                                                                                                                                                                                                                                                                                              ls /dev/cu.usbmodem*\n
                                                                                                                                                                                                                                                                                                              With the pico unplugged, there should be no files that match the ls wildcard pattern. However, after you plug in the pico the following should be returned:

                                                                                                                                                                                                                                                                                                              /dev/cu.usbmodem14101\n

                                                                                                                                                                                                                                                                                                              This is the port you will use to connect to the pico. We will use the -p for port option to startup rshell.

                                                                                                                                                                                                                                                                                                              rshell -p /dev/cu.usbmodem14101\n
                                                                                                                                                                                                                                                                                                              Using buffer-size of 128\nConnecting to /dev/cu.usbmodem14101 (buffer-size 128)...\nTrying to connect to REPL  connected\nRetrieving sysname ... rp2\nTesting if ubinascii.unhexlify exists ... Y\nRetrieving root directories ... /LCD_SPI.py/ /lcd-spi-test.py/ /lcd-test.py/ /lcd.py/\nSetting time ... Oct 28, 2021 20:30:56\nEvaluating board_name ... pyboard\nRetrieving time epoch ... Jan 01, 1970\nWelcome to rshell. Use Control-D (or the exit command) to exit rshell.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#boards","title":"Boards","text":"

                                                                                                                                                                                                                                                                                                              The boards command will list the boards rshell is connected to:

                                                                                                                                                                                                                                                                                                              boards pyboard @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pyboard/hello.py /pyboard/main.py

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#listing-files","title":"Listing Files","text":"

                                                                                                                                                                                                                                                                                                              We can see that the board is called \"pyboard\" and you can use that as a path to list the files on the board.

                                                                                                                                                                                                                                                                                                              ls /pyboard\nhello.py      main.py\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#giving-your-board-a-name","title":"Giving Your Board a Name","text":"

                                                                                                                                                                                                                                                                                                              rshell will look for a program called board.py when it connects to the board. If this file contains a board name it will use that as the board name the next time it connects to the board. You can use the \"echo\" command to generate the file. In the example below, we will call our board \"pico\"

                                                                                                                                                                                                                                                                                                              echo 'name=\"pico\"' > /pyboard/board.py\n

                                                                                                                                                                                                                                                                                                              After you use the CONTROL-C and reconnect you will see the following:

                                                                                                                                                                                                                                                                                                              pico @ /dev/cu.usbmodem14101 connected Epoch: 1970 Dirs: /pico/hello.py /pico/main.py\n

                                                                                                                                                                                                                                                                                                              Remember you must disconnect from rshell and reconnect before the boards.py function is used.

                                                                                                                                                                                                                                                                                                              For the remainder of this lesson we will assume you have renamed your board \"pico\".

                                                                                                                                                                                                                                                                                                              You can then type cd /pico followed by a ls to see the files on your pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#entering-repl","title":"Entering REPL","text":"

                                                                                                                                                                                                                                                                                                              You can enter the REPL loop using the repl command and use the same commands that you used in the Thonny shell.

                                                                                                                                                                                                                                                                                                              repl\nprint('Hello World!')\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              Hello World!\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#getting-help-on-rshell-commands","title":"Getting Help on rshell commands","text":"

                                                                                                                                                                                                                                                                                                              You can type the help command to see all the rshell commands:

                                                                                                                                                                                                                                                                                                              help\n\nDocumented commands (type help <topic>):\n========================================\nargs    cat  connect  date  edit  filesize  help  mkdir  rm     shell\nboards  cd   cp       echo  exit  filetype  ls    repl   rsync\n\nUse Control-D (or the exit command) to exit rshell.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#running-backup","title":"Running Backup","text":"

                                                                                                                                                                                                                                                                                                              If you want to copy all the python files from the pico to a backup directory you can use the following command:

                                                                                                                                                                                                                                                                                                              cd /pico\ncp *.py /Users/dan/backup\n

                                                                                                                                                                                                                                                                                                              You will need to create the /Users/dan/backup directory before you do this. You can also use the tilde ~ character to stand in for your home directory like this:

                                                                                                                                                                                                                                                                                                              cp *.py /Users/dan/backup\n

                                                                                                                                                                                                                                                                                                              Copying '/pico/hello.py' to '/Users/dan/backup/hello.py' ... Copying '/pico/main.py' to '/Users/dan/backup/main.py' ...

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#installing-files","title":"Installing files","text":"

                                                                                                                                                                                                                                                                                                              If you have a directory called ~/build that contains many files you want to install on the pico file system you can use the following command:

                                                                                                                                                                                                                                                                                                              cp ~/build/* /pico\n

                                                                                                                                                                                                                                                                                                              If you have done a clone to the CoderDojoTC micropython repository and put it in your home directory under ~/micropython then following command will copy the python files from the Maker Pi RP2040 kit to your pico:

                                                                                                                                                                                                                                                                                                              mkdir /pico/lib\ncp ~/micropython/src/drivers/*.py /pico/lib\ncp ~/micropython/src/kits/maker-pi-rp2040/*.py /pico\ncp ~Documents/ws/micropython/src/kits/maker-pi-rp2040-robots/*.py /pico/lib\n

                                                                                                                                                                                                                                                                                                              Note that the drivers will be placed in the /lob directory.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/11-rshell/#direct-command-execution","title":"Direct Command Execution","text":"

                                                                                                                                                                                                                                                                                                              You do not need to use an interactive session to run a command with rshell. You can just add the command you would like to run to the end of the rshell command like this:

                                                                                                                                                                                                                                                                                                              rshell -p /dev/cu.usbmodem14101 ls /pico\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              hello.py      main.py\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/12-string-formatting/","title":"MicroPython String Formatting","text":"

                                                                                                                                                                                                                                                                                                              The normal Python has advanced string formatting functions using \"%\" and .format methods documented at the PyFormat website.

                                                                                                                                                                                                                                                                                                              Although most of these functions work, there are some exceptions when using date formats.

                                                                                                                                                                                                                                                                                                              The following % formats do not work under MicroPython:

                                                                                                                                                                                                                                                                                                              1. %Y - year
                                                                                                                                                                                                                                                                                                              2. %m - month
                                                                                                                                                                                                                                                                                                              3. %d - day of month
                                                                                                                                                                                                                                                                                                              4. %H - hour of day
                                                                                                                                                                                                                                                                                                              5. %M - minute
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/12-string-formatting/#padding-example","title":"Padding Example","text":"

                                                                                                                                                                                                                                                                                                              The following example prints a floating point number with two decimals of precision in a field of six characters with leading zeros.

                                                                                                                                                                                                                                                                                                              print('{:06.2f}'.format(3.141592653589793))\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              003.14\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/","title":"Timers in MicroPython","text":"

                                                                                                                                                                                                                                                                                                              When clocks are used to trigger future events, they are called timers. Timers are used to efficiently use CPU resources. In microcontrollers, the work of keeping track of timers is frequently delegated to hardware outside of the main CPU loop. This makes your microcontroller more efficient, more reliable, and makes your code easier to read.

                                                                                                                                                                                                                                                                                                              Timers work independently of the main CPU's clock. As a result, they are called asynchronous objects. Using timers can be both efficient and reliable, but they can be complex to debug. Errors within Timers and interrupts can be difficult to get information on.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#types-of-timers","title":"Types of Timers","text":"

                                                                                                                                                                                                                                                                                                              Timers are used to schedule events in the future. There are two types:

                                                                                                                                                                                                                                                                                                              1. A PERIODIC timer will continually fire events in the future at periodic intervals.
                                                                                                                                                                                                                                                                                                              2. A ONE_SHOT timer will fire an event once and then stop.

                                                                                                                                                                                                                                                                                                              Both of these timer objects need a callback function to be specified when they are initialized. These callback functions are also called interrupt service routines (ISRs). This is the function that will be executed when the timer gets triggered. So we must define an ISR function before timers are properly initialized.

                                                                                                                                                                                                                                                                                                              Periodic timers are usually initialized with a period parameter. This is the amount of time in milliseconds between each event. They are useful for doing like checking if new data is available on a network connection or checking if a sensor is still working.

                                                                                                                                                                                                                                                                                                              One-shot timers are also initialized with a period parameter often called a \"timeout\" period. This is the amount of time in milliseconds before the timer will fire. One-shot timers are used if you want to do something in the future but don't want to deal with it now. You can think of this as a reminder service.

                                                                                                                                                                                                                                                                                                              Here is how both Periodic and one-shot timers are setup:

                                                                                                                                                                                                                                                                                                              myOneShotTimer = Timer()\n# call once in 10 seconds from now\nmyOneShotTimer.init(mode=Timer.ONE_SHOT, callback=myCallbackFunction, period=10000)\n\n# call every two seconds until the timer is deactivated\nmyPeriodicTimer = Timer()\nmyPeriodicTimer.init(mode=Timer.PERIODIC, callback=myCallbackFunction, period=2000) \n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#using-frequency-on-periodic-timers","title":"Using Frequency on Periodic Timers","text":"

                                                                                                                                                                                                                                                                                                              A Periodic timer can be configured to use either a period or a frequency as a parameter. The frequency is the number of times the timer will fire per second. The period is the amount of time in milliseconds between each event. The frequency is used to calculate the period. The following are equivalent:

                                                                                                                                                                                                                                                                                                              # 50ms between events\nmyTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel) \n# 20 events per second\nmyTimer.init(freq=20, mode=Timer.PERIODIC, callback=move_pixel) \n

                                                                                                                                                                                                                                                                                                              You can always convert between the two by taking the inverse and multiplying by 1000.

                                                                                                                                                                                                                                                                                                              frequency = 1 / period * 1000\nperiod = 1 / frequency * 1000\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#hardware-vs-virtual-software-timers","title":"Hardware vs. Virtual Software Timers","text":"

                                                                                                                                                                                                                                                                                                              Older microcontrollers have fixed hardware associated with each timer. These are call \"hardware timers\". When you initialize a hardware timer, you specify what set of hardware to use using a fixed ID (0,1,2,3 etc.). On the Raspberry Pi Pico all timers are \"virtual\" and are implemented in software. All virtual timers have an ID of -1 and the timer ID does not need to be specified.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#sample-timer-program","title":"Sample Timer Program","text":"

                                                                                                                                                                                                                                                                                                              In the following program we will create timer that will toggle the built-in LED on the Raspberry Pi Pico every second. We will create a new function called toggle_led() that will toggle the builtin LED on and off each time it is called. There are three key lines in this program.

                                                                                                                                                                                                                                                                                                              1. line 1 imports the Timer library
                                                                                                                                                                                                                                                                                                              2. line 7 creates the uninitialized timer object
                                                                                                                                                                                                                                                                                                              3. line 16 initialize the timer object to indicate how often to trigger the timer, the mode (periodic) and the callback function (toggle_led)
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#sample-code-to-toggle-the-builtin-led","title":"Sample Code to Toggle the Builtin LED","text":"

                                                                                                                                                                                                                                                                                                              Here is a sample code to toggle the builtin LED on the Raspberry Pi Pico and off.

                                                                                                                                                                                                                                                                                                              from machine import Pin, Timer\nfrom utime import sleep\n\n# create an LED object using the onboard LED\nmyLED = machine.Pin(\"LED\", machine.Pin.OUT)\n\n# create an uninitialized timer object\nmyTimer = Timer()\n\n# create a function to be called when the timer goes off\n# this function just toggles the onboard LED\ndef toggle_led(timer):\n    myLED.toggle()\n\n# initialize the timer object to tick every second (1,000 milliseconds)\nmyTimer.init(period=1000, mode=Timer.PERIODIC, callback=toggle_led)\n\nwhile True:\n    sleep(10)\n    print('just sleeping here')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#sample-code-to-animate-an-led-strip-with-a-timer","title":"Sample Code to Animate an LED Strip With a Timer","text":"

                                                                                                                                                                                                                                                                                                              Many times you want to animate an LED strip but not complicate up your main event loop with this code. For example, you might want to light up the entire strip with a pattern of motion on the LED strip. You can do this by creating a new function that will conditionally turn one pixel to a color and increment a global variable that keeps track of which pixel to turn on. This function will be called every time the timer goes off.

                                                                                                                                                                                                                                                                                                              from machine import Pin, Timer\nfrom utime import sleep\nfrom neopixel import NeoPixel\n\nNEOPIXEL_PIN = 0\nNUMBER_PIXELS = 8\nstrip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\n# create an uninitialized timer object\nmyTimer = Timer()\n\ncounter = 0\n# a callback function.  Use this with a timer that triggers 20 times a second\ndef move_pixel(myTimer):\n    global counter\n    for i in range(0, NUMBER_PIXELS):\n        if i == counter:\n            strip[i] = (10,0,0)\n        else:\n            strip[i] = (0,0,10)\n        strip.write()\n    counter += 1\n    if counter > NUMBER_PIXELS:\n        counter = 0\n\n# initialize the timer object to tick 20 times per second (50 milliseconds)\nmyTimer.init(period=50, mode=Timer.PERIODIC, callback=move_pixel)\n\nwhile True:\n    print('Just sleeping here.  The timer is doing all the work flashing the LED...', counter)\n    sleep(5) # sleep for five seconds\n

                                                                                                                                                                                                                                                                                                              For example, if a robot has a set of \"modes\" like driving forward, turning left, turning right, backing up etc. You can use a timer to flash the LED strip in different colors with different patterns to indicate the robot is in different modes.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#removing-a-timer","title":"Removing a Timer","text":"

                                                                                                                                                                                                                                                                                                              The Timer.deinit() can be used to remove a timer from the system. This is useful if you want to stop a timer that is currently running. If you have many timers that are each using memory, it is a good practice to remove them when you are done with them.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#limits-on-the-number-of-timers","title":"Limits on the Number of Timers","text":"

                                                                                                                                                                                                                                                                                                              In MicroPython on the RP2040, there are no limits placed on the number of timers other than you must have enough memory available. Because there are no specific hardware limits, these are often referred to as \"virtual\" timers. The number of virtual timers is limited by the amount of memory available to the microcontroller.

                                                                                                                                                                                                                                                                                                              Other implementations of MicroPython on different hardware have stricter limits placed on the number of timers. The ESP32 MicroPython port currently only has four hardware timers and a numeric ID of 0 to 3 must be used when you setup these timers. For the pyboard has a limit of 14 timers. Be aware of these limits if you are interested in creating portable MicroPython code.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#drawbacks-of-timers-and-isrs","title":"Drawbacks of Timers and ISRs","text":"

                                                                                                                                                                                                                                                                                                              Unfortunately, different hardware implementations of MicroPython have different ways to setup and use timers. Some hardware requires timers to each have an ID tied to a specific resource. Because of this, be cautious about using timers in your code if you require portability between hardware.

                                                                                                                                                                                                                                                                                                              As we mentioned, timers need callback functions are a type of function called interrupt service requests (ISRs). In multi-core systems like the RP2040 these interrupts can only be called from the core that executed the timer. This means that if you are using a timer to trigger an interrupt, you must make sure that the interrupt is only called from the core that is executing the timer.

                                                                                                                                                                                                                                                                                                              There are special limitations on what can and can't be done within interrupts in most systems. For example, you are not allowed to allocate dynamic memory within an interrupt. Your interrupt handler should be a short function that performs the minimum work to change external variables. This is because the interrupt handler is called in a separate thread and can't allocate memory.

                                                                                                                                                                                                                                                                                                              In general, doing complex logic within timers and interrupts is not a good idea. If you are interested in doing complex logic, you should use a different method that is easy to debug. This will make your code easier to understand and maintain.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#exercises","title":"Exercises","text":"
                                                                                                                                                                                                                                                                                                              1. Can you change the frequency of the times in the sample code above?
                                                                                                                                                                                                                                                                                                              2. How much memory do you think a timer will use? How many timers can be used on a RP2040 with 264K of memory?
                                                                                                                                                                                                                                                                                                              3. What if you wanted a timer to check in on the health of your program? Could it reboot the Raspberry Pi using machine.reset() if it gets stuck? Hint: See Watchdog Timers
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/13-timers/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython Timers
                                                                                                                                                                                                                                                                                                              2. MicroPython Documentation on Timers on the RP2040
                                                                                                                                                                                                                                                                                                              3. Engineers Garage on Time and Timers in MicroPython
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/","title":"Memory Management in MicroPython","text":"

                                                                                                                                                                                                                                                                                                              In the recent past, memory management has been a challenge for embedded systems. Before 2020 microcontrollers like the Arduino usually only came with a few kilobytes of RAM, and careful attention needed to be paid to each byte using clever memory management trickery. The memory management system in recent years has become much easier. Even a low-cost $4 Raspberry Pi Pico now comes with 264K RAM! This is an almost 100-fold increase over the older Arduino Uno which only had 2K of RAM. That being said, there are always developers that push their hardware to the limit, and knowing the basics of memory management is important to understand how embedded systems work.

                                                                                                                                                                                                                                                                                                              MicroPython is very clever about how memory is allocated. It is very stingy about memory use and will only allocate memory for what is needed. This is very different from the standard Python that allocates memory for everything that is needed up-front assuming that most laptops, desktops and servers have gigabytes of RAM and virtual memory support. This is an important difference, and it is important to understand if you want to push the limits of your microcontroller.

                                                                                                                                                                                                                                                                                                              This lab will cover the basics of memory management, and how to use the memory management system in MicroPython. We will cover the following topics:

                                                                                                                                                                                                                                                                                                              1. Memory Management Concepts: The Heap, Stack, and Garbage Collection
                                                                                                                                                                                                                                                                                                              2. Functions to show the amount of free and used memory and current memory usage
                                                                                                                                                                                                                                                                                                              3. Functions to manually allocate and free memory
                                                                                                                                                                                                                                                                                                              4. Functions to debug memory allocation
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#memory-management-concepts","title":"Memory Management Concepts","text":"

                                                                                                                                                                                                                                                                                                              The memory management system is responsible for allocating and freeing memory. The memory management system must allocate memory for data variables, and for freeing this memory when a variable is no longer needed. The system is also responsible for allocating memory for the parameters used by functions, and for freeing memory when a function is no longer needed. You can read more about memory management on the MicroPython Memory Management Docs website.

                                                                                                                                                                                                                                                                                                              The heap is the area of memory that is used to store general data. In MicroPython the heap is located in the lower memory and it grows upwards in memory address space. The exception is memory used as parameters to functions, which is stored in the stack.

                                                                                                                                                                                                                                                                                                              The stack is the area of memory that is used to store all the parameters to function calls. In MicroPython the stack is located in the upper memory and it grows downwards in memory address space. If you are calling highly recursive functions, the stack will get a lot of use.

                                                                                                                                                                                                                                                                                                              The garbage collector is a process to reuse memory that is no longer in use. The garbage collector is automatically run when the heap is full, but you can also run it manually to reclaim unused memory to get finer-grain control over memory usage and to avoid memory fragmentation.

                                                                                                                                                                                                                                                                                                              In MicroPython most of these operations are done automatically for you. You don't really need to worry about how memory works unless you are reaching the limits of what your microcontroller can do.

                                                                                                                                                                                                                                                                                                              One other key concept is continuous memory. If you are allocating a large amount of memory in an array or a long string, we need to allocate all this memory in one large chunk. As programs run for a long time memory becomes fragmented (many small free sections) and can't be used for storing large arrays.

                                                                                                                                                                                                                                                                                                              You can read more about how MicroPython is clever about memory usage by reading the MicroPython Optimizations Docs website.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#functions-to-show-free-and-used-memory","title":"Functions to show free and used memory","text":"

                                                                                                                                                                                                                                                                                                              We will be using the \"gc\" module to show the amount of free and used memory. \"gc\" orignally stood for \"garbage collection\", but the model has been generalized to perform other memory management tasks.

                                                                                                                                                                                                                                                                                                              Here are the key functions to show the amount of free and used memory and current memory usage on a Raspberry Pi Pico with an RP2040 microcontroller: gc.mem_free() and gc.mem_alloc():

                                                                                                                                                                                                                                                                                                              import gc\nimport micropython\n\nprint('Memory Free:', \"{:,}\".format(gc.mem_free()), 'bytes')\nprint('Memory Allocated:', \"{:,}\".format(gc.mem_alloc()), 'bytes')\n

                                                                                                                                                                                                                                                                                                              results for RP2040:

                                                                                                                                                                                                                                                                                                              Memory Free: 187,232 bytes\nMemory Allocated: 4,864 bytes\n

                                                                                                                                                                                                                                                                                                              You can see that although the RP2040 chip has a specification of 264K of RAM, it only has 187,232 bytes of RAM available for program use. The other RAM us used to store the MicroPython interpreter software. You can also see that the heap is currently using 4,864 bytes of RAM. This is typical of the additional overhead that MicroPython requires to run a program.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#viewing-memory-layout","title":"Viewing Memory Layout","text":"

                                                                                                                                                                                                                                                                                                              You can use the micropython.mem_info(1) function to view the memory layout of the MicroPython interpreter. This function returns a list of tuples, each tuple containing the address, size and type of each memory block. The address on the left of each row is the memory address of the start of the block within the heap. In MicroPython, memory blocks are each typically 16 bytes.

                                                                                                                                                                                                                                                                                                              ```python\nimport micropython\nprint(micropython.mem_info(1))\n

                                                                                                                                                                                                                                                                                                              results:

                                                                                                                                                                                                                                                                                                              stack: 532 out of 7936\nGC: total: 192064, used: 4896, free: 187168\n No. of 1-blocks: 52, 2-blocks: 13, max blk sz: 64, max free sz: 11650\nGC memory layout; from 200084a0:\n00000: h=MhhhBDhhBTTBDhTBDBBBh===DBDh====B=BBBBBBTB=BTB=BBBTB=TBTB=Bh==\n00400: =BB=h===========TB=h=h===================h=====h==h=============\n00800: ====h===========================================================\n00c00: ====h===========================================================\n01000: ====h=hBhh=ShhS..h=.........Sh=.................................\n01400: ....Shh=======h========h====h=====..............................\n       (181 lines all free)\n2ec00: ....................................\nNone\n

                                                                                                                                                                                                                                                                                                              This shows that the garbage collector is responsible for managing a total of 192,064 bytes of memory. The other numbers give you an indication of how fragmented you heap is.

                                                                                                                                                                                                                                                                                                              • The number of 1-blocks is 52
                                                                                                                                                                                                                                                                                                              • The number of 2-block spaces is 13
                                                                                                                                                                                                                                                                                                              • The maximum block size is 64
                                                                                                                                                                                                                                                                                                              • The maximum free size is 11,650
                                                                                                                                                                                                                                                                                                              • The heap starts at memory location: 2000 84a0

                                                                                                                                                                                                                                                                                                              Each of the letters represents the type of memory at that position on the heap:

                                                                                                                                                                                                                                                                                                              | Letter | Description | ||| |.|Free memory| |h|head of a block of memory| |=|tail of a block of memory| |T|Tuple| |L|List| |D|Dictionary| |S|String| |A|Array or Byte Array| |F|Float| |B|Function BC| |M|Module|

                                                                                                                                                                                                                                                                                                              If the heap is 192,064 bytes and each block is 16 bytes then there should be 12,004 blocks on the heap. If each row in the report displays 62 characters then there are 12,004/62=193 rows in the report. To keep the report short, the function will only show the rows that are not free. The report indicates that there are 181 lines all free blocks, so it will only show the non-free lines which in the example above is about six non-free rows in lower heap memory.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#functions-to-manually-allocate-and-free-memory","title":"Functions to manually allocate and free memory","text":"

                                                                                                                                                                                                                                                                                                              You can manually run the garbage collector using the gc.collect() functions. This function is used to force garbage collection exactly when you want to, not when the heap is full. This may occur at a time that is inconvenient for the program when it must be sending data at a specific speed.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              Still under development.

                                                                                                                                                                                                                                                                                                              import gc\nimport micropython\n\ndef show_memory():\n    print('Memory Free:', \"{:,}\".format(gc.mem_free()), 'bytes')\n    print('Memory Allocated:', \"{:,}\".format(gc.mem_alloc()), 'bytes')\n\nshow_memory()\n# allocate a block of memory\nprint('Allocating a block of memory')\nmyBigBlockOfMemory = matrix[100][100]\nshow_memory()\nprint('Freeing the block of memory')\n# free the block of memory\ngc.mem_free(ptr)\nshow_memory()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#image-size","title":"Image Size","text":"

                                                                                                                                                                                                                                                                                                              You can determine how much space we have available on the Pico flash after programming an ELF or UF2 file. For example, if we have an ELF file that's 1 MB and we were to program via openocd, then where should we offset my user data in flash? (i.e. XIP_BASE + OFFSET)

                                                                                                                                                                                                                                                                                                              With an elf or uf2 file, using picotool info -a on it will show the start and end of the binary (the start is usually 0x10000000 unless you did something to change it).

                                                                                                                                                                                                                                                                                                              Inside your code, you can use the symbols defined by the linker script __flash_binary_start (defined here) and __flash_binary_end (defined here) like this:

                                                                                                                                                                                                                                                                                                              extern char __flash_binary_start;  // defined in linker script\nextern char __flash_binary_end;    // defined in linker script\nuintptr_t start = (uintptr_t) &__flash_binary_start;\nuintptr_t end = (uintptr_t) &__flash_binary_end;\nprintf(\"Binary starts at %08x and ends at %08x, size is %08x\\n\", start, end, end-start);\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/14-memory-management/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Code that Prints Memory Block Types
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/15-measuring-vsys/","title":"Measuring VSys","text":"

                                                                                                                                                                                                                                                                                                              You need to set GP25 to output and set it high and also set GP29 to input with no pull resistors before reading. And don't forget that the input from VSYS to ADC is divided by 3, so you have to multiply your result to get real value. When I do that I get around 4.7 V when powered from USB, so it definitely works.

                                                                                                                                                                                                                                                                                                              https://forums.raspberrypi.com/viewtopic.php?t=301152

                                                                                                                                                                                                                                                                                                              import machine\n\n# Vsys = machine.ADC(3)\nVsys = machine.ADC(29)\nconversion_factor = (3.3 / (65535)) * 3\n\nreading = Vsys.read_u16() * conversion_factor\n\nprint(reading)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/17-file-system/","title":"MicroPython File Systems","text":"

                                                                                                                                                                                                                                                                                                              Unlike older Arduino systems, MicroPython has full support for a \"virtual file system\" (VFS) that we use to store and retrieve programs and data. The way we access the file systems in MicroPython is similar to the way we access files in standard Python.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/17-file-system/#blocks-and-fragments","title":"Blocks and Fragments","text":"

                                                                                                                                                                                                                                                                                                              First, we need to define two key terms: blocks and fragments.

                                                                                                                                                                                                                                                                                                              The block size refers to the size of the fundamental unit of storage on the file system. All files and directories occupy an integral number of blocks, with the size of each file and directory being a multiple of the block size. The block size is typically a power of 2, and can vary depending on the file system and the size of the storage medium.

                                                                                                                                                                                                                                                                                                              The fragment size, on the other hand, refers to the smallest unit of space that can be allocated for a file or directory. Files and directories may occupy a number of fragments that is not necessarily an integer multiple of the fragment size. Fragmentation occurs when the file system is unable to allocate a contiguous block of storage for a file or directory, resulting in the file or directory being spread out over multiple fragments. The fragment size is typically smaller than the block size, and may also vary depending on the file system and the size of the storage medium.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/17-file-system/#file-systems-statistics","title":"File Systems Statistics","text":"

                                                                                                                                                                                                                                                                                                              In MicroPython, the os.statvfs('/') function provides information about the root file system. Among the information it provides is the block size and fragment size of the file system.

                                                                                                                                                                                                                                                                                                              In the os.statvfs('/') function, the block size and fragment size are reported as the first and second elements of the tuple returned by the function, respectively. Specifically, stats[0] contains the block size, and stats[1] contains the fragment size. These values can be used to calculate various file system statistics, such as the total size of the file system, the total number of blocks and fragments, and the amount of free space available.

                                                                                                                                                                                                                                                                                                              You can also mount file systems on other flash drives. You can get the stats of these file systems by using the new mount point with the os.statvfs() function.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/17-file-system/#using-statvfs","title":"Using Statvfs","text":"
                                                                                                                                                                                                                                                                                                              \"\"\"\nPrint the statistics from the virtual file system (vfs)\n\nhttps://docs.micropython.org/en/latest/library/os.html?highlight=os#os.statvfs\n\n0 f_bsize \u2013 file system block size\n1 f_frsize \u2013 fragment size\n2 f_blocks \u2013 size of fs in f_frsize units\n3 f_bfree \u2013 number of free blocks\n4 f_bavail \u2013 number of free blocks for unprivileged users\n5 f_files \u2013 number of inodes\n6 f_ffree \u2013 number of free inodes\n7 f_favail \u2013 number of free inodes for unprivileged users\n8 f_flag \u2013 mount flags\n9 f_namemax \u2013 maximum filename length\n\"\"\"\n\nimport os\n\nstats = os.statvfs(\"/\")\nprint(stats)\n\nblock_size = stats[0]\nfragment_size = stats[1]\ntotal_blocks = stats[2]\n\nfree_blocks = stats[3]\navailable_blocks = stats[4]\n\nmount_flags = stats[8]\nmax_filename_length = stats[9]\n\n# byte calculations\ntotal_bytes = total_blocks * fragment_size\nfree_bytes = free_blocks * fragment_size\navailable_bytes = available_blocks * fragment_size\n\nprint(\"File system block size: {:,} bytes\".format(block_size))\nprint(\"Fragement size: {:,} bytes\".format(fragment_size))\nprint(\"Size of entire file system in fragement blocks: {:,}\".format(total_blocks))\nprint(\"Size of entire file system in bytes: {:,}\".format(total_bytes))\n\nprint(\"Total free blocks for system and users: {:,}\".format(free_blocks))\nprint(\"Number of free blocks for unprivileged users: {:,} bytes\".format(available_blocks))\n\nprint(\"Free size for system and users: {:,} bytes\".format(free_bytes))\nprint(\"Free size for users: {:,} bytes\".format(available_bytes))\nprint(\"Mount flags: {:,}\".format(mount_flags))\nprint(\"Max filename length: {:,}\".format(max_filename_length))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/20-tinyml/","title":"TinyML","text":"

                                                                                                                                                                                                                                                                                                              TinyML is designed to help you do machine learning and embedded systems. Once you have trained a deep learning model, you can use TinyML perform data analysis (inference) on a microcontroller or a cell phone.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/20-tinyml/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • UCTRONICS RP2040 Dev Board for TinyMLd - $50.00 US
                                                                                                                                                                                                                                                                                                              • Harvard Fundamentals of TinyML Course - free without certificate.
                                                                                                                                                                                                                                                                                                              • EMLearn GitHub Repo for Machine Learning
                                                                                                                                                                                                                                                                                                              • EMLearn YouTube Video
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/21-botton-callback/","title":"Button Callback","text":"
                                                                                                                                                                                                                                                                                                              import re\n\ndef extract_gpio_pin(input_string):\n    # Use a regular expression to find the GPIO number\n    match = re.search(r\"GPIO(\\d+)\", input_string)\n    if match:\n        # Convert the extracted number to an integer to remove leading zeros\n        return int(match.group(1))\n    else:\n        # Return None if no match is found (or raise an exception if that's preferable)\n        return None\n\n# Test the function with examples\nprint(extract_gpio_pin(\"Pin(GPIO15, mode=IN, pull=PULL_UP)\"))  # Output: 15\nprint(extract_gpio_pin(\"Pin(GPIO7, mode=IN, pull=PULL_UP)\"))   # Output: 7\nprint(extract_gpio_pin(\"Pin(GPIO03, mode=IN, pull=PULL_UP)\"))  # Output: 3\n

                                                                                                                                                                                                                                                                                                              https://chat.openai.com/share/6e6d8123-ed4d-4dc6-a915-030fe2245dfe

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/","title":"Spectrum Analyzer","text":""},{"location":"advanced-labs/30-spectrum-analyzer/#chatgpt-prompt","title":"ChatGPT Prompt","text":"
                                                                                                                                                                                                                                                                                                              I would like to create an audio spectrum analyzer using a Raspberry Pi Pico and a 128x64 OLED display using MicroPython. How would you suggest I go about this project. Break it down step-by-step.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#chatgpt-gpt-4-response","title":"ChatGPT GPT-4 Response","text":"

                                                                                                                                                                                                                                                                                                              Creating an audio spectrum analyzer with a Raspberry Pi Pico and a 128x64 OLED display using MicroPython is a fascinating project that combines hardware interfacing with digital signal processing. Below is a step-by-step guide to help you get started on this project.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-1-gather-the-components","title":"Step 1: Gather the Components","text":"
                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico: A microcontroller board based on the RP2040 microcontroller chip.
                                                                                                                                                                                                                                                                                                              2. 128x64 OLED Display: This will be used for visualizing the audio spectrum. Ensure it's compatible with the Pi Pico, ideally one that communicates over I2C or SPI.
                                                                                                                                                                                                                                                                                                              3. Electret Microphone Amplifier: This captures the audio signals. A module like the MAX4466 or a similar one would be suitable.
                                                                                                                                                                                                                                                                                                              4. Jump Wires: For connecting the components.
                                                                                                                                                                                                                                                                                                              5. Breadboard: Useful for prototyping without soldering.
                                                                                                                                                                                                                                                                                                              6. USB Cable: For programming the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-2-set-up-the-raspberry-pi-pico","title":"Step 2: Set Up the Raspberry Pi Pico","text":"
                                                                                                                                                                                                                                                                                                              1. Install MicroPython: Download and flash MicroPython onto the Raspberry Pi Pico. The Raspberry Pi Pico documentation provides clear instructions for this process.
                                                                                                                                                                                                                                                                                                              2. Prepare Your Development Environment: Install any necessary drivers and a code editor that supports MicroPython, such as Thonny or Visual Studio Code with the appropriate extensions.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-3-connect-the-hardware","title":"Step 3: Connect the Hardware","text":"
                                                                                                                                                                                                                                                                                                              1. Microphone to Pi Pico: Connect the output of the electret microphone amplifier to one of the analog input pins of the Pi Pico. Also, connect the ground and Vcc pins accordingly.
                                                                                                                                                                                                                                                                                                              2. OLED Display to Pi Pico: Connect the OLED display to the Pi Pico using I2C or SPI, depending on your display module. For I2C, you'll need to connect SDA, SCL, Vcc, and GND. For SPI, the connections will include SCK, MOSI, RES, DC, CS, Vcc, and GND.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-4-write-the-software","title":"Step 4: Write the Software","text":"
                                                                                                                                                                                                                                                                                                              1. Initialize the OLED Display: Write or adapt a MicroPython script to initialize the OLED display using the appropriate library. There are libraries available for both I2C and SPI OLED displays in MicroPython.
                                                                                                                                                                                                                                                                                                              2. Capture Audio Data: Write a script to capture audio data from the microphone using the ADC (Analog to Digital Converter) of the Pi Pico. The data capture should be done in real-time, and you may need to experiment with sampling rates.
                                                                                                                                                                                                                                                                                                              3. Process Audio Data: Implement a Fast Fourier Transform (FFT) algorithm to convert the time-domain audio signals into the frequency domain. This step is crucial for creating the spectrum analysis.
                                                                                                                                                                                                                                                                                                              4. Visualize the Spectrum: Map the frequency domain data to the OLED display. You will likely need to scale the data to fit nicely on the 128x64 display, representing different frequencies and their intensities.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-5-testing-and-troubleshooting","title":"Step 5: Testing and Troubleshooting","text":"
                                                                                                                                                                                                                                                                                                              1. Run Your Script: Test the entire system by running your script. You may need to adjust the audio capture settings or the way the data is visualized on the OLED display.
                                                                                                                                                                                                                                                                                                              2. Troubleshoot: If you encounter issues, use serial print statements to debug and understand where things might be going wrong.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#step-6-refinement-and-expansion","title":"Step 6: Refinement and Expansion","text":"
                                                                                                                                                                                                                                                                                                              1. Refine the Display: You can refine how the audio spectrum is displayed, perhaps by adjusting the resolution, colors (if your OLED supports it), or adding additional visual elements like peak hold.
                                                                                                                                                                                                                                                                                                              2. Experiment with Features: Consider adding features such as different modes for the spectrum analyzer, audio input from different sources, or even a GUI for interacting with the device.
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/#resources","title":"Resources","text":"
                                                                                                                                                                                                                                                                                                              • MicroPython Documentation: Essential for understanding how to program the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              • FFT Libraries: Look for MicroPython libraries or examples of FFT implementations suitable for the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              • OLED Libraries: Find libraries specific to your OLED display model for easier programming.

                                                                                                                                                                                                                                                                                                              This project involves a mix of hardware setup, digital signal processing, and real-time data visualization. Take it step by step, and don't hesitate to seek out community forums and resources if you encounter challenges.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/","title":"Test Incoming Sound","text":""},{"location":"advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/#prompt","title":"Prompt","text":"
                                                                                                                                                                                                                                                                                                              OK, I now have a Raspberry Pi Pico and the OLED display hooked up.  I also have a microphone hooked up to ADC0 on port GPIO26.  How can I test that the signal is coming into the ADC?  Can you write a MicroPython program that displays the audio signal on the OLED?\n\nI am using a ssd1306 and I use the following MicroPython:\n
                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport ssd1306\n\nWIDTH = 128\nHEIGHT = 64\n\nclock=Pin(2) #SCL\ndata=Pin(3) #SDA\nRES = machine.Pin(4)\nDC = machine.Pin(5)\nCS = machine.Pin(6)\n\nspi=machine.SPI(0, sck=clock, mosi=data)\ndisplay = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n# clear the display\ndisplay.fill(0)\n# draw a diagonal line\ndisplay.line(0, 0, WIDTH, HEIGHT, 1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/01-test-incoming-sound/#gpt-4-reponse","title":"GPT-4 Reponse","text":"

                                                                                                                                                                                                                                                                                                              To test that the signal is coming into the ADC (Analog-to-Digital Converter) on the Raspberry Pi Pico via GPIO26, and to display the audio signal on your SSD1306 OLED, you can use the following MicroPython script. This script will read the analog values from the microphone connected to GPIO26 and plot these values in real-time on the OLED display, creating a simple waveform visualization.

                                                                                                                                                                                                                                                                                                              Note: Before running this script, ensure you have properly initialized and connected your microphone to GPIO26 (ADC0), and the OLED display is correctly wired for SPI communication as per your provided initialization.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom machine import Pin, ADC, SPI\nimport ssd1306\n\n# OLED display width and height\nWIDTH = 128\nHEIGHT = 64\n\n# SPI pins for OLED\nclock = Pin(2) # SCL\ndata = Pin(3) # SDA\nRES = Pin(4)\nDC = Pin(5)\nCS = Pin(6)\n\n# Initialize SPI and OLED Display\nspi = SPI(0, sck=clock, mosi=data)\ndisplay = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\n# Initialize ADC for GPIO26 (ADC0)\nadc = ADC(Pin(26))\n\ndef plot_signal():\n    display.fill(0) # Clear the display\n    old_x = 0\n    old_y = HEIGHT // 2\n\n    # For simplicity, we're plotting every other pixel\n    for x in range(0, WIDTH, 2):\n        # Read from ADC (values will be from 0 to 4095)\n        val = adc.read_u16()\n        # Scale the ADC value to fit the OLED height\n        y = int((val / 65535) * HEIGHT)\n        # Invert y to plot correctly on the OLED\n        y = HEIGHT - y\n        # Draw a line from the last point to the new point\n        display.line(old_x, old_y, x, y, 1)\n        old_x, old_y = x, y\n\n    display.show() # Update the display with the new data\n\nwhile True:\n    plot_signal()\n    utime.sleep(0.1) # Small delay to reduce flickering\n

                                                                                                                                                                                                                                                                                                              This script continuously reads the analog signal from the microphone and plots a simplified version of the waveform across the OLED display. Here's a breakdown of the plotting part:

                                                                                                                                                                                                                                                                                                              • The screen is cleared at the beginning of each frame with display.fill(0).
                                                                                                                                                                                                                                                                                                              • We read a value from the ADC and scale it to fit the OLED's screen height.
                                                                                                                                                                                                                                                                                                              • We draw a line from the previous point to the current point to create a continuous waveform.
                                                                                                                                                                                                                                                                                                              • The display is updated with display.show() to visualize the waveform.

                                                                                                                                                                                                                                                                                                              This example provides a basic way to visualize audio signals. The resolution and quality of the visualization can be further enhanced or adjusted according to your requirements.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/02-gain-pot/","title":"Adding A Gain Potentiometer.","text":""},{"location":"advanced-labs/30-spectrum-analyzer/02-gain-pot/#prompt","title":"Prompt","text":"

                                                                                                                                                                                                                                                                                                              The signal is very low on the display. I have added a Potentiometer on ADC1 which is on GPIO PIN 27. Can you please regenerate the entire program with sound on ADC0 and gain on ADC1. sound = ADC(Pin(26)) gain = ADC(Pin(27))

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/02-gain-pot/#chatgpt-","title":"ChatGPT-","text":"

                                                                                                                                                                                                                                                                                                              Certainly! To adjust the signal's amplitude on the display based on the gain from a potentiometer connected to ADC1 (GPIO PIN 27), you can modify the program as follows. This updated script will use the value from the potentiometer to scale the audio signal from the microphone, making the waveform larger or smaller on the OLED display according to the potentiometer's position.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom machine import Pin, ADC, SPI\nimport ssd1306\n\n# OLED display width and height\nWIDTH = 128\nHEIGHT = 64\n\n# SPI pins for OLED\nclock = Pin(2)  # SCL\ndata = Pin(3)  # SDA\nRES = Pin(4)\nDC = Pin(5)\nCS = Pin(6)\n\n# Initialize SPI and OLED Display\nspi = SPI(0, sck=clock, mosi=data)\ndisplay = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\n# Initialize ADC for sound input (GPIO26) and gain control (GPIO27)\nsound = ADC(Pin(26))\ngain = ADC(Pin(27))\n\ndef plot_signal_with_gain():\n    display.fill(0)  # Clear the display\n    old_x = 0\n    old_y = HEIGHT // 2\n\n    # Read gain control (potentiometer) value\n    gain_value = gain.read_u16() + 1  # Adding 1 to avoid division by zero\n\n    for x in range(0, WIDTH, 2):\n        # Read from ADC (sound input)\n        val = sound.read_u16()\n\n        # Adjust the sound value based on the gain\n        # Note: This scaling might need adjustment depending on your specific potentiometer and desired sensitivity\n        adjusted_val = min(((val * gain_value) >> 16), 65535)  # Ensure the adjusted value does not exceed ADC's max value\n\n        # Scale the adjusted value to fit the OLED height\n        y = int((adjusted_val / 65535) * HEIGHT)\n        # Invert y to plot correctly on the OLED\n        y = HEIGHT - y\n        # Draw a line from the last point to the new point\n        display.line(old_x, old_y, x, y, 1)\n        old_x, old_y = x, y\n\n    display.show()  # Update the display with the new data\n\nwhile True:\n    plot_signal_with_gain()\n    utime.sleep(0.1)  # Small delay to reduce flickering\n

                                                                                                                                                                                                                                                                                                              In this script, the gain control (potentiometer) reading is used to adjust the amplitude of the sound signal before plotting it. The gain_value is read from ADC1 and is used to scale the audio signal from the microphone connected to ADC0. The line adjusted_val = min(((val * gain_value) >> 16), 65535) scales the microphone input based on the potentiometer's position, and the bit shift >> 16 is used to keep the value within the 16-bit range of the ADC's output.

                                                                                                                                                                                                                                                                                                              This method should help make the displayed signal more responsive to the potentiometer's adjustments, allowing you to visually enhance or reduce the waveform amplitude on the OLED display.

                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/03-display-scroll/","title":"Display Scroll","text":""},{"location":"advanced-labs/30-spectrum-analyzer/03-display-scroll/#prompt","title":"Prompt","text":"
                                                                                                                                                                                                                                                                                                              The display is a bit slow. Can you rewrite the plot\\_signal\\_with\\_gain function so that the scroll() function is used to move the display to the left by one pixel?\n
                                                                                                                                                                                                                                                                                                              "},{"location":"advanced-labs/30-spectrum-analyzer/03-display-scroll/#chatgpt-gpt-4-response","title":"ChatGPT GPT-4 Response","text":"

                                                                                                                                                                                                                                                                                                              To make the display update faster and to create a scrolling effect that moves the waveform to the left by one pixel, you can modify the plot_signal_with_gain function to use the scroll() method of the SSD1306 library. This will shift the entire display content to the left by one pixel, and then you can plot the new data point at the right edge of the display. Here's how you can implement this:

                                                                                                                                                                                                                                                                                                              def plot_signal_with_gain():\n    # Scroll the display content to the left by one pixel\n    display.scroll(-1, 0)\n\n    # Read gain control (potentiometer) value\n    gain_value = gain.read_u16() + 1  # Adding 1 to avoid division by zero\n\n    # Read from ADC (sound input)\n    val = sound.read_u16()\n\n    # Adjust the sound value based on the gain\n    adjusted_val = min(((val * gain_value) >> 16), 65535)  # Ensure the adjusted value does not exceed ADC's max value\n\n    # Scale the adjusted value to fit the OLED height\n    y = int((adjusted_val / 65535) * HEIGHT)\n    # Invert y to plot correctly on the OLED\n    y = HEIGHT - y\n\n    # Since we've scrolled, we only need to update the last column (x = WIDTH - 1)\n    # Clear the last column first (optional, depending on the desired visual effect)\n    for clear_y in range(HEIGHT):\n        display.pixel(WIDTH - 1, clear_y, 0)\n\n    # Draw the new data point at the right edge of the display\n    display.pixel(WIDTH - 1, y, 1)\n\n    # Update the display with the new data\n    display.show()\n

                                                                                                                                                                                                                                                                                                              In this updated function, the display is scrolled left by one pixel at the beginning of each update cycle using display.scroll(-1, 0). This creates room to draw the new data point at the far right edge (WIDTH - 1) of the display. The loop that clears the last column before drawing the new point is optional and can be adjusted or removed depending on the visual effect you're aiming for.

                                                                                                                                                                                                                                                                                                              Remember, while scroll() improves the visual fluidity by creating a continuous scrolling effect, the update rate can still be limited by the display's physical refresh rate and the speed at which your MicroPython script can run. Experiment with the utime.sleep(0.1) delay at the end of the main loop to find a balance between smoothness and speed that works for your specific application.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/01-intro/","title":"Introduction to MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This lesson assumes that you have at least skimmed the Getting Started sections and have selected one of the MicroPython IDEs to write your code.

                                                                                                                                                                                                                                                                                                              The lesson will introduce you to the basic concepts of using MicroPython using the $4 Raspberry Pi Pico or a similar microcontroller.

                                                                                                                                                                                                                                                                                                              The first two examples just use the Raspberry Pi Pico and don't require a breadboard or wiring. All the subsequent examples will require you to place components on a solderless breadboard.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/","title":"Blink in MicroPython","text":""},{"location":"basics/03-blink/#overview","title":"Overview","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will use MicroPython to make the green on-board LED on the Raspberry Pi Pico blink on and off every half second. The only things you need to run this program are

                                                                                                                                                                                                                                                                                                              1. a working IDE like Thonny
                                                                                                                                                                                                                                                                                                              2. a USB cable
                                                                                                                                                                                                                                                                                                              3. a $4 Raspberry Pi Pico microcontroller
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#blinking-the-builtin-led","title":"Blinking the Builtin LED","text":"

                                                                                                                                                                                                                                                                                                              The pico has a single built in green LED wired to logical pin 25. We call this GPIO 25. GPIO means General Purpose Input and Output pin. Here is a sample program that you can use. Don't worry about understanding each line yet. We will cover the various parts of the file in later sections.

                                                                                                                                                                                                                                                                                                              # Setup - run once\nfrom machine import Pin # Get the Pin function from the machine module.\nfrom time import sleep # Get the sleep library from the time module.\n\n# This is the built-in green LED on the Pico.\nBUILT_IN_LED_PIN = 25\n# change this to the following named pin on the \"W\"\n# BUILT_IN_LED_PIN = Pin(\"LED\", Pin.OUT)\n\n# The line below indicates we are configuring this as an output (not input)\nled = machine.Pin(BUILT_IN_LED_PIN, machine.Pin.OUT)\n\n# Main loop: Repeat the forever...\nwhile True:\n    led.high() # turn on the LED\n    sleep(0.5) # leave it on for 1/2 second\n    led.low()  # Turn off the LED\n    sleep(0.5) # leave it off for 1/2 second\n

                                                                                                                                                                                                                                                                                                              This program has two main parts. The first part is often called the preamble or the setup code. This code gets executed only once when the program is run. In this example, the setup loads the right libraries and initializes global variables.

                                                                                                                                                                                                                                                                                                              The second part is the main event loop. This program continues to run until the device is powered down or the program is reset.

                                                                                                                                                                                                                                                                                                              The from machine import Pin statement is required to define the characteristics of our physical machine. In this case, we are loading the Pin python library.

                                                                                                                                                                                                                                                                                                              The from time import sleep library is required for the python sleep function. Note that some programs use utime for MicroPython time. These both work the same. They are really just synonyms or alias of each other. Although the use of utime is technically a little bit more precise - the reader knows that the code is using the actual MicroPython time library, the use of the time alias makes our code on character smaller and can make our code more portable to other systems.

                                                                                                                                                                                                                                                                                                              Note that the text after the hash or pound characters are comments. Comments are ignored by the Python interpreter but it is a good practice to put in comments in your code to help others understand your program.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#changing-the-blink-speed","title":"Changing the Blink Speed","text":"

                                                                                                                                                                                                                                                                                                              Next, lets create a Python global variable for the delay that the LED is on and off.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nBUILT_IN_LED_PIN = 25\n# this is the builtin LED on the Pico\nled = Pin(BUILT_IN_LED_PIN, machine.Pin.OUT)\n\n# global variables\ndelay = .25\n\n# repeat forever\nwhile True:\n    led.high() # turn on the LED\n    sleep(delay) # leave it on for 1/2 second\n    led.low() # Turn off the LED\n    sleep(delay) # leave it off for 1/2 second\n

                                                                                                                                                                                                                                                                                                              This program will blink the built-in LED on and off every 1/4 of a second. By changing the delay variable you can make the LED blink faster and slower.

                                                                                                                                                                                                                                                                                                              Challenge

                                                                                                                                                                                                                                                                                                              What is the fastest you can make the LED blink and still see it changing? What does this tell you about the human eye?

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#using-toggle","title":"Using Toggle","text":"

                                                                                                                                                                                                                                                                                                              Instead of using the on() and off() methods, we can also just use the toggle() function.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nled_onboard = machine.Pin(25, machine.Pin.OUT)\nwhile True:\n    led_onboard.toggle()\n    sleep(.25)\n

                                                                                                                                                                                                                                                                                                              The toggle() function looks at the state of the output pin. If it is high, it sets the value low. If it is low, it sets it high. Whatever the value currently is, it will set it to the opposite value.

                                                                                                                                                                                                                                                                                                              If you save the file as main.py, this program will run when the microcontroller starts up without the BOOTSEL being pressed.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#blinking-an-external-led","title":"Blinking an External LED","text":"

                                                                                                                                                                                                                                                                                                              Although the builtin LED is convenient, you can use the almost the code to blink any external LED that is connected through a 330 ohm resister in series to the LED.

                                                                                                                                                                                                                                                                                                              We will assume that an LED is connected to pin GIO16 and is connected via a 330 ohm resistor to ground.

                                                                                                                                                                                                                                                                                                              Here is the code that will blink an LED that is connected to PIN GIO16, which is in the upper right corner of the Pico.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\n# this is the lower right corner pin on the Pico with USB on the bottom\nEXTERNAL_LED_PIN = 16\nled = machine.Pin(EXTERNAL_LED_PIN, machine.Pin.OUT)\n\n# repeat forever\nwhile True:\n    led.high() # turn on the LED\n    time.sleep(0.5) # leave it on for 1/2 second\n    led.low() # Turn off the LED\n    sleep(0.5) # leave it off for 1/2 second\n

                                                                                                                                                                                                                                                                                                              Here is that same program using the toggle() function:

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nEXTERNAL_LED_PIN = 16\nexternal_led = machine.Pin(EXTERNAL_LED_PIN, machine.Pin.OUT)\n\nwhile True:\n    external_led.toggle()\n    sleep(5)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#solution-to-led-row-lab","title":"Solution to LED Row Lab","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nEXTERNAL_LED_PIN1 = 16\nEXTERNAL_LED_PIN2 = 17\nEXTERNAL_LED_PIN3 = 18\nEXTERNAL_LED_PIN4 = 19\nled1 = machine.Pin(EXTERNAL_LED_PIN1, machine.Pin.OUT)\nled2 = machine.Pin(EXTERNAL_LED_PIN2, machine.Pin.OUT)\nled3 = machine.Pin(EXTERNAL_LED_PIN3, machine.Pin.OUT)\nled4 = machine.Pin(EXTERNAL_LED_PIN4, machine.Pin.OUT)\n\nwhile True:\n    # blink the first LED\n    led1.high()\n    sleep(.5)\n    led1.low()\n\n    # blink the 2nd LED\n    led2.high()\n    sleep(.5)\n    led2.low()\n\n\n    # blink the 3rd LED\n    led3.high()\n    sleep(.5)\n    led3.low()\n\n\n    # blink the 4th LED\n    led4.high()\n    sleep(.5)\n    led4.low()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#extra-credit-lab","title":"Extra credit lab","text":"

                                                                                                                                                                                                                                                                                                              Can you rewrite the program above using an array of pin values like this:

                                                                                                                                                                                                                                                                                                              LED_PINS = [16,17,28,19]\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-blink/#more-to-explore","title":"More to Explore","text":"
                                                                                                                                                                                                                                                                                                              1. Can you blink both the internal on board LED and an external LED?
                                                                                                                                                                                                                                                                                                              2. How many external LEDs can you blink? What is the maximum number of output pins on the Raspberry Pi Pico?
                                                                                                                                                                                                                                                                                                              3. What if you wanted to control more LEDs then you have available output pins? What do you think your options might be? (answer - use a NeoPixel or a shift register like a SN74HC595). See the peppe8o Shift Register Tutorial on the RP2040 for an example of this.
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/","title":"Button","text":"

                                                                                                                                                                                                                                                                                                              In this lesson we will hook a single momentary push button up to our Raspberry Pi Nano. We will use it to toggle the built-in LED. We will start out with simply polling the button 10 times a second to check it's state. Then we will show how to use an interrupt handler function to monitor events from the button.

                                                                                                                                                                                                                                                                                                              In the example above, we are connecting the button on the left to the lower-left corner pin of the Raspberry Pi Pico. This is GPIO Pin 15 and is in row number 20 of our breadboard.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#momentary-switch-buttons","title":"Momentary Switch Buttons","text":"

                                                                                                                                                                                                                                                                                                              We use \"B3F\" tactile switch buttons that can be mounted directly on our breadboards. When the button is pressed, it connects a wire that joins two pins on one side to the two pins on the other side. The buttons can be mounted directly over the trough in the center of the breadboard. They typically cost under $2 for 10 buttons or about 20 cents per button.

                                                                                                                                                                                                                                                                                                              Here are the internal connections within the switch.

                                                                                                                                                                                                                                                                                                              This is the connection diagram that shows how the button is connected to the GPIO connector in the lower-left corner of the Raspberry Pi Pico. This corresponds to GP15 or Pin #15 in our code.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#sample-button-polling-code","title":"Sample Button Polling Code","text":"

                                                                                                                                                                                                                                                                                                              Here is our fist example that uses a simple \"watching\" loop to check if the button value has change 10 times per second. In this case, the built-in LED is connected to pin 25.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport time\n\n# GPIO is the internal built-in LED\nled = Pin(25, Pin.OUT)\n# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating\nbutton = Pin(15, Pin.IN, Pin.PULL_DOWN) \n\nwhile True:\n    if button.value(): # if the value changes\n        led.toggle()\n        time.sleep(0.1) # wait 1/10th of a second\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#interrupt-handler-version","title":"Interrupt Handler Version","text":"

                                                                                                                                                                                                                                                                                                              Although the polling version is simple, it does take a lot of the CPU resources. The button.value() is checked 10 times a second, even though the button might only be pressed once a day!

                                                                                                                                                                                                                                                                                                              A more efficient version uses a strategy called an interrupt handler. This is a function that is \"registered\" by micropython to handel external events such as a button press.

                                                                                                                                                                                                                                                                                                              # Use an interrupt function count the number of times a button has been pressed\nfrom machine import Pin\nimport micropython\nimport time\n\n# global value\nbutton_pressed_count = 0\n\n# Interrupt Service Routine for Button Pressed Events - with no debounce\ndef button1_pressed(change):\n    global button_pressed_count\n    button_pressed_count += 1\n\nbutton1 = Pin(14, Pin.IN, Pin.PULL_DOWN)\nbutton1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING)\n\nbutton_pressed_count_old = 0\nwhile True:\n    if button_pressed_count_old != button_pressed_count:\n       print('Button 1 value:', button_pressed_count)\n       button_pressed_count_old = button_pressed_count\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#interrupt-handler-with-a-debounce-feature","title":"Interrupt Handler with a Debounce Feature","text":"

                                                                                                                                                                                                                                                                                                              One of the problems with most switches is that they don't turn on and off perfectly each time. As the connection is getting close to closing some electrons jump the gap and the switch appears to turn on for a few microseconds. So to a computer, this looks like someone quickly pressing a button rapidly until it is firmly closed or completely open. This intermediate stage between completely open and closed is called the \"bounce\" stage of a switch opening and closing.

                                                                                                                                                                                                                                                                                                              To remove this problem and get a clean signal, we can use either a hardware solution (wiring a capacitor to remove the high frequency noise) or we can be clever and solve the problem with a few extra lines of code.

                                                                                                                                                                                                                                                                                                              The secret is to setup a timer when the switch is first closed or opened. We then ignore all the crazy stuff that happens for about 1/5th of a second (200 milliseconds). By then we usually have a solid indication that the button is changing state and we can return the new value.

                                                                                                                                                                                                                                                                                                              Here is a example of this \"Debounce\" code in MicroPython:

                                                                                                                                                                                                                                                                                                              import utime\nfrom machine import Pin\n\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n\nbutton_presses = 0 # the count of times the button has been pressed\nlast_time = 0 # the last time we pressed the button\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail\nbutton_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global button_presses, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200: \n        button_presses +=1\n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nbutton_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# This is for only printing when a new button press count value happens\nold_presses = 0\nwhile True:\n    # only print on change in the button_presses value\n    if button_presses != old_presses:\n        print(button_presses)\n        builtin_led.toggle()\n        old_presses = button_presses\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#two-button-example","title":"Two Button Example","text":"

                                                                                                                                                                                                                                                                                                              This example uses two buttons. One adds one to a counter, and the other decrements the counter. In the IRQ we look for the string '''14''' in the incoming pin event string. If the string is present, then we increment the button_presses variable. If it is not, then we decrement the counter.

                                                                                                                                                                                                                                                                                                              This example is useful whenever you have two buttons that control the mode of a microcontroller.

                                                                                                                                                                                                                                                                                                              Note that you can tune the delay period. If you have clean buttons and you want to allow for fast double-click events you can lower the time. 200 milliseconds is good for low-cost noisy buttons that may have many spikes in the open and closing transitions.

                                                                                                                                                                                                                                                                                                              import utime\nfrom machine import Pin\n\n# Sample two button Raspberry Pi Pico MicroPython example\n# with a debounce delay value of 200ms in the interrupt handler\n# https://www.coderdojotc.org/micropython/basics/03-button/\n\n# these are the pins in the lower-left corner (USB on top)\nBUTTON_PIN_A = 14\nBUTTON_PIN_B = 15\n\nbutton_presses = 0 # the count of times the button has been pressed.  A is +1, B is -1\nlast_time = 0 # the last time we pressed the button\n\n# we toggle the builtin LED to get visual feedback\nbuiltin_led = machine.Pin(25, Pin.OUT)\n\n# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail\nbutton_a = machine.Pin(BUTTON_PIN_A, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_b = machine.Pin(BUTTON_PIN_B, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# this is the interrupt callback handler\n# get in and out quickly\ndef button_callback(pin):\n    global button_presses, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # print(pin)\n        if '14' in str(pin):\n            button_presses +=1\n        else:\n            button_presses -= 1\n        last_time = new_time\n\n# now we register the handler functions when either of the buttons is pressed\nbutton_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback)\nbutton_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback)\n\n# This is for only printing when a new button press count value happens\nold_presses = 0\n\nprint(button_presses)\nwhile True:\n    # only print on change in the button_presses value\n    if button_presses != old_presses:\n        print(button_presses)\n        builtin_led.toggle()\n        old_presses = button_presses\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-button/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico Getting Started Guide Lab 6
                                                                                                                                                                                                                                                                                                              2. YouTube Video
                                                                                                                                                                                                                                                                                                              3. Sample eBay List of Switches with trough pins
                                                                                                                                                                                                                                                                                                              4. Sample B3F Button on eBay 10 pieces for $1.50
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/","title":"MicroPython Potentiometer Lab","text":"

                                                                                                                                                                                                                                                                                                              In this lab we will use a 10K ohm potentiometer to demonstrate how a turn of a knob can result in getting a continuous variable from a user into our code. We will show how we can use a potentiometer to change the blinking speed of on LED.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/#about-analog-to-digital-converters","title":"About Analog to Digital Converters","text":"

                                                                                                                                                                                                                                                                                                              Digital microcontrollers are inherently noisy. They have clocks that pull power from the power supply and cause voltage fluctuations when we compare a signal to these power lines. This makes it difficult to get

                                                                                                                                                                                                                                                                                                              ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required. AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and terminating at this pin.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/#circuit-diagram","title":"Circuit Diagram","text":"
                                                                                                                                                                                                                                                                                                              1. Connect the top rail of the potentiometer to row 6 which is the ADC_VREF pin.
                                                                                                                                                                                                                                                                                                              2. Connect the center tap to row 10 which is ADC0
                                                                                                                                                                                                                                                                                                              3. Connect row 8 to the bottom rail of the potentiometer to the Analog Ground (AGND) pin

                                                                                                                                                                                                                                                                                                              Note: to get an accurate noise-free reading from the potentiometer you must use the ADC_VREF and the AGND pins. These are special pins designed to reduce the noise on the power areas of the pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/#sample-code-to-print-potentiometer-values","title":"Sample Code To Print Potentiometer Values","text":"
                                                                                                                                                                                                                                                                                                              from machine import ADC\nfrom utime import sleep\npot = ADC(26)\nwhile True:\n    print(pot.read_u16())\n    sleep(.2)\n
                                                                                                                                                                                                                                                                                                              graph LR\np[Pico]-->|ADC_VREF 36 row=6| pos(Positive)\np[Pico]-->|AGND 33 row=8| neg(Negative)\np[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)\n    pos(Positive) --- pot(Potentiometer)\n    neg(Negative) --- pot(Potentiometer)\n    tap(Center Tap) --- pot(Potentiometer)\n

                                                                                                                                                                                                                                                                                                              Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/#changing-blink-speed-with-a-potentiometer","title":"Changing Blink Speed with a Potentiometer","text":"
                                                                                                                                                                                                                                                                                                              from machine import ADC, Pin\nfrom utime import sleep\n\n# this is the built-in LED on the Pico\nled = Pin(25, Pin.OUT)\n\n# ADC0 is GPIO 26.  Connect to row 10 the right side\npot = ADC(26)\n\nMAX_DELAY = .5 # seconds\n\n# global variables\ndelay = 0\n\n# repeat forever\nwhile True:\n    pot_value = pot.read_u16() # read the value from the pot\n    delay = pot_value/65025 * MAX_DELAY\n    print(\"delay:\", delay)\n    if delay > 0:\n        print(\"frequency (toggles per second):\", 1/delay)\n    led.high() # turn on the LED\n    sleep(delay) # leave it on for 1/2 second\n    led.low() # Turn off the LED\n    sleep(delay) # leave it off for 1/2 second\n

                                                                                                                                                                                                                                                                                                              The following video shows this script in action.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/03-potentiometer/#changing-the-brightness-of-the-building-led","title":"Changing the Brightness of the Building LED","text":"

                                                                                                                                                                                                                                                                                                              We can change the brightness of the builtin LED by using the POT value to change the PWM duty cycle.

                                                                                                                                                                                                                                                                                                              Here is a sample progam that does this:

                                                                                                                                                                                                                                                                                                              from machine import ADC, Pin, PWM\nfrom utime import sleep\n\n# Pins Used\nBUILT_IN_LED_PIN = 25\nPOT_PIN = 26\n\npot = ADC(POT_PIN)\n\nbuiltin_pwm = PWM(Pin(BUILT_IN_LED_PIN))\nbuiltin_pwm.freq(1000) # 1K Hz\n\nPOLL_DELAY = .1 # poll the pot after this delay in seconds\n\n# repeat forever\nwhile True:\n    pot_value = pot.read_u16() # read the value from the pot\n    print(\"pot value:\", pot_value)\n    builtin_pwm.duty_u16(pot_value)\n    sleep(POLL_DELAY)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-fade-in-and-out/","title":"Fade an LED in and Out","text":"

                                                                                                                                                                                                                                                                                                              In the prior Blink lab, we turned an LED on an off at different speeds. But what if we want to slowly turn on our LED on and off? In this lab we will show you how to dim your LED to any brightness level you want.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-fade-in-and-out/#welcome-to-pulse-width-modulation","title":"Welcome to Pulse Width Modulation","text":"

                                                                                                                                                                                                                                                                                                              Although digital computers are good at quickly turning signals on and off, they don't really allow us to easily set an output to a given voltage level without complex circuits. But there is an easier way to adjust the brightness of an LED! We can quickly turn the signal to the LED on and off. We can do this so quickly that you can't even see it flicker. Controlling the amount of time a signal is on is all about controlling the width of the ON pulse. That is why this is called Pulse Width Modulation or PWM for short.

                                                                                                                                                                                                                                                                                                              With a PWM design there are two things we need to tell the microcontroller:

                                                                                                                                                                                                                                                                                                              1. How often do you want a square wave to go on and off?
                                                                                                                                                                                                                                                                                                              2. How wide should the on part of the pulse be (relative to the total width). This is called the duty cycle.

                                                                                                                                                                                                                                                                                                              The rate of change of the pulse is call the frequency. You can set the frequency to be 1,000 changes per second, which is much faster than the human eye can detect. This is done using the following line:

                                                                                                                                                                                                                                                                                                              pwm.freq(1000)\n

                                                                                                                                                                                                                                                                                                              Note that we can slow the frequency way down and the dimming effect will still work. As an experiment you can change the PWM frequency to around 20 and you will see a distinct flicker as the LED turns on.

                                                                                                                                                                                                                                                                                                              Here is the sample program that will slowly dim the builtin LED that is on pin 25:

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom time import sleep\n\npwm = PWM(Pin(25))\n\npwm.freq(1000)\n\nwhile True:\n    for duty in range(65025):\n        pwm.duty_u16(duty)\n        sleep(0.0001)\n    for duty in range(65025, 0, -1):\n        pwm.duty_u16(duty)\n        sleep(0.0001)\n

                                                                                                                                                                                                                                                                                                              Note that the duty cycle starts at 0 (always off) and moves slowly up to 65,025 (always on). It then does the reverse and slowly dims the LED and then repeats. There is only a 1/10,000 of a delay between these changes so the LED will completely turn on in about six seconds before it starts to dim again.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-fade-in-and-out/#pwm-functions","title":"PWM Functions","text":"

                                                                                                                                                                                                                                                                                                              Here is a list of the PWM functions.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\n\npwm0 = PWM(Pin(0))      # create PWM object from a pin\npwm0.freq()             # get current frequency\npwm0.freq(1000)         # set frequency (1000 cycles per minute)\npwm0.duty_u16()         # get current duty cycle, range 0-65535\npwm0.duty_u16(200)      # set duty cycle, range 0-65535\npwm0.deinit()           # turn off PWM on the pin\n

                                                                                                                                                                                                                                                                                                              Make sure you deinit() to de-initialize the PWM controller after you are done. You may have to trap the stop to do this. For example if a PWM is driving motors, your Stop must send deinit() to each motor controller. See the Interrupt Handlers for details.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-fade-in-and-out/#suggested-exercises","title":"Suggested Exercises","text":"
                                                                                                                                                                                                                                                                                                              1. Change the frequency from 1,000 to 500, 100, 50, 40, 30, 25, 20, and 10. When can you just barley see it flicker? What does this tell you about the human eye?
                                                                                                                                                                                                                                                                                                              2. Can you add a delay so that the LED stays on at full brightness for one second before it starts to dim again?
                                                                                                                                                                                                                                                                                                              3. Can you add a delay so that the LED is completely off for five seconds and then goes to full brightness and off in one second?
                                                                                                                                                                                                                                                                                                              4. What lights in your home would you like to see slowly dim on and off? How could you modify a light (safely) so that it slowly dimmed on and off. Would PWM work with all lightbulb types such as tungsten filament bulbs that take a long time to heat up and cool down?
                                                                                                                                                                                                                                                                                                              5. Can you hook up a set of red, green and blue LEDs program them to fade in and out to display all the colors of the rainbow (red, orange, yellow, green, blue, indigo and violet)?
                                                                                                                                                                                                                                                                                                              6. When you stop the program does the LED stop changing brightness? Does it retain the value that it had when you pressed the Stop function? What does that tell you about how main CPU and the role of PWM? Note that we will cover up doing \"cleanup\" events that stop all PWM activity in our Interrupt Handlers Lab
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-fade-in-and-out/#references","title":"References","text":""},{"location":"basics/04-fade-in-and-out/#pulse-with-modulation","title":"Pulse With Modulation","text":"
                                                                                                                                                                                                                                                                                                              1. Wikipedia Article on Pulse With Modulation
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-motor/","title":"Driving a Motor with the Pico","text":"

                                                                                                                                                                                                                                                                                                              The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the Raspberry Pi Pico Datasheet Table 5. 17 milliamps is fine for lighting up an LED. However, motors require much more power. 17 milliamps is not enough current to drive even small motors. Even our small DC hobby motors we use with our robots require around 200 milliamps.

                                                                                                                                                                                                                                                                                                              But don't worry! We have two ways around this problem.

                                                                                                                                                                                                                                                                                                              1. The first option is to use a simple transistor as a \"switch\" that will use our low-power digital signal to control its on-and-off settings.
                                                                                                                                                                                                                                                                                                              2. The second option is to use a full motor driver chip such as an L293D chip. This chip takes the same PWM signal we learned about in our Fade In and Out Lab.
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-motor/#basic-transistor-circuit","title":"Basic Transistor Circuit","text":"
                                                                                                                                                                                                                                                                                                              1. Transistor NPN 2222A
                                                                                                                                                                                                                                                                                                              2. Diode: 1N1448
                                                                                                                                                                                                                                                                                                              3. Motor: 3-6 volt hobby motor
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-motor/#pwm-control","title":"PWM Control","text":""},{"location":"basics/04-motor/#pwm-frequency","title":"PWM Frequency","text":"

                                                                                                                                                                                                                                                                                                              Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms)

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-motor/#sample-coder","title":"Sample Coder","text":"
                                                                                                                                                                                                                                                                                                              import machine\n\n# set the 7th from the bottom on right as our motor pin\nmotor_pin = machine.Pin(21, machine.Pin.OUT)\n# allocate a PWM object for controlling the motor speed\nmotor_pwm = machine.PWM(motor_pin)\nmotor_pwm.freq(50) # 50 hertz\nmotor_pwm.duty(51)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-motor/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Sparkfun Motor Lab from SIK Kit
                                                                                                                                                                                                                                                                                                              2. Nick Zoic MicroPython Motor Control Tutorial
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-read-pot/","title":"Using MicroPython to Read a Potentiometer","text":""},{"location":"basics/04-read-pot/#reading-a-potentiometer","title":"Reading a Potentiometer","text":"

                                                                                                                                                                                                                                                                                                              ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required. AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and terminating at this pin.

                                                                                                                                                                                                                                                                                                              graph LR\np[Pico]-->|ADC_VREF 36 row=6| pos(Positive)\np[Pico]-->|AGND 33 row=8| neg(Negative)\np[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)\n    pos(Positive) --- pot(Potentiometer)\n    neg(Negative) --- pot(Potentiometer)\n    tap(Center Tap) --- pot(Potentiometer)\n

                                                                                                                                                                                                                                                                                                              Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-read-pot/#sampling-data","title":"Sampling data","text":"

                                                                                                                                                                                                                                                                                                              Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values.

                                                                                                                                                                                                                                                                                                              Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples.

                                                                                                                                                                                                                                                                                                              def sample_pot(pin, count):\n    total = 0\n    for i in range(count):\n        total += int(pin.read_u16())\n        utime.sleep_ms(5)\n    return int(total / count)\n
                                                                                                                                                                                                                                                                                                              pot_pin_1 = machine.ADC(26)\n# return a value after sampling 10 times\nsample_pot(pot_pin_1, 10)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/04-servo/","title":"Micropython Servo Lab","text":"

                                                                                                                                                                                                                                                                                                              TBD

                                                                                                                                                                                                                                                                                                              import machine\nimport pyb\n\n# The pyboard has four simple servo connections\nservo = pyb.Servo(1)\n\nservo.angle(90, 5000)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/","title":"NeoPixels","text":"

                                                                                                                                                                                                                                                                                                              NeoPixels are Red-Green-Blue LEDs that are designed to makes them easy to control with three wires: GND, +5V and a single serial data line. They are very popular with our students because they are powerful, easy to program and full of bling.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              As of March of 2022 there is now built-in support for NeoPixels in the MicroPython 1.18 runtime for the Raspberry Pi RP2040 microcontroller. Although you can still use custom libraries, this tutorial assumes you are using version 1.18 or later.

                                                                                                                                                                                                                                                                                                              Controlling NeoPixels is challenging since the timing of data being sent must be very precise. Python alone is not fast enough to send bits out of a serial port. So a small function that uses assembly code is used. This code can be called directly from a neopixel driver file so that the user's don't need to see this code.

                                                                                                                                                                                                                                                                                                              MicroPython Example Code on ESP8266

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#different-types-of-neopixels","title":"Different Types of NeoPixels","text":"

                                                                                                                                                                                                                                                                                                              There are many different types of NeoPixels. They come in many forms such as strips, rings and matrices.

                                                                                                                                                                                                                                                                                                              The most common type of NeoPixels are strips. The strips come in a variety of densities and waterproofing. The most common and easiest to use are the 60 pixels-per-meter type.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#circuit-connections","title":"Circuit connections","text":"LED Strip Pico Name Pico Pin Description GND GND 3 Ground 5v VBUS 40 Voltage from the USB bus. Top right with USB on top Data GP22 22 Row 12 on the right side

                                                                                                                                                                                                                                                                                                              Note that you can also power most of the LED strips using the 3.3 volts available on Grove connectors. The only difference is the brightness might not be quite as high, but for most applications this will not be a problem.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#setup-parameters","title":"Setup Parameters","text":"

                                                                                                                                                                                                                                                                                                              Our Python code will have four parts:

                                                                                                                                                                                                                                                                                                              1. Declaration of the imports from the RP2 MicroPython runtime. We also import the sleep function from the utime module and some samples will also need the random library. All our programs have been tested on version 1.18 of the MicroPython RP2 library or later.
                                                                                                                                                                                                                                                                                                              2. Initialization of the fixed static parameters. This is done once and the parameters are usually at the top of the file to make them easy to find and change for each application. Make sure you adjust the pin number and the number of pixels in your setup in this area.
                                                                                                                                                                                                                                                                                                              3. Initialization of the NeoPixel object using these static parameters. This is also done just once.
                                                                                                                                                                                                                                                                                                              4. Sending the drawing commands to the device through the data port. This is usually done within a main loop.
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#import-statements","title":"Import Statements","text":"

                                                                                                                                                                                                                                                                                                              Here are the import statements we use:

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\nfrom neopixel import NeoPixel\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#static-initialization-parameters","title":"Static Initialization Parameters","text":"

                                                                                                                                                                                                                                                                                                              There are only two values. The number of pixels in the LED strip or LED ring and the pin number the data pin is connected to.

                                                                                                                                                                                                                                                                                                              NUMBER_PIXELS = 8\nLED_PIN = 22\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#initialize-the-strip-object","title":"Initialize the Strip Object","text":"

                                                                                                                                                                                                                                                                                                              To setup the NeoPixel object we just pass it the two parameters like this:

                                                                                                                                                                                                                                                                                                              strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n

                                                                                                                                                                                                                                                                                                              Here is the full initialization code:

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\nfrom neopixel import NeoPixel\n\nNUMBER_PIXELS = 8\nLED_PIN = 22\nstrip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#sample-programs","title":"Sample Programs","text":"

                                                                                                                                                                                                                                                                                                              Now we are ready to write our first small test program!

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#move-red-pixel-across-strip","title":"Move Red Pixel Across Strip","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nfrom neopixel import NeoPixel\n\nNUMBER_PIXELS = 60\nLED_PIN = 0\n\nstrip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n\nwhile True:\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] = (255,0,0) # red=255, green and blue are 0\n        strip.write() # send the data from RAM down the wire\n        sleep(.1) # keep on 1/10 of a second\n        strip[i] = (0,0,0) # change the RAM back but don't resend the data\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#fade-in-and-out","title":"Fade in and Out","text":"

                                                                                                                                                                                                                                                                                                              Make the first pixel fade the red color in and out. We do this by slowly turning up the color level of the red on strip[0].

                                                                                                                                                                                                                                                                                                              Off: strip[0] = (0,0,0)\nRed Very Dim: strip[0] = (1,0,0)\nDim Red: strip[0] = (10,0,0)\nRed Half Brightness: strip[0] = (128,0,0)\nRed Full Brightness: strip[0] = (255,0,0)\n

                                                                                                                                                                                                                                                                                                              We start a 0 and go up to 255. Then we go back from 255 back down to zero. We delay about 5 milliseconds between each of the 255 brightness levels.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nfrom neopixel import NeoPixel\n\n\nNUMBER_PIXELS = 60\nLED_PIN = 0\n\nstrip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n\ndelay = .005\n\nwhile True:\n    for i in range(0, 255):\n        strip[0] = (i,0,0) # red=255, green and blue are 0\n        strip.write() # send the data from RAM down the wire\n        sleep(delay)\n    for i in range(255, 0, -1):\n        strip[0] = (i,0,0)\n        strip.write()\n        sleep(delay)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#heartbeat-lab","title":"Heartbeat Lab","text":"

                                                                                                                                                                                                                                                                                                              What if you were building a robot and you wanted to flash the LED to look like a human heartbeat? Instead of slowing fading in and out, you would want the brightness to follow the electrical signals coming from the heart. This is called an electro cardiogram (EKG) and it look like this:

                                                                                                                                                                                                                                                                                                              Notice that the signal is low for about one second and then it spikes up to maximum brightness and then comes back down. When we are moving the brightness up and down, we don't have to pause between each of the 256 brightness values. The eye can't usually see the intermediate brightness values if the brightness is changing quickly. To make our code efficient we can skip over 9 out of 10 of the brightness gradations between 0 and 255. We call this the skip_interval in our code below.

                                                                                                                                                                                                                                                                                                              The following code emulates this heart beat pattern:

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nfrom neopixel import NeoPixel\n\n# Most people have a heart rate of around 60-70 beats per minute\n# If we add a once second delay between \"beats\" you can make and LED\n# look like a beating heart.\n\nNUMBER_PIXELS = 1\nLED_PIN = 0\n\nstrip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n\nramp_delay = .001\nbeat_delay = 1\nskip_interval = 10\n\nwhile True:\n    # ramp brightness up using the ramp_delay\n    for i in range(0, 255, skip_interval):\n        strip[0] = (i,0,0)\n        strip.write()\n        sleep(ramp_delay)\n    # ramp brightness down using the same delay\n    for i in range(255, 0, -skip_interval):\n        strip[0] = (i,0,0)\n        strip.write()\n        sleep(ramp_delay)\n    strip[0] = (0,0,0)\n    strip.write()\n    sleep(beat_delay)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#move-red-green-and-blue","title":"Move Red, Green and Blue","text":"

                                                                                                                                                                                                                                                                                                              The following program will just take the block of code in the for loop above and duplicate it three times, one for red, one for blue and one for green.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom neopixel import NeoPixel\nfrom time import sleep\n\nNUMBER_PIXELS = 8\nLED_PIN = 0\n\nstrip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS)\n\n# we use the same brightness for each color\nbrightness = 25\ndelay = .1\n# here we define variables for each color\nred = (brightness, 0, 0)\ngreen = (0, brightness, 0)\nblue = (0, 0, brightness)\nwhile True:\n    # draw red up the strip\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] = red\n        strip.write()\n        sleep(delay)\n        strip[i] = (0,0,0)\n    # draw blue up the strip\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] =  green\n        strip.write()\n        sleep(delay)\n        strip[i] = (0,0,0)\n    # draw green up the strip\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] =  blue\n        strip.write()\n        sleep(delay)\n        strip[i] = (0,0,0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#rainbow-cycle","title":"Rainbow Cycle","text":"

                                                                                                                                                                                                                                                                                                              The program cycles each pixel through all the colors in a rainbow. It uses two functions:

                                                                                                                                                                                                                                                                                                              1. wheel(pos) this function takes a position parameter from 0 to 255 and returns a triple of numbers for the red, green and blue values as the position moves around the color wheel. This is a handy program anytime you want to cycle through all the colors of the rainbow!
                                                                                                                                                                                                                                                                                                              2. rainbow_cycle(wait) will cycle each of the pixels in a strip through the color wheel. It gives the appearance that colors are moving across the strip. The wait is the delay time between updating the colors. A typical value for wait is .05 seconds or 50 milliseconds.
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom neopixel import NeoPixel\nfrom utime import sleep\n\nNEOPIXEL_PIN = 22\nNUMBER_PIXELS = 8\nstrip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\ndef wheel(pos):\n    # Input a value 0 to 255 to get a color value.\n    # The colors are a transition r - g - b - back to r.\n    if pos < 0 or pos > 255:\n        return (0, 0, 0)\n    if pos < 85:\n        return (255 - pos * 3, pos * 3, 0)\n    if pos < 170:\n        pos -= 85\n        return (0, 255 - pos * 3, pos * 3)\n    pos -= 170\n    return (pos * 3, 0, 255 - pos * 3)\n\ndef rainbow_cycle(wait):\n    global NUMBER_PIXELS, strip\n    for j in range(255):\n        for i in range(NUMBER_PIXELS):\n            rc_index = (i * 256 // NUMBER_PIXELS) + j\n            # print(rc_index)\n            strip[i] = wheel(rc_index & 255)\n        strip.write()\n    sleep(wait)\n\ncounter = 0\noffset = 0\nwhile True:\n    print('Running cycle', counter)\n    rainbow_cycle(.05)\n    counter += 1\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/05-neopixel/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • MicroPython RP2 Reference for NeoPixel Driver
                                                                                                                                                                                                                                                                                                              • Core Electronics: How to use WS2812B RGB LEDs with Raspberry Pi Pico - HTML page, sample code and video
                                                                                                                                                                                                                                                                                                              • MicroPython Library for NeoPixel (used before version 1.18 of the MicroPython RP2 Runtime) - note the lack of support for the RP2040 microcontroller.
                                                                                                                                                                                                                                                                                                              • rp2 port no module named array
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/","title":"MicroPython Pico W Wireless Examples","text":"

                                                                                                                                                                                                                                                                                                              One June 30th, 2022 the Raspberry Pi Foundation announced the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth.

                                                                                                                                                                                                                                                                                                              The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the lwip TCP/IP stack. This stack is accessible using the MicroPython network functions.

                                                                                                                                                                                                                                                                                                              The WiFi chip used is the Infineon CYW43439 chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication.

                                                                                                                                                                                                                                                                                                              You can read more about the capabilities of the WiFi/Bluetooth chip by reading the Infineon CYW43439 Datasheet. I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains!

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#compatibility-with-prior-code","title":"Compatibility with Prior Code","text":"

                                                                                                                                                                                                                                                                                                              The Pico W code is very similar to prior versions of the Pico with a few small exceptions. One of these is the fact that we must now use a symbolic label called an alias such as Pin(\"LED\") instead of Pin(25) to access the LED pin, not a hardwired PIN number. This allows us to keep our code more portable as the underlying hardware changes.

                                                                                                                                                                                                                                                                                                              from machine import Pin, Timer\n\n# was Pin(25)\nled = Pin(\"LED\", Pin.OUT)\ntim = Timer()\ndef tick(timer):\n    global led\n    led.toggle()\n\ntim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)\n

                                                                                                                                                                                                                                                                                                              See the new Sample Blink code on the Raspberry Pi Examples site.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#getting-the-new-pico-w-image","title":"Getting the New Pico W Image","text":"

                                                                                                                                                                                                                                                                                                              I had to download a brand new image for the Pico W runtime from the Raspberry Pi Foundation Software Site

                                                                                                                                                                                                                                                                                                              After I downloaded the new image and ran a Stop/Reset on Thonny I got the following prompt:

                                                                                                                                                                                                                                                                                                              MicroPython v1.19.1-88-g74e33e714 on 2022-06-30; Raspberry Pi Pico W with RP2040\nType \"help()\" for more information.\n>>> \n

                                                                                                                                                                                                                                                                                                              Note that the \"Pico W\" is listed in the prompt. If you do not see the \"W\" then the network code will not work.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#beginner-wifi-programs","title":"Beginner WiFi Programs","text":"

                                                                                                                                                                                                                                                                                                              We will store the name of our local WiFi network we wish to connect to and the password for that name in a file called secrets.py. This is called you WiFi \"access point\" and the variable name to store the name is called the `SSID. We will need to make sure we never save this file into a public GitHub repo by adding this file to our .gitignore file.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#setting-up-your-wifi-secretspy","title":"Setting Up Your WIFI secrets.py","text":"

                                                                                                                                                                                                                                                                                                              By convention, we put both our SSID and password in a python file called \"secrets.py\". This file should never be checked into a public source code repository. We can add secrets.py to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone.

                                                                                                                                                                                                                                                                                                              SSID = \"MY_WIFI_NETWORK_NAME\"\nPASSWORD = \"MY_WIFI_PASSWORD\"\n

                                                                                                                                                                                                                                                                                                              By importing the secrets.py file you can then reference your network name like this:

                                                                                                                                                                                                                                                                                                              print('Connecting to WiFi Network Name:', secrets.SSID)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#testing-your-wifi-access-point-connection","title":"Testing Your WiFi Access Point Connection","text":"

                                                                                                                                                                                                                                                                                                              Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable.

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True) # power up the WiFi chip\nprint('Waiting for wifi chip to power up...')\nsleep(3) # wait three seconds for the chip to power up and initialize\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nprint('Waiting for access point to log us in.')\nsleep(2)\nif wlan.isconnected():\n  print('Success! We have connected to your access point!')\n  print('Try to ping the device at', wlan.ifconfig()[0])\nelse:\n  print('Failure! We have not connected to your access point!  Check your secrets.py file for errors.')\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME\nWaiting for wifi chip to power up...\nWaiting for access point to log us in...\nSuccess! We have connected to your access point!\nTry to ping the device at 10.0.0.70\n

                                                                                                                                                                                                                                                                                                              If the result is a Failure you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing.

                                                                                                                                                                                                                                                                                                              Note that we are using the sleep() function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#waiting-for-a-valid-access-point-connection","title":"Waiting for a Valid Access Point Connection","text":"

                                                                                                                                                                                                                                                                                                              Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected.

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nstart = ticks_ms() # start a millisecond counter\n\nif not wlan.isconnected():\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    while not wlan.isconnected():\n        sleep(1)\n        print(counter, '.', sep='', end='', )\n        counter += 1\n\ndelta = ticks_diff(ticks_ms(), start)\nprint(\"Connect Time:\", delta, 'milliseconds')\nprint('IP Address:', wlan.ifconfig()[0])\n

                                                                                                                                                                                                                                                                                                              This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds.

                                                                                                                                                                                                                                                                                                              First run upon power on might take several seconds:

                                                                                                                                                                                                                                                                                                              >>> %Run -c $EDITOR_CONTENT\nConnecting to WiFi Network Name: MY_NETWORK_NAME\nWaiting for connection...\n0.1.2.3.Connect Time: 4640\nIP Address: 10.0.0.70\n

                                                                                                                                                                                                                                                                                                              The second and consecutive runs will use a cached connection.

                                                                                                                                                                                                                                                                                                              >>> %Run -c $EDITOR_CONTENT\nConnecting to WiFi Network Name: MY_NETWORK_NAME\nConnect Time: 0 milliseconds\nIP Address: 10.0.0.70\n>>>\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#error-handling","title":"Error Handling","text":"
                                                                                                                                                                                                                                                                                                              lan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(ssid, password)\n\n# Wait for connect or fail\nmax_wait = 10\nwhile max_wait > 0:\n  if wlan.status() < 0 or wlan.status() >= 3:\n    break\n  max_wait -= 1\n  print('waiting for connection...')\n  time.sleep(1)\n\n# Handle connection error\nif wlan.status() != 3:\n   raise RuntimeError('network connection failed')\nelse:\n  print('connected')\n  status = wlan.ifconfig()\n  print( 'ip = ' + status[0] )\n

                                                                                                                                                                                                                                                                                                              The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#testing-http-get","title":"Testing HTTP GET","text":"

                                                                                                                                                                                                                                                                                                              The following example was taken from Tom's Hardware

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\nimport urequests\n\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\n\nstart = ticks_ms() # start a millisecond counter\n\nastronauts = urequests.get(\"http://api.open-notify.org/astros.json\").json()\n\ndelta = ticks_diff(ticks_ms(), start)\n\nnumber = astronauts['number']\nprint('There are', number, 'astronauts in space.')\nfor i in range(number):\n    print(i+1, astronauts['people'][i]['name'])\n\nprint(\"HTTP GET Time in milliseconds:\", delta)\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              There are 10 astronauts in space.\n1 Oleg Artemyev\n2 Denis Matveev\n3 Sergey Korsakov\n4 Kjell Lindgren\n5 Bob Hines\n6 Samantha Cristoforetti\n7 Jessica Watkins\n8 Cai Xuzhe\n9 Chen Dong\n10 Liu Yang\nHTTP GET Time in milliseconds: 786\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#listing-the-functions-in-your-network-library","title":"Listing the Functions in Your Network Library","text":"

                                                                                                                                                                                                                                                                                                              The network library provided by the Raspberry Pi Foundation for the Pico W is new an may change as new functions are added. To get the list of functions in your network library you can use the Python help(network) at the prompt or use the dir() function.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#network-help","title":"Network Help","text":"

                                                                                                                                                                                                                                                                                                              You can also get a list of the network functions by typing help(network) at the Python REPL prompt.

                                                                                                                                                                                                                                                                                                              help(network)\nobject <module 'network'> is of type module\n  __name__ -- network\n  route -- <function>\n  WLAN -- <class 'CYW43'>\n  STAT_IDLE -- 0\n  STAT_CONNECTING -- 1\n  STAT_WRONG_PASSWORD -- -3\n  STAT_NO_AP_FOUND -- -2\n  STAT_CONNECT_FAIL -- -1\n  STAT_GOT_IP -- 3\n  STA_IF -- 0\n  AP_IF -- 1\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#network-dir-function","title":"Network dir() Function","text":"
                                                                                                                                                                                                                                                                                                              import network\nfunction_list = dir(network)\n\nfor function in function_list:\n    print(function)\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              __class__\n__name__\nAP_IF\nSTAT_CONNECTING\nSTAT_CONNECT_FAIL\nSTAT_GOT_IP\nSTAT_IDLE\nSTAT_NO_AP_FOUND\nSTAT_WRONG_PASSWORD\nSTA_IF\nWLAN\nroute\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#urequest","title":"Urequest","text":"

                                                                                                                                                                                                                                                                                                              It is easy to communicate with non-SSL protected HTTP protocols sites using the WLAN `urequest function. It supports the standard GET, POST, PUT and DELETE functions.

                                                                                                                                                                                                                                                                                                              help(urequests)\nobject <module 'urequests' from 'urequests.py'> is of type module\n  head -- <function head at 0x2000b740>\n  post -- <function post at 0x2000ba80>\n  delete -- <function delete at 0x2000bbb0>\n  get -- <function get at 0x2000b750>\n  __file__ -- urequests.py\n  Response -- <class 'Response'>\n  patch -- <function patch at 0x2000baf0>\n  put -- <function put at 0x2000ba90>\n  usocket -- <module 'lwip'>\n  __name__ -- urequests\n  request -- <function request at 0x2000bb80>\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#getting-the-macethernet-access","title":"Getting the MAC/Ethernet Access","text":"

                                                                                                                                                                                                                                                                                                              You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function.

                                                                                                                                                                                                                                                                                                              import network\nfrom utime import sleep, ticks_us, ticks_diff\n\nprint('Getting MAC/Ethernet Address for this device.')\n\nstart = ticks_us() # start a millisecond counter\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True) # this line powers up the chip - it takes about 2.5 seconds\n\n# This returns a byte array of hex numbers\nmac_addess = wlan.config('mac')\nprint('Time in microseconds:', ticks_diff(ticks_us(), start))\n# each MAC address is 6 bytes or 48 bits\nprint(\"Hex byte array:\", mac_addess, 'length:', len(mac_addess))\n\n# This should be in hex per the Notational Conventions\n# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions\n# b'(\\xcd\\xc1\\x015X'\n# 28:cd:c1:1:35:58\n# format in MAC Notational Convention\nfor digit in range(0,5):\n    print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '')\nprint(str(hex(mac_addess[5]))[2:4] )\n

                                                                                                                                                                                                                                                                                                              First Time After Power On Results:

                                                                                                                                                                                                                                                                                                              Getting MAC/Ethernet Address for this device.\nTime in microseconds: 2584424\nHex byte array: b'(\\xcd\\xc1\\x015X' length: 6\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address.

                                                                                                                                                                                                                                                                                                              Subsequent Times

                                                                                                                                                                                                                                                                                                              Getting MAC/Ethernet Address for this device.\nTime in microseconds: 211\nHex byte array: b'(\\xcd\\xc1\\x015X' length: 6\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              We must add the wlan.active(True) line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros.

                                                                                                                                                                                                                                                                                                              The MAC address is six bytes or \"octets\". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the Wikipedia Page on MAC Address for more information. If you run this on your Pico W the first octets should be similar.

                                                                                                                                                                                                                                                                                                              Here are the two MAC addresses for two different Pico W devices:

                                                                                                                                                                                                                                                                                                              28:cd:c1:1:35:54\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Because they were purchased together, their MAC address are very similar.

                                                                                                                                                                                                                                                                                                              I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#advanced-wifi-programs","title":"Advanced WiFi Programs","text":"

                                                                                                                                                                                                                                                                                                              Once we have mastered the basics of connecting to a local access point and returning our IP address, we are no ready to build some sample Internet of Things applications.

                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#using-the-pico-w-as-a-web-server","title":"Using the Pico W as a Web Server","text":"

                                                                                                                                                                                                                                                                                                              This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off.

                                                                                                                                                                                                                                                                                                              Screen image of Pico W Web Server:

                                                                                                                                                                                                                                                                                                              # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/\nimport network\nimport socket\nimport time\nimport secrets\n\nfrom machine import Pin\n\n# Select the onboard LED\nled = machine.Pin(\"LED\", machine.Pin.OUT)\n\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nstateis = \"LED is OFF\"\n\nhtml = \"\"\"<!DOCTYPE html>\n<html>\n   <head>\n     <title>Web Server On Pico W </title>\n   </head>\n  <body>\n      <h1>Pico Wireless Web Server</h1>\n      <p>%s</p>\n      <a href=\"/light/on\">Turn On</a>\n      <a href=\"/light/off\">Turn Off</a>\n  </body>\n</html>\n\"\"\"\n\n# Wait for connect or fail\nmax_wait = 10\nwhile max_wait > 0:\n  if wlan.status() < 0 or wlan.status() >= 3:\n    break\n  max_wait -= 1\n  print('waiting for connection...')\n  time.sleep(1)\n\n# Handle connection error\nif wlan.status() != 3:\n  raise RuntimeError('network connection failed')\nelse:\n  print('We are connected to WiFI access point:', secrets.SSID)\n  status = wlan.ifconfig()\n  print( 'The IP address of the pico W is:', status[0] )\n\n# Open socket\naddr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]\nprint('addr:', addr)\ns = socket.socket()\n#if not addr:\ns.bind(addr)\ns.listen(1)\n\nprint('listening on', addr)\n\n# Listen for connections\nwhile True:\n  try:\n    cl, addr = s.accept()\n    print('client connected from', addr)\n    request = cl.recv(1024)\n    print(request)\n    request = str(request)\n    led_on = request.find('/light/on')\n    led_off = request.find('/light/off')\n    print( 'led on = ' + str(led_on))\n    print( 'led off = ' + str(led_off))\n\n    if led_on == 6:\n      print(\"led on\")\n      led.value(1)\n      stateis = \"LED is ON\"\n\n    if led_off == 6:\n      print(\"led off\")\n      led.value(0)\n      stateis = \"LED is OFF\"\n    # generate the we page with the stateis as a parameter\n    response = html % stateis\n    cl.send('HTTP/1.0 200 OK\\r\\nContent-type: text/html\\r\\n\\r\\n')\n    cl.send(response)\n    cl.close()\n\n  except OSError as e:\n    cl.close()\n    print('connection closed')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#shttp-support","title":"SHTTP Support","text":"

                                                                                                                                                                                                                                                                                                              Warning

                                                                                                                                                                                                                                                                                                              This code is not working. I believe we need to get a SSL certificate for SSL to work. To do this I think we need to use a command line tool to generate a certificate for the device and store it in RAM.

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nimport time\nimport urequests\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nprint(wlan.isconnected())\nmy_ip = urequests.get(\"https://api.myip.com/\").json()\nprint(im_pi)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"basics/06-wireless/#sending-notifications","title":"Sending Notifications","text":"

                                                                                                                                                                                                                                                                                                              We can connect to a remote server to send text and e-mail notifications if specific events occur on our devices. To do this you must have credentials on some system that response to messages such as IFTTT or an MQTT server.

                                                                                                                                                                                                                                                                                                              TBD

                                                                                                                                                                                                                                                                                                              "},{"location":"concept-cards/01-intro/","title":"MicroPython Concept Cards","text":"

                                                                                                                                                                                                                                                                                                              This is a list of concept cards that are related to MicroPython. Our goal is to print these concept cards on 1/2 sheet laminated paper and have them available at the center of the tables in our CoderDojo Classrooms.

                                                                                                                                                                                                                                                                                                              Please let me know if you are willing to volunteer.

                                                                                                                                                                                                                                                                                                              Each concept card will have the content stored in a MarkDown file. A Python script will convert the MarkDown into HTML with a CSS file that paginates the output.

                                                                                                                                                                                                                                                                                                              Concept Cards

                                                                                                                                                                                                                                                                                                              "},{"location":"concept-cards/01-intro/#beginning-concepts","title":"Beginning concepts","text":""},{"location":"concept-cards/01-intro/#physical-computing","title":"Physical Computing","text":""},{"location":"concept-cards/01-intro/#sensors","title":"Sensors","text":""},{"location":"concept-cards/01-intro/#switches-and-buttons","title":"Switches and Buttons","text":""},{"location":"concept-cards/01-intro/#sensing-light","title":"Sensing Light","text":""},{"location":"concept-cards/01-intro/#sensing-distance","title":"[Sensing Distance]","text":""},{"location":"concept-cards/01-intro/#ping-distance-sensors","title":"Ping Distance Sensors","text":""},{"location":"concept-cards/01-intro/#time-of-flight-distance-sensors","title":"Time of Flight Distance Sensors","text":""},{"location":"concept-cards/01-intro/#motors","title":"Motors","text":""},{"location":"concept-cards/01-intro/#dc-motors","title":"DC Motors","text":""},{"location":"concept-cards/01-intro/#servos","title":"Servos","text":""},{"location":"concept-cards/01-intro/#stepper-motors","title":"Stepper Motors","text":""},{"location":"concept-cards/01-intro/#batteries-and-power","title":"Batteries and Power","text":""},{"location":"concept-cards/01-intro/#aa-batteries","title":"AA Batteries","text":""},{"location":"concept-cards/01-intro/#lipo-batteries","title":"LiPo Batteries","text":""},{"location":"concept-cards/01-intro/#intermediate-concepts","title":"Intermediate Concepts","text":""},{"location":"concept-cards/01-intro/#interrupts","title":"Interrupts","text":""},{"location":"concept-cards/01-intro/#advanced-concepts","title":"Advanced Concepts","text":""},{"location":"concept-cards/01-intro/#multicore-programming","title":"MultiCore Programming","text":""},{"location":"concept-cards/01-intro/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              https://www.sitepoint.com/css-printer-friendly-pages/

                                                                                                                                                                                                                                                                                                              https://www.jotform.com/blog/css-perfect-print-stylesheet-98272/

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/28-debugging-python/","title":"How to Debug Micropython","text":""},{"location":"debugging/28-debugging-python/#listing-the-modules","title":"Listing the Modules","text":"
                                                                                                                                                                                                                                                                                                              help('modules')\n

                                                                                                                                                                                                                                                                                                              Result:

                                                                                                                                                                                                                                                                                                              __main__          gc                uasyncio/funcs    uos\n_boot             machine           uasyncio/lock     urandom\n_onewire          math              uasyncio/stream   ure\n_rp2              micropython       ubinascii         uselect\n_thread           onewire           ucollections      ustruct\n_uasyncio         rp2               uctypes           usys\nbuiltins          uasyncio/__init__ uhashlib          utime\nds18x20           uasyncio/core     uio               uzlib\nframebuf          uasyncio/event    ujson\nPlus any modules on the filesystem\n
                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/28-debugging-python/#micropython-issues","title":"Micropython issues","text":"

                                                                                                                                                                                                                                                                                                              https://github.com/micropython/micropython/issues

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/","title":"Debugging SPI","text":"

                                                                                                                                                                                                                                                                                                              In this lab we use a logic analyzer to debug the SPI protocol being used to drive a sample OLED device. We will be using the the 8 port Saleae Logic Analyser. The retail cost is about $399.00 although there are lower cost logic analyzer available.

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#the-ssd1306-spi-oled-timing-diagram","title":"The SSD1306 SPI OLED Timing Diagram","text":"

                                                                                                                                                                                                                                                                                                              The OLED display is a read-only interface. It does not send any data back to the microcontroller, so there is no MOSI connection. The data is transmitted on the SDK line when the SCL line goes high. The CS line must be low for the OLED to be active.

                                                                                                                                                                                                                                                                                                              For details, see section 8.1.3 MCU Serial Interface on page 21 of the SSD1305 132 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller.

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#oled-spi-settings","title":"OLED SPI settings","text":"

                                                                                                                                                                                                                                                                                                              Our OLED device has seven wires. In addition to power and ground there a five data connections we will be observing on our logic analyzer.

                                                                                                                                                                                                                                                                                                              1. CS - Chip Select pin 4
                                                                                                                                                                                                                                                                                                              2. DC - Data/Command - pin 5
                                                                                                                                                                                                                                                                                                              3. RES - Reset - pin 6
                                                                                                                                                                                                                                                                                                              4. SDA - Data - SPIO TX GP7 pin 10 (Data from the )
                                                                                                                                                                                                                                                                                                              5. SCL - Clock - Connect to SPIO SCK GP6 pin 9
                                                                                                                                                                                                                                                                                                              6. VCC - Connect to the 3.3V Out pin 36
                                                                                                                                                                                                                                                                                                              7. GND - pin 38 or 3 any other GND pin
                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#setting-up-a-logic-analyzer","title":"Setting up a Logic Analyzer","text":""},{"location":"debugging/29-debugging-spi/#setup-spi-analyser","title":"Setup SPI Analyser","text":""},{"location":"debugging/29-debugging-spi/#configure-spi-channel-settings","title":"Configure SPI Channel Settings","text":"

                                                                                                                                                                                                                                                                                                              Saleae Logic Analyser SPI Logic Analyser Settings

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#check-a-working-device","title":"Check a Working Device","text":"

                                                                                                                                                                                                                                                                                                              The first thing we want to see is what the signals to a working SPI OLED should be. There are plenty of working drivers for the Arduino, so I hooked one up to the Logic analizer to see what they were.

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#viewing-data-clock-and-res","title":"Viewing Data Clock and RES","text":"

                                                                                                                                                                                                                                                                                                              All five signals

                                                                                                                                                                                                                                                                                                              DC and CS signals have a larger period.

                                                                                                                                                                                                                                                                                                              1. DC on was 3.668 milliseconds
                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#clock-period","title":"Clock Period","text":"

                                                                                                                                                                                                                                                                                                              Our Clock (SCL) has 8 positive pulses with a width of .4167 microseconds. This means that the positve/negative combined width has a period of 2 * .4167 = .8333 microseconds. This can be converted into a frequency of 1.2 megahertz.

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29-debugging-spi/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Video on how to use the Saleae Logic Analyzer

                                                                                                                                                                                                                                                                                                              https://www.youtube.com/watch?v=Ak9R4yxQPhs

                                                                                                                                                                                                                                                                                                              "},{"location":"debugging/29a-debugging-i2c/","title":"Debugging I2C Bus","text":""},{"location":"displays/graph/01-intro/","title":"Introduction to OLED Displays","text":"

                                                                                                                                                                                                                                                                                                              Four colors of 2.44\" OLED displays from DIY More. We can purchase them on EBay for around $18 each.

                                                                                                                                                                                                                                                                                                              We use small OLED displays in many of our labs because:

                                                                                                                                                                                                                                                                                                              1. They are inexpensive (around $4).
                                                                                                                                                                                                                                                                                                              2. They are easy to connect** via I2C and SPI. Just four wires for I2C and seven wires for SPI.
                                                                                                                                                                                                                                                                                                              3. They have a large area to display feedback. Most of them are 128X64 pixels.
                                                                                                                                                                                                                                                                                                              4. Once you get the drivers installed (not always easy) they are easy to program. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions.
                                                                                                                                                                                                                                                                                                              5. OLEDs, unlike LCDs, have high contrast over a large range of input voltages. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast.
                                                                                                                                                                                                                                                                                                              6. There is plenty of sample code and tutorials available.
                                                                                                                                                                                                                                                                                                              7. You can program them with Python (our student's favorite language)
                                                                                                                                                                                                                                                                                                              8. They are crazy fun!

                                                                                                                                                                                                                                                                                                              The first step is to find out what type of display graphics chip is used in your OLED.

                                                                                                                                                                                                                                                                                                              In these lessons we will assume you have a 128X64 or similar OLED display. Many of these displays can be purchased for around $4 on eBay. Many of these displays use the popular SSD1306 chip to drive the displays. There are also to communication options:

                                                                                                                                                                                                                                                                                                              1. I2C - simple 2 wire connection (not including power and ground)
                                                                                                                                                                                                                                                                                                              2. SPI - five wires but also faster screen refresh rates

                                                                                                                                                                                                                                                                                                              Updating a 128X64 display using I2C takes around 37ms. When using the SPI interface, updating the display can be reduced to around 2.79ms.

                                                                                                                                                                                                                                                                                                              These labs will assume these parameters, but you can modify the labs to use different sizes and display driver chips by only modifying a few lines of code.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/01-intro/#i2c-scanner","title":"I2C Scanner","text":"

                                                                                                                                                                                                                                                                                                              Because your microcontroller might have multiple displays on it, their must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function.

                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(0) # row one on our standard Pico breadboard\nscl=machine.Pin(1) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              If you don't see a return value of \"60\" or similar, then you need to check your wiring and make sure that you have an I2C (not an SPI) device.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/01-intro/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Wokwi web-based simulator of OLED display
                                                                                                                                                                                                                                                                                                              • Mike Causer's Awesome MicroPython Display Drivers
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/","title":"OLED Setup","text":"

                                                                                                                                                                                                                                                                                                              At the beginning of of your Python programs there is usually a few lines of setup instruction to tell the system which libraries to use, what pins to assign and what devices to initialize.

                                                                                                                                                                                                                                                                                                              We will first look at the simple I2C setup. Then we will look at the SPI setup.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/#i2c-scanner","title":"I2C Scanner","text":"

                                                                                                                                                                                                                                                                                                              Because your microcontroller might have multiple I2C devices and displays on it, there must be some way to address the devices using an address. Most of the devices come with a default address of decimal value 60 (hex value X3C). To test this the i3c module has a i2c scan function.

                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              returns: [60]

                                                                                                                                                                                                                                                                                                              returns: [60]

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/#ssd1306-examples","title":"SSD1306 Examples","text":""},{"location":"displays/graph/02-oled-setup/#ssd1306-i2c-setup","title":"SSD1306 I2C Setup","text":"
                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\noled = SSD1306_I2C(128, 64, i2c)\noled.text('Hello World!', 0, 0, 1)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/#ssd1306-spi-setup","title":"SSD1306 SPI Setup","text":"

                                                                                                                                                                                                                                                                                                              Back connections:

                                                                                                                                                                                                                                                                                                              Front labels on OLED with SPI:

                                                                                                                                                                                                                                                                                                              Here is the connection diagram:

                                                                                                                                                                                                                                                                                                              Here is the code:

                                                                                                                                                                                                                                                                                                              import machine import ssd1306\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi=machine.SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx)\nCS = machine.Pin(1)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\noled.text('Hello World!', 0, 0, 1)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/#ssh1106-i2c-setup","title":"SSH1106 I2C Setup","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nimport sh1106\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c = I2C(0, scl=scl, sda=sda, freq=400000)\noled = SH1106_I2C(128, 64, i2c)\noled.text('Hello World!', 0, 0, 1)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/02-oled-setup/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Micropython SSD1306 Driver on GitHub

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/","title":"Basic Drawing","text":""},{"location":"displays/graph/03-basic-drawing/#basic-draw-functions","title":"Basic Draw Functions","text":"

                                                                                                                                                                                                                                                                                                              For our beginning labs we will just do some basic drawing. We will start out with just four functions:

                                                                                                                                                                                                                                                                                                              1. Initialize the display framebuffer memory with the right object class initialization
                                                                                                                                                                                                                                                                                                              2. Fill the framebuffer will zeros which are black pixels with the oled.fill(0)
                                                                                                                                                                                                                                                                                                              3. Draw white text in the framebuffer memory with the oled.text(\"Hello World!\", 40, 10)
                                                                                                                                                                                                                                                                                                              4. Send the entire framebuffer to the display over the bus with the oled.show() function.
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/#initializing-the-framebuffer","title":"Initializing the Framebuffer","text":"

                                                                                                                                                                                                                                                                                                              Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled \"oled\" using the following line:

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\noled = SSD1306_I2C(128, 64, i2c)\n
                                                                                                                                                                                                                                                                                                              Function Description Parameters oled.fill(0) Fill the display with white or black 0=black and 1=white oled.text(\"Hello\", Draw text String, x (horizontal from left edge) and y (vertical from the top)Example: Draw \"Hello World\" 40 over and 10 down. oled.text(\"Hello World!\", 40, 10) show Show the display Send the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.

                                                                                                                                                                                                                                                                                                              The full program would look like this:

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\noled = SSD1306_I2C(128, 64, i2c)\noled.fill(0)\noled.text(\"Hello World!\", 0, 0)\noled.show()\n

                                                                                                                                                                                                                                                                                                              This would display the following:

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/#full-list-of-drawing-functions","title":"Full list of Drawing Functions","text":"

                                                                                                                                                                                                                                                                                                              Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class.

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\nprint(dir(SSD1306_I2C))\n
                                                                                                                                                                                                                                                                                                              This returns the following list:

                                                                                                                                                                                                                                                                                                              ['__class__', '__init__', '__module__', '__name__', '__qualname__',\n'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline',\n'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline',\n'init_display', 'write_cmd', 'show', 'poweroff', 'poweron',\n'contrast', 'write_data']\n
                                                                                                                                                                                                                                                                                                              Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions.

                                                                                                                                                                                                                                                                                                              The following are relevant for the SSD1306_I2C display.

                                                                                                                                                                                                                                                                                                              The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state or color is 0=off (black) and 1=on (white).

                                                                                                                                                                                                                                                                                                              Function Description Example blit(fbuf, x, y, color) Bit Level Transfer blit(fbuf, 1, 1) fill(state) Fill Fill with black (0) or white(1) fill_rect Fill a rectangle hline(x, x, length, state) Draw a horizontal line Draw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1) invert() invert the display Filp the orientation of the display line(x1,y1,x2,y2) draw a line at any angle Horizontal oled.line(0,0, 127, 63, 1) pixel(x,y, color) Draw a single point on the screen rect(x, y, width, height) Draw an empty rectangle scroll(x,y) Scroll the display text(x,y,color) Write text at a point vline(x,y,length, color) Draw a Vertical Line oled.vline(width - 1, 0, height - 1, 1) # right edge init_display() Initialize the display write_cmd Write a command to the display show() Update the display from the frame buffer poweroff() poweron() contrast() write_data()"},{"location":"displays/graph/03-basic-drawing/#pixel-drawing-example","title":"Pixel Drawing Example","text":"
                                                                                                                                                                                                                                                                                                              ICON = [\n    [ 0, 0, 0, 0, 0, 0, 0, 0, 0],\n    [ 0, 1, 1, 0, 0, 0, 1, 1, 0],\n    [ 1, 1, 1, 1, 0, 1, 1, 1, 1],\n    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [ 0, 1, 1, 1, 1, 1, 1, 1, 0],\n    [ 0, 0, 1, 1, 1, 1, 1, 0, 0],\n    [ 0, 0, 0, 1, 1, 1, 0, 0, 0],\n    [ 0, 0, 0, 0, 1, 0, 0, 0, 0],\n]\n\ndisplay.fill(0) # Clear the display\nfor y, row in enumerate(ICON):\n    for x, c in enumerate(row):\n        display.pixel(x, y, c)    \n\ndisplay.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/#drawing-tutorial-and-primitives","title":"Drawing Tutorial and Primitives","text":"

                                                                                                                                                                                                                                                                                                              Taken from the MicroPython site: Using a SSD1306 OLED display - although the path name imply the ESP8266, these functions also run on the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              display.poweroff()     # power off the display, pixels persist in memory\ndisplay.poweron()      # power on the display, pixels redrawn\ndisplay.contrast(0)    # dim\ndisplay.contrast(255)  # bright\ndisplay.invert(1)      # display inverted\ndisplay.invert(0)      # display normal\ndisplay.rotate(True)   # rotate 180 degrees\ndisplay.rotate(False)  # rotate 0 degrees\ndisplay.show()         # write the contents of the FrameBuffer to display memory\n
                                                                                                                                                                                                                                                                                                              display.fill(0)                         # fill entire screen with colour=0\ndisplay.pixel(0, 10)                    # get pixel at x=0, y=10\ndisplay.pixel(0, 10, 1)                 # set pixel at x=0, y=10 to colour=1\ndisplay.hline(0, 8, 4, 1)               # draw horizontal line x=0, y=8, width=4, colour=1\ndisplay.vline(0, 8, 4, 1)               # draw vertical line x=0, y=8, height=4, colour=1\ndisplay.line(0, 0, 127, 63, 1)          # draw a line from 0,0 to 127,63\ndisplay.rect(10, 10, 107, 43, 1)        # draw a rectangle outline 10,10 to 107,43, colour=1\ndisplay.fill_rect(10, 10, 107, 43, 1)   # draw a solid rectangle 10,10 to 107,43, colour=1\ndisplay.text('Hello World', 0, 0, 1)    # draw some text at x=0, y=0, colour=1\ndisplay.scroll(20, 0)                   # scroll 20 pixels to the right\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/#working-with-the-framebuf","title":"Working with the framebuf","text":"

                                                                                                                                                                                                                                                                                                              A frame buffer is a region of RAM that holds an exact image of what is on the display. The data can be copied from the framebuffer memory with the blit() (BLock Transfer) operation that copies a rectangular area of one framebuffer to another framebuffer.

                                                                                                                                                                                                                                                                                                              Here is an example of the blit() function:

                                                                                                                                                                                                                                                                                                              oled.blit(my_frame_buf, 10, 10, 0)\n
                                                                                                                                                                                                                                                                                                              # draw another FrameBuffer on top of the current one at the given coordinates\nimport framebuf\nfbuf = framebuf.FrameBuffer(bytearray(8 * 8 * 1), 8, 8, framebuf.MONO_VLSB)\nfbuf.line(0, 0, 7, 7, 1)\ndisplay.blit(fbuf, 10, 10, 0)           # draw on top at x=10, y=10, key=0\ndisplay.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-basic-drawing/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • MicroPython Documentation on FrameBuffer
                                                                                                                                                                                                                                                                                                              • Drawing Primitive Shapes
                                                                                                                                                                                                                                                                                                              • Driving I2C OLED displays with MicroPython - by Martin Fitzpatrick
                                                                                                                                                                                                                                                                                                              • ST7735 Micropython Driver by Anthony Norman
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/","title":"Drawing Bitmaps with MicroPython","text":""},{"location":"displays/graph/03-bitmaps/#framebuffers","title":"Framebuffers","text":"

                                                                                                                                                                                                                                                                                                              A Framebuffer is the core data structure we use when drawing bitmaps.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#block-image-transfers-blit","title":"Block Image Transfers (blit)","text":"

                                                                                                                                                                                                                                                                                                              The basic function we use to draw a rectangular region of the screen is called the blit() function:

                                                                                                                                                                                                                                                                                                              display.blit(frame_buffer, x, y)\n

                                                                                                                                                                                                                                                                                                              This function moves all the data within any frame buffer to the given (x,y) position of the display. The function will check the dimensions of the frame buffer to know how much data to move to the display. You just need to tell the function where to start drawing.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#blit-functions-are-efficient","title":"Blit Functions Are Efficient","text":"

                                                                                                                                                                                                                                                                                                              Blit operations can be much more efficient then the display.show() function when you are just updating a small region of the screen. This is because the display.show() function transfers the entire screen image each time it is called. Using blit functions can be written to only update the area of the screen that changes.

                                                                                                                                                                                                                                                                                                              For example, if you are writing a video game that has a ball moving across the screen, you only need to update the pixels around the ball, not the entire screen image. The exact performance difference between show() and blit() operations will depend on the size of the screen, the size of the blit update and the speed of the transfer of data from the framebuffer to the display device.

                                                                                                                                                                                                                                                                                                              The key disadvantage of using blit() functions is that you must consider what other artifacts there are on the screen that you might overwrite. Keeping track of the differences requires more computation by the microcontroller. The more powerful your microcontroller is relative to the communication speed, the more difference computations you can do.

                                                                                                                                                                                                                                                                                                              Not all display drivers will let you write directly from the microcontroller resident image directly to a region of the display. Sometimes you must follow your blit() operations with a show() to transfer the entire framebuffer to the display.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#working-with-bytearrays","title":"Working with ByteArrays","text":"

                                                                                                                                                                                                                                                                                                              MicroPython blit operations use a data representation format for images called a ByteArray. These are sequences of the bytes that will be sent in a blit operation. They are coded using the following notation:

                                                                                                                                                                                                                                                                                                              my_bytearray = (b\"\\xFF\\xFF\\xFF\\xBF\\xDF\\xEF\\xF7\\xFF\\xFB\\xFF\\xFD\")\n

                                                                                                                                                                                                                                                                                                              Note that the letter b begins the parameter to show the Python interpreter that the all the characters between the double quotes are byte array values. The characters \\x indicate that there are hexadecimals useds to encode the bit values.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#creating-a-solid-block-of-pixels","title":"Creating a Solid Block of Pixels","text":"

                                                                                                                                                                                                                                                                                                              Sometimes you want to update an entire region of the screen with a block of pixels that are all on or off. You can do this with the following steps

                                                                                                                                                                                                                                                                                                              # create a 10x10 matrix of on pixels\n# allocate an array of 20 bytes = \non_buffer = bytearray(20)\n# put all 1's in that buffer\non_buffer[:] = b'\\xff' * 20\n# create a frame buffer using monochrome \non_square = framebuf.FrameBuffer(on_buffer, 10, 10, framebuf.MONO_HLSB)\n\noled.blit(logo, i, 0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#image-encoding-options","title":"Image Encoding Options","text":"

                                                                                                                                                                                                                                                                                                              There are several alternate methods to encode the bits of an image into a byte array. The bits can be coded left to right or top to bottom. You can also put the bits in most-significant bit first or least-significant bit first. All these options and controlled when you interface with a framebuffer.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#vertical-least-significant-bit-layout","title":"Vertical Least Significant Bit Layout","text":"

                                                                                                                                                                                                                                                                                                              framebuf.MONO_VLSB Monochrome (1-bit) color format This defines a mapping where the bits in a byte are vertically mapped with bit 0 being nearest the top of the screen. Consequently each byte occupies 8 vertical pixels. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached. Further bytes are rendered at locations starting at the leftmost edge, 8 pixels lower.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#horizontal","title":"Horizontal","text":"

                                                                                                                                                                                                                                                                                                              MONO_HLSB. Monochrome (1-bit) color format This defines a mapping where the bits in a byte are horizontally mapped. Each byte occupies 8 horizontal pixels with bit 7 being the leftmost. Subsequent bytes appear at successive horizontal locations until the rightmost edge is reached.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/03-bitmaps/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              MicroPython Bitmap Tool Video - this video created by Lucky Resistor is a good overview of the image formats used by MicroPython.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/04-extended-drawing-functions/","title":"Extending Drawing Functions","text":"

                                                                                                                                                                                                                                                                                                              Although there are several drawing functions available in most of the standard graphics libraries, most of them lack some basic shapes such as a circle. To draw circles on your display, you will need to add new Python functions. Here are some examples of these custom drawing functions.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/04-extended-drawing-functions/#circle","title":"Circle","text":"

                                                                                                                                                                                                                                                                                                              Here is a function to draw a circle at a given (x,y) point with a radius of r and fill indicator.

                                                                                                                                                                                                                                                                                                              Here are the parameters for circle functions

                                                                                                                                                                                                                                                                                                              1. X position of the circle center
                                                                                                                                                                                                                                                                                                              2. Y position of the circle center
                                                                                                                                                                                                                                                                                                              3. The radius of the circle in pixels
                                                                                                                                                                                                                                                                                                              4. The color of the circle (1 for on and 0 for off.
                                                                                                                                                                                                                                                                                                              from math import sqrt\n\ndef draw_circle(cx, cy, r, color):\n    diameter = r*2\n    upper_left_x = cx - r\n    upper_left_y = cy - r \n    # scan through all pixels and only turn on pixels within r of the center\n    for i in range(upper_left_x, upper_left_x + diameter):\n        for j in range(upper_left_y, upper_left_y + diameter):\n            # distance of the current point (i, j) from the center (cx, cy)\n            d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 )\n            if d < r:\n                oled.pixel(i, j, color)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/04-extended-drawing-functions/#testing-circle-drawing","title":"Testing Circle Drawing","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\nfrom math import sqrt\nimport ssd1306\n\nWIDTH = 128\nHEIGHT = 64\nclock=Pin(2) # SCL\ndata=Pin(3) # SDA\nRES = machine.Pin(4)\nDC = machine.Pin(5)\nCS = machine.Pin(6)\n\nspi=machine.SPI(0, sck=clock, mosi=data)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\ndef circle(cx, cy, r, color):\n    diameter = r*2\n    upper_left_x = cx - r\n    upper_left_y = cy - r \n    # scan through all pixels and only turn on pixels within r of the center\n    for i in range(upper_left_x, upper_left_x + diameter):\n        for j in range(upper_left_y, upper_left_y + diameter):\n            # distance of the current point (i, j) from the center (cx, cy)\n            d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 )\n            if d < r:\n                oled.pixel(i, j, color)\n\nHALF_WIDTH = int(WIDTH/2)\nHALF_HEIGHT = int(HEIGHT/2)\nwhile True:\n    for rad in range(1,HALF_HEIGHT+2):\n        draw_circle(HALF_WIDTH, HALF_HEIGHT, rad, 1)\n        oled.show()\n        sleep(.1)\n    sleep(3)\n    oled.fill(1)\n    for rad in range(1,HALF_HEIGHT+2):\n        circle(HALF_WIDTH, HALF_HEIGHT, rad, 0)\n        oled.show()\n        sleep(.1)\n    oled.fill(0)\n    sleep(3)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/04-extended-drawing-functions/#drawing-a-face","title":"Drawing a Face","text":"

                                                                                                                                                                                                                                                                                                              If we assume we have a 64x128 display we can call two circle functions to draw eyes

                                                                                                                                                                                                                                                                                                              display.fill(0) # Clear the display. display.circle(32, 32, 10, 1) # draw the left eye

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/05-timing-draw-speed/","title":"Timing Drawing Speed","text":"

                                                                                                                                                                                                                                                                                                              If you are writing a video game and want fast drawing times for objects on the screen, there are several different algorithms you can try. You can use the MicroPython time_us function to record the time before and after you call a drawing function and return the difference to get an idea of the time saved in different versions of your drawing functions.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/05-timing-draw-speed/#sample-function-timer-code","title":"Sample Function Timer Code","text":""},{"location":"displays/graph/05-timing-draw-speed/#sample-function-code","title":"Sample Function Code","text":"
                                                                                                                                                                                                                                                                                                              from utime import ticks_us\n\nstart = ticks_us()\nmy_function()\nend = ticks_us()\nprint('Execution time in microseconds:', end - start)\n

                                                                                                                                                                                                                                                                                                              MicroPython also supports the ticks_cpu() function which could return a smaller granularity for precise time measurements. However, on the Raspberry Pi implementation, the results are exactly the same as the ticks_us() function.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/05-timing-draw-speed/#comparing-two-circle-drawing-algorithms","title":"Comparing Two Circle Drawing Algorithms","text":"

                                                                                                                                                                                                                                                                                                              In the following code, we compare two circle drawing algorithms.

                                                                                                                                                                                                                                                                                                              1. Row Scanner Method - this method scans each pixel in the square around the circle and turns it on if the pixel is within a distance range. It must calculate the distance of each pixel and compare
                                                                                                                                                                                                                                                                                                              2. that distance to both the inside and outside distances. The time-consuming operations are to calculate the squares of the x and y distances.
                                                                                                                                                                                                                                                                                                              3. Point Draw Method - this method walks around the circle and for each degree, it draws a single pixel at the edge of the circle. Each point uses the sine() and cosine() functions to calculate the x and y distance from the center of the circle to that point.

                                                                                                                                                                                                                                                                                                              For small circles, it is very inefficient to calculate all 360 points. Scanning all the points in a 5X5 grid only takes 25 calculations. However, the larger the circle becomes, the more points there are to calculate in the row scanner method. A 20X20 circle will need to run the distance calculation 400 times.

                                                                                                                                                                                                                                                                                                              from utime import sleep, ticks_cpu, ticks_us\nimport math\nimport ssd1306\n\n# this is the built-in LED on the Pico\nled = Pin('LED', Pin.OUT)\n\nWIDTH = 128\nHEIGHT = 64\nclock=Pin(2)\ndata=Pin(3)\nRES = machine.Pin(4)\nDC = machine.Pin(5)\nCS = machine.Pin(6)\n\nspi=machine.SPI(0, sck=clock, mosi=data)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\n# \ndef fast_circle(x, y, r, color):\n    # draw points around a circle skiping every 4th one\n    for theta in range(0, 360, 2):\n        # we can save 5% of the time by only doing this once\n        radians = math.radians(theta)\n        x_pos = int(x + r * math.cos(radians))\n        y_pos = int(y + r * math.sin(radians))\n        # check if we are within range\n        #if 0 <= x_pos < 128 and 0 <= y_pos < 64:\n        # we can cut another 5% by not doing these checks\n        oled.pixel(x_pos, y_pos, color)\n\ndef circle(x, y, r, color):\n    diameter1 = (r - 0.5) ** 2\n    diameter2 = (r + 0.5) ** 2\n    x_min = max(0, int(x - r))\n    x_max = min(128, int(x + r + 1))\n    y_min = max(0, int(y - r))\n    y_max = min(64, int(y + r + 1))\n\n    for y_pos in range(y_min, y_max):\n        for x_pos in range(x_min, x_max):\n            if ((x_pos - x) ** 2 + (y_pos - y) ** 2 >= diameter1) and ((x_pos - x) ** 2 + (y_pos - y) ** 2 <= diameter2):\n                oled.pixel(x_pos, y_pos, color)\n\n\nstart = ticks_us()\ncircle(32, 32, 10, 1)\nend = ticks_us()\nprint('Standard scanner circle draw time in cpu ticks', end - start)\noled.show()\nsleep(1)\nstart = ticks_us()\nfast_circle(96, 32, 10, 1)\nend = ticks_us()\nprint('Fast draw time in cpu ticks', end - start)\noled.show()\n

                                                                                                                                                                                                                                                                                                              Challenge

                                                                                                                                                                                                                                                                                                              1. Write a program that compares drawing speed for various sizes of circles.
                                                                                                                                                                                                                                                                                                              2. Modify the circle function to use the most efficient algorithm
                                                                                                                                                                                                                                                                                                              3. If you have a small circle, how many points do you need to not make the circle appear broken? Try changing the number of points calculated in the line `for theta in range(0, 360, 2):. Can you dynamically change the number of points skipped as the circle becomes smaller?
                                                                                                                                                                                                                                                                                                              4. Can you add a parameter to the circle function that only draws every 3rd point?
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/10-oled-bounce/","title":"OLED Bounce","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will draw a box around the edge of the display using the commands that draw horizontal and vertical lines: hline and vline. Then we will draw a ball that bounces off these edges.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/10-oled-bounce/#draw-a-border","title":"Draw a border","text":"
                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom ssd1306 import SSD1306_I2C\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl)\n# Screen size\nwidth=128\nheight=64\noled = SSD1306_I2C(width, height, i2c)\n\noled.hline(0, 0, width - 1, 1) # top edge\noled.hline(0, height - 1, width - 1, 1) # bottom edge\noled.vline(0, 0, height - 1, 1) # left edge\noled.vline(width - 1, 0, height - 1, 1) # right edge\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/10-oled-bounce/#make-a-ball-bounce-around-inside-the-wall","title":"Make a Ball Bounce Around Inside the Wall","text":"
                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom ssd1306 import SSD1306_I2C\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl)\n# Screen size\nwidth=128\nheight=64\noled = SSD1306_I2C(width, height, i2c)\n\noled.fill(0) # clear to black\n\n# note that OLEDs have problems with screen burn it - don't leave this on too long!\ndef border(width, height):\n    oled.hline(0, 0, width - 1, 1) # top edge\n    oled.hline(0, height - 1, width - 1, 1) # bottom edge\n    oled.vline(0, 0, height - 1, 1) # left edge\n    oled.vline(width - 1, 0, height - 1, 1) # right edge\n\n# ok, not really a circle - just a square for now\ndef draw_ball(x,y, size, state):\n    if size == 1:\n        oled.pixel(x, y, state) # draw a single pixel\n    else:\n        for i in range(0,size): # draw a box of pixels of the right size\n            for j in range(0,size):\n                oled.pixel(x + i, y + j, state)\n    # TODO: for size above 4 round the corners\n\nborder(width, height)\n\nball_size = 2\n# start in the middle of the screen\ncurrent_x = int(width / 2)\ncurrent_y = int(height / 2)\n# start going down to the right\ndirection_x = 1\ndirection_y = -1\n# delay_time = .0001\n\n# Bounce forever\nwhile True:\n    draw_ball(current_x,current_y, ball_size,1)\n    oled.show()\n    # utime.sleep(delay_time)\n    draw_ball(current_x,current_y,ball_size,0)\n    # reverse at the edges\n    # left edge test\n    if current_x < 2:\n        direction_x = 1\n    # right edge test\n    if current_x > width - ball_size -2:\n        direction_x = -1\n    # top edge test\n    if current_y < 2:\n        direction_y = 1\n    # bottom edge test\n    if current_y > height - ball_size - 2:\n        direction_y = -1\n    # update the ball\n    current_x = current_x + direction_x\n    current_y = current_y + direction_y\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-lcd-waveshare/","title":"Waveshare LCD","text":""},{"location":"displays/graph/11-lcd-waveshare/#specification","title":"Specification","text":"
                                                                                                                                                                                                                                                                                                              1. Description: 1.8 inch TFT LCD Display Module For Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              2. List price: $10 US + shipping
                                                                                                                                                                                                                                                                                                              3. 65K RGB Colors
                                                                                                                                                                                                                                                                                                              4. Resolution: 160\u00d7128 Pixels
                                                                                                                                                                                                                                                                                                              5. Interface: SPI
                                                                                                                                                                                                                                                                                                              6. Driver: ST7735S Driver
                                                                                                                                                                                                                                                                                                              7. Onboard Female Pin Header For Direct Attaching To Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              8. Pixel size: 0.219 \u00d7 0.219 mm
                                                                                                                                                                                                                                                                                                              9. Dimensions 52.0 \u00d7 34.5 mm
                                                                                                                                                                                                                                                                                                              10. Operating voltage: 2.6~5.5V
                                                                                                                                                                                                                                                                                                              11. 18 bits per pixel (6 bits per color)
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-lcd-waveshare/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Waveshare spec Waveshare wiki Demo Code ST7735S Datasheet

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ping/","title":"OLED PING","text":""},{"location":"displays/graph/11-oled-ping/#circuit","title":"Circuit","text":""},{"location":"displays/graph/11-oled-ping/#coder","title":"Coder","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C, Timer\nfrom ssd1306 import SSD1306_I2C\nimport utime\n\n\n# global toggle button variable\nmeasure_on = False\n\n# debounce for button\ndef debounce(pin):\n    timer.init(mode=Timer.ONE_SHOT, period=200, callback=on_pressed)\n\n# if button pressed, toggle measure_on\ndef on_pressed(timer):\n    global measure_on\n    measure_on = not measure_on\n\n# Init button\nbutton = Pin(16, Pin.IN, Pin.PULL_DOWN)\ntimer = Timer()\nbutton.irq(debounce, Pin.IRQ_RISING)\n\n# Init Display\ni2c = I2C(0,sda=Pin(0),scl=Pin(1),freq=40000)\noled = SSD1306_I2C(128,64,i2c)\n\n# Init HC-SR04 pins\ntrigger = Pin(14, Pin.OUT)\necho = Pin(13, Pin.IN)\n\n\ndef ultra():\n    trigger.low()\n    utime.sleep_us(2)\n    trigger.high()\n    utime.sleep_us(5)\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    return distance\n\ntry:\n    while True:\n        oled.fill(0)\n        if measure_on:\n            result = ultra()\n            oled.text(\"Distance:\",0,0)\n            oled.text(str(result) + \" cm\",0,10)\n        oled.show()\n        utime.sleep(1)            \nexcept KeyboardInterrupt:\n    pass\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/","title":"OLED SSD1306 I2C Examples","text":"

                                                                                                                                                                                                                                                                                                              We use small OLED displays in many of our labs because:

                                                                                                                                                                                                                                                                                                              1. They are inexpensive (around $4).
                                                                                                                                                                                                                                                                                                              2. They are easy to connect via SPI. Just four wires: GND, VCC, Clock and Data.
                                                                                                                                                                                                                                                                                                              3. They have a large area to display feedback. Most of them are 128X64 pixels.
                                                                                                                                                                                                                                                                                                              4. Once you get the drivers installed (not always easy) they are easy to program. You only need to initialize the device and run the oled.fill(), oled.text() and oled.show() functions.
                                                                                                                                                                                                                                                                                                              5. OLEDs, unlike LCDs, have high contrast over a large range of input voltages. This means that as your batteries slowly discharge, your OLEDs will keep their high-quality contrast.
                                                                                                                                                                                                                                                                                                              6. There is plenty of sample code and tutorials available.

                                                                                                                                                                                                                                                                                                              The first step is to find out what type of display graphics chip is used in your OLED.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/#sh1106-example","title":"SH1106 Example","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nimport sh1106\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c = I2C(0, scl=scl, sda=sda, freq=400000)\n\ndisplay = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)\ndisplay.sleep(False)\n\ndisplay.fill(0)\ndisplay.text('CoderDojo', 0, 0, 1)\ndisplay.show()\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/#counter-example","title":"Counter Example","text":"

                                                                                                                                                                                                                                                                                                              In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom ssd1306 import SSD1306_I2C\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)\noled = SSD1306_I2C(128, 64, i2c)\n\nfor i in range(1, 51): # count 1 to 50\n    oled.fill(0) # clear to black\n    oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black\n    oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top\n    oled.show() # update display\n    utime.sleep(0.1) #wait 1/10th of a second\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/#animated-box","title":"Animated Box","text":"

                                                                                                                                                                                                                                                                                                              This draws a title and four lines around a drawing area. It then draws boxes that move to the right.

                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nimport sh1106\nimport utime\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c = I2C(0, scl=scl, sda=sda, freq=400000)\n\n## note that we can only draw from 0 to 62\ndisplay = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)\ndisplay.sleep(False)\n\ndisplay.fill(0) # clear to black\ndisplay.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black\n# line under title\ndisplay.hline(0, 9, 127, 1)\n# bottom of display\ndisplay.hline(0, 30, 127, 1)\n# left edge\ndisplay.vline(0, 10, 32, 1)\n# right edge\ndisplay.vline(127, 10, 32, 1)\n\nfor i in range(0, 118):\n    # box x0, y0, width, height, on\n    display.fill_rect(i,10, 10, 10, 1)\n    # draw black behind number\n    display.fill_rect(10, 21, 30, 8, 0)\n    display.text(str(i), 10, 21, 1)\n    display.show() # update display\n    # utime.sleep(0.001)\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/#bounce-on-the-sh1106-display-using-i2c","title":"Bounce on the SH1106 Display using I2C","text":"

                                                                                                                                                                                                                                                                                                              This example is a ball that bounces around the inside of a border rectangle. Is similar to other bounce examples with the exception that you can't draw on the last row of pixels.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\n# from ssd1306 import SSD1306_I2C\nimport sh1106\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl)\n# Screen size\nwidth=128\nheight=64 # we could make this be 63 but the init method should use the full value\n# oled = SSD1306_I2C(width, height, i2c)\noled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c)\n\noled.fill(0) # clear to black\n\n# note that OLEDs have problems with screen burn it - don't leave this on too long!\ndef border(width, height):\n    oled.hline(0, 0, width - 1, 1) # top edge\n    oled.hline(0, height - 2, width - 1, 1) # bottom edge\n    oled.vline(0, 0, height - 1, 1) # left edge\n    oled.vline(width - 1, 0, height - 1, 1) # right edge\n\n# ok, not really a circle - just a square for now\ndef draw_ball(x,y, size, state):\n    if size == 1:\n        oled.pixel(x, y, state) # draw a single pixel\n    else:\n        for i in range(0,size): # draw a box of pixels of the right size\n            for j in range(0,size):\n                oled.pixel(x + i, y + j, state)\n    # TODO: for size above 4 round the corners\n\nborder(width, height)\n\nball_size = 5\ncurrent_x = int(width / 2)\ncurrent_y = int(height / 2)\ndirection_x = 1\ndirection_y = -1\n# delay_time = .0001\n\n# oled.line(0, height-2, width-1, height-2, 1)\n\n# Bounce forever\nwhile True:\n    draw_ball(current_x,current_y, ball_size,1)\n    oled.show()\n    # utime.sleep(delay_time)\n    draw_ball(current_x,current_y,ball_size,0)\n    # reverse at the edges\n    # left edge test\n    if current_x < 2:\n        direction_x = 1\n    # right edge test\n    if current_x > width - ball_size -2:\n        direction_x = -1\n    # top edge test\n    if current_y < 2:\n        direction_y = 1\n    # bottom edge test\n    if current_y > height - ball_size - 3:\n        direction_y = -1\n    # update the ball\n    current_x = current_x + direction_x\n    current_y = current_y + direction_y\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-sh1106-i2c/#sh1106-references","title":"SH1106 References","text":"
                                                                                                                                                                                                                                                                                                              1. Robert HH SH1106 Driver GitHub
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/","title":"OLED SSD1306 Examples","text":""},{"location":"displays/graph/11-oled-ssd1306-i2c/#using-the-ssd1306-with-i2c-interfaces","title":"Using the SSD1306 with I2C Interfaces","text":""},{"location":"displays/graph/11-oled-ssd1306-i2c/#add-the-ssd1306-python-module","title":"Add the ssd1306 Python Module","text":"

                                                                                                                                                                                                                                                                                                              You can now use the Thonny \"Tools -> Manage Packages...\" menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use.

                                                                                                                                                                                                                                                                                                              If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#i2c-hello-world","title":"I2C Hello World","text":"
                                                                                                                                                                                                                                                                                                              import machine\nfrom ssd1306 import SSD1306_I2C\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)\noled = SSD1306_I2C(128, 64, i2c)\noled.fill(0)\noled.text(\"Hello World!\", 0, 0)\noled.show()\nprint('Done')\n

                                                                                                                                                                                                                                                                                                              After this program runs you should see the text on your OLED display.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#sh1106-example","title":"SH1106 Example","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nimport sh1106\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c = I2C(0, scl=scl, sda=sda, freq=400000)\n\ndisplay = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)\ndisplay.sleep(False)\n\ndisplay.fill(0)\ndisplay.text('CoderDojo', 0, 0, 1)\ndisplay.show()\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#counter-example","title":"Counter Example","text":"

                                                                                                                                                                                                                                                                                                              In this example we will updated the display 50 times with a 1/10th of a second pause between each refresh. A counter will cycle from 1 to 50.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nfrom ssd1306 import SSD1306_I2C\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)\noled = SSD1306_I2C(128, 64, i2c)\n\nfor i in range(1, 51): # count 1 to 50\n    oled.fill(0) # clear to black\n    oled.text('CoderDojo Rocks!', 0, 0, 1) # at x=0, y=0, white on black\n    oled.text(str(i), 40, 20, 1) # move 30 pixels horizontal and 20 down from the top\n    oled.show() # update display\n    utime.sleep(0.1) #wait 1/10th of a second\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#animated-box","title":"Animated Box","text":"

                                                                                                                                                                                                                                                                                                              This draws a title and four lines around a drawing area. It then draws boxes that move to the right.

                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nimport sh1106\nimport utime\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c = I2C(0, scl=scl, sda=sda, freq=400000)\n\ndisplay = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c)\ndisplay.sleep(False)\n\ndisplay.fill(0) # clear to black\ndisplay.text('CoderDojo Rocks', 0, 0, 1) # at x=0, y=0, white on black\n# line under title\ndisplay.hline(0, 9, 127, 1)\n# bottom of display\ndisplay.hline(0, 30, 127, 1)\n# left edge\ndisplay.vline(0, 10, 32, 1)\n# right edge\ndisplay.vline(127, 10, 32, 1)\n\nfor i in range(0, 118):\n    # box x0, y0, width, height, on\n    display.fill_rect(i,10, 10, 10, 1)\n    # draw black behind number\n    display.fill_rect(10, 21, 30, 8, 0)\n    display.text(str(i), 10, 21, 1)\n    display.show() # update display\n    # utime.sleep(0.001)\n\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#install-ssd1306-module","title":"Install SSD1306 Module","text":""},{"location":"displays/graph/11-oled-ssd1306-i2c/#ssd1306-module","title":"ssd1306 module","text":"

                                                                                                                                                                                                                                                                                                              SSD1306 Library - click the RAW button and then right click to do a \"Save As\"

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#ssd1306-vs-sh1106","title":"SSD1306 vs. SH1106","text":"

                                                                                                                                                                                                                                                                                                              There is only one small difference between SSD1306 and SH1106: The SH1106 controller has an internal RAM of 132x64 pixel. The SSD1306 only has 128x64 pixel.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#the-spi-interface","title":"The SPI interface","text":"

                                                                                                                                                                                                                                                                                                              The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#spi-baudrate","title":"SPI Baudrate","text":"

                                                                                                                                                                                                                                                                                                              https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c

                                                                                                                                                                                                                                                                                                              The seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display:

                                                                                                                                                                                                                                                                                                              1. CS - Chip Select - pin 4
                                                                                                                                                                                                                                                                                                              2. DC - Data/Command - pin 5
                                                                                                                                                                                                                                                                                                              3. RES - Reset - pin 6
                                                                                                                                                                                                                                                                                                              4. SDA - Data - SPIO TX GP7 pin 10
                                                                                                                                                                                                                                                                                                              5. SCL - Clock - Connect to SPIO SCK GP6 pin 9
                                                                                                                                                                                                                                                                                                              6. VCC - Connect to the 3.3V Out pin 36
                                                                                                                                                                                                                                                                                                              7. GND - pin 38 or 3 any other GND pin
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#pico-pins","title":"Pico Pins","text":"
                                                                                                                                                                                                                                                                                                              # Sample code sections\n 28 # ------------ SPI ------------------\n 29 # Pin Map SPI\n 30 # - 3v - xxxxxx - Vcc\n 31 # - G - xxxxxx - Gnd\n 32 # - D7 - GPIO 13 - Din / MOSI fixed\n 33 # - D5 - GPIO 14 - Clk / Sck fixed\n 34 # - D8 - GPIO 4 - CS (optional, if the only connected device)\n 35 # - D2 - GPIO 5 - D/C\n 36 # - D1 - GPIO 2 - Res\n

                                                                                                                                                                                                                                                                                                              SCK is the clock - hook this to the oled SCL MOSI is the line taking data from your Pico to the peripheral device. Hook this to SDA

                                                                                                                                                                                                                                                                                                              From the SDK: https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf Section 3.7

                                                                                                                                                                                                                                                                                                              1. SPI0_SCK - pin 6
                                                                                                                                                                                                                                                                                                              2. SPI0_MOSI - pin 7
                                                                                                                                                                                                                                                                                                              3. SPI0_MISO - pin 8

                                                                                                                                                                                                                                                                                                              This contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO

                                                                                                                                                                                                                                                                                                              spi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi_rx=machine.Pin(4)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#spi-terms","title":"SPI Terms","text":"

                                                                                                                                                                                                                                                                                                              Master Out Slave In (MOSI)

                                                                                                                                                                                                                                                                                                              We send the data to the SPI RX (Receive) port on the Pico. These are pin 1 (GP0) or pin 6 (GP4)

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#sample-nonworking-spi-code","title":"Sample Nonworking SPI Code","text":"

                                                                                                                                                                                                                                                                                                              From the documentation:

                                                                                                                                                                                                                                                                                                              From

                                                                                                                                                                                                                                                                                                              spi is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used.

                                                                                                                                                                                                                                                                                                              dc is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver.

                                                                                                                                                                                                                                                                                                              res is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.

                                                                                                                                                                                                                                                                                                              cs is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.

                                                                                                                                                                                                                                                                                                              import machine\nimport machine\nimport utime\nimport ssd1306\nled = machine.Pin(25, machine.Pin.OUT)\n\n# From: https://github.com/robert-hh/SH1106\n# display = sh1106.SH1106_SPI(width, height, spi, dc, res, cs)\n#MOSI=machine.Pin(7)\n#SCK=machine.Pin(6)\n#spi = machine.SPI(0, baudrate=400000, sck=SCK, mosi=MOSI)\nspi_sck=machine.Pin(6)\nspi_tx=machine.Pin(7)\n# spi_rx=machine.Pin(4)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\n\nCS = machine.Pin(8)\nDC = machine.Pin(9)\nRES = machine.Pin(10)\n\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\n\n# flash all pixels on\noled.fill(1)\noled.show()\nutime.sleep(0.5)\n\noled.fill(0)\noled.text('CoderDojo Rocks!', 0, 0, 1)\noled.show()\n\n# flash the LED to show end\nled.high()\nutime.sleep(0.5)\nled.low()\n\nprint('Done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-i2c/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython Tutorial on the SSD1306

                                                                                                                                                                                                                                                                                                              2. robert-hh's SH1106 Driver

                                                                                                                                                                                                                                                                                                              3. M Fitzp OLED Display i2c Article

                                                                                                                                                                                                                                                                                                              4. Adafruit Stats

                                                                                                                                                                                                                                                                                                              DIY More OLED Product Description

                                                                                                                                                                                                                                                                                                              1. Using I2C Defaults
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/","title":"OLED SSD1306 SPI Examples","text":""},{"location":"displays/graph/11-oled-ssd1306-spi/#using-the-ssd1306-with-spi-interfaces","title":"Using the SSD1306 with SPI Interfaces","text":""},{"location":"displays/graph/11-oled-ssd1306-spi/#add-the-ssd1306-python-module","title":"Add the ssd1306 Python Module","text":"

                                                                                                                                                                                                                                                                                                              You can now use the Thonny \"Tools -> Manage Packages...\" menu to add the Python driver for the SSD1306 device. You will need to do this for every new device you use.

                                                                                                                                                                                                                                                                                                              If the Manage Packages menu is disabled, then you will need to go into the shell and add it with the pip command.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#install-ssd1306-module","title":"Install SSD1306 Module","text":""},{"location":"displays/graph/11-oled-ssd1306-spi/#ssd1306-module","title":"ssd1306 module","text":"

                                                                                                                                                                                                                                                                                                              SSD1306 Library - click the RAW button and then right click to do a \"Save As\"

                                                                                                                                                                                                                                                                                                              SSD1306 Library Searchable

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#the-spi-interface","title":"The SPI interface","text":"

                                                                                                                                                                                                                                                                                                              The four wire I2C interface is great for kids that don't want to hook up more than four wires. But there are times when we want a higher performance screen with faster refresh times. This is when the SPI interface comes in handy.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#displaying-spi-defaults","title":"Displaying SPI Defaults","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom ssd1306 import SSD1306_SPI\n# default is data (MOSI) on GP7 and clock (sck) on GP6\nspi=machine.SPI(0)\nprint(spi)\nSPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=6, mosi=7, miso=4)\n### SPI Baudrate\nhttps://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga37f4c04ce4165ac8c129226336a0b66c\n\nThe seven wires on the back of the SPI OLED screens are the following as read from the top to bottom looking at the back of the display:\n\n![](../../img/oled-back-connections.png)\n\n1. CS - Chip Select - pin 4\n2. DC - Data/Command - pin 5\n3. RES - Reset - pin 6\n4. SDA - Data - SPIO TX GP7 pin 10\n5. SCL - Clock - Connect to SPIO SCK GP6 pin 9\n6. VCC - Connect to the 3.3V Out pin 36\n7. GND - pin 38 or 3 any other GND pin\n\n### Pico Pins\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#sample-code-sections","title":"Sample code sections","text":"

                                                                                                                                                                                                                                                                                                              28 # ------------ SPI ------------------ 29 # Pin Map SPI 30 # - 3v - xxxxxx - Vcc 31 # - G - xxxxxx - Gnd 32 # - D7 - GPIO 13 - Din / MOSI fixed 33 # - D5 - GPIO 14 - Clk / Sck fixed 34 # - D8 - GPIO 4 - CS (optional, if the only connected device) 35 # - D2 - GPIO 5 - D/C 36 # - D1 - GPIO 2 - Res

                                                                                                                                                                                                                                                                                                              * SCK is the clock - hook this to the oled SCL\n* MOSI is the line taking data from your Pico to the peripheral device.  Hook this to SDA\n\nFrom the SDK:\nhttps://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf\nSection 3.7\n\n1. SPI0_SCK - pin 6\n2. SPI0_MOSI - pin 7\n3. SPI0_MISO - pin 8\n\nThis contradicts p122 in GET STARTED WITH MICROPYTHON ON RASPBERRY PI PICO\n
                                                                                                                                                                                                                                                                                                              spi_sck=machine.Pin(2) spi_tx=machine.Pin(3) spi_rx=machine.Pin(4)
                                                                                                                                                                                                                                                                                                              We send the data to the SPI RX (Receive) port on the Pico.  These are pin 1 (GP0) or pin 6 (GP4)\n\n## Sample Nonworking SPI Code\n\nFrom the documentation:\n\n!!! From Raspberry Pi Pico Documentation\n    **spi** is an SPI object, which has to be created beforehand and tells the ports for SCLJ and MOSI. MISO is not used.\n\n    **dc** is the GPIO Pin object for the Data/Command selection. It will be initialized by the driver.\n\n    **res** is the GPIO Pin object for the reset connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.\n\n    **cs** is the GPIO Pin object for the CS connection. It will be initialized by the driver. If it is not needed, it can be set to None or omitted. In this case the default value of None applies.\n\n```py\nimport machine\nimport utime\nimport ssd1306\nled = machine.Pin(25, machine.Pin.OUT)\n\nspi_sck=machine.Pin(6)\nspi_tx=machine.Pin(7)\n# spi_rx=machine.Pin(4)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\n\nCS = machine.Pin(8)\nDC = machine.Pin(9)\nRES = machine.Pin(10)\n\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\n\n# flash all pixels on\noled.fill(1)\noled.show()\nutime.sleep(0.5)\n\noled.fill(0)\noled.text('CoderDojo Rocks!', 0, 0, 1)\noled.show()\n\n# flash the LED to show end\nled.high()\nutime.sleep(0.5)\nled.low()\n\nprint('Done')\n

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              robert-hh's SH1106 Driver

                                                                                                                                                                                                                                                                                                              MicroPython SSD1306 Class

                                                                                                                                                                                                                                                                                                              https://www.mfitzp.com/article/oled-displays-i2c-micropython/

                                                                                                                                                                                                                                                                                                              https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/master/examples/ssd1306_stats.py

                                                                                                                                                                                                                                                                                                              https://github.com/robert-hh/SH1106/blob/master/sh1106.py

                                                                                                                                                                                                                                                                                                              DIY More OLED Product Description

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#ssd1306","title":"SSD1306","text":"

                                                                                                                                                                                                                                                                                                              https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1306/

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-oled-ssd1306-spi/#ssd1307","title":"SSD1307","text":"

                                                                                                                                                                                                                                                                                                              https://www.solomon-systech.com/en/product/advanced-display/oled-display-driver-ic/ssd1307/

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/","title":"Pong","text":"

                                                                                                                                                                                                                                                                                                              Using a low-cost OLED device you can write a pong game. If you use a small 128X64 OLED the price can be around $12.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#part-list","title":"Part list","text":"Part Name Price Link Description Raspberry Pi Pico $4 Microcenter With 264K RAM it has plenty of room for storing the framebuffer 1/2 Size Solderless Breadboard $2 link 400 tie breadboard 128X64 OLED $5 eBay You can also get larger 2.42\" displays for around $20 2 10K Potentiometers $1.5 each eBay You can purchase these in QTY 10 for less. Use the part number B10K to narrow your search. Clear Plastic Box $4 The Container Store Shallow Narrow Stackable Rectangle Clear with Lids 8-1/4\" x 3-1/2\" x 1-7/8\" h. The link is to the white lids.

                                                                                                                                                                                                                                                                                                              Raspberry Pi Pico for $4.

                                                                                                                                                                                                                                                                                                              OLED with I2C Interface. Note the pins are VCC, GND, SCL (clock), SDA (data).

                                                                                                                                                                                                                                                                                                              1/2 size 400 connector solderless breadboard

                                                                                                                                                                                                                                                                                                              10K potentiometer with pre-soldered connectors. You will need two of these. You can use a male-to-male header to connect it to the breadboard.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#connections","title":"Connections","text":"
                                                                                                                                                                                                                                                                                                              1. Connect the GND of the OLED to GND of the Pico
                                                                                                                                                                                                                                                                                                              2. Connect the VCC of the OLED to 3V3 OUT (physical pin 36)
                                                                                                                                                                                                                                                                                                              3. Connect the SDA (data) of the OLED to the Pico GP0 (physical pin 1 on the top left with USB up)
                                                                                                                                                                                                                                                                                                              4. Connect the SCL (clock) of the OLED to GP1 (physical pin 2)
                                                                                                                                                                                                                                                                                                              5. Connect the center tap of both potentiometers to ADC0 (GP26 - pin 31) and ADC1 (GP27 - pin 32)
                                                                                                                                                                                                                                                                                                              6. Connect the outer connectors of the potentiometers to VCC and GND
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#getting-the-right-python-libraries","title":"Getting the Right Python Libraries","text":"

                                                                                                                                                                                                                                                                                                              To run this program, you will need a MicroPython display driver. Our display in this example is the popular SSD1306 driver chip. Your OLED might have a slightly different driver type.

                                                                                                                                                                                                                                                                                                              Here is the line that must be customized for your display:

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#testing-the-oled","title":"Testing the OLED","text":"

                                                                                                                                                                                                                                                                                                              This test will verify that your OLED connections are correct.

                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nfrom ssd1306 import SSD1306_I2C\nWIDTH  = 128\nHEIGHT = 64\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0,sda=sda, scl=scl)\noled = SSD1306_I2C(WIDTH, HEIGHT, i2c)\noled.fill(0)\noled.text(\"CoderDojo Rocks\",0,0)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#drawing-the-border","title":"Drawing the Border","text":"
                                                                                                                                                                                                                                                                                                              def border(WIDTH, HEIGHT):\n    oled.rect(0, 0, WIDTH, HEIGHT, 1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/11-pong/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              # Pong game on Raspberry Pi Pico with a OLED and two Potentimeters\nfrom machine import Pin, PWM, SPI\nimport ssd1306\nfrom utime import sleep\nimport random # random direction for new ball\n\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\nCS = machine.Pin(1)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\n# connect the center tops of the potentiometers to ADC0 and ADC1\npot_pin_1 = machine.ADC(26)\npot_pin_2 = machine.ADC(26) # make them the same for testing\n\n# lower right corner with USB connector on top\nSPEAKER_PIN = 16\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\n# globals variables\n# static variables are constants are uppercase variable names\nWIDTH = 128\nHALF_WIDTH = int(WIDTH / 2)\nHEIGHT = 64\nHALF_HEIGHT = HEIGHT\nBALL_SIZE = 3 # 2X2 pixels\nPAD_WIDTH = 2\nPAD_HEIGHT = 8\nHALF_PAD_WIDTH = int(PAD_WIDTH / 2)\nHALF_PAD_HEIGHT = int(PAD_HEIGHT / 2)\nPOT_MIN = 3000\nPOT_MAX = 65534\nMAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1\n# dynamic global variables use lowercase\npaddle1_vel = 0\npaddle2_vel = 0\nl_score = 0\nr_score = 0\n# continiuous update of the paddle and ball\n# play_startup_sound()\n# start with the ball in the center\nball_x = int(WIDTH / 2)\nball_y = int(HEIGHT / 2)\n# set the initial directinon to down to the right\nball_x_dir = 1\nball_y_dir = 1\n\ndef play_startup_sound():\n    speaker.duty_u16(1000)\n    speaker.freq(600)\n    sleep(.25)\n    speaker.freq(800)\n    sleep(.25)\n    speaker.freq(1200)\n    sleep(.25)\n    speaker.duty_u16(0)\n\ndef play_bounce_sound():\n    speaker.duty_u16(1000)\n    speaker.freq(900)\n    sleep(.25)\n    speaker.duty_u16(0)\n\ndef play_score_sound():\n    speaker.duty_u16(1000)\n    speaker.freq(600)\n    sleep(.25)\n    speaker.freq(800)\n    sleep(.25)\n    speaker.duty_u16(0)\n\n# note that OLEDs have problems with screen burn it - don't leave this on too long!\ndef border(WIDTH, HEIGHT):\n    oled.rect(0, 0, WIDTH, HEIGHT, 1)\n\n\n# Takes an input number vale and a range between high-and-low and returns it scaled to the new range\n# This is similar to the Arduino map() function\ndef valmap(value, istart, istop, ostart, ostop):\n  return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart)))\n\n# draw a vertical bar\ndef draw_paddle(paddle_no, paddle_center):\n    if paddle_no == 1:\n         x = 0\n    else:\n         x = WIDTH - 2\n    y = paddle_center - HALF_PAD_HEIGHT\n    oled.fill_rect(x,  y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s\n\ndef draw_ball():\n    oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now\n\n# The main event loop\nwhile True:\n    oled.fill(0) # clear screen\n    oled.vline(int(WIDTH / 2), 0, HEIGHT,  1)\n    # border(WIDTH, HEIGHT)\n    # read both the pot values\n    pot_val_1 = pot_pin_1.read_u16()\n    pot_val_2 = pot_pin_1.read_u16()\n    # print(pot_val_1)\n\n    # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT\n    # ideally, it should range from 5 to 58\n    pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2)\n    pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2)\n\n    # print(pot_val, pot_scaled)\n    draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT)\n    draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT)\n    draw_ball()\n\n    #update ball position with the current directions\n    ball_x = ball_x + ball_x_dir\n    ball_y = ball_y + ball_y_dir\n\n    # update the ball direction if we are at the top or bottom edge\n    if ball_y < 0:\n        ball_y_dir = 1\n        #play_bounce_sound()\n    if ball_y > HEIGHT - 3:\n        ball_y_dir = -1\n        #play_bounce_sound()\n\n    # if it hits the paddle bounce else score\n    if ball_x < 1:\n        top_paddle = pot_val_1 - HALF_PAD_HEIGHT\n        bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT\n        if ball_y > top_paddle and ball_y < bottom_paddle:\n            # we have a hit\n            ball_x_dir = 1\n            ball_x = 2\n            play_bounce_sound()\n            print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle)\n        else:\n            # we have a score for the right player\n            play_score_sound()\n            r_score += 1\n            ball_x = int(WIDTH / 2)\n            ball_y = int(HEIGHT / 2)\n            ball_x_dir = random.randint(-1, 2)\n            if ball_x_dir == 0:\n                ball_x_dir = 1\n            ball_y_dir = random.randint(-1, 2)\n            print('score on left edge', pot_val_1, top_paddle, bottom_paddle)\n            sleep(.25)\n\n    if ball_x > WIDTH - 3:\n        ball_x = WIDTH - 4\n        top_paddle = pot_val_2 - HALF_PAD_HEIGHT\n        bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT\n        if ball_y > top_paddle and ball_y < bottom_paddle:\n            ball_x_dir = -1\n            print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle)\n        else:\n            l_score += 1\n            play_score_sound()\n            ball_x = int(WIDTH / 2)\n            ball_y = int(HEIGHT / 2)\n            ball_x_dir = random.randint(-1, 2)\n            if ball_x_dir == 0:\n                ball_x_dir = 1\n            ball_y_dir = random.randint(-1, 2)\n            play_bounce_sound()\n            print('score on right edge', pot_val_1, top_paddle, bottom_paddle)\n            sleep(.25)\n\n    oled.text(str(l_score), HALF_WIDTH - 20, 5, 1)\n\n    oled.text(str(r_score), HALF_WIDTH + 5, 5, 1)\n\n    oled.show()\n

                                                                                                                                                                                                                                                                                                              YouTube Video

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-e-paper-display/","title":"Raspberry Pi E-Paper Displays with","text":""},{"location":"displays/graph/12-e-paper-display/#specifications","title":"Specifications","text":"
                                                                                                                                                                                                                                                                                                              1. 2.9inch capacitive touch ePaper module, 296\u00d7128 resolution
                                                                                                                                                                                                                                                                                                              2. 5-points touch support, user-defined wakeup gesture
                                                                                                                                                                                                                                                                                                              3. No backlight, keeps displaying last content for a long time even when power down
                                                                                                                                                                                                                                                                                                              4. Ultra low power consumption, basically power is only required for refreshing
                                                                                                                                                                                                                                                                                                              5. SPI / I2C interface, requires minimal IO pins
                                                                                                                                                                                                                                                                                                              6. Comes with development resources and manual (Raspberry Pi Pico C/C++ and MicroPython examples)
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-e-paper-display/#resources","title":"Resources","text":"
                                                                                                                                                                                                                                                                                                              1. Waveshare Product Page
                                                                                                                                                                                                                                                                                                              2. Waveshare Wiki
                                                                                                                                                                                                                                                                                                              3. [Sample MicroPython Driver](https://github.com/waveshare/Pico_ePaper_Code/blob/main/python/0Pico-ePaper-5.65f.py
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/","title":"OLED Potentiometer Example","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will use a potentiometer to change the value of an OLED display. We will use a small SSD1306 OLED with an I2C interface.

                                                                                                                                                                                                                                                                                                              A potentiometer has three wires. The two outside wires connect to GND and the 3.3 volt output. The center wire, called the \"tap\" wire will connect to the pin that converts an continuous analog voltage value into a digital number.

                                                                                                                                                                                                                                                                                                              Wikipedia Page on Potentiometer

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#circuit-diagram","title":"Circuit Diagram","text":""},{"location":"displays/graph/12-oled-pot/#sample-code","title":"Sample Code","text":""},{"location":"displays/graph/12-oled-pot/#testing-the-pot","title":"Testing the POT","text":"

                                                                                                                                                                                                                                                                                                              Our first task is to find what pin to use for our first Analog to Digital concerter. GP26 is the same as ADC0. This is pin number 31 on the Pico.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\npot = machine.ADC(26)\nwhile True:\n    print(pot.read_u16())\n    utime.sleep(.2)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#sample-16-bit-output","title":"Sample 16 bit output","text":"

                                                                                                                                                                                                                                                                                                              A 16-bit integer can store 216 (or 65,536) distinct values. In an unsigned representation, these values are the integers between 0 and 65,535. So we are expecting numbers from 0 to 65,535.

                                                                                                                                                                                                                                                                                                              Sample results as we move the potentiometer from the minimum to the maximum values.

                                                                                                                                                                                                                                                                                                              65535\n52844\n31047\n7745\n256\n352\n19140\n41114\n62239\n65535\n57277\n33384\n10114\n352\n288\n19940\n28086\n

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#testing-the-oled","title":"Testing the OLED","text":""},{"location":"displays/graph/12-oled-pot/#getting-the-defaults","title":"Getting the defaults","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\n# i2c=machine.I2C(0)\ni2c=machine.I2C(0)\nprint(\"Device found at decimal\", i2c.scan())\nprint(i2c)\n

                                                                                                                                                                                                                                                                                                              Results: This tells you the default pins and frequency that the I2C bus is running at.

                                                                                                                                                                                                                                                                                                              Device found at decimal [60]\nI2C(0, freq=399361, scl=9, sda=8)\n
                                                                                                                                                                                                                                                                                                              Device found at decimal [60]\nI2C(0, freq=399361, scl=1, sda=0)\n

                                                                                                                                                                                                                                                                                                              This tells us that the default pins are GP9 (row 12) for clock and GP8 (row 11) for data.

                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nfrom ssd1306 import SSD1306_I2C\nWIDTH  = 128\nHEIGHT = 64\ni2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) \noled = SSD1306_I2C(WIDTH, HEIGHT, i2c)\noled.fill(0)\noled.text(\"CoderDojo Rocks\",0,0)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#continuous-text-display-on-oled","title":"Continuous Text Display on OLED","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, I2C\nfrom ssd1306 import SSD1306_I2C\nWIDTH  = 128\nHEIGHT = 32\ni2c = I2C(0) # Init I2C using I2C0 defaults SCL on GP9 (12) and SDA on GP8 (11) \noled = SSD1306_I2C(WIDTH, HEIGHT, i2c)\n\nPOT_PIN = machine.ADC(26)\n\nwhile True:\n    oled.fill(0)\n    oled.text(POT_PIN.read_u16())\n    oled.show()\n    utime.sleep(.2)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#bar-chart-and-text-display-of-pot-value","title":"Bar Chart and Text Display of Pot Value","text":"
                                                                                                                                                                                                                                                                                                              import machine\nimport utime\nimport sh1106\n\nsda=machine.Pin(0)\nscl=machine.Pin(1)\npot_pin = machine.ADC(26)\n\ni2c=machine.I2C(0,sda=sda, scl=scl)\n# Screen size\nwidth=128\nheight=64\nhalf_height = int(height / 2)\n# oled = SSD1306_I2C(width, height, i2c)\noled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c)\n\noled.fill(0) # clear to black\n\n# note that OLEDs have problems with screen burn it - don't leave this on too long!\ndef border(width, height):\n    oled.hline(0, 0, width - 1, 1) # top edge\n    oled.hline(0, height - 2, width - 1, 1) # bottom edge\n    oled.vline(0, 0, height - 1, 1) # left edge\n    oled.vline(width - 1, 0, height - 1, 1) # right edge\n\n# Takes an input number vale and a range between high-and-low and returns it scaled to the new range\n# This is similar to the Arduino map() function\ndef valmap(value, istart, istop, ostart, ostop):\n  return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart)))\n\n# draw a horizontal bar\ndef draw_hbar(inval, height, state):\n    oled.fill(0) # clear screen\n    border(width, height) # draw a border\n    oled.fill_rect(0, 1, inval, height, 1) # fill with 1\n    utime.sleep(.1) # wait a bit\n\n# continuous update\nwhile True:\n    pot_val = int(pot_pin.read_u16())\n    # the max value of the input is a 2^16 or 65536\n    pot_scaled = valmap(pot_val, 0, 65536, 0, 127)\n    print(pot_val, pot_scaled)\n    draw_hbar(pot_scaled, half_height, 1)\n\n    oled.text('raw:', 0, half_height + 5, 1)\n    oled.text(str(pot_val), 30, half_height + 5, 1)\n\n    oled.text('scaled:', 0, half_height + 15, 1)\n    oled.text(str(pot_scaled), 60, half_height + 15, 1)\n    oled.show()  \n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-pot/#gif-of-oled","title":"Gif of OLED","text":"

                                                                                                                                                                                                                                                                                                              Gif of small .96\" OLED

                                                                                                                                                                                                                                                                                                              Gif of larger 2.42\" OLED

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-ssd1306-spi-v1/","title":"OLED SSD1306 SPI V1","text":""},{"location":"displays/graph/12-oled-ssd1306-spi-v1/#oled-spi-demo","title":"OLED SPI Demo","text":"

                                                                                                                                                                                                                                                                                                              This code was provide by Jim Tannenbaum (aka Jet)

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/12-oled-ssd1306-spi-v1/#image","title":"Image","text":""},{"location":"displays/graph/12-oled-ssd1306-spi-v1/#code","title":"Code","text":"
                                                                                                                                                                                                                                                                                                              import machine import ssd1306\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\nCS = machine.Pin(1)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\n# flash all pixels on oled.fill(0)\noled.show()\noled.text('Hello Jet', 0, 0, 1)\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/13-pixel-draw/","title":"Sample Pixel-Based Drawing Program","text":"

                                                                                                                                                                                                                                                                                                              Code example provided by Jim Tannenbaum.

                                                                                                                                                                                                                                                                                                              This program will act like an Etch-A-Sketch(TM) program. It will use potentiometers with the center tap on GPIO pins GP26 and GP27 and draw as you move the potentiometers to control the X and Y dimensions.

                                                                                                                                                                                                                                                                                                              from machine import Pin, SPI, ADC\nimport ssd1306\nimport time\n\n# Takes an input number value and a range between high-and-low and returns it scaled to the new range\n# This is similar to the Arduino map() function\ndef scaled(value, istart, istop, ostart, ostop):\n  return int(ostart + (ostop - ostart) * ((int(value) - istart) / (istop - istart)))\n\n# Define the pins for SPI Clock and Transmit\nspi_sck = Pin(2)\nspi_tx = Pin(3)\nspi = SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx)\n\n# Define the pins for Chip Select, DC (Command), and Reset\nCS = Pin(1)\nDC = Pin(4)\nRES = Pin(5)\n\noled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)\n\n# Turn all pixels off\noled.fill(0)\noled.show()\n\n# Provide info to user\noled.text('Etch-A-Sketch', 0, 0, 1)\noled.text('Hit the reset', 0, 20, 1)\noled.text('button to clear', 0, 30, 1)\noled.text('the screen', 0, 40, 1)\noled.show()\n\n# Define the pin for the reset button\nresetButton = Pin(14, Pin.IN, Pin.PULL_DOWN)\n\n# Wait unti the user hits the button to clear the screen and start drawing\nwhile resetButton.value() != 1:\n    time.sleep(.25)\n\noled.fill(0)\noled.show()\n\n# Define the Horizontal and Vertical inputs from the Rheostats\nvert = ADC(26)\nhoriz = ADC(27)\n\n# Calculate where to start the line\nx = newX = scaled(vert.read_u16(), 0, 65536, 0, 128)\ny = newY = scaled(horiz.read_u16(), 0, 65536, 0, 64)\n\n# Loop forever\n# Draw the line, look for a reset to clear the screen, and get the new end points for the line\nwhile True:\n    oled.line(x, y, newX, newY, 1)\n    x = newX\n    y = newY\n    if resetButton.value():\n        oled.fill(0)\n    oled.show()\n    time.sleep(.2)\n    newX = scaled(vert.read_u16(), 0, 65536, 0, 128)\n    newY = scaled(horiz.read_u16(), 0, 65536, 0, 64)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/","title":"MicroPython ST7789V LCD Display","text":"

                                                                                                                                                                                                                                                                                                              The Sitronix ST7789 is a driver chip for small color IPS LCD displays that supports SPI interfaces. This example uses a 2-inch color LDC display manufactured by Waveshare with a retail price of approximately $13 or $14.75 on Amazon Prime.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#specifications","title":"Specifications","text":"
                                                                                                                                                                                                                                                                                                              • Resolution: 240(V) x 320(H) RGB
                                                                                                                                                                                                                                                                                                              • 18 bit color (6 bits for R, G and B)
                                                                                                                                                                                                                                                                                                              • 1,382,400 bits of display memory
                                                                                                                                                                                                                                                                                                              • Interface: 4-wire SPI (kind of)
                                                                                                                                                                                                                                                                                                              • Operating voltage: 3.3V

                                                                                                                                                                                                                                                                                                              Note: The ST7789 uses a SPI interfaces but not a true standard SPI protocol. The device only uses MOSI (DIN) to send data from master to slave for LCD display. Only four wires are needed to connect from the Pico to the device.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#device-interface","title":"Device Interface","text":""},{"location":"displays/graph/14-lcd-st7789V/#interface","title":"Interface","text":"
                                                                                                                                                                                                                                                                                                              1. VCC Power (3.3V input)
                                                                                                                                                                                                                                                                                                              2. GND Ground
                                                                                                                                                                                                                                                                                                              3. DIN SPI data input
                                                                                                                                                                                                                                                                                                              4. CLK SPI clock input
                                                                                                                                                                                                                                                                                                              5. CS Chip selection, low active
                                                                                                                                                                                                                                                                                                              6. DC Data/Command selection (high for data, low for command)
                                                                                                                                                                                                                                                                                                              7. RST Reset, low active
                                                                                                                                                                                                                                                                                                              8. BL Backlight - tie to GND to turn the backlight on

                                                                                                                                                                                                                                                                                                              Although the device has eight wires, your Pico only needs a few of them to be controlled by the GPIO ports.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#uploading-the-st7789v-python-firmware","title":"Uploading the ST7789V Python Firmware","text":"

                                                                                                                                                                                                                                                                                                              The firmware contains pre-compiled objects for various devices with the st7789 C driver and frozen python font files.

                                                                                                                                                                                                                                                                                                              The library for the driver is delivered as a single firmware.uf2 file available here:

                                                                                                                                                                                                                                                                                                              https://github.com/russhughes/st7789_mpy/tree/master/firmware/RP2

                                                                                                                                                                                                                                                                                                              To load this file you will need to hold down the BOTSEL button on the Pico and drag this file into the RP2 folder that is mounted.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#micropython-initialization","title":"MicroPython Initialization","text":"

                                                                                                                                                                                                                                                                                                              I used the following SPI Device ID 1 pinout on the lower left corner of the Pico:

                                                                                                                                                                                                                                                                                                              Pin GP Number Label on LCD 14 (GP10) BL 15 (GP11) RST 16 (GP12) DC 17 (GP13) CS 18 (GND) GND 19 (GP14) CLK 20 (GP15) DIN"},{"location":"displays/graph/14-lcd-st7789V/#sample-device-initialize","title":"Sample Device Initialize","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, SPI\nimport st7789\n\nBACKLIGHT_PIN = 10\nRESET_PIN = 11\nDC_PIN = 12\nCS_PIN = 13\nCLK_PIN = 14\nDIN_PIN = 15 # lower left corner\n\nimport vga1_bold_16x32 as font\n\nspi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN))\ntft = st7789.ST7789(spi, 240, 320,\n    reset=Pin(RESET_PIN, Pin.OUT),\n    cs=Pin(CS_PIN, Pin.OUT),\n    dc=Pin(DC_PIN, Pin.OUT),\n    backlight=Pin(BACKLIGHT_PIN, Pin.OUT),\n    rotation=3)\ntft.init()\n# draw white letters on a back background at 10 over and 20 down\ntft.text(font, \"Hello World!\", 10, 20, st7789.color565(255,255,255), st7789.color565(0,0,0))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#sample-hello-world-in-four-colors","title":"Sample Hello World In Four Colors","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, SPI\nimport st7789\n\nBACKLIGHT_PIN = 10\nRESET_PIN = 11\nDC_PIN = 12\nCS_PIN = 13\nCLK_PIN = 14\nDIN_PIN = 15 # lower left corner\n\nimport vga1_bold_16x32 as font\n\nspi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN))\ntft = st7789.ST7789(spi, 240, 320,\n    reset=Pin(RESET_PIN, Pin.OUT),\n    cs=Pin(CS_PIN, Pin.OUT),\n    dc=Pin(DC_PIN, Pin.OUT),\n    backlight=Pin(BACKLIGHT_PIN, Pin.OUT),\n    rotation=3)\ntft.init()\n\ntft.text(font, \"Hello World!\",10, 0, st7789.color565(255,255,255), st7789.color565(0,0,0))\ntft.text(font, \"Hello World!\",10, 50, st7789.color565(255,0,0), st7789.color565(0,0,0))\ntft.text(font, \"Hello World!\",10, 100, st7789.color565(0,255,0), st7789.color565(0,0,0))\ntft.text(font, \"Hello World!\",10, 150, st7789.color565(0,0,255), st7789.color565(0,0,0))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#driver-implementation-notes","title":"Driver Implementation Notes","text":"

                                                                                                                                                                                                                                                                                                              The ST7789V supports RGB444, RGB565 and RGB666 three formats. The Waveshare LCD uses RGB565. For most LCD controllers, the communication method of the controller can be configured, they are usually using 8080 parallel interface, 3-line SPI, 4-line SPI, and other communication methods. This LCD uses a 4-line SPI interface for reducing GPIO and fast speed.LCD

                                                                                                                                                                                                                                                                                                              1. RESX: Reset, should be pull-down when power on, set to 1 other time.
                                                                                                                                                                                                                                                                                                              2. CSX: Slave chip select. The chip is enabled only CS is set Low
                                                                                                                                                                                                                                                                                                              3. D/CX: Data/Command selection; DC=0, write command; DC=1, write data
                                                                                                                                                                                                                                                                                                              4. SDA: Data transmitted. (RGB data)
                                                                                                                                                                                                                                                                                                              5. SCL: SPI clock
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#timing-diagram","title":"Timing Diagram","text":"

                                                                                                                                                                                                                                                                                                              You can see what data needs to be changing from the timing diagram below:

                                                                                                                                                                                                                                                                                                              1. The SPI communication protocol of the data transmission uses control bits: clock phase (CPHA) and clock polarity (CPOL)
                                                                                                                                                                                                                                                                                                              2. CPOL defines the level while the synchronization clock is idle. If CPOL=0, then it is LOW.
                                                                                                                                                                                                                                                                                                              3. CPHA defines at whish clock\u2019s tick the data transmission starts. CPHL=0 \u2013 at the first one, otherwise at the second one

                                                                                                                                                                                                                                                                                                              This combination of two bits provides 4 modes of SPI data transmission. The commonly used is SPI0 mode, i.e. GPHL=0 and CPOL=0.

                                                                                                                                                                                                                                                                                                              According to the figure above, data transmitting begins at the first falling edge, 8bit data are transmitted at one clock cycle. It is SPI0. MSB.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-lcd-st7789V/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. ST7789C Datasheet (PDF)
                                                                                                                                                                                                                                                                                                              2. Waveshare Wiki
                                                                                                                                                                                                                                                                                                              3. Waveshare Pico Dispaly
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/14-random-hearts/","title":"Draw Random Hearts","text":"

                                                                                                                                                                                                                                                                                                              This program uses the MicroPython urandom library to generate random X and Y positions on the display. It then uses an array of binary values to draw a heart icon at that location.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM, SPI\nimport urandom\nimport ssd1306\nfrom utime import sleep\nimport random # random direction for new ball\n\nWIDTH = 128\nHEIGHT = 64\nCS = machine.Pin(1)\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\n\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\nHEART = [\n    [ 0, 0, 0, 0, 0, 0, 0, 0, 0],\n    [ 0, 1, 1, 0, 0, 0, 1, 1, 0],\n    [ 1, 1, 1, 1, 0, 1, 1, 1, 1],\n    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [ 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [ 0, 1, 1, 1, 1, 1, 1, 1, 0],\n    [ 0, 0, 1, 1, 1, 1, 1, 0, 0],\n    [ 0, 0, 0, 1, 1, 1, 0, 0, 0],\n    [ 0, 0, 0, 0, 1, 0, 0, 0, 0],\n]\n\ndef draw_heart(xofs, yofs):\n    for y, row in enumerate(HEART):\n        for x, c in enumerate(row):\n            oled.pixel(x + xofs, y + yofs, c)\n\ndef random_heart():\n    xofs = urandom.getrandbits(7)\n    yofs = urandom.getrandbits(6)\n    print(xofs, yofs)\n    draw_heart(xofs, yofs)\n\n\noled.fill(0)\nfor n in range(10):\n    random_heart()\n\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-cu1609c-led/","title":"CU1609C LED Display","text":"

                                                                                                                                                                                                                                                                                                              Note: This is a work-in-progress. We have not found a MicroPython driver for this display.

                                                                                                                                                                                                                                                                                                              The UC1609 is a graphic LED driver chip with an SPI interface. Because it is low cost ($4) and 2 inches across it is ideal for low-cost robot displays.

                                                                                                                                                                                                                                                                                                              192X62 LCD display for $4 USB device

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-cu1609c-led/#connections","title":"Connections","text":"Pin Name Description 1 K Backlight Cathode Connect to GND rail 2 A Backlight Anode Connect via 200 ohm to 3.2v rail to limit backlight current to 3 milliamps. The current for backlight is limited to 20 milliamps. 3 GND Ground Connect to GND rail 4 VDD Power Supply connect to +3.3v rail 5 SCK Serial clock input. Connect to SPI CLK 6 SDA Serial data input. Connect to SPI Data SCL 7 RST Connect to 3.3v rail. 8 CD It determines whether the access is related to data or command. Connect to GPIO 9 CS Chip select input. Connect to GND when LCD is use."},{"location":"displays/graph/15-cu1609c-led/#connection-notes","title":"Connection Notes","text":"

                                                                                                                                                                                                                                                                                                              When RST=L, all control registers are re-initialized by their default sates. Since UC1609c has built-in Power-on Reset, the RST pin is not required for proper chip operation. An RC filter has been included on-chip. There is no need for external RC noise filter. When RST is not used, connect the pin to High.

                                                                                                                                                                                                                                                                                                              CS determines whether the access is related to data or command. When CS=\u201cH\u201d : Display data. When CS=\u201cL\u201d : Command.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-cu1609c-led/#hello-world","title":"Hello World","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, SPI\n\nSPI_CLK = 2 # SPI clock\nSPI_SDA = 3\nCD = 5 # command or data\n# RST is tied to 3.3v\n# CS is tied to GND\n\n# SPI(0, baudrate=992063, polarity=0, phase=0, bits=8, sck=2, mosi=3, miso=4)\nspi = SPI(0, baudrate=31250000, sck=Pin(SPI_CLK), mosi=Pin(SPI_SDA))\nprint(spi)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-cu1609c-led/#similar-drivers","title":"Similar Drivers","text":"

                                                                                                                                                                                                                                                                                                              There are two similar drivers. One is for the LCD160CR

                                                                                                                                                                                                                                                                                                              LCD160CR Display Driver

                                                                                                                                                                                                                                                                                                              The other is the Arduino C version by Gavin Lyones that has been around for a long time.

                                                                                                                                                                                                                                                                                                              Gavin Lyons GitHub Repo supporting the UC1609

                                                                                                                                                                                                                                                                                                              Our goal is to port Gavin's C code to use the same function as the LCD160CR driver.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-cu1609c-led/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. BuyDisplay Product 2 inch Blue 192x64 Graphic LCD Display Module,UC1609,SPI for $3.48
                                                                                                                                                                                                                                                                                                              2. ERM19264-4 SeriesGraphic Display Module Datasheet
                                                                                                                                                                                                                                                                                                              3. Gavin Lyons GitHub Repo supporting the UC1609
                                                                                                                                                                                                                                                                                                              4. EBay Product 2 inch White 192x64 Graphic LCD Display Module,UC1609,SPI
                                                                                                                                                                                                                                                                                                              5. MicroPython Pyboard LCD Class
                                                                                                                                                                                                                                                                                                              6. List of LCD Graphic Displays
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/","title":"OLED Patterns","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will show how you can display interesting repeating patterns on your OLED screen. Our program will write a pattern into the framebuffer using a simple math equation. The oled.show() will then update the pattern on the display.

                                                                                                                                                                                                                                                                                                              This lesson was suggested by Parker Erickson.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#math-functions","title":"Math Functions","text":"

                                                                                                                                                                                                                                                                                                              We will use a few unusual functions to create repeating patterns:

                                                                                                                                                                                                                                                                                                              1. Modulo (%)
                                                                                                                                                                                                                                                                                                              2. Bitwise AND (&)

                                                                                                                                                                                                                                                                                                              The modulo function is written %. It returns the integer remainder after a division. So 7 % 3 is 1 and 7 % 4 is 3. The Power function of X to the Y power is written in python as pow(x,y). For example pow(7, 2) is seven squared = 49.

                                                                                                                                                                                                                                                                                                              The bitwise and is written as x & y

                                                                                                                                                                                                                                                                                                              for i in range(8):\n    13 & i\n
                                                                                                                                                                                                                                                                                                              Function Returns 13 & 0 0 13 & 1 1 13 & 2 0 13 & 3 1 13 & 4 4 13 & 5 5 13 & 6 4 13 & 7 5 13 & 8 8 13 & 9 9 13 & 10 8 13 & 11 9 13 & 12 12"},{"location":"displays/graph/15-oled-patterns/#some-sample-equations","title":"Some Sample Equations","text":"
                                                                                                                                                                                                                                                                                                              1. x & y
                                                                                                                                                                                                                                                                                                              2. x % y
                                                                                                                                                                                                                                                                                                              3. (x ^ y) % 9
                                                                                                                                                                                                                                                                                                              4. (x ^ y) % 5
                                                                                                                                                                                                                                                                                                              5. (x ^ y) % 17
                                                                                                                                                                                                                                                                                                              6. (x ^ y) % 33
                                                                                                                                                                                                                                                                                                              7. (x * y) & 64
                                                                                                                                                                                                                                                                                                              8. (x * y) & 24
                                                                                                                                                                                                                                                                                                              9. (x * y) & 47
                                                                                                                                                                                                                                                                                                              10. (x * 2) % y
                                                                                                                                                                                                                                                                                                              11. (x * 64) % y
                                                                                                                                                                                                                                                                                                              12. (x * 31) % y
                                                                                                                                                                                                                                                                                                              13. ((x-128) * 64) % (y-128)
                                                                                                                                                                                                                                                                                                              14. (x % y) % 4
                                                                                                                                                                                                                                                                                                              15. (y % x) % 20
                                                                                                                                                                                                                                                                                                              16. 40 % (x % y)

                                                                                                                                                                                                                                                                                                              Note there are other patterns that use the power pow(x,y) or Exponentiation ** function but I can't get these to work with Micropython.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#sample-code","title":"Sample Code","text":"

                                                                                                                                                                                                                                                                                                              This program evaluates the function x % (y+1) for each of the pixels on the screen. If the function returns a non-zero the pixel will be off. If the pixel is zero, the pixel will be on.

                                                                                                                                                                                                                                                                                                              draw-patterns-ssd1306-spi.py

                                                                                                                                                                                                                                                                                                              import machine\nimport ssd1306\n\nWIDTH = 128\nHEIGHT = 64\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\nCS = machine.Pin(1)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\noled.fill(0) # clear display\nfor x in range(WIDTH):\n    for y in range(HEIGHT):\n        if x % (y+1):\n           oled.pixel(x,y,0)\n        else:\n            oled.pixel(x,y,1)\noled.show()\n

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#adding-a-list-of-patterns","title":"Adding a List of Patterns","text":""},{"location":"displays/graph/15-oled-patterns/#the-eval-function","title":"The Eval Function","text":"

                                                                                                                                                                                                                                                                                                              The eval() function takes any string and passes it to the python interpreter for evaluation within the current context of variables that are in scope. We can use eval to pass an expression that should be evaluated to any function.

                                                                                                                                                                                                                                                                                                              list = [\"x+y\", \"x-y\", \"x*y\", \"x % (y+1)\"]\n\nfor i in range(0, 4):\n    print(list[i], ': ', sep='', end='')\n    for x in range(5):\n      for y in range(5):\n         print(eval(list[i]), '', end='')\n    print('')\n

                                                                                                                                                                                                                                                                                                              Output:

                                                                                                                                                                                                                                                                                                              x+y: 0 1 2 3 4 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 \nx-y: 0 -1 -2 -3 -4 1 0 -1 -2 -3 2 1 0 -1 -2 3 2 1 0 -1 4 3 2 1 0 \nx*y: 0 0 0 0 0 0 1 2 3 4 0 2 4 6 8 0 3 6 9 12 0 4 8 12 16 \nx % (y+1): 0 0 0 0 0 0 1 1 1 1 0 0 2 2 2 0 1 0 3 3 0 0 1 0 4 \n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#the-command-design-pattern","title":"The Command Design Pattern","text":"

                                                                                                                                                                                                                                                                                                              The command pattern holds a list of commands in an array. Each command is executed in the sequence it appears in the list of commands.

                                                                                                                                                                                                                                                                                                              In the following program we have the equations in a list. The program steps through each item in the list and displays that equation on the OLED display.

                                                                                                                                                                                                                                                                                                              import machine\nimport ssd1306\nfrom utime import sleep, time\n\nWIDTH = 128\nHEIGHT = 64\nspi_sck=machine.Pin(2)\nspi_tx=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)\nCS = machine.Pin(1)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\nequations = ['(x * y) & 24', '(x * y) & 47', '(x * y) & 64', 'x & y', 'x % y', '(x % y) % 4', '40 % (x % y+1)']\n\nfor eqn in range(0, len(equations)):\n    start = time()\n\n    oled.fill(0) # clear display\n    oled.text('calculating', 0, 0, 1)\n    oled.text(equations[eqn], 0, 10, 1)\n    oled.show()\n    for x in range(WIDTH):\n        for y in range(1, HEIGHT):\n            if eval(equations[eqn]):\n               oled.pixel(x,y,0)\n            else:\n                oled.pixel(x,y,1)\n    oled.show()\n    sleep(5)\n\n    end = time()\n    duration = str(end - start)\n    print(equations[eqn])\n    print(duration, ' seconds')\n\noled.text('done', 0, 0, 1)\noled.show()\nprint('done')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#sample-screen-images","title":"Sample Screen Images","text":""},{"location":"displays/graph/15-oled-patterns/#x-modulo-y","title":"X Modulo Y","text":"

                                                                                                                                                                                                                                                                                                              x % y

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#x-y-4","title":"(x % y) % 4","text":""},{"location":"displays/graph/15-oled-patterns/#sierpinsky-triangles-x-y","title":"Sierpinsky Triangles (x & y)","text":"

                                                                                                                                                                                                                                                                                                              Sierpinsky Triangles Bitwise and of x and y

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/15-oled-patterns/#x-y-24","title":"(x * y) & 24","text":""},{"location":"displays/graph/15-oled-patterns/#x-y-64","title":"(x * y) & 64","text":""},{"location":"displays/graph/15-oled-patterns/#40-x-y1","title":"40 % x % (y+1)","text":""},{"location":"displays/graph/15-oled-patterns/#reference","title":"Reference","text":"

                                                                                                                                                                                                                                                                                                              Martin Kleppe Post on Twitter

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/","title":"LI9341 TDF Display","text":"

                                                                                                                                                                                                                                                                                                              This is a 3.2\" $10 240X320 color display that is easy to set up on the Raspberry Pi Pico using the SPI interface. The hardware supports a touch screen and an SD card, but we could not locate drivers for these components.

                                                                                                                                                                                                                                                                                                              Sample $10 part on Amazon or ebay

                                                                                                                                                                                                                                                                                                              The TFT uses a 16-bit representation of the color of each pixel:

                                                                                                                                                                                                                                                                                                              1. 5-bits for red
                                                                                                                                                                                                                                                                                                              2. 6-bits for green
                                                                                                                                                                                                                                                                                                              3. 5-bits for blue

                                                                                                                                                                                                                                                                                                              This requires us to include the color565 library for doing color operations. So for example, to get the color yellow, you would need to do the following:

                                                                                                                                                                                                                                                                                                              yellow = color565(255, 255, 0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#sample-spi-hello-world-example","title":"Sample SPI Hello World Example","text":"
                                                                                                                                                                                                                                                                                                              # print out \"Hello World!\" using the rotation=3 using 32-bit high font\n# the default is white text on a black background\nfrom ili934x import ILI9341\nfrom machine import Pin, SPI\nimport tt32\n\n# Use these PIN definitions.  SCK must be on 2 and data (SDL) on 3\nSCK_PIN = 2\nMISO_PIN = 3 # labeled SDI(MOSI) on the back of the display\nDC_PIN = 4\nRESET_PIN = 5\nCS_PIN = 6\n\n# mosi=Pin(23)\n# miso=Pin(MISO_PIN)\nspi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))\ndisplay = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RESET_PIN), w=320, h=240, r=3)\ndisplay.erase()\ndisplay.set_font(tt32)\ndisplay.set_pos(0,0)\ndisplay.print('Hello World!')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#draw-random-rectangles","title":"Draw Random Rectangles","text":"
                                                                                                                                                                                                                                                                                                              from ili934x import ILI9341, color565\nfrom machine import Pin, SPI\nfrom utime import sleep\nfrom random import randint\n\nWIDTH = 320\nHALF_WIDTH = int(WIDTH/2)\nHEIGHT = 240\nHALF_HEIGHT = int(HEIGHT/2)\nROTATION = 3 # landscape with 0,0 in upper left and pins on left\n\nSCK_PIN = 2\nMISO_PIN = 3\nDC_PIN = 4\nRST_PIN = 5\nCS_PIN = 6\n\n# mosi=Pin(23)\n# miso=Pin(MISO_PIN)\nspi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN), sck=Pin(SCK_PIN))\ndisplay = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)\ndisplay.erase()\n\n# color defintions converted to 565 represnetations\nblack = color565(0, 0, 0)\nwhite = color565(255, 255, 255)\nred = color565(255, 0, 0)\ngreen = color565(0, 255, 0)\nblue = color565(0, 0, 255)\nyellow = color565(255, 255, 0)\ncyan = color565(0, 255, 255)\nmagenta = color565(255, 0, 255)\ngray = color565(128, 128, 128)\nlight_gray = color565(192, 192, 192)\ndark_gray = color565(64, 64, 64)\nbrown = color565(165, 42, 42)\norange = color565(255, 60, 0)\n# 150 for the green and blue wash out the colors\npink = color565(255, 130, 130)\npurple = color565(128, 0, 128)\nlavender = color565(150, 150, 200)\nbeige = color565(200, 200, 150)\n# by definition, maroon is 50% of the red on, but 128 is way too bright\nmaroon = color565(105, 0, 0)\nolive = color565(128, 128, 0)\nturquoise = color565(64, 224, 208)\ndark_green = color565(0,100,0)\ncolor_list = [white, red, green, blue, yellow, cyan, magenta,\n              gray, light_gray, dark_gray, brown, orange, pink, purple, lavender,\n              beige, maroon, olive, turquoise, dark_green, black]\ncolor_num = len(color_list)\n\n# Draw forever\nwhile True:\n    # rect_fill(x, y, width, height, color)\n    x = randint(0, HALF_WIDTH)\n    y = randint(0, HALF_HEIGHT)\n    width = randint(0, HALF_WIDTH)\n    height = randint(0, HALF_HEIGHT)\n    color = color_list[randint(0, color_num-1)]\n    print('fill_rectangle(', x, y, width, height, color)\n    display.fill_rectangle(x, y, width, height, color)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#draw-color-lists","title":"Draw Color Lists","text":"

                                                                                                                                                                                                                                                                                                              One of the best ways to study the color values is to display a rectangle and list the color name and values under the rectangle.

                                                                                                                                                                                                                                                                                                              Here is a sample program that will do this.

                                                                                                                                                                                                                                                                                                              from ili934x import ILI9341, color565\nfrom machine import Pin, SPI\nfrom utime import sleep\nfrom random import randint\nimport tt32\n\nWIDTH = 320\nHALF_WIDTH = int(WIDTH/2)\nHEIGHT = 240\nHALF_HEIGHT = int(HEIGHT/2)\nROTATION = 3 # landscape with 0,0 in upper left and pins on left\nSCK_PIN = 2\nMISO_PIN = 3\nDC_PIN = 4\nRST_PIN = 5\nCS_PIN = 6\n\n# mosi=Pin(23)\n# miso=Pin(MISO_PIN)\nspi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))\ndisplay = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)\ndisplay.set_font(tt32)\ndisplay.erase()\n\n# color defintions convered to 565 represnetations\nblack = color565(0, 0, 0)\nwhite = color565(255, 255, 255)\nred = color565(255, 0, 0)\ngreen = color565(0, 255, 0)\nblue = color565(0, 0, 255)\nyellow = color565(255, 255, 0)\ncyan = color565(0, 255, 255)\nmagenta = color565(255, 0, 255)\ngray = color565(128, 128, 128)\nlight_gray = color565(192, 192, 192)\ndark_gray = color565(64, 64, 64)\nbrown = color565(165, 42, 42)\norange = color565(255, 60, 0)\n# 150 for the green and blue wash out the colors\npink = color565(255, 130, 130)\npurple = color565(128, 0, 128)\nlavender = color565(150, 150, 200)\nbeige = color565(200, 200, 150)\n# by definition, maroon is 50% of the red on, but 128 is way too bright\nmaroon = color565(105, 0, 0)\nolive = color565(128, 128, 0)\nturquoise = color565(64, 224, 208)\ndark_green = color565(0,100,0)\ncolor_list = [white, red, green, blue, yellow, cyan, magenta,\n              gray, light_gray, dark_gray, brown, orange, pink, purple, lavender,\n              beige, maroon, olive, turquoise, dark_green, black]\ncolor_names = ['white (255,255,255)', 'red (255,0,0)', 'green (0,255,0)', 'blue (0,0,255)', 'yellow (255,255,0)',\n               'cyan (0,255,255)', 'magenta (255,0,255)',\n              'gray (128,128,128)', 'light gray (192,192,192)', 'dark gray (64,64,64)',\n               'brown (165,42,42)', 'orange (255,60,0)', 'pink (255,130,130)', 'purple (128,0,128)',\n               'lavender (150,150,200)',\n              'beige (200,200,150)', 'maroon (105,0,0)', 'olive (128,128,0)', 'turquoise (64,224,208)',\n               'dark green (0,100,0)', 'black (0,0,0)']\ncolor_num = len(color_list)\n\ndisplay.fill_rectangle(0, 0, WIDTH, HEIGHT, black)\nwhile True:\n    for i in range(0, color_num):\n        display.fill_rectangle(0, 0, WIDTH, HEIGHT-33, color_list[i])\n        # black behind the white text\n        display.fill_rectangle(0, HEIGHT-32, WIDTH, 32, black)\n\n        display.set_pos(0,HEIGHT-32)\n        display.print(color_names[i])\n        print(color_names[i])\n        sleep(1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#screen-update-speed","title":"Screen Update Speed","text":"

                                                                                                                                                                                                                                                                                                              One large disadvantage of this display is the very slow refresh rate. Transmitting the entire screen of 240X320 with two bytes per pixel takes a long time over SPI. This makes this setup difficult to use for animation.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#ball-bounce-animation","title":"Ball Bounce Animation","text":"

                                                                                                                                                                                                                                                                                                              Here is a very slow \"ball bounce\" animation that is slow and has a lot of flicker.

                                                                                                                                                                                                                                                                                                              from ili934x import ILI9341, color565\nfrom machine import Pin, SPI\nfrom utime import sleep\n\nWIDTH = 320\nHEIGHT = 240\nROTATION = 3 # landscape with 0,0 in upper left and pins on left\nSCK_PIN = 2\nMISO_PIN = 3\nDC_PIN = 4\nRST_PIN = 5\nCS_PIN = 6\n\n# mosi=Pin(23)\n# miso=Pin(MISO_PIN)\nspi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN))\ndisplay = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION)\ndisplay.erase()\n\n# color defintions convered to 565 represnetations\nblack = color565(0, 0, 0)\nwhite = color565(255, 255, 255)\nred = color565(255, 0, 0)\ngreen = color565(0, 255, 0)\nblue = color565(0, 0, 255)\n\n# ok, not really a circle - just a square for now\ndef draw_ball(x,y, size, color):\n    if size == 1:\n        display.pixel(x, y, color) # draw a single pixel\n    else:\n        display.fill_rectangle(x, y, size, size, color)\n\nball_size = 20\n# start in the middle of the screen\ncurrent_x = int(WIDTH / 2)\ncurrent_y = int(HEIGHT / 2)\n# start going down to the right\ndirection_x = 1\ndirection_y = -1\n# delay_time = .0001\n\n# Bounce forever\nwhile True:\n    # draw the square ball in white\n    draw_ball(current_x,current_y, ball_size, white)\n    sleep(.1)\n    # the erase the old ball takes too long and causes a flicker\n    draw_ball(current_x,current_y,ball_size, black)\n    if current_x < 0:\n        direction_x = 1\n    # right edge test\n    if current_x > WIDTH - ball_size -2:\n        direction_x = -1\n    # top edge test\n    if current_y < 0:\n        direction_y = 1\n    # bottom edge test\n    if current_y > HEIGHT - ball_size - 2:\n        direction_y = -1\n    # update the ball\n    current_x = current_x + direction_x\n    current_y = current_y + direction_y\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/16-tft-ili9341/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Jeffmer's GitHub library which includes four fonts - the sizes are 8, 14, 24 and 32 pixels.

                                                                                                                                                                                                                                                                                                              2. Amazon HiLetgo ILI9341 2.8\" SPI TFT LCD Display Touch Panel 240X320 with PCB 5V/3.3V STM32

                                                                                                                                                                                                                                                                                                              3. ebay Listing

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/17-ssd1352/","title":"OLED SSD1351 MicroPython Driver","text":"

                                                                                                                                                                                                                                                                                                              The SSD1351 is a $40 color OLED measures 1.5\" diagonal and contains 128x128 RGB pixels. It supports a SPI interface.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/17-ssd1352/#drawing-shapes","title":"Drawing Shapes","text":"

                                                                                                                                                                                                                                                                                                              This demo shows how to draw shapes on the display. It starts out with simple lines and rectangles then progresses to more complex shapes such as circles and ellipses.

                                                                                                                                                                                                                                                                                                              \"\"\"SSD1351 demo (shapes).\"\"\"\nfrom time import sleep\nfrom ssd1351 import Display, color565\nfrom machine import Pin, SPI\n\n\ndef test():\n    \"\"\"Test code.\"\"\"\n    # Baud rate of 14500000 seems about the max\n    spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))\n    print('spi started')\n    display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))\n    print('display started')\n\n    display.clear(color565(64, 0, 255))\n    sleep(1)\n\n    display.clear()\n\n    display.draw_hline(10, 127, 63, color565(255, 0, 255))\n    sleep(1)\n\n    display.draw_vline(10, 0, 127, color565(0, 255, 255))\n    sleep(1)\n\n    display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255))\n    sleep(1)\n\n    display.draw_hline(0, 0, 127, color565(255, 0, 0))\n    sleep(1)\n\n    display.draw_line(127, 0, 64, 127, color565(255, 255, 0))\n    sleep(2)\n\n    display.clear()\n\n    coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]]\n    display.draw_lines(coords, color565(0, 255, 255))\n    sleep(1)\n\n    display.clear()\n    display.fill_polygon(7, 63, 63, 50, color565(0, 255, 0))\n    sleep(1)\n\n    display.fill_rectangle(0, 0, 15, 127, color565(255, 0, 0))\n    sleep(1)\n\n    display.clear()\n\n    display.fill_rectangle(0, 0, 63, 63, color565(128, 128, 255))\n    sleep(1)\n\n    display.draw_rectangle(0, 64, 63, 63, color565(255, 0, 255))\n    sleep(1)\n\n    display.fill_rectangle(64, 0, 63, 63, color565(128, 0, 255))\n    sleep(1)\n\n    display.draw_polygon(3, 96, 96, 30, color565(0, 64, 255),\n                         rotate=15)\n    sleep(3)\n\n    display.clear()\n\n    display.fill_circle(32, 32, 30, color565(0, 255, 0))\n    sleep(1)\n\n    display.draw_circle(32, 96, 30, color565(0, 0, 255))\n    sleep(1)\n\n    display.fill_ellipse(96, 32, 30, 16, color565(255, 0, 0))\n    sleep(1)\n\n    display.draw_ellipse(96, 96, 16, 30, color565(255, 255, 0))\n\n    sleep(5)\n    display.cleanup()\n\n\ntest()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/17-ssd1352/#ssd1351-micropython-driver","title":"SSD1351 MicroPython Driver","text":"

                                                                                                                                                                                                                                                                                                              The driver is here RDagger GitHub

                                                                                                                                                                                                                                                                                                              SSD1351 MicroPython Driver on RDagger GitHub

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/17-ssd1352/#ssd1351-datasheet","title":"SSD1351 Datasheet","text":"

                                                                                                                                                                                                                                                                                                              Datasheet on NewHaven Displays

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/","title":"NeoPixel Matrix Display","text":""},{"location":"displays/graph/18-neopixel-matrix/#introduction","title":"Introduction","text":"

                                                                                                                                                                                                                                                                                                              This lesson uses MicroPython to control display that uses a 8X32 matrix of WS2812 RGB LEDs to display information. The entire display is controlled by three wires, a ground, +5V, and a serial data signal. We will use the MicroPython builtin NeoPixel library to control the display. You can use many of the programs in the NeoPixel Basics lesson to control the display. The key difference is that we will need to convert matrix coordinates to NeoPixel index numbers.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#purchasing-hardware","title":"Purchasing Hardware","text":"

                                                                                                                                                                                                                                                                                                              You can purchase a matrix of 8X32 WS2812 RGB LED on eBay for about $12 on eBay or about $100 on Adafruit. They are also available in 16X16 versions and the devices can be chained together to make larger displays. On our version tested here, we have a total of 8*32 = 256 pixels.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#basic-software-setup","title":"Basic Software Setup","text":"

                                                                                                                                                                                                                                                                                                              We must first create a function that will draw a pixel at a given x and y position. This is complicated by the fact that the matrix is not a regular grid, but rather a grid that is connected in a zig-zag serpentine pattern illustrated below.

                                                                                                                                                                                                                                                                                                              Note that the math for doing even and odd columns is different. The even columns are drawn from the top down and the odd columns are drawn from the bottom to the top which is the order the pixels are wired together in the matrix.

                                                                                                                                                                                                                                                                                                              To use the functions that draw pixels, we must first create a function that will convert the x and y coordinates to a NeoPixel index. This is done by the following function. We will then pass this function into the library that will draw characters on the screen.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom neopixel import NeoPixel\n\nNEOPIXEL_PIN = 0\nROWS = 8\nCOLS = 32\nNUMBER_PIXELS = ROWS * COLS\n# Allocate memory for the NeoPixel matrix\nmatrix = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\ndef write_pixel(x, y, value):\n    if y >= 0 and y < ROWS and x >=0 and x < COLS:\n        # odd count rows 1, 3, 5 the wire goes from bottup\n        if x % 2: \n            strip[(x+1)*ROWS - y - 1] = value             \n        else: # even count rows, 0, 2, 4 the wire goes from the top down up\n            strip[x*ROWS + y] = value\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#testing-your-write-pixel-function","title":"Testing Your Write Pixel Function","text":"

                                                                                                                                                                                                                                                                                                              We can then test the function by calling it at four corners with different colors.

                                                                                                                                                                                                                                                                                                              # draw four colors at each corner of the matrix\nwrite_pixel(0, 0, (255, 0, 0)) # draw a red pixel at the top left corner\nwrite_pixel(7, 0, (0, 255, 0)) # draw a green pixel at the lower left corner\nwrite_pixel(0, 7, (0, 0, 255)) # draw a blue pixel at the top right corner\nwrite_pixel(7, 7, (255, 255, 255)) # draw a white pixel at the lower right corner\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#bounce-a-ball","title":"Bounce a Ball","text":"

                                                                                                                                                                                                                                                                                                              To test the write_pixel() function, lets write a function that will draw a ball at a given x and y position. We will move the ball around the screen and reverse the direction when the ball hits the edge of the screen.

                                                                                                                                                                                                                                                                                                              # Bounce a ball around a NeoPixel Matrix\nfrom neopixel import NeoPixel\nfrom utime import sleep\n\nNEOPIXEL_PIN = 0\nROWS = 8\nCOLS = 32\nNUMBER_PIXELS = ROWS * COLS\nstrip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\n# matrix = [[0 for _ in range(cols)] for _ in range(rows)]\ndef clear():\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] = (0,0,0)\n    strip.write()\n\ndef write_pixel(x, y, value):\n    if y >= 0 and y < ROWS and x >=0 and x < COLS:\n        # odd count rows 1, 3, 5 the wire goes from bottup\n        if x % 2: \n            strip[(x+1)*ROWS - y - 1] = value             \n        else: # even count rows, 0, 2, 4 the wire goes from the top down up\n            strip[x*ROWS + y] = value\n\ndef show():\n    strip.write()\n\nbrightness=1\nx=0\ny=0\ndx = 1\ndy = 1\ncounter = 0\nwhile True:\n    if x <= 0:\n        dx = 1\n    if y <= 0:\n        dy = 1\n    if x >= COLS-1:\n        dx = -1\n    if y >= ROWS-1:\n        dy = -1\n    print(x,y)\n    if counter < 100:\n        write_pixel(x, y, (brightness,0,0)) # blue\n    elif counter < 200:\n        write_pixel(x, y, (0,brightness,0)) # blue\n    elif counter < 300:\n        write_pixel(x, y, (0,0,brightness)) # blue\n    show()\n    x += dx\n    y += dy\n    counter += 1\n    if counter > 300:\n        counter = 0\n    if not counter % 150:\n        x += 1\n    sleep(.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#bitmap-library","title":"Bitmap LIbrary","text":"
                                                                                                                                                                                                                                                                                                              # MicroPython basic bitmap font renderer.\n# Author: Tony DiCola\n# License: MIT License (https://opensource.org/licenses/MIT)\ntry:\n    import ustruct\nexcept ImportError:\n    import struct as ustruct\n\n\nclass BitmapFont:\n\n    def __init__(self, width, height, pixel, font_name='font5x8.bin'):\n        # Specify the drawing area width and height, and the pixel function to\n        # call when drawing pixels (should take an x and y param at least).\n        # Optionally specify font_name to override the font file to use (default\n        # is font5x8.bin).  The font format is a binary file with the following\n        # format:\n        # - 1 unsigned byte: font character width in pixels\n        # - 1 unsigned byte: font character height in pixels\n        # - x bytes: font data, in ASCII order covering all 255 characters.\n        #            Each character should have a byte for each pixel column of\n        #            data (i.e. a 5x8 font has 5 bytes per character).\n        self._width = width\n        self._height = height\n        self._pixel = pixel\n        self._font_name = font_name\n\n    def init(self):\n        # Open the font file and grab the character width and height values.\n        # Note that only fonts up to 8 pixels tall are currently supported.\n        self._font = open(self._font_name, 'rb')\n        self._font_width, self._font_height = ustruct.unpack('BB', self._font.read(2))\n\n    def deinit(self):\n        # Close the font file as cleanup.\n        self._font.close()\n\n    def __enter__(self):\n        self.init()\n        return self\n\n    def __exit__(self, exception_type, exception_value, traceback):\n        self.deinit()\n\n    def draw_char(self, ch, x, y, *args, **kwargs):\n        # Don't draw the character if it will be clipped off the visible area.\n        if x < -self._font_width or x >= self._width or \\\n           y < -self._font_height or y >= self._height:\n            return\n        # Go through each column of the character.\n        for char_x in range(self._font_width):\n            # Grab the byte for the current column of font data.\n            self._font.seek(2 + (ord(ch) * self._font_width) + char_x)\n            line = ustruct.unpack('B', self._font.read(1))[0]\n            # Go through each row in the column byte.\n            for char_y in range(self._font_height):\n                # Draw a pixel for each bit that's flipped on.\n                if (line >> char_y) & 0x1:\n                    self._pixel(x + char_x, y + char_y, *args, **kwargs)\n\n    def text(self, text, x, y, *args, **kwargs):\n        # Draw the specified text at the specified location.\n        for i in range(len(text)):\n            self.draw_char(text[i], x + (i * (self._font_width + 1)), y,\n                           *args, **kwargs)\n\n    def width(self, text):\n        # Return the pixel width of the specified text message.\n        return len(text) * (self._font_width + 1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#full-code","title":"Full Code","text":"
                                                                                                                                                                                                                                                                                                              # LED Matrix message scroller demo.\n\nimport bitmapfont\nimport machine\nimport utime\nfrom neopixel import NeoPixel\n\nNEOPIXEL_PIN = 0\nROWS = 8\nCOLS = 32\nNUMBER_PIXELS = ROWS * COLS\nmatrix = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\ndef fill(val):\n    for i in range(0, NUMBER_PIXELS):\n        matrix[i] = val\n\n# Configuration:\nDISPLAY_WIDTH  = 32      # Display width in pixels.\nDISPLAY_HEIGHT = 8       # Display height in pixels.\nSPEED          = 20.0    # Scroll speed in pixels per second.\n\ndef show():\n    matrix.write()\n\ndef write_pixel_value(x, y, value):\n    if y >= 0 and y < ROWS and x >=0 and x < COLS:\n        # odd count rows 1, 3, 5 the wire goes from bottup\n        if x % 2: \n            matrix[(x+1)*ROWS - y - 1] = value             \n        else: # even count rows, 0, 2, 4 the wire goes from the top down up\n            matrix[x*ROWS + y] = value\n\ndef write_pixel(x, y):\n    write_pixel_value(x, y, (1,1,2))\n\ndef scroll_text(message):\n\n    with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, write_pixel) as bf:\n        # Global state:\n        pos = DISPLAY_WIDTH                 # X position of the message start.\n        message_width = bf.width(message)   # Message width in pixels.\n        last = utime.ticks_ms()             # Last frame millisecond tick time.\n        speed_ms = SPEED / 1000.0           # Scroll speed in pixels/ms.\n        # Main loop:\n        while True:\n            # Compute the time delta in milliseconds since the last frame.\n            current = utime.ticks_ms()\n            delta_ms = utime.ticks_diff(current, last)\n            last = current\n            # Compute position using speed and time delta.\n            pos -= speed_ms*delta_ms\n            if pos < -message_width:\n                pos = DISPLAY_WIDTH\n            # Clear the matrix and draw the text at the current position.\n            fill((0,0,0))\n            bf.text(message, int(pos), 0)\n            # Update the matrix LEDs.\n            show()\n            # Sleep a bit to give USB mass storage some processing time (quirk\n            # of SAMD21 firmware right now).\n            utime.sleep_ms(20)\n\nwrite_pixel(0,0)\nshow()\n#scroll_text('Dan Loves Ann!')\nscroll_text('MicroPython Rocks')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/18-neopixel-matrix/#references","title":"References","text":""},{"location":"displays/graph/19-wiring-harness/","title":"Display Wiring Harness","text":"

                                                                                                                                                                                                                                                                                                              Unlike simple sensors that only have a few wires, displays have up to seven wires that need to be connected. This can be tricky when we use breadboards where we can accidentally pull one wire out.

                                                                                                                                                                                                                                                                                                              To keep our displays running reliably, we can use a 20 cm ribbon cable and some hot glue to make a connector that is easy to hook up. It will be very reliable.

                                                                                                                                                                                                                                                                                                              We start by purchasing some 20 cm long Male-Female Dupont ribbon connectors from eBay. The price should be about $8 for 120 connectors. Make sure to get the Male-Female version.

                                                                                                                                                                                                                                                                                                              We then will separate 7 of these wires making sure to put the black and red colors in the GND and VCC edge of the group of wires.

                                                                                                                                                                                                                                                                                                              You can see a close-up of each of the colors and their connections in the picture below.

                                                                                                                                                                                                                                                                                                              At the other end of the cable, we need to make a small change in the order of the cable. Here are the changes:

                                                                                                                                                                                                                                                                                                              1. We separate the red wire from the rest of the group and connect the red to the 3.3V regulated output of the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              2. We move the back GND wire two be in between the blue and purple CS and DC wires. This allows the row of all the wires to be connected in a single block of wires.

                                                                                                                                                                                                                                                                                                              We can then plug this group of wires directly into the breadboard from breadboard rows 3 to 9. This is shown below.

                                                                                                                                                                                                                                                                                                              We designed these connections with the following rules:

                                                                                                                                                                                                                                                                                                              1. The Clock (SCL) and Data (SDA) MUST be connected to rows 4 and 5 respectively because this is where SPI0 CLK and SPI0 TX are located.
                                                                                                                                                                                                                                                                                                              2. The other three signals RES, DC and CS can be on pin so we will use the rows that make the cable connectors direct to rows 6, 7 and 9. Note that GND is on breadboard row 8.

                                                                                                                                                                                                                                                                                                              We have found that once we create these cable assemblies with hot glue to keep the pins in the right order it makes it much easier to connect the displays.

                                                                                                                                                                                                                                                                                                              Warning

                                                                                                                                                                                                                                                                                                              Note that we still MUST make sure that the black wire in the wiring harness is connected to the GND. It is easy to get the cable reversed so make sure to double-check the cable orientation before you use it.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/19-wiring-harness/#cable-wiring-diagram","title":"Cable Wiring Diagram","text":"

                                                                                                                                                                                                                                                                                                              Here is the detailed wiring diagram showing the wires as they route from the back of the OLED display to the pins on the breadboard:

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/19-wiring-harness/#sample-python-code","title":"Sample Python Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\n\n# Customize these GPIO numbers for your layout\n# Note these are not breadboard row numbers\n# The breadboard row numbers are 4,5,6,7 and 9 with GND on row 8\nSCL_PIN = 2\nSDA_PIN = 3\nRES_PIN = 4\nDC_PIN = 5\nCS_PIN = 6\n\n# create the Pin objects\nscl=Pin(SCL_PIN)\nsda=Pin(SDA_PIN)\nres=Pin(RES_PIN)\ndc=Pin(DC_PIN)\ncs = Pin(CS_PIN)\n\nspi=machine.SPI(0, sck=scl, mosi=sda)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/19-wiring-harness/#building-a-harness-for-the-cytron-maker-pi-rp2040-board","title":"Building A Harness for the Cytron Maker Pi RP2040 Board","text":"

                                                                                                                                                                                                                                                                                                              We can also make a display harness for the Cytron Maker Pi RP2040 Board. To do this we will need to use three grove connectors. We use all four wires of the first Grove connector, two of the data signals on the second and just a single wire on the third Grove connector. This connector is shown below.

                                                                                                                                                                                                                                                                                                              The MicroPython code for this harness is the following:

                                                                                                                                                                                                                                                                                                              from machine import Pin\n\n# Customize these GPIO pin numbers for your layout\nSCL_PIN = 2\nSDA_PIN = 3\nRES_PIN = 4\nDC_PIN = 5\nCS_PIN = 16\n\n# create the Pin objects\nscl=Pin(SCL_PIN)\nsda=Pin(SDA_PIN)\nres=Pin(RES_PIN)\ndc=Pin(DC_PIN)\ncs = Pin(CS_PIN)\n\nspi=machine.SPI(0, sck=scl, mosi=sda)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, dc, res, cs)\n

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              This code is exactly the same as the Pico version above with the exception of the CS_PIN which was on GPIO 6 but we now moved it to GPIO 16.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/20-seven-segments/","title":"Drawing a Seven Segment Display","text":"

                                                                                                                                                                                                                                                                                                              https://en.wikipedia.org/wiki/Seven-segment_display

                                                                                                                                                                                                                                                                                                              Wikipedia Seven Segment Display

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/graph/40-oled-references/","title":"OLED References","text":"
                                                                                                                                                                                                                                                                                                              1. Analysis of OLED drawing performance using SPI interface
                                                                                                                                                                                                                                                                                                              2. Analysis of OLED drawing performance using SPI interface
                                                                                                                                                                                                                                                                                                              3. Example of displaying a complex animation on an OLED with SPI
                                                                                                                                                                                                                                                                                                              4. Video of the Above on YouTube
                                                                                                                                                                                                                                                                                                              5. Peter Hinch's MicroPython Nano GUI
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/01-intro/","title":"Using Non-Graphic Displays with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              In this section cover small non-graphical displays such as LED bar displays, LCD character displays and other displays that don't require a drawing library and support for framebuffers. There is a separate section for graphical displays.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/02-led-button/","title":"LED Buttons Lab","text":"

                                                                                                                                                                                                                                                                                                              LED Button

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/","title":"Ten Bar LED Display","text":""},{"location":"displays/non-graph/03-10-bar-leds/#goals-for-the-lesson","title":"Goals for the Lesson","text":"

                                                                                                                                                                                                                                                                                                              These LED displays can be purchased on eBay for around 40 cents each in quantity 10. These displays are ideal for showing a reading such as a battery charge or a signal strength.

                                                                                                                                                                                                                                                                                                              Our goal is to learn how to use python lists to turn on and off a row of 10 LEDs.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#circuit","title":"Circuit","text":"

                                                                                                                                                                                                                                                                                                              The LEDs come in a dual-in-line package with each of the LEDs connected by the pins aligned across the package.

                                                                                                                                                                                                                                                                                                              In the circuit below, I connected the positive (anode) of each LED to a GPIO pin and the negative (cathode) through a 330-ohm resistor to the GND rail of the solderless breadboard.

                                                                                                                                                                                                                                                                                                              Note! You MUST use a current limiting resistor or you will burn out the LED.

                                                                                                                                                                                                                                                                                                              One end of each of the bars will go to one of the power rails and the other to a GIPO pin. I used the pis on the lower part of the Raspberry Pi Pico for this demo.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#programming","title":"Programming","text":"

                                                                                                                                                                                                                                                                                                              We will create a list that has each of the GPIO pins for output.

                                                                                                                                                                                                                                                                                                              pin_ids = [12,13,14,15,20,19,18,17,16]\n

                                                                                                                                                                                                                                                                                                              For each pin on this list, we will create a new list that contains the pin object that we can turn on or off.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\n\npin_ids = [12,13,14,15,20,19,18,17,16]\npins = []\npin_ids\nfor i in pin_ids:\n    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))\n

                                                                                                                                                                                                                                                                                                              We will use this same preamble code in all our examples.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#code-to-blink-all-10-leds","title":"Code to Blink all 10 LEDs","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\n\npin_ids = [12,13,14,15,20,19,18,17,16]\npins = []\npin_ids\nfor i in pin_ids:\n    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))\n\ndelay = .5\nwhile True:\n    # turn all the pins on\n    for pin in pins:\n        pins.on()\n    sleep(delay) # wait\n    # turn all the pins off\n    for pin in pins:\n        pins[i].off()\n    sleep(delay)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#sample-running-lights-example","title":"Sample Running Lights Example","text":"

                                                                                                                                                                                                                                                                                                              The \"running lights\" pattern gives the impression that there is a red object that is moving up and down a row. We do this by successively turning on adjacently LEDs and then turning them off. This give the illusion of motion.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\n\npin_ids = [12,13,14,15,20,19,18,17,16]\npins = []\n\nfor i in range(0, 9):\n    pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT))\n\ndelay = .1\nwhile True:\n    for i in range(0, 9):\n        pins[i].on()\n        sleep(delay)\n        pins[i].off()\n    for i in range(8, 1, -1):\n        pins[i].on()\n        sleep(delay)\n        pins[i].off()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#swipe","title":"swipe","text":"

                                                                                                                                                                                                                                                                                                              The swipe pattern turns each LED on but keeps it on until the direction is reversed.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/03-10-bar-leds/#adding-a-binary-counter-patterns","title":"Adding a Binary Counter Patterns","text":"

                                                                                                                                                                                                                                                                                                              We can also create another patten that will demonstrate binary counting. In this pattern, the least significant bit flickers on and off. For each cycle the adjacent pixel toggles once. The happens for each adjacent pixel. The most significant bit will only change every 1024 cycles of the least significant bit.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/04-8x8-led-matrix/","title":"MAX7219 8x8 LED Matrix","text":"

                                                                                                                                                                                                                                                                                                              This is a low-cost ($3) and easy-to-program device that is perfect for small projects that don't need a full graphical display. You will be surprised at how creative our students are with just an 8x8 display!

                                                                                                                                                                                                                                                                                                              eBay Search for \"MAX7219 8x8 matrix\"

                                                                                                                                                                                                                                                                                                              The device comes with five connectors:

                                                                                                                                                                                                                                                                                                              1. Power (VCC)
                                                                                                                                                                                                                                                                                                              2. Ground (GND)
                                                                                                                                                                                                                                                                                                              3. Clock (SCK)
                                                                                                                                                                                                                                                                                                              4. Data (MOSI)
                                                                                                                                                                                                                                                                                                              5. Chip Select (CS)

                                                                                                                                                                                                                                                                                                              We can communicate with the device using the standard SPI interface. There is also an 8x8 driver supplied by Mike Causer Here is an excerpt of how we configured the driver to use a single display:

                                                                                                                                                                                                                                                                                                              from machine import SPI, Pin\nimport max7219\nfrom utime import sleep\nCLOCK_PIN = 2\nDATA_PIN = 3\nCS_PIN = 4\nspi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN))\ncs = Pin(CS_PIN, Pin.OUT)\nmatrix = max7219.Matrix8x8(spi0, cs , 1)\n# display text a x=0, y=0 and state = 1 (on)\nmatrix.text('1234', 0, 0, 1)\nmatrix.show()\n

                                                                                                                                                                                                                                                                                                              You can change the last parameter from \"1\" to \"4\" if you have 4 displays wired together:

                                                                                                                                                                                                                                                                                                              import max7219\nfrom machine import Pin, SPI\nspi = SPI(1)\nmatrix = max7219.Matrix8x8(spi0, cs , 4)\ndisplay.text('1234',0,0,1)\ndisplay.show()\n

                                                                                                                                                                                                                                                                                                              The displays can also be \"cascaded\"

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/04-8x8-led-matrix/#basic-program","title":"Basic Program","text":"
                                                                                                                                                                                                                                                                                                              from machine import SPI, Pin\nimport max7219\nfrom utime import sleep\nCLOCK_PIN = 2\nDATA_PIN = 3\nCS_PIN = 4\nspi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN))\n\ncs = Pin(CS_PIN, Pin.OUT)\n\nmatrix = max7219.Matrix8x8(spi0, cs , 1)\n\nmatrix.text('A', 0, 0, 1)\nmatrix.show()\nsleep(delay_time)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/04-8x8-led-matrix/#full-demo","title":"Full Demo","text":"
                                                                                                                                                                                                                                                                                                              from machine import SPI, Pin\nimport max7219\nfrom utime import sleep\nspi0=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))\n\ncs = Pin(4, Pin.OUT)\n\nmatrix = max7219.Matrix8x8(spi0, cs , 1)\n\ndelay_time = 1\nwhile True:\n    # Draw a single character\n\n    matrix.text('A', 0, 0, 1)\n    matrix.show()\n    sleep(delay_time)\n\n    # Draw an X in a box\n    matrix.fill(0)\n    matrix.line(0, 0, 7, 7, 1)\n    matrix.show()\n    sleep(delay_time)\n\n    matrix.line(7, 0, 0, 7, 1)\n    matrix.show()\n    sleep(delay_time)\n\n    matrix.rect(0, 0, 8, 8, 1)\n    matrix.show()\n    sleep(delay_time)\n    matrix.fill(0)\n\n    # Smile Face\n    matrix.pixel(1, 1, 1)\n    matrix.pixel(6, 1, 1)\n    matrix.pixel(0, 4, 1)\n    matrix.pixel(7, 4, 1)\n    matrix.pixel(1, 5, 1)\n    matrix.pixel(6, 5, 1)\n    matrix.pixel(2, 6, 1)\n    matrix.pixel(5, 6, 1)\n    matrix.pixel(3, 7, 1)\n    matrix.pixel(4, 7, 1)\n    matrix.show()\n    sleep(delay_time)\n    matrix.fill(0)\n    matrix.show()\n    sleep(delay_time)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/05-4-digit/","title":"Four Digit LED Display","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will use a 4-digit LED display to create a clock that displays the time of day. These clocks will use Mike Causer's tm1637 library to communicate with the four-digit display. Some of these displays also have a \"colon\" between the hour and minute digits that flashes every second.

                                                                                                                                                                                                                                                                                                              You can purchase 4-digit LED displays on eBay for about $2 each.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/05-4-digit/#connections","title":"Connections","text":"

                                                                                                                                                                                                                                                                                                              These displays have four pins:

                                                                                                                                                                                                                                                                                                              1. Ground (GND)
                                                                                                                                                                                                                                                                                                              2. Power (3.2 v or 5 v)
                                                                                                                                                                                                                                                                                                              3. Data (DIO)
                                                                                                                                                                                                                                                                                                              4. Clock (CLK)

                                                                                                                                                                                                                                                                                                              In our examples, we will connect the power to our 3.3 regulated output of the Pico. We will connect Data to GP0 and Clock to GP1.

                                                                                                                                                                                                                                                                                                              The following example

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\nimport tm1637\n\n# data and clock pins\nDIO_PIN = 0\nCLK_PIN = 1\n\ntm = tm1637.TM1637(clk=Pin(CLK_PIN), dio=Pin(DIO_PIN))\n\n# display \"1234\"\ntm.write([1, 2, 3, 4])\n

                                                                                                                                                                                                                                                                                                              The tm.write() function takes a sequence of numbers and will shifts them in from right to left.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/05-4-digit/#clock","title":"Clock","text":"

                                                                                                                                                                                                                                                                                                              We can create a simple clock by using the localtime() function when the programs first starts up and then we just update the time after the sleep() functions run for a second. This also can updates the colon between the hours and minutes.

                                                                                                                                                                                                                                                                                                              localtime() returns an array of numbers for date, hour, minute and second. In our example here, we only need the hour and minutes.

                                                                                                                                                                                                                                                                                                              # a simple clock that only grabs the time from the server on startup\nimport tm1637\nfrom machine import Pin\nfrom utime import sleep, localtime\n\ntm = tm1637.TM1637(clk=Pin(1), dio=Pin(0))\n\nnow = localtime()\nhour = now[3]\n# use AM/PM 12 hour time\nif hour > 12:\n    hour = hour - 12\nminute = now[4]\nsec = now[5]\nprint(hour, ':', minute, ' ', sec, sep='')\n\n# update from the first time\nwhile True:\n    # turn the colon on\n    tm.numbers(hour,minute,colon=True)\n    sleep(0.5)\n    # turn the colon off\n    tm.numbers(hour,minute,colon=False)\n    sleep(0.5)\n    sec = sec + 1\n    if sec == 60:\n        minute = minute + 1\n        sec = 0\n        if minute == 60:\n            hour = hour + 1\n            minute = 0\n            if hour == 24:\n                hour = 0\n

                                                                                                                                                                                                                                                                                                              A more accurate version will access the new time from the server every minute.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/05-4-digit/#accurate-clock","title":"Accurate Clock","text":"
                                                                                                                                                                                                                                                                                                              # a more accurate clock that only grabs the time from the server once per minute\nimport tm1637\nfrom machine import Pin\nfrom utime import sleep, localtime\n\nhour = 0\nminute = 0\nsec = 0\n\ndef update_time():\n    global hour, minute, second\n    now = localtime()\n    hour = now[3]\n    # use AM/PM\n    if hour > 12:\n        hour = hour - 12\n    minute = now[4]\n    sec = now[5]\n\ntm = tm1637.TM1637(clk=Pin(1), dio=Pin(0))\n\nupdate_time()\n# loop every second\nwhile True:\n    tm.numbers(hour,minute,colon=True)\n    sleep(0.5)\n    tm.numbers(hour,minute,colon=False)\n    sleep(0.5)\n    sec = sec + 1\n    if sec == 60:\n        # get the new time from the host\n        update_time()\n        print(hour, ':', minute, ' ', sec, sep='')\n        minute = minute + 1\n        sec = 0\n        if minute == 60:\n            hour = hour + 1\n            minute = 0\n            if hour == 24:\n                hour = 0\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/05-4-digit/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Nerd Cave YouTube Tutorial
                                                                                                                                                                                                                                                                                                              • Mike Causer's GitHub Repo with TM-1637 driver
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/","title":"Character LCD Display","text":"

                                                                                                                                                                                                                                                                                                              This lesson is for using the LCM1602 I2C LCD interface. It is a popular It has four wires:

                                                                                                                                                                                                                                                                                                              1. GND - connect to any GND pin
                                                                                                                                                                                                                                                                                                              2. VCC - connect to 3V3(out) pin unless you have a 3.3 to 5v voltage converter
                                                                                                                                                                                                                                                                                                              3. SDA - connect to GP0
                                                                                                                                                                                                                                                                                                              4. SCL - connect to GP1

                                                                                                                                                                                                                                                                                                              The photo above shows the use of a 3.3 to 5v voltage converter. This allows us to use the full 5v to the LCD backlight so we get bright contrast. You can connect the VCC to the 3V3(out) pin but the display will be harder to read.

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/#i2c-address-scanner-test","title":"I2C Address Scanner Test","text":"

                                                                                                                                                                                                                                                                                                              Our first task is to make sure that the 1602 chip's I2C circuits are working. We use the following I2C scanner code to do this.

                                                                                                                                                                                                                                                                                                              import machine\nI2C_SDA_PIN = 0\nI2C_SCL_PIN = 1\ni2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)\n\nprint('Scanning I2C bus.')\ndevices = i2c.scan() # this returns a list of devices\ndevice_count = len(devices)\nif device_count == 0:\n    print('No i2c device found.')\nelse:\n    print(device_count, 'devices found.')\nfor device in devices:\n    print('Decimal address:', device, \", Hex address: \", hex(device))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/#scanner-result","title":"Scanner Result","text":"
                                                                                                                                                                                                                                                                                                              Scanning I2C bus.\n1 devices found.\nDecimal address: 39 , Hex address:  0x27\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/#testing-the-lcd","title":"Testing the LCD","text":"
                                                                                                                                                                                                                                                                                                              from machine import I2C\nfrom lcd_api import LcdApi\nfrom pico_i2c_lcd import I2cLcd\n\nI2C_ADDR     = 0x27\nI2C_NUM_ROWS = 2\nI2C_NUM_COLS = 16\n\ni2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)\nlcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)    \nlcd.putstr(\"CoderDojo Rocks!\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/#putting-the-device-through-display-option-tests","title":"Putting the Device Through Display Option Tests","text":"

                                                                                                                                                                                                                                                                                                              Now that we know how to display text on the device, we can learn how other functions work:

                                                                                                                                                                                                                                                                                                              1. lcd.move_to(x,y)
                                                                                                                                                                                                                                                                                                              2. lcd.display_on() and lcd.display_off()
                                                                                                                                                                                                                                                                                                              3. lcd.show_cursor() and lcd.hide_cursor()
                                                                                                                                                                                                                                                                                                              4. lcd.blink_cursor_on() and lcd.blink_cursor_off()
                                                                                                                                                                                                                                                                                                              5. lcd.backlight_on() and lcd.backlight_off()
                                                                                                                                                                                                                                                                                                              6. lcd.clear()
                                                                                                                                                                                                                                                                                                              import utime\n\nimport machine\nfrom machine import I2C\nfrom lcd_api import LcdApi\nfrom pico_i2c_lcd import I2cLcd\n\nI2C_ADDR     = 0x27\nI2C_NUM_ROWS = 2\nI2C_NUM_COLS = 16\n\ndef test_main():\n    #Test function for verifying basic functionality\n    print(\"Running test_main\")\n    i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)\n    lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)    \n    lcd.putstr(\"CoderDojo Rocks!\")\n    utime.sleep(10)\n    lcd.clear()\n    count = 0\n    while True:\n        lcd.clear()\n        time = utime.localtime()\n        lcd.putstr(\"{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}\".format(\n            year=time[0], month=time[1], day=time[2],\n            HH=time[3], MM=time[4], SS=time[5]))\n        if count % 10 == 0:\n            print(\"Turning cursor on\")\n            lcd.show_cursor()\n        if count % 10 == 1:\n            print(\"Turning cursor off\")\n            lcd.hide_cursor()\n        if count % 10 == 2:\n            print(\"Turning blink cursor on\")\n            lcd.blink_cursor_on()\n        if count % 10 == 3:\n            print(\"Turning blink cursor off\")\n            lcd.blink_cursor_off()                    \n        if count % 10 == 4:\n            print(\"Turning backlight off\")\n            lcd.backlight_off()\n        if count % 10 == 5:\n            print(\"Turning backlight on\")\n            lcd.backlight_on()\n        if count % 10 == 6:\n            print(\"Turning display off\")\n            lcd.display_off()\n        if count % 10 == 7:\n            print(\"Turning display on\")\n            lcd.display_on()\n        if count % 10 == 8:\n            print(\"Filling display\")\n            lcd.clear()\n            string = \"\"\n            for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS):\n                string += chr(x)\n            lcd.putstr(string)\n        count += 1\n        utime.sleep(2)\n\n#if __name__ == \"__main__\":\ntest_main()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/10-character-lcd-display/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              MFitzp article on OLED displays

                                                                                                                                                                                                                                                                                                              Adafruit SSD1306 Driver

                                                                                                                                                                                                                                                                                                              Adafruit LCD Guide

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/seven-segment/","title":"Sample Seven Segment Display Lab","text":""},{"location":"displays/non-graph/seven-segment/#4-digit-seven-segment-display","title":"4 Digit Seven Segment Display","text":"

                                                                                                                                                                                                                                                                                                              Make sure to put a current limiting resistor in series with each LED. A 330 ohm resistor is a generally safe value for 5 volt circuits and you can use a 220 ohm resistor for 3.3 volt circuits.

                                                                                                                                                                                                                                                                                                              This code was provided by Jaison Miller from his GitHub Repo.

                                                                                                                                                                                                                                                                                                              ```py from machine import Pin, PWM, Timer import utime

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/seven-segment/#constants-where-the-pins-are-currently-plugged-into-etc","title":"Constants - where the pins are currently plugged into, etc.","text":"

                                                                                                                                                                                                                                                                                                              number_bitmaps = { 0: 0b00111111, 1: 0b00000110, 2: 0b01011011, 3: 0b01001111, 4: 0b01100110, 5: 0b01101101, 6: 0b01111101, 7: 0b00000111, 8: 0b01111111, 9: 0b01100111 } segment_masks = { 'a': 0b00000001, 'b': 0b00000010, 'c': 0b00000100, 'd': 0b00001000, 'e': 0b00010000, 'f': 0b00100000, 'g': 0b01000000 } pin_segments = { 'a': 10, 'b': 11, 'c': 12, 'd': 17, 'e': 16, 'f': 13, 'g': 14} pin_others = { 'decimal': 22, 'colon': 6, 'dash': 8 } pin_digits = { 1: 18, 2: 19, 3: 20, 4: 21 } pin_control_others = { 'colon': 27, 'dash': 7 }

                                                                                                                                                                                                                                                                                                              "},{"location":"displays/non-graph/seven-segment/#initial-setup-of-the-pins-alternatives-include-using-pwm-to-set-the-brightness","title":"initial setup of the pins, alternatives include using PWM to set the brightness","text":""},{"location":"displays/non-graph/seven-segment/#if-not-using-pwm-then-make-sure-to-use-appropriate-resistors-to-avoid-blowing-the-leds-in-the-display-like-i-have","title":"if not using PWM then make sure to use appropriate resistors to avoid blowing the LEDs in the display (like I have)","text":"

                                                                                                                                                                                                                                                                                                              segment_maps = {}

                                                                                                                                                                                                                                                                                                              for segment, pin in pin_segments.items(): segment_maps[segment] = Pin(pin, Pin.OUT)

                                                                                                                                                                                                                                                                                                              other_pin_maps = {}

                                                                                                                                                                                                                                                                                                              for feature, pin in pin_others.items(): other_pin_maps[feature] = Pin(pin, Pin.OUT)

                                                                                                                                                                                                                                                                                                              digit_maps = {}

                                                                                                                                                                                                                                                                                                              for digit, pin in pin_digits.items(): digit_maps[digit] = Pin(pin, Pin.OUT)

                                                                                                                                                                                                                                                                                                              other_maps = {}

                                                                                                                                                                                                                                                                                                              for feature, pin in pin_control_others.items(): other_maps[feature] = Pin(pin, Pin.OUT)

                                                                                                                                                                                                                                                                                                              def render_digit_display(show_digit=1, number=8, decimal=False):

                                                                                                                                                                                                                                                                                                              # turn everything off\nfor segment, mask in segment_masks.items():\n    segment_maps[segment].value(1)\n\nother_pin_maps['decimal'].value(1)\n\n# turn on the digit required to be displayed\nfor digit, digit_pin in digit_maps.items():\n    if show_digit == digit:\n        digit_pin.value(1)\n        # print(\"\\n\\nDigit: {} - Pin: {} - Number: {}\\n\".format(digit, pin, number))\n    else:\n        digit_pin.value(0)\n\nutime.sleep(0.001)\n\ndisplay_number_bitmap = number_bitmaps[number]\n\n# check every\nfor segment, mask in segment_masks.items():\n    # print(\"segment: {}\\nmask: {}\".format(segment, mask))\n\n    if display_number_bitmap & mask == mask:\n        # print(\"segment OFF: {}\".format(segment))\n        segment_maps[segment].value(0)\n    else:\n        segment_maps[segment].value(1)\n\n# show decimal\nif decimal:\n    other_pin_maps['decimal'].value(0)\nelse:\n    other_pin_maps['decimal'].value(1)\n\nutime.sleep(0.001)\n

                                                                                                                                                                                                                                                                                                              def render_feature_display(show_colon=False, show_dash=False): if show_colon: other_pin_maps['colon'].value(0) other_maps['colon'].value(1) else: other_pin_maps['colon'].value(0) other_maps['colon'].value(0)

                                                                                                                                                                                                                                                                                                              if show_dash:\n    other_pin_maps['dash'].value(0)\n    other_maps['dash'].value(1)\nelse:\n    other_pin_maps['dash'].value(0)\n    other_maps['dash'].value(0)\n

                                                                                                                                                                                                                                                                                                              while True:

                                                                                                                                                                                                                                                                                                              lt_year, lt_month, lt_mday, lt_hour, lt_minute, lt_second, lt_weekday, lt_yearday = utime.localtime()\n\n# testing out all the features of the display\ndigit_1_decimal = (lt_second % 4 == 0)\ndigit_2_decimal = (lt_second % 4 == 1)\ndigit_3_decimal = (lt_second % 4 == 2)\ndigit_4_decimal = (lt_second % 4 == 3)\n\nrender_digit_display(1, lt_minute // 10, digit_1_decimal)\nrender_digit_display(2, lt_minute % 10, digit_2_decimal)\nrender_digit_display(3, lt_second // 10, digit_3_decimal)\nrender_digit_display(4, lt_second % 10, digit_4_decimal)\n\nif (lt_second % 2 == 0):\n    render_feature_display(True, False)\nelse:\n    render_feature_display(False, True)\n\n ```\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01-intro/","title":"Welcome to the CoderDojo course on MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This course is about MicroPython, a variation of the popular Python programming language that is used to program microcontrollers.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01-intro/#intended-audience","title":"Intended Audience","text":"
                                                                                                                                                                                                                                                                                                              • Junior High or High School Students
                                                                                                                                                                                                                                                                                                              • Age 10-16
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01-intro/#preferred-skills","title":"Preferred Skills","text":"
                                                                                                                                                                                                                                                                                                              • Familiarity with basic text editing functions such as select, copy and paste
                                                                                                                                                                                                                                                                                                              • Understand how to save files to disk
                                                                                                                                                                                                                                                                                                              • Basic understanding of Python programming language (We strongly suggest you take the Introduction to Python Programming CoderDojo Course if you are not familiar with Python.)
                                                                                                                                                                                                                                                                                                              • User should be familiar with the the following Python concepts:

                                                                                                                                                                                                                                                                                                              • imports

                                                                                                                                                                                                                                                                                                              • libraries
                                                                                                                                                                                                                                                                                                              • variables
                                                                                                                                                                                                                                                                                                              • loops
                                                                                                                                                                                                                                                                                                              • conditionals
                                                                                                                                                                                                                                                                                                              • lists
                                                                                                                                                                                                                                                                                                              • functions
                                                                                                                                                                                                                                                                                                              • function parameters
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01-intro/#course-outline","title":"Course Outline","text":"
                                                                                                                                                                                                                                                                                                              • What is a Microcontroller?
                                                                                                                                                                                                                                                                                                              • What is Micropython?
                                                                                                                                                                                                                                                                                                              • Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Getting Started: Setting up MicroPython environment using Thonny or VS Code
                                                                                                                                                                                                                                                                                                              • Introduction to MicroPython - Getting Started
                                                                                                                                                                                                                                                                                                              • Sensors: getting information about the world around us
                                                                                                                                                                                                                                                                                                              • Displays: showing information to users
                                                                                                                                                                                                                                                                                                              • Sound and Music: playing tones, sounds and music
                                                                                                                                                                                                                                                                                                              • OLED Displays: drawing on displays
                                                                                                                                                                                                                                                                                                              • Robots: making robots move around with motors
                                                                                                                                                                                                                                                                                                              • Advanced Topics
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01-intro/#license-of-content","title":"License of Content","text":"

                                                                                                                                                                                                                                                                                                              Our intent is to allow teachers and mentors around the world to integrate MicroPython into their courses without any fees. We want you to be able to use this content freely with a few conditions: please give us attribution and please don't resell our content for profit.

                                                                                                                                                                                                                                                                                                              Note that we use the same Creative Commons licensing as the Raspberry Pi Foundation and the CoderDojo Foundation:

                                                                                                                                                                                                                                                                                                              Creative Commons Attribution NonCommercial ShareAlike

                                                                                                                                                                                                                                                                                                              This means you are free to reuse and remix this content for non-commercial educational purposes as long as you keep the attribution and preserve the license agreement.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/","title":"What is MicroPython?","text":"

                                                                                                                                                                                                                                                                                                              MicroPython is an implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers. (From micropython.org)

                                                                                                                                                                                                                                                                                                              MicroPython was originally created by the Australian programmer and physicist Damien George. It is written in C.

                                                                                                                                                                                                                                                                                                              MicroPython is now an OpenSource project and the source code is available in GitHub.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#micropython-libraries","title":"Micropython Libraries","text":"

                                                                                                                                                                                                                                                                                                              When you start up your IDE, it may have a list of python modules built in. You can list the current modules you have installed by running the help('modules') command.

                                                                                                                                                                                                                                                                                                              help('modules')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#micropython-builtin-functions","title":"MicroPython Builtin Functions","text":"

                                                                                                                                                                                                                                                                                                              MicroPython is designed to run quickly in a small memory system. So it has trimmed down many of the standard Python libraries to fit the needs of microcontrollers. Most of these libraries start with the letter \"u\" so that you are aware they are designed to run on microcontrollers.

                                                                                                                                                                                                                                                                                                              cmath \u2013 mathematical functions for complex numbers\ngc \u2013 control the garbage collector\nmath \u2013 mathematical functions\nuarray \u2013 arrays of numeric data\nuasyncio \u2014 asynchronous I/O scheduler\nubinascii \u2013 binary/ASCII conversions\nucollections \u2013 collection and container types\nuerrno \u2013 system error codes\nuhashlib \u2013 hashing algorithms\nuheapq \u2013 heap queue algorithm\nuio \u2013 input/output streams\nujson \u2013 JSON encoding and decoding\nuos \u2013 basic \u201coperating system\u201d services\nure \u2013 simple regular expressions\nuselect \u2013 wait for events on a set of streams\nusocket \u2013 socket module\nussl \u2013 SSL/TLS module\nustruct \u2013 pack and unpack primitive data types\nusys \u2013 system specific functions\nutime \u2013 time related functions\nuzlib \u2013 zlib decompression\n_thread \u2013 multithreading support\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#micropython-specific-libraries","title":"MicroPython Specific Libraries","text":"
                                                                                                                                                                                                                                                                                                              btree \u2013 simple BTree database\nframebuf \u2014 frame buffer manipulation\nmachine \u2014 functions related to the hardware\nmicropython \u2013 access and control MicroPython internals\nnetwork \u2014 network configuration\nubluetooth \u2014 low-level Bluetooth\nucryptolib \u2013 cryptographic ciphers\nuctypes \u2013 access binary data in a structured way\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#adding-a-module","title":"Adding a module","text":"

                                                                                                                                                                                                                                                                                                              When you are using python and you attempt to use a module that python can't find you will get an error. You must then use the python pip installer tool to add the new library.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#getting-micropython-libraries-from-pypi","title":"Getting MicroPython Libraries from PyPi","text":"

                                                                                                                                                                                                                                                                                                              Filter Only MicroPython Libraries

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/01b-libraries/#full-list-of-modules","title":"Full List of modules","text":"
                                                                                                                                                                                                                                                                                                              ESP-test            audioop             filecmp             random\n__future__          base64              fileinput           re\n_abc                bcrypt              fnmatch             readline\n_ast                bdb                 formatter           reedsolo\n_asyncio            binascii            fractions           reprlib\n_bisect             binhex              ftplib              resource\n_blake2             bisect              functools           rlcompleter\n_bootlocale         bitstring           gc                  runpy\n_bz2                blink-builtin-led   genericpath         sched\n_cffi_backend       brain_argparse      getopt              secrets\n_codecs             brain_attrs         getpass             select\n_codecs_cn          brain_builtin_inference gettext         selectors\n_codecs_hk          brain_collections   glob                send2trash\n_codecs_iso2022     brain_crypt         grp                 serial\n_codecs_jp          brain_curses        gzip                setuptools\n_codecs_kr          brain_dataclasses   hashlib             sh1106\n_codecs_tw          brain_dateutil      heapq               sh1106-test\n_collections        brain_fstrings      hmac                shelve\n_collections_abc    brain_functools     html                shlex\n_compat_pickle      brain_gi            http                shutil\n_compression        brain_hashlib       i2c-display         signal\n_contextvars        brain_http          i2c-scanner         site\n_crypt              brain_io            i2c_lcd             six\n_csv                brain_mechanize     i2clcd              smtpd\n_ctypes             brain_multiprocessing imaplib           smtplib\n_ctypes_test        brain_namedtuple_enum imghdr            sndhdr\n_curses             brain_nose          imp                 socket\n_curses_panel       brain_numpy_core_fromnumeric importlib  socketserver\n_datetime           brain_numpy_core_function_base inspect  spi-debug\n_dbm                brain_numpy_core_multiarray io          sqlite3\n_decimal            brain_numpy_core_numeric ipaddress      sre_compile\n_dummy_thread       brain_numpy_core_numerictypes isort     sre_constants\n_elementtree        brain_numpy_core_umath itertools        sre_parse\n_functools          brain_numpy_ndarray jedi                ssl\n_hashlib            brain_numpy_random_mtrand json          stat\n_heapq              brain_numpy_utils   keyword             statistics\n_imp                brain_pkg_resources lazy_object_proxy   string\n_io                 brain_pytest        led-strip           stringprep\n_json               brain_qt            lib2to3             struct\n_locale             brain_random        linecache           subprocess\n_lsprof             brain_re            list-modules        sunau\n_lzma               brain_six           locale              symbol\n_markupbase         brain_ssl           logging             symtable\n_md5                brain_subprocess    lzma                sys\n_multibytecodec     brain_threading     macpath             sysconfig\n_multiprocessing    brain_typing        mailbox             syslog\n_opcode             brain_uuid          mailcap             tabnanny\n_operator           builtins            marshal             tarfile\n_osx_support        bz2                 math                telnetlib\n_pickle             cProfile            mccabe              tempfile\n_posixsubprocess    calendar            mimetypes           termios\n_py_abc             certifi             mmap                test\n_pydecimal          cffi                modulefinder        textwrap\n_pyio               cgi                 multiprocessing     this\n_queue              cgitb               mypy                thonny\n_random             chunk               mypy_extensions     threading\n_scproxy            clonevirtualenv     mypyc               time\n_sha1               cmath               nacl                timeit\n_sha256             cmd                 netrc               tkinter\n_sha3               code                nis                 token\n_sha512             codecs              nntplib             tokenize\n_signal             codeop              ntpath              toml\n_sitebuiltins       collections         nturl2path          trace\n_socket             colorsys            numbers             traceback\n_sqlite3            compileall          opcode              tracemalloc\n_sre                concurrent          operator            tty\n_ssl                configparser        optparse            turtle\n_stat               contextlib          os                  turtledemo\n_string             contextvars         paramiko            typed_ast\n_strptime           copy                parser              types\n_struct             copyreg             parso               typing\n_symtable           crypt               pathlib             typing_extensions\n_sysconfigdata_m_darwin_darwin cryptography        pdb      unicodedata\n_testbuffer         csv                 pickle              unittest\n_testcapi           ctypes              pickletools         urllib\n_testimportmultiple curses              pip                 uu\n_testmultiphase     dataclasses         pipenv              uuid\n_thread             datetime            pipes               venv\n_threading_local    dbm                 pkg_resources       virtualenv\n_tkinter            decimal             pkgutil             virtualenv_support\n_tracemalloc        difflib             platform            warnings\n_uuid               dir-example         plistlib            wave\n_warnings           dis                 poplib              weakref\n_weakref            distutils           posix               webbrowser\n_weakrefset         doctest             posixpath           websockets\n_xxtestfuzz         docutils            pprint              wheel\nabc                 dummy_threading     profile             wrapt\naifc                easy_install        pstats              wsgiref\nantigravity         ecdsa               pty                 xdrlib\nargparse            email               ptyprocess          xml\narray               encodings           pwd                 xmlrpc\narray-test          ensurepip           py_compile          xxlimited\nast                 enum                pyclbr              xxsubtype\nastroid             errno               pycparser           zipapp\nasttokens           espefuse            pydoc               zipfile\nasynchat            espressif           pydoc_data          zipimport\nasyncio             espsecure           pyexpat             zlib\nasyncore            esptool             pylint              \nat                  faulthandler        queue               \natexit              fcntl               quopri              \n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-boards/","title":"Micropython Boards","text":"

                                                                                                                                                                                                                                                                                                              Technically, any computer that has at least 16K of RAM can run MicroPython as long as someone has ported the MicroPython runtime to use that instruction set.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-boards/#raspberry-pi-pico","title":"Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              Most of these lessons use a low-cost ($4 retail list price) Raspberry Pi Pico(../glossary.md#pico). The microcontroller was designed by the Raspberry Pi Foundation specifically to provide a low-cost way for student to learn how to program MicroPython. The Raspberry Pi Foundation has also worked with the Thonny developers to create a simple clean kid-friendly interface that is ideal for beginning students.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-boards/#esp32","title":"ESP32","text":"

                                                                                                                                                                                                                                                                                                              The ESP32 is similar to the Raspberry Pi Pico but ESP32 also has both WiFi and bluetooth.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-boards/#cables","title":"Cables","text":"

                                                                                                                                                                                                                                                                                                              You will need a USB cable to program your microcontroller. These cables are frequently sold at high margin rates at retail stores. If you plan ahead, you can usually find these cables on eBay for about 50% less. Classroom purchases make this a good option.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-boards/#getting-machine-statistics","title":"Getting Machine Statistics","text":"
                                                                                                                                                                                                                                                                                                              import machine\nhelp(machine)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-breadboards/","title":"Breadboards","text":"

                                                                                                                                                                                                                                                                                                              We use standard solderless mini breadboards in our labs. The breadboards have holes that are spaced 1/10th of an inch apart which is a standard for most electronics in the US.

                                                                                                                                                                                                                                                                                                              Our breadboards are usually 1/2 size with 400-ties. They have a central trough and power rails on the left and right edges.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-breadboards/#breadboard-regions-and-connections","title":"Breadboard Regions and Connections","text":"

                                                                                                                                                                                                                                                                                                              Learning how a breadboard works is critical for building your projects. In the figure above you will see that there are two types of regions of the breadboard

                                                                                                                                                                                                                                                                                                              1. The side regions are called the power distribution rails. They are similar to power lines that reach across our projects.
                                                                                                                                                                                                                                                                                                              2. The central region is call the row connector region. In this area the horizontal rows are all connected inside the breadboard. Within any row, columns a, b, c, d and e are all electrically connected. Within any row, columns f, h, i, j, and k are also electrically connected. However, there is a gap between columns e and f called the center gap or component slot that parts are usually placed over. Components like buttons and chips usually have their pins straddle the component slot.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-breadboards/#pico-placement-on-breadboard","title":"Pico Placement on Breadboard","text":"

                                                                                                                                                                                                                                                                                                              For most of our labs we place the Pico so that pin 1 of the Pico is in row 1 of the breadboard as in the image below.

                                                                                                                                                                                                                                                                                                              This means that the GND connections to the Pico are always in rows 3, 8, 13 and 18 on both sides of the breadboard. One of the ground pins is usually hooked up to the vertical blue power rails on the sides of the breadboard.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-breadboards/#pico-placement-annotations","title":"Pico Placement Annotations","text":"
                                                                                                                                                                                                                                                                                                              1. GND are the ground connections. There are
                                                                                                                                                                                                                                                                                                              2. VBUS is the 5V power from the USB and is high only when the USB is connected. This is nominally 5V (or 0V if the USB is not connected or not powered).
                                                                                                                                                                                                                                                                                                              3. VSYS (also know and Voltage System Input) is the main system input voltage. When the Pico is disconnected from the USB you apply power to the Voltage System Input. The input can vary in the allowed range 1.8V to 5.5V, and is used by the on-board SMPS to generate the 3.3V for the RP2040 and its GPIO connections. When the input voltage is less than 3.3 volts the Pico uses an internal DC voltage Boost converter to get the correct voltage to the processor.

                                                                                                                                                                                                                                                                                                              3V3_EN connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. To disable the 3.3V (which also de-powers the RP2040), short this pin low. In effect by making the 3V3_EN LOW you are turning off the Pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-breadboards/#breadboard-connections","title":"Breadboard Connections","text":""},{"location":"getting-started/02-esp32/","title":"ESP32 TTGO","text":"

                                                                                                                                                                                                                                                                                                              The ESP32 is a low-cost (under $10) microcontroller with both built-in WiFi and Bluetooth. This lab demonstrates using a version of the ESP32 that includes an integrated display.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-1-install-the-usb-to-uart-bridge-vcp-drivers","title":"Step 1: Install the USB to UART Bridge VCP Drivers","text":"

                                                                                                                                                                                                                                                                                                              Follow the directions here:

                                                                                                                                                                                                                                                                                                              https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

                                                                                                                                                                                                                                                                                                              Test this by running the ``ls -l /dev/cu*``` and verify you see:

                                                                                                                                                                                                                                                                                                              /dev/cu.SLAB_USBtoUART

                                                                                                                                                                                                                                                                                                              If you don't see this try to reboot.

                                                                                                                                                                                                                                                                                                              Mac: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/establish-serial-connection.html https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/raw/master/MicroPython_BUILD/firmware/MicroPython_LoBo_esp32_all.zip

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-2-create-a-python-conda-environment-for-esp32","title":"Step 2: Create a Python Conda Environment for ESP32","text":"

                                                                                                                                                                                                                                                                                                              This is so we don't mess up other Python projects on your system.

                                                                                                                                                                                                                                                                                                              conda create -n esp32 python=3\nconda activate esp32\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-3-install-the-esptool","title":"Step #3: Install the esptool","text":"
                                                                                                                                                                                                                                                                                                              $ pip3 install esptool\nCollecting esptool\n  Downloading esptool-3.0.tar.gz (149 kB)\n     |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 149 kB 2.9 MB/s \n     ...\nInstalling collected packages: pycparser, six, cffi, reedsolo, pyserial, ecdsa, cryptography, bitstring, esptool\nSuccessfully installed bitstring-3.1.7 cffi-1.14.5 cryptography-3.4.6 ecdsa-0.16.1 esptool-3.0 pycparser-2.20 pyserial-3.5 reedsolo-1.5.4 six-1.15.0\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-4-erase-the-old-firmware","title":"Step 4: Erase the Old Firmware","text":"
                                                                                                                                                                                                                                                                                                              esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-5-download-the-new-firmware","title":"Step 5: Download the New Firmware","text":"

                                                                                                                                                                                                                                                                                                              Get the ESP32_All prebuilt binary:

                                                                                                                                                                                                                                                                                                              https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/firmwares

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#step-6-reflash-the-new-esp32-firmware","title":"Step 6: Reflash the new ESP32 Firmware","text":"
                                                                                                                                                                                                                                                                                                              cd esp32_all/\n../flash.sh -p /dev/cu.SLAB_USBtoUART\n

                                                                                                                                                                                                                                                                                                              this will run...

                                                                                                                                                                                                                                                                                                              $ esptool.py --port /dev/cu.SLAB_USBtoUART erase_flash\nesptool.py v3.0\nSerial port /dev/cu.SLAB_USBtoUART\nConnecting........_\nDetecting chip type... ESP32\nChip is ESP32-D0WDQ6 (revision 1)\nFeatures: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None\nCrystal is 40MHz\nMAC: 24:62:ab:ca:62:84\nUploading stub...\nRunning stub...\nStub running...\nErasing flash (this may take a while)...\nChip erase completed successfully in 2.5s\nHard resetting via RTS pin...\n

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#configure-thonny","title":"Configure Thonny","text":"

                                                                                                                                                                                                                                                                                                              You must configure Thonny to use the ESP32.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#set-the-serial-port","title":"Set the Serial Port","text":"

                                                                                                                                                                                                                                                                                                              First, you must tell Thonny how to find the right port.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#set-the-interpreter","title":"Set the Interpreter","text":"

                                                                                                                                                                                                                                                                                                              Next, yo must tell Thonny to use the ESP32 interpreter.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#run-a-test","title":"Run a test","text":"
                                                                                                                                                                                                                                                                                                              import machine, display, time, math, network, utime\n\n\ntft = display.TFT()\ntft.init(tft.ST7789,bgr=False,rot=tft.LANDSCAPE, miso=17,backl_pin=4,backl_on=1, mosi=19, clk=18, cs=5, dc=16)\n\ntft.setwin(40,52,320,240)\n\nfor i in range(0,241):\n    color=0xFFFFFF-tft.hsb2rgb(i/241*360, 1, 1)\n    tft.line(i,0,i,135,color) \n\ntft.set_fg(0x000000) \ntft.ellipse(120,67,120,67) \ntft.line(0,0,240,135) \n\ntext=\"CoderDojo Rocks!\" \ntft.text(120-int(tft.textWidth(text)/2),67-int(tft.fontSize()[1]/2),text,0xFFFFFF)\n

                                                                                                                                                                                                                                                                                                              You should see the following on the ESP32 display:

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-esp32/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              https://www.instructables.com/TTGO-color-Display-With-Micropython-TTGO-T-display/

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/","title":"Getting Started with the Raspberry Pi RP2040 Microcontroller","text":"

                                                                                                                                                                                                                                                                                                              The Raspberry Pi RP2040 is a custom silicon microcontroller built by the Raspberry Pi Foundation. The RP2040 is used in the Raspberry Pi Pico with a retail list prices of $4. With 264K SRAM, it has around 100 times the RAM of an Arduino Uno (2K). It is ideal for projects that need more RAM such as projects that require drawing to an OLED display.

                                                                                                                                                                                                                                                                                                              \"H\" is with headers.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#specs","title":"Specs","text":"
                                                                                                                                                                                                                                                                                                              • RP2040 microcontroller chip designed by Raspberry Pi Foundation
                                                                                                                                                                                                                                                                                                              • Dual-core Arm Cortex M0+ processor, flexible clock running up to 133 MHz
                                                                                                                                                                                                                                                                                                              • 264KB of SRAM, and 2MB of on-board Flash memory
                                                                                                                                                                                                                                                                                                              • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
                                                                                                                                                                                                                                                                                                              • DMA controller
                                                                                                                                                                                                                                                                                                              • Interpolator and integer divider peripherals
                                                                                                                                                                                                                                                                                                              • Castellated module allows soldering direct to carrier boards
                                                                                                                                                                                                                                                                                                              • USB 1.1 and PHY with device and host support
                                                                                                                                                                                                                                                                                                              • Low-power sleep and dormant modes
                                                                                                                                                                                                                                                                                                              • Drag-and-drop programming using mass storage over USB
                                                                                                                                                                                                                                                                                                              • 26 \u00d7 multi-function GPIO pins
                                                                                                                                                                                                                                                                                                              • 3 12 bit analogue inputs
                                                                                                                                                                                                                                                                                                              • 16 controllable PWM channels
                                                                                                                                                                                                                                                                                                              • 2 SPI, 2 I2C, and 2 UART channels
                                                                                                                                                                                                                                                                                                              • Accurate clock and timer on-chip
                                                                                                                                                                                                                                                                                                              • 8 Raspberry Pi Programmable I/O (PIO) state machines
                                                                                                                                                                                                                                                                                                              • Temperature sensor
                                                                                                                                                                                                                                                                                                              • Accelerated floating-point libraries on-chip
                                                                                                                                                                                                                                                                                                              • 8 \u00d7 Programmable I/O (PIO) state machines for custom peripheral support
                                                                                                                                                                                                                                                                                                              • Created using the TSMC 40LP (40 nano meter low power) manufacturing process
                                                                                                                                                                                                                                                                                                              • USB mass-storage boot mode with UF2 support, for drag-and-drop programming
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#runtimes","title":"Runtimes","text":""},{"location":"getting-started/02-pi-pico/#usb-cable","title":"USB Cable","text":"

                                                                                                                                                                                                                                                                                                              The Raspberry Pi Pico uses a USB-micro connector. You can purchase USB Micro-B to USB-A or USB-C (Mac) cables on e-bay for under $2 or for $5 at Microcenter. - image from ebay

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#pico-pinout","title":"Pico Pinout","text":"

                                                                                                                                                                                                                                                                                                              The pinout diagram for the Raspberry Pi Pico is shown below.

                                                                                                                                                                                                                                                                                                              It features: * 26 \u00d7 multi-function GPIO pins * 2 \u00d7 SPI, 2 \u00d7 I2C, 2 \u00d7 UART, 3 \u00d7 12-bit ADC, 16 \u00d7 controllable PWM

                                                                                                                                                                                                                                                                                                              Raspberry Pi Pico\u2019s 40 pins with pin 1 in the upper right corner with the USB connector at the top. The pin numbers are incremented as you go counterclockwise around the board. You go down the left side and then continue up on the right side until you get to pin 40 in the upper right corner.

                                                                                                                                                                                                                                                                                                              When you program the Pico, you use the machine.Pin() but you always use the GP* number, never the pin number on the board pin numbers.

                                                                                                                                                                                                                                                                                                              The diagram above shows the top view where pins 1, 2 and 40 are printed next to the pins.

                                                                                                                                                                                                                                                                                                              • Pico Pinout Datasheet PDF

                                                                                                                                                                                                                                                                                                              Next to each pin is the primary label of what the pin does. Pins 3, 8, 13, 18, 23, 28, 33 and 38 with the black background are all GND pins.

                                                                                                                                                                                                                                                                                                              Pins are numbered 0-29, and 26-29 have ADC capabilities Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN

                                                                                                                                                                                                                                                                                                              Label Name Description V3 3.3 volts power A source of 3.3 V power, the same voltage your Pico runs at internally, generated from the VSYS input. This power supply can be switched on and off using the 3V3_EN pin above it, which also switches your Pico off. VSYS ~2-5 volts power A pin directly connected to your Pico\u2019s internal power supply, which cannot be switched off without also switching Pico off. VBUS 5 volts power A source of 5 V power taken from your Pico\u2019s micro USB port, and used to power hardware which needs more than 3.3 V. GND 0 volts ground A ground connection, used to complete a circuit connected to a power source. Several of these pins are dotted around your Pico to make wiring easier. GPxx General-purpose input/output pin number \u2018xx The GPIO pins available for your program, labelled \u2018GP0\u2019 through to \u2018GP28\u2019. GPxx_ADCx General-purpose input/output pin number \u2018xx\u2019, with analogue input number \u2018x\u2019 A GPIO pin which ends in \u2018ADC\u2019 and a number can be used as an analogue input as well as a digital input or output \u2013 but not both at the same time. ADC_VREF Analogue-to-digital converter (ADC) voltage reference A special input pin which sets a reference voltage for any analogue inputs. AGND Analogue-to-digital converter (ADC) 0 volts ground A special ground connection for use with the ADC_VREF pin. RUN Enables or disables your Pico The RUN header is used to start and stop your Pico from another microcontroller."},{"location":"getting-started/02-pi-pico/#steps-to-get-micropython-running-on-the-mac","title":"Steps To Get Micropython Running on the Mac","text":"
                                                                                                                                                                                                                                                                                                              1. Download the MicroPython UF2 file.
                                                                                                                                                                                                                                                                                                              2. Push and hold the BOOTSEL button and plug your Pico into the USB port of your Raspberry Pi or other computer. Release the BOOTSEL button after your Pico is connected. It will mount as a Mass Storage Device called RPI-RP2.
                                                                                                                                                                                                                                                                                                              3. Drag and drop the MicroPython UF2 file onto the RPI-RP2 volume. Your Pico will reboot. You are now running MicroPython.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#using-thonny","title":"Using Thonny","text":"

                                                                                                                                                                                                                                                                                                              Thonny is a free lightweight Python development tool.

                                                                                                                                                                                                                                                                                                              1. Download the Thonny Application
                                                                                                                                                                                                                                                                                                              2. Download the Thonny Pico driver
                                                                                                                                                                                                                                                                                                              3. Configure Thonny to use the Pico interpreter
                                                                                                                                                                                                                                                                                                              4. Test using the help() function
                                                                                                                                                                                                                                                                                                              5. Test by running a blink application

                                                                                                                                                                                                                                                                                                              Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2\nWriting to /Volumes/RPI-RP2/firmware\n100%\nWaiting for the port...\nFound 2e8a:0005 at /dev/cu.usbmodem0000000000001\n\nDone!\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#getting-the-bootloader-running-from-the-thonny-python-shell","title":"Getting The Bootloader Running from the Thonny Python Shell","text":"

                                                                                                                                                                                                                                                                                                              Although you can hold down the BOOTSEL button as you are plugging in the Pico, there is a much easier way. Just type the following into the Thonny shell:

                                                                                                                                                                                                                                                                                                              machine.bootloader()\n

                                                                                                                                                                                                                                                                                                              This will make the Pico go into the Bootloader Mode and mount the file system. You can then copy the bootloader file using the drag-and-drop from your file system or use a UNIX copy command. Once the copy is finished the Pico will automaticaly restart using the new uf2 file.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#using-the-onboard-led","title":"Using the Onboard LED","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport utime\nled_onboard = machine.Pin(25, machine.Pin.OUT)\nled_onboard.value(1)\n

                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport utime\n\n# right uppermost pin with USB on the left\nled = Pin(16, Pin.OUT)\nled.low()\nwhile True:\n   led.toggle()\n   utime.sleep(1)\n
                                                                                                                                                                                                                                                                                                              Press the Play Button

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#adding-gnd-markers","title":"Adding GND Markers","text":"

                                                                                                                                                                                                                                                                                                              One of the key disadvantages

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#references","title":"References","text":""},{"location":"getting-started/02-pi-pico/#getting-started-guide","title":"Getting Started Guide","text":"

                                                                                                                                                                                                                                                                                                              Raspberry Pi Getting Started

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#micropython-rp2040-reference","title":"MicroPython RP2040 Reference","text":"

                                                                                                                                                                                                                                                                                                              MicroPython RP2040 Quick Reference - this web page has details on how MicroPython was ported to the RP2040 Microcontroller.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02-pi-pico/#book-pdf","title":"Book PDF","text":"

                                                                                                                                                                                                                                                                                                              Raspberry Pi Book PDF Download from HackSpace Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/","title":"Thonny Python IDE","text":"

                                                                                                                                                                                                                                                                                                              A lightweight Python integrated development environment (IDE) that is ideal for beginners writing simple Python programs for first-time users. It has been modified to work well with the Raspberry Pi Pico. It supports different ways of stepping through the code, step-by-step expression evaluation, detailed visualization of the call stack and a mode for explaining the concepts of references and heap.

                                                                                                                                                                                                                                                                                                              We strongly suggest that classes begin with Thonny for the first several weeks. As students want to do more complex functions such as build automatic deployment scripts other IDEs are more appropriate.

                                                                                                                                                                                                                                                                                                              Thonny 3.3.3 (2021-01-21) was the first version to support the Raspberry Pi Pico. There have also been several enhancements since that release. For a release history, see the Thonny Release History. We suggest checking this link monthly for updates.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#installing-thonny","title":"Installing Thonny","text":"

                                                                                                                                                                                                                                                                                                              The best way to install Thonny is to go to the Thonny website an look for the \"Download\" area for your operating system. That link is here:

                                                                                                                                                                                                                                                                                                              https://thonny.org/

                                                                                                                                                                                                                                                                                                              Make sure you upgrade to the latest version of Thonny if you already have a Thonny installed on your computer.

                                                                                                                                                                                                                                                                                                              You can find more tips on getting started with Thonny on the Raspberry Pi website:

                                                                                                                                                                                                                                                                                                              https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/2

                                                                                                                                                                                                                                                                                                              Thonny runs on Mac, Windows and Linux.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#upgrading-thonny","title":"Upgrading Thonny","text":"

                                                                                                                                                                                                                                                                                                              Although you can always upgrade Thonny by removing it and reinstalling a new version, on Mac and Linux systems there is an easier method.

                                                                                                                                                                                                                                                                                                              Run the following shell command:

                                                                                                                                                                                                                                                                                                              sudo yum upgrade thonny\n

                                                                                                                                                                                                                                                                                                              or

                                                                                                                                                                                                                                                                                                              sudo apt-get upgrade thonny\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#running-help","title":"Running help()","text":"

                                                                                                                                                                                                                                                                                                              You can enter the help() function in the main script area and then press the Play button. This will tell you

                                                                                                                                                                                                                                                                                                              MicroPython v1.14 on 2021-02-02; Raspberry Pi Pico with RP2040\nType \"help()\" for more information.\n>>> %Run -c $EDITOR_CONTENT\nWelcome to MicroPython!\n\nFor online help please visit https://micropython.org/help/.\n\nFor access to the hardware use the 'machine' module.  RP2 specific commands\nare in the 'rp2' module.\n\nQuick overview of some objects:\n  machine.Pin(pin) -- get a pin, eg machine.Pin(0)\n  machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n    methods: init(..), value([v]), high(), low(), irq(handler)\n  machine.ADC(pin) -- make an analog object from a pin\n    methods: read_u16()\n  machine.PWM(pin) -- make a PWM object from a pin\n    methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d])\n  machine.I2C(id) -- create an I2C object (id=0,1)\n    methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True)\n             readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg)\n  machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1)\n    methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf)\n  machine.Timer(freq, callback) -- create a software timer object\n    eg: machine.Timer(freq=1, callback=lambda t:print(t))\n\nPins are numbered 0-29, and 26-29 have ADC capabilities\nPin IO modes are: Pin.IN, Pin.OUT, Pin.ALT\nPin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN\n\nUseful control commands:\n  CTRL-C -- interrupt a running program\n  CTRL-D -- on a blank line, do a soft reset of the board\n  CTRL-E -- on a blank line, enter paste mode\n\nFor further help on a specific object, type help(obj)\nFor a list of available modules, type help('modules')\n>>>\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#save-options","title":"Save Options","text":"

                                                                                                                                                                                                                                                                                                              You can save a python file in Thonny to either the Pico or to your local computer's file system.

                                                                                                                                                                                                                                                                                                              first stop execution of any program you are running.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#downloading-the-firmware","title":"Downloading the Firmware","text":"

                                                                                                                                                                                                                                                                                                              After you start up Thonny there will be a button in the lower right corner.

                                                                                                                                                                                                                                                                                                              After you click on it you will see the following:

                                                                                                                                                                                                                                                                                                              Downloading 465408 bytes from https://github.com/raspberrypi/micropython/releases/download/pico-20210120/pico_micropython_20210121.uf2\nWriting to /Volumes/RPI-RP2/firmware\n100%\nWaiting for the port...\nFound 2e8a:0005 at /dev/cu.usbmodem0000000000001\n\nDone!\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#version","title":"Version","text":"

                                                                                                                                                                                                                                                                                                              After you press play the following will appear in the console.

                                                                                                                                                                                                                                                                                                              MicroPython v1.13-290-g556ae7914 on 2021-01-21; Raspberry Pi Pico with RP2040\nType \"help()\" for more information.\n>>> %Run -c $EDITOR_CONTENT\n
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#plotting-values-on-thonny","title":"Plotting Values on Thonny","text":"

                                                                                                                                                                                                                                                                                                              If you are reading sensor values and want to see a nice plot of the values, you can use Thonny's Plot function to view the values. Simply add numeric print values to your main loop and they will be displayed in the plot window. This is very useful for any analog to digital conversions and can be used as a simple tool to view anomalies in incoming data. For example if you accidentally hook up a potentiometer's positive rail to 3.3OUT instead of the 3.3REF you will see noise in the incoming data caused by spikes on the power rails.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02c-thonny/#background-on-thonny","title":"Background on Thonny","text":"

                                                                                                                                                                                                                                                                                                              MicroPython was originally developed by Damien George and first released in 2014. However, MicroPython did not have a development environment that was easy for students to use. Thonny was developed to provide an easy to use tool just for MicroPython development. Thonny was created at the University of Tartu Institute of Computer Science in Estonia for this purpose. They continue to support Thonny.

                                                                                                                                                                                                                                                                                                              Several feature for Thonny were sponsored by the Raspberry Pi Foundation and we continue to see a close relationship between the Raspberry Pi Foundation and the Thonny development team.

                                                                                                                                                                                                                                                                                                              • Thonny web site
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02d-vscode/","title":"Using Visual Studio Code to Program MicroPython","text":"

                                                                                                                                                                                                                                                                                                              Although the Thonny IDE is a great way for kids to start programming in Python on the Raspberry Pi Pico, it has limited advanced features and no large library of extensions.

                                                                                                                                                                                                                                                                                                              For intermediate to advanced Python developers, the Visual Studio Code IDE is a good options when it is used with an appropriate extension such as the Pico Go extension by Chris Wood.

                                                                                                                                                                                                                                                                                                              Note that Visual Studio Code is sometimes just called VS Code.

                                                                                                                                                                                                                                                                                                              Code extensions provide code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REPL console. You can a single file on your board, sync your entire project or directly type and execute commands. Because the files are stored on your local computer, it makes it easier to use version control software to allow you to work in teams with remote developers.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02d-vscode/#installing-visual-studio-code","title":"Installing Visual Studio Code","text":"

                                                                                                                                                                                                                                                                                                              Visual Studio Code runs on Windows, Mac and Linux systems such as the operating systems that run on the Raspberry Pi 3 or 4. You typically need around 2GB of RAM to run VS-Code.

                                                                                                                                                                                                                                                                                                              See the VS Code Requirements.

                                                                                                                                                                                                                                                                                                              If you have a Raspberry Pi the installation instructions are here.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02d-vscode/#adding-the-pico-go-extension","title":"Adding the Pico Go Extension","text":"

                                                                                                                                                                                                                                                                                                              After you have installed VS-Code you must download the Pico Go Extension:

                                                                                                                                                                                                                                                                                                              Pico Go Quick Start

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/02d-vscode/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Pico Go by Chris Wood
                                                                                                                                                                                                                                                                                                              2. Bao Phan Micropython Extension
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/","title":"Sourcing Parts","text":"

                                                                                                                                                                                                                                                                                                              One of the key values of CoderDojo clubs around the world is to not charge any fees for attending these clubs. Parts need to be purchase by limited funds raised through donations. Club organizers need to be frugal about getting low-cost parts for the participants.

                                                                                                                                                                                                                                                                                                              Our experience is that is difficult to get the right parts at low cost using firms that promise quick delivery times of a few days. The lowest price parts often must be purchased weeks in advance from places like China and Taiwan. As a result, clubs that use funds carefully must plan weeks if not months in advance of classes and events. So we strongly suggest bringing an robot part procurement team together two months before you begin to offer robot courses where students can each have their own robots.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#purchasing-the-raspberry-pi-kits","title":"Purchasing The Raspberry Pi Kits","text":"

                                                                                                                                                                                                                                                                                                              As of June 2021, the Raspberry Pi Pico did not come integrated into low-cost development kits that include robot kit parts. You frequently must to purchase the independent parts yourself.

                                                                                                                                                                                                                                                                                                              Here are some of the parts we recommend.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#the-raspberry-pi-pico","title":"The Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              In the US, our best source of these has been Microcenter stores. They sell them for $3.99 and they often have them on sale for $1.99.

                                                                                                                                                                                                                                                                                                              Microcenter Pico Part Listing

                                                                                                                                                                                                                                                                                                              Microcenter has around 25 Locations in the US.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#usb-cable","title":"USB Cable","text":"

                                                                                                                                                                                                                                                                                                              For a Mac with USB-C connectors, you will need to get a USB micro to C cable:

                                                                                                                                                                                                                                                                                                              • Ebay USB 3.1 USB C Type C to Micro USB Male Sync OTG Charge Data Transfers Adapters Sample 1 meter USB cable on eBay for $2.40.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#headers","title":"Headers","text":"

                                                                                                                                                                                                                                                                                                              We need male breakaway headers with standard 1/10th inch spacing. The Raspberry Pi Pico will need 20 pins on each side. If you get 40-pin versions they can easily be broken in half.

                                                                                                                                                                                                                                                                                                              • EBay: Ebay 40-Pin Male Header 0.1\" 2.54mm Breadboard PCB Strip Connectors 5pc - these ship from China in a few weeks and you can get five of them for $1 (including shipping).

                                                                                                                                                                                                                                                                                                              • Amazon: Amazon MCIGICM 10pcs Male Header Pin, 40 Pin Header Strip (2.54 mm) for Arduino Connector

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#solderless-breadboards","title":"Solderless Breadboards","text":"

                                                                                                                                                                                                                                                                                                              We like the 1/2 size boards that have 400 connection points. We like to mount them with the USB connector at the top with the numbers running down the left side to align with the pin numbers.

                                                                                                                                                                                                                                                                                                              • EBay: Solderless Breadboard 400 Point Tie Prototype Test Bread Board PCB For Arduino

                                                                                                                                                                                                                                                                                                              • Amazon: Amazon 4 Pieces for $6

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#hookup-wire","title":"Hookup Wire","text":"

                                                                                                                                                                                                                                                                                                              Use 22 gauge wire. Get a large spool of black and red and smaller spools of other colors. We use

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#breakable-40-pin-headers","title":"Breakable 40-Pin Headers","text":"

                                                                                                                                                                                                                                                                                                              If you purchase the Raspberry Pi Pico kit that does not have the header pins soldered in, you can use the following to add your own header pins in so the Pico's can be used with the header pins.

                                                                                                                                                                                                                                                                                                              40 pin Breakable Pin Header 2.54mm Single Row Male Header Connector Kit on eBay. I purchased 12 of these for $5 or $4.24 per pack of 12 when I purchase 4 packs.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#male-to-male-breadboard-jumper-wires","title":"Male-to-Male Breadboard Jumper Wires","text":"

                                                                                                                                                                                                                                                                                                              You can use 22 gauge wire to build your projects, however kids that don't have fine motor skills sometimes get frustrated with raw wires. You can purchase a Jumper Wire Kit with 65 jumpers on EBay for under $2 that has nice plastic ends that are easier to use.

                                                                                                                                                                                                                                                                                                              • Ebay: 65pcs Jumper Wire cable kit for Solderless Breadboard New - 65 of various lengths for $1.50

                                                                                                                                                                                                                                                                                                              • Ebay: 65X 65PCS Jumper Wire Cable Kit For Solderless Breadboard

                                                                                                                                                                                                                                                                                                              • Amazon: ZYAMY 195pcs Breadboard Jumper Wire 12cm 16cm 20cm 24cm Solderless Flexible Breadboard Connecting Line Cables Male to Male Breadboard Jumpers (65pcs/Set x 3) - three packs of 65 for about $8

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#momentary-press-buttons","title":"Momentary Press Buttons","text":"

                                                                                                                                                                                                                                                                                                              A B3F Momentary Press Button with a blue cap.

                                                                                                                                                                                                                                                                                                              Note the schematic in the lower right corner that shows the internal connections of the button.

                                                                                                                                                                                                                                                                                                              We like the B3F-4055 12 x12x7.3mm Tactile Switch Momentary Press Buttons that have small dimples on the bottom that fit into the breadboard center trough. They can be purchased for under 10 cents per unit on eBay. You can by them with our without colored caps. The links below have example listings on eBay.

                                                                                                                                                                                                                                                                                                              • eBay Tactile Push Button Switch Momentary Tact & Cap 12x12x7.3mm Assorted Kit - this kit includes 15 switchs with seven colors of caps for US $8.95.
                                                                                                                                                                                                                                                                                                              • eBay: 10PCS New B3F Tactile Switch Key Button Switch 12x12x7.3mm Blue
                                                                                                                                                                                                                                                                                                              • eBay 100PCS B3F-4055 Tactile Switch W/ OMRON Tact Push Button Momentary 12 x12 x7.3mm
                                                                                                                                                                                                                                                                                                              • eBay Button Caps 140PCS Round Tactile Button Cap Kits 9.585.1mm for 1212*7.3mm Tact Switch
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#sensor-kit","title":"Sensor Kit","text":"

                                                                                                                                                                                                                                                                                                              Although not all of these items are really \"sensors\" (some are displays), these kits provide high value at a low price-per item cost. Note that some of these kits contain tilt switches that contain Mercery. I remove these from the kits.

                                                                                                                                                                                                                                                                                                              • EBay 16 Sensor Kit Raspberry Pi / Arduino Sensor Kit 16 Modules Package 16 kinds of sensor
                                                                                                                                                                                                                                                                                                              • EBay 45 Sensor Kit for $18 US 45 In 1 Sensor Module Starter Kit Updated Set For Arduino Raspberry Pi Education
                                                                                                                                                                                                                                                                                                              • HiLetgo 37 Sensors Assortment Kit 37 Sensors Kit Sensor Starter Kit for Arduino Raspberry pi Sensor kit 37 in 1 Robot Projects Starter Kits for Arduino Raspberry pi
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#linear-10k-potentiometers","title":"Linear 10K Potentiometers","text":"

                                                                                                                                                                                                                                                                                                              We use linear 10K potentiometers in many labs and kits. The pre-wired options are very handy but you will need some male-to-male jumpers.

                                                                                                                                                                                                                                                                                                              • EBay: Pre-wired Potentiometer with Knob
                                                                                                                                                                                                                                                                                                              • EBay: 10 10K Pots for $2.29
                                                                                                                                                                                                                                                                                                              • Amazon: 10K Pot Kit with 8 pots and knobs for $8
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#momentary-press-buttons_1","title":"Momentary Press Buttons","text":"

                                                                                                                                                                                                                                                                                                              We like these small momentary press buttons because they are easy to mount directly on the breadboard. They provide ideal \"Mode Programming\" buttons to put the microcontroller into a programming mode.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#switches","title":"Switches","text":"

                                                                                                                                                                                                                                                                                                              These are ideal for turning your project boxes on and off.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#small-096-oled-displays","title":"Small 0.96\" OLED displays","text":"

                                                                                                                                                                                                                                                                                                              We love these low-cost 128X64 OLED displays. They are bright and draw very little power. There are two different connectors: 4-wire I2C and 7-wire SPI. I would suggest the simpler I2C for most starter projects.

                                                                                                                                                                                                                                                                                                              • EBay: 0.96\" OLED LCD Display Module IIC I2C Interface 128x64 For SSD1306
                                                                                                                                                                                                                                                                                                              • Amazon: Five OLED displays for $7
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#larger-242-oleds","title":"Larger 2.42\" OLEDs","text":"

                                                                                                                                                                                                                                                                                                              For our robot projects our students like to view the values from a distance. For them we use these $17 OLED displays that are about twice the size.

                                                                                                                                                                                                                                                                                                              2.42\" OLED Display wired with SPI

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#non-rechargeable-aa-and-aaa-battery-packs","title":"Non-rechargeable AA and AAA Battery Packs","text":""},{"location":"getting-started/03-suggested-parts/#rechargeable-battery-packs","title":"Rechargeable Battery Packs","text":"

                                                                                                                                                                                                                                                                                                              If you are work on project that need long-lasting portable power such as LED strip costumes, there are a wide variety of long-lasting rechargeable battery packs available from prices around $9 to $15. My favorites are ones that have percentage of power remaining displayed.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#ultrasonic-distance-sensors","title":"Ultrasonic Distance Sensors","text":"

                                                                                                                                                                                                                                                                                                              These inexpensive \"ping\" sensors are used in many robot projects.

                                                                                                                                                                                                                                                                                                              • HC-SR04 Ultrasonic Distance Sensor - $1 on eBay
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/03-suggested-parts/#motor-controllers","title":"Motor Controllers","text":"

                                                                                                                                                                                                                                                                                                              We like two motor three wheel robots in our classrooms. They need a H-Bridge circuit for controlling the motor direction. The popular L293D chip takes four PWM signals and will use these to drive two 3-12v DC motors. The L293D chip can be mounted directly on your breadboard. However, we like the low-cost Mini motor controller boards that are only $2 that also have handy screw headers for easily attaching and removing the motor and power wires.

                                                                                                                                                                                                                                                                                                              Here are the specs: Here

                                                                                                                                                                                                                                                                                                              • Input DC 4.5-36V
                                                                                                                                                                                                                                                                                                              • 600mA output per channel (per motor)

                                                                                                                                                                                                                                                                                                              • See section 4.4 in the Raspberry Pi Pico Datasheet on the Powerchain - note that the input VSYS, the main system input voltage, is only designed to go up to up to 5.5 volts. VSYS feeds the RVT6150 buck-boost SMPS.

                                                                                                                                                                                                                                                                                                              • Mini Motor Drive Shield Expansion Board L293D Module For Arduino UNO MEGA2560 R3 $3

                                                                                                                                                                                                                                                                                                              • [Amazon 3 motor drives for $7]
                                                                                                                                                                                                                                                                                                              • L293 Datasheet
                                                                                                                                                                                                                                                                                                              • Banggood L293D Motor Drive Module
                                                                                                                                                                                                                                                                                                              • Parshavele
                                                                                                                                                                                                                                                                                                              • ST Microelectronics L78M Datasheet
                                                                                                                                                                                                                                                                                                              • Datasheet for 78M05 Voltage
                                                                                                                                                                                                                                                                                                              • Datasheet for ST 78M05 Voltage Regulators

                                                                                                                                                                                                                                                                                                              Note that the L293D Mini Motor Drive shield also has a voltage regulator that delivers a constant 5 volt signal to the robot microcontroller.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/","title":"Powering Your MicroPython Projects","text":"

                                                                                                                                                                                                                                                                                                              If you are just using MicroPython to learn how to code you can use the USB connector from your Mac or PC to power your project. However, if you are creating a device that can't be connected to the USB cable such as a robot, then you will need to hook up portable power supply like a battery pack to power your device.

                                                                                                                                                                                                                                                                                                              The good news is that most microcontrollers like the Raspberry Pi Pico or ESP32 have many options and they are easy to use. Just be careful about applying too much power since unlike the old 5V Arduino boards, these devices only use 3.3v power supplies. Connecting the Pico to a 4 AA batteries (4 X 1.5 volts = 6 volt total) can damage the Pico microcontroller.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#power-connectors","title":"Power Connectors","text":"

                                                                                                                                                                                                                                                                                                              The Raspberry Pi Pico has three important power connectors you should learn about.

                                                                                                                                                                                                                                                                                                              1. VBUS - A direct connection to the USB System bus and available in the upper right corner of the Pico. When connected, circuits inside the Pico will disconnect the other power sources. This is the preferred way to power the Pico when doing development and if a USB battery pack is used.
                                                                                                                                                                                                                                                                                                              2. VSYS - This the main system input voltage and used when the device is not connected to the USB. The Pico has on-board power control circuits that allow VSYS to vary anywhere in the range of 1.8V to 5.5V. This is great since three AAA batteries which start at 4.5 volts can be used even as their voltage drops to 1.8 volts. VSYS is used by the on-board SMPS (Switched Mode Power Supply) to generate the 3.3V for the RP2040 and its GPIO. You can use this to power the Pico if you have any non-USB battery pack such as 3 AA batteries or an external 5 volt power supply that is generated by a motor driver circuit.
                                                                                                                                                                                                                                                                                                              3. 3V3_EN connects to the on-board SMPS enable pin, and is pulled high (to VSYS) via a 100K resistor. To disable the 3.3V (which also de-powers the RP2040), short this pin low.
                                                                                                                                                                                                                                                                                                              4. 3.3OUT This pin can be used to power external circuitry. The maximum output current will depend on RP2040 load and VSYS voltage, it is recommended to keep the load on this pin less than 300mA. In in other words, you don't want to drive more than about 15 LEDs that each draw up to 20 milliamps at full power. 3V3 is the main 3.3V supply to RP2040 and its I/O, generated by the on-board SMPS.
                                                                                                                                                                                                                                                                                                              5. ADC_VREF - This should not be used for any purpose other than to provide a low-current voltage reference for any of the three analog-to-digital inputs. For example if you have three potentiometers you would hook the positive rail of each of them to this pin. This allows for reasonably high-resolution analog to digital that is mostly free of the power noise present on the 3.3OUT pin.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#usb-battery-packs","title":"USB Battery Packs","text":"

                                                                                                                                                                                                                                                                                                              There is large and growing market for rechargeable cell-phone power packs that are ideal for applications such as robotics and powering a remote microcontroller for a long time. They can be purchased in many power storage levels from 2500 milliamp hours up to over 1 million milliamp hours.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#preventing-usb-power-pack-autoshutdown","title":"Preventing USB Power Pack Autoshutdown","text":"

                                                                                                                                                                                                                                                                                                              The one issue to be aware of with battery packs is that they automatically power down if they don't sense a minimum current being drawn such as about 10 milliamps. In many applications the Pico draws less than that amount. One fix is to simply add LED power indicator that draws 10 milliamps. This will

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#battery-power","title":"Battery Power","text":"

                                                                                                                                                                                                                                                                                                              3 AA alkaline batteries wired in series provide plenty of power for small Pico-based MicroPython projects. Each battery is 1.5 volts which give a total of 4.5 volts which is well within the maximum power use by the VSYS input on the Pico.

                                                                                                                                                                                                                                                                                                              As an alternative, you can also use 4 rechargeable NiCad batteries that have a nominal rating of 1.2 volts each. This is a total of 4.8 volts, which is still under the 5.5 volt limit.

                                                                                                                                                                                                                                                                                                              Warning

                                                                                                                                                                                                                                                                                                              Do not connect 4 AA batteries directly to VSYS. 6 volts is too high for the Pico's power system and could damage it. Use a voltage regulator such as is found on motor driver boards. Another alternative is to use a DC-to-DC voltage regulator such as a Buck Converter.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#monitoring-usb-power","title":"Monitoring USB Power","text":"

                                                                                                                                                                                                                                                                                                              On the Pico, GP24 can be used to indicate if power is being drawn from the USB cable. You can also use this information to change the behavior such as drop into low-power mode when disconnected from a USB source.

                                                                                                                                                                                                                                                                                                              See here

                                                                                                                                                                                                                                                                                                              Here is some sample MicroPython code that displays this value:

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\n\nled_onboard = machine.Pin(25, machine.Pin.OUT)\nUSBpower = machine.Pin(24, machine.Pin.IN) \n\nwhile True:\n   led_onboard.value(1)\n   utime.sleep(0.5)\n   led_onboard.value(0)\n   utime.sleep(0.5)\n   if USBpower() != 1:\n      utime.sleep(1)\n

                                                                                                                                                                                                                                                                                                              This program prints out the value of the USB Power indicator.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\n\nled_onboard = machine.Pin(25, machine.Pin.OUT)\nUSBpower = machine.Pin(24, machine.Pin.IN) \n\nif USBpower() = 1:\n    print('drawing power from the USB')\nelse\n    print('drawing power from VSYS - a battery or external power source')\n

                                                                                                                                                                                                                                                                                                              Power consumption when running this code is approximately 0.1W (19mA at 4.99V, so 4 x AA batteries (@ 2,000mAh each) would keep the Pico running for well over 4 days.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#running-both-usb-and-external-battery-power-on-the-raspberry-pi-pico","title":"Running both USB and External Battery Power on the Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              The battery should provide a voltage greater than 1.8v and less than 5.5v. Importantly if both a battery and a micro USB cable are connected at the same time a Schottky diode should be placed between the battery positive and VSYS [see section 4.4 & 4.5 of the Raspberry Pi Pico Datasheet. As long as the battery voltage is less than that coming in from the USB cable, power will be drawn from the USB supply and not the battery and, when you unplug the Pico from its USB supply, the Pico will keep on running, using power from the battery (and visa versa when you plug it back in).

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/04-power/#monitoring-batter-power-level-on-the-raspberry-pi-pico","title":"Monitoring Batter Power Level on the Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              You can use one of the three analog to digital converters to allow the Pico to monitor the power remaining in an external battery. For example if you have 3 AA batteries you can connect two 100K ohm resistors in series and connect the top and bottom to the power and ground. Then connect the midpoint to one of the three ADC inputs. This will give you a way to monitor the power remaining in an external battery. A fully charge battery pack voltage such at 4.5 volts will generate a voltage of 1/2 the maximum level. As the voltage drops to 1.8 volts it should display a value of 0%. An OLED can provide an ideal way to display the power level remaining.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/06-yd-2040/","title":"The YD-RP2040","text":"

                                                                                                                                                                                                                                                                                                              The VCC-GND YD-RP2040 is a microcontroller that sells for $5-$10 on e-Bay. It is rumored to come with either 4MB or 16MB flash, but the units I have received only have 2MB.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/06-yd-2040/#additions","title":"Additions","text":"
                                                                                                                                                                                                                                                                                                              • Pin labels are on the top where they should be!
                                                                                                                                                                                                                                                                                                              • There is a red LED to show that power is connected
                                                                                                                                                                                                                                                                                                              • There is a RESET button
                                                                                                                                                                                                                                                                                                              • There is a USER button on GP24
                                                                                                                                                                                                                                                                                                              • There is a blue LED on GP25
                                                                                                                                                                                                                                                                                                              • There is an RGB NeoPixel LED on GP23
                                                                                                                                                                                                                                                                                                              • Four Analog to digital converters (the Pico only had two)
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/06-yd-2040/#w25q32-flash-chip","title":"W25Q32 Flash Chip","text":"

                                                                                                                                                                                                                                                                                                              The board has a W25Q32 (32M-bit) Serial Flash chip.

                                                                                                                                                                                                                                                                                                              From the W25Q32 Datasheet:

                                                                                                                                                                                                                                                                                                              It provides a storage solution for systems with limited space, pins and power. The 25Q series offers flexibility and performance well beyond ordinary Serial Flash devices. They are ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI (XIP) and storing voice, text and data. The devices operate on a single 2.7V to 3.6V power supply with current consumption as low as 5mA active and 1\u00b5A for power-down. All devices are offered in space-saving packages.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/06-yd-2040/#demo-program","title":"Demo Program","text":"

                                                                                                                                                                                                                                                                                                              This program shows the blue LED flashing and the NeoPixel cycling through colors. You can press the USR button to change the cycle speed.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/06-yd-2040/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Walmart
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/","title":"Adding A Display to Your Project","text":"

                                                                                                                                                                                                                                                                                                              In the past, the memory available in an standard Arduino Uno (2K bytes) was too small to add high quality displays. With the arrival of the ESP32 and the Raspberry Pi Pico this has all changed. These microcontrollers have around 100 times that RAM - typically around 200K bytes. So we are integrating low-cost OLED displays into many of our CoderDojo projects!

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#display-types","title":"Display Types","text":"

                                                                                                                                                                                                                                                                                                              There are four main types of display technology that use for small microcontrollers.

                                                                                                                                                                                                                                                                                                              1. LED - Light Emitting Diode - these are often low-resolution but have larger area. The start with single color displays but there are also multi-color LED strips and LED matrix displays.
                                                                                                                                                                                                                                                                                                              2. OLED - Organic Light Emitting Diode - small low-cost and high-contrast monochrome displays used in watches.
                                                                                                                                                                                                                                                                                                              3. LCD - Liquid Crystal Display - many of these are monochrome displays that must have precise power to get consistent contrast.
                                                                                                                                                                                                                                                                                                              4. TFT - Thin Film Transistor - a type of LCD that are used for larger color screens.

                                                                                                                                                                                                                                                                                                              240X240 TFT Display

                                                                                                                                                                                                                                                                                                              Full Color LCD TFT Display SPI HD 65K Module ST7735

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#concepts","title":"Concepts","text":"

                                                                                                                                                                                                                                                                                                              Before you begin to use these displays, there are a few things to understand to use them effectively. Based on your project needs, you can use this knowledge to find the right solution for you.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#framebuffers","title":"Framebuffers","text":"

                                                                                                                                                                                                                                                                                                              A framebuffer is a copy of the display information that is resident within the RAM of the microcontroller. It must be as large as the display. For a 128X64 monochrome display this would be 128 * 64 = 8192 bits or 1,024 bytes (1K). A full color 240X240 TFT which uses 8 bits for red, green and blue would require 3 X 8 X 240 X 240 = 1,382,400 bits or 172K bytes.

                                                                                                                                                                                                                                                                                                              Not all all displays need framebuffers. Some displays can take a series of vector drawing commands such as \"draw line\" and \"draw text\". These displays can be useful if you don't have a large amount of RAM.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#display-chip-types","title":"Display Chip Types","text":"

                                                                                                                                                                                                                                                                                                              There are two common versions:

                                                                                                                                                                                                                                                                                                              1. SSD1306 - This is the most popular and versatile chip. It can be used to drive many different types and sizes of OLEDs. The SSD1306 can be used with both the simple 4 wire I2C interface as well as the slightly faster 7 wire SPI interface. These devices have only four wires labeled VCC, GND, SDA and SCL. SDA is for data and SCL is for the clock.
                                                                                                                                                                                                                                                                                                              2. SH1106 - This is less popular version and supports the 4-wire I2C interface.
                                                                                                                                                                                                                                                                                                              3. ST7735 - This chip is used on larger color TFT displays.
                                                                                                                                                                                                                                                                                                              4. ILI9341 - This chip is used on larger TDF displays.

                                                                                                                                                                                                                                                                                                              You can usually look on the back of the display device and see what type of check controls your OLED display.

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#communication-protocols","title":"Communication Protocols","text":"

                                                                                                                                                                                                                                                                                                              In addition to the multiple types of displays and types of chips driving the displays, there are also two options on how you want to communicate between your microcontroller and the display.

                                                                                                                                                                                                                                                                                                              1. I2C - This is the most common type and only requires two wires beside power and ground. Us this as your default unless you display does not support it. The original specification of I2C had a communication speed of 100K bits per second. Many systems can be run at 400K per second.
                                                                                                                                                                                                                                                                                                              2. SPI - This is a more complex interface and requires up to seven wires. Some devices only support SPI interfaces. SPI typically runs around 1M bits/second although it can go up to 10M bits/second in some applications. SPI is ideal when you want to transfer a large amount of display data to a screen quickly.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#basic-draw-functions","title":"Basic Draw Functions","text":"

                                                                                                                                                                                                                                                                                                              For our beginning labs we will just do some basic drawing. We will start out with just four functions:

                                                                                                                                                                                                                                                                                                              1. Initialize the display framebuffer memory with the right object class initialization
                                                                                                                                                                                                                                                                                                              2. Fill the framebuffer will zeros which are black pixels with the oled.fill(0)
                                                                                                                                                                                                                                                                                                              3. Draw white text in the framebuffer memory with the oled.text(\"Hello World!\", 40, 10)
                                                                                                                                                                                                                                                                                                              4. Send the entire framebuffer to the display over the bus with the oled.show() function.
                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#initializing-the-framebuffer","title":"Initializing the Framebuffer","text":"

                                                                                                                                                                                                                                                                                                              Let's assume that we have a four wire OLED that uses the popular SSD1306 chip with 128X64 pixels. We call our oled \"oled\" using the following line:

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\noled = SSD1306_I2C(128, 64, i2c)\n
                                                                                                                                                                                                                                                                                                              Function Description Parameters oled.fill(0) Fill the display with white or black 0=black and 1=white oled.text(\"Hello\", Draw text String, x (horizontal from left edge) and y (vertical from the top)Example: Draw \"Hello World\" 40 over and 10 down. oled.text(\"Hello World!\", 40, 10) show Show the display Send the current frame buffer to the display. You must do this after you make and changes to the Framebuffer.

                                                                                                                                                                                                                                                                                                              The full program would look like this:

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\noled = SSD1306_I2C(128, 64, i2c)\noled.fill(0)\noled.text(\"Hello World!\", 0, 0)\noled.show()\n

                                                                                                                                                                                                                                                                                                              This would display the following:

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#full-list-of-drawing-functions","title":"Full list of Drawing Functions","text":"

                                                                                                                                                                                                                                                                                                              Every drawing library might have slightly different functions. But we can quickly see the functions that we want by using the dir() function on the SSD1306_I2C class.

                                                                                                                                                                                                                                                                                                              from ssd1306 import SSD1306_I2C\nprint(dir(SSD1306_I2C))\n
                                                                                                                                                                                                                                                                                                              This returns the following list:

                                                                                                                                                                                                                                                                                                              ['__class__', '__init__', '__module__', '__name__', '__qualname__',\n'__bases__', '__dict__', 'blit', 'fill', 'fill_rect', 'hline',\n'invert', 'line', 'pixel', 'rect', 'scroll', 'text', 'vline',\n'init_display', 'write_cmd', 'show', 'poweroff', 'poweron',\n'contrast', 'write_data']\n
                                                                                                                                                                                                                                                                                                              Technically, these are called methods of the SSD1306_I2C class. The ones that begin and end with double underscores are class methods for creating new object instances. The rest of the items on the list are the drawing functions.

                                                                                                                                                                                                                                                                                                              The following are relevant for the SSD1306_I2C display.

                                                                                                                                                                                                                                                                                                              The display has (0,0) in the upper left corner. X is horizontal (width) and Y is vertical (height). The state is 0=off (black) and 1=on (white).

                                                                                                                                                                                                                                                                                                              Function Description Example blit fill(state) Fill Fill with black (0) or white(1) fill_rect Fill a rectangle hline(x1, x2, y, state) Draw a horizontal line Draw a horizontal line at the top of the display: oled.hline(0, 0, 127, 1) invert invert the display line(x1,y1,x2,y2) draw a line at any angle Horizontal oled.line(0,0, 127, 63, 1) pixel Draw a single point on the screen rect Draw an empty rectangle scroll Scroll the display text Write text at a point vline Draw a Vertical Line oled.vline(width - 1, 0, height - 1, 1) # right edge init_display Initialize the display write_cmd Write a command to the display show Update the display from the frame buffer poweroff poweron contrast write_data"},{"location":"getting-started/10-displays/#interfaces","title":"Interfaces","text":""},{"location":"getting-started/10-displays/#i2c","title":"I2C","text":"

                                                                                                                                                                                                                                                                                                              Pros: Simple four wire interface

                                                                                                                                                                                                                                                                                                              Pin Purpose Description"},{"location":"getting-started/10-displays/#spi","title":"SPI","text":"

                                                                                                                                                                                                                                                                                                              Example: 128X64 pixel monochrome displays

                                                                                                                                                                                                                                                                                                              "},{"location":"getting-started/10-displays/#types-of-displays","title":"Types of Displays","text":""},{"location":"getting-started/10-displays/#summary-table","title":"Summary Table","text":"Display Type Cost Links Notes"},{"location":"getting-started/10-displays/#lcd","title":"LCD","text":""},{"location":"getting-started/10-displays/#oled","title":"OLED","text":""},{"location":"getting-started/10-displays/#tft-displays","title":"TFT Displays","text":""},{"location":"getting-started/10-displays/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              ST7735 Micropython Driver by Anthony Norman

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/","title":"About MicroPython for Kids","text":"

                                                                                                                                                                                                                                                                                                              The this site provides a rich collection of resources to teach computational thinking to students from 10 to 16 years old using fun Python programs that control the physical world around us.

                                                                                                                                                                                                                                                                                                              The sub-field of computer science that reads sensors and controls lights and motors is called Physical Computing. We cover physical computing in our next section.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#content-licenses","title":"Content Licenses","text":"

                                                                                                                                                                                                                                                                                                              All the content on this website is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike. This means if your preserve the attribution and license you can use the content for free in your classrooms and modify and extend the curriculum to meet your needs. However, you can not charge your students additional feeds for the content or resell the content.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#contributing-to-this-website","title":"Contributing to This Website","text":"

                                                                                                                                                                                                                                                                                                              We invite all students, teachers and mentors to help us build a better website. You can read our publishing process on the CoderDojo Twin Cities Content Authoring Guide.

                                                                                                                                                                                                                                                                                                              Please make sure you using original content and avoid using any images that you have not created yourself. It is always a good idea to have a friend check your spelling, typos and links.

                                                                                                                                                                                                                                                                                                              There are several ways to contribute to get your content on this website.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#git-pull-requests","title":"Git Pull Requests","text":"

                                                                                                                                                                                                                                                                                                              If you know how, you can student submit a Git Pull Request. This tells our team that you have content to contribute. Don't be scared about learning how to do this. There are lots of examples online and please reach out if you are having trouble. This is our preferred approach, but we realize that the first time you do this there are several things you need to know.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#adding-a-new-issues","title":"Adding a New Issues","text":"

                                                                                                                                                                                                                                                                                                              You can just open a new [Issue](https://github.com/CoderDojoTC/micropython/issues and put your content in Markdown. You will also need to tell us where you store any images and videos. It might take us some time get this content into a new release.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#let-us-setup-a-edit-page","title":"Let Us Setup a Edit Page","text":"

                                                                                                                                                                                                                                                                                                              If learning how to do pull requests is too daunting for you, don't worry! You are not alone. If you want us to setup a web page you can edit using the simple \"Edit\" button on GitHub we can do that for you. Just tell us where you want the page located and give us your GitHub ID and we will set this up. You will need to let us know when your content is ready to be merged in to our releases.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/01-about/#manual-methods","title":"Manual Methods","text":"

                                                                                                                                                                                                                                                                                                              What if you have an urgent class coming up and don't have time to learn Markdown? If this happens, you can send us your raw content in MS-Word, PowerPoint or a Google Doc. Since we are an all-volunteer organization, we will need time to find a volunteer to convert your content into Markdown. All urgent requests should go to:

                                                                                                                                                                                                                                                                                                              info@codesavvy.org

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/","title":"What is Physical Computing?","text":"

                                                                                                                                                                                                                                                                                                              Physical Computing is the process of using computers to read data from sensors about the world around us and then taking actions on this incoming data stream. These actions are typically doing things like blinking and LED, moving a motor or updating a display.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#physical-computing-in-teaching-computational-thinking","title":"Physical Computing in Teaching Computational Thinking","text":"

                                                                                                                                                                                                                                                                                                              Physical computing plays an important role in teaching the core concepts in Computational Thinking. Often times students quickly lose interest when only abstract concepts are used. Physical computing allows direct hands-on experiences that keeps students engaged and gives them immediate feedback. Although our labs start slowly with simply blinking LEDs, they quick move to controlling motors and building robots.

                                                                                                                                                                                                                                                                                                              The material in this website is designed to leverage everything we have learned to make our lessons be fun, engaging and allow students to come up with their own ideas for project-based learning.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#why-physical-computing-has-become-so-popular","title":"Why Physical Computing Has Become So Popular","text":"

                                                                                                                                                                                                                                                                                                              In the past, the chips we used to teach physical computing (called microcontrollers) were slow, had huge memory limitations, and were expensive. They were also hard to program and since we could not use the Python language that is popular in most classrooms today.

                                                                                                                                                                                                                                                                                                              This all changed in January of 2021 when the Raspberry Pi Foundation released a $4 microcontroller called the Pico that has 200 times the memory of the most popular microcontroller (The $25 Arduino Uno). Now teachers could purchase an entire classroom full of microcontrollers that were powerful enough to even do machine learning.

                                                                                                                                                                                                                                                                                                              One way to measure the cost effectiveness of this system is to compare the cost per kilobyte of RAM. The Arduino Uno was about $12.50 per kilobyte. The new Raspberry Pi Pico, with 264K RAM cost only 2 cents per kilobyte!

                                                                                                                                                                                                                                                                                                              There was also one other HUGE advantage of these microcontrollers. They ran Python! Python is the most popular language for students today. There are millions of on-line websites that show kids how to learn Python like our own CoderDojo Beginning Python classes. Teachers now had the big three factors:

                                                                                                                                                                                                                                                                                                              1. Low cost ($4)
                                                                                                                                                                                                                                                                                                              2. Powerful (264K RAM)
                                                                                                                                                                                                                                                                                                              3. Runs Python - the most popular language for teaching

                                                                                                                                                                                                                                                                                                              But there was a small problem. Although there were millions of sample programs for the old under-powered Arduino microcontrollers, we needed high-quality lessons for our students to learn to use the new microcontrollers. And these lessons need to be flexible so teachers around the world could build new courses out of this content without having to purchase expensive textbooks. That is why this website is so important. We hope you see how excited we are to bring you this new content!

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#examples-of-sensors","title":"Examples of Sensors","text":"

                                                                                                                                                                                                                                                                                                              Here are some sample sensors that we use:

                                                                                                                                                                                                                                                                                                              1. Buttons and switches
                                                                                                                                                                                                                                                                                                              2. Light sensors (photoresistor)
                                                                                                                                                                                                                                                                                                              3. Distance sensor (both ultrasonic and light)
                                                                                                                                                                                                                                                                                                              4. Sound sensors
                                                                                                                                                                                                                                                                                                              5. Motion and acceleration sensors
                                                                                                                                                                                                                                                                                                              6. Gesture sensors
                                                                                                                                                                                                                                                                                                              7. Magnetic field sensors (like a compass)
                                                                                                                                                                                                                                                                                                              8. Heat sensors
                                                                                                                                                                                                                                                                                                              9. Touch sensor
                                                                                                                                                                                                                                                                                                              10. Voltage and current sensors
                                                                                                                                                                                                                                                                                                              11. Orientation and tilt sensors
                                                                                                                                                                                                                                                                                                              12. Water and moisture sensors
                                                                                                                                                                                                                                                                                                              13. Chemistry sensors such as Ph level (acidity)
                                                                                                                                                                                                                                                                                                              14. Smoke and gas sensors
                                                                                                                                                                                                                                                                                                              15. Air quality sensors
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#examples-of-actuators","title":"Examples of Actuators","text":"

                                                                                                                                                                                                                                                                                                              Here are some of the Actuators we use:

                                                                                                                                                                                                                                                                                                              1. LEDs
                                                                                                                                                                                                                                                                                                              2. Motors (simple DC motors)
                                                                                                                                                                                                                                                                                                              3. Servos
                                                                                                                                                                                                                                                                                                              4. Displays (character displays, graphic displays)
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#what-are-the-challenges-in-physical-computing","title":"What are the Challenges in Physical Computing","text":"

                                                                                                                                                                                                                                                                                                              In the real world, sensor data can be complex. We often need to look for complex patterns in an incoming data stream. For example, how can we detect complex motion such as gestures from a simple distance measurement? Other questions that we have to consider include:

                                                                                                                                                                                                                                                                                                              1. How often should we sample the data provided by a sensor?
                                                                                                                                                                                                                                                                                                              2. How to we calibrate sensors to get accurate readings?
                                                                                                                                                                                                                                                                                                              3. How do we convert sensor data into forms that are easy to use?
                                                                                                                                                                                                                                                                                                              4. How can we look for patterns in data? Can we detect specific sounds or speech?
                                                                                                                                                                                                                                                                                                              5. How can use use machine learning to train a model to detect specific patterns such as a \"wake word\" in a smart speaker system?
                                                                                                                                                                                                                                                                                                              6. If you have allergies, what types of sensors could tell you how bad the pollen counts are outside today?
                                                                                                                                                                                                                                                                                                              7. How can we send data back to a central server?
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#questions-for-discussion","title":"Questions for Discussion","text":"
                                                                                                                                                                                                                                                                                                              1. What other sensors and actuators can you think of?
                                                                                                                                                                                                                                                                                                              2. How would you determine how much battery power is left in your robot?
                                                                                                                                                                                                                                                                                                              3. Can you give an example of a sensor in your house that is used to regulate temperature?
                                                                                                                                                                                                                                                                                                              4. Can you name a sensor in your house that could save your life?
                                                                                                                                                                                                                                                                                                              5. How many sensors do you think a typical car has?
                                                                                                                                                                                                                                                                                                              6. What data could you gather and sell?
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Wikipedia on Physical Computing in Education
                                                                                                                                                                                                                                                                                                              2. Sample Sensor Kit on Amazon
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#answers-to-discussion-questions","title":"Answers to Discussion questions","text":"
                                                                                                                                                                                                                                                                                                              • You would use a voltage sensor to see how much power is available in a battery.
                                                                                                                                                                                                                                                                                                              • The name of a device that controls the temperature in your home is called a thermostat. It tells your home furnace or air conditioner to go on or off.
                                                                                                                                                                                                                                                                                                              • Smoke detectors and carbon monoxide detectors are examples of devices that save thousands of lives every year. According the the New York Department of Health presence of a working smoke alarm in a home reduces the risk of dying in a fire by about 50%. Worldwide, over 10,000 lives are saved every year by smoke detectors. Freakonomics
                                                                                                                                                                                                                                                                                                              • A modern car has almost 100 sensors in it. This includes motor sensors and sensors to detect if your doors are closed and your seatbelt is fastened.
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/02-physical-computing/#references_1","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • How a Small Charity is Upsetting the Trillion-Dollar Silicon Chip Industry
                                                                                                                                                                                                                                                                                                              • [Raspberry Pi Pico Robot in Micropython] (https://dmccreary.medium.com/raspberry-pi-pico-robot-in-micropython-51f956486270)
                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/","title":"Microcontrollers","text":"

                                                                                                                                                                                                                                                                                                              Left to right: Raspberry Pi Pico, Cytron Maker Pi Nano, Cytron Maker Pi 2040, Cytron Maker Pi Pico, ESP-32, ESP TTGO

                                                                                                                                                                                                                                                                                                              This lesson is an overview of microcontrollers and their role in teaching physical computing.

                                                                                                                                                                                                                                                                                                              A microcontroller is a small low-cost computer used to control physical devices such as LED, servos and motors. Microcontroller boards typically cost around $4 to $6 and are an ideal way to learn about computer science because you can use them to build fun projects. For example you can control a row of LEDs, move a robot and sense the world around us with a variety of light, sound and motion sensors.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#types-of-microcontroller-boards-used-in-these-labs","title":"Types of Microcontroller Boards Used in These Labs","text":"

                                                                                                                                                                                                                                                                                                              We use a variety of microcontroller boards that are based on either the Raspberry Pi RP2040 chip or the ESP32. The boards we use are all low-cost (under $10) but have a variety of on-board devices such as buttons, LEDs, speakers and motor controllers. Which board you use depends on how many of these components you need in your projects. The RP2040 has 264K RAM and the ESP32 has 520K RAM.

                                                                                                                                                                                                                                                                                                              Some of the boards are mounted on breadboards and others use Grove connectors to connect sensors and actuators.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#raspberry-pi-pico","title":"Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              This microcontroller is low cost (retail list price is $4) and can be mounted directly on a breadboard. The Pico has just a single LED and no buttons.

                                                                                                                                                                                                                                                                                                              In the past, microcontrollers were difficult for younger students to program. They were also too expensive for every student to purchase and take home. A typical Arduino kit could easily cost over $20 and required you to learn C to program it.

                                                                                                                                                                                                                                                                                                              Today, microcontrollers such as the Raspberry Pi Pico and the ESP32 cost as little as four dollars. And these devices are designed to be programmed in Python, the most popular programming language for students.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#what-is-physical-computing","title":"What is Physical Computing?","text":"

                                                                                                                                                                                                                                                                                                              Physical Computing is a field of study that can sense and respond to the world around us. Unlike programming a cell phone or a laptop computer, our focus is reading sensor values and quickly responding to changes. Physical Computing is widely used to teach principals of computer science because students can create their own projects and express creativity such a controlling the patterns of lights or creating complex sounds.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#how-microcontrollers-are-used","title":"How Microcontrollers are Used","text":"

                                                                                                                                                                                                                                                                                                              Microcontrollers do three things:

                                                                                                                                                                                                                                                                                                              1. They read sensor values of the world around them
                                                                                                                                                                                                                                                                                                              2. They transform this data into useful representations
                                                                                                                                                                                                                                                                                                              3. They send outputs to devices that control the world such as LEDs and motors as well as displays

                                                                                                                                                                                                                                                                                                              Here is a general diagram to think about when you are designing microcontroller systems:

                                                                                                                                                                                                                                                                                                              Here is a specific example instance of what inputs and outputs might do.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#programming-a-microcontroller","title":"Programming a Microcontroller","text":"

                                                                                                                                                                                                                                                                                                              In this class, we will use the MicroPython to program our Microcontroller.

                                                                                                                                                                                                                                                                                                              Our programs will usually have the following structure:

                                                                                                                                                                                                                                                                                                              1. Imports: Specify the Python libraries used in the code (More Information on Python libraries are available here)
                                                                                                                                                                                                                                                                                                              2. Setup: Setup/ Initialize variables and sensors
                                                                                                                                                                                                                                                                                                              3. Main loop: Continuously monitor sensor inputs and take actions

                                                                                                                                                                                                                                                                                                              The following is an example code in Micropython:

                                                                                                                                                                                                                                                                                                              # Import Section\nimport machine\nimport time\n\n# Setup Section\nled = machine.Pin(16, machine.Pin.OUT)\n\n# Main Loop\nwhile True:\n    led.high()\n    time.sleep(0.5)\n    led.low()\n    time.sleep(0.5)\n

                                                                                                                                                                                                                                                                                                              Almost all our programs will start with the import machine line. This tells the system that we need to gather all the libraries that understand our physical machine.

                                                                                                                                                                                                                                                                                                              If you couldn't understand the example program - don't worry! We will be going through it in detail as we work on our labs.

                                                                                                                                                                                                                                                                                                              "},{"location":"intro/03-microcontrollers/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Listing of RP2040-based Boards on the Raspberry Pi Foundation Website
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/","title":"Kits for Learning MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This section review several kits for learning MicroPython. Most of them use the RP2040 chip, but there are some that also use the ESP32 when wireless communication is needed.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#solderless-connectors","title":"Solderless Connectors","text":"

                                                                                                                                                                                                                                                                                                              There are several types of solderless connectors used in these kits. They connect sensors and motors to these kits without the need for soldering. They are ideal for student labs that don't want the fire-hazards associated with soldering or where solderless breadboards and hot-glue is not flexible enough.

                                                                                                                                                                                                                                                                                                              These are usually 3 and 4-wire connectors that support analog and digital input and output as well as I2C bus and UART communications. They are typically designed to carry about 1 amp of current.

                                                                                                                                                                                                                                                                                                              • Grove Connectors - popular with Seeed and Cyton kits. See the manual here
                                                                                                                                                                                                                                                                                                              • Qwiic - SparkFun I2C connector
                                                                                                                                                                                                                                                                                                              • Stemma and Stemma QT - Adafruit connectors are built around standard JST PH 2mm spacing connectors.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#example-kits","title":"Example Kits","text":"

                                                                                                                                                                                                                                                                                                              The following list is not design to be an exhaustive list of all MicroPython development kits available on the market. We focus on value-based kits that will help our students have fun learning computational thinking.

                                                                                                                                                                                                                                                                                                              • Basic Kit - Our standard labs use a $4 Raspberry Pi Pico on a $2 solderless breadboard. You will also need some 22-gauge wire or a jumper wire kit.
                                                                                                                                                                                                                                                                                                              • Maker Pi RP2040 Kit - this is a $9.90 kit from Cytron that features a single board with many features for small robots. It is an ideal low-cost starter kit.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#searching-sparkfun","title":"Searching SparkFun","text":"

                                                                                                                                                                                                                                                                                                              You can also use the MicroPython \"tag\" to search all the kits on the SparkFun site:

                                                                                                                                                                                                                                                                                                              https://www.sparkfun.com/categories/tags/micropython

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Here are kits that we have seen but have not yet evaluated:

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#waveshare-picogo-robot","title":"Waveshare PicoGo Robot","text":"

                                                                                                                                                                                                                                                                                                              PicoGo Mobile Robot is a $43 robot based on Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              1. SKU: 20380
                                                                                                                                                                                                                                                                                                              2. Part Number: PicoGo-EN
                                                                                                                                                                                                                                                                                                              3. Powered by 2x 14500 Li-ion batteries. NOTE! We don't recommend these for classroom use since they are a fire hazard.
                                                                                                                                                                                                                                                                                                              4. Battery protection circuit: over charge/discharge protection, over current protection, short circuit protection, reverse proof, more stable and safe operating Recharge/Discharge circuit, allows programming/debugging concurrently while recharging
                                                                                                                                                                                                                                                                                                              5. 5-ch infrared sensor, analog output, combined with PID algorithm, stable line tracking Onboard multiple smart robot sensors like line tracking, obstacle avoidance, no more messy wiring
                                                                                                                                                                                                                                                                                                              6. 1.14 inch IPS colorful LCD display, 240 x135 pixels, 65K colors
                                                                                                                                                                                                                                                                                                              7. Integrates Bluetooth module, allows teleoperations like robot movement, RGB LED display color, buzzer, etc. by using mobile phone APP
                                                                                                                                                                                                                                                                                                              8. N20 micro geared motors, with metal gears, low noise, high accuracy
                                                                                                                                                                                                                                                                                                              9. NeoPixel
                                                                                                                                                                                                                                                                                                              10. Line following sensors

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/01-intro/#getting-started-kits","title":"Getting Started Kits","text":""},{"location":"kits/01-intro/#vilros-getting-started-kit","title":"Vilros Getting Started Kit","text":"

                                                                                                                                                                                                                                                                                                              Vilros Getting Started With MicroPython on Raspberry Pi Pico Kit

                                                                                                                                                                                                                                                                                                              This kit includes:

                                                                                                                                                                                                                                                                                                              1. List price is $44.99
                                                                                                                                                                                                                                                                                                              2. Raspberry Pi Pico with soldered headers
                                                                                                                                                                                                                                                                                                              3. Includes printed Vilros Get Started with MicroPython on Raspberry Pi Pico booklet
                                                                                                                                                                                                                                                                                                              4. USB Type-A to micro cable - 1 meter
                                                                                                                                                                                                                                                                                                              5. 3AA battery pack with micro USB connector
                                                                                                                                                                                                                                                                                                              6. 30 \u00d7 Jumper wires
                                                                                                                                                                                                                                                                                                              7. 12 LEDs: 3x red, 3x blue,3x yellow and 3x green
                                                                                                                                                                                                                                                                                                              8. 5 Push-button switches
                                                                                                                                                                                                                                                                                                              9. 10 330 \u03a9 resistors
                                                                                                                                                                                                                                                                                                              10. Piezoelectric buzzer
                                                                                                                                                                                                                                                                                                              11. 2 10 k\u03a9 potentiometers
                                                                                                                                                                                                                                                                                                              12. HC-SR501 PIR sensor
                                                                                                                                                                                                                                                                                                              13. I2C 1602 character LCD module
                                                                                                                                                                                                                                                                                                              14. WS2812B LED strip
                                                                                                                                                                                                                                                                                                              15. Clear hard plastic box for small part storage
                                                                                                                                                                                                                                                                                                              16. Neoprene case With pocket
                                                                                                                                                                                                                                                                                                              17. Raspberry Pi Pico pinout guide

                                                                                                                                                                                                                                                                                                              The only problem with the parts is the lack of connectors for the potentiometers don't work well directly on the breadboard. You will need to solder wires to use them on the breadboard.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/microbit/","title":"MicroBit","text":"

                                                                                                                                                                                                                                                                                                              Although the BBC MicroBit is a good educational product for learning MicroPython, we don't use it in our MicroPython courses for the following reason:

                                                                                                                                                                                                                                                                                                              1. Price - The current price on sites like Amazon is around $22. We can get the Raspberry Pi Pico for $4.
                                                                                                                                                                                                                                                                                                              2. Availability - MicroBits have not been available due to shortages of chips that it needs.
                                                                                                                                                                                                                                                                                                              3. Memory - The MicroBit only has 32KB of RAM. The Pico has 256K. We need this extra RAM for our OLED display labs.
                                                                                                                                                                                                                                                                                                              4. Breadboard - We use simple, standardized, easy-to-upgrade breadboards in our classes. This makes it easy to upgrade our microcontrollers and promotes higher sustainability. We also believe that teaching breadboarding skills is critical for future projects.
                                                                                                                                                                                                                                                                                                              5. Expandability - we like the ability to expand our base labs to include many low costs sensors
                                                                                                                                                                                                                                                                                                              6. Multi-Core - we want to be able to teach multi-core coding in our classrooms. Because the MicroBit only has a single core this is not possible on the MicroBit. The Raspberry Pi Pico has two cores. Many projects use one core for monitoring the sensors and another core for doing analysis and updating the display.
                                                                                                                                                                                                                                                                                                              7. Pulse Width Modulation Channels - The MicroBit only has 3 PWM channels. We need a minimum of 4 to drive our robots.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/microbit/#side-by-side-comparision","title":"Side-By-Side Comparision","text":"Feature Name MicroBit v2 Raspberry Pi Pico Notes Price $22 $4 The Pico \"W\" with wireless is $6 Breadboard No Yes Allows us to teach breadboarding skills RAM 32MB 256MB We need around 100MB to support our 128x64 OLED frame buffers Flash 2MB 512MB We use extra flash to store hundreds of programs, images and sounds Sensors Temp,Accelerometers,Compass,Light,Touch Temp For about $5 we can add these sensors to the Pico Processor ARM Cortex-M4 Dual-core Arm Cortex-M0+ The M4 has better support for DSP and floating point LEDs 25 1 We use 8X8 LEDs and NeoPixels in our labs to create similar displays Block Programming Microsoft MakeCode BIPES Block coding is great for younger students that don't have strong keyboarding skills GPIOs 20 26 This has not been a concern. None of our labs need over 20 GPIOs ADCs 5 3 Also not a concern. None of our labs need more that 3 Analog to Digital converters that run concurrently Serial Bus 1 I2C, 1 SPI 2x UART, 2x I2C, 2x SPI, up to 16 PWM channels Pulse Width Modulation 3 16 We need 4 PWM to drive our robots (a forward and back for each motor)"},{"location":"kits/microbit/#sample-sources","title":"Sample Sources","text":""},{"location":"kits/microbit/#microcenter","title":"Microcenter","text":"
                                                                                                                                                                                                                                                                                                              • MicroCenter MicroBit Go Bundle for $22.92 - includes USB cable and battery pack
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/microbit/#sparkfun","title":"SparkFun","text":"
                                                                                                                                                                                                                                                                                                              • Pico for $3.99
                                                                                                                                                                                                                                                                                                              • Microbit for $22
                                                                                                                                                                                                                                                                                                              • Breakout Board for Breadboards $7
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/microbit/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Cytron
                                                                                                                                                                                                                                                                                                              • Pico:ed V2 - a RP2040 in MicroBit Form Factor
                                                                                                                                                                                                                                                                                                              • Pico:ed $12
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/","title":"Larson Scanner Pumpkin","text":"

                                                                                                                                                                                                                                                                                                              The Larson Scanner is a light pattern special effect named after Glen A. Larson. Larson used this pattern to give his Battlestar Galactica Cylon and KITT robot eyes a sense of sentience. See Knight Rider for the backstory.

                                                                                                                                                                                                                                                                                                              This project uses a 144 pixel/meter LED strip and a Raspberry Pi Pico to produce this effect.

                                                                                                                                                                                                                                                                                                              I used a craft pumpkin from Michaels. I cut a slit in it and used hot-glue to hold the LED strip in place.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/#parts-list","title":"Parts List","text":"
                                                                                                                                                                                                                                                                                                              1. 9\" Craft Pumpkin from Micheals $10
                                                                                                                                                                                                                                                                                                              2. Raspberry Pi Pico ($4)
                                                                                                                                                                                                                                                                                                              3. Breadboard ($2)
                                                                                                                                                                                                                                                                                                              4. 27 pixels of WS2811B NeoPixel Strip 144 pixels per meter preferred ($8)
                                                                                                                                                                                                                                                                                                              5. 3 AA battery pack or a USB battery pack

                                                                                                                                                                                                                                                                                                              This is a screen image from e-bay showing a 1/2 meter of LED strip for $8.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/#sample-code","title":"Sample Code","text":"

                                                                                                                                                                                                                                                                                                              This code shows a five-pixel wide \"eye\" moving back-an-forth over a 27 pixel strip. There is a central bright red LED surrounded by dimmer red LEDs that move back-and-forth. We are using the NeoPixel library supplied by Bla\u017e Rolih.

                                                                                                                                                                                                                                                                                                              The example below has a delay of 1/10th of a second between drawing events. You can make the delay smaller to speed up the speed of the eye movement.

                                                                                                                                                                                                                                                                                                              from utime import sleep\n# We are using https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nNUMBER_PIXELS = 27\nSTATE_MACHINE = 0\nLED_PIN = 0\n\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n\n# Color RGB values\nred = (255, 0, 0)\nred_med = (32, 0, 0)\nred_light = (8, 0, 0)\noff = (0,0,0)\n\ndelay = .1\nwhile True:\n    for i in range(2, NUMBER_PIXELS-2):\n        strip.set_pixel(i-2, red_light)\n        strip.set_pixel(i-1, red_med)\n        strip.set_pixel(i, red)\n        strip.set_pixel(i+1, red_med)\n        strip.set_pixel(i+2, red_light)\n        if i > 0: strip.set_pixel(i-3, off)\n        strip.show()\n        sleep(delay)\n    for i in range(NUMBER_PIXELS-4, 1, -1):\n        if i < NUMBER_PIXELS-2: strip.set_pixel(i+3, off)\n        strip.set_pixel(i-2, red_light)\n        strip.set_pixel(i-1, red_med)\n        strip.set_pixel(i, red)\n        strip.set_pixel(i+1, red_med)\n        strip.set_pixel(i+2, red_light)\n        strip.show()\n        sleep(delay)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/#adding-some-color","title":"Adding Some Color","text":"

                                                                                                                                                                                                                                                                                                              The pattern above is faithful to the original Cylon robot pattern, but to be honest, it is a little boring. We can spruce it up a bit by adding some color and the comet-tail pattern.

                                                                                                                                                                                                                                                                                                              This program cycles through a \"moving rainbow\" pattern and then the comet pattern for 10 colors.

                                                                                                                                                                                                                                                                                                              from utime import sleep\n# We are using https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nNUMBER_PIXELS = 25\nSTATE_MACHINE = 0\nLED_PIN = 0\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n\n# Color RGB values\nred = (255, 0, 0)\noff = (0,0,0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\ncyan = (255, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet)\n\n# set to be 1 to 100 for percent brightness\nstrip.brightness(100)\n\ndef draw_eye_7(r, g, b):\n    for i in range(6, NUMBER_PIXELS): \n        strip.set_pixel(i, (r, g, b))\n        # step back from the current to 6 back halfing the intensity each time\n        for j in range(0,7):\n            strip.set_pixel(i-j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j))))\n        if i > 6: strip.set_pixel(i-7, (0,0,0))\n        strip.show()\n        sleep(delay)\n        strip.set_pixel(i, off)\n    for i in range(NUMBER_PIXELS-6, 0, -1):\n        strip.set_pixel(i, (r, g, b)) \n        for j in range(7,0):\n            strip.set_pixel(i+j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j))))\n        if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0))\n        strip.show()\n        sleep(delay)\n\ndef draw_rainbow():\n    for i in range(0, NUMBER_PIXELS-7):\n        strip.set_pixel(i, violet)\n        strip.set_pixel(i+1, indigo)\n        strip.set_pixel(i+2, blue)\n        strip.set_pixel(i+3, green)\n        strip.set_pixel(i+4, yellow)\n        strip.set_pixel(i+5,orange)\n        strip.set_pixel(i+6, red)\n        if i > 6: strip.set_pixel(i-7, (0,0,0))\n        strip.show()\n        sleep(delay)\n        strip.set_pixel(i, off)\n    for i in range(NUMBER_PIXELS-7, 1, -1):\n        strip.set_pixel(i, red)\n        strip.set_pixel(i+1, orange)\n        strip.set_pixel(i+2, yellow)\n        strip.set_pixel(i+3, green)\n        strip.set_pixel(i+4, blue)\n        strip.set_pixel(i+5, indigo)\n        strip.set_pixel(i+6, violet)\n        if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0))\n        strip.show()\n        sleep(delay)\n\n# delay = .031\n\ndelay = .06\ncolor_index = 0\nwhile True:\n    draw_rainbow()\n    draw_eye_7(255,0,0) #red\n    draw_eye_7(255,60,0) #orange\n    draw_eye_7(255,255,0) # yellow\n    draw_eye_7(0,255,0) # green\n    draw_eye_7(0,0,255) # b;ie\n    draw_eye_7(0,255,255) # cyan\n    draw_eye_7(75,30,130) # indigo\n    draw_eye_7(255,0,255) # violet\n    draw_eye_7(255,255,255) # white\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/#adding-the-cylon-scanner-sounds","title":"Adding the Cylon Scanner Sounds","text":"

                                                                                                                                                                                                                                                                                                              You can also add the Cylon eye scanner sound by addint a .wav file to the pico and using the playWave library. This is covered in the Sound and Music Play Audio File lesson of this microsite.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/larson-scanner/01-intro/#more-to-explore","title":"More to Explore","text":"
                                                                                                                                                                                                                                                                                                              1. Add a potentiometer to change the speed of the eye scan.
                                                                                                                                                                                                                                                                                                              2. Add a button to cycle through colors of the eye.
                                                                                                                                                                                                                                                                                                              3. Add multiple patterns such as a \"comet trail\" that has the first pixel brighter and the following pixels dimmer.
                                                                                                                                                                                                                                                                                                              4. Add a PIR motion sensor that will sense motion and get brighter if motion is sensed.
                                                                                                                                                                                                                                                                                                              5. Use the new I2S software to play a sound when the PIR motion sensor has been triggered.
                                                                                                                                                                                                                                                                                                              6. Use an MP3 player such as the DRF0229 to play the cylon sound when motion is detected.
                                                                                                                                                                                                                                                                                                              7. Add an OLED display and buttons to the back of the pumpkin to change the parameters of the display and the sounds.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-nano-rp2040/01-intro/","title":"Cytron Maker Nano RP2040","text":"

                                                                                                                                                                                                                                                                                                              The Cytron Nano RP2040 is a low-cost ($9), high-functionality board.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-nano-rp2040/01-intro/#features","title":"features","text":"
                                                                                                                                                                                                                                                                                                              1. Low cost: $9
                                                                                                                                                                                                                                                                                                              2. 14 GPIO blue LEDs
                                                                                                                                                                                                                                                                                                              3. 2 RGB LEDs (Neopixels)
                                                                                                                                                                                                                                                                                                              4. 1 Piezo buzzer
                                                                                                                                                                                                                                                                                                              5. 2 4-wire JST-SH ports (with Grove connectors)
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-nano-rp2040/01-intro/#blink-lab","title":"Blink Lab","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin # get the Pin function from the machine module\nfrom time import sleep # get the sleep library from the time module\n# this is the built-in green LED on the Pico\nled = machine.Pin(0, machine.Pin.OUT)\n\n# repeat forever\nwhile True:\n    led.high() # turn on the LED\n    sleep(0.5) # leave it on for 1/2 second\n    led.low() # Turn off the LED\n    sleep(0.5) # leave it off for 1/2 second\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/","title":"Cytron Maker Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              The Cytron Maker Pi Pico is a $9.99 breakout board for the Raspberry Pi Pico with many features.

                                                                                                                                                                                                                                                                                                              1. Speaker
                                                                                                                                                                                                                                                                                                              2. Stereo headphone jacks
                                                                                                                                                                                                                                                                                                              3. SD Card reader
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/#sample-labs","title":"Sample Labs","text":"
                                                                                                                                                                                                                                                                                                              1. Running Lights
                                                                                                                                                                                                                                                                                                              2. SD Card File Reader/Writer
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Cytron Maker Pi Pico Github Repo

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/02-running-lights/","title":"Running lights","text":"

                                                                                                                                                                                                                                                                                                              This program turns on all 24 blue LEDs on the board, one at a time. It then turns them all off.

                                                                                                                                                                                                                                                                                                              TODO - record a GIF or video.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime\n\n# RUNNING LIGHT\n\nfor i in range(29):                     # from 0 to 28  \n    if i != 23 and i != 24:             # pin 23 and 24 are not GPIO pins\n        machine.Pin(i,machine.Pin.OUT)  # set the pins to output\n\nwhile True:\n    for i in range(29):                      \n        if i != 23 and i != 24:      \n            machine.Pin(i).value(0)     # turn off the LED\n            utime.sleep(0.1)            # sleep for 100ms\n            machine.Pin(i).value(1)     # turn on the LED\n\n    for i in range(28,-1,-1):           # from 28 to 0\n        if i != 23 and i != 24:\n            machine.Pin(i).value(1)     # turn on the LED\n            utime.sleep(0.1)\n            machine.Pin(i).value(0)     # turn off the LED\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/02-running-lights/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              This program was taken from tje Cytron GitHub site here.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/","title":"Micro SD Card Reader","text":"

                                                                                                                                                                                                                                                                                                              Secure Digital (SD) is a non-volatile memory card format for use in portable devices such as cameras, MP3 players and portable devices.

                                                                                                                                                                                                                                                                                                              On Microcontrollers SD cards are usually access through an SPI interface although there are also devices that use I2C interfaces.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/#maker-pi-pico-connections","title":"Maker Pi Pico Connections","text":"GPIO Pin SD Mode SPI Mode GP10 CLK SCK GP11 CMD SDI GP12 DAT0 SD0 GP13 DAT1 X GP14 DAT2 X GP15 CD/DAT3 CSn"},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/#maker-pi-pico-example-code","title":"Maker Pi Pico Example Code","text":""},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/#pin-definitions","title":"Pin Definitions","text":"
                                                                                                                                                                                                                                                                                                              # SD Mode Definitions\nSDCARD_CLK = 10\nSDCARD_CMD = 11\nSDCARD_DAT0 = 12\nSDCARD_DAT1 = 13\nSDCARD_DAT2 = 14\nSDCARD_CD_DAT3 = 15\n\n# SPI Mode Definitions\nSDCARD_SCK = 10\nSDCARD_SDI = 11\nSDCARD_SD0 = 12\nSDCARD_X1 = 13\nSDCARD_X2 = 14\nSDCARD_CSn = 15\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/#sample-code-for-spi-mode","title":"Sample Code for SPI Mode","text":"
                                                                                                                                                                                                                                                                                                              import machine, os, sdcard\n\n# Assign chip select (CS) pin (and start it high)\ncs = machine.Pin(15, machine.Pin.OUT)\n# Intialize SPI peripheral (start with 1 MHz)\nspi = machine.SPI(1,\n                  baudrate=1000000,\n                  polarity=0,\n                  phase=0,\n                  bits=8,\n                  firstbit=machine.SPI.MSB,\n                  sck=machine.Pin(10),\n                  mosi=machine.Pin(11),\n                  miso=machine.Pin(12))\n# Initialize SD card\nsd = sdcard.SDCard(spi, cs)\n\n# OR this simpler initialization code should works on Maker Pi Pico too...\n#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))\n\nos.mount(sd, '/sd')\n# check the content\nos.listdir('/sd')\n\n# try some standard file operations\nfile = open('/sd/test.txt', 'w')\nfile.write('Testing SD card on Maker Pi Pico')\nfile.close()\nfile = open('/sd/test.txt', 'r')\ndata = file.read()\nprint(data)\nfile.close()\n

                                                                                                                                                                                                                                                                                                              Results:

                                                                                                                                                                                                                                                                                                              Testing SD card on Maker Pi Pico\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-pico/09-micro-sd-card-reader/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython sdcard.py driver - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266
                                                                                                                                                                                                                                                                                                              2. MicroPython.org Documentation
                                                                                                                                                                                                                                                                                                              3. Raspberry Pi Pico Forum
                                                                                                                                                                                                                                                                                                              4. YouTube Video by Shawn Hymel
                                                                                                                                                                                                                                                                                                              5. Cytron Maker Pi Pico Datasheet
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/","title":"Maker Pi RP2040 MicroPython Robotics Kit","text":"

                                                                                                                                                                                                                                                                                                              The Maker Pi PR2040 kit from Cytron Technologies is a $9.90 US kit that is designed to simplify learning robotics using the RP2040 chip. It became available in April of 2021, but demand has been very high and it is out-of-stock on many retailers sites. We can understand this. The Maker Pi PR2040 is the most powerful robotics board we have ever seen for under $10!

                                                                                                                                                                                                                                                                                                              The photo above is our base robot kit. It includes the Maker Pi RP2040 board mounted on a standards Smart Car chassis. The image above shows the Time-of-flight distance sensor mounted in the front below the chassis. Note that the batteries are mounted on the bottom of the robot.

                                                                                                                                                                                                                                                                                                              Below is the top view of the Cytron Maker Pi RP2040 robotics board.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#features","title":"Features","text":"

                                                                                                                                                                                                                                                                                                              All our robots are built around a RP2040 and a motor driver with a few low-cost sensors and displays. With the exception of the OLED display, this board packs in a huge number of features for a low cost of $9.90.

                                                                                                                                                                                                                                                                                                              • Power status LED (green)
                                                                                                                                                                                                                                                                                                              • On/off switch
                                                                                                                                                                                                                                                                                                              • 13 blue LEDs to show status on GP pins 0,1,2,3,4,5,6,16,17,26,27 and 28
                                                                                                                                                                                                                                                                                                              • 2 WS2812B RGB LEDs connected to GP18
                                                                                                                                                                                                                                                                                                              • LiPo Battery Connector
                                                                                                                                                                                                                                                                                                              • Micro USB Port (use for powering and programming)
                                                                                                                                                                                                                                                                                                              • Reset button
                                                                                                                                                                                                                                                                                                              • Boot button
                                                                                                                                                                                                                                                                                                              • Momentary press buttons on ports GP20 and GP21
                                                                                                                                                                                                                                                                                                              • 2 Motor drivers. Motor A is controlled by GP8 and GP10 and motor B is controlled by GP9 and GP11.
                                                                                                                                                                                                                                                                                                              • 4 motor test buttons for testing motors A and B, forward and backward
                                                                                                                                                                                                                                                                                                              • 4 red motor status LEDs buttons for displaying motors A and B, forward and backward
                                                                                                                                                                                                                                                                                                              • 7 Grove Ports on GPs 1:0,1; 2:2,3; 3:4,5; 4:16,17; 5:6,26; 6:26,27 and 7:7,28
                                                                                                                                                                                                                                                                                                              • 4 servo connectors on ports GP12, GP13, GP14 and GP15
                                                                                                                                                                                                                                                                                                              • Piezo buzzer on port GP22
                                                                                                                                                                                                                                                                                                              • On/Off switch on GP22 which can be used to mute the sound
                                                                                                                                                                                                                                                                                                              • Phillips head screwdriver that works on the header pins - really convenient for students!
                                                                                                                                                                                                                                                                                                              • 4 Grove Connectors
                                                                                                                                                                                                                                                                                                              • Rubber mounting feet
                                                                                                                                                                                                                                                                                                              • Pins numbers clearly labeled both on top and bottom of the board
                                                                                                                                                                                                                                                                                                              • Large area on bottom of the board for students to write their name
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#list-of-labs","title":"List of Labs","text":""},{"location":"kits/maker-pi-rp2040/#part-1-no-accessories-required-labs","title":"Part 1: No Accessories Required Labs","text":"

                                                                                                                                                                                                                                                                                                              These labs don't need anything except the Maker Pi RP2040 board.

                                                                                                                                                                                                                                                                                                              1. Blue LED Lab - make the blue GPIO status LEDs show cool patterns
                                                                                                                                                                                                                                                                                                              2. NeoPixel Lab - make the two NeoPixel each display many colors
                                                                                                                                                                                                                                                                                                              3. Button Lab - make the two buttons change the state of system
                                                                                                                                                                                                                                                                                                              4. Sound Lab - make the Piezoelectric Buzzer create sounds
                                                                                                                                                                                                                                                                                                              5. Up Down Mode Lab - make the buttons change the LEDs, NeoPixels and Sound
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#part-2-motor-and-servo-labs","title":"Part 2: Motor and Servo Labs","text":"

                                                                                                                                                                                                                                                                                                              These labs require additional parts such as DC hobby motors and servos

                                                                                                                                                                                                                                                                                                              1. Motor Connection Lab - make two motors turn forward and in reverse
                                                                                                                                                                                                                                                                                                              2. Up/Down Motor Speed Lab - change the speed as you change the mode
                                                                                                                                                                                                                                                                                                              3. Servo Lab - control the direction of a 108% servo motor. Calibrate the end angles and sweep the direction back and forth.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#part-3-sensor-labs","title":"Part 3: Sensor Labs","text":"

                                                                                                                                                                                                                                                                                                              There are literally hundreds of sensors that have Grove connectors on them. In addition, we can purchase Grove connectors for as low as 30 cents each. Any other sensors with male pins can be easily connected with these 38 cent connectors with female Dupont jumper connectors. Classrooms with a large collection of these sensors can allow students to try new sensors and outputs without needing a breadboard or soldering. We will focus initially on two sensors we will use for our collision avoidance robot. We prefer the Time-of-Flight sensor because it uses a standard I2C interface and thus could share the I2C bus with other devices.

                                                                                                                                                                                                                                                                                                              1. Time of Flight Distance Sensor Lab - measure the distance to an object
                                                                                                                                                                                                                                                                                                              2. Ultrasonic Ping Distance Sensor - the classic low-cost ultrasonic distance sensor but now it works on a 3.3 volt power! (TBD)
                                                                                                                                                                                                                                                                                                              3. Time of Flight Sound Lab - sound pitch changes with distance
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#part-4-collision-avoidance-robot","title":"Part 4: Collision Avoidance Robot","text":"
                                                                                                                                                                                                                                                                                                              1. Collision Avoidance Robot - this lab joins our motor and sensor labs with a SmartCar chassis to create a robot that avoids collisions.
                                                                                                                                                                                                                                                                                                              2. Collision Robot with Modes - TBD
                                                                                                                                                                                                                                                                                                              3. Adjustable Collision Avoidance - the adjusta bot! TBD
                                                                                                                                                                                                                                                                                                              4. Adding a display
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#basis-for-a-low-cost-robot-kit","title":"Basis for a Low-Cost Robot Kit","text":"

                                                                                                                                                                                                                                                                                                              When this kit is combined with a standard 2 Wheel Drive Smart Car Chassis and a distance sensor it becomes a great low-cost way of getting started with Python and robots.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#clearly-labeled-pin-numbers","title":"Clearly Labeled Pin Numbers","text":"

                                                                                                                                                                                                                                                                                                              One of the biggest disadvantages of the Raspberry Pi Pico is the fact that pin labels are NOT visible when it is mounted on a breadboard. We have to take the Pico out of the breadboard to read the pin numbers on the bottom of the board. A much better design would be to follow the best practices and put the labels on the top of the board where they are visible. This is clearly done on the Maker Pi RP2040 board!

                                                                                                                                                                                                                                                                                                              Note the pin labels, GND, 3.3V, GP0 and GP1 are clearly printed on the top of the board.

                                                                                                                                                                                                                                                                                                              Note the circuit in the upper right corner displays how you can use the analog input port to read the battery level of the robot.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#removing-the-default-circuitpython","title":"Removing the Default CircuitPython","text":"

                                                                                                                                                                                                                                                                                                              Cytron Technologies has a wonderful YouTube videos on how to program the Maker Pi RP2040 using MicroPython. Unfortunately, this board does NOT come with our standard MicroPython loaded! :-O It uses the non-standard Adafruit CircuitPython that is incompatible with most MicroPython programs being used today. This is a sad state of affairs that confuses our students and makes it difficult to share code and libraries for MicroPython. According to Google trends, over the last 12 months for worldwide searches, MicroPython has almost five time the interest of CircuitPython. Preloading the board with CircuitPython sends a very confusing message to the marketplace.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#flash-nuke","title":"Flash Nuke","text":"

                                                                                                                                                                                                                                                                                                              I want to make sure that my RP2040 was starting out with a clean image. I downloaded the flash_nuke.uf2 file to remove the default CircuitPython runtime and all the related files.

                                                                                                                                                                                                                                                                                                              Note that the board must be fully powered down after this load for it to work. I had 4 AA batteries connected to the VIN screw headers, so it was not resetting correctly and the reset was not working until I disconnected the batteries.

                                                                                                                                                                                                                                                                                                              The latests MicroPython runtimes are here

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#easy-motor-testing-buttons","title":"Easy Motor Testing Buttons","text":"

                                                                                                                                                                                                                                                                                                              One of the things I love about this board is how incredibly easy it is for students to test their motors. The board provides four very convenient motor test buttons right on the board. By pressing each one you can make both motors go forward and backwards. This is a great way for students to learn about how we can generate PWM signals to simulate these four buttons. Whoever design this board clearly had their students in mind!

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Link on Box
                                                                                                                                                                                                                                                                                                              • GitHub Link
                                                                                                                                                                                                                                                                                                              • Cytron Maker Pi RP2040 Product Page
                                                                                                                                                                                                                                                                                                              • Cytron Maker Pi RP2040 Datasheet on Google Docs
                                                                                                                                                                                                                                                                                                              • Digi-Key Cytron Maker Pi RP2040 reseller
                                                                                                                                                                                                                                                                                                              • Amazon Listing - no availability as of Aug. 15th 2021
                                                                                                                                                                                                                                                                                                              • Adafruit Cytron Maker Pi RP2040 reseller - out of stock as of Aug. 15th 2021
                                                                                                                                                                                                                                                                                                              • 1300 mah battery
                                                                                                                                                                                                                                                                                                              • Ultrasonic Sensor Video on YouTube
                                                                                                                                                                                                                                                                                                              • Circuit Schematic
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/01-getting-started/","title":"Getting Started","text":""},{"location":"kits/maker-pi-rp2040/01-getting-started/#purchasing","title":"Purchasing","text":"

                                                                                                                                                                                                                                                                                                              The retail list price is $9.99. Thie Cytron Maker Pi RP2040 kit includes 3 Grove connectors, screwdriver and feet) Cytron

                                                                                                                                                                                                                                                                                                              Here are some online retailers that seel this kit:

                                                                                                                                                                                                                                                                                                              • DigiKey
                                                                                                                                                                                                                                                                                                              • Amazon
                                                                                                                                                                                                                                                                                                              • Adafruit

                                                                                                                                                                                                                                                                                                              There is also a YouTube Video that demonstrates the features of the board.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/01-getting-started/#install-the-micropython-runtime-library","title":"Install the MicroPython Runtime Library","text":"

                                                                                                                                                                                                                                                                                                              The Maker Pi RP2040 comes with an incompatible CircuitPython run-time. Our first step is to re-initialize the board with the Raspberry Pi flash_nuke.uf2 runtime. We can then load the latest MicroPython libraries. When we wrote these labs we were using MicroPython version 1.7 that was released in September of 2021.

                                                                                                                                                                                                                                                                                                              To install MicroPython you mush hold down the BOTSEL button on the main board while you turn on the board using the on-board power switch. This will make the board look like a USB drive. You can then just drag the flash-nuke file onto the drive and the board will be initialized. Make sure to power the board off and back on.

                                                                                                                                                                                                                                                                                                              You can now repeat this process with the Raspberry Pi MicroPython Runtime. Just remember to press and hold down the BOTSEL before you turn on the board and reboot after the image has been copied to the microcontroller.

                                                                                                                                                                                                                                                                                                              If you have never used MicroPython, the Raspberry Pi Foundation has a nice Getting Started Guide that can be helpful.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/01-getting-started/#get-familiar-with-your-ide-thonny-and-the-basic-programs","title":"Get Familiar with your IDE (Thonny) and the Basic Programs","text":"

                                                                                                                                                                                                                                                                                                              There are many Integrated Development Environments (IDEs) that work with the Raspberry Pi RP2040 chip. The one you chose just should support MicroPython and be able to upload and run new programs. Once you turn on the board you should be able to configure Thonny to use the Raspberry Pi MicroPython interface. When you press the Stop/Reset button you should see the MicroPython REPL prompt.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/01-getting-started/#_1","title":"Getting Started","text":""},{"location":"kits/maker-pi-rp2040/01-getting-started/#test-the-motor-connections","title":"Test the Motor Connections","text":"

                                                                                                                                                                                                                                                                                                              Use the Motor Connection Lab

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/01-getting-started/#getting-help","title":"Getting Help","text":"

                                                                                                                                                                                                                                                                                                              MicroPython on the RP2040 is the most powerful low-cost system on the market today. With 264K of RAM, it will take a LOT of work to run out of memory. But with all things new, there is a lock of good documentation, drivers and sample code. To help you along, we suggest the following resources:

                                                                                                                                                                                                                                                                                                              1. The MicroPython Raspsberry Pi Forum. Be sure use the search to check for prior questions. 2.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/02-blue-led-lab/","title":"Blue LED Lab","text":"

                                                                                                                                                                                                                                                                                                              Once you have the MicroPython runtime installed and your IDE setup, this board is easy to program!

                                                                                                                                                                                                                                                                                                              Let's take a look at the classic \"Blink\" program that turns a single LED on and off every second.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/02-blue-led-lab/#blink-first-blue-led","title":"Blink First Blue LED","text":"

                                                                                                                                                                                                                                                                                                              The Maker Pi RP2040 has a row of 13 small blue LEDs that monitor the digital input/output of 13 of the GPIO signals. If you set any of the output pins to be HIGH, the LED will be on. If you set the pin to be LOW, the blue LED will be off. These LEDs make it easy for you to view the state of your GPIO pins and can help debugging your programs.

                                                                                                                                                                                                                                                                                                              Just remember that if you are using the pins for communication, you can't use the LEDs for other purposes.

                                                                                                                                                                                                                                                                                                              Here is a small program that will blink the first blue LED:

                                                                                                                                                                                                                                                                                                              import machine\nimport time\n# setup the first LED as an output signal\nfirst_led = machine.Pin(0, machine.Pin.OUT)\n\nwhile True:\n    first_led.toggle()\n    time.sleep(1)\n

                                                                                                                                                                                                                                                                                                              Note that the first four lines are the \"setup\" of the program. These lines will only run once when the program starts. The code indented after the while True: line will continue to run until the device is reset or powered down.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/02-blue-led-lab/#running-lights-on-all-leds","title":"Running Lights on All LEDs","text":"

                                                                                                                                                                                                                                                                                                              Here is a demo using the 13 nice blue LEDs used to show the status of the pins.

                                                                                                                                                                                                                                                                                                              import machine\nimport time\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs\nblue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]\nnumber_leds = len(blue_led_pins)\nled_ports = []\ndelay = .05\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# loop forever\nwhile True:\n    # blue up\n    for i in range(0, number_leds):\n        led_ports[i].high()\n        time.sleep(delay)\n        led_ports[i].low()\n    # blue down\n    for i in range(number_leds - 1, 0, -1):\n        led_ports[i].high()\n        time.sleep(delay)\n        led_ports[i].low()\n

                                                                                                                                                                                                                                                                                                              This demo uses a list of all the 13 digital I/O ports. For each port it sets the port to be a digital output. In the main loop it then goes up and down the strip of LEDs, turning each one on for 1/20th of a second (.05 seconds).

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/03-neopixel-lab/","title":"NeoPixel Lab","text":""},{"location":"kits/maker-pi-rp2040/03-neopixel-lab/#neopixel-demo-lab","title":"NeoPixel Demo Lab","text":"

                                                                                                                                                                                                                                                                                                              The Maker Pi RP2040 comes with two built-in NeoPixels. Each NeoPixel has a red, green and blue LED inside it. Each of these LEDs can be set to any one of 256 values from 0 (off) to 255 (brightest value).

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/03-neopixel-lab/#neopixel-setup","title":"NeoPixel Setup","text":"
                                                                                                                                                                                                                                                                                                              from neopixel import Neopixel\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nLED_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/03-neopixel-lab/#neopixel-blink-lab","title":"NeoPixel Blink Lab","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will turn the first NeoPixel element on red for 1/2 second and then turn it off for 1/2 second. We repeat this until the program is terminated.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/03-neopixel-lab/#setting-up-the-neopixel-library","title":"Setting up the NeoPixel Library","text":"

                                                                                                                                                                                                                                                                                                              We will be calling a NeoPixel driver in the /lib directory. We initiaze our NeoPixel strip by calling the init method all Neopixel() and pass it three parameters:

                                                                                                                                                                                                                                                                                                              1. The number of pixels in the strip (in our case there are just two)
                                                                                                                                                                                                                                                                                                              2. The state machine (in our case 0)
                                                                                                                                                                                                                                                                                                              3. The LED PIN (in our case this is GP18)
                                                                                                                                                                                                                                                                                                              from utime import sleep\n# We are using https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nLED_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n\nwhile True:\n    # turn on first pixel red for 1/2 second\n    strip.set_pixel(0, (255, 0, 0))\n    strip.show()\n    sleep(.5)   \n    strip.set_pixel(0, (0, 0, 0)) # turn all colors off\n    strip.show()\n    sleep(.5)\n
                                                                                                                                                                                                                                                                                                              import time\n# We are using https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nLED_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n\n# Color RGB values\nred = (255, 0, 0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet)\n\n# set to be 1 to 100 for percent brightness\nstrip.brightness(100)\n\ncolor_index = 0\nwhile True:\n    for color in colors:\n        for i in range(NUMBER_PIXELS):\n            print(i, color_names[color_index])\n            strip.set_pixel(i, color)\n            strip.show()\n            time.sleep(1)\n        color_index += 1\n        if color_index >= num_colors: color_index = 0\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/04-button-lab/","title":"Two Button Press","text":"

                                                                                                                                                                                                                                                                                                              We learned how to write code to monitor a button press in the Button Lab.

                                                                                                                                                                                                                                                                                                              Recall we talked about how to remove the \"debounce noise\" when a button is pressed by adding a timer to make sure we had a clean transition (debouncing the switch):

                                                                                                                                                                                                                                                                                                              We did this by waiting for the transition to settle down to its new state.

                                                                                                                                                                                                                                                                                                              import utime\nfrom machine import Pin\n\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n\nbutton_presses = 0 # the count of times the button has been pressed\nlast_time = 0 # the last time we pressed the button\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail\nfaster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)\nslower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global button_presses, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            button_presses +=1\n        else:\n            button_presses -=1\n        last_time = new_time\n\n\n# now we register the handler function when the button is pressed\nfaster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nslower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# This is for only printing when a new button press count value happens\nold_presses = 0\n\nwhile True:\n    # only print on change in the button_presses value\n    if button_presses != old_presses:\n        print(button_presses)\n        builtin_led.toggle()\n        old_presses = button_presses\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/04-button-lab/#making-the-buttons-change-the-neopixel-color","title":"Making the Buttons Change the NeoPixel Color","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will combine the button press lab with our NeoPixel lab to allow you to change the NeoPixel colors if a button on the board is pressed. Each button will control the color of one of the pixels.

                                                                                                                                                                                                                                                                                                              # press buttons to change the color of the NeoPixels\nimport utime\nfrom machine import Pin\nfrom neopixel import Neopixel\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nLED_PIN = 18\nBUTTON_A_PIN = 20\nBUTTON_B_PIN = 21\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, \"GRB\")\n\n# Color RGB values\nred = (255, 0, 0)\norange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\ncyan = (0, 255, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\nwhite = (255, 255, 255)\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, cyan, indigo, violet, white)\n\n# color index into colors list\nneopixel_a = 0\nneopixel_b = 0\n# set to be 1 to 100 for percent brightness\nstrip.brightness(100)\n\nbutton_presses = 0 # the count of times the button has been pressed\nlast_time = 0 # the last time we pressed the button\n\n# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail\nbutton_a = machine.Pin(BUTTON_A_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_b = machine.Pin(BUTTON_B_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global button_presses, last_time, num_colors, neopixel_a, neopixel_b\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        button_presses += 1\n        if '20' in str(pin):\n            neopixel_a +=1\n            if neopixel_a > num_colors - 1:\n                neopixel_a = 0 \n        else:\n            neopixel_b +=1\n            if neopixel_b > num_colors - 1:\n                neopixel_b = 0 \n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nbutton_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nbutton_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# This is for only printing when a new button press count value happens\nold_presses = 0\nprint('Running NeoPixel Button Lab')\nstrip.set_pixel(0, (4,5,5))\nstrip.set_pixel(1, (4,5,5))\nstrip.show()\n\ndef main():\n    global button_presses, old_presses, colors, neopixel_a, neopixel_b\n    while True:\n        # only print on change in the button_presses value\n        if button_presses != old_presses:\n            print(button_presses)\n            print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a)\n            print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b)\n            strip.set_pixel(0, colors[neopixel_a])\n            strip.set_pixel(1, colors[neopixel_b])\n            strip.show()\n            old_presses = button_presses\n\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Cleanup code\n    print('Turning off NeoPixels')\n    strip.set_pixel(0, (0,0,0))\n    strip.set_pixel(1, (0,0,0))\n    strip.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/05-sound-lab/","title":"Play Mario on MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This program will play the theme music from the Mario video game.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\nbuzzer = PWM(Pin(22))\n\ntones = {\n\"B0\": 31,\"C1\": 33,\"CS1\": 35,\"D1\": 37,\"DS1\": 39,\"E1\": 41,\"F1\": 44,\"FS1\": 46,\n\"G1\": 49,\"GS1\": 52,\"A1\": 55,\"AS1\": 58,\"B1\": 62,\"C2\": 65,\n\"CS2\": 69,\"D2\": 73,\"DS2\": 78,\"E2\": 82,\"F2\": 87,\"FS2\": 93,\"G2\": 98,\n\"GS2\": 104,\"A2\": 110,\"AS2\": 117,\"B2\": 123,\"C3\": 131,\"CS3\": 139,\n\"D3\": 147,\"DS3\": 156,\"E3\": 165,\"F3\": 175,\"FS3\": 185,\n\"G3\": 196,\"GS3\": 208,\"A3\": 220,\"AS3\": 233,\"B3\": 247,\"C4\": 262,\"CS4\": 277,\"D4\": 294,\"DS4\": 311,\n\"E4\": 330,\"F4\": 349,\"FS4\": 370,\"G4\": 392,\"GS4\": 415,\"A4\": 440,\"AS4\": 466,\"B4\": 494,\"C5\": 523,\"CS5\": 554,\"D5\": 587,\"DS5\": 622,\"E5\": 659,\"F5\": 698,\n\"FS5\": 740,\"G5\": 784,\"GS5\": 831,\"A5\": 880,\"AS5\": 932,\"B5\": 988,\"C6\": 1047,\"CS6\": 1109,\"D6\": 1175,\"DS6\": 1245,\"E6\": 1319,\"F6\": 1397,\"FS6\": 1480,\"G6\": 1568,\"GS6\": 1661,\n\"A6\": 1760,\"AS6\": 1865,\"B6\": 1976,\"C7\": 2093,\"CS7\": 2217,\"D7\": 2349,\"DS7\": 2489,\"E7\": 2637,\"F7\": 2794,\"FS7\": 2960,\"G7\": 3136,\"GS7\": 3322,\"A7\": 3520,\n\"AS7\": 3729,\"B7\": 3951,\"C8\": 4186,\"CS8\": 4435,\"D8\": 4699,\"DS8\": 4978\n}\n\nsong = [\"E5\",\"G5\",\"A5\",\"P\",\"E5\",\"G5\",\"B5\",\"A5\",\"P\",\"E5\",\"G5\",\"A5\",\"P\",\"G5\",\"E5\"]\nmario = [\"E7\", \"E7\", 0, \"E7\", 0, \"C7\", \"E7\", 0, \"G7\", 0, 0, 0, \"G6\", 0, 0, 0, \"C7\", 0, 0, \"G6\",\n         0, 0, \"E6\", 0, 0, \"A6\", 0, \"B6\", 0, \"AS6\", \"A6\", 0, \"G6\", \"E7\", 0, \"G7\", \"A7\", 0, \"F7\", \"G7\",\n         0, \"E7\", 0,\"C7\", \"D7\", \"B6\", 0, 0, \"C7\", 0, 0, \"G6\", 0, 0, \"E6\", 0, 0, \"A6\", 0, \"B6\", 0,\n         \"AS6\", \"A6\", 0, \"G6\", \"E7\", 0, \"G7\", \"A7\", 0, \"F7\", \"G7\", 0, \"E7\", 0,\"C7\", \"D7\", \"B6\", 0, 0]\n\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\ndef playsong(mysong):\n    for i in range(len(mysong)):\n        if (mysong[i] == \"P\" or mysong[i] == 0 ):\n            bequiet()\n        else:\n            playtone(tones[mysong[i]])\n        sleep(0.3)\n    bequiet()\nplaysong(mario)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/06-up-down-lab/","title":"Up Down Mode Lab","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will combine the two buttons with the blue LEDs, the NeoPixels and the buzzer labs. The We will make the LED, NeoPixels and sound all change for each button press. You will be able to up and down the color spectrum and the sound frequency.

                                                                                                                                                                                                                                                                                                              We will start with the material from our button lab. We will create two functions that will be triggered by the two buttons. One will increment a counter (add one) and the other will decrement the counter (subtract 1). By pressing one of the two buttons you will cycle through the modes of the program.

                                                                                                                                                                                                                                                                                                              The diagram has eight different modes. The default mode is usually mode=0. When you press the left button the mode will increase by one. The NeoPixels will change from red to orange. Pressing the left button will increase the mode by one going to the orange mode. Pressing the right button will subtract one from the mode going from mode 1 (orange) back to model 0 (red).

                                                                                                                                                                                                                                                                                                              Within our Interrupt Request Handler (IRQ) function we will also have to add two lines to deal with the wrap around logic like this:

                                                                                                                                                                                                                                                                                                                      # wrap around to first mode\n        if mode >= mode_count: mode = 0\n        if mode < 0: mode = mode_count - 1\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040/06-up-down-lab/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              # Mode Up/Down Lab\n# Change a mode using the buttons on the Maker Pi RP2040 board\n# Changes the NeoPixel color and the blue GPIO status LEDs\nimport time\nfrom machine import Pin, PWM\n# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nBUZZER_PORT = 22\nbuzzer = PWM(Pin(BUZZER_PORT))\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nNEOPIXEL_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, \"GRB\")\n\n# have up to 13 that we can use\nblue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]\nnumber_leds = len(blue_led_pins)\nled_ports = []\n# create a list of the port pin object instances\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# Color RGB values as tuples - needs some Gamma corrections\nred = (255, 0, 0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncyan = (0, 255, 255)\nlightgreen = (100, 255, 100)\nwhite = (128, 128, 128) # not too bright\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white)\n\n# set to be 1 to 100 for percent brightness\nstrip.brightness(100)\n\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n\nmode = 0 # the default mode on powerup and reset\nmode_count = len(color_names)\nlast_time = 0 # the last time we pressed the button\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n# Give our pins some logical names\nnext_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)\nprevious_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global mode, last_time\n    new_time = time.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            mode +=1\n        else:\n            mode -=1\n        # wrap around to first mode\n        if mode >= mode_count: mode = 0\n        if mode < 0: mode = mode_count - 1\n        last_time = new_time\n\ndef set_blue_led_mode(mode):\n    global num_colors\n    for i in range(0, num_colors):\n        if i == mode:\n            led_ports[i].high()\n        else:\n            led_ports[i].low()\n\n# Register the handler function when either button is pressed\nnext_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nprevious_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n#  Note the non-linear increases in frequency - note that some are louder\ntone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\n# This is for only printing when a new button press count value happens\nold_mode = -1\n\nprint('found ', mode_count, ' modes.')\nwhile True:\n    # only print on change in the button_presses value\n    if mode != old_mode:\n        print('new mode:', mode, color_names[mode], tone_freq[mode])\n        # get the color mode\n        color = colors[mode]\n        strip.set_pixel(0, color)\n        strip.set_pixel(1, color)\n        strip.show()\n        set_blue_led_mode(mode)\n        playtone(tone_freq[mode])\n        time.sleep(.2)\n        bequiet()\n        old_mode = mode\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/","title":"Cytron Maker Pi RP2040 Collision Avoidance Robot","text":"

                                                                                                                                                                                                                                                                                                              We have been working on designing a run robot that can be used to teach computational thinking since 2014. We have gone through many generations, and now we think we have a fantastic design that is powerful, flexible, extendible and inexpensive. We love this robot because:

                                                                                                                                                                                                                                                                                                              1. The cost of parts is under $20.00 US
                                                                                                                                                                                                                                                                                                              2. It is programmed with Python
                                                                                                                                                                                                                                                                                                              3. It has plenty of power - with 264K RAM it has the ability to run complex programs
                                                                                                                                                                                                                                                                                                              4. The design is flexible and it is easy to add displays and other sensors
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/#base-cytron-maker-pi-rp2040-robot-kit","title":"Base Cytron Maker Pi RP2040 Robot Kit","text":"

                                                                                                                                                                                                                                                                                                              This version uses the time-of-flight sensor.

                                                                                                                                                                                                                                                                                                              The robot can be built ia a few hours using a screwdriver and soldering four wires onto the motors.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/#sample-parts-list","title":"Sample Parts List","text":"
                                                                                                                                                                                                                                                                                                              1. Cytron Maker Pi RP2040 board (includes Grove connectors, screwdriver and feet) Cytron DigiKey Amazon Adafruit YouTube Video
                                                                                                                                                                                                                                                                                                              2. 2 Wheel Drive Smart Car Kit: Chassis Main board (acrylic), 2x DC Motors with wires soldered, 2x wheels, 4x AA Battery Case: Cytron Amazon eBay
                                                                                                                                                                                                                                                                                                              3. Distance Sensor (Time-of-flight or Ultrasonic ping): Cytron ebay Amazon
                                                                                                                                                                                                                                                                                                              4. Ping sensor mount
                                                                                                                                                                                                                                                                                                              5. 2x M3 6 mm screws and nuts
                                                                                                                                                                                                                                                                                                              6. 4x M3 10 mm screes and nuts
                                                                                                                                                                                                                                                                                                              7. Micro USB cable
                                                                                                                                                                                                                                                                                                              8. 4x AA batteries
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/#demo-with-oled-display","title":"Demo with OLED Display","text":"
                                                                                                                                                                                                                                                                                                              1. Cytron Maker Pi RP2040 robotics board ($10)
                                                                                                                                                                                                                                                                                                              2. SmartCar kit ($9)
                                                                                                                                                                                                                                                                                                              3. Time-of-flight sensor (4)
                                                                                                                                                                                                                                                                                                              4. Optional OLED SPI 2.24\" SSD1606 display ($18)
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/02-assembly/","title":"Assembling Your Maker Pi RP2040 Robot","text":"

                                                                                                                                                                                                                                                                                                              This kit is a $25 robot kit that we will use in our CoderDojo robotics classes. This kit includes:

                                                                                                                                                                                                                                                                                                              1. A SmartCar Chassis
                                                                                                                                                                                                                                                                                                                1. Two 3 to 6-volt DC geared hobby motors and wheels
                                                                                                                                                                                                                                                                                                                2. Plexiglass (acrylic) main-board
                                                                                                                                                                                                                                                                                                                3. Screws and nuts
                                                                                                                                                                                                                                                                                                                4. 4 AA battery pack
                                                                                                                                                                                                                                                                                                                5. Power switch
                                                                                                                                                                                                                                                                                                              2. Cytron Maker Pi RP2040 kit
                                                                                                                                                                                                                                                                                                                1. Maker Pi RP2040 board
                                                                                                                                                                                                                                                                                                                2. 4x Grove to female header cables
                                                                                                                                                                                                                                                                                                                3. Screwdriver
                                                                                                                                                                                                                                                                                                                4. Silicone rubber feet (pack of 4)
                                                                                                                                                                                                                                                                                                              3. Ultrasonic sensor
                                                                                                                                                                                                                                                                                                                1. mounting bracket
                                                                                                                                                                                                                                                                                                                2. 2 M2 6mm screws and nuts

                                                                                                                                                                                                                                                                                                              You will need to provide 4 AA batteries and a Micro USB connector that works with your PC or Mac.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/02-assembly/#assemble-the-smartcar-chassis","title":"Assemble the SmartCar Chassis","text":"

                                                                                                                                                                                                                                                                                                              In this version of the kit, the wires are pre-soldered onto the motors.

                                                                                                                                                                                                                                                                                                              Here is the robot kit in all the packaging:

                                                                                                                                                                                                                                                                                                              Your first task is to remove the protective backing from the acrylic body.

                                                                                                                                                                                                                                                                                                              Here are all the parts removed from the packaging:

                                                                                                                                                                                                                                                                                                              We mount the motors with the wires on the inside and the heads of the bolts on the outside. This photo shows cable ties I have added so that the wires don't get pulled out by our students. These cable ties are optional.

                                                                                                                                                                                                                                                                                                              Next, we position the battery pack on the BOTTOM so that we have more room on the top for our circuit board, sensors and add-on displays.

                                                                                                                                                                                                                                                                                                              I used a 1/8th inch drill bit to put holes where the battery pack should be mounted.

                                                                                                                                                                                                                                                                                                              Next, I put the flat-head screws in the battery pack. We want to make sure the top of the screw is all the way in so that it does not get in the way of the battery.

                                                                                                                                                                                                                                                                                                              Next, we mount the rubber feet on the bottom of the Maker Pi RP2040 circuit board so that we have some space between the PC board and the main chassis. I use the space next to the four corners to mount the feet. Note that we must put the drag wheel on before we put the PC board on top of the chassis.

                                                                                                                                                                                                                                                                                                              Next, we put the four screws and spacers in the four holes at the bottom rear of the robot directly behind the battery pack.

                                                                                                                                                                                                                                                                                                              We then add the four screws to mount the drag wheel.

                                                                                                                                                                                                                                                                                                              Now is a good time to check the spacing of the battery pack and the read drag wheel. The rear drag wheel must be able to spin freely in a full circle without bumping into the battery. If it bumps you might need to remount the battery pack before you proceed to the next step.

                                                                                                                                                                                                                                                                                                              This figure has the switch that comes with the battery pack. For our work, we will not need this switch since the Maker Pi RP2040 circuit board has an no-board power switch. Most of our students put the switch in if they ever need to change circuit boards that don't have a built-in power switch. If you do this, you can solder the switch between the red power of the battery and the positive terminal of VIN.

                                                                                                                                                                                                                                                                                                              Next, line up the printed circuit board with the USB connector facing the rear. Note where the holes are in the board and drill two 1/8\" holes to mount the board.

                                                                                                                                                                                                                                                                                                              This photo shows the holes drilled with the screws in them.

                                                                                                                                                                                                                                                                                                              This is the side-view from the rear of the screws holding on the circuit board.

                                                                                                                                                                                                                                                                                                              Next use two 6 mm M3 screws to mount the ultrasonic distance sensor on top front of the robot. Some of our students like to mount the ultrasonic sensor under the chassis and point the sensor up a little so the sensor does not reflect off the floor. You can use a heat gun to soften the plastic mount to change the angle.

                                                                                                                                                                                                                                                                                                              Next I added a drop of hot-glue under the front screws that mount the pc board. I did this because the battery pack and motor mounts get in the way of adding a nut under the board.

                                                                                                                                                                                                                                                                                                              Next, I used a small rubber coated twist tie to keep the wires under the robot away from the wheels and battery. We don't want them to drag on the floor.

                                                                                                                                                                                                                                                                                                              Next, we connect the motors up to the screw headers on the printed circuit board. There is a screwdriver that comes with the Cytron Maker Pi RP2040 that is handy for tightening the screws. Don't worry about getting the connections all correct. They can be adjusted in your software.

                                                                                                                                                                                                                                                                                                              Press the wheels on the motors.

                                                                                                                                                                                                                                                                                                              Lastly, we connect the battery to the VIN jumper, making sure to connect the red wire to the \"+\" terminal and the black wire to the \"-\" terminal.

                                                                                                                                                                                                                                                                                                              Connect the Maker Pi RP2040 board to the top with the USB connector facing the rear.

                                                                                                                                                                                                                                                                                                              Here is a short video of the assembly of a SmartCar Chassis. Note that this video puts the battery on the top, where we put it on the bottom.

                                                                                                                                                                                                                                                                                                              There are many videos online how to assemble to motors to the chassis. The trick is orienting the motors correctly and making sure the bolts don't get in the way of the wheels.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/06-up-down-motor-lab/","title":"Up Down Motor Speed Lab","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will make the motor speed change as the mode changes.

                                                                                                                                                                                                                                                                                                              # Motor Setup\n# motors just barely turn at this power level\nMIN_POWER_LEVEL = 10000\nMAX_POWER_LEVEL = 65025\nPOWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10)\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\ndef drive_speed(power_level):\n    right_forward.duty_u16(power_level)\n    left_forward.duty_u16(power_level)\n

                                                                                                                                                                                                                                                                                                              In the main we have:

                                                                                                                                                                                                                                                                                                              power_level = MIN_POWER_LEVEL + mode * POWER_STEP\n# turn off the motor if we are at mode 0\nif mode == 0: power_level = 0\ndrive_speed(power_level)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/06-up-down-motor-lab/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              # Mode Up/Down Lab\n# Change a mode using the buttons on the Maker Pi RP2040 board\n# Changes the NeoPixel color and the blue GPIO status LEDs\nimport time\nfrom machine import Pin, PWM\n# We are using a MicroPython NeoPixel library from here: https://github.com/blaz-r/pi_pico_neopixel\nfrom neopixel import Neopixel\n\nBUZZER_PORT = 22\nbuzzer = PWM(Pin(BUZZER_PORT))\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nNEOPIXEL_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, \"GRB\")\n\n# have up to 13 that we can use\nblue_led_pins = [0,1,2,3,4,5,6,7,16,17,26,27,28]\nnumber_leds = len(blue_led_pins)\nled_ports = []\n# create a list of the port pin object instances\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# Color RGB values as tuples - needs some Gamma corrections\nred = (255, 0, 0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncyan = (0, 255, 255)\nlightgreen = (100, 255, 100)\nwhite = (128, 128, 128) # not too bright\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white)\n\n# set to be 1 to 100 for percent brightness\nstrip.brightness(100)\n\n# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler\n\n# Motor Setup\n# motors just barely turn at this power level\nMIN_POWER_LEVEL = 10000\nMAX_POWER_LEVEL = 65025\nPOWER_STEP = int((MAX_POWER_LEVEL - MIN_POWER_LEVEL) / 10)\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\ndef drive_speed(power_level):\n    right_forward.duty_u16(power_level)\n    left_forward.duty_u16(power_level)\n\nmode = 0 # the default mode on powerup and reset\nmode_count = len(color_names)\nlast_time = 0 # the last time we pressed the button\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n# Give our pins some logical names\nnext_mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)\nprevious_mode_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global mode, last_time, power_level\n    new_time = time.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            mode +=1\n            # power_level += POWER_STEP\n        else:\n            mode -=1\n            # power_level -= POWER_STEP\n        # wrap around to first mode\n        if mode >= mode_count: mode = 0\n        if mode < 0: mode = mode_count - 1\n        last_time = new_time\n\ndef set_blue_led_mode(mode):\n    global num_colors\n    for i in range(0, num_colors):\n        if i == mode:\n            led_ports[i].high()\n        else:\n            led_ports[i].low()\n\n# Register the handler function when either button is pressed\nnext_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nprevious_mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# non-linear increase is frequency - note that some are lowder\ntone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\n# This is for only printing when a new button press count value happens\nold_mode = -1\n\npower_level = MIN_POWER_LEVEL\nprint('found ', mode_count, ' modes.')\nwhile True:\n    # only print on change in the button_presses value\n    if mode != old_mode:\n        print('new mode:', mode, color_names[mode], tone_freq[mode], power_level)\n        # get the color mode\n        color = colors[mode]\n        strip.set_pixel(0, color)\n        strip.set_pixel(1, color)\n        strip.show()\n        set_blue_led_mode(mode)\n        playtone(tone_freq[mode])\n        time.sleep(.2)\n        bequiet()\n        power_level = MIN_POWER_LEVEL + mode * POWER_STEP\n        # turn off the motor if we are at mode 0\n        if mode == 0: power_level = 0\n        drive_speed(power_level)\n        old_mode = mode\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07-motor-connection-lab/","title":"Motor Drive Connection Test","text":""},{"location":"kits/maker-pi-rp2040-robot/07-motor-connection-lab/#built-in-motor-driver","title":"Built-In Motor Driver","text":"

                                                                                                                                                                                                                                                                                                              The Maker Pi RP2040 board contains a MX1508 dual channel H-bridge chip and easy-to-connect screw headers for power and motor connections. This is fantastic for teaching robotics since students can driver two motors without ever having to use a soldering iron.

                                                                                                                                                                                                                                                                                                              !!! Note that the is designed to work with small DC-hobby motors and there is no documentation on exactly what motor driver chip is used or its precise current and power limitations.

                                                                                                                                                                                                                                                                                                              The documentation only indicates that the maximum current is 1A continuous power and 1.5A for up to 5 seconds. The input voltage is only rated at 6 volts, which find for our standard 4 AA battery packs.

                                                                                                                                                                                                                                                                                                              If this motor driver chip is similar to the ubiquitous L293x motor controllers, and the current should be 1A per motor.

                                                                                                                                                                                                                                                                                                              I suspect that if you glued a small heat sink like a 16 pin DIP fin to the unknown motor driver IC on the main board you could drive slightly larger motors.

                                                                                                                                                                                                                                                                                                              Close-up of the motor driver chip. I can't quite make out the numbers on the chip, but the logo is not \"TI\".

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07-motor-connection-lab/#testing-the-connections","title":"Testing The Connections","text":"

                                                                                                                                                                                                                                                                                                              In our standard robot, the M1 is the right wheel as you are looking from the top-back of the robot. The M2 wheel is the left wheel. I connect the red to the right of the two connectors and it is also the right terminal of the motors as you are looking from the rear.

                                                                                                                                                                                                                                                                                                              Look at the buttons near the motor connectors. Press the M1A button and verify that the right wheel is moving forward. Press the M1B and the motor should turn in reverse. Similarly the M2B button should turn the left wheel forward and the M2A should turn the left wheel in reverse. If you don't wire these connections the same way I did it is not a worry. It is easy to change the code.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07-motor-connection-lab/#motor-pin-definitions","title":"Motor Pin Definitions","text":"

                                                                                                                                                                                                                                                                                                              Now that we know what buttons control what motors and directions they turn, we are ready to define the pins that are associated with each robot movement. We have four pin assignments: both forward and reverse for both the right and left motors.

                                                                                                                                                                                                                                                                                                              RIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07-motor-connection-lab/#testing-your-pin-definitions","title":"Testing Your Pin Definitions","text":"

                                                                                                                                                                                                                                                                                                              The following program is called our motor connection test. It will turn each motor direction for three seconds and it will print out the motor and direction in the console.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nimport time\n\nPOWER_LEVEL = 65025\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\ndef spin_wheel(pwm):\n        pwm.duty_u16(POWER_LEVEL)\n        time.sleep(3)\n        pwm.duty_u16(0)\n        time.sleep(2)\n\nwhile True:\n    print('right forward')\n    spin_wheel(right_forward)\n\n    print('right reverse')\n    spin_wheel(right_reverse)\n\n    print('left foward')\n    spin_wheel(left_forward)\n\n    print('left_reverse')\n    spin_wheel(left_reverse)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07b-drive-square-lab/","title":"Drive Square Lab","text":""},{"location":"kits/maker-pi-rp2040-robot/07b-drive-square-lab/#prerequsites","title":"Prerequsites","text":"

                                                                                                                                                                                                                                                                                                              This lab assumes you have your Maker Pi RP2040 mounted on a SmartCar chassis with two motors and a battery hooked up.

                                                                                                                                                                                                                                                                                                              In this lab we will program our robot to drive in a square pattern. We will start out doing a \"bench test\" that will require you to put the robot up on a block so you can see the wheels turn, but it will not drive off your desktop. You can also observe the red LED lights on the many board to see which motor direction is on.

                                                                                                                                                                                                                                                                                                              The main loop will look like this:

                                                                                                                                                                                                                                                                                                              while True:\n    forward()\n    sleep(FWD_TIME)\n\n    stop()\n    sleep(STOP_TIME)\n\n    turn_right()\n    sleep(TURN_TIME)\n\n    stop()\n    sleep(STOP_TIME)\n

                                                                                                                                                                                                                                                                                                              We will need to adjust the TURN_TIME parameter to have the robot turn 90 degrees. A good value for most robots is about 1/2 second or sleep(.5).

                                                                                                                                                                                                                                                                                                              Since we will be calling the sleep function many times we will use the following import format to keep our code tidy:

                                                                                                                                                                                                                                                                                                              from utime import sleep\n
                                                                                                                                                                                                                                                                                                              This says that whenever we want to pause our system we just use the sleep(time) function we mean to use the sleep function in the micropython time library. This keeps our code small and portable.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07b-drive-square-lab/#adding-a-keyboard-interrupt-handler-control-c","title":"Adding a Keyboard Interrupt Handler (Control-C)","text":"

                                                                                                                                                                                                                                                                                                              It is also a problem that when we stop a program running that the PWM circuits keep generating signals, which means the robot keeps moving even after we press the STOP/RESET button. To clean this up we will allow you to run a special cleanup handler that will add a function to set all the motors to off using the stop() function.

                                                                                                                                                                                                                                                                                                              try:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('Cleaning up')\n    print('Powering down all motors now.')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/07b-drive-square-lab/#full-program","title":"Full Program","text":"

                                                                                                                                                                                                                                                                                                              You are now ready to test the full program. Save the following to the main.py file, disconnect the USB connector and turn on the power on the main board. Your robot should not we driving in a square!

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\nPOWER_LEVEL = 65025\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\nFWD_TIME = 2\nTURN_TIME = .5 # adjust this to get the turn to be 90 degrees\nSTOP_TIME = 2\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\nprint('Running Drive Square Lab')\nprint('Use Control-C to Stop All Motors')\n\ndef main():\n    while True:\n        print('forward')\n        forward()\n        sleep(FWD_TIME)\n\n        print('stop')\n        stop()\n        sleep(STOP_TIME)\n\n        print('turning right')\n        turn_right()\n        sleep(TURN_TIME)\n\n        print('stop')\n        stop()\n        sleep(STOP_TIME)\n\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('Cleaning up')\n    print('Powering down all motors now.')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/","title":"Maker Pi RP2040 Servo Lab","text":"

                                                                                                                                                                                                                                                                                                              Servo motors are ideal for controlling the angle of an item such as a steering angle or the direction of a sensor. The servos used in these labs are inexpensive SG90 micro-servos that draw very little power and are ideal for a teaching lab. They can be purchased for about $3 each US on eBay. To control a 180 degree servo, you just tell it what angle you would like it to move to. The range of values is typically -90 to 90 degrees with 0 being the nominal resting position for many applications such as the steering wheel angle of a car.

                                                                                                                                                                                                                                                                                                              The Maker Pi RP2040 has four servo ports in the upper left corner of the board (with the USB on the bottom) that use ports GP12, GP13, GP14 and GP15. You can connect any small micro servo directly to these ports. Just make sure to get the polarity correct. The colors for servos may vary somewhat, but the two most common standards are:

                                                                                                                                                                                                                                                                                                              • Orange, red and brown - signal, positive and ground
                                                                                                                                                                                                                                                                                                              • White, red, black - signal, positive and ground

                                                                                                                                                                                                                                                                                                              The general rule is that the lighter colors of orange and white will be the signal and the brown and black will be ground.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#servo-control","title":"Servo Control","text":"

                                                                                                                                                                                                                                                                                                              We will use the PWM functions in our MicroPython library to send a PWM signal to each of the servos. Servos are not controlled by the duty cycle directly. They are controlled by the width of the pulses. But we can control the approximate with of the pulses by holding the frequency constant and changing the duty cycle.

                                                                                                                                                                                                                                                                                                              We will use a 40 hertz signal to send a PWM signal to each of the servos like this.

                                                                                                                                                                                                                                                                                                              SERVO_FREQ_HZ = 40\n# SERVO_PERIOD_MS = 1000 / SERVO_FREQ_HZ is a 25 millisecond pulse width\nmy_pwm.freq(SERVO_FREQ_HZ)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#calibration-of-the-servo","title":"Calibration of the Servo","text":"

                                                                                                                                                                                                                                                                                                              There are small manufacturing variations in servos. This means to get the full sweep of a 180% servo you have to adjust the duty cycle.

                                                                                                                                                                                                                                                                                                              • Minimum duty cycle: 1700
                                                                                                                                                                                                                                                                                                              • Maximum duty cycle: 6300

                                                                                                                                                                                                                                                                                                              By some experimentation I got the following results

                                                                                                                                                                                                                                                                                                              SERVO_MIN_DUTY = 1725 # -90 degrees\nSERVO_MAX_DUTY = 6378 # 90 degrees\n

                                                                                                                                                                                                                                                                                                              We can use a linear mapping function to convert the angle (from -90 to 90):

                                                                                                                                                                                                                                                                                                              # This will take in integers of range in (min and max) return a integer in the output range (min and max)\n# Used to convert one range of values into another using a linear function like the Arduino map() function\ndef convert(x, in_min, in_max, out_min, out_max):\n    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min\n\nangle = 0\nduty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)\nprint('For angle: ', angle, ' the duty is: ', duty)\npwm.duty_u16(duty)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#checking-your-servo-calibration-with-buttons","title":"Checking your Servo Calibration with Buttons","text":"

                                                                                                                                                                                                                                                                                                              We can also use the buttons on the Maker Pi RP2040 to verify that the extreme angles are correct. One button will increase the angle and one will decrease the angle.

                                                                                                                                                                                                                                                                                                              # Maker Pi RP2040 program to check the limits of a 180 degree servo such as a SG90 micro servo\nfrom machine import Pin, PWM\nimport time\n\nBUTTON_1_PIN = 20 # increment the angle\nBUTTON_2_PIN = 21 # decrement the angle\n\nSERVO_1_PIN = 12\nSERVO_2_PIN = 13 # MAX=5749@40\nSERVO_3_PIN = 14\nSERVO_4_PIN = 15\n# this is ususlly standard across most servos\nSERVO_FREQ_HZ = 40\n\npwm = PWM(Pin(SERVO_2_PIN))\n\n# the two button on the Maker Pi RP2040\nincrement_angle_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\ndecrement_angle_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n\n#  return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 )\n# This will take in integers of range in (min and max) return a integer in the output range (min and max)\n# Used to convert one range of values into another using a linear function like the Arduino map() function\ndef convert(x, in_min, in_max, out_min, out_max):\n    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min\n\n# globals\nangle = -90\nlast_time = 0 # the last time we pressed the button\n\n# if the pin is 20 then increment, else decement\ndef button_pressed_handler(pin):\n    global angle, last_time\n    new_time = time.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            angle +=1\n        else:\n            angle -=1\n        last_time = new_time\n # now we register the handler function when the button is pressed\nincrement_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\ndecrement_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\npwm.freq(SERVO_FREQ_HZ)\nold_angle = -1\n\nwhile True:\n    # only print on change in the button_presses value\n    if angle != old_angle:\n        duty = ServoDuty(angle)\n        print('new angle:', angle, 'duty: ', duty)\n        pwm.duty_u16(duty)\n        old_angle = angle\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#sample-sweep-code","title":"Sample Sweep Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nimport time\n\nBUTTON_1_PIN = 20\nBUTTON_2_PIN = 21\n\nSERVO_1_PIN = 12\nSERVO_2_PIN = 13\nSERVO_3_PIN = 14\nSERVO_4_PIN = 15\nSERVO_FREQ_HZ = 50\nSERVO_MIN_DUTY = 1725\nSERVO_MAX_DUTY = 6378\n# this is ususlly standard across most servos\nSERVO_FREQ_HZ = 40\n\npwm = PWM(Pin(SERVO_2_PIN))\n\n# the two button on the Maker Pi RP2040\nclock_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\ncounter_clock_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\n# globals\nangle = 90\nlast_time = 0 # the last time we pressed the button\n\ndef button_pressed_handler(pin):\n    global angle, last_time\n    new_time = time.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            angle +=1\n        else:\n            angle -=1\n        # wrap around to first mode\n        if mode >= mode_count: mode = 0\n        if mode < 0: mode = mode_count - 1\n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nclock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\ncounter_clock_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)      \n#  return int( ( (0.0015*SERVO_FREQ_HZ) + ((angle/90) * (0.0005*SERVO_FREQ_HZ)) ) * 65535 )\n\n# Thisw will take in integers of range in (min and max) return a integer in the output range (min and max)\n# Used to convert one range of values into another using a linear function like the Arduino map() function\ndef convert(x, in_min, in_max, out_min, out_max):\n    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min\n\n# -90 should generate 1725\n# 90 should generate 7973\n\nold_angle = -1\n\npwm.freq(50)\nwhile True:\n    for angle in range(-90, 90):\n        duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)\n        print('angle:', angle, 'duty: ', duty)\n        pwm.duty_u16(duty)\n        old_angle = angle\n        time.sleep(.01)\n    for angle in range(90, -90, -1):\n        duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY)\n        print('angle:', angle, 'duty: ', duty)\n        pwm.duty_u16(duty)\n        old_angle = angle\n        time.sleep(.01)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#shutting-down-all-servos","title":"Shutting Down All Servos","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nimport time\n\nSERVO_1_PIN = 12\nSERVO_2_PIN = 13\nSERVO_3_PIN = 14\nSERVO_4_PIN = 15\n\nprint('shutting down all servos!')\nfor i in range(12, 16):\n    print('Servo', i, 'shutting down')\n    pwm1 = PWM(Pin(SERVO_1_PIN))\n    pwm1.duty_u16(0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#adding-cleanup-code","title":"Adding Cleanup Code","text":"

                                                                                                                                                                                                                                                                                                              PWM signals continue to be generated even after you do a STOP/RESET on your microcontroller. This could drain batteries and wear out your servo motors. To stop the servos from getting PWM signals you can add an interrupt to your code to catch these signals and set the PWM duty cycle back to zero. This

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/08-servo-lab/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              MicroPython Reference Page - this page is not very helpful. The implication is that servo controls are standardized across MicroPython system. This does not appear to be the case.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/09-i2c-scanner-test/","title":"I2C Scanner Test","text":"

                                                                                                                                                                                                                                                                                                              How do we know that our connection to the distance sensor is wired correctly? The quick way to test this is to run a program called the I2C scanner. It will return a list of all the devices it finds on the I2C bus.

                                                                                                                                                                                                                                                                                                              We first run the I2C scanner program to verify that the sensor is connected correct and is responding to the I2C bus scan.

                                                                                                                                                                                                                                                                                                              import machine\n# Pins on the Grove Connector 1 on the Maker Pi RP2040 are GP0 and GP1\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"I2C device ID list:\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              This should return a list of the devices it finds. If you just have the Time-of-Flight sensor it will look like this:

                                                                                                                                                                                                                                                                                                              [41]\n``\n\n```py\ndevice_id = i2c.scan()[0]\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/09-i2c-scanner-test/#testing-for-the-time-of-flight-sensor","title":"Testing for the Time-of-Flight Sensor","text":"
                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(0)\nscl=machine.Pin(1)\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n\n# i2c.scan() returns a list of devices that have been found\n# i2c.scan()[0] is the first device found\ndevice_id = i2c.scan()[0]\nprint(\"Device found at decimal\", device_id)\n\nif device_id == 41:\n    print(\"TEST PASS\")\nelse:\n    print(\"No device found at decimal 41\")\n    print(\"TEST FAIL\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/10-time-of-flight-lab/","title":"Time of Flight Distance Sensor Lab","text":"

                                                                                                                                                                                                                                                                                                              In this lab we create a program that will show the distance measured by the Time-of-Flight sensor by printing the distance on the console and also displaying the distance on 11 blue LEDs.

                                                                                                                                                                                                                                                                                                              First, make sure you have your driver for the Time-of-Flight sensor installed.

                                                                                                                                                                                                                                                                                                              You can copy the code from here and save it in the file VL53L0X.py. Note the zero between the \"L\" and \"X\" in the file name, not the letter \"O\".

                                                                                                                                                                                                                                                                                                              We use a non-linear distance scale as we get closer to an object. We store the numbers of each LED and the distance it should change in a lists:

                                                                                                                                                                                                                                                                                                              blue_led_pins = [2, 3, 4,  5,  6,  7,  16, 17, 26, 27, 28]\ndist_scale =    [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150]\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/10-time-of-flight-lab/#calibration","title":"Calibration","text":"

                                                                                                                                                                                                                                                                                                              There are three numbers you can change when you calibrate the sensor:

                                                                                                                                                                                                                                                                                                              ZERO_DIST = 60 # The value of the sensor when an object is 0 CM away\nMAX_DIST = 1200 # max raw distance we are able to read\nSCALE_DIST = .3 # multiplier for raw to calibrated distance in CM\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/10-time-of-flight-lab/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board using the VL32L0X time of flight distance sensor\n# Note the driver I used came from here: https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py\n# Perhaps derived from here: https://github.com/uceeatz/VL53L0X/blob/master/VL53L0X.py\n\n# This demo makes the blue LEDs show the distance and prints the distance on the console\nimport machine\nimport time\nimport VL53L0X\n\nsda=machine.Pin(0) # row one on our standard Pico breadboard\nscl=machine.Pin(1) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n# print(\"Device found at decimal\", i2c.scan())\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs which we can use 11\n# The distance scale is non linear\n# GP0 and GP1 will always be on since they are the I2C Data and Clock\nblue_led_pins = [2, 3, 4,  5,  6,  7,  16, 17, 26, 27, 28]\ndist_scale =    [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150]\nnumber_leds = len(blue_led_pins)\nled_ports = []\ndelay = .05\n\n# initial calibration parameters\nZERO_DIST = 60\nMAX_DIST = 1200 # max raw distance we are able to read\nSCALE_DIST = .3 # multiplier for raw to calibrated distance\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\n\n\n# get the normalized time-of-flight distance\ndef get_distance():\n    global zero_dist, scale_factor\n    tof_distance = tof.read()\n    if tof_distance > MAX_DIST:\n        return tof_distance\n    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance\n    if tof_distance < ZERO_DIST:\n        zero_dist = tof_distance\n    return  int((tof_distance - ZERO_DIST) * SCALE_DIST)\n\n# use the dist_scale to turn on LEDs\ndef led_show_dist(in_distance):\n    global number_leds\n    for led_index in range(0, number_leds):\n        if in_distance > dist_scale[led_index]:\n            led_ports[led_index].high()\n        else:\n            led_ports[led_index].low()\n\nprint('Using', number_leds, ' blue leds to show distance.')\n\n# blue up\nfor i in range(0, number_leds):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n# blue down\nfor i in range(number_leds - 1, 0, -1):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n\n# start our time-of-flight sensor\ntof.start()\n# autocalibrate the minimum distance\nmin_distance = 1000\n\n\n# loop forever\nwhile True:\n    raw_distance = get_distance()\n    # recalibrate if we have a new min distance\n    if raw_distance < min_distance:\n        min_distance = raw_distance\n    calibrated_distance = raw_distance - min_distance\n    print(raw_distance, calibrated_distance)\n    led_show_dist(calibrated_distance)\n    time.sleep(0.05)\n\n# clean up\ntof.stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/10-time-of-flight-lab/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Kevin McAleer's GitHub Repo on the Vl53lx0 Kevin McAleer's 662 line driver - I am not sure we need all 662 lines of code. Kevin McAleer's Time of Flight Test

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/11-ping-lab/","title":"Ultrasonic Ping Sensor Lab","text":"

                                                                                                                                                                                                                                                                                                              The Grove sensors on our Maker Pi RP2040 only supply 3.3 volts. So the standard very popular low cost HC-SR04 will not work, since it requires 5 volts of power. We have two options. One is to get a separate 5V power source, but the other is to purchase the new HC-SR04P (for Pico?) sensor that will work with our 3.3 volt power on our Grove connector.

                                                                                                                                                                                                                                                                                                              Using the Grove 4 connection wire the HC-SP04P sensor with the trigger on GPIO-16 (White cable) and the echo on GPIO-17 (Yellow cable), VCC (Red cable), and GND (Black cable)

                                                                                                                                                                                                                                                                                                              All wired up

                                                                                                                                                                                                                                                                                                              # Sample code to test HC-SR04 Ultrasonice Ping Sensor\n# Connect GND to any GND pin on the Pico\n# Connnect VCC to VBUS or 5 Volt power\n\nfrom machine import Pin, Timer\nimport utime\n\nTRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner\nECHO_PIN = 17 # One up from bottom left corner\n\n# Init HC-SR04 pins\ntrigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor\necho = Pin(ECHO_PIN, Pin.IN) # get the delay interval back\n\ndef ping():\n    trigger.low()\n    utime.sleep_us(2) # Wait 2 microseconds low\n    trigger.high()\n    utime.sleep_us(5) # Stay high for 5 miroseconds\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    return distance\n\nwhile True:\n    print(\"Distance:\", ping(), \"cm\")\n    utime.sleep(.25)\n

                                                                                                                                                                                                                                                                                                              More advanced version with sound

                                                                                                                                                                                                                                                                                                              # Sample code to test HC-SR04 Ultrasonice Ping Sensor\n# Connect GND to any GND pin on the Pico\n# Connnect VCC to VBUS or 5 Volt power\n\nfrom machine import Pin, Timer, PWM\nimport utime\n\nTRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner\nECHO_PIN = 17 # One up from bottom left corner\n\n# Init HC-SR04 pins\ntrigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor\necho = Pin(ECHO_PIN, Pin.IN) # get the delay interval back\n\nBUZZER_PORT = 22\nbuzzer = PWM(Pin(BUZZER_PORT))\n\n#  Note the non-linear increases in frequency - note that some are louder\ntone_freq = [100, 150, 210, 280, 350, 450, 580, 750, 850, 950, 1000]\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\ndef ping():\n    trigger.low()\n    utime.sleep_us(2) # Wait 2 microseconds low\n    trigger.high()\n    utime.sleep_us(5) # Stay high for 5 miroseconds\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    return distance\n\nwhile True:\n    dist=round(ping())\n    print(\"Distance:\", dist, \"cm\")\n    if dist < 20:\n        print(\"Panic\")\n        playtone(350)\n        # Beep faster the closer you get\n        utime.sleep(.05/(20/dist))\n        bequiet()\n    utime.sleep(.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/11-ping-lab/#link-to-sample-ping-lab","title":"Link to Sample Ping Lab","text":"

                                                                                                                                                                                                                                                                                                              This code is very similar to the previous ping lab but with the different GPIO lines used.

                                                                                                                                                                                                                                                                                                              Link to Standard Ping Lab

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/12-time-of-flight-sound-lab/","title":"Time of Flight Distance Sensor Test","text":"
                                                                                                                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board\n\nfrom machine import Pin,PWM\nimport time\nimport VL53L0X\nbuzzer=PWM(Pin(22))\n\nsda=machine.Pin(0) # row one on our standard Pico breadboard\nscl=machine.Pin(1) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n# print(\"Device found at decimal\", i2c.scan())\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs\nblue_led_pins = [2, 3,  4,  5,  6,  7, 16, 17, 26, 27, 28]\n# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]\ndist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]\n\nnumber_leds = len(blue_led_pins)\nled_ports = []\ndelay = .05\n\n# calibration parameters\nzero_dist = 65 # distance measure when an object is about 1/2 cm away\nmax_dist = 350 # max distance we are able to read\nscale_factor = .2\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\n\n# blue up\nfor i in range(0, number_leds):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n# blue down\nfor i in range(number_leds - 1, 0, -1):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n\n# get the normalized time-of-flight distance\ndef get_distance():\n    global zero_dist, scale_factor\n    tof_distance = tof.read()\n    if tof_distance > max_dist:\n        return tof_distance\n    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance\n    if tof_distance < zero_dist:\n        zero_dist = tof_distance\n    return  int((tof_distance - zero_dist) * scale_factor)\n\ndef led_show_dist(in_distance):\n    global number_leds\n    for led_index in range(0, number_leds):\n        if in_distance > dist_scale[led_index]:\n            led_ports[led_index].high()\n        else:\n            led_ports[led_index].low()\n\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\ndef play_no_signal():\n    playtone(100)\n    time.sleep(0.1)\n    bequiet()\n\ndef play_turn():\n    playtone(500)\n    time.sleep(0.1)\n    bequiet()\n\n# start our time-of-flight sensor\ntof.start()\nvalid_distance = 1\n\n# loop forever\ndef main():\n    while True:\n        global valid_distance\n        distance = get_distance()\n        if distance > 1000:\n            # only print if we used to have a valid distance\n            if valid_distance == 1:\n                print('no signal')\n\n            valid_distance = 0\n        else:\n            print(distance)\n            if distance < 30:\n                play_turn()\n            valid_distance = 1\n            led_show_dist(distance)\n        time.sleep(0.05)\n\n# clean up\n\n\n# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('turning off sound')\n    buzzer.duty_u16(0)\n    tof.stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/20-collision-avoidance-robot/","title":"Maker Pi RP2040 Collision Avoidance Robot","text":"

                                                                                                                                                                                                                                                                                                              This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board.

                                                                                                                                                                                                                                                                                                              The board is mounted on a SmartCar Chassis and Grove Connector 0 is used to connect to a Time-of-Flight distance sensor that is using the I2C bus.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/20-collision-avoidance-robot/#random-turn-direction","title":"Random Turn Direction","text":"
                                                                                                                                                                                                                                                                                                              if dist < TURN_DIST:\n    play_reverse()\n    reverse()\n    sleep(REVERSE_TIME)\n    # half right and half left turns\n    if urandom.random() < .5:\n        turn_right()\n        play_turn_right()\n    else:\n        turn_left()\n        play_turn_left()\n    sleep(TURN_TIME)\n    forward()\n
                                                                                                                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board\n\nfrom machine import Pin,PWM\nfrom time import sleep, sleep_ms\nimport urandom\nimport VL53L0X\n\n# Piezo Buzzer is on GP22\nbuzzer=PWM(Pin(22))\n\n# this is the max power level\nPOWER_LEVEL = 65025\n\n# Motor Pins are A: 8,9 and B: 10,11\nRIGHT_FORWARD_PIN = 8\nRIGHT_REVERSE_PIN = 9\nLEFT_FORWARD_PIN = 11\nLEFT_REVERSE_PIN = 10\n\n# our PWM objects\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(65025)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\n# Time of flight sensor is on the I2C bus on Grove connector 0\nsda=machine.Pin(0) # row one on our standard Pico breadboard\nscl=machine.Pin(1) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n# print(\"Device found at decimal\", i2c.scan())\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs\nblue_led_pins = [2, 3,  4,  5,  6,  7, 16, 17, 26, 27, 28]\n# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]\ndist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]\n\nnumber_leds = len(blue_led_pins)\nled_ports = []\ndelay = .05\n\n# calibration parameters\nzero_dist = 65 # distance measure when an object is about 1/2 cm away\nmax_dist = 350 # max distance we are able to read\nscale_factor = .2\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\n\n# blue up\nfor i in range(0, number_leds):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n# blue down\nfor i in range(number_leds - 1, 0, -1):\n    led_ports[i].high()\n    time.sleep(delay)\n    led_ports[i].low()\n\n# get the normalized time-of-flight distance\ndef get_distance():\n    global zero_dist, scale_factor\n    tof_distance = tof.read()\n    if tof_distance > max_dist:\n        return tof_distance\n    # if our current time-of-flight distance is lower than our zero distance then reset the zero distance\n    if tof_distance < zero_dist:\n        zero_dist = tof_distance\n    return  int((tof_distance - zero_dist) * scale_factor)\n\ndef led_show_dist(in_distance):\n    global number_leds\n    for led_index in range(0, number_leds):\n        if in_distance > dist_scale[led_index]:\n            led_ports[led_index].high()\n        else:\n            led_ports[led_index].low()\n\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\ndef play_no_signal():\n    playtone(100)\n    time.sleep(0.1)\n    bequiet()\n\ndef play_turn():\n    playtone(500)\n    sleep(0.1)\n    bequiet()\n\n# start our time-of-flight sensor\ntof.start()\nvalid_distance = 1\n\n# loop forever\ndef main():\n    global valid_distance\n    while True:  \n        distance = get_distance()\n        if distance > 1000:\n            # only print if we used to have a valid distance\n            if valid_distance == 1:\n                print('no signal')      \n            valid_distance = 0\n        else:\n            print(distance)\n            if distance < 30:\n                play_turn()\n                # back up for 1/2 second\n                reverse()\n                sleep(0.5)\n                turn_right()\n                sleep(0.75)\n                forward()\n            else:\n                print('forward')\n                forward()\n            valid_distance = 1\n            led_show_dist(distance)\n        sleep(0.05)\n\n# clean up\n\n\n# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('turning off sound')\n    buzzer.duty_u16(0)\n    print('powering down all motors')\n    stop()\n    print('stopping time of flight sensor')\n    tof.stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/","title":"Maker Pi RP2040 Collision Avoidance Robot With Ping Sensor","text":"

                                                                                                                                                                                                                                                                                                              This robot works very similar to our standard CoderDojo Collision Avoidance Robot but all the pins are now configured to use the connections on the Maker Pi RP2040 board.

                                                                                                                                                                                                                                                                                                              The board is mounted on a SmartCar Chassis and Grove Connector 4 is used to connect the ultrasonic ping sensor. Connect the Trigger on white and Echo on yellow. The black should be connected to GND and the Red is connected to the VCC which on the

                                                                                                                                                                                                                                                                                                              The robot has an initial mode of 0, which will run the blue LEDs and change colors on the Neopixels. By pressing the on-board button you will start the collision avoidance program.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/#robot-parameters","title":"Robot Parameters","text":"

                                                                                                                                                                                                                                                                                                              There are four different robot parameters you can adjust. They change the speed and distance before the robot backs up. You can also adjust the time the robots goes into reverse and the time it turns.

                                                                                                                                                                                                                                                                                                              POWER_LEVEL = 35000 # max is \nTURN_DISTANCE = 20 # distance in cm we decide to turn - try 20\nREVERSE_TIME = .4 # how long we backup\nTURN_TIME = .4 # how long we turn\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/#full-source-code","title":"Full Source Code","text":"
                                                                                                                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board using Ping sensor\nfrom machine import Pin, PWM, Timer\nimport utime\nimport urandom\nfrom neopixel import Neopixel\n\n# Adjust these parameters to tune the collision avoidance behavior\n\nPOWER_LEVEL = 35000\nTURN_DISTANCE = 20 # distance we decide to turn - try 20\nREVERSE_TIME = .4 # how long we backup\nTURN_TIME = .4 # how long we turn\n\n# startup mode is 0 - motors off and LEDs flashing\n# mode 1 is slow\n# mode 2 is medium\n# mode 3 is fast\nmode = 0\n\n# Use the Grove 4 Connector and put trigger on white and echo on yellow\nTRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner\nECHO_PIN = 17 # One up from bottom left corner\n\n# Init HC-SR04P pins\ntrigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor\necho = Pin(ECHO_PIN, Pin.IN) # get the delay interval back\n\nfaster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)\nslower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\nlast_time = 0 # the last time we pressed the button\n\n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global mode, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '20' in str(pin):\n            mode +=1\n        else:\n            mode -=1\n        # deal with ends\n        if mode > 4: mode = 2\n        if mode < 0: mode = 0\n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nfaster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nslower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# Piezo Buzzer is on GP22\nbuzzer=PWM(Pin(22))\n\nMAX_POWER_LEVEL = 65025\n\nMAX_DISTANCE = 100 # ignore anything above this\n\n# Motor Pins are A: 8,9 and B: 10,11\nRIGHT_FORWARD_PIN = 11\nRIGHT_REVERSE_PIN = 10\nLEFT_FORWARD_PIN = 9\nLEFT_REVERSE_PIN = 8\n\n# our PWM objects\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n# returns distance in cm\ndef ping():\n    print('in ping')\n    trigger.low()\n    utime.sleep_us(2) # Wait 2 microseconds low\n    trigger.high()\n    utime.sleep_us(5) # Stay high for 5 miroseconds\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    print('echo is 1')\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    print(distance)\n    return int(distance)\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(65025)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs\n# remove 16 and 17 since the are used for the ping sensor\nblue_led_pins = [0, 1, 2, 3,  4,  5,  6,  7, 26, 27, 28]\n# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]\ndist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nNEOPIXEL_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, \"GRB\")\nstrip.brightness(100)\n\nnumber_leds = len(blue_led_pins)\nled_ports = []\nred = (255, 0, 0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncyan = (0, 255, 255)\nlightgreen = (100, 255, 100)\nwhite = (128, 128, 128) # not too bright\npink = (255, 128, 128)\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink)\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\nLED_DELAY = .08\ndef run_lights():\n    for i in range(0, number_leds):\n        led_ports[i].high()\n        strip.set_pixel(0, colors[i])\n        strip.set_pixel(1, colors[i])\n        strip.show()\n        utime.sleep(LED_DELAY)\n        led_ports[i].low()\n    # blue down\n    for i in range(number_leds - 1, 0, -1):\n        led_ports[i].high()\n        strip.set_pixel(0, colors[i])\n        strip.set_pixel(1, colors[i])\n        strip.show()\n        utime.sleep(LED_DELAY)\n        led_ports[i].low()\n\ndef led_show_dist(in_distance):\n    global number_leds\n    for led_index in range(0, number_leds):\n        if in_distance > dist_scale[led_index]:\n            led_ports[led_index].high()\n        else:\n            led_ports[led_index].low()\n\ndef play_no_signal():\n    playnote(100, 0.1)\n    sound_off()\n\ndef play_turn():\n    playnote(500, .1)\n    sound_off()\n\ndef setfreq(frequency):\n    buzzer.freq(frequency)\n\ndef playnote(frequency, time):\n    buzzer.duty_u16(1000)\n    setfreq(frequency)\n    utime.sleep(time)\n\ndef sound_off():\n    buzzer.duty_u16(0)\n\ndef rest(time):\n    buzzer.duty_u16(0)\n    utime.sleep(time)\n\ndef play_startup():\n    playnote(600, .2)\n    rest(.05)\n    playnote(600, .2)\n    rest(.05)\n    playnote(600, .2)\n    rest(.1)\n    playnote(800, .4)\n    sound_off()\n\nvalid_distance = 1\n# loop forever\ndef main():\n    global valid_distance\n    print(\"running main()\")\n\n    play_startup()\n\n    while True:\n        if mode == 0:\n            stop()\n            run_lights()\n        else:\n            distance = ping()\n            print('Distance:', distance)\n            if distance > MAX_DISTANCE:\n                # only print if we used to have a valid distance\n                if valid_distance == 1:\n                    print('no signal')      \n                valid_distance = 0\n            else:\n                print(distance)\n                if distance < TURN_DISTANCE:\n                    play_turn()\n                    # back up for a bit\n                    reverse()\n                    utime.sleep(REVERSE_TIME)\n                    # half right and half left turns\n                    if urandom.random() < .5:\n                        turn_right()\n                    else:\n                        turn_left()\n                    utime.sleep(TURN_TIME)\n                    forward()\n                else:\n                    print('forward')\n                    forward()\n                valid_distance = 1\n                led_show_dist(distance)\n            utime.sleep(0.05)\n\n# clean up\n\n# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('turning off sound')\n    buzzer.duty_u16(0)\n    print('shutting motors down')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/21-collision-avoidance-ping/#experiments","title":"Experiments","text":"
                                                                                                                                                                                                                                                                                                              1. Adjust the power level and the distance before turning. See how these change the performance of the robot.
                                                                                                                                                                                                                                                                                                              2. Adjust the angle of the ping sensor by gently heating the plexiglass holder. How does this change the robot behavior?
                                                                                                                                                                                                                                                                                                              3. Add additional modes that change the power and the turn distance. You can have one mode for slow, one for medium and one for fast.
                                                                                                                                                                                                                                                                                                              4. Change the Neopixel colors to indicate the distance to an object.
                                                                                                                                                                                                                                                                                                              5. Change the pattern of the blue LEDs to indicate the distance to the object.
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/23-microswitch-bot/","title":"MicroSwitch Robot using the Cytron Maker Pi RP2040","text":"

                                                                                                                                                                                                                                                                                                              This robot was inspired by my friend, Michael York.

                                                                                                                                                                                                                                                                                                              Microswitches can be purchased for under $1. They can be mounted on the front of our robot. When the robot hits a wall in front of it the switch will open (or close) and the robot controller can make the robot go in reverse or turn.

                                                                                                                                                                                                                                                                                                              In the example below, we attached a stiff wire to the lever of the microswitch.

                                                                                                                                                                                                                                                                                                              In the example below, we connected three microswitches to the front of our robot.

                                                                                                                                                                                                                                                                                                              If the left switch is activated, the robot should turn to the right. If the right switch is activated, the robot should go to the left.

                                                                                                                                                                                                                                                                                                              This image shows how we used two of the Grove connectors to read in the values of the switches.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/23-microswitch-bot/#testing-switches","title":"Testing Switches","text":"

                                                                                                                                                                                                                                                                                                              The following code can be used to test your switches. A line on the console prints out which of the three switches are activated using the pin value() function.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom time import sleep\n\n# GPIO is the internal built-in LED\nled0 = Pin(0, Pin.OUT)\nled1 = Pin(1, Pin.OUT)\nled2 = Pin(2, Pin.OUT)\n\n# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating\nmiddle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) \nright_switch = Pin(28, Pin.IN, Pin.PULL_DOWN)\nleft_switch = Pin(27, Pin.IN, Pin.PULL_DOWN)\n\nwhile True:\n    if middle_switch.value(): # if the value changes\n        led0.on()\n        print('middle')\n    else: led0.off()\n\n    if right_switch.value(): # if the value changes\n        led1.on()\n        print('right')\n    else: led1.off()\n\n    if left_switch.value(): # if the value changes\n        led2.on()\n        print('left')\n    else: led2.off()\n    sleep(.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/23-microswitch-bot/#sample-collision-avoidance-robot-code","title":"Sample Collision Avoidance Robot Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom time import sleep\n\n# GPIO is the internal built-in LED\nled0 = Pin(0, Pin.OUT)\nled1 = Pin(1, Pin.OUT)\nled2 = Pin(2, Pin.OUT)\n\n# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating\nmiddle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) \nright_switch = Pin(28, Pin.IN, Pin.PULL_DOWN)\nleft_switch = Pin(27, Pin.IN, Pin.PULL_DOWN)\n\n# Go slow to avoid bending wires\nPOWER_LEVEL = 25000 # max is 65000\n\n# These values depend on motor wiring\nRIGHT_FORWARD_PIN = 10\nRIGHT_REVERSE_PIN = 11\nLEFT_FORWARD_PIN = 9\nLEFT_REVERSE_PIN = 8\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\ndef main():\n    while True:\n        if middle_switch.value(): # if the value changes\n            print('middle')\n            led0.on()\n            reverse()\n            sleep(1)\n            turn_right()\n            sleep(.75)\n            forward()\n        else:\n            led0.off()\n            forward()\n\n        if right_switch.value(): # if the value changes\n            print('right')\n            led1.on()\n            reverse()\n            sleep(.75)\n            turn_left()\n            sleep(.5)\n            forward()\n        else:\n            led1.off()\n            forward()\n\n        if left_switch.value(): # if the value changes\n            led2.on()\n            print('left')\n            reverse()\n            sleep(.75)\n            turn_right()\n            sleep(.5)\n            forward()\n        else:\n            led2.off()\n            forward()\n\nprint('middle', middle_switch.value())\nprint('left', left_switch.value())\nprint('right', right_switch.value())\n\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Optional cleanup code\n    print('turning off sound')\n    # sound_off()\n    print('turning off motors')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/24-ping-servo-meter/","title":"Cytron Maker Pi RP2040 Ping Servo Meter Bot","text":"

                                                                                                                                                                                                                                                                                                              This robot works very similar to our standard CoderDojo Collision Avoidance Robot. However it adds a 180 degree servo to show the distance to the object in front of it. It also uses a OLED display to present instructions and display the distance to the object.

                                                                                                                                                                                                                                                                                                              This program was contributed by Joe Glenn for the Minneapolis Bakken Museum Droid December event in December 2021.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/24-ping-servo-meter/#test-servo","title":"Test Servo","text":"

                                                                                                                                                                                                                                                                                                              This program tests the servo by sweeping the angle from 0 to 180 and back.

                                                                                                                                                                                                                                                                                                              # servo sweep test\n# Brown: GND\n# Orange/Red : VCC\n# Yellow: Signal\n#\n# Time for high level (Radio Shack Micro-servo @ 5V)\n# 0.5 ms :   0 degree\n# 1.0 ms :  45 degree\n# 1.5 ms :  90 degree\n# 2.0 ms : 135 degree\n# 2.5 ms : 180 degree\n\nfrom machine import Pin, PWM\nfrom time import sleep\n\nSERVO_PIN = 15\nservoPin = PWM(Pin(SERVO_PIN))\nservoPin.freq(50)\n\ndef servo(degrees):\n    if degrees > 180: degrees=180\n    if degrees < 0: degrees=0\n    maxDuty=8000 # duty*100\n    minDuty=2000 # duty*100\n    #maxDuty=2000 # test\n    #minDuty=8000 # test\n    newDuty=minDuty+(maxDuty-minDuty)*(degrees/180)\n    servoPin.duty_u16(int(newDuty))\n\nwhile True:\n\n  for degree in range(0,180,1):\n    servo(degree)\n    sleep(0.01)\n    print(\"increasing -- \"+str(degree))\n\n  for degree in range(180, 0, -1):\n    servo(degree)\n    sleep(0.01)\n    print(\"decreasing -- \"+str(degree))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/24-ping-servo-meter/#main-python-code","title":"Main Python Code","text":"
                                                                                                                                                                                                                                                                                                              # Demo for Maker Pi RP2040 board using Ping sensor, servo and i2c display\n\nfrom machine import Pin, PWM, Timer\nimport utime\nimport urandom\nfrom ssd1306 import SSD1306_I2C\nfrom neopixel import Neopixel\nfrom machine import Pin, I2C\nfrom ssd1306 import SSD1306_I2C\nimport framebuf\nimport math\nimport utime\n#\n# Ping Sensor\n# Use the Grove 4 Connector and put trigger on white and echo on yellow\n#\nPING_TRIGGER_PIN = 7 # GP7\nPING_ECHO_PIN = 28 # GP28\n\n#\n# i2c OLED 128x32\n#\nOLED_SDA_PIN = 26 # GP26\nOLED_SCL_PIN = 27 # GP27\n\n#\n# Servo\n# GND: Brown\n# VCC: Orange/Red\n# GP15 Yellow: Signal\n#\n# Time for high level (Radio Shack Micro-servo @ 5V)\n# 0.5 ms :   0 degree\n# 1.0 ms :  45 degree\n# 1.5 ms :  90 degree\n# 2.0 ms : 135 degree\n# 2.5 ms : 180 degree\nSERVO_PIN = 15\n\n# IQR Pins\nFASTER_PIN = 20\nSLOWER_PIN = 21\n\n# built-in Buzzer\nBUZZER_PIN = 22\n\n# Adjust these parameters to tune the collision avoidance behavior\n\nPOWER_LEL = 35000\nTURN_DISTANCE = 20 # distance we decide to turn - try 20\nREVERSE_TIME = .4 # how long we backup\nTURN_TIME = .4 # how long we turn\n\n# startup mode is 0 - motors off and LEDs flashing\n# mode 1 is slow\n# mode 2 is medium\n# mode 3 is fast\nmode = 0\n\n# Init HC-SR04P pins\ntrigger = Pin(PING_TRIGGER_PIN, Pin.OUT) # send trigger out to sensor\necho = Pin(PING_ECHO_PIN, Pin.IN) # get the delay interval back\n\nfaster_pin = machine.Pin(FASTER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\nslower_pin = machine.Pin(SLOWER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\nlast_time = 0 # the last time we pressed the button\n\n#\n# DISPLAY STUFF\n#\n# Display Image & text on I2C driven ssd1306 OLED display \n\n\nWIDTH  = 128 # oled display width\nHEIGHT = 32  # oled display height\n\n# Explicit Method\nsda=machine.Pin(OLED_SDA_PIN)\nscl=machine.Pin(OLED_SCL_PIN)\ni2c=machine.I2C(1,sda=sda, scl=scl, freq=40000) # 400k is too fast and has issues\nprint( 'i2c={:02X}'.format( i2c.scan()[0] ) )\n#print(help(i2c))\n#print(help(i2c.init))\n#print(help(i2c.scan))\n#print(help(i2c.start))\n#print(help(i2c.stop))\n#print(help(i2c.readinto))\n#print(help(i2c.write))\n#print(help(i2c.readfrom))\n#print(help(i2c.readfrom_into))\n#print(help(i2c.writeto))\n#print(help(i2c.writevto))\n#print(help(i2c.readfrom_mem))\n#print(help(i2c.readfrom_mem_into))\n#print(help(i2c.writeto_mem))\n#exit\n\noled = SSD1306_I2C(128, 32, i2c)\n\n# Raspberry Pi logo as 32x32 bytearray\nbuffer = bytearray(b\"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00|?\\x00\\x01\\x86@\\x80\\x01\\x01\\x80\\x80\\x01\\x11\\x88\\x80\\x01\\x05\\xa0\\x80\\x00\\x83\\xc1\\x00\\x00C\\xe3\\x00\\x00~\\xfc\\x00\\x00L'\\x00\\x00\\x9c\\x11\\x00\\x00\\xbf\\xfd\\x00\\x00\\xe1\\x87\\x00\\x01\\xc1\\x83\\x80\\x02A\\x82@\\x02A\\x82@\\x02\\xc1\\xc2@\\x02\\xf6>\\xc0\\x01\\xfc=\\x80\\x01\\x18\\x18\\x80\\x01\\x88\\x10\\x80\\x00\\x8c!\\x00\\x00\\x87\\xf1\\x00\\x00\\x7f\\xf6\\x00\\x008\\x1c\\x00\\x00\\x0c \\x00\\x00\\x03\\xc0\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\")\n\n# Load the raspberry pi logo into the framebuffer (the image is 32x32)\nfb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)\n\ndef blk():\n    oled.fill(0)\n    oled.show()\n\ndef horiz(l,t,r,c):  # left, right , top\n    n = r-l+1        # Horizontal line\n    for i in range(n):\n        oled.pixel(l + i, t, c)\n\ndef vert(l,t,b,c):   # left, top, bottom\n    n = b-t+1        # Vertical line\n    for i in range(n):\n        oled.pixel(l, t+i,c)\n\ndef box(l,t,r,b,c):  # left, top, right, bottom\n    horiz(l,t,r,c)   # Hollow rectangle\n    horiz(l,b,r,c)\n    vert(l,t,b,c)\n    vert(r,t,b,c)\n\ndef ring2(cx,cy,r,c):   # Centre (x,y), radius, colour\n    for angle in range(0, 90, 2):  # 0 to 90 degrees in 2s\n        y3=int(r*math.sin(math.radians(angle)))\n        x3=int(r*math.cos(math.radians(angle)))\n        oled.pixel(cx-x3,cy+y3,c)  # 4 quadrants\n        oled.pixel(cx-x3,cy-y3,c)\n        oled.pixel(cx+x3,cy+y3,c)\n        oled.pixel(cx+x3,cy-y3,c)\n\n#print(help(oled.text()))\n#print(help())\n#help('modules')\n#help(oled)\n#help(oled.text)\n#help(framebuf.FrameBuffer)\n#help(framebuf.FrameBuffer.help())\n\n# Clear the oled display in case it has junk on it.\noled.fill(0) # Black\n\n# Blit the image from the framebuffer to the oled display\noled.blit(fb, 96, 0)\n\n# Basic stuff\noled.text(\"Raspberry Pi\",5,5)\noled.text(\"RP2040\",5,15)\noled.text(\"press GP21\",5,25)\noled.pixel(10,60,1)\n\n#ring2(50,43,20,1)  # Empty circle             \n# Finally update the oled display so the image & text is displayed\noled.show()\nutime.sleep(1)\n\n\n#\n# Back to the motor control stuff. (sorry... i'm soppy today)\n# \n# This function gets called every time the button is pressed.  The parameter \"pin\" is not used.\ndef button_pressed_handler(pin):\n    global mode, last_time\n    new_time = utime.ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200:\n        # this should be pin.id but it does not work\n        if '21' in str(pin):\n            mode +=1\n        else:\n            mode -=1\n        # deal with ends\n        if mode > 4: mode = 2\n        if mode < 0: mode = 0\n        last_time = new_time\n\n# now we register the handler function when the button is pressed\nfaster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\nslower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\n# Piezo Buzzer is on GP22\nbuzzer=PWM(Pin(BUZZER_PIN))\n\nMAX_POWER_LEVEL = 65025\n\nMAX_DISTANCE = 100 # ignore anything above this\n\n# Motor Pins are A: 8,9 and B: 10,11\nRIGHT_FORWARD_PIN = 11 # this must be wired backword?\nRIGHT_REVERSE_PIN = 10 \nLEFT_FORWARD_PIN = 9\nLEFT_REVERSE_PIN = 8\n\n# our PWM objects\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n# returns distance in cm\ndef ping():\n    #print('in ping')\n    trigger.low()\n    utime.sleep_us(2) # Wait 2 microseconds low\n    trigger.high()\n    utime.sleep_us(5) # Stay high for 5 miroseconds\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    #print('echo is 1')\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    print(distance)\n\n    return int(distance)\n\ndef turn_motor_on(pwm):\n   #pwm.duty_u16(65025)\n   pwm.duty_u16(16000)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\n# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs\nblue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28]\nblue_led_pins.remove(PING_TRIGGER_PIN)\nblue_led_pins.remove(PING_ECHO_PIN)\nblue_led_pins.remove(OLED_SDA_PIN)\nblue_led_pins.remove(OLED_SCL_PIN)\n\n\n# dist_scale =    [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100]\ndist_scale =    [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300]\n\nNUMBER_PIXELS = 2\nSTATE_MACHINE = 0\nNEOPIXEL_PIN = 18\n\n# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB\nstrip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, \"GRB\")\nstrip.brightness(100)\n\nnumber_leds = len(blue_led_pins)\nled_ports = []\nred = (255, 0, 0)\norange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow\nyellow = (255, 150, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130) # purple?\nviolet = (138, 43, 226) # mostly pink\ncyan = (0, 255, 255)\nlightgreen = (100, 255, 100)\nwhite = (128, 128, 128) # not too bright\npink = (255, 128, 128)\ncolor_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white')\nnum_colors = len(color_names)\ncolors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink)\n\n# create a list of the ports\nfor i in range(number_leds):\n   led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT))\n\nLED_DELAY = .08\ndef run_lights():\n    for i in range(0, number_leds):\n        led_ports[i].high()\n        strip.set_pixel(0, colors[i])\n        strip.set_pixel(1, colors[i])\n        strip.show()\n        utime.sleep(LED_DELAY)\n        led_ports[i].low()\n    # blue down\n    for i in range(number_leds - 1, 0, -1):\n        led_ports[i].high()\n        strip.set_pixel(0, colors[i])\n        strip.set_pixel(1, colors[i])\n        strip.show()\n        utime.sleep(LED_DELAY)\n        led_ports[i].low()\n\ndef led_show_dist(in_distance):\n    global number_leds\n    for led_index in range(0, number_leds):\n        if in_distance > dist_scale[led_index]:\n            led_ports[led_index].high()\n        else:\n            led_ports[led_index].low()\n\ndef play_no_signal():\n    playnote(100, 0.1)\n    sound_off()\n\ndef play_turn():\n    playnote(500, .1)\n    sound_off()\n\ndef setfreq(frequency):\n    buzzer.freq(frequency)\n\ndef playnote(frequency, time):\n    buzzer.duty_u16(1000)\n    setfreq(frequency)\n    utime.sleep(time)\n\ndef sound_off():\n    buzzer.duty_u16(0)\n\ndef rest(time):\n    buzzer.duty_u16(0)\n    utime.sleep(time)\n\ndef play_startup():\n    playnote(600, .2)\n    rest(.05)\n    playnote(600, .2)\n    rest(.05)\n    playnote(600, .2)\n    rest(.1)\n    playnote(800, .4)\n    sound_off()\n\ndef servo(degrees):\n    if degrees > 180: degrees=180\n    if degrees < 0: degrees=0\n    maxDuty=8000 # duty*100\n    minDuty=2000 # duty*100\n    #maxDuty=2000 # test\n    #minDuty=8000 # test\n    newDuty=minDuty+(maxDuty-minDuty)*(degrees/180)\n    servoPin.duty_u16(int(newDuty))\n\nservoPin = PWM(Pin(SERVO_PIN))\nservoPin.freq(50)\n\nvalid_distance = 1\n\ndef main():\n    global valid_distance\n    print(\"running main()\")\n\n    play_startup()\n    oled_count=0 # repeat every\n    oled_count_max=0 # times through loop\n    servo_count=0 \n    servo_count_max=0 # when to update\n    servo_degrees = 0\n    servo(servo_degrees) # start in that pos\n\n    # loop forever\n    while True:\n        if mode == 0:\n            stop()\n            run_lights()\n        else:\n            distance = ping()\n            print('Distance:', distance)\n            oled_count += 1\n            if oled_count > oled_count_max:\n                oled.fill(0) # Black\n                oled.text(\"Distance:\",5,5)\n                oled.text(\"{:f}\".format(distance),5,15)\n                oled.show()\n                oled_count = 0\n\n            servo_count += 1\n            if servo_count > servo_count_max:\n                if distance > MAX_DISTANCE:\n                    servo_degrees = 0\n                else:\n                    servo_degrees = 180-distance/MAX_DISTANCE*180\n                servo(servo_degrees)\n                servo_count = 0\n\n            if distance > MAX_DISTANCE:\n                # only print if we used to have a valid distance\n                if valid_distance == 1:\n                    print('no signal')      \n                valid_distance = 0\n            else:\n                print(distance)\n                #note=distance*10\n                #playnote(note, .025)\n\n                if distance < TURN_DISTANCE:\n                    play_turn()\n                    # back up for a bit\n                    reverse()\n                    utime.sleep(REVERSE_TIME)\n                    # half right and half left turns\n                    if urandom.random() < .5:\n                        turn_right()\n                    else:\n                        turn_left()\n                    utime.sleep(TURN_TIME)\n                    forward()\n                else:\n                    print('forward')\n                    forward()\n                valid_distance = 1\n                led_show_dist(distance)\n            utime.sleep(0.05)\n\n# clean up\n\n# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nexcept Exception as e: print(e)\nfinally:\n    # Optional cleanup code\n    print('turning off sound')\n    buzzer.duty_u16(0)\n    print('shutting motors down')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/25-line-follower/","title":"Line Follower Robot","text":"

                                                                                                                                                                                                                                                                                                              Line following robot projects is a favorite project for our students. They teach the students the concept of feedback to keep a robot following a line on a track or on the floor. They are not easy to get working and require careful calibration of the sensor sensitivity and carefully adjusting the right and left motor power to keep the robot on track. Once the student gets the robot working it is a time for celebration!

                                                                                                                                                                                                                                                                                                              The total cost of the kit is about $20.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/25-line-follower/#parts-list","title":"Parts List","text":"Part Name Description Price Link Cytron Board Main board with RP2040 and motor driver. Kits come with Grove connectors and a screwdriver. $12 SmartCar Chassis SmartCar chassis with wheels and 4 AA battery pack IR Sensors (2) Low cost IR light sensors $1"},{"location":"kits/maker-pi-rp2040-robot/25-line-follower/#ir-sensors","title":"IR Sensors","text":"

                                                                                                                                                                                                                                                                                                              We can purchase IR sensors on eBay for about $1 each in quantity 10. The sensors send a digital 0/1 signal to the microcontroller depending on if they are over the line. Our job is to write some MicroPython code to keep the robot following the line. Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room.

                                                                                                                                                                                                                                                                                                              Each IR sensor has a small trim potentiometer that we must adjust for the correct sensitivity for each room. Some of our rooms have a white floor with a black line and some of our rooms have a dark floor with a white line. You may have to adjust both the trim potentiometer and the logic of the code for different situations.

                                                                                                                                                                                                                                                                                                              Use the Grove connectors to hook up the IR sensors. I used the red (VCC), black (GDN) and white wires (Data) and I just cut off the yellow wires to keep them out of the way. I then connected the Grove connectors to ports 2 and 3 of the Cytron board.

                                                                                                                                                                                                                                                                                                              I connected the motors to the MOTOR 1 and MOTOR 2 headers with a screwdriver and I hooked the battery wires up to the power header of the board.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom utime import sleep\n\nRIGHT_SENSOR_PIN = 2\nLEFT_SENSOR_PIN = 4\n\nright_sensor = Pin(RIGHT_SENSOR_PIN)\nleft_sensor = Pin(LEFT_SENSOR_PIN)\n\nwhile True:\n    r = right_sensor.value()\n    l = left_sensor.value()\n    print(\"r\", r, \"l=\", l)\n    if r == 0:\n        print(\"right over white\")\n    if l == 0:\n        print(\"left over white\")\n    sleep(.2)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/maker-pi-rp2040-robot/25-line-follower/#full-source-code","title":"Full Source Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom time import sleep\n\n# sensor setup\nRIGHT_SENSOR_PIN = 2\nLEFT_SENSOR_PIN = 4\n\nright_sensor = Pin(RIGHT_SENSOR_PIN)\nleft_sensor = Pin(LEFT_SENSOR_PIN)\n\n# speaker pin on the Cytron Maker Pi RP2040\nSPEAKER_PIN = 22\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n# set the duty cycle\nspeaker.duty_u16(1000)\n\n# Motor setup\nRIGHT_FORWARD_PIN = 11\nRIGHT_REVERSE_PIN =10\nLEFT_FORWARD_PIN = 8\nLEFT_REVERSE_PIN = 9\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\nMAX_POWER_LEVEL = 65025\nQUARTER_POWER = 65025 >> 2\nSLOW_DRIVE_POWER = 16000\nBOOST_LEVEL = 15000\n\n# while True:\ndef spin_wheel(pwm):\n    pwm.duty_u16(SLOW_DRIVE_POWER)\n    sleep(2)\n    pwm.duty_u16(0)\n    sleep(1)\n\ndef forward():\n    right_forward.duty_u16(SLOW_DRIVE_POWER)\n    right_reverse.duty_u16(0)\n    left_forward.duty_u16(SLOW_DRIVE_POWER)\n    left_reverse.duty_u16(0)\n    speaker.duty_u16(0)\n\ndef right():\n    right_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL)\n    right_reverse.duty_u16(0)\n    left_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL)\n    left_reverse.duty_u16(0)\n    speaker.duty_u16(1000)\n    speaker.freq(800)\n\ndef left():\n    right_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL)\n    right_reverse.duty_u16(0)\n    left_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL)\n    left_reverse.duty_u16(0)\n    speaker.duty_u16(1000)\n    speaker.freq(1000)\n\ndef stop():\n    right_forward.duty_u16(0)\n    right_reverse.duty_u16(0)\n    left_forward.duty_u16(0)\n    left_reverse.duty_u16(0)\n    speaker.duty_u16(0)\n\ndef main():\n    while True:\n        r = right_sensor.value()\n        l = left_sensor.value()\n        if r == 0 and l == 1:\n            print(\"right over white - turning left\")\n            right()\n        if l == 0:\n            print(\"left over white\")\n            left()\n        else:\n            forward()\n\n# end of main()\n\ntry:\n    main()\nexcept KeyboardInterrupt:\n    print('Got ctrl-c')\nfinally:\n    # Cleanup code\n    print('Cleaning up')\n    print('Powering down all motors now.')\n    stop()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/","title":"NeoPixel Kit","text":"

                                                                                                                                                                                                                                                                                                              This is a low-cost (under $10) kit that we use in many of our classes. It contains the following parts:

                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico ($4)
                                                                                                                                                                                                                                                                                                              2. 1/2 size breadboard ($2)
                                                                                                                                                                                                                                                                                                              3. LED Strip (WS2811b) ($3) - these come in many lengths from 8 to 60 pixels
                                                                                                                                                                                                                                                                                                              4. Two momentary push buttons (20 cents)
                                                                                                                                                                                                                                                                                                              5. USB cable (Micro-B to A)

                                                                                                                                                                                                                                                                                                              These lessons will assume you have these parts and can connect up to the Pico to your laptop using a USB cable. If you have a Mac with a USB-C connector you may need to provide a USB-C to USB-A adaptor.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/#sample-labs","title":"Sample Labs","text":"

                                                                                                                                                                                                                                                                                                              We start with the sample code in the Basics/NeoPixel area.

                                                                                                                                                                                                                                                                                                              We then show how you can load full programs. Here is the source code:

                                                                                                                                                                                                                                                                                                              NeoPixel Samples Source Code

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/#getting-started","title":"Getting Started","text":"

                                                                                                                                                                                                                                                                                                              Getting Started Lab

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/#_1","title":"Introduction","text":""},{"location":"kits/neopixel/01-getting-started/","title":"Getting Started with the NeoPixel Kit","text":"

                                                                                                                                                                                                                                                                                                              Your kit should have several parts. Place them all on a table and hook them up. When you power on the kit with your USB cable the default main.py program will be running.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/02-simple-patterns/","title":"NeoPixel Simple Patterns","text":""},{"location":"kits/neopixel/02-simple-patterns/#blink","title":"Blink","text":""},{"location":"kits/neopixel/02-simple-patterns/#wipe","title":"Wipe","text":""},{"location":"kits/neopixel/02-simple-patterns/#move-pixel","title":"Move Pixel","text":""},{"location":"kits/neopixel/03-buttons/","title":"NeoPixel Button Lab","text":""},{"location":"kits/neopixel/03-buttons/#review-of-button-basics","title":"Review of Button Basics","text":"

                                                                                                                                                                                                                                                                                                              Button Basics

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/03-buttons/#working-with-two-buttons","title":"Working with Two Buttons","text":""},{"location":"kits/neopixel/03-buttons/#changing-color-with-buttons","title":"Changing Color With Buttons","text":""},{"location":"kits/neopixel/03-buttons/#using-modes","title":"Using Modes","text":"

                                                                                                                                                                                                                                                                                                              Our LED kit can run a single \"main\" loop forever. But we often want to have the main loop run a different subprogram. Each subprogram can be triggered by pressing a button. The button will update a variable and the main loop will use this variable to redirect the main to the appropriate function.

                                                                                                                                                                                                                                                                                                              The mode variable is traditionally used to store the current subprogram being run. You are not limited to a single mode. You can also have modes within modes.

                                                                                                                                                                                                                                                                                                              1. Using a buttons to advance a mode
                                                                                                                                                                                                                                                                                                              2. Using a two buttons to move to the next and previous mode
                                                                                                                                                                                                                                                                                                              3. Using two modes - one mode or each button
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/neopixel/03-buttons/#changing-patterns-with-buttons","title":"Changing Patterns With Buttons","text":""},{"location":"kits/neopixel/03-buttons/#changing-color-and-pattern","title":"Changing Color and Pattern","text":""},{"location":"kits/neopixel/04-rotary-neopixel/","title":"Rotary NeoPixel","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we use a rotary encoder to change which pixel is turned on. Turning the knob will appear to move the pixel.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/rfid-rc522/","title":"RFIG Reader RC-522","text":"

                                                                                                                                                                                                                                                                                                              The RC-522 is a popular RFID reader that has strong support in the MicroPython community.

                                                                                                                                                                                                                                                                                                              "},{"location":"kits/rfid-rc522/#pinout","title":"Pinout","text":"NAME PICO GPIO COLOR SDA 1 Yellow SCK 2 Orange MOSI 4 Purple MISO 3 Blue IRQ 7 Brown GND GND Black RST 0 Green 3.3V 3.3v Out Red"},{"location":"kits/rfid-rc522/#wires-at-the-rc522","title":"Wires at the RC522","text":""},{"location":"kits/rfid-rc522/#wires-at-the-pico","title":"Wires at the Pico","text":""},{"location":"kits/rfid-rc522/#config-file","title":"Config File","text":"

                                                                                                                                                                                                                                                                                                              Place this in the config.py

                                                                                                                                                                                                                                                                                                              # reader = MFRC522(spi_id=0, sck=2, miso=4, mosi=3, cs=1, rst=0)\nSPI_ID = 0\nRESET_PIN = 0 # Green OUT\nSDA_PIN = 1 # Yellow OUT but used a Chip Select CS \nSCK_PIN = 2 # Orange OUT clock going from Pico to RC522\nMISO_PIN = 3 # Blue \nMOSI_PIN = 4 # Purple\nIRQ_PIN = 7 # Brown, OUT but not used in the reader demo\n\n# GND is Black\n# Red goes to 3.3v out\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/rfid-rc522/#reader","title":"Reader","text":"
                                                                                                                                                                                                                                                                                                              from mfrc522 import MFRC522\nimport utime\n\n\ndef uidToString(uid):\n    mystring = \"\"\n    for i in uid:\n        mystring = \"%02X\" % i + mystring\n    return mystring\n\n\nreader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0)\n\nprint(\"\")\nprint(\"Please place card on reader\")\nprint(\"\")\n\n\n\nPreviousCard = [0]\n\ntry:\n    while True:\n\n        reader.init()\n        (stat, tag_type) = reader.request(reader.REQIDL)\n        #print('request stat:',stat,' tag_type:',tag_type)\n        if stat == reader.OK:\n            (stat, uid) = reader.SelectTagSN()\n            if uid == PreviousCard:\n                continue\n            if stat == reader.OK:\n                print(\"Card detected {}  uid={}\".format(hex(int.from_bytes(bytes(uid),\"little\",False)).upper(),reader.tohexstring(uid)))\n                defaultKey = [255,255,255,255,255,255]\n                reader.MFRC522_DumpClassic1K(uid, Start=0, End=64, keyA=defaultKey)\n                print(\"Done\")\n                PreviousCard = uid\n            else:\n                pass\n        else:\n            PreviousCard=[0]\n        utime.sleep_ms(50)                \n\nexcept KeyboardInterrupt:\n    pass\n
                                                                                                                                                                                                                                                                                                              "},{"location":"kits/rfid-rc522/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • How To Electronics: Using RC522 RFID Reader Module with Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Dan J Perron Driver
                                                                                                                                                                                                                                                                                                              • Microcontrollers Lab Tutorial
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/30-colophon/","title":"Colophon","text":"

                                                                                                                                                                                                                                                                                                              We are mostly a group of unpaid volunteers without a large budget for distributed content management software. However, we still want to provide a great user experience for both our mentors and our students. So we use free open-source tools whenever we can. Here is how we built this site.

                                                                                                                                                                                                                                                                                                              • Our content language is Markdown.
                                                                                                                                                                                                                                                                                                              • We use Python Markdown to parse our content.
                                                                                                                                                                                                                                                                                                              • We convert Markdown to HTML with mkdocs.
                                                                                                                                                                                                                                                                                                              • Our user interface theme isMkdocs Material. We use an extensive number of Material user interface components.
                                                                                                                                                                                                                                                                                                              • Our software version control system is git
                                                                                                                                                                                                                                                                                                              • Our site is hosted on GitHub page.
                                                                                                                                                                                                                                                                                                              • We use standard code highlighting provided by the mkdocs codehilite extension.
                                                                                                                                                                                                                                                                                                              • Our BY-NC-SA content license agreement is created by Creative Commons

                                                                                                                                                                                                                                                                                                              We wish to acknowledge the work of everyone that contributes to open-source projects. Without these systems this work would not be possible.

                                                                                                                                                                                                                                                                                                              If you would like to contribute lesson we welcome your contribution as a git pull request. You can read our CoderDojo Twin CitiesAuthoring Guide if you would like to help out.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contact/","title":"Cybersecurity for Kids Contacts","text":""},{"location":"misc/contact/#general-code-savvy-contact","title":"General Code Savvy Contact","text":"

                                                                                                                                                                                                                                                                                                              kidscode@codesavvy.org

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contact/#contact-for-coderdojo-twin-cities","title":"Contact for CoderDojo Twin Cities","text":"

                                                                                                                                                                                                                                                                                                              hello@coderdojotc.org

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contact/#specific-questions-on-this-repository","title":"Specific questions on this repository","text":"

                                                                                                                                                                                                                                                                                                              Dan McCreary

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/","title":"MicroPython Book Contributing Guide","text":"

                                                                                                                                                                                                                                                                                                              The goal of this microsite is to provide MicroPython content to STEM educational programs around the world. We value inclusion and we love low-cost projects that promote STEM instruction in communities that don't have large budgets. We value a focus on instructional design that teaches computational thinking and uses evidence of the effective delivery of this content to underprivileged communities.

                                                                                                                                                                                                                                                                                                              We welcome anyone that would like to add content to this microsite with the following guidelines:

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/#contribution-license","title":"Contribution License","text":"
                                                                                                                                                                                                                                                                                                              1. Your content must be your own original content. We discourage copying bulk content from other sites without clear understanding of the copyrights that govern this content. We put a special focus on image attribution. Any images added must clearly state that the images are original content created by the author.
                                                                                                                                                                                                                                                                                                              2. You must agree to license your new original content to allow other teachers and mentors to reuse this content in their classrooms free of charge. We use Creative Commons Licenses Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) for all content in this microsite and other microsites managed by CoderDojo Twin Cities.

                                                                                                                                                                                                                                                                                                              Under these terms teachers and mentors are free to:

                                                                                                                                                                                                                                                                                                              • Share \u2014 copy and redistribute the material in any medium or format
                                                                                                                                                                                                                                                                                                              • Adapt \u2014 remix, transform, and build upon the material

                                                                                                                                                                                                                                                                                                              The licensor cannot revoke these freedoms as long as you follow the license terms. Under the following terms:

                                                                                                                                                                                                                                                                                                              • Attribution \u2014 You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

                                                                                                                                                                                                                                                                                                              • NonCommercial \u2014 You may not use the material for commercial purposes.

                                                                                                                                                                                                                                                                                                              • ShareAlike \u2014 If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

                                                                                                                                                                                                                                                                                                              • No additional restrictions \u2014 You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/#ways-to-contribute","title":"Ways to Contribute","text":"
                                                                                                                                                                                                                                                                                                              1. Start out by helping us proof-read our content and help us find typos, spelling, lack-of clarity, and missing content. As you learn the style of our lessons you will be better able to contribute new lessons that have a similar style
                                                                                                                                                                                                                                                                                                              2. You may submit pull requests to this site of if you are not familiar with this process, you can add a link to your content in an issue.
                                                                                                                                                                                                                                                                                                              3. You may add an issue to our issues board here
                                                                                                                                                                                                                                                                                                              4. You are welcome to participate by looking for open tasks and using GitHub workflows to take on tasks to completion.
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/#teaching-suggestions","title":"Teaching Suggestions","text":"

                                                                                                                                                                                                                                                                                                              Avoid too much focus on building games that don't promote teaching computational thinking skills. Simple remote control robots might be fun, but sometime the fun of driving a robot around gets in the way of learning new concepts.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/#lesson-structure","title":"Lesson Structure","text":"
                                                                                                                                                                                                                                                                                                              1. Try to begin each section or lesson with a kid-friendly image. This help readers quickly recall if they have visited this page before.
                                                                                                                                                                                                                                                                                                              2. If if it not obvious, include any prior knowledge that is required to understand a lesson in an Intended Audience or Prerequsites section.
                                                                                                                                                                                                                                                                                                              3. Try to keep the introductory lessons in a section short and small. After you have introduce the core concepts you can integrate concepts from other areas.
                                                                                                                                                                                                                                                                                                              4. Add a \"Further Explorations\" section to the end of each lesson Include references to other sites or wikipedia articles that can be explored further.
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/contributing/#resources","title":"Resources","text":"

                                                                                                                                                                                                                                                                                                              Please see our page on Teaching Computational Thinking.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/","title":"Micropython Glossary of Terms","text":""},{"location":"misc/glossary/#ampy","title":"Ampy","text":"

                                                                                                                                                                                                                                                                                                              An obsolete MicroPython support tool created by Adafruit but no longer supported.

                                                                                                                                                                                                                                                                                                              Check out other MicroPython tools like rshell or mpfshell for more advanced interaction with boards.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#analog-to-digital-converter","title":"Analog to Digital Converter","text":"

                                                                                                                                                                                                                                                                                                              A component that takes an analogue signal and changes it to a digital one.

                                                                                                                                                                                                                                                                                                              Every ADC has two parameters, its resolution, measured in digital bits, and its channels, or how many analogue signals it can accept and convert at once.

                                                                                                                                                                                                                                                                                                              • Also know as: ADC
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#blit","title":"Blit","text":"

                                                                                                                                                                                                                                                                                                              A special form of copy operation; it copies a rectangular area of pixels from one framebuffer to another. It is used in MicroPython when doing drawing to a display such as an OLED display.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#bootsel","title":"BOOTSEL","text":"

                                                                                                                                                                                                                                                                                                              A button on the pico that when pressed during power up will allow you to mount the device as a USB drive. You can then drag-and-drop any uf2 image file to reset or update the runtime libraries.

                                                                                                                                                                                                                                                                                                              • Also known as: Boot Selection
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#castellated-edge","title":"Castellated Edge","text":"

                                                                                                                                                                                                                                                                                                              Plated through holes or vias located in the edges of a printed circuit board that make it easier to solder onto another circuit board.

                                                                                                                                                                                                                                                                                                              The word \"Castellated\" means having grooves or slots on an edge and is derived from the turrets of a castle.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#dupont-connectors","title":"Dupont Connectors","text":"

                                                                                                                                                                                                                                                                                                              Pre-made low-cost used and used to connect breadboards to hardware such as sensors and displays.

                                                                                                                                                                                                                                                                                                              The connectors are available in male and female ends and are typically sold in lengths of 10 or 20cm. They have a with a 2.54mm (100mill) pitch so they are easy to align with our standard breadboards. They are typically sold in a ribbon of mixed colors for around $2.00 US for 40 connectors.

                                                                                                                                                                                                                                                                                                              • Also known as: Jumper Wires
                                                                                                                                                                                                                                                                                                              • Sample eBay Search for Jumper Wires
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#esp32","title":"ESP32","text":"

                                                                                                                                                                                                                                                                                                              A series of low-cost, low-power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth.

                                                                                                                                                                                                                                                                                                              Typical costs for the ESP32 is are around $10 US on eBay.

                                                                                                                                                                                                                                                                                                              • Sample on eBay $5
                                                                                                                                                                                                                                                                                                              • Sample on Amazon $11
                                                                                                                                                                                                                                                                                                              • Sample on Sparkfun $21
                                                                                                                                                                                                                                                                                                              • ESP32 Quick Reference
                                                                                                                                                                                                                                                                                                              • Sample eBay Search for ESP32 from $5 to $20
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#formatted-strings","title":"Formatted Strings","text":"

                                                                                                                                                                                                                                                                                                              The ability to use a simplified syntax to format strings by added the letter \"f\" before the string. Values within curly braces are formatted from variables.

                                                                                                                                                                                                                                                                                                              name = \"Lisa\"\nage = 12\nf\"Hello, {name}. You are {age}.\"\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              Hello, Lisa. You are 12.\n

                                                                                                                                                                                                                                                                                                              Formatted string support was added to MicroPython in release 1.17. Most formats work except the date and time formats. For these we must write our own formatting functions.

                                                                                                                                                                                                                                                                                                              • Also known as: f-strings
                                                                                                                                                                                                                                                                                                              • Also known as: Literal String Interpolation
                                                                                                                                                                                                                                                                                                              • From Python Enhancement Proposal: PEP 498
                                                                                                                                                                                                                                                                                                              • Official Python documentation on string formatting
                                                                                                                                                                                                                                                                                                              • Link to Formatted Strings Docs: formatted strings
                                                                                                                                                                                                                                                                                                              • PyFormat library for formatting strings: PyFormat.info
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#framebuffer","title":"Framebuffer","text":"

                                                                                                                                                                                                                                                                                                              A region of your microcontroller RAM that stores a bitmap image of your display.

                                                                                                                                                                                                                                                                                                              For a 128X64 monochrome display this would be 128 * 64 = 8,192 bits or 1,024 bytes (1K). Color displays must store up to 8 bytes per color for each color (red, green and blue).

                                                                                                                                                                                                                                                                                                              • Wikipedia page on Framebuffer
                                                                                                                                                                                                                                                                                                              • MicroPython Documentation on FrameBuffer ]
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#interrupts","title":"Interrupts","text":"

                                                                                                                                                                                                                                                                                                              A type of signal used to pause a program and execute a different program. We use interrupts to pause our program and execute a different program when a button is pressed.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#i2c","title":"I2C","text":"

                                                                                                                                                                                                                                                                                                              A communications protocol common in microcontroller-based systems, particularly for interfacing with sensors, memory devices and liquid crystal displays.

                                                                                                                                                                                                                                                                                                              I2C is similar to SPI, it's a synchronous protocol because it uses a clock line.

                                                                                                                                                                                                                                                                                                              • Also Known as: Inter-integrated Circuit
                                                                                                                                                                                                                                                                                                              • See also: SPI
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#micropython","title":"MicroPython","text":"

                                                                                                                                                                                                                                                                                                              A set of Python libraries and tools developed specifically for microcontrollers.

                                                                                                                                                                                                                                                                                                              MicroPython was originally developed by Damien George and first released in 2014. It includes many of the features of mainstream Python, while adding a range of new ones designed to take advantage of the facilities available on Raspberry Pi Pico and other microcontroller boards like the ESP32.

                                                                                                                                                                                                                                                                                                              • See also: CircuitPython
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#mpg-shell","title":"MPG Shell","text":"

                                                                                                                                                                                                                                                                                                              A simple MicroPython shell based file explorer for ESP8266 and WiPy MicroPython based devices.

                                                                                                                                                                                                                                                                                                              The shell is a helper for up/downloading files to the ESP8266 (over serial line and Websockets) and WiPy (serial line and telnet). It basically offers commands to list and upload/download files on the flash FS of the device.

                                                                                                                                                                                                                                                                                                              GitHub Repo for MPFShell

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#oled-display","title":"OLED Display","text":"

                                                                                                                                                                                                                                                                                                              OLED (Organic polymer light emitting diode) dispays are small but bright displays with high contrast, low power and a wide viewing angle. We use these displays throughout our labs. The small displays are around 1\" (diagonal) and only cost around $4 to $5. Larger 2.24\" displays cost around $20. These displays work both with 4-wire I2C and 7-wire SPI connections.

                                                                                                                                                                                                                                                                                                              Typical chips that control the OLED include the SSD1306 driver chips.

                                                                                                                                                                                                                                                                                                              • See: Graph Displays
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#raspberry-pi-foundation","title":"Raspberry Pi Foundation","text":"

                                                                                                                                                                                                                                                                                                              The company that builds the Raspberry Pi hardware and provides some software.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#raspberry-pi-pico","title":"Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              A microcontroller designed by the Raspberry Pi foundation for doing real-time control systems.

                                                                                                                                                                                                                                                                                                              The Pico was introduced in 2020 with a retail list price of $4. It was a key development because it used a custom chip that had 100 times the RAM of an Arduino Nano.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#pico-pinout-diagram","title":"Pico Pinout Diagram","text":"

                                                                                                                                                                                                                                                                                                              The Pico pinout diagram shows you the ways that each Pin can be used. Different colors are used for GPIO numbers, I2C, and SPI interfaces.

                                                                                                                                                                                                                                                                                                              • Pinout PDF
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#pwm","title":"PWM","text":"

                                                                                                                                                                                                                                                                                                              A type of output signal used to control items with continuous values. For example, we use PWM to control the brightness of a light or the speed of a motor. We use pulse-width modulation (PWM) to control the speed of our DC motors.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#rp2040-chip","title":"RP2040 chip","text":"

                                                                                                                                                                                                                                                                                                              A custom chip created by the Raspberry Pi Foundation to power the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#rshell","title":"rshell","text":"

                                                                                                                                                                                                                                                                                                              A MicroPython shell that runs on the host and uses MicroPython's raw-REPL to send python snippets to the pyboard in order to get filesystem information, and to copy files to and from MicroPython's filesystem.

                                                                                                                                                                                                                                                                                                              It also has the ability to invoke the regular REPL, so rshell can be used as a terminal emulator as well.

                                                                                                                                                                                                                                                                                                              Note: With rshell you can disable USB Mass Storage and still copy files into and out of your pyboard.

                                                                                                                                                                                                                                                                                                              RShell GitHub Repo

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#spi","title":"SPI","text":"

                                                                                                                                                                                                                                                                                                              An interface bus commonly used to send data between microcontrollers and small peripherals such as sensors, displays and SD cards. SPI uses separate clock and data lines, along with a select line to choose the device you wish to talk to.

                                                                                                                                                                                                                                                                                                              Also known as: Serial Peripheral Interface See also: I2C

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#thonny","title":"Thonny","text":"

                                                                                                                                                                                                                                                                                                              A lightweight Python IDE ideal for writing simple Python programs for first time users.

                                                                                                                                                                                                                                                                                                              Thonny runs on Mac, Windows and Linux.

                                                                                                                                                                                                                                                                                                              • Thonny web site
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#uf2-file","title":"UF2 File","text":"

                                                                                                                                                                                                                                                                                                              The file that must be uploaded into the Raspberry Pi Pico folder to allow it to be used.

                                                                                                                                                                                                                                                                                                              The file name format looks like this:

                                                                                                                                                                                                                                                                                                              rp2-pico-20210205-unstable-v1.14-8-g1f800cac3.uf2

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#unicorn","title":"Unicorn","text":"

                                                                                                                                                                                                                                                                                                              MicroPython on Unicorn is completely open source Micropython emulator

                                                                                                                                                                                                                                                                                                              • Github Repo: https://github.com/micropython/micropython-unicorn
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/glossary/#see-also","title":"See Also","text":"

                                                                                                                                                                                                                                                                                                              MicroPython.org Glossary

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/mermaid-test/","title":"Mermaid test","text":"
                                                                                                                                                                                                                                                                                                              graph LR\n    p[Pico] -->|ADC_VREF 36 row=6| pos(Positive)\n    p[Pico] -->|AGND 33 row=8| neg(Negative)\n    p[Pico] -->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)\n    pos(Positive) --- pot(Potentiometer)\n    neg(Negative) --- pot(Potentiometer)\n    tap(Center Tap) --- pot(Potentiometer)\n
                                                                                                                                                                                                                                                                                                              graph LR\nMyApp --> DB(<font color=white>fa:fa-database MySQL)\nstyle DB fill:#00758f\n
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/projects/","title":"CoderDojo MicroPython Projects","text":"

                                                                                                                                                                                                                                                                                                              Projects are groups lesson plans that need to work together and frequently build on other projects. Key project areas include:

                                                                                                                                                                                                                                                                                                              1. Sensors - find low cost sensors and create a lesson around them
                                                                                                                                                                                                                                                                                                              2. Robot Extensions - build extensions to our Base robot
                                                                                                                                                                                                                                                                                                              3. Sound and Music - add labs that generate sound and play music
                                                                                                                                                                                                                                                                                                              4. OLED Displays and Graphics - leverage the new low-cost OLED displays
                                                                                                                                                                                                                                                                                                              5. Debugging - build lesson plans to help student learn how to debug MicroPython programs and use logic analyzers
                                                                                                                                                                                                                                                                                                              6. Advanced Labs - using multiple cores, programming the IP processors, integrating C and assembly code
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/projects/#projects-that-a-in-development","title":"Projects that a In Development","text":"

                                                                                                                                                                                                                                                                                                              Please connect with Dan McCreary if you are interested in helping out with these projects.

                                                                                                                                                                                                                                                                                                              Name Status Description Ping HC-SR04 50%) Create an OLED ping lab Motion Sensor 0% Create a lesson that uses a motion sensor. Use an OLED to display motion vs. time Photosensor 0% Create a lesson that will monitor light on a photo sensor DS18B Temp Sensor 0% Create a lesson that will read and display a waterproof temperature sensor JoyStick 0% Create a lesson that will read the X, Y and button of a JoyStick OLED JoyStick 0% Use a Joystick to move a ball around an OLED and paint pixels OLED Game of Life 0% Write a Game of Life with an OLED. Add a Joystick to paint initial conditions"},{"location":"misc/references/","title":"References for MicroPython","text":""},{"location":"misc/references/#micropython-references","title":"Micropython References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython Forum - a good place to ask questions about MicroPython. Mostly for hard core developers.
                                                                                                                                                                                                                                                                                                              2. MicroPython.org site - We would not recommend the PyBoard for beginners. They are over 10x more expensive than the the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              3. Spider Maf Github Repo
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#pico-references","title":"Pico References","text":"
                                                                                                                                                                                                                                                                                                              1. MicroPython Firmware for the Raspberry Pi Pico - You will want to bookmark this site. It has the firmware required to run MicroPython on your Raspberry Pi Pico. As of March 2021, they are fixing bugs weekly, so you will want to make sure your firmware is current.
                                                                                                                                                                                                                                                                                                              2. Pico Launch Video on YouTube
                                                                                                                                                                                                                                                                                                              3. Raspberry Pi Web Site Project Search
                                                                                                                                                                                                                                                                                                              4. Pico Data Sheet - you will only need this for detailed information on how to use the Pico hardware.
                                                                                                                                                                                                                                                                                                              5. Meet Raspberry Silicon: Raspberry Pi Pico now on sale at $4 - The original Raspberry Pi Pico announcement.
                                                                                                                                                                                                                                                                                                              6. The journey to Raspberry Silicon - blog by Liam Fraser - Feb. 8th 2021. Nice story of how the Raspberry Pi Foundation created the custom silicon chip.
                                                                                                                                                                                                                                                                                                              7. TensorFlow Lite Micro for the Pico
                                                                                                                                                                                                                                                                                                              8. Pico Invaders Video
                                                                                                                                                                                                                                                                                                              9. YouTube video of Raspberry Pi driving a full color VGA screen - Full-speed high-fidelity BBC Micro emulation on a (slightly) overclocked Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              10. Raspberry Pi RP2040: Our Microcontroller for the Masses - James Adams, COO and Director of Hardware, Raspberry Pi
                                                                                                                                                                                                                                                                                                              11. ARM Blueprint post on TinyML - nice review of the Tiny Machine Learning possible on the ARM processor.
                                                                                                                                                                                                                                                                                                              12. Google TensorFlow engineer talking about how ARM and Google are working together on TinyML - short 60 second video clip of Google TensorFlow engineer Ian Nappier talking about how they are working with ARM to create a standard TinyML library for all ARM processors to use.
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#components","title":"Components","text":"

                                                                                                                                                                                                                                                                                                              Comparison of RP2040 Boards

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#components-references","title":"Components References","text":"
                                                                                                                                                                                                                                                                                                              1. 2.42\" OLED Display from DIY More
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#variations-of-the-the-raspberry-pi-pico","title":"Variations of the the Raspberry Pi Pico","text":"
                                                                                                                                                                                                                                                                                                              1. WeAct RP2040 board adds 16MB flash, USB-C port to Raspberry Pi Pico form factor - JULY 13, 2022 BY JEAN-LUC AUFRANC (CNXSOFT) - CNX SOFTWARE \u2013 EMBEDDED SYSTEMS NEWS
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#open-source-references","title":"Open-Source References","text":"
                                                                                                                                                                                                                                                                                                              1. Open Source Guide
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#coding-general","title":"Coding General","text":"
                                                                                                                                                                                                                                                                                                              • Sam Altman on Coding
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#getting-started-videos","title":"Getting Started Videos","text":"
                                                                                                                                                                                                                                                                                                              • Raspberry Pi Pico W LESSON 1: Write Your First Program for Absolute Beginners by Paul McWhorter. A nice gentle introduction to getting started with Thonny on the Raspberry Pi Pico.
                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#snake-game","title":"Snake Game","text":"

                                                                                                                                                                                                                                                                                                              Micropython Snake Game

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/references/#turing-the-raspberry-pi-pico-into-a-logic-analyzer","title":"Turing the Raspberry Pi Pico into a Logic Analyzer","text":"

                                                                                                                                                                                                                                                                                                              Make a 100MHz 24 Channel Logic Analyzer from your favorite Raspberry Pi Pico - In this video you will learn how to setup the Raspberry Pi Pico so it can be used as a 24 channel signal analyzer. You will also see some examples using the signal analyzer decoding some different protocols like a UART, I2C-bus and 1-wire.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/upip/","title":"MicroPython PIP (UPIP)","text":"

                                                                                                                                                                                                                                                                                                              MicroPython also has a package manager that can be run directly on the microcontoller.

                                                                                                                                                                                                                                                                                                              "},{"location":"misc/upip/#install-upip-from-thonny-package-manager","title":"Install UPIP From Thonny Package Manager","text":""},{"location":"misc/upip/#install-a-package","title":"Install A Package","text":"

                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: anndan-2.4 Waiting for connection... 1.2.3.4.Connect Time: 4641 Ping the following address: 10.0.0.49 Installing to: /lib/ Warning: micropython.org SSL certificate is not validated Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/","title":"Using MicroPython to Control Motors and Servos","text":"

                                                                                                                                                                                                                                                                                                              Controlling motors are one of the funnest ways to learn how to program! They give us quick hand-on feedback on what are programs are doing. Motors are used in almost all our robot project. Robots are used in many STEM courses and coding clubs around the world. Programs like the AI Racing League allow students to learn topics like Machine Learning, Computer Vision and AI. These programs all depend on our understanding of how motors work and how to control them.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/#motor-types","title":"Motor Types","text":"

                                                                                                                                                                                                                                                                                                              There are three types of motors we will learn how to control:

                                                                                                                                                                                                                                                                                                              1. DC Motors
                                                                                                                                                                                                                                                                                                              2. Servos
                                                                                                                                                                                                                                                                                                              3. Stepper Motors
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/#outline-of-labs","title":"Outline of Labs","text":""},{"location":"motors/01-intro/#lab-1-using-and-transistor-to-control-a-motor","title":"Lab 1: Using and Transistor to Control a Motor","text":"

                                                                                                                                                                                                                                                                                                              In this lab we will use MicroPython to turn a motor on and off. We will use the digital output from the Raspberry Pi Pico to control a transistor as a switch to control the current to a motor. We will also learn how to use a diode to to protect the transistor from flyback current.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/#theory-what-is-an-h-bridge-circuit","title":"Theory: What is an H-Bridge Circuit?","text":"

                                                                                                                                                                                                                                                                                                              This lab shows a sample circuit with four switches arranged in the shape of the letter \"H\" with the motor at the center of the letter. By closing switches in opposite corners we can make the motor reverse direction.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/#lab-2-controlling-a-motor-speed-with-the-l293-h-bridge-chip","title":"Lab 2: Controlling a Motor Speed with the L293 H-Bridge Chip","text":"

                                                                                                                                                                                                                                                                                                              In this lab we will use a PWM signal to control the speed of a motor.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/01-intro/#lab-3-changing-motor-direction","title":"Lab 3: Changing Motor Direction","text":"

                                                                                                                                                                                                                                                                                                              In this lab we will make a motor go both forward and backward and change the speed.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/02-transistor/","title":"Using an Transistor to Control a Motor","text":""},{"location":"motors/02-transistor/#power-requirements-for-motors","title":"Power Requirements for Motors","text":"

                                                                                                                                                                                                                                                                                                              Motors need about 200 milliamps to work. But a microcontroller like the Raspberry Pi Pico only can switch about 18 milliamps. So we need a way to control more power.

                                                                                                                                                                                                                                                                                                              The Pico has 26 general purpose input and output pins. However, each pin's power is designed to digitally communicate with other devices and has a limited current capacity of around 17 milliamps according to the Raspberry Pi Pico Datasheet Table 5. The solution is to either use the digital output signal to turn on and off a switch such as a transistor of to use a motor driver chip such as an L293D chip.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/02-transistor/#basic-transistor-circuit","title":"Basic Transistor Circuit","text":"
                                                                                                                                                                                                                                                                                                              1. Transistor NPN 2222A
                                                                                                                                                                                                                                                                                                              2. Diode: 1N1448
                                                                                                                                                                                                                                                                                                              3. Motor: 3-6 volt hobby motor
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/02-transistor/#pwm-control","title":"PWM Control","text":""},{"location":"motors/02-transistor/#pwm-frequency","title":"PWM Frequency","text":"

                                                                                                                                                                                                                                                                                                              Set the frequency to 50Hz (one cycle per 20ms) and the duty value to between 51 (51/1023 * 20ms = 1ms) and 102 (102/1023 * 20ms = 2ms)

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/02-transistor/#sample-coder","title":"Sample Coder","text":"
                                                                                                                                                                                                                                                                                                              import machine\n\n# set the 7th from the bottom on right as our motor pin\nmotor_pin = machine.Pin(21, machine.Pin.OUT)\n# allocate a PWM object for controlling the motor speed\nmotor_pwm = machine.PWM(motor_pin)\nmotor_pwm.freq(50) # 50 hertz\nmotor_pwm.duty(51)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/02-transistor/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Sparkfun Motor Lab from SIK Kit
                                                                                                                                                                                                                                                                                                              2. Nick Zoic MicroPython Motor Control Tutorial
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/03-h-bridge/","title":"H-Bridge Circuits","text":"

                                                                                                                                                                                                                                                                                                              H-Bridge circuits are use to drive a motor both forward and backward. The circuit is called an \"H-Bridge\" because the arrangement of the switches around a motor form the letter \"H\".

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/03-h-bridge/#h-bridge-circuit-operation","title":"H-Bridge Circuit Operation","text":"

                                                                                                                                                                                                                                                                                                              If you connect a 5 volt power supply to a motor you will turn the motor in a specific direction such as clockwise. If you reverse the connections to the motor, the motor will turn the opposite direction such as counter-clockwise.

                                                                                                                                                                                                                                                                                                              In order to turn on the motor, switches 1 and 4 must be closed to allow current to flow through the motor. Switches 2 and 3 must be turned off.

                                                                                                                                                                                                                                                                                                              To reverse the motor direction you must open switches 1 and 4 and close switches 2 and three in the upper right and lower left portion of the diagram.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/03-h-bridge/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Wikipedia Page on H-Bridge Circuits
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/04-l293d/","title":"Controlling a Motor with the L293D Motor Controller Chip","text":""},{"location":"motors/04-l293d/#what-is-an-h-bridge","title":"What is an H-Bridge?","text":""},{"location":"motors/04-l293d/#the-l293d-circuit","title":"The L293D Circuit","text":"

                                                                                                                                                                                                                                                                                                              The L293D motor driver IC has two power input pins viz. \u2018Vcc1\u2019 and \u2018Vcc2\u2019.

                                                                                                                                                                                                                                                                                                              Vcc1 is used for driving the internal logic circuitry which should be 5V.

                                                                                                                                                                                                                                                                                                              From Vcc2 pin the H-Bridge gets its power for driving the motors which can be 4.5V to 36V. And they both sink to a common ground named GND.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/04-l293d/#sample-program","title":"Sample Program","text":""},{"location":"motors/04-l293d/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Last Minute Engineer L293D DC Motor Tutorial (Arduino version)

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/06-servos/","title":"Controlling a Servo Motor with MicroPython","text":""},{"location":"motors/06-servos/#types-of-servos","title":"Types of Servos","text":"

                                                                                                                                                                                                                                                                                                              Although there are may types of servos you can purchase, in our labs there are two main types of servos that we use:

                                                                                                                                                                                                                                                                                                              1. SG90 Micro Servo, 9 grams, 180 degree, plastic gears - $4
                                                                                                                                                                                                                                                                                                              2. MG90S Micro Servo, 9 grams, 180 degree, metal gears - $5

                                                                                                                                                                                                                                                                                                              There are other variations that have 360 degree or continuous rotation servos.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/06-servos/#servo-connections","title":"Servo Connections","text":"

                                                                                                                                                                                                                                                                                                              Almost all servos have a three pin connector that are spaced 1/10th of an inch apart so they will work with our breadboards.

                                                                                                                                                                                                                                                                                                              1. Ground (black or brown wire)
                                                                                                                                                                                                                                                                                                              2. 5 volt power (always red)
                                                                                                                                                                                                                                                                                                              3. Data (orange or yellow)
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/06-servos/#references","title":"references","text":"
                                                                                                                                                                                                                                                                                                              1. SparkFun Servos Page
                                                                                                                                                                                                                                                                                                              2. SparkFun Category for Servos
                                                                                                                                                                                                                                                                                                              3. eBay Servo Plastic Servo
                                                                                                                                                                                                                                                                                                              4. eBay Servo Metal Gear Servo
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/07-stepper-motors/","title":"Controlling a Stepper Motor with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              Stepper motors are specialized motors that precisely control the angle of rotation of the shaft of a motor. They are often used to carefully position items that move along an axis. For example you can use stepper motors to control the position the printing head of a 3D printer. Stepper motors are also quite a bit more expensive than our DC hobby motors and mini servos, so we don't use them frequently in our classes.

                                                                                                                                                                                                                                                                                                              "},{"location":"motors/07-stepper-motors/#sample-code","title":"Sample Code","text":"
                                                                                                                                                                                                                                                                                                              # Code example from YoungWorks blog on how to use a stepper motor\n# https://www.youngwonks.com/blog/How-to-use-a-stepper-motor-with-the-Raspberry-Pi-Pico\nfrom machine import Pin\nimport utime\n\npins = [\n    Pin(15, Pin.Out),\n    Pin(14, Pin.Out),\n    Pin(16, Pin.Out),\n    Pin(17, Pin.Out),\n]\n\n# one hot encoding vectors\nfull_step_sequence = [\n    [1.0.0.0],\n    [0.1.0.0],\n    [0.0.1.0],\n    [0.0.0.1]\n]\n\nwhile True:\n    for step in full_step_sequence:\n        for i in rang(len(pins)):\n            pins[i].value(step[i])\n            utime.sleep(0.001)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"motors/07-stepper-motors/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Wikipedia Page on Stepper Motors
                                                                                                                                                                                                                                                                                                              2. Raspberry Pi L293D Example
                                                                                                                                                                                                                                                                                                              3. Young Wonks Stepper Motor Example with a
                                                                                                                                                                                                                                                                                                              "},{"location":"projects/01-intro/","title":"MicroPython Projects","text":""},{"location":"projects/01-intro/#rgb-box-for-kids","title":"RGB Box for Kids","text":"

                                                                                                                                                                                                                                                                                                              This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/01-intro/#alarm-clock","title":"Alarm Clock","text":"

                                                                                                                                                                                                                                                                                                              https://github.com/wahlencraft/pico-alarm-clock

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/","title":"Raspberry Pi RGB Box","text":"

                                                                                                                                                                                                                                                                                                              This is a box with three potentiometers and a NeoPixel strip. Changing the potentiometers changes the mix of Red, Green and Blue colors. We use this at many science fairs or demonstration projects that has kids as young as three years old! As the kids learn to adjust the knobs, we say \"Hey, your a programmer!\".

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#related-labs","title":"Related Labs","text":"

                                                                                                                                                                                                                                                                                                              Before you do this project, it is a good idea to get familiar with the Potentiometer lab. This lab will show you how to hook up a single potentiometer to the Raspberry Pi Pico and read it's values.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#required-tools","title":"Required Tools","text":"

                                                                                                                                                                                                                                                                                                              Although we will be using a solderless breadboard to connect the components, we use a hot-glue gun to make sure the wires don't get dislocated when the box gets bumped around.

                                                                                                                                                                                                                                                                                                              1. Soldering iron (unless you have pre-solders potentiometers)
                                                                                                                                                                                                                                                                                                              2. Hot glue gun (for securing the wires to the breadboard)
                                                                                                                                                                                                                                                                                                              3. Drill (for putting a hole in the box)
                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#parts-list","title":"Parts List","text":"
                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico with headers ($4)
                                                                                                                                                                                                                                                                                                              2. 1/2 size breadboard ($2)
                                                                                                                                                                                                                                                                                                              3. Three 10K linear potentiometers ($2)
                                                                                                                                                                                                                                                                                                              4. LED strip with 10 NeoPixels ($2)
                                                                                                                                                                                                                                                                                                              5. Battery case with 3 AA batteries (2)
                                                                                                                                                                                                                                                                                                              6. 22-gauge solid hookup wire
                                                                                                                                                                                                                                                                                                              7. Power switch (optional) (50 cents)
                                                                                                                                                                                                                                                                                                              8. Clear plastic box (4)

                                                                                                                                                                                                                                                                                                              With a bit of clever shopping, you can get the total part costs: under about $15. If you purchase the parts in Quantity 10+ you can get the costs under $10/kit.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#circuit-diagram","title":"Circuit Diagram","text":"

                                                                                                                                                                                                                                                                                                              TBD

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#assembly","title":"Assembly","text":"

                                                                                                                                                                                                                                                                                                              Solder six-inches of hookup wire to each of the three pins on the three potentiometers.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/02-rgb-box/#sample-code","title":"Sample Code","text":""},{"location":"projects/02-rgb-box/#test-the-neopixel-connection","title":"Test the NeoPixel Connection","text":"

                                                                                                                                                                                                                                                                                                              Our first step will be to verify we have the NeoPixel strip connected correctly and that we have the right configuration. There are two items you might have to change:

                                                                                                                                                                                                                                                                                                              1. The pin number connected to the data wire of the LED strip
                                                                                                                                                                                                                                                                                                              2. The number of pixels

                                                                                                                                                                                                                                                                                                              We use two Python variables to configure

                                                                                                                                                                                                                                                                                                              NEOPIXEL_PIN = 0\nNUMBER_PIXELS = 10\n

                                                                                                                                                                                                                                                                                                              import machine, neopixel\nfrom utime import sleep\nfrom neopixel import Neopixel\n\nNEOPIXEL_PIN = 0\nNUMBER_PIXELS = 10\nstrip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, \"GRB\")\n\nprint('flashing pixel 0 red')\ndelay=.3\nwhile True:\n    strip.set_pixel(0, (255,0,0)) // turn pixel 0 red\n    strip.show()\n    sleep(delay)\n    strip.set_pixel(0, (0,0,0)) // turn pixel 0 off\n    strip.show()\n    sleep(delay)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-neopixel-strip-two-buttons/","title":"NeoPixel Two Button Kit","text":"

                                                                                                                                                                                                                                                                                                              This is a low-cost (around $10) kit that is used for hackathons and activities such as a Halloween costume contest.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-neopixel-strip-two-buttons/#contents","title":"Contents","text":"
                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico with Headers
                                                                                                                                                                                                                                                                                                              2. Breadboard
                                                                                                                                                                                                                                                                                                              3. NeoPixel Strip (ideally a 1 meter strip with 60 pixels)
                                                                                                                                                                                                                                                                                                              4. Two momentary push buttons
                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-neopixel-strip-two-buttons/#background","title":"Background","text":"

                                                                                                                                                                                                                                                                                                              See the Basic Example for the NeoPixel Strip lab.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-neopixel-strip-two-buttons/#labs","title":"Labs","text":"

                                                                                                                                                                                                                                                                                                              We supply a small set of \"getting started\" labs to demonstrate how to program colors on the LED strip and give the perception of motion up and down the strip.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-neopixel-strip-two-buttons/#blink","title":"Blink","text":""},{"location":"projects/03-neopixel-strip-two-buttons/#move","title":"Move","text":""},{"location":"projects/03-neopixel-strip-two-buttons/#fade-in-and-out","title":"Fade In and Out","text":"
                                                                                                                                                                                                                                                                                                              from neopixel import NeoPixel\nfrom time import sleep\n\nNUMBER_PIXELS = 60\nLED_PIN = 0\n\nstrip = NeoPixel(machine.Pin(LED_PIN), NUMBER_PIXELS)\n\ndelay = .005\n\nwhile True:\n    for i in range(0, 255):\n        strip[0] = (i,0,0) # red=255, green and blue are 0\n        strip.write() # send the data from RAM down the wire\n        sleep(delay) # keep on 1/10 of a second\n    for i in range(255, 0, -1):\n        strip[0] = (i,0,0) # red=255, green and blue are 0\n        strip.write() # send the data from RAM down the wire\n        sleep(delay) # keep on 1/10 of a second\n
                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-rotary-neopixel/","title":"Rotary NeoPixel","text":"

                                                                                                                                                                                                                                                                                                              This project has a rotary encoder and a button. Spinning the rotary encoder changes the pixel index. Pressing the knob of the encoder changes the color. Pressing the button changes the pattern.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-rotary-neopixel/#circuit","title":"Circuit","text":"

                                                                                                                                                                                                                                                                                                              We connect the two ends of the rotary (A and B) to pins 14 and 15. We connect the center pin to the 3.3v rail of the breadboard.

                                                                                                                                                                                                                                                                                                              Next, we connect the rotary button and the other button to pins 16 and 17 and to the 3.3v rail.

                                                                                                                                                                                                                                                                                                              All the buttons use PULL.DOWN option when they are configured.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-rotary-neopixel/#sample-code","title":"Sample Code","text":"

                                                                                                                                                                                                                                                                                                              We use the rotary.py library

                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom rotary import Rotary\n\nENCODER_A = 15\nENCODER_B = 14\nSWITCH = 17\nrotary = Rotary(ENCODER_A, ENCODER_B, SWITCH)\n

                                                                                                                                                                                                                                                                                                              You can change the order of A and B to match the turn direction.

                                                                                                                                                                                                                                                                                                              "},{"location":"projects/03-rotary-neopixel/#full-source-code","title":"Full Source Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nfrom rotary import Rotary\nfrom utime import sleep, ticks_ms\nfrom neopixel import NeoPixel\n\nNEOPIXEL_PIN = 0\nNUMBER_PIXELS = 12\n\nstrip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\n# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch.\nENCODER_A = 15\nENCODER_B = 14\nSWITCH = 17\nrotary = Rotary(ENCODER_A, ENCODER_B, SWITCH)\n\nbutton_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)\nmode = 0 # mode to display\nmode_names = ['dot', 'hole', 'compare', 'chase', 'rainbow']\n\nbutton_presses = 0 # the count of times the button has been pressed\nlast_time = 0 # the last time we pressed the button\ndef button_pressed_handler(pin):\n    global button_presses, last_time, mode\n    new_time = ticks_ms()\n    # if it has been more that 1/5 of a second since the last event, we have a new event\n    if (new_time - last_time) > 200: \n        mode +=1\n        last_time = new_time\n    # make mode 0 or 1\n    mode = mode % 5\n    print('mode=', mode, mode_names[mode])\n# now we register the handler function when the button is pressed\nbutton_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler)\n\nval = 0 # value of the LED strip index set by the rotary know\n\nred = (255, 0, 0)\norange = (140, 60, 0)\nyellow = (255, 255, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\ncyan = (0, 255, 255)\nindigo = (75, 0, 130)\nviolet = (138, 43, 226)\nwhite = (128, 128, 128)\ncolors = (red, orange, yellow, green, blue, cyan, indigo, violet)\ncolor_count = len(colors)\n\n\n# this function is called whenever the rotory is changed\ndef rotary_changed(change):\n    global val, button_press, color_index\n    if change == Rotary.ROT_CW:\n        val = val + 1\n    elif change == Rotary.ROT_CCW:\n        val = val - 1      \n    elif change == Rotary.SW_PRESS:\n        print('PRESS')\n        # button_press = 1\n    elif change == Rotary.SW_RELEASE:\n        print('RELEASE')\n        color_index += 1\n        color_index = color_index % (color_count - 1)\n    val = val % NUMBER_PIXELS\n    print(val) \n\nrotary.add_handler(rotary_changed)\n\ncolor_index = 0\ncolor = red\nwhile True:\n    if mode == 0:\n        for i in range(0, NUMBER_PIXELS):\n            if i == val:\n                strip[i] = color\n            else:\n                strip[i] = (0,0,0)\n    elif mode == 1:\n        for i in range(0, NUMBER_PIXELS):\n            if i == val:\n                strip[i] = (0,0,0)\n            else:\n                strip[i] = color\n    elif mode == 2:\n        for i in range(0, NUMBER_PIXELS):\n            if i > val:\n                strip[i] = (0,0,0)\n            else:\n                strip[i] = color\n    elif mode == 3:\n        for i in range(0, NUMBER_PIXELS):\n            if (i-val) % 3:\n                strip[i] = (0,0,0)\n            else:\n                strip[i] = color    \n    elif mode == 4:\n        # if the val + offset is larger than the number of pixels we need to do a modulo\n        strip[val     % (NUMBER_PIXELS)] = violet\n        strip[(val+1) % (NUMBER_PIXELS)] = indigo\n        strip[(val+2) % (NUMBER_PIXELS)] = blue\n        strip[(val+3) % (NUMBER_PIXELS)] = green\n        strip[(val+4) % (NUMBER_PIXELS)] = yellow\n        strip[(val+5) % (NUMBER_PIXELS)] = orange\n        strip[(val+6) % (NUMBER_PIXELS)] = red\n        # turn off the rest\n        strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0)\n        strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0)\n        strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0)\n        strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0)\n        strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0)\n    strip.write()\n    # print('color index', color_index)\n    color = colors[color_index]\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/","title":"Introduction to MicroPython Robots","text":"

                                                                                                                                                                                                                                                                                                              Robots are the most powerful learning machines in our curriculum. They allow our students to control motion with their own programs. Not only are they incredibly fun for our students, our students learn computational thinking and enable them to quickly proceed to our advanced AI Racing League projects.

                                                                                                                                                                                                                                                                                                              The Raspberry Pi Pico and the Maker Pi RP2040 components have truly been transformative for our clubs. Instead of being trapped in the 2K RAM on our Arduino systems and being forced to learn \"C\", our students are programming in their favorite Python language!

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/#robot-journey-map","title":"Robot Journey Map","text":"

                                                                                                                                                                                                                                                                                                              This section of the course takes you on a tour of our base $25 collision avoidance robots. It then builds on this robot by adding an OLED display, programming controls and servos. Here is a Journey Map of these lessons:

                                                                                                                                                                                                                                                                                                              Note that the $25 price assumes you purchase low-cost parts from suppliers like eBay. You can lower the cost per robot by purchasing the parts in higher quantities for classroom use. You can also purchase older Arduino robot kits and upgrade the processors to use the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              This section only covers using the Raspberry Pi Pico robots with external motor drivers. We now have many additional robot lessons that use the Cytron Maker Pi RP2040 robotics board. These robots are still low-cost ($20) but have much more integrated power and are easier for younger students to use since they don't require any breadboards or soldering.

                                                                                                                                                                                                                                                                                                              Our base robot is a collision avoidance robot that is ideal for teaching beginning robotics principles. The robots have one or more distance sensors on the front and will continue to move forward until they get near an object in front of them. They then will reverse and turn in another direction. We test our robots on the floor in a \"Robot Corral\" that has six-inch high walls. Students can adjust various parameters to allow the robot to navigate around the corral without colliding with the walls.

                                                                                                                                                                                                                                                                                                              1. Base Bot - This is the foundational robot that the other projects are built on. The base includes a standard Smart Car chassis, two DC hobby motors, a battery pack and wheels. On top of the chassis we add a breadboard, jumpers, a motor controller, a distance sensor, and our $4 Raspberry Pi microcontroller.

                                                                                                                                                                                                                                                                                                              2. Rainbow Bot This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red.

                                                                                                                                                                                                                                                                                                              3. IR Sensor Bot This takes our base robot and adds a low-cost LED strip so that students can change the color of the LED based on what the robot is sensing and doing. For example when the robot is turning right the LEDs can turn red.

                                                                                                                                                                                                                                                                                                              4. Face Bot - We extend the Base Bot by adding a $4 128x64 OLED display. This allows students to see the values of the distance sensor and to hear a sound when a key event occurs.

                                                                                                                                                                                                                                                                                                              5. Adjustable Parameter Bot - We extend the face-bot to add some buttons and knobs to allow our users to change the collision avoidance parameters such as forward speed and turning threshold distance.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/#parts","title":"Parts","text":"

                                                                                                                                                                                                                                                                                                              Our beginning Base Bot

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/#chassis","title":"Chassis","text":"

                                                                                                                                                                                                                                                                                                              SmartCar Chassis

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/#sensors","title":"Sensors","text":"
                                                                                                                                                                                                                                                                                                              • Ping Ultrasonic Distance Sensor
                                                                                                                                                                                                                                                                                                              • IR sensors
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/#motor-controllers","title":"Motor Controllers","text":""},{"location":"robots/02-base-bot/","title":"Raspberry Pi Pico Micropython Base Robot","text":"

                                                                                                                                                                                                                                                                                                              This lesson describes our base robot kit in the CoderDojo Twin Cities coding club. This robot is programmed entirely in Python to be consistent with our Python Courses.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#base-robot-design","title":"Base Robot Design","text":"

                                                                                                                                                                                                                                                                                                              Our goal is to build a robotics platform for teaching computational thinking. Here are our main design goals:

                                                                                                                                                                                                                                                                                                              1. Low cost (under $25) so that most students can afford their own robot
                                                                                                                                                                                                                                                                                                              2. Open platform to make it easy to upgrade (sustainably)
                                                                                                                                                                                                                                                                                                              3. Interchangeable parts
                                                                                                                                                                                                                                                                                                              4. Minimal amount of soldering
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#video","title":"Video","text":"

                                                                                                                                                                                                                                                                                                              Here is a video of the collision avoidance robot in action:

                                                                                                                                                                                                                                                                                                              YouTube Video

                                                                                                                                                                                                                                                                                                              Note that the forward-speed and distance-before-you-turn can be adjusted. You can see I didn't quite get the distance right and the robot bumps into some of the barriers.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#connection-diagram","title":"Connection Diagram","text":"

                                                                                                                                                                                                                                                                                                              Here is a connection diagram of the base robot.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#power-regulation","title":"Power Regulation","text":"

                                                                                                                                                                                                                                                                                                              Note that the power comes from the battery at 6 volts and is connected to the input voltage of the motor controller board. The motor controller has a voltage regulator that converts any input voltage from 6 to 12 volts down to 5 volts. The output voltage of the motor controller is then connected to the power rail on the left, which is in turn connected to the VSYS input to the Pico. The Pico, in turn, has another voltage regulator that drop the input from VSYS down to 3.3 volts on the 3.3V OUT pin. This voltage is then used to power the distance sensor.

                                                                                                                                                                                                                                                                                                              One of the downsides to this design is that as the batteries get low, once they drop below around 5 volts the double voltage drops cause the 3.3 OUT to become too low and the sensor becomes unreliable. A better design would be to find a motor controller that produces a stable 3.3 volts as the batteries slowly run down. Let us know if you can find one of these designs that cost under $2.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#hardware-description","title":"Hardware Description","text":"

                                                                                                                                                                                                                                                                                                              Here is a summary of some of the parts we use in this robot and their approximate prices as of June 2021. Some parts come from China so you might need to wait 2-3 weeks for them to arrive.

                                                                                                                                                                                                                                                                                                              Here is a Google sheet with these parts:

                                                                                                                                                                                                                                                                                                              Detailed Parts List Google Sheet

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#two-wheel-drive-smart-car-chassis","title":"Two Wheel Drive Smart Car Chassis","text":"

                                                                                                                                                                                                                                                                                                              Our cars all use a standard Two Wheel Drive (2WD) SmartCar Chassis that is available in many retail outlets online.

                                                                                                                                                                                                                                                                                                              • $5 Cytron 2WD Smart Car Chassis
                                                                                                                                                                                                                                                                                                              • YouTube Video of Assembly - note that he does not remove the backing paper on the Plexiglass and he mounts the battery on the top. We like ours on the bottom.
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#motor-driver","title":"Motor Driver","text":""},{"location":"robots/02-base-bot/#software","title":"Software","text":"

                                                                                                                                                                                                                                                                                                              All software is written in MicroPython.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#time-of-flight-distance-sensor","title":"Time-of-Flight Distance Sensor","text":"

                                                                                                                                                                                                                                                                                                              We are using the VL53L0X time-of-flight distance sensor. This works on an I2C bus. After you have hooked up the Power (VCC to the 3.3 rail and GND) you must hook up the I2C data and clock.

                                                                                                                                                                                                                                                                                                              sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top\nscl=machine.Pin(17) # One up from the lower right corner of the Pico\ni2c=machine.I2C(0, sda=sda, scl=scl)\n

                                                                                                                                                                                                                                                                                                              Many of our older robots used the ultrasonic ping sensors. The are unreliable with voltage drops as our batteries wear down.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#testing-the-sensor-connections-with-the-i2c-scanner","title":"Testing the Sensor Connections with the I2C Scanner","text":"
                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(16) # Lower right corner of the Pico with the USB on top\nscl=machine.Pin(17) # One up from the lower right corner of the Pico\ni2c=machine.I2C(0, sda=sda, scl=scl)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              You should see a decimal number returned. By default the I2C address is 41 (decimal) or x29 (hexadecimal).

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#download-the-vl53l0x-driver","title":"Download the VL53L0X Driver","text":"

                                                                                                                                                                                                                                                                                                              You will need to add a VL53L0X driver file to the file system on the pico.

                                                                                                                                                                                                                                                                                                              We have a copy here: https://raw.githubusercontent.com/CoderDojoTC/micropython/main/src/drivers/VL53L0X.py

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#time-of-flight-sensor-test","title":"Time-of-Flight Sensor Test","text":"

                                                                                                                                                                                                                                                                                                              Once the driver file is loaded we are ready to test the time-of-flight distance sensor.

                                                                                                                                                                                                                                                                                                              import time\nfrom machine import Pin\nfrom machine import I2C\nimport VL53L0X\n\nsda=machine.Pin(16) # row one on our standard Pico breadboard\nscl=machine.Pin(17) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl)\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\ntof.start() # startup the sensor\nwhile True:\n# Start ranging\n    dist = tof.read()\n    print(dist)\n    time.sleep(.1)\n

                                                                                                                                                                                                                                                                                                              When you run this program a sequence of integers will appear in the console. The numbers usually will range from around 30 if there is an object directly in front of the sensor to a number around 1,300 for a object that is about 1.3 meters away from the sensor. There is a 1/10th of a second pause between each measurement. This can be changed in the last line of the program.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#motor-drive-test","title":"Motor Drive Test","text":"

                                                                                                                                                                                                                                                                                                              After we have the four wires connected to the motor driver, we need to make sure we get the right wires to the right motors and motor directions. This program will help you debug this.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nimport time # sleep\n\nPOWER_LEVEL = 65025\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 21\nRIGHT_REVERSE_PIN = 20\nLEFT_FORWARD_PIN = 18\nLEFT_REVERSE_PIN = 19\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n\ndef spin_wheel(pwm):\n        pwm.duty_u16(POWER_LEVEL)\n        time.sleep(3)\n        pwm.duty_u16(0)\n        time.sleep(2)\n\nwhile True:\n    print('right forward')\n    spin_wheel(right_forward)\n\n    print('right reverse')\n    spin_wheel(right_reverse)\n\n    print('left foward')\n    spin_wheel(left_forward)\n\n    print('left_reverse')\n    spin_wheel(left_reverse)\n

                                                                                                                                                                                                                                                                                                              One thing to remember is that the \"Right\" refers to our orientation from the rear of the car or if we were sitting inside the car. If the robot is facing you with the sensor in the front, it is the wheel on the left that we call the \"RIGHT\" wheel. Very confusing! Using this naming convention will pay of as we are walking behind larger robots.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#sample-drive-and-turn-functions","title":"Sample Drive and Turn Functions","text":"

                                                                                                                                                                                                                                                                                                              We will need a set of function to drive our robot:

                                                                                                                                                                                                                                                                                                              1. Forward: both wheels going forward
                                                                                                                                                                                                                                                                                                              2. Reverse: both wheels going in reverse
                                                                                                                                                                                                                                                                                                              3. Turn Right: The right wheel turning backward and the left going forward
                                                                                                                                                                                                                                                                                                              4. Turn Left: The left wheel turning backward and the right wheel going forward
                                                                                                                                                                                                                                                                                                              5. Stop: all motors off

                                                                                                                                                                                                                                                                                                              Our challenge is for each of these operations we must change the value of all four PWM signals. We can never have a motor be going both forward and reverse. Here are some sample drive functions:

                                                                                                                                                                                                                                                                                                              def turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#turning-logic","title":"Turning Logic","text":"
                                                                                                                                                                                                                                                                                                              while True:\n    dist = read_sensor() \n    if dist < TURN_THRESHOLD:\n        print('object detected')\n        reverse()\n        sleep(BACKUP_TIME)\n        turn_right()\n        sleep(TURN_TIME)\n    else:\n        forward()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#test-motor-connections","title":"Test Motor Connections","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nimport time # sleep\n\nPOWER_LEVEL = 65025 # usually a number from 30,000 to max of 65,025\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 21\nRIGHT_REVERSE_PIN = 20\nLEFT_FORWARD_PIN = 18\nLEFT_REVERSE_PIN = 19\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n\ndef spin_wheel(pwm):\n        pwm.duty_u16(POWER_LEVEL)\n        time.sleep(3)\n        pwm.duty_u16(0)\n        time.sleep(2)\n\nwhile True:\n    print('right forward')\n    spin_wheel(right_forward)\n\n    print('right reverse')\n    spin_wheel(right_reverse)\n\n    print('left foward')\n    spin_wheel(left_forward)\n\n    print('left_reverse')\n    spin_wheel(left_reverse)\n

                                                                                                                                                                                                                                                                                                              After you load this program, watch which wheels turn and in what direction.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#drive-functions","title":"Drive Functions","text":"

                                                                                                                                                                                                                                                                                                              We will define Python functions for forward, reverse, turn right and turn left.

                                                                                                                                                                                                                                                                                                              POWER_LEVEL = 65025\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#stop-all-motors-program","title":"Stop All Motors Program","text":"

                                                                                                                                                                                                                                                                                                              One other thing to remember is that the PWM signals continue to be generated even after the main loop has stopped. This is because on the Pico, the four PWM signals are being continuously generated by an independent processors. To stop the motors you must run a separate stop program like this:

                                                                                                                                                                                                                                                                                                              stop-all-motors.py:

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom time import sleep\n\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 19\nRIGHT_REVERSE_PIN = 21\nLEFT_FORWARD_PIN = 18\nLEFT_REVERSE_PIN = 20\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\nright_forward.duty_u16(0)\nright_reverse.duty_u16(0)\nleft_forward.duty_u16(0)\nleft_reverse.duty_u16(0)\n

                                                                                                                                                                                                                                                                                                              This can be frustrating at times when you can't find the stop program. I like to bring the stop program up in a separate tab when I am writing robot motor code.

                                                                                                                                                                                                                                                                                                              To

                                                                                                                                                                                                                                                                                                              figure out how to write an interrup handler so that when the IDE STOP function is pressed the stop motors (and speaker) are stopped.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#collision-avoidance-logic","title":"Collision Avoidance Logic","text":""},{"location":"robots/02-base-bot/#final-program","title":"Final Program","text":"

                                                                                                                                                                                                                                                                                                              To get this to work on battery power up you must name the program main.py and save it on the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              Make sure you have the VL53L0X distance sensor driver installed.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\nimport VL53L0X\n\n# used to blink the onboard LED\nled_onboard = machine.Pin(25, machine.Pin.OUT)\n\n# driving parameters\nPOWER_LEVEL = 65025 # use a value from 20000 to 65025\nTURN_THRESHOLD = 400 # 25 cm\nTURN_TIME = .25 # seconds of turning\nBACKUP_TIME = .75 # seconds of backing up if obstacle detected\n\n# Motor pins to the L293 H-Bridge\nRIGHT_FORWARD_PIN = 21\nRIGHT_REVERSE_PIN = 20\nLEFT_FORWARD_PIN = 18\nLEFT_REVERSE_PIN = 19\n\n# setup the PWM objects\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\nsda=machine.Pin(16) # row one on our standard Pico breadboard\nscl=machine.Pin(17) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl)\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n\ndef read_sensor_avg():\n    total = 0\n    for i in range(10):\n        total = total + tof.read()\n        sleep(.01)\n    return int(total/10)\n\ntof.start() # startup the sensor\n\nwhile True:\n    dist = read_sensor_avg();\n    print(dist)\n\n    if dist < TURN_THRESHOLD:\n        print('object detected')\n        reverse()\n        sleep(BACKUP_TIME)\n        led_onboard.high()\n        turn_right()\n        sleep(TURN_TIME)\n    else:\n        if dist > 1300:\n            print('no signal')\n            led_onboard.low()\n        else:\n            print('Go forward')\n            led_onboard.high()\n        forward()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/02-base-bot/#more-to-explore-labs","title":"More To Explore Labs","text":"
                                                                                                                                                                                                                                                                                                              1. Can you change the hard-coded parameters at the begging of the program? What happens when you make the POWER_LEVEL go too high and the TURN_THRESHOLD too low?
                                                                                                                                                                                                                                                                                                              2. What is the lowest POWER_LEVEL that will allow the robot to move? What if you changed the power from 6 volts to be 9 volts by adding two more AA batteries?
                                                                                                                                                                                                                                                                                                              3. Can you randomly turn right or left if you encounter and object? Note you will need to import the random library and generate a random number between 0 and 2 with the random.randint(0,2) function.
                                                                                                                                                                                                                                                                                                              4. How would you design a robot that you could adjust the parameters? What parameters would you change? What would their valid ranges be?
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-ir-sensor-bot/","title":"IR Collision Avoidance Bot","text":"

                                                                                                                                                                                                                                                                                                              Instead of our time-of-flight sensor used in our base robot, this robot uses three low-cost IR distance sensors.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-ir-sensor-bot/#purchasing-ir-distance-sensors","title":"Purchasing IR Distance Sensors","text":""},{"location":"robots/03-ir-sensor-bot/#connecting-the-ir-sensors","title":"Connecting the IR Sensors","text":"
                                                                                                                                                                                                                                                                                                              # connections to the three IR distance sensors\nleft = Pin(8, Pin.IN, Pin.PULL_DOWN)\ncenter = Pin(7, Pin.IN, Pin.PULL_DOWN)\nright = Pin(6, Pin.IN, Pin.PULL_DOWN)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-ir-sensor-bot/#connecting-the-speaker","title":"Connecting the Speaker","text":"

                                                                                                                                                                                                                                                                                                              This robot has an optional speaker connected to GPIO Pin 21. This allows us to \"hear\" what signals are coming into the robot It will generate a different tone if the left, center or right sensor is detecting an object and an different tone for going straight, reversing and turning.

                                                                                                                                                                                                                                                                                                              The speaker is a small buzzer or a Piezoelectric speaker that can be purchased for around $1. It has one wire connected to the GPIO pin and the other connected to any GND pin or GND rail on the breadboard.

                                                                                                                                                                                                                                                                                                              Here are the lines related to setting up the speaker code.

                                                                                                                                                                                                                                                                                                              SPEAKER_PIN = 21\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-ir-sensor-bot/#drive-logic","title":"Drive Logic","text":"

                                                                                                                                                                                                                                                                                                              The three IR sensors go LOW if there is an item in front of them. So the statement:

                                                                                                                                                                                                                                                                                                              center.value()\n

                                                                                                                                                                                                                                                                                                              will normally be HIGH if there is nothing in front of the robot.

                                                                                                                                                                                                                                                                                                              Our main logic look will look like the following:

                                                                                                                                                                                                                                                                                                              while True:\n    if left.value()==0:\n        turn_right()\n    if center.value()==0:\n        reverse()\n    if right.value()==0:\n        turn_left()\n    if left.value() and center.value() and right.value():\n        forward()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-ir-sensor-bot/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\nimport ssd1306\n\n# Motor pins to the L293 H-Bridge\nRIGHT_FORWARD_PIN = 17\nRIGHT_REVERSE_PIN = 16\nLEFT_FORWARD_PIN = 18\nLEFT_REVERSE_PIN = 19\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n# connections to the three IR distance sensors\nleft = Pin(8, Pin.IN, Pin.PULL_DOWN)\ncenter = Pin(7, Pin.IN, Pin.PULL_DOWN)\nright = Pin(6, Pin.IN, Pin.PULL_DOWN)\n\nSPEAKER_PIN = 21\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\nWIDTH  = 128\nHEIGHT = 64\nCS = machine.Pin(1)\nSCL = machine.Pin(2)\nSDA = machine.Pin(3)\nDC = machine.Pin(4)\nRES = machine.Pin(5)\nspi=machine.SPI(0, sck=SCL, mosi=SDA)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(65025)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n\ndef sound_off():\n    speaker.duty_u16(0)\n\ndef left_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(700) # 1 Kilohertz\n    sleep(.5) # wait a 1/4 second\n    sound_off()\n\ndef center_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(900)\n    sleep(.5)\n    sound_off()\n\ndef right_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(600)\n    sleep(.5)\n    sound_off()\n\ndef forward_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(400)\n    sleep(.1)\n    speaker.freq(900)\n    sleep(.1)\n    speaker.freq(1200)\n    sleep(.1)\n    sound_off()\n\ndef update_oled():\n    oled.fill(0)\n    oled.text(\"CoderDojo Rocks!\", 0, 0, 1)\n\n    oled.text(\"Left:\", 0, 10, 1)\n    oled.text(str(left.value()), 50, 10, 1)\n\n\n    oled.text(\"Center:\", 0, 20, 1)\n    oled.text(str(center.value()), 60, 20, 1)\n\n    oled.text(\"Right:\", 0, 30, 1)\n    oled.text(str(right.value()), 55, 30, 1)\n\n    BAR_WIDTH = 40\n    BAR_HEIGHT = 20\n    if left.value():\n        oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0)\n    else:\n        oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\n    if center.value():\n        oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0)\n    else:\n        oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\n    if right.value():\n        oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0)\n    else:\n        oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\n    oled.show()\n\n\n\n# 0=stopped, 1=forward, 2=turing right, 3=turning left\ndrive_state = 0\ncounter = 0\nwhile True:\n    if left.value()==0:\n        print('Left')\n        #left_tone()\n        turn_right()\n        update_oled()\n        drive_state = 2\n    if center.value()==0:\n        print('Center')\n        center_tone()\n        reverse()\n        update_oled()\n        drive_state = 0\n    if right.value()==0:\n        print('Right')\n        #right_tone()\n        turn_left()\n        update_oled()\n        drive_state = 3\n\n    # if (left.value()==1) and (center.value()==1) and (right.value()==1):\n    if left.value() and center.value() and right.value():\n        print('Go forward!')    \n        drive_state = 1\n        # forward_tone()\n        forward()\n        update_oled()\n    print(\"counter: \", counter)\n    counter += 1\n    sleep(.25)\n

                                                                                                                                                                                                                                                                                                              Pins GP6, 7, 8 and 9

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/","title":"Rainbow Bot","text":"

                                                                                                                                                                                                                                                                                                              This robot takes our base robot and adds an LED strip arranged in a 12X6 pixel grid to display colors and patterns based on what the robot is doing or thinking about.

                                                                                                                                                                                                                                                                                                              We use the same materials as our Base Robot but we add a low-cost addressable LED strips that are easy to hook up with just power, ground and data wires added to our breadboard. The LED is known as an addressable LED strip since you can individually program each LED. The standard is called the WS-2812B LED strip and is often called a NeoPixel LED strip (The Adafruit Term). We also used a Python library called a Neopixel micropython library, although the library is not created or maintained by Adafruit.

                                                                                                                                                                                                                                                                                                              Of course, you can also add longer LED strips and program the patterns in interesting ways.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#part-1-ordering-the-led-strip","title":"Part 1: Ordering The LED Strip","text":"

                                                                                                                                                                                                                                                                                                              The LED strips come in a variety of lengths, density and packing. We use the 1 meter long strips that have 60 pixels/meter. These strips are easy to cut apart and solder. We like the black backgrounds but they also come with white. The LED strips come with three packaging options:

                                                                                                                                                                                                                                                                                                              1. No waterproofing - these are fine for our indoor robots
                                                                                                                                                                                                                                                                                                              2. Waterproofing with the strips coated in silicon rubber called IP65 waterproofing
                                                                                                                                                                                                                                                                                                              3. Waterproofing with the strips encased in a flexible rubber sleeve

                                                                                                                                                                                                                                                                                                              The waterproofing options tend to be a little more expensive but can also provide a bit more protection for the components on the strips. Waterproofing keeps moisture and dust out of the circuits, but does not mean that they can be submerged under water.

                                                                                                                                                                                                                                                                                                              A sample place to purchase them is here

                                                                                                                                                                                                                                                                                                              We can take a $3 strip of 60 LEDs and cut them up into six segments of 10 LEDs each for a cost of around 50 cents per strip. We solder stranded wire to the segments and then put 22 gauge solid wire to make them easy to put in the breadboards.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#connecting-the-led-strips","title":"Connecting the LED Strips","text":""},{"location":"robots/03-rainbow-bot/#adding-a-standoff","title":"Adding a Standoff","text":""},{"location":"robots/03-rainbow-bot/#upgrading-to-9-volt-power","title":"Upgrading to 9 Volt Power","text":"

                                                                                                                                                                                                                                                                                                              Our base robot only needed power for the motors. This robot has 72 RGB LEDs so it might draw more power. So we upgraded the 6 volt battery pack with 4 AA batteries to two packs of 3 batteries for a total of 9 volts. This allows the robot to continue to run even when the batteries are partially drained. The battery packs must be wired in series to deliver the full 9 volts to the input of the motor controller where it powers the motors and also runs though a voltage regulator to power the reset of the robot.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#72-pixel-configuration","title":"72 Pixel Configuration","text":"

                                                                                                                                                                                                                                                                                                              Here is the top view of the LEDs shining through the clear plexiglass.

                                                                                                                                                                                                                                                                                                              You can see the individual LEDs in this configuration. By adding a small space between the plexiglass and a diffusion layer you can get a much more uniform color distribution over the top surface of the robot.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#part-2-making-the-connections","title":"Part 2: Making The Connections","text":"

                                                                                                                                                                                                                                                                                                              The LED strips use 5 volts of power and have a GND and a data connector. To make the connections we connect the center pin to Pin 0 (upper left corner of the Pico), the GND to the ground rail and the 5 volt to the 5 volt power rail.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#part-3-adding-the-neopixel-library","title":"Part 3: Adding the Neopixel Library","text":""},{"location":"robots/03-rainbow-bot/#part-4-testing-your-code","title":"Part 4: Testing Your Code","text":"

                                                                                                                                                                                                                                                                                                              In our first test, we will just make the first pixel on the LED strip blink bright red.

                                                                                                                                                                                                                                                                                                              import machine, neopixel, time\n# Set the pin number and number of pixels\nLED_PIN = machine.Pin(4)\nNUMBER_PIXELS = 12\nnp = neopixel.NeoPixel(LED_PIN, NUMBER_PIXELS)\n\n# blink the first pixel red\n\nwhile True:\n    np[0] = (255, 0, 0)\n    np.write()\n    time.sleep(1)\n    np[0] = (0, 0, 0)\n    np.write()\n    time.sleep(1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#functions-for-drawing-on-matrix","title":"Functions For Drawing on Matrix","text":"

                                                                                                                                                                                                                                                                                                              The numbering of the pixels is a bit odd. The first 12 are 0 to 11, but the second 12 pixels are in reverse order, so the second row counts from 23 down to 13. Here are some functions that demonstrate this:

                                                                                                                                                                                                                                                                                                              import time\nfrom neopixel import Neopixel\n\nnumpix = 72\nstrip = Neopixel(numpix, 0, 0, \"GRB\")\n\nred = (255, 0, 0)\norange = (255, 150, 0)\nyellow = (255, 255, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130)\nviolet = (138, 43, 226)\ncolors = (red, orange, yellow, green, blue, indigo, violet)\n\nstrip.brightness(255)\n\ndef color_wipe():\n    for color in colors:\n        for i in range(numpix):\n            strip.set_pixel(i, color)\n            strip.show()\n            time.sleep(0.01)\n\ndef color_wipe_2():\n    for color in colors:\n        for i in range(12):\n            strip.set_pixel(i, color)\n            strip.set_pixel(i+12, color)\n            strip.set_pixel(i+24, color)\n            strip.set_pixel(i+36, color)\n            strip.set_pixel(i+48, color)\n            strip.set_pixel(i+60, color)\n            strip.show()\n            time.sleep(0.01)\n\ndef color_wipe_3():\n    for color in colors:\n        for i in range(12):\n            strip.set_pixel(i, color)\n            strip.set_pixel(23-i, color)\n            strip.set_pixel(i+24, color)\n            strip.set_pixel(47-i, color)\n            strip.set_pixel(48+i, color)\n            strip.set_pixel(71-i, color)\n            strip.show()\n            time.sleep(0.3)\n\n# offset is the color to start (0 to 6)\n# dir is 1 for forward and -1 for reverse\ndef color_wipe_4(offset, dir):\n    for i in range(12):\n        if dir == 1:\n            this_color = colors[ ((i-offset) %7 )]\n        else:\n            this_color = colors[ ((i+offset) %7 )]\n        strip.set_pixel(i, this_color)\n        strip.set_pixel(23-i, this_color)\n        strip.set_pixel(i+24, this_color)\n        strip.set_pixel(47-i, this_color)\n        strip.set_pixel(48+i, this_color)\n        strip.set_pixel(71-i, this_color)\n        strip.show()\n        # time.sleep(0.01)\n\nwhile True:\n    for counter in range(100):\n        color_wipe_4(counter %7, 1)\n    for counter in range(100):\n        color_wipe_4(counter%7, -1)  \n
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#full-source-code","title":"Full Source Code","text":"

                                                                                                                                                                                                                                                                                                              We now combine the motor controls, the distance sensor and the LED functions so that a moving rainbow pattern moves from to back as the robot moves forward. If the robot encounters an obstacle, the robot will backup and change the direction of the rainbow. After it backs up a bit it will turn and move forward again.

                                                                                                                                                                                                                                                                                                              main.py

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom time import sleep\nfrom machine import Pin\nfrom machine import I2C\nimport VL53L0X\nfrom neopixel import Neopixel\n\n# Motor Code\n# lower right pins with USB on top\nRIGHT_FORWARD_PIN = 19\nRIGHT_REVERSE_PIN = 18\nLEFT_FORWARD_PIN = 20\nLEFT_REVERSE_PIN = 21\n\nright_forward = PWM(Pin(RIGHT_FORWARD_PIN))\nright_reverse = PWM(Pin(RIGHT_REVERSE_PIN))\nleft_forward = PWM(Pin(LEFT_FORWARD_PIN))\nleft_reverse = PWM(Pin(LEFT_REVERSE_PIN))\n\n# Sensor Code\nsda=machine.Pin(16)\nscl=machine.Pin(17)\ni2c=machine.I2C(0, sda=sda, scl=scl)\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\ntof.start() # startup the sensor\n\n# used to blink the onboard LED\nled_onboard = machine.Pin(25, machine.Pin.OUT)\n\n# LED Code\nnumpix = 72\nstrip = Neopixel(numpix, 0, 0, \"GRB\")\n# we turn the brightness way down to not oversaturate the brightness in the video\nstrip.brightness(20)\n\n# driving parameters\nPOWER_LEVEL = 30000 # use a value from 20000 to 65025\nTURN_THRESHOLD = 400 # 25 cm\nTURN_TIME = .25 # seconds of turning\nBACKUP_TIME = .75 # seconds of backing up if obstacle detected\n\nred = (255, 0, 0)\norange = (255, 165, 0)\nyellow = (255, 255, 0)\ngreen = (0, 255, 0)\nblue = (0, 0, 255)\nindigo = (75, 0, 130)\nviolet = (138, 43, 226)\ncolors = (red, orange, yellow, green, blue, indigo, violet)\n\ndef turn_motor_on(pwm):\n   pwm.duty_u16(POWER_LEVEL)\n\ndef turn_motor_off(pwm):\n   pwm.duty_u16(0)\n\ndef forward():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_reverse)\n    #for i in range(numpix):\n    #    strip.set_pixel(i, green)\n    #strip.show()\n\ndef reverse():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_forward)\n    #for i in range(numpix):\n    #    strip.set_pixel(i, red)\n    #strip.show()\n\ndef turn_right():\n    turn_motor_on(right_forward)\n    turn_motor_on(left_reverse)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    #for i in range(numpix):\n    #    strip.set_pixel(i, blue)\n    #strip.show()\n\ndef turn_left():\n    turn_motor_on(right_reverse)\n    turn_motor_on(left_forward)\n    turn_motor_off(right_forward)\n    turn_motor_off(left_reverse)\n    #for i in range(numpix):\n    #    strip.set_pixel(i, yellow)\n    #strip.show()\n\ndef stop():\n    turn_motor_off(right_forward)\n    turn_motor_off(right_reverse)\n    turn_motor_off(left_forward)\n    turn_motor_off(left_reverse)\n    for i in range(numpix):\n        strip.set_pixel(i, violet)\n    strip.show()\n\ndef read_sensor_avg():\n    total = 0\n    for i in range(10):\n        total = total + tof.read()\n        sleep(.01)\n    return int(total/10)\n\n# offset is the color to start (0 to 6)\n# dir is 1 for forward and -1 for reverse\ndef color_wipe_4(offset, dir):\n    for i in range(12):\n        if dir == 1:\n            this_color = colors[ ((i-offset) %7 )]\n        else:\n            this_color = colors[ ((i+offset) %7 )]\n        strip.set_pixel(i, this_color)\n        strip.set_pixel(23-i, this_color)\n        strip.set_pixel(i+24, this_color)\n        strip.set_pixel(47-i, this_color)\n        strip.set_pixel(48+i, this_color)\n        strip.set_pixel(71-i, this_color)\n        strip.show()\n        # time.sleep(0.01)\n\ncounter = 0\nwhile True:\n    dist = read_sensor_avg() \n    if dist < TURN_THRESHOLD:\n        print('object detected')\n        reverse()\n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1\n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1\n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n        turn_right()\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n        color_wipe_4(counter % 7, -1)\n        sleep(.1)\n        counter += 1        \n\n    else:\n        forward()\n        color_wipe_4(counter % 7, 1)\n    counter += 1\n

                                                                                                                                                                                                                                                                                                              Rainbow Bot Source Code

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/03-rainbow-bot/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Micropython NeoPixel Library
                                                                                                                                                                                                                                                                                                              "},{"location":"robots/04-face-bot/","title":"MicroPython FaceBot","text":"

                                                                                                                                                                                                                                                                                                              This lesson will allow you to draw simple faces on the display on the front of our robots. The faces can reflect the emotions of your robot. We are inspired by the faces on the

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/05-ajusta-bot/","title":"Adjusta Bot","text":"

                                                                                                                                                                                                                                                                                                              This robot uses buttons and a rotary encoder to allow the user to reprogram the Pico and adjust the collision avoidance parameters.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/20-faqs/","title":"Robots Frequently Asked Questions","text":""},{"location":"robots/20-faqs/#why-a-two-motor-three-wheel-robot-not-four-motor-four-wheel-robot","title":"Why a two-motor three wheel robot, not four motor four wheel robot?","text":"

                                                                                                                                                                                                                                                                                                              We evaluated both the two-motor three wheel robot and the four motor four wheel robots and found that we could achieve all our learning objectives with the two-motor three wheel version. The kits are lower cost, have a simpler assembly process and have plenty of power for our projects.

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/20-faqs/#why-do-we-use-the-l293d-vs-l298n-motor-driver","title":"Why do we use the L293D vs L298N Motor Driver?","text":"

                                                                                                                                                                                                                                                                                                              Both of these popular motor driver chips are commonly used in robot kits. Our focus is teaching the principals of computational thinking using low-cost parts. Since the L293D is lower cost and has plenty of power for our two-motor robots we chose that. There is a detailed side-by-side comparison [here] (https://www.etechnophiles.com/l293d-vs-l298n-motor-driver-differences-specifications-and-pinouts/)

                                                                                                                                                                                                                                                                                                              "},{"location":"robots/20-faqs/#why-dont-we-just-create-a-remote-control-robot-car","title":"Why don't we just create a remote control robot car?","text":"

                                                                                                                                                                                                                                                                                                              Remote control cars are very fun to play with. But we find that it often detracts from our mission of learning how to code. So we try to minimize the time students spend just driving their cars around our tracks.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/01-intro/","title":"Sensors in MicroPython","text":""},{"location":"sensors/01-intro/#light-sensor","title":"Light Sensor","text":""},{"location":"sensors/01-intro/#ping","title":"Ping","text":""},{"location":"sensors/01-intro/#temperature","title":"Temperature","text":""},{"location":"sensors/02-photosensor/","title":"Light Sensor with Raspberry Pi Pico in MicroPython","text":"

                                                                                                                                                                                                                                                                                                              A photoresistor is a sensor that decreases resistance when light is shined on its surface. With no light a photoresistor has high resistance in the range of megaohms. As light shines on the surface the resistance drops to kiloohms. We can use this effect as a light sensor.

                                                                                                                                                                                                                                                                                                              To convert the variable resistance of a photoresistor to something we can measure with our microcontroller we will need to build a small circuit that includes a 10K ohm resistor. We then measure the voltage between the photoresistor and the 10K resistor as light falls on the sensor. The top and bottom of the circuit are tied to ground and a power rail. This will move the voltage of the midpoint of the circuit.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-photosensor/#circuit","title":"Circuit","text":"

                                                                                                                                                                                                                                                                                                              We want to make sure that we use the stable analog ground (AGND) and analog to reference voltage at either end of the circuit to protect the circuit from all the noise of the power in our processor. Using other power and ground pins will work, but power fluctuations will make the result noisy.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-photosensor/#sample-code","title":"Sample Code","text":"

                                                                                                                                                                                                                                                                                                              Our program will first use the Analog to Digital Circuit (ADC0) as an input. On the Pico this is on pin 26.

                                                                                                                                                                                                                                                                                                              import machine\nimport time\nphoto_pin = machine.ADC(26)\n\nwhile True:\n    val = photo_pin.read_u16()\n    print(val)\n    time.sleep(.2)\n

                                                                                                                                                                                                                                                                                                              When you run the program a series of print values is displayed in the shell every 1/5th of a second. You can also use the Thonny plot window to see how the numbers change and you cover and uncover detector from a light source.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-photosensor/#experiments","title":"Experiments","text":"
                                                                                                                                                                                                                                                                                                              1. What types of devices could use a light detector?
                                                                                                                                                                                                                                                                                                              2. How does a night-light work? How could you add an LED to the circuit so that the LED would turn on if the light level got too low?
                                                                                                                                                                                                                                                                                                              3. Could you automatically adjust the brightness of LEDs on a costume to get brighter in a sunny room and dim if you enter a dark room? What would that code look like?
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-photosensor/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Wikipedia Page on Photoresistor
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-pot/","title":"Reading a Potentiometer","text":"

                                                                                                                                                                                                                                                                                                              Video Demo

                                                                                                                                                                                                                                                                                                              In this lab we will hook up a Potentiometer to the Analog to Digital Converter of the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-pot/#connections","title":"Connections","text":"

                                                                                                                                                                                                                                                                                                              Potentiometers have three wires:

                                                                                                                                                                                                                                                                                                              1. The ground rail
                                                                                                                                                                                                                                                                                                              2. The center tap
                                                                                                                                                                                                                                                                                                              3. The positive rail

                                                                                                                                                                                                                                                                                                              The rails are hooked up to fixed reference voltages. As you turn the know, the center tap returns a value that varies between the ground and the positive rail voltages.

                                                                                                                                                                                                                                                                                                              On many microcontrollers, the positive voltage is very \"noisy\" in that it contains voltage that varies as the components draw power. The Raspberry Pi has a special region for high-quality data gathering that is isolated from this noise. To use this section you MUST hook the rails to the right pins.

                                                                                                                                                                                                                                                                                                              ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required.

                                                                                                                                                                                                                                                                                                              AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and terminating at this pin.

                                                                                                                                                                                                                                                                                                              <!-- ->

                                                                                                                                                                                                                                                                                                              graph LR\np[Pico]-->|ADC_VREF 36 row=6| pos(Positive)\np[Pico]-->|AGND 33 row=8| neg(Negative)\np[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)\n    pos(Positive) --- pot(Potentiometer)\n    neg(Negative) --- pot(Potentiometer)\n    tap(Center Tap) --- pot(Potentiometer)\n

                                                                                                                                                                                                                                                                                                              Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/02-pot/#sampling-data","title":"Sampling data","text":"

                                                                                                                                                                                                                                                                                                              Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values.

                                                                                                                                                                                                                                                                                                              Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples.

                                                                                                                                                                                                                                                                                                              def sample_pot(pin, count):\n    total = 0\n    for i in range(count):\n        total += int(pin.read_u16())\n        utime.sleep_ms(5)\n    return int(total / count)\n
                                                                                                                                                                                                                                                                                                              pot_pin_1 = machine.ADC(26)\n# return a value after sampling 10 times\nsample_pot(pot_pin_1, 10)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/03-ping/","title":"Ultrasonic Ping Sensor","text":"

                                                                                                                                                                                                                                                                                                              The HC-SR04 is a low cost ($4) sensor that measures the distance to an object in front of it.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/03-ping/#wiring-diagram","title":"Wiring Diagram","text":"
                                                                                                                                                                                                                                                                                                              1. Connect GND to any GND pin on the Pico
                                                                                                                                                                                                                                                                                                              2. Connect VCC to VBUS or 5 Volt power
                                                                                                                                                                                                                                                                                                              3. Connect Trigger to pin 15. With USB on the top, this pin is the bottom left corner.
                                                                                                                                                                                                                                                                                                              4. Connect Echo to pin 14. One up from bottom left corner.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/03-ping/#sample-code","title":"Sample Code","text":"
                                                                                                                                                                                                                                                                                                              # Sample code to test HC-SR04 Ultrasonice Ping Sensor\n# Connect GND to any GND pin on the Pico\n# Connnect VCC to VBUS or 5 Volt power\n\nfrom machine import Pin, Timer\nimport utime\n\nTRIGGER_PIN = 15 # With USB on the top, this pin is the bottom left corner\nECHO_PIN = 14 # One up from bottom left corner\n\n# Init HC-SR04 pins\ntrigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor\necho = Pin(ECHO_PIN, Pin.IN) # get the delay interval back\n\ndef ping():\n    trigger.low()\n    utime.sleep_us(2) # Wait 2 microseconds low\n    trigger.high()\n    utime.sleep_us(5) # Stay high for 5 miroseconds\n    trigger.low()\n    while echo.value() == 0:\n        signaloff = utime.ticks_us()\n    while echo.value() == 1:\n        signalon = utime.ticks_us()\n    timepassed = signalon - signaloff\n    distance = (timepassed * 0.0343) / 2\n    return distance\n\nwhile True:\n    print(\"Distance:\", ping(), \" cm\")\n    utime.sleep(.25)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/03-ping/#oled","title":"OLED","text":"

                                                                                                                                                                                                                                                                                                              If you have a small OLED screen, you can also display the results of the distance measurement directly on an OLED screen.

                                                                                                                                                                                                                                                                                                              See the OLED example here: OLED Ping Example

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/04-temp-dht11/","title":"Sensing Temperature and Humidity with the DHT11 Sensor","text":""},{"location":"sensors/04-temp-dht11/#sample-code","title":"Sample Code","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport utime as time\nfrom dht import DHT11, InvalidChecksum\n\nDHT_PIN = 15\n# this is a bit odd, since although it is an input, we need a pull down set\ndhtSensor = DHT11(Pin(DHT_PIN, Pin.OUT, Pin.PULL_DOWN))\n\nwhile True:\n    temp = dhtSensor.temperature\n    humidity = dhtSensor.humidity/100\n    print(\"Temp: {}\u00b0C\".format(temp),  \"| Hum: {0:.1%}\".format(humidity))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/04-temp-dht11/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Peppe80's Example
                                                                                                                                                                                                                                                                                                              • Axel \u00d6rn Sigur\u00f0sson's DHT11 Driver
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/05-temp-dsb20/","title":"Temp with DS18B20","text":"

                                                                                                                                                                                                                                                                                                              https://randomnerdtutorials.com/micropython-ds18b20-esp32-esp8266/

                                                                                                                                                                                                                                                                                                              ```py

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/05-temp-dsb20/#complete-project-details-at-httpsrandomnerdtutorialscom","title":"Complete project details at https://RandomNerdTutorials.com","text":"

                                                                                                                                                                                                                                                                                                              import machine, onewire, ds18x20, time

                                                                                                                                                                                                                                                                                                              ds_pin = machine.Pin(4) ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))

                                                                                                                                                                                                                                                                                                              roms = ds_sensor.scan() print('Found DS devices: ', roms)

                                                                                                                                                                                                                                                                                                              while True: ds_sensor.convert_temp() time.sleep_ms(750) for rom in roms: print(rom) print(ds_sensor.read_temp(rom)) time.sleep(5) ```

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/","title":"MPU-9250 Accelerometer Gyroscope Compass","text":"

                                                                                                                                                                                                                                                                                                              The MPU-9250 by InvenSense is a nine-axis motion tracking device. It includes:

                                                                                                                                                                                                                                                                                                              1. A MPU-6500, which contains a 3-axis accelerometer and a 3-axis gyroscope and
                                                                                                                                                                                                                                                                                                              2. A AK8963, the market leading 3-axis digital compass that senses magnetic fields

                                                                                                                                                                                                                                                                                                              (Gyro + Accelerometer + Compass) MEMS MotionTracking\u2122 Device

                                                                                                                                                                                                                                                                                                              1PCS GY-91 10DOF Accelerometer Gyroscope Compass Temp/Pressure MPU-9250 BMP-280

                                                                                                                                                                                                                                                                                                              • Art of Circuits
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#pinouts","title":"Pinouts","text":"
                                                                                                                                                                                                                                                                                                              1. VIN: Voltage Supply Pin
                                                                                                                                                                                                                                                                                                              2. 3V3: 3.3v Regulator output
                                                                                                                                                                                                                                                                                                              3. GND: 0V Power Supply
                                                                                                                                                                                                                                                                                                              4. SCL: I2C Clock / SPI Clock
                                                                                                                                                                                                                                                                                                              5. SDA: I2C Data or SPI Data Input
                                                                                                                                                                                                                                                                                                              6. SDO/SAO: SPI Data output / I2C Slave Address configuration pin
                                                                                                                                                                                                                                                                                                              7. NCS: Chip Select for SPI mode only for MPU-9250
                                                                                                                                                                                                                                                                                                              8. CSB: Chip Select for BMP280

                                                                                                                                                                                                                                                                                                              You only need to hook the 3.3 to VIN, the GND to GND and the SCL and SDA. The other connections are not needed.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#i2c-scanner-results","title":"I2C Scanner Results","text":"
                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(16) # row one on our standard Pico breadboard\nscl=machine.Pin(17) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              Device found at decimal [104, 118]

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#mpu9250-drivers","title":"MPU9250 Drivers","text":"

                                                                                                                                                                                                                                                                                                              MicroPython Driver

                                                                                                                                                                                                                                                                                                              import utime\nfrom machine import I2C, Pin\nfrom mpu9250 import MPU9250\n\ni2c = I2C(scl=Pin(22), sda=Pin(21))\nsensor = MPU9250(i2c)\n\nprint(\"MPU9250 id: \" + hex(sensor.whoami))\n\nwhile True:\n    print(sensor.acceleration)\n    print(sensor.gyro)\n    print(sensor.magnetic)\n    print(sensor.temperature)\n\n    utime.sleep_ms(1000)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#lsm6ds3-accelerometer-and-gyroscope","title":"LSM6DS3 Accelerometer and Gyroscope","text":"

                                                                                                                                                                                                                                                                                                              The LSM6DS3 is a combined 3-axis accelerometer gyroscope with an 8kb FIFO buffer and an embedded processing interrupt function for the gyro sensor, specifically for the mobile phone market. Specifications:

                                                                                                                                                                                                                                                                                                              1. 3-axis accelerometer
                                                                                                                                                                                                                                                                                                              2. 6 parameter gyroscope
                                                                                                                                                                                                                                                                                                              3. 8K FIFO for buffering reads
                                                                                                                                                                                                                                                                                                              4. Embedded temperature sensor
                                                                                                                                                                                                                                                                                                              5. 3.3 logic. Any voltages above 3.3 will damage the board
                                                                                                                                                                                                                                                                                                              6. Gyro read data speed: 6.7ks / s
                                                                                                                                                                                                                                                                                                              7. Accelerometer read data speed: 1.7ks / s
                                                                                                                                                                                                                                                                                                              8. Power consumption: 0.9 mA for standard rate, 1.25 mA for high-performance mode
                                                                                                                                                                                                                                                                                                              9. Input supply voltage: 1.71V to 5V
                                                                                                                                                                                                                                                                                                              10. Interfaces: IIC and SPI
                                                                                                                                                                                                                                                                                                              11. Accelerometer Sensitivity Ranges: \u00b12/\u00b14/\u00b116/\u00b18 g
                                                                                                                                                                                                                                                                                                              12. Gyro Sensitivity Ranges: \u00b1 125/245/500/1000/2000 degrees per second

                                                                                                                                                                                                                                                                                                              With LSM6DS3 breakout, you will be able to detect the motion, impact, and tilt.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#selecting-the-accelerometer-sensitivity-range","title":"Selecting the Accelerometer Sensitivity Range","text":"

                                                                                                                                                                                                                                                                                                              The sensitivity ratings for an accelerometer specify the maximum measurable acceleration that the device can sense along its measurement axis (or axes). When an accelerometer states its sensitivity as \u00b12/\u00b14/\u00b116/\u00b18 g, it usually means that the device can be set to different ranges or scales of measurement. Here's what each of those ratings mean:

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#2g-sensitivity-setting","title":"\u00b12g Sensitivity Setting","text":"

                                                                                                                                                                                                                                                                                                              The accelerometer can measure accelerations between -2g and +2g. This is a lower range, so it can detect small changes in acceleration with high precision. This range would be ideal for applications that require precise measurements of small movements. For example, the orientation of a screen as it is being tilted or rotated.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#4g-sensitivity-setting","title":"\u00b14g Sensitivity Setting","text":"

                                                                                                                                                                                                                                                                                                              In this setting, the accelerometer can measure accelerations between -4g and +4g. This provides a slightly larger range than the \u00b12g setting, making it suitable for applications that might experience slightly stronger forces or movements but still require a good amount of precision.

                                                                                                                                                                                                                                                                                                              One example is wearable fitness trackers, like smartwatches and sport bands, often have built-in accelerometers to monitor and analyze user movement. For regular walking or jogging, a \u00b12g accelerometer might suffice. However, for more intense activities like plyometric exercises, sprinting, or aggressive directional changes in sports like basketball or soccer, the forces exerted on the tracker can exceed 2g. These activities involve rapid starts, stops, jumps, and changes in direction.

                                                                                                                                                                                                                                                                                                              Why \u00b14g?: The accelerometer needs to capture both the subtleties of everyday motion and the higher-intensity bursts of activity without saturating or clipping the data. A \u00b14g range provides a good balance between sensitivity and maximum measurable acceleration, making it suitable for wearable devices intended for diverse and dynamic physical activities.

                                                                                                                                                                                                                                                                                                              With this capability, fitness trackers can more accurately measure and analyze the user's movements across a wider range of activities, providing better data and feedback on their workouts and performance.

                                                                                                                                                                                                                                                                                                              \u00b116g: The accelerometer can measure accelerations between -16g and +16g. This is a much broader range and is less sensitive to small movements. It's ideal for applications that are exposed to stronger forces or rapid movements, such as crash detection or certain sports applications.

                                                                                                                                                                                                                                                                                                              \u00b18g: The accelerometer can measure accelerations between -8g and +8g. This provides a balance between sensitivity and range, suitable for applications that might experience moderate forces.

                                                                                                                                                                                                                                                                                                              In practice, these settings allow the user (or designer) to choose the best range for their application. For applications where precision in detecting small accelerations is essential, a lower range (like \u00b12g) would be selected. In contrast, for applications where large accelerations may occur, a higher range (like \u00b116g) would be more appropriate to prevent the sensor from saturating or clipping the readings.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#selecting-gyroscope-sensitivity-ranges","title":"Selecting Gyroscope Sensitivity Ranges","text":"

                                                                                                                                                                                                                                                                                                              Gyroscopes measure the rate of angular change, often referred to as the angular velocity or angular rate. The unit for this rate of change is typically represented in degrees per second (DPS).

                                                                                                                                                                                                                                                                                                              The sensitivity ranges for a gyroscope describe the maximum rate of rotation it can measure. When a gyroscope has sensitivity ranges listed as \u00b1125/245/500/\u00b11000/\u00b12000 DPS, it means the device has multiple selectable scales or ranges of measurement. Let's break down each of these ranges:

                                                                                                                                                                                                                                                                                                              \u00b1125 DPS: At this setting, the gyroscope can measure angular velocities between -125 and +125 degrees per second. This is a low range and would provide high precision for slow rotational movements. For example, a slowly turning sailboat.

                                                                                                                                                                                                                                                                                                              \u00b1245 DPS: The device can measure angular velocities between -245 and +245 degrees per second. This offers a slightly larger range than the \u00b1125 DPS setting.

                                                                                                                                                                                                                                                                                                              \u00b1500 DPS: This setting allows the gyroscope to measure between -500 and +500 degrees per second.

                                                                                                                                                                                                                                                                                                              \u00b11000 DPS: The device can measure angular velocities ranging between -1000 and +1000 degrees per second. This is suitable for applications that might experience moderately fast rotations.

                                                                                                                                                                                                                                                                                                              \u00b12000 DPS: At this maximum setting, the gyroscope can capture angular velocities between -2000 and +2000 degrees per second. It's best for very fast rotational movements. For example, inside a rapidly spinning ball thown in the air.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#gyroscope-sensitivity-ranges-and-their-applications","title":"Gyroscope Sensitivity Ranges and Their Applications","text":"

                                                                                                                                                                                                                                                                                                              Here are some examples of different applications that might be used in each of these ranges.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#125-dps","title":"\u00b1125 DPS","text":"
                                                                                                                                                                                                                                                                                                              • Wearable Health Devices: Devices like posture trackers which monitor the orientation of a user to ensure they are maintaining a healthy posture.
                                                                                                                                                                                                                                                                                                              • Human Movement Analysis: In biomechanics or rehabilitation scenarios where slow and controlled movements are being assessed.
                                                                                                                                                                                                                                                                                                              • Precision Robotics: Robots that need to make very slow, controlled, and precise rotations.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#245-dps","title":"\u00b1245 DPS","text":"
                                                                                                                                                                                                                                                                                                              • Consumer Electronics: Gadgets like virtual reality (VR) headsets or augmented reality (AR) devices that track head movements, where moderate but not very rapid turns are common.
                                                                                                                                                                                                                                                                                                              • Gaming Controllers: For games where precise tracking of tilt and rotation is crucial for gameplay.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#500-dps","title":"\u00b1500 DPS","text":"
                                                                                                                                                                                                                                                                                                              • Drones: Hobby drones or quadcopters that don't perform aggressive maneuvers might fit into this range.
                                                                                                                                                                                                                                                                                                              • Camera Gimbal Systems: Devices that stabilize cameras may need to compensate for moderate motions.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#1000-dps","title":"\u00b11000 DPS","text":"
                                                                                                                                                                                                                                                                                                              • Advanced Drones: Racing drones or those designed for aerial acrobatics that require swift and agile movements.
                                                                                                                                                                                                                                                                                                              • Sports Analysis: Tracking rapid movements in sports training equipment, like baseball or golf swing analyzers.
                                                                                                                                                                                                                                                                                                              • Automotive Systems: Stability control systems in vehicles that monitor and counteract skidding or rollovers.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#2000-dps","title":"\u00b12000 DPS","text":"
                                                                                                                                                                                                                                                                                                              • High-performance Aircraft: Certain maneuvers in aeronautical or aerospace applications might need this high range.
                                                                                                                                                                                                                                                                                                              • High-speed Robotics: Robots designed for tasks that involve very rapid rotations.
                                                                                                                                                                                                                                                                                                              • Extreme Sports Equipment: Equipment used in scenarios where extreme rotational velocities can occur, like certain types of motorsport or action sports.

                                                                                                                                                                                                                                                                                                              Module size: 13 * 18mm

                                                                                                                                                                                                                                                                                                              Package Include: 1 x GY-LSM6DS3 IIC/SPI Accelerometer Tilt Angle Gyro Sensor Breakout Transfer Module

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#settings-for-robot-tracking-orientation-and-position","title":"Settings for Robot Tracking Orientation and Position","text":"

                                                                                                                                                                                                                                                                                                              If we are Tracking Orientation and Position for a Small Robot we need the following:

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#1-accelerometer","title":"1. Accelerometer:","text":"
                                                                                                                                                                                                                                                                                                              • Sensitivity: Given the maximum speed of 6 inches per second, the accelerometer's main role is to capture any rapid starts, stops, or changes in direction. A \u00b12g setting is likely sufficient for most small robot applications. If uncertain about specific accelerations or possible bumps or drops, consider a \u00b14g setting.
                                                                                                                                                                                                                                                                                                              • Purpose: Measures acceleration and helps detect the robot's orientation with respect to the Earth's gravitational field.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#2-gyroscope","title":"2. Gyroscope:","text":"
                                                                                                                                                                                                                                                                                                              • Sensitivity: For moderate speeds and non-rapid spins, a \u00b1250 DPS setting might be adequate. For rapid turns, a higher setting might be needed.
                                                                                                                                                                                                                                                                                                              • Purpose: Measures the rate of angular change to help determine the robot's orientation.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#3-magnetometer-if-included-in-imu","title":"3. Magnetometer (if included in IMU):","text":"
                                                                                                                                                                                                                                                                                                              • Purpose: Measures the Earth's magnetic field to determine the robot's heading relative to magnetic north.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#4-sensor-fusion","title":"4. Sensor Fusion:","text":"
                                                                                                                                                                                                                                                                                                              • Combine data from the accelerometer, gyroscope, and magnetometer (if available) for a comprehensive understanding of the robot's movement and orientation.
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#5-additional-considerations","title":"5. Additional Considerations:","text":"
                                                                                                                                                                                                                                                                                                              • Wheel Encoders: Useful for position tracking by measuring wheel rotation.
                                                                                                                                                                                                                                                                                                              • External Sensors: Consider infrared, ultrasonic sensors, or computer vision techniques for advanced navigation and localization.

                                                                                                                                                                                                                                                                                                              Remember to test and calibrate in real-world scenarios for optimal performance.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-accelerometer-compass/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • MEMS YouTube Video The ingenious micro mechanisms inside your phone
                                                                                                                                                                                                                                                                                                              • LSM6DS3 IIC/SPI 3 Axis Accelerometer Gyroscope 6 Degrees Sensor Transfer Module - on Ebay for $3 each - IIC and SPI
                                                                                                                                                                                                                                                                                                              • SparkFun LSM6DS3 Breakout Hookup Guide
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/","title":"BME280 Environmental Sensor","text":"

                                                                                                                                                                                                                                                                                                              The Bosch BME280 is a low-cost ($2) temperature, and pressure sensor that has an I2C interface. This is an ideal way to learn how to use an I2C interface.

                                                                                                                                                                                                                                                                                                              Note mbe280 is different from the BMP280 and does not read humidity. The default address is Hex x76 or decimal 118.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#circuit","title":"Circuit","text":"

                                                                                                                                                                                                                                                                                                              The BME280 has a standard I2C interface with four wires:

                                                                                                                                                                                                                                                                                                              • GND - connect to any of the GND pins
                                                                                                                                                                                                                                                                                                              • VCC - connect this to the 3.3V output of the Pico
                                                                                                                                                                                                                                                                                                              • SCL - clock
                                                                                                                                                                                                                                                                                                              • SDA - data
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#i2c-scanner","title":"I2C Scanner","text":"

                                                                                                                                                                                                                                                                                                              After you have connected your sensor you can check the connection by running a quick \"I2C Scanner\" to find the address of the sensor.

                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top\nscl=machine.Pin(1) # Row two of our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              Results:

                                                                                                                                                                                                                                                                                                              [118]\n

                                                                                                                                                                                                                                                                                                              This is decimal of hex 0x76

                                                                                                                                                                                                                                                                                                              If the scanner does not return a number then your connections might not be working.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#bme280-driver","title":"BME280 Driver","text":"

                                                                                                                                                                                                                                                                                                              You should be able to find the BME280 driver by using the Thonny Tool -> Manage Packages... menu. If that does not work you can try a github search:

                                                                                                                                                                                                                                                                                                              Search GitHub for MBE 280 Python Code

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#test-code","title":"Test Code","text":"
                                                                                                                                                                                                                                                                                                              import machine\nfrom utime import sleep\nimport BME280\nsda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top\nscl=machine.Pin(1) # Row two of our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n\n# initialize the bme class using the default address\nbme = BME280()\n(chip_id, chip_version) = bme.getID()\nprint( \"Chip ID:\", chip_id)\nprint( \"Version:\", chip_version)\n\nwhile True():\n    # get new data from the \n    temperature,pressure,humidity = bme.getData()\n    #adj_bar = bme.adj_baro(pressure, temperature)\n    print(\"Adj {}\".format(bme.adj_baro(pressure, temperature)))\n\n    print( \"Temperature: {}C\".format(temperature))\n    print( \"Pressure: {}hpa, {}In\".format(pressure, round(pressure * 0.02953, 2)))\n\n    sleep(1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#code-2","title":"Code 2","text":"
                                                                                                                                                                                                                                                                                                              from machine import I2C\nimport BME280\nfrom time import sleep\n\nsda=machine.Pin(16)\nscl=machine.Pin(17)\ni2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)\nbme = BME280.BME280(i2c=i2c)\n# print(i2c.scan())\n\nwhile True:\n\n  temp = bme.temperature\n  hum = bme.humidity\n  pres = bme.pressure\n  # uncomment for temperature in Fahrenheit\n  temp = (bme.read_temperature()/100) * (9/5) + 32\n  #temp = str(round(temp, 2)) + 'F'\n  print('Temperature: ', temp, end='')\n  print(' Humidity:', hum, end='')\n  print(' Pressure:', pres)\n\n  sleep(5)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Robert HH BME280 Test Page
                                                                                                                                                                                                                                                                                                              2. Official Datasheet
                                                                                                                                                                                                                                                                                                              3. eBay BME280 Sensor Search
                                                                                                                                                                                                                                                                                                              4. Driver Sample code
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/06-bme280/#digital-barometric-pressure-sensor-board-swap-i2cspi-bmp280-bme280-33v","title":"Digital Barometric Pressure Sensor Board Swap I2C/SPI BMP280 BME280 3.3V","text":"

                                                                                                                                                                                                                                                                                                              BME280 4. BME280 logger 5. The Electronics India

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/","title":"VL53L0X Time-of-Flight Laser Ranging Module IR Distance Sensor","text":"

                                                                                                                                                                                                                                                                                                              Figure: VL53L0X in the GY-530 package.

                                                                                                                                                                                                                                                                                                              The VL53L0X is a low-cost ($5) time-of-flight light-based distance sensor that is easy to use. It comes packaged in a I2C board and gives precise distance measurements up to 1.5 meters away. It measures the time that light pulses take to travel to an object and back to estimate distance. Light travels about 1 foot every nanosecond, so the timing inside this little chip must be very accurate.

                                                                                                                                                                                                                                                                                                              The VL53L0X integrates a group of Single Photon Avalanche Diodes (SPAD) and embeds ST Electronic's second generation FlightSense\u2122 patented technology. The VL53L0X\u2019s 940 nm emitter Vertical Cavity Surface-Emitting Laser (VCSEL), is safe for kids and totally invisible to the human eye. Coupled with internal physical infrared filters, the sensor enables longer ranging distance, higher immunity to ambient light, and better robustness to cover glass optical crosstalk.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#circuit","title":"Circuit","text":"

                                                                                                                                                                                                                                                                                                              Hook the VCC to the 3.3 out of the Pico, the GND of the sensor to andy of the GND pins of the Pico and then connect the Clock and Data to two pins such as GPIO pins 16 and 17.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#i2c-scanner-test","title":"I2C Scanner Test","text":"

                                                                                                                                                                                                                                                                                                              We first run the I2C scanner program to verify that the sensor is connected correctly and is responding to the I2C bus scan.

                                                                                                                                                                                                                                                                                                              import machine\nsda=machine.Pin(0) # row one on our standard Pico breadboard\nscl=machine.Pin(1) # row two on our standard Pico breadboard\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\nprint(\"Device found at decimal\", i2c.scan())\n

                                                                                                                                                                                                                                                                                                              This should return a single decimal number.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#download-the-vl53l0x-driver","title":"Download The VL53L0X Driver","text":"

                                                                                                                                                                                                                                                                                                              If you are using Thonny, you can try to use the \"Manage Packages\" menu and search for the driver.

                                                                                                                                                                                                                                                                                                              We have a sample of the driver here

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#create-a-test-program","title":"Create a Test Program","text":"
                                                                                                                                                                                                                                                                                                              # Test program for VL53L0X\nimport time\nfrom machine import Pin\nfrom machine import I2C\nimport VL53L0X\n\nsda=machine.Pin(16) # lower right pin\nscl=machine.Pin(17) # one up from lower right pin\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n\n# Create a VL53L0X object\ntof = VL53L0X.VL53L0X(i2c)\n\nwhile True:\n    tof.start()\n    tof.read()\n    print(tof.read())\n    tof.stop()\n    time.sleep(0.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#use-the-thonny-plot","title":"Use the Thonny Plot","text":""},{"location":"sensors/07-VL53L0X_GY/#reference-purchase-links","title":"Reference Purchase links","text":"
                                                                                                                                                                                                                                                                                                              1. ST Microelectronics
                                                                                                                                                                                                                                                                                                              2. User Manual
                                                                                                                                                                                                                                                                                                              3. Ebay $4
                                                                                                                                                                                                                                                                                                              4. Amazon $12
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/07-VL53L0X_GY/#ebay","title":"eBay","text":"

                                                                                                                                                                                                                                                                                                              qty 10 for $25

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/","title":"IR Distance Sensor","text":""},{"location":"sensors/08-ir-distance-sensor/#ir-distance-sensors","title":"IR Distance Sensors","text":"

                                                                                                                                                                                                                                                                                                              IR distance sensors are low cost (five for $3) but may have problems working in rooms with outdoor lighting. They have an adjustable potentiometer on them that can be used to adjust a triggering distance call the threshold distance. The sensors return a HIGH signal if there is no object within the threshold distance and a LOW signal if there is an object within this distance. Since the sensor threshold distance can not be adjusted programmatically they are best suited when you can manually adjust the potentiometer to change the threshold.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#connections","title":"Connections","text":"

                                                                                                                                                                                                                                                                                                              These sensors have three wires:

                                                                                                                                                                                                                                                                                                              1. GND - connect to a ground rail on your breadboard or directly to a GND ping on the Pico.
                                                                                                                                                                                                                                                                                                              2. VCC - connect to the 5 volt power rail powered by the motor controller voltage regulator
                                                                                                                                                                                                                                                                                                              3. OUT - a 5 volt digital signal that is usually 5 volts but is GND when triggered by an object
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#sample-python-code","title":"Sample Python Code","text":"
                                                                                                                                                                                                                                                                                                              # connections to the three IR distance sensors\nleft = Pin(8, Pin.IN, Pin.PULL_DOWN)\ncenter = Pin(7, Pin.IN, Pin.PULL_DOWN)\nright = Pin(6, Pin.IN, Pin.PULL_DOWN)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#the-ky-032","title":"The KY-032","text":"

                                                                                                                                                                                                                                                                                                              The KY-032 obstacle avoidance sensor is a four-wire distance-adjustable, infrared proximity sensor designed for wheeled robots. Also known as AD-032.

                                                                                                                                                                                                                                                                                                              The sensor detection distance ranges from 2cm to 40cm, it can be adjusted by turning the potentiometer knob. The operating voltage is 3.3V-5V so it is suitable for a variety of microcontrollers like Arduino, ESP32, Teensy, ESP8266, Raspberry Pi, and others.

                                                                                                                                                                                                                                                                                                              It has strong adaptability to ambient light and it is fairly accurate to sense changes in the surrounding environment.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#speaker-test","title":"Speaker Test","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n\nleft = Pin(8, Pin.IN, Pin.PULL_DOWN)\ncenter = Pin(7, Pin.IN, Pin.PULL_DOWN)\nright = Pin(6, Pin.IN, Pin.PULL_DOWN)\n\nSPEAKER_PIN = 21\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\ndef sound_off():\n    speaker.duty_u16(0)\n\ndef left_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(300) # 1 Kilohertz\n    sleep(.5) # wait a 1/4 second\n    sound_off()\n\ndef center_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(800)\n    sleep(.5)\n    sound_off()\n\ndef right_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(400)\n    sleep(.5)\n    sound_off()\n\ndef right_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(800)\n    sleep(.25)\n    sound_off()\n\ndef forward_tone():\n    speaker.duty_u16(1000)\n    speaker.freq(400)\n    sleep(.1)\n    speaker.freq(900)\n    sleep(.1)\n    speaker.freq(1200)\n    sleep(.1)\n    sound_off()\n\n# 0=stopped, 1=forward, 2=turing right, 3=turning left\ndrive_state = 0\nwhile True:\n    if left.value()==0:\n        print('Left')\n        left_tone()\n        drive_state = 2\n    if center.value()==0:\n        print('Center')\n        center_tone()\n        drive_state = 0\n    if right.value()==0:\n        print('Right')\n        right_tone()\n        drive_state = 3\n\n    # if (left.value()==1) and (center.value()==1) and (right.value()==1):\n    if left.value() and center.value() and right.value():\n        print('Go forward!')\n        drive_state = 1\n        forward_tone()\n    sleep(.25)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#full-program","title":"Full Program","text":"

                                                                                                                                                                                                                                                                                                              ```py from machine import Pin, PWM from utime import sleep import ssd1306

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#motor-pins-to-the-l293-h-bridge","title":"Motor pins to the L293 H-Bridge","text":"

                                                                                                                                                                                                                                                                                                              RIGHT_FORWARD_PIN = 17 RIGHT_REVERSE_PIN = 16 LEFT_FORWARD_PIN = 18 LEFT_REVERSE_PIN = 19

                                                                                                                                                                                                                                                                                                              right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) left_forward = PWM(Pin(LEFT_FORWARD_PIN)) left_reverse = PWM(Pin(LEFT_REVERSE_PIN))

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#connections-to-the-three-ir-distance-sensors","title":"connections to the three IR distance sensors","text":"

                                                                                                                                                                                                                                                                                                              left = Pin(8, Pin.IN, Pin.PULL_DOWN) center = Pin(7, Pin.IN, Pin.PULL_DOWN) right = Pin(6, Pin.IN, Pin.PULL_DOWN)

                                                                                                                                                                                                                                                                                                              SPEAKER_PIN = 21

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#create-a-pulse-width-modulation-object-on-this-pin","title":"create a Pulse Width Modulation Object on this pin","text":"

                                                                                                                                                                                                                                                                                                              speaker = PWM(Pin(SPEAKER_PIN))

                                                                                                                                                                                                                                                                                                              WIDTH = 128 HEIGHT = 64 CS = machine.Pin(1) SCL = machine.Pin(2) SDA = machine.Pin(3) DC = machine.Pin(4) RES = machine.Pin(5) spi=machine.SPI(0, sck=SCL, mosi=SDA) oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)

                                                                                                                                                                                                                                                                                                              def turn_motor_on(pwm): pwm.duty_u16(65025)

                                                                                                                                                                                                                                                                                                              def turn_motor_off(pwm): pwm.duty_u16(0)

                                                                                                                                                                                                                                                                                                              def forward(): turn_motor_on(right_forward) turn_motor_on(left_forward)

                                                                                                                                                                                                                                                                                                              def reverse(): turn_motor_on(right_reverse) turn_motor_on(left_reverse)

                                                                                                                                                                                                                                                                                                              def turn_right(): turn_motor_on(right_forward) turn_motor_on(left_reverse)

                                                                                                                                                                                                                                                                                                              def turn_left(): turn_motor_on(right_reverse) turn_motor_on(left_forward)

                                                                                                                                                                                                                                                                                                              def sound_off(): speaker.duty_u16(0)

                                                                                                                                                                                                                                                                                                              def left_tone(): speaker.duty_u16(1000) speaker.freq(700) # 1 Kilohertz sleep(.5) # wait a 1/4 second sound_off()

                                                                                                                                                                                                                                                                                                              def center_tone(): speaker.duty_u16(1000) speaker.freq(900) sleep(.5) sound_off()

                                                                                                                                                                                                                                                                                                              def right_tone(): speaker.duty_u16(1000) speaker.freq(600) sleep(.5) sound_off()

                                                                                                                                                                                                                                                                                                              def forward_tone(): speaker.duty_u16(1000) speaker.freq(400) sleep(.1) speaker.freq(900) sleep(.1) speaker.freq(1200) sleep(.1) sound_off()

                                                                                                                                                                                                                                                                                                              def update_oled(): oled.fill(0) oled.text(\"CoderDojo Rocks!\", 0, 0, 1)

                                                                                                                                                                                                                                                                                                              oled.text(\"Left:\", 0, 10, 1)\noled.text(str(left.value()), 50, 10, 1)\n\n\noled.text(\"Center:\", 0, 20, 1)\noled.text(str(center.value()), 60, 20, 1)\n\noled.text(\"Right:\", 0, 30, 1)\noled.text(str(right.value()), 55, 30, 1)\n\nBAR_WIDTH = 40\nBAR_HEIGHT = 20\nif left.value():\n    oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0)\nelse:\n    oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\nif center.value():\n    oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0)\nelse:\n    oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\nif right.value():\n    oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0)\nelse:\n    oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1)\n\noled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/08-ir-distance-sensor/#0stopped-1forward-2turing-right-3turning-left","title":"0=stopped, 1=forward, 2=turing right, 3=turning left","text":"

                                                                                                                                                                                                                                                                                                              drive_state = 0 counter = 0 while True: if left.value()==0: print('Left') #left_tone() turn_right() update_oled() drive_state = 2 if center.value()==0: print('Center') center_tone() reverse() update_oled() drive_state = 0 if right.value()==0: print('Right') #right_tone() turn_left() update_oled() drive_state = 3

                                                                                                                                                                                                                                                                                                              # if (left.value()==1) and (center.value()==1) and (right.value()==1):\nif left.value() and center.value() and right.value():\n    print('Go forward!')    \n    drive_state = 1\n    # forward_tone()\n    forward()\n    update_oled()\nprint(\"counter: \", counter)\ncounter += 1\nsleep(.25)\n```\n\n## More to Explore\n\n1. Try to change the values of the potentiometers on the sensors.  What is the minimum and maximum distance you can detect and object?\n2.  Does the reflectivity of the object impact the distance of the object?\n3. If you put a small mirror in front of the sensor what happens to the distance measured?\n4. Place the robot near bright sun in a window or try the robot outdoors on both a cloudy day and a sunny day?  What is the change is accuracy of the sensors under these conditions?  What about running the robot in the dark?\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/","title":"Rotary Encoder","text":"

                                                                                                                                                                                                                                                                                                              A rotary encoder, or more specifically a directional rotary encoder, may look similar to a potentiometer in some ways. Both have a knob that you turn to adjust a value. But unlike a potentiometer, a rotary encoder is far more flexible in the range and precision of values it can control. Our students love to use them in their projects to change the color or patterns in an LED strip.

                                                                                                                                                                                                                                                                                                              Rotary encoders can be thought of as two concentric rings of switches that go on and off as you turn the knob. The switches are placed so that you can tell the direction of rotation by the order the two switches get turned on and off. They turn on and off quickly so we need a high-quality function to quickly detect their changes. And as we learned in the Button lab, switches can be noisy and have a complex state transition that must be debounced to get a good quality signal.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#learning-how-to-monitor-the-rotary-switch-transitions","title":"Learning How to Monitor the Rotary Switch Transitions","text":"

                                                                                                                                                                                                                                                                                                              We will be using a low-cost ($1 USD) encoder that has five connectors, three for the direction and one for a momentary switch that is closed when you press the knob in. Here is the circuit that we will be using:

                                                                                                                                                                                                                                                                                                              We hooked up the outer pins of the encoder to GPIO pins 16 and 17 in the lower right corner of the Pico.

                                                                                                                                                                                                                                                                                                              Then we hooked the center pin to the 3.3 volt rail. The Pico likes to pull switches down from the 3.3 volt rail. This means that we will not be connecting any of the pins to GND.

                                                                                                                                                                                                                                                                                                              We also hooked up the central press button to GPIO 22 and the 3.3 volt rail.

                                                                                                                                                                                                                                                                                                              We then ran this code and turned the knob:

                                                                                                                                                                                                                                                                                                              import time\nfrom machine import Pin\n\nrotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)\nrotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)\n\nwhile True:\n    print(rotaryA.value(), end='')\n    print(rotaryB.value())\n    time.sleep(.1)\n

                                                                                                                                                                                                                                                                                                              the results look like the following lines:

                                                                                                                                                                                                                                                                                                              00\n00\n00\n10\n01\n00\n00\n00\n11\n00\n00\n00\n01\n11\n00\n

                                                                                                                                                                                                                                                                                                              Note that the bit values the encoders switches (on or off as 0 and 1) are place next to each other on the same line. We did this by making the end of the first print statement be the null string not the default newline character.

                                                                                                                                                                                                                                                                                                              This program prints out a LONG stream of numbers, mostly of the value 00. The values are printed 10 times each second. Now let's take a closer look at only the values that change.

                                                                                                                                                                                                                                                                                                              What we would like to do is now only print numbers if there is a change. To do this we will \"pack\" binary values into a two bit number by shifting the A pin value to the left:

                                                                                                                                                                                                                                                                                                              import time\nfrom machine import Pin\n\nrotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)\nrotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)\n\n# we set the old value to zero for both bits being off\nold_combined = 0\nwhile True:\n    A_val = rotaryA.value()\n    B_val = rotaryB.value()\n    # a sifts by one bit and then is ORed with the B calue\n    new_combined = (A_val << 1) | B_val\n    if new_combined != old_combined:\n            print(A_val, end='')\n            print(B_val)\n            old_combined = new_combined\n    time.sleep(.1)\n

                                                                                                                                                                                                                                                                                                              Now we get values that look like this:

                                                                                                                                                                                                                                                                                                              01\n11\n00\n01\n11\n00\n01\n11\n10\n00\n10\n00\n01\n11\n00\n10\n
                                                                                                                                                                                                                                                                                                              Turning the knob clockwise we see the 01 before the 11 frequently

                                                                                                                                                                                                                                                                                                              Turning the know counterclockwise:

                                                                                                                                                                                                                                                                                                              00\n10\n11\n00\n10\n11\n00\n11\n00\n10\n00\n10\n01\n00\n

                                                                                                                                                                                                                                                                                                              Here we see the reverse 10 pattern occur more frequently. But there is noise in the switches as they open and close due to small variations in the contacts as they move.

                                                                                                                                                                                                                                                                                                              import time\nfrom machine import Pin\n\nrotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)\nrotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)\n\n# we set the old value to zero for both bits being off\nold_combined = 0\nwhile True:\n    A_val = rotaryA.value()\n    B_val = rotaryB.value()\n    # a sifts by one bit and then is ORed with the B calue\n    new_combined = (A_val << 1) | B_val\n    if new_combined != old_combined:\n            #print(A_val, end='')\n            #print(B_val)\n            old_combined = new_combined\n    if A_val == 0 and B_val == 1:\n        print('clock')\n    elif A_val == 1 and B_val == 0:\n        print('counter clock')\n    time.sleep(.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#the-rotary-class","title":"The Rotary Class","text":"

                                                                                                                                                                                                                                                                                                              Here is one rotary class:

                                                                                                                                                                                                                                                                                                              Mike Teachman Rotary Class. This is preferred since it does not call a slow scheduler within an interrupt.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#using-a-scheduler","title":"Using a Scheduler","text":"

                                                                                                                                                                                                                                                                                                              There is another class Gurgle Apps Rotary Encoder that uses a scheduler within an interrupt which is not a best practice. However, we can show how this does work work with the one she created. The numbers incremented, but they didn't decrement. I had to change the pins to use the PULL_DOWN settings in the init method.

                                                                                                                                                                                                                                                                                                              import machine\nimport utime as time\nfrom machine import Pin\nimport micropython\n\nclass Rotary:\n\n    ROT_CW = 1\n    ROT_CCW = 2\n    SW_PRESS = 4\n    SW_RELEASE = 8\n\n    def __init__(self,dt,clk,sw):\n        self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN)\n        self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN)\n        self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN)\n        self.last_status = (self.dt_pin.value() << 1) | self.clk_pin.value()\n        self.dt_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )\n        self.clk_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )\n        self.sw_pin.irq(handler=self.switch_detect, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )\n        self.handlers = []\n        self.last_button_status = self.sw_pin.value()\n\n    def rotary_change(self, pin):\n        new_status = (self.dt_pin.value() << 1) | self.clk_pin.value()\n        if new_status == self.last_status:\n            return\n        transition = (self.last_status << 2) | new_status\n        if transition == 0b1110:\n            micropython.schedule(self.call_handlers, Rotary.ROT_CW)\n        elif transition == 0b1101:\n            micropython.schedule(self.call_handlers, Rotary.ROT_CCW)\n        self.last_status = new_status\n\n    def switch_detect(self,pin):\n        if self.last_button_status == self.sw_pin.value():\n            return\n        self.last_button_status = self.sw_pin.value()\n        if self.sw_pin.value():\n            micropython.schedule(self.call_handlers, Rotary.SW_RELEASE)\n        else:\n            micropython.schedule(self.call_handlers, Rotary.SW_PRESS)\n\n    def add_handler(self, handler):\n        self.handlers.append(handler)\n\n    def call_handlers(self, type):\n        for handler in self.handlers:\n            handler(type)\n

                                                                                                                                                                                                                                                                                                              The following were the lines that I changed:

                                                                                                                                                                                                                                                                                                                  self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN)\n    self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN)\n    self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#testing-script","title":"Testing Script","text":"
                                                                                                                                                                                                                                                                                                              from rotary import Rotary\nimport utime as time\nfrom machine import Pin\n\n# GPIO Pins 16 and 17 are for the encoder pins. 22 is the button press switch.\nrotary = Rotary(16, 17, 22)\nval = 0\n\ndef rotary_changed(change):\n    global val\n    if change == Rotary.ROT_CW:\n        val = val + 1\n        print(val)\n    elif change == Rotary.ROT_CCW:\n        val = val - 1\n        print(val)\n    elif change == Rotary.SW_PRESS:\n        print('PRESS')\n    elif change == Rotary.SW_RELEASE:\n        print('RELEASE')\n\nrotary.add_handler(rotary_changed)\n\nwhile True:\n    time.sleep(0.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#adding-plot","title":"Adding Plot","text":"

                                                                                                                                                                                                                                                                                                              Now I can move the knob back and forth and get consistent values that go up and down. You can turn on the plot function of Thonny to see the values consistently go up and down.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#mysterious-runtime-error-on-scheduling-queue","title":"Mysterious Runtime Error on Scheduling Queue","text":"

                                                                                                                                                                                                                                                                                                              I did notice that the Shell output did register the following errors:

                                                                                                                                                                                                                                                                                                              Traceback (most recent call last):\n  File \"rotary.py\", line 30, in rotary_change\nRuntimeError: schedule queue full\n

                                                                                                                                                                                                                                                                                                              The error also occurred on line 32.

                                                                                                                                                                                                                                                                                                              The following lines generated this error:

                                                                                                                                                                                                                                                                                                              micropython.schedule(self.call_handlers, Rotary.ROT_CW)\nmicropython.schedule(self.call_handlers, Rotary.ROT_CCW)\n

                                                                                                                                                                                                                                                                                                              This error did not seem to impact the execution of the code. My suspicion is that this is a bug in the Micropython firmware.

                                                                                                                                                                                                                                                                                                              As a fix, you can use the try/except block an catch any runtime error. The pass function is a no-op (no operation)

                                                                                                                                                                                                                                                                                                                  def rotary_change(self, pin):\n        new_status = (self.dt_pin.value() << 1) | self.clk_pin.value()\n        if new_status == self.last_status:\n            return\n        transition = (self.last_status << 2) | new_status\n        try:\n            if transition == 0b1110:\n                micropython.schedule(self.call_handlers, Rotary.ROT_CW)\n            elif transition == 0b1101:\n                micropython.schedule(self.call_handlers, Rotary.ROT_CCW)\n        except RuntimeError:\n            pass\n        self.last_status = new_status\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/10-rotary-encoder/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Counter get stuck on \"schedule queue full\" - suggest using a try/catch
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/11-compass/","title":"MicroPython Compass Lab","text":"

                                                                                                                                                                                                                                                                                                              Digital Compass Lab Video

                                                                                                                                                                                                                                                                                                              This lab will use the popular HML5883L chip to show how we can sense a magnetic field and allow our robots to sense the direction they are going.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/11-compass/#about-the-hml5883l","title":"About the HML5883L","text":"

                                                                                                                                                                                                                                                                                                              The HMC5883L is a multi-chip module able to measure magnetic sensing. It can communicate with an I2C digital interface with other devices in order to let creating applications such as low-cost compass, being used in many electronic fields like mobile phones, netbooks, consumer electronics, auto navigation systems, and personal navigation devices.

                                                                                                                                                                                                                                                                                                              The module works with a low voltage supply (from 2.16 to 3.6V) and also has a low power consumption (100 \u03bcA).

                                                                                                                                                                                                                                                                                                              HMC5883L has a 1\u00b0 to 2\u00b0 degrees heading accuracy, which is enough for a wide number of applications. It also allows setting its internal gain to increase resolution with a 3-bit gain control register. But increasing gain also increases noise effects.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/11-compass/#pinout","title":"Pinout","text":"

                                                                                                                                                                                                                                                                                                              The HMC5883L pinout has 5 PINs:

                                                                                                                                                                                                                                                                                                              1. Vcc: Connect to the 3.3 volt rail of the breadboard or power supply
                                                                                                                                                                                                                                                                                                              2. GND: Ground
                                                                                                                                                                                                                                                                                                              3. SCL: I2C clock
                                                                                                                                                                                                                                                                                                              4. SDA: I2C data
                                                                                                                                                                                                                                                                                                              5. DRDY: Data ready. You can use this to be notified if new data is ready in memory. We will not use this pin in our labs. The
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/11-compass/#checking-i2c-connections","title":"Checking I2C Connections","text":"

                                                                                                                                                                                                                                                                                                              You can use a standard i2c-scanner program to verify that the four pins are connected correctly:

                                                                                                                                                                                                                                                                                                              import machine\n\n# Change this if you are using other ports\nI2C_SDA_PIN = 0\nI2C_SCL_PIN = 1\ni2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)\n\nprint('Scanning I2C bus.')\ndevices = i2c.scan() # this returns a list of devices\n\ndevice_count = len(devices)\n\nif device_count == 0:\n    print('No i2c device found.')\nelse:\n    print(device_count, 'devices found.')\n\nfor device in devices:\n    print('Decimal address:', device, \", Hex address: \", hex(device))\n

                                                                                                                                                                                                                                                                                                              For my system this returns the following report:

                                                                                                                                                                                                                                                                                                              Scanning I2C bus.\n1 devices found.\nDecimal address: 30 , Hex address:  0x1e\n

                                                                                                                                                                                                                                                                                                              You will notice that the scanner found a single device at hex address 0x1e.

                                                                                                                                                                                                                                                                                                              Like many sensors, this sensor uses a \"memory map\" to transmit it's data. You can write a quick test to verify that the values are changing by doing a read from this i2c address like this:

                                                                                                                                                                                                                                                                                                              data = array('B', [0] * 6)\nwhile True:\n    i2c.readfrom_mem_into(0x1e, 0x03, data)\n

                                                                                                                                                                                                                                                                                                              Here is a program that will display the raw values. You can rotate the sensor to verify the raw values are changing.

                                                                                                                                                                                                                                                                                                              from array import array\n# create an incomming data array of 6 bytes\nI2C_SDA_PIN = 0\nI2C_SCL_PIN = 1\ni2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)\ndata = array('B', [0] * 6)\nwhile True:\n    i2c.readfrom_mem_into(0x1e, 0x03, data)\n

                                                                                                                                                                                                                                                                                                              Note that these are \"raw\" values because they have not been converted to easy-to-understand values by the driver.

                                                                                                                                                                                                                                                                                                              from hmc5883l import HMC5883L\nfrom utime import sleep\n\nI2C_SDA_PIN = 0\nI2C_SCL_PIN = 1\n\n# i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)\n\n# The default address is address=0x1e\n\nsensor = HMC5883L(scl=I2C_SDA_PIN, sda=I2C_SCL_PIN)\n\nwhile True:\n    x, y, z = sensor.read()\n    # print(sensor.format_result(x, y, z))\n    if x <400:\n        print(x)\n    sleep(.1)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/11-compass/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. PPPPE80 Magnetometer Compass with Raspberry PI Pico: GY-271 HMC5883L wiring and use with MicroPython
                                                                                                                                                                                                                                                                                                              2. PPPPE80 driver
                                                                                                                                                                                                                                                                                                              3. Data Sheet
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/","title":"Avago APDS-9960 Gesture Sensor","text":"

                                                                                                                                                                                                                                                                                                              The APDS-9960 is an I2C device with advanced Gesture detection, Proximity detection, Digital Ambient Light Sense (ALS) and Color Sense (RGBC). It incorporates an IR LED and factory-calibrated LED driver.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#gesture-detection","title":"Gesture detection","text":"

                                                                                                                                                                                                                                                                                                              Gesture detection utilizes four directional photodiodes to sense reflected IR energy (sourced by the integrated LED) to convert physical motion information (i.e. velocity, direction and distance) to a digital information. The architecture of the gesture engine features automatic activation (based on Proximity engine results), ambient light subtraction, cross-talk cancelation, dual 8-bit data converters, power saving inter-conversion delay, 32-dataset FIFO, and interrupt driven I2C communication. The gesture engine accommodates a wide range of mobile device gesturing requirements: simple UP-DOWN-RIGHT-LEFT gestures or more complex gestures can be accurately sensed.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#code","title":"Code","text":"
                                                                                                                                                                                                                                                                                                              import machine\nfrom time import sleep_ms\nfrom uPy_APDS9960.apds9960LITE import APDS9960LITE\n\n#Init I2C Buss on RP2040\nsda=machine.Pin(12)\nscl=machine.Pin(13)\ni2c =  machine.I2C(0,scl=scl, sda=sda)\n\napds9960=APDS9960LITE(i2c)      # Enable sensor\napds9960.prox.enableSensor()    # Enable Proximit sensing\n\nwhile True:\n        sleep_ms(25) # wait for readout to be ready\n        print(apds9960.prox.proximityLevel)   #Print the proximity value\n

                                                                                                                                                                                                                                                                                                              Returns

                                                                                                                                                                                                                                                                                                              0 1 1 1 1 1 0 1 1 2 2 1 1 1 1 1 0 \n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#ambient-light","title":"Ambient Light","text":"
                                                                                                                                                                                                                                                                                                              # from https://github.com/rlangoy/uPy_APDS9960\nimport machine\nfrom time import sleep,sleep_ms\nfrom APDS9960LITE import APDS9960LITE\n\n#Init I2C Buss on RP2040\nsda=machine.Pin(12)\nscl=machine.Pin(13)\ni2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)\n\nprint(i2c)\n# create the driver\napds9960=APDS9960LITE(i2c)\napds9960.als.enableSensor()           # Enable Light sensor\nsleep_ms(25)                          # Wait for readout to be ready\n\n#apds9960.powerOn(True)\n#print(apds9960.statusRegister())\n\nwhile True:\n    print(apds9960.als.ambientLightLevel, ' ', end='')\n    sleep(.1)\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              1  1  0  0  0  0  0  0  0  0  1  1  1  4  8  10  10  10  12  16  17  19  19  20  21  21  22  25  27  30  33  35  36  37  38  33  33  34  34  34  34  34  35  36  36  38  39  40  38  37  38  40  42  45  48  49  55  61  66  73  76  76  82  93  109  132  156  169  171  173  173  171  164  160  169  165  162  162  164  163  159  158  152  148  148  145  141  135  122  106  96  101  108  89  62  48  33  20  10  5  3  1  0  0  0  0  0  0  0  1  2  4  8  14  26  45  65  91  110  121  124  127  132  150  191  225  244  244  254  288  295  243  219  259  299  287  204  99  31  10  2  1  1  1  0\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#reading-rgb","title":"Reading RGB","text":"
                                                                                                                                                                                                                                                                                                              while True:\n    print(apds9960.als.ambientLightLevel,'', end='')\n    print(apds9960.als.redLightLevel,'', end='')\n    print(apds9960.als.greenLightLevel,'', end='')\n    print(apds9960.als.blueLightLevel)\n    sleep(.1)\n
                                                                                                                                                                                                                                                                                                              1 0 0 0\n2 0 0 1\n4 1 0 1\n8 3 2 2\n17 6 5 5\n28 14 10 8\n38 19 12 11\n37 27 15 12\n38 30 15 12\n43 29 15 14\n35 22 11 11\n26 17 9 7\n18 12 6 5\n13 7 4 3\n9 4 3 2\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#rgb-display-graph","title":"RGB Display Graph","text":"

                                                                                                                                                                                                                                                                                                              This program displays the red, green and blue light values as bars on an OLED display.

                                                                                                                                                                                                                                                                                                              # from https://github.com/rlangoy/uPy_APDS9960\nfrom machine import Pin, I2C\nimport ssd1306\nfrom time import sleep,sleep_ms\nfrom APDS9960LITE import APDS9960LITE\n\n#Init I2C Buss on RP2040\nsda=Pin(12)\nscl=Pin(13)\ni2c=I2C(0, sda=sda, scl=scl, freq=400000)\n\nprint(i2c)\n# create the driver\napds9960=APDS9960LITE(i2c)\napds9960.als.enableSensor()           # Enable Light sensor\nsleep_ms(25)                          # Wait for readout to be ready\n\n# display\nWIDTH = 128\nONE_THIRD_WIDTH = int(WIDTH/3)\nHEIGHT = 64\nclock=Pin(2)\ndata=Pin(3)\nRES = machine.Pin(4)\nDC = machine.Pin(5)\nCS = machine.Pin(6)\nspi=machine.SPI(0, sck=clock, mosi=data)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\n\ndef update_display(red, green, blue):\n    oled.fill(0)\n    # scale red, green and blue to the height\n    red = int(red*4)\n    green = int(green*4)\n    blue = int(blue*3)\n\n    oled.fill(0)\n    # rect_fill(x, y, width, height)\n    oled.fill_rect(0, HEIGHT - red, ONE_THIRD_WIDTH, red, 1)\n    oled.fill_rect(ONE_THIRD_WIDTH, HEIGHT - green, ONE_THIRD_WIDTH, green, 1)\n    oled.fill_rect(ONE_THIRD_WIDTH * 2, HEIGHT - blue, ONE_THIRD_WIDTH, blue, 1)\n    oled.text(str(red), 0, 56, 0)\n    oled.text(str(green), ONE_THIRD_WIDTH, 56, 0)\n    oled.text(str(blue), ONE_THIRD_WIDTH*2, 56, 0)\n    oled.show()\n\nwhile True:\n    # print(apds9960.als.ambientLightLevel,'', end='')\n    red = apds9960.als.redLightLevel\n    green = apds9960.als.greenLightLevel\n    blue = apds9960.als.blueLightLevel\n    update_display(red, green, blue)\n    sleep(.05)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#references","title":"References","text":""},{"location":"sensors/13-gesture/#using-tinyml","title":"Using TinyML","text":"

                                                                                                                                                                                                                                                                                                              https://www.hackster.io/mjrobot/tinyml-motion-recognition-using-raspberry-pi-pico-6b6071?f=1

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#datasheet","title":"Datasheet","text":"

                                                                                                                                                                                                                                                                                                              https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/13-gesture/#other-references","title":"Other References","text":"

                                                                                                                                                                                                                                                                                                              https://robojax.com/learn/arduino/?vid=robojax-gesture-APDS9960

                                                                                                                                                                                                                                                                                                              https://upy-apds9960.readthedocs.io/en/latest/#

                                                                                                                                                                                                                                                                                                              https://www.youtube.com/watch?v=wH9HpP9bKwE

                                                                                                                                                                                                                                                                                                              https://github.com/rlangoy/uPy_APDS9960/blob/master/uPy_APDS9960/apds9960LITE.py

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/14-microphone/","title":"Microphone","text":""},{"location":"sensors/14-microphone/#basic-sound-sensor","title":"Basic Sound Sensor","text":"

                                                                                                                                                                                                                                                                                                              Pros:

                                                                                                                                                                                                                                                                                                              • low cost ($2 or less)
                                                                                                                                                                                                                                                                                                              • able to detect if sound is present and send a digital signal
                                                                                                                                                                                                                                                                                                              • adjustable trim pot to adjust sound level trigger level

                                                                                                                                                                                                                                                                                                              Cons:

                                                                                                                                                                                                                                                                                                              • low quality sound
                                                                                                                                                                                                                                                                                                              • sound impacted by noise on the power supply
                                                                                                                                                                                                                                                                                                              • limited frequency response
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/14-microphone/#inmp441","title":"INMP441","text":"

                                                                                                                                                                                                                                                                                                              Pros:

                                                                                                                                                                                                                                                                                                              • high quality sound
                                                                                                                                                                                                                                                                                                              • excellent frequency response
                                                                                                                                                                                                                                                                                                              • I2C interface
                                                                                                                                                                                                                                                                                                              • strong isolation from power supply noise

                                                                                                                                                                                                                                                                                                              Cons:

                                                                                                                                                                                                                                                                                                              • slightly higher cost ($4)
                                                                                                                                                                                                                                                                                                              • triggers must be written in software

                                                                                                                                                                                                                                                                                                              I2C Interface

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/14-microphone/#inmp441-24-bit-i2s-interface-omnidirectional-microphone-sensor-module","title":"INMP441 24-bit I2S Interface Omnidirectional Microphone Sensor Module","text":""},{"location":"sensors/14-microphone/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              • Sound Detector Board on eBay
                                                                                                                                                                                                                                                                                                              • YouTube Video Raspberry Pi Pico Audio Recorder with INMP441 - MCU Application Lab
                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/dht11-temp-humidity/","title":"The DHT22 (AM2302) Temperature and Humidity Sensor","text":"

                                                                                                                                                                                                                                                                                                              The DHT22 is a low-cost ($2) digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and transmits a digital signal on the data pin.

                                                                                                                                                                                                                                                                                                              These devices are easy to use since they have an internal analog to digital conversion. They are good for 20-80% humidity readings with 5% accuracy and 0-50\u00b0C temperature readings with \u00b12\u00b0C accuracy. They are designed to be polled about once every two seconds.

                                                                                                                                                                                                                                                                                                              "},{"location":"sensors/dht11-temp-humidity/#circuit","title":"Circuit","text":""},{"location":"sensors/dht11-temp-humidity/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              DHT22 Datasheet (PDF)

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/","title":"Simulators for Learning MicroPython","text":"
                                                                                                                                                                                                                                                                                                              • Knowledge Graph

                                                                                                                                                                                                                                                                                                              • Wokwi

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/breadboard/","title":"Breadboard Simulator","text":"

                                                                                                                                                                                                                                                                                                              Breadboard Simulator Over Image - simulator written in P5.js

                                                                                                                                                                                                                                                                                                              Vector Breadboard With Zoom

                                                                                                                                                                                                                                                                                                              Vector Drawn Breadboard Simulator

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/","title":"Knowledge Graphs","text":""},{"location":"sims/knowledge-graphs/#prompt-engineering","title":"Prompt Engineering","text":"
                                                                                                                                                                                                                                                                                                              • Concept Enumeration
                                                                                                                                                                                                                                                                                                              • Concept Dependency
                                                                                                                                                                                                                                                                                                              • Concept Taxonomy
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/#demo-graphs","title":"Demo Graphs","text":"
                                                                                                                                                                                                                                                                                                              • Dependency Graph
                                                                                                                                                                                                                                                                                                              • Taxonomy Colored Dependency Graph
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-dependency/","title":"Concept Dependency","text":""},{"location":"sims/knowledge-graphs/concept-dependency/#prompt","title":"Prompt","text":"
                                                                                                                                                                                                                                                                                                              Our next step is to create a fully connected dependency graph.\nIn this step, for each line or concept on this list, \nplease create a new list of other concepts on which it depends.\nIf a concept depends on a specific concept that is not listed,\nthen we must add it as a new concept.\nThis will help us determine the teaching order of the concepts.\n\nReturn the new list as a CSV file using the following format:\n\nThe first column is a numeric concept ID you assigned,  \nthe second column is the concept name,\nand the third column is a pipe-delimited list of the concept IDs\nthat the concept depends upon.\n\nCheck your results to make sure that all concepts are\nconnected to at least one other concept.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-dependency/#response","title":"Response","text":"

                                                                                                                                                                                                                                                                                                              ChatGPT o1-mini Thought for 53 seconds

                                                                                                                                                                                                                                                                                                              Here is the CSV file containing the concepts along with their dependencies:

                                                                                                                                                                                                                                                                                                              ID,Concept Name,Dependencies (IDs)\n1,Intro to Computational Thinking,\n2,Problem Decomposition,1\n3,Pattern Recognition,1\n4,Abstraction,1\n5,Algorithm Design,1|2|3|4\n6,Basic Programming Concepts,1|5\n7,Variables in Programming,6\n8,Data Types in Programming,6|7\n9,Operators,6|7|8\n10,Control Structures,6|7|8|9\n11,Conditional Statements,10|9\n12,Loops,10\n13,General Functions in Programming,6|7|8|10\n14,Introduction to MicroPython,6\n15,Setting Up MicroPython Environment,14\n16,Syntax in MicroPython,14|15\n17,Functions in MicroPython,13|16\n18,Modules in MicroPython,16|17\n19,Input and Output,16|7|8\n20,Working with Strings,8|16\n21,Working with Numbers,8|16\n22,Lists,8|16\n23,Tuples,8|16\n24,Dictionaries,8|16\n25,Exception Handling,16|10\n26,Microcontroller Basics,\n27,The Raspberry Pi Pico,26\n28,Understanding GPIO Pins,26|27\n29,Solderless Breadboards,32\n30,Breadboard Usage,29|32\n31,Circuit Basics,\n32,Ohm's Law,31\n33,Resistors in Circuits,31|32\n34,LEDs in Circuits,31\n35,Using Resistors with LEDs,33|34|32\n36,Current Limiting Resistors,33|35\n37,Connecting LEDs,34|30\n38,Blinking an LED with MicroPython,37|16|28\n39,Digital Output Signals,28|16\n40,Digital Input Signals,28|16\n41,Reading Button Inputs,40|30\n42,Debouncing Switches,41|10\n43,Pull-up and Pull-down Resistors,33|41\n44,Controlling Multiple LEDs,37|38|16\n45,Using Breadboard Jumpers,30\n46,Potentiometers in Circuits,31|33\n47,Reading Analog Inputs,46|28\n48,Analog-to-Digital Conversion,47\n49,Using ADC in MicroPython,48|16\n50,Reading Potentiometer Values,49|46\n51,Pulse Width Modulation Fundamentals,6|10\n52,Implementing Pulse Width Modulation in MicroPython,51|16\n53,LED Brightness Control with Pulse Width Modulation,52|37\n54,Fading LEDs Using Pulse Width Modulation,53|12\n55,Advanced Pulse Width Modulation Techniques,54|52\n56,Servo Motors Overview,31\n57,Controlling Servo Motors,52|28|56\n58,DC Motors Overview,31\n59,Transistors as Switches,31|33\n60,Controlling Motors with Transistors,59|58\n61,Transistor Biasing Resistors,59|33\n62,Power Management with Transistors,59|61\n63,Photocells,31|33\n64,Making a Night Light,63|28|16\n65,Voltage Dividers,33|31\n66,Voltage Dividers and Sensors,65|63\n67,Time-of-Flight Sensors,31|28\n68,Interfacing Time-of-Flight Sensors,67|16\n69,I2C Protocol,70|16\n70,SPI Protocol,28|16\n71,Connecting I2C Devices,69|28\n72,LED Displays Overview,34|31\n73,Organic Light-Emitting Diode Displays,72\n74,Display Drawing,73|16\n75,Drawing Circles and Ellipses,74\n76,Drawing Polygons,74\n77,Changing Fonts,74\n78,Advanced I2C,69|16\n79,Advanced SPI,70|16\n80,WS2812B LED Strips,34|31\n81,LED Strip Code,80|16\n82,Moving Pixels on LED Strips,81|12\n83,LED Strip Patterns,81|82\n84,LED Strip Button Demos,83|41\n85,Sensors and Actuators,31|28\n86,Integrating Multiple Sensors,85|16\n87,Event-Driven Programming,6|10\n88,Interrupts,28|87\n89,Using Interrupts with GPIO Pins,88|28\n90,Debouncing with Interrupts,89|42\n91,Timers,6|16\n92,Delays and Timing Functions,91|16\n93,Using the Time Module,92|16\n94,Data Logging with MicroPython,16|97\n95,Storing Data on Raspberry Pi Pico,94|27\n96,File Handling,16|95\n97,Universal Serial Bus Communication,27|16\n98,Universal Asynchronous Receiver-Transmitter Communication,27|16\n99,Introduction to Sensors,31\n100,Temperature Sensors,99|28\n101,Interfacing Temperature Sensors,100|16\n102,Humidity Sensors,99|28\n103,Using DHT11 and DHT22 Sensors,101|102\n104,Reading Sensor Data,103|16\n105,Interpreting Sensor Data,104\n106,Calibrating Sensors,105\n107,Introduction to Actuators,31\n108,Controlling Relays,107|16\n109,Relays Overview,107\n110,Relays Safety,109\n111,Stepper Motors,31\n112,Controlling Stepper Motors,111|16\n113,Using Stepper Motor Drivers,112|28\n114,Generating Sound with Buzzers,31|28\n115,Using Piezoelectric Buzzers,114|16\n116,Generating Tones and Melodies,115|12\n117,Infrared Communication,28|16\n118,Using Infrared Sensors,117|31\n119,Infrared Remote Control,118|16\n120,Ultrasonic Sensors,99|28\n121,Serial Communication Protocols,27|16\n122,I2C vs SPI vs UART,69|70|98\n123,Data Communication Principles,121\n124,Wireless Communication Basics,123\n125,Bluetooth Low Energy,124|27\n126,Wi-Fi Connectivity,124|27\n127,Python Modules Overview,16\n128,Internet of Things Concepts,124|27\n129,Connecting to the Internet,126|16\n130,Sending Data to Web Servers,129|16\n131,Hypertext Transfer Protocol Basics,130\n132,Message Queuing Telemetry Transport Protocol,130\n133,IoT Applications,128|130\n134,Cloud Services Integration,133\n135,Data Visualization Tools,134\n136,Programming Best Practices,6\n137,Code Optimization Techniques,136\n138,Debugging Techniques,16|136\n139,Using Debugging Tools,138\n140,Version Control Systems,6\n141,Using Git for Code Management,140\n142,Collaborative Coding Practices,141\n143,Documentation Standards,136\n144,Commenting Code Effectively,136\n145,Advanced MicroPython Features,16\n146,Object-Oriented Programming,6|136\n147,Classes and Objects,146\n148,Inheritance and Polymorphism,147\n149,Encapsulation in Object-Oriented Programming,147\n150,Designing Reusable Code,146|149\n151,Memory Management,16|136\n152,Managing Resources Efficiently,151\n153,Energy Efficiency in Programming,152\n154,Sleep Modes in Microcontrollers,153|27\n155,Battery-Powered Projects,154\n156,Power Management Techniques,155\n157,Advanced Electronics Concepts,31\n158,Capacitors in Circuits,157\n159,Inductors and Coils,157\n160,Diodes and Rectification,157\n161,Voltage Regulation,160\n162,Using Voltage Regulators,161\n163,Building Power Supplies,162\n164,Analog Signals vs Digital Signals,31|157\n165,Signal Conditioning,164|157\n166,Filtering Noise in Circuits,165\n167,Interference and Shielding,166\n168,Electromagnetic Compatibility,167\n169,Circuit Design Principles,157\n170,Using Simulation Tools,169\n171,Prototyping Techniques,169\n172,Schematic Diagram Reading,169\n173,Understanding Datasheets,169\n174,Component Specifications,173\n175,Safety in Electronics,157\n176,Electrostatic Discharge Precautions,175\n177,Soldering Techniques,175\n178,Printed Circuit Board Design,169\n179,Using PCB Design Software,178\n180,Fabricating Custom PCBs,179\n181,Advanced Sensor Integration,85|157\n182,Gesture Recognition Sensors,181|28\n183,Touch Sensors,181|28\n184,Environmental Monitoring,181|105\n185,Robotics Basics,31|157\n186,Building Simple Robots,185|16\n187,Line-Following Robots,186|83\n188,Obstacle Avoidance Robots,186|120\n189,Control Systems Basics,185\n190,Feedback Mechanisms,189\n191,Proportional-Integral-Derivative Controllers,190\n192,Machine Learning Concepts,6|136\n193,Using MicroPython for Artificial Intelligence,192|16\n194,Edge Computing,193|128\n195,Ethics in Technology,6\n196,Future Trends in Computing,195\n

                                                                                                                                                                                                                                                                                                              Notes:

                                                                                                                                                                                                                                                                                                              • Added Concepts: No additional concepts were required as dependencies were within the provided list.
                                                                                                                                                                                                                                                                                                              • Connectivity Check: All concepts are connected to at least one other concept through dependencies.
                                                                                                                                                                                                                                                                                                              • Formatting: The dependencies are listed using concept IDs, separated by a pipe (|) as per your instructions.
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-dependency/#explanation-of-dependencies-for-selected-concepts","title":"Explanation of Dependencies for Selected Concepts","text":"
                                                                                                                                                                                                                                                                                                              • Concept 1: Intro to Computational Thinking

                                                                                                                                                                                                                                                                                                                • Dependencies: None (foundational concept).
                                                                                                                                                                                                                                                                                                                • Concept 26: Microcontroller Basics

                                                                                                                                                                                                                                                                                                                • Dependencies: None (introduces the hardware aspect).

                                                                                                                                                                                                                                                                                                                • Concept 27: The Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                                • Dependencies: Depends on Microcontroller Basics (26) for understanding microcontrollers.

                                                                                                                                                                                                                                                                                                                • Concept 38: Blinking an LED with MicroPython

                                                                                                                                                                                                                                                                                                                • Dependencies: Connecting LEDs (37), Syntax in MicroPython (16), Understanding GPIO Pins (28).

                                                                                                                                                                                                                                                                                                                • Concept 57: Controlling Servo Motors

                                                                                                                                                                                                                                                                                                                • Dependencies: Implementing PWM in MicroPython (52), Understanding GPIO Pins (28), Servo Motors Overview (56).

                                                                                                                                                                                                                                                                                                                • Concept 95: Storing Data on Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                                • Dependencies: Data Logging with MicroPython (94), The Raspberry Pi Pico (27).

                                                                                                                                                                                                                                                                                                                • Concept 128: Internet of Things Concepts

                                                                                                                                                                                                                                                                                                                • Dependencies: Wireless Communication Basics (124), The Raspberry Pi Pico (27).

                                                                                                                                                                                                                                                                                                                • Concept 193: Using MicroPython for Artificial Intelligence

                                                                                                                                                                                                                                                                                                                • Dependencies: Machine Learning Concepts (192), Syntax in MicroPython (16).

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-dependency/#final-remarks","title":"Final Remarks","text":"
                                                                                                                                                                                                                                                                                                              • The dependencies are designed to ensure that each concept builds upon the necessary foundational knowledge.
                                                                                                                                                                                                                                                                                                              • This structure will aid in determining an effective teaching order for the course, ensuring that students have the requisite background before approaching more advanced topics.
                                                                                                                                                                                                                                                                                                              • By maintaining clear dependencies, the course can be structured to enhance learning progression and retention.
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-enumeration/","title":"Learning Concept Enumeration","text":""},{"location":"sims/knowledge-graphs/concept-enumeration/#prompt","title":"Prompt","text":"

                                                                                                                                                                                                                                                                                                              ```linenums=\"0\" Raspberry Pi Pico, and solderless breadboards. In our labs, we also use many parts such as photosensors, potentiometers, LEDs, resistors, transistors, time-0f-flight sensors, WS2812B LED strips, 128x64 OLED displays, motors, and the Cytron Maker Pi RP2040, which has the same RP2040 microcontroller.

                                                                                                                                                                                                                                                                                                              We have a lot of material and lesson plans right now, but I would like an overall list of the 200 key concepts we need to cover in this course.

                                                                                                                                                                                                                                                                                                              For this course, please create a list of the core learning concepts that we need to present in this course and the order in which they should be taught.

                                                                                                                                                                                                                                                                                                              Please create a list of the 200 most essential concepts in this course. Return the concept's preferred label in a numbered list for each learning concept. Make sure that the concept names are distinct and not synonyms. Don't repeat

                                                                                                                                                                                                                                                                                                              Start with the most basic foundational concepts and then proceed to the most complex concepts. Return just one concept label per line. Avoid using acronyms or abbreviations.

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-enumeration/#response","title":"Response","text":"

                                                                                                                                                                                                                                                                                                              ChatGPT o1-preview Thought for 22 seconds

                                                                                                                                                                                                                                                                                                              1. Intro to Computational Thinking
                                                                                                                                                                                                                                                                                                              2. Problem Decomposition
                                                                                                                                                                                                                                                                                                              3. Pattern Recognition
                                                                                                                                                                                                                                                                                                              4. Abstraction
                                                                                                                                                                                                                                                                                                              5. Algorithm Design
                                                                                                                                                                                                                                                                                                              6. Basic Programming Concepts
                                                                                                                                                                                                                                                                                                              7. Variables
                                                                                                                                                                                                                                                                                                              8. Data Types
                                                                                                                                                                                                                                                                                                              9. Operators
                                                                                                                                                                                                                                                                                                              10. Control Structures
                                                                                                                                                                                                                                                                                                              11. Conditional Statements
                                                                                                                                                                                                                                                                                                              12. Loops
                                                                                                                                                                                                                                                                                                              13. Functions
                                                                                                                                                                                                                                                                                                              14. Introduction to MicroPython
                                                                                                                                                                                                                                                                                                              15. Setting Up MicroPython Environment
                                                                                                                                                                                                                                                                                                              16. Syntax
                                                                                                                                                                                                                                                                                                              17. Variables
                                                                                                                                                                                                                                                                                                              18. Data Types
                                                                                                                                                                                                                                                                                                              19. Input and Output
                                                                                                                                                                                                                                                                                                              20. Working with Strings
                                                                                                                                                                                                                                                                                                              21. Working with Numbers
                                                                                                                                                                                                                                                                                                              22. Lists
                                                                                                                                                                                                                                                                                                              23. Tuples
                                                                                                                                                                                                                                                                                                              24. Dictionaries
                                                                                                                                                                                                                                                                                                              25. Functions
                                                                                                                                                                                                                                                                                                              26. Modules
                                                                                                                                                                                                                                                                                                              27. Exception Handling
                                                                                                                                                                                                                                                                                                              28. The Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              29. The Thonny IDE
                                                                                                                                                                                                                                                                                                              30. Microcontroller Basics
                                                                                                                                                                                                                                                                                                              31. Understanding GPIO Pins
                                                                                                                                                                                                                                                                                                              32. Solderless Breadboards
                                                                                                                                                                                                                                                                                                              33. Breadboard Usage
                                                                                                                                                                                                                                                                                                              34. Circuit Basics
                                                                                                                                                                                                                                                                                                              35. Ohm's Law
                                                                                                                                                                                                                                                                                                              36. Resistors in Circuits
                                                                                                                                                                                                                                                                                                              37. LEDs in Circuits
                                                                                                                                                                                                                                                                                                              38. Using Resistors with LEDs
                                                                                                                                                                                                                                                                                                              39. Current Limiting Resistors
                                                                                                                                                                                                                                                                                                              40. Connecting LEDs
                                                                                                                                                                                                                                                                                                              41. Blinking an LED with MicroPython
                                                                                                                                                                                                                                                                                                              42. Digital Output Signals
                                                                                                                                                                                                                                                                                                              43. Digital Input Signals
                                                                                                                                                                                                                                                                                                              44. Reading Button Inputs
                                                                                                                                                                                                                                                                                                              45. Debouncing Switches
                                                                                                                                                                                                                                                                                                              46. Pull-up and Pull-down Resistors
                                                                                                                                                                                                                                                                                                              47. Controlling Multiple LEDs
                                                                                                                                                                                                                                                                                                              48. Using Breadboard Jumpers
                                                                                                                                                                                                                                                                                                              49. Potentiometers in Circuits
                                                                                                                                                                                                                                                                                                              50. Reading Analog Inputs
                                                                                                                                                                                                                                                                                                              51. Analog-to-Digital Conversion
                                                                                                                                                                                                                                                                                                              52. Using ADC
                                                                                                                                                                                                                                                                                                              53. Reading Potentiometer Values
                                                                                                                                                                                                                                                                                                              54. LED Brightness with PWM
                                                                                                                                                                                                                                                                                                              55. Pulse Width Modulation
                                                                                                                                                                                                                                                                                                              56. Using Pulse Width Modulation
                                                                                                                                                                                                                                                                                                              57. Fading an LED with PWM
                                                                                                                                                                                                                                                                                                              58. Controlling Servo Motors
                                                                                                                                                                                                                                                                                                              59. Servo Motors
                                                                                                                                                                                                                                                                                                              60. DC Motors
                                                                                                                                                                                                                                                                                                              61. Transistors as Switches
                                                                                                                                                                                                                                                                                                              62. Transistors Motors Control
                                                                                                                                                                                                                                                                                                              63. Transistor Bias Resistors
                                                                                                                                                                                                                                                                                                              64. Transistors Power
                                                                                                                                                                                                                                                                                                              65. Photocells
                                                                                                                                                                                                                                                                                                              66. Making a Night Light
                                                                                                                                                                                                                                                                                                              67. Voltage Dividers
                                                                                                                                                                                                                                                                                                              68. Voltage Dividers and Sensors
                                                                                                                                                                                                                                                                                                              69. Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                              70. Interfacing Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                              71. I2C Protocol
                                                                                                                                                                                                                                                                                                              72. SPI Protocol
                                                                                                                                                                                                                                                                                                              73. Connecting Inter-Integrated Circuit Devices
                                                                                                                                                                                                                                                                                                              74. LED Displays
                                                                                                                                                                                                                                                                                                              75. OLED Displays
                                                                                                                                                                                                                                                                                                              76. Display Drawing
                                                                                                                                                                                                                                                                                                              77. Drawing Circles and Ellipse
                                                                                                                                                                                                                                                                                                              78. Drawing Polygons
                                                                                                                                                                                                                                                                                                              79. Changing Fonts
                                                                                                                                                                                                                                                                                                              80. Advanced I2C
                                                                                                                                                                                                                                                                                                              81. Advanced SPI
                                                                                                                                                                                                                                                                                                              82. WS2812B LED Strips
                                                                                                                                                                                                                                                                                                              83. LED Strip Code
                                                                                                                                                                                                                                                                                                              84. Moving Pixels on LED Strips
                                                                                                                                                                                                                                                                                                              85. LED Strip Patterns
                                                                                                                                                                                                                                                                                                              86. LED Strip Button Demos
                                                                                                                                                                                                                                                                                                              87. Sensors and Actuators
                                                                                                                                                                                                                                                                                                              88. Integrating Multiple Sensors
                                                                                                                                                                                                                                                                                                              89. Event-Driven Programming
                                                                                                                                                                                                                                                                                                              90. Interrupts
                                                                                                                                                                                                                                                                                                              91. Using Interrupts with GPIO Pins
                                                                                                                                                                                                                                                                                                              92. Debouncing with Interrupts
                                                                                                                                                                                                                                                                                                              93. Timers
                                                                                                                                                                                                                                                                                                              94. Delays and Timing Functions
                                                                                                                                                                                                                                                                                                              95. Using the Time Module
                                                                                                                                                                                                                                                                                                              96. Data Logging with MicroPython
                                                                                                                                                                                                                                                                                                              97. Storing Data on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              98. File Handling
                                                                                                                                                                                                                                                                                                              99. USB
                                                                                                                                                                                                                                                                                                              100. UART
                                                                                                                                                                                                                                                                                                              101. Introduction to Sensors
                                                                                                                                                                                                                                                                                                              102. Temperature Sensors
                                                                                                                                                                                                                                                                                                              103. Interfacing Temperature Sensors
                                                                                                                                                                                                                                                                                                              104. Humidity Sensors
                                                                                                                                                                                                                                                                                                              105. Using DHT11 and DHT22 Sensors
                                                                                                                                                                                                                                                                                                              106. Reading Sensor Data
                                                                                                                                                                                                                                                                                                              107. Interpreting Sensor Data
                                                                                                                                                                                                                                                                                                              108. Calibrating Sensors
                                                                                                                                                                                                                                                                                                              109. Introduction to Actuators
                                                                                                                                                                                                                                                                                                              110. Controlling Relays
                                                                                                                                                                                                                                                                                                              111. Relays
                                                                                                                                                                                                                                                                                                              112. Relays Safety
                                                                                                                                                                                                                                                                                                              113. Stepper Motors
                                                                                                                                                                                                                                                                                                              114. Controlling Stepper Motors
                                                                                                                                                                                                                                                                                                              115. Using Stepper Motor Drivers
                                                                                                                                                                                                                                                                                                              116. Advanced PWM
                                                                                                                                                                                                                                                                                                              117. Generating Sound with Buzzers
                                                                                                                                                                                                                                                                                                              118. Using Piezoelectric Buzzers
                                                                                                                                                                                                                                                                                                              119. Generating Tones and Melodies
                                                                                                                                                                                                                                                                                                              120. Infrared Communication
                                                                                                                                                                                                                                                                                                              121. Using Infrared Sensors
                                                                                                                                                                                                                                                                                                              122. Infrared Remote Control
                                                                                                                                                                                                                                                                                                              123. Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                              124. Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                              125. Serial Communication Protocols
                                                                                                                                                                                                                                                                                                              126. I2C vs SPI vs UART
                                                                                                                                                                                                                                                                                                              127. Data Communication Principles
                                                                                                                                                                                                                                                                                                              128. Wireless Communication Basics
                                                                                                                                                                                                                                                                                                              129. Bluetooth Low Energy
                                                                                                                                                                                                                                                                                                              130. Wi-Fi Connectivity
                                                                                                                                                                                                                                                                                                              131. Python Modules
                                                                                                                                                                                                                                                                                                              132. IoT
                                                                                                                                                                                                                                                                                                              133. Connecting to the Internet
                                                                                                                                                                                                                                                                                                              134. Sending Data to Web Servers
                                                                                                                                                                                                                                                                                                              135. Hypertext Transfer Protocol Basics
                                                                                                                                                                                                                                                                                                              136. MQTT
                                                                                                                                                                                                                                                                                                              137. IoT Applications
                                                                                                                                                                                                                                                                                                              138. Cloud Services Integration
                                                                                                                                                                                                                                                                                                              139. Data Visualization Tools
                                                                                                                                                                                                                                                                                                              140. Programming Best Practices
                                                                                                                                                                                                                                                                                                              141. Code Optimization Techniques
                                                                                                                                                                                                                                                                                                              142. Debugging Techniques
                                                                                                                                                                                                                                                                                                              143. Using Debugging Tools
                                                                                                                                                                                                                                                                                                              144. Version Control Systems
                                                                                                                                                                                                                                                                                                              145. Using Git for Code Management
                                                                                                                                                                                                                                                                                                              146. Collaborative Coding Practices
                                                                                                                                                                                                                                                                                                              147. Documentation Standards
                                                                                                                                                                                                                                                                                                              148. Commenting Code Effectively
                                                                                                                                                                                                                                                                                                              149. Advanced MicroPython Features
                                                                                                                                                                                                                                                                                                              150. Object-Oriented Programming
                                                                                                                                                                                                                                                                                                              151. Classes and Objects
                                                                                                                                                                                                                                                                                                              152. Inheritance and Polymorphism
                                                                                                                                                                                                                                                                                                              153. Encapsulation in OOP
                                                                                                                                                                                                                                                                                                              154. Designing Reusable Code
                                                                                                                                                                                                                                                                                                              155. Memory Management
                                                                                                                                                                                                                                                                                                              156. Managing Resources Efficiently
                                                                                                                                                                                                                                                                                                              157. Energy Efficiency
                                                                                                                                                                                                                                                                                                              158. Sleep Modes in Microcontrollers
                                                                                                                                                                                                                                                                                                              159. Battery-Powered Projects
                                                                                                                                                                                                                                                                                                              160. Power Management Techniques
                                                                                                                                                                                                                                                                                                              161. Advanced Electronics Concepts
                                                                                                                                                                                                                                                                                                              162. Capacitors in Circuits
                                                                                                                                                                                                                                                                                                              163. Inductors and Coils
                                                                                                                                                                                                                                                                                                              164. Diodes and Rectification
                                                                                                                                                                                                                                                                                                              165. Voltage Regulation
                                                                                                                                                                                                                                                                                                              166. Using Voltage Regulators
                                                                                                                                                                                                                                                                                                              167. Building Power Supplies
                                                                                                                                                                                                                                                                                                              168. Analog Signals vs. Digital Signals
                                                                                                                                                                                                                                                                                                              169. Signal Conditioning
                                                                                                                                                                                                                                                                                                              170. Filtering Noise in Circuits
                                                                                                                                                                                                                                                                                                              171. Interference and Shielding
                                                                                                                                                                                                                                                                                                              172. Electromagnetic Compatibility
                                                                                                                                                                                                                                                                                                              173. Circuit Design Principles
                                                                                                                                                                                                                                                                                                              174. Using Simulation Tools
                                                                                                                                                                                                                                                                                                              175. Prototyping Techniques
                                                                                                                                                                                                                                                                                                              176. Schematic Diagram Reading
                                                                                                                                                                                                                                                                                                              177. Understanding Datasheets
                                                                                                                                                                                                                                                                                                              178. Component Specifications
                                                                                                                                                                                                                                                                                                              179. Safety in Electronics
                                                                                                                                                                                                                                                                                                              180. Electrostatic Discharge Precautions
                                                                                                                                                                                                                                                                                                              181. Soldering Techniques
                                                                                                                                                                                                                                                                                                              182. Printed Circuit Board Design
                                                                                                                                                                                                                                                                                                              183. Using PCB Design Software
                                                                                                                                                                                                                                                                                                              184. Fabricating Custom PCB
                                                                                                                                                                                                                                                                                                              185. Advanced Sensor Integration
                                                                                                                                                                                                                                                                                                              186. Gesture Recognition Sensors
                                                                                                                                                                                                                                                                                                              187. Touch Sensors
                                                                                                                                                                                                                                                                                                              188. Environmental Monitoring
                                                                                                                                                                                                                                                                                                              189. Robotics Basics
                                                                                                                                                                                                                                                                                                              190. Building Simple Robots
                                                                                                                                                                                                                                                                                                              191. Line-Following Robots
                                                                                                                                                                                                                                                                                                              192. Obstacle Avoidance Robots
                                                                                                                                                                                                                                                                                                              193. Control Systems Basics
                                                                                                                                                                                                                                                                                                              194. Feedback Mechanisms
                                                                                                                                                                                                                                                                                                              195. PID Controllers
                                                                                                                                                                                                                                                                                                              196. Machine Learning Concepts
                                                                                                                                                                                                                                                                                                              197. Using MicroPython for AI
                                                                                                                                                                                                                                                                                                              198. Edge Computing
                                                                                                                                                                                                                                                                                                              199. Ethics in Technology
                                                                                                                                                                                                                                                                                                              200. Future Trends in Computing
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-enumeration/#original-list","title":"Original List","text":"
                                                                                                                                                                                                                                                                                                              • Introduction to Computational Thinking
                                                                                                                                                                                                                                                                                                              • Problem Decomposition
                                                                                                                                                                                                                                                                                                              • Pattern Recognition
                                                                                                                                                                                                                                                                                                              • Abstraction
                                                                                                                                                                                                                                                                                                              • Algorithm Design
                                                                                                                                                                                                                                                                                                              • Basic Programming Concepts
                                                                                                                                                                                                                                                                                                              • Variables in Programming
                                                                                                                                                                                                                                                                                                              • Data Types in Programming
                                                                                                                                                                                                                                                                                                              • Operators in Programming
                                                                                                                                                                                                                                                                                                              • Control Structures in Programming
                                                                                                                                                                                                                                                                                                              • Conditional Statements
                                                                                                                                                                                                                                                                                                              • Loops in Programming
                                                                                                                                                                                                                                                                                                              • Functions in Programming
                                                                                                                                                                                                                                                                                                              • Introduction to MicroPython
                                                                                                                                                                                                                                                                                                              • Setting Up MicroPython Environment
                                                                                                                                                                                                                                                                                                              • Syntax in MicroPython
                                                                                                                                                                                                                                                                                                              • Variables in MicroPython
                                                                                                                                                                                                                                                                                                              • Data Types in MicroPython
                                                                                                                                                                                                                                                                                                              • Input and Output in MicroPython
                                                                                                                                                                                                                                                                                                              • Working with Strings in MicroPython
                                                                                                                                                                                                                                                                                                              • Working with Numbers in MicroPython
                                                                                                                                                                                                                                                                                                              • Lists in MicroPython
                                                                                                                                                                                                                                                                                                              • Tuples in MicroPython
                                                                                                                                                                                                                                                                                                              • Dictionaries in MicroPython
                                                                                                                                                                                                                                                                                                              • Functions in MicroPython
                                                                                                                                                                                                                                                                                                              • Modules in MicroPython
                                                                                                                                                                                                                                                                                                              • Exception Handling in MicroPython
                                                                                                                                                                                                                                                                                                              • Introduction to Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Setting Up Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Microcontroller Basics
                                                                                                                                                                                                                                                                                                              • Understanding GPIO Pins
                                                                                                                                                                                                                                                                                                              • Breadboard Basics
                                                                                                                                                                                                                                                                                                              • Solderless Breadboard Usage
                                                                                                                                                                                                                                                                                                              • Circuit Basics
                                                                                                                                                                                                                                                                                                              • Ohm's Law
                                                                                                                                                                                                                                                                                                              • Resistors in Circuits
                                                                                                                                                                                                                                                                                                              • LEDs in Circuits
                                                                                                                                                                                                                                                                                                              • Using Resistors with LEDs
                                                                                                                                                                                                                                                                                                              • Current Limiting Resistors
                                                                                                                                                                                                                                                                                                              • Connecting LEDs to Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Blinking an LED with MicroPython
                                                                                                                                                                                                                                                                                                              • Digital Output Signals
                                                                                                                                                                                                                                                                                                              • Digital Input Signals
                                                                                                                                                                                                                                                                                                              • Reading Button Inputs
                                                                                                                                                                                                                                                                                                              • Debouncing Switches
                                                                                                                                                                                                                                                                                                              • Pull-up and Pull-down Resistors
                                                                                                                                                                                                                                                                                                              • Controlling Multiple LEDs
                                                                                                                                                                                                                                                                                                              • Using Breadboard Jumpers
                                                                                                                                                                                                                                                                                                              • Potentiometers in Circuits
                                                                                                                                                                                                                                                                                                              • Reading Analog Inputs
                                                                                                                                                                                                                                                                                                              • Analog-to-Digital Conversion
                                                                                                                                                                                                                                                                                                              • Using the ADC on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Reading Potentiometer Values
                                                                                                                                                                                                                                                                                                              • Controlling LED Brightness with Pulse Width Modulation
                                                                                                                                                                                                                                                                                                              • Pulse Width Modulation
                                                                                                                                                                                                                                                                                                              • Using Pulse Width Modulation in MicroPython
                                                                                                                                                                                                                                                                                                              • Fading an LED with Pulse Width Modulation
                                                                                                                                                                                                                                                                                                              • Controlling Servo Motors
                                                                                                                                                                                                                                                                                                              • Using Servo Motors with Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Interfacing Direct Current Motors
                                                                                                                                                                                                                                                                                                              • Transistors as Switches
                                                                                                                                                                                                                                                                                                              • Using Transistors to Control Motors
                                                                                                                                                                                                                                                                                                              • Understanding NPN Transistors
                                                                                                                                                                                                                                                                                                              • Understanding PNP Transistors
                                                                                                                                                                                                                                                                                                              • Using Photocells in Circuits
                                                                                                                                                                                                                                                                                                              • Reading Light Levels with Photocells
                                                                                                                                                                                                                                                                                                              • Voltage Dividers
                                                                                                                                                                                                                                                                                                              • Using Voltage Dividers with Sensors
                                                                                                                                                                                                                                                                                                              • Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                              • Interfacing Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                              • Inter-Integrated Circuit Communication Protocol
                                                                                                                                                                                                                                                                                                              • Using Inter-Integrated Circuit in MicroPython
                                                                                                                                                                                                                                                                                                              • Connecting Inter-Integrated Circuit Devices
                                                                                                                                                                                                                                                                                                              • Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                              • Using 128x64 Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                              • Displaying Text on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                              • Displaying Graphics on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                              • Understanding Display Coordinates
                                                                                                                                                                                                                                                                                                              • Using Fonts on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                              • Serial Peripheral Interface Communication Protocol
                                                                                                                                                                                                                                                                                                              • Using Serial Peripheral Interface in MicroPython
                                                                                                                                                                                                                                                                                                              • WS2812B Light-Emitting Diode Strips
                                                                                                                                                                                                                                                                                                              • Controlling WS2812B Light-Emitting Diodes
                                                                                                                                                                                                                                                                                                              • Using Neopixel Library
                                                                                                                                                                                                                                                                                                              • Creating Color Effects on WS2812B Light-Emitting Diodes
                                                                                                                                                                                                                                                                                                              • Programming Color Patterns
                                                                                                                                                                                                                                                                                                              • Sensors and Actuators
                                                                                                                                                                                                                                                                                                              • Integrating Multiple Sensors
                                                                                                                                                                                                                                                                                                              • Event-Driven Programming
                                                                                                                                                                                                                                                                                                              • Interrupts in MicroPython
                                                                                                                                                                                                                                                                                                              • Using Interrupts with GPIO Pins
                                                                                                                                                                                                                                                                                                              • Debouncing with Interrupts
                                                                                                                                                                                                                                                                                                              • Timers in MicroPython
                                                                                                                                                                                                                                                                                                              • Delays and Timing Functions
                                                                                                                                                                                                                                                                                                              • Using the Time Module
                                                                                                                                                                                                                                                                                                              • Data Logging with MicroPython
                                                                                                                                                                                                                                                                                                              • Storing Data on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • File Handling in MicroPython
                                                                                                                                                                                                                                                                                                              • Communicating with Personal Computer over Serial
                                                                                                                                                                                                                                                                                                              • Using Universal Asynchronous Receiver-Transmitter Communication
                                                                                                                                                                                                                                                                                                              • Introduction to Sensors
                                                                                                                                                                                                                                                                                                              • Temperature Sensors
                                                                                                                                                                                                                                                                                                              • Interfacing Temperature Sensors
                                                                                                                                                                                                                                                                                                              • Humidity Sensors
                                                                                                                                                                                                                                                                                                              • Using DHT11 and DHT22 Sensors
                                                                                                                                                                                                                                                                                                              • Reading Sensor Data
                                                                                                                                                                                                                                                                                                              • Interpreting Sensor Data
                                                                                                                                                                                                                                                                                                              • Calibrating Sensors
                                                                                                                                                                                                                                                                                                              • Introduction to Actuators
                                                                                                                                                                                                                                                                                                              • Controlling Relays
                                                                                                                                                                                                                                                                                                              • Using Relays with Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              • Safety Precautions with Relays
                                                                                                                                                                                                                                                                                                              • Stepper Motors
                                                                                                                                                                                                                                                                                                              • Controlling Stepper Motors
                                                                                                                                                                                                                                                                                                              • Using Stepper Motor Drivers
                                                                                                                                                                                                                                                                                                              • Advanced Pulse Width Modulation Techniques
                                                                                                                                                                                                                                                                                                              • Generating Sound with Buzzers
                                                                                                                                                                                                                                                                                                              • Using Piezoelectric Buzzers
                                                                                                                                                                                                                                                                                                              • Generating Tones and Melodies
                                                                                                                                                                                                                                                                                                              • Infrared Communication
                                                                                                                                                                                                                                                                                                              • Using Infrared Sensors
                                                                                                                                                                                                                                                                                                              • Infrared Remote Control
                                                                                                                                                                                                                                                                                                              • Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                              • Measuring Distance with Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                              • Serial Communication Protocols
                                                                                                                                                                                                                                                                                                              • Inter-Integrated Circuit vs Serial Peripheral Interface vs Universal Asynchronous Receiver-Transmitter
                                                                                                                                                                                                                                                                                                              • Data Communication Principles
                                                                                                                                                                                                                                                                                                              • Wireless Communication Basics
                                                                                                                                                                                                                                                                                                              • Bluetooth Low Energy
                                                                                                                                                                                                                                                                                                              • Wi-Fi Connectivity
                                                                                                                                                                                                                                                                                                              • Using ESP8266 Modules
                                                                                                                                                                                                                                                                                                              • Internet of Things Concepts
                                                                                                                                                                                                                                                                                                              • Connecting to the Internet
                                                                                                                                                                                                                                                                                                              • Sending Data to Web Servers
                                                                                                                                                                                                                                                                                                              • Hypertext Transfer Protocol Basics
                                                                                                                                                                                                                                                                                                              • Using Message Queuing Telemetry Transport Protocol
                                                                                                                                                                                                                                                                                                              • Building Internet of Things Applications
                                                                                                                                                                                                                                                                                                              • Cloud Services Integration
                                                                                                                                                                                                                                                                                                              • Data Visualization Tools
                                                                                                                                                                                                                                                                                                              • Programming Best Practices
                                                                                                                                                                                                                                                                                                              • Code Optimization Techniques
                                                                                                                                                                                                                                                                                                              • Debugging Techniques
                                                                                                                                                                                                                                                                                                              • Using Debugging Tools
                                                                                                                                                                                                                                                                                                              • Version Control Systems
                                                                                                                                                                                                                                                                                                              • Using Git for Code Management
                                                                                                                                                                                                                                                                                                              • Collaborative Coding Practices
                                                                                                                                                                                                                                                                                                              • Documentation Standards
                                                                                                                                                                                                                                                                                                              • Commenting Code Effectively
                                                                                                                                                                                                                                                                                                              • Advanced MicroPython Features
                                                                                                                                                                                                                                                                                                              • Object-Oriented Programming
                                                                                                                                                                                                                                                                                                              • Classes and Objects in MicroPython
                                                                                                                                                                                                                                                                                                              • Inheritance and Polymorphism
                                                                                                                                                                                                                                                                                                              • Encapsulation in Object-Oriented Programming
                                                                                                                                                                                                                                                                                                              • Designing Reusable Code
                                                                                                                                                                                                                                                                                                              • Memory Management
                                                                                                                                                                                                                                                                                                              • Managing Resources Efficiently
                                                                                                                                                                                                                                                                                                              • Energy Efficiency in Programming
                                                                                                                                                                                                                                                                                                              • Sleep Modes in Microcontrollers
                                                                                                                                                                                                                                                                                                              • Battery-Powered Projects
                                                                                                                                                                                                                                                                                                              • Power Management Techniques
                                                                                                                                                                                                                                                                                                              • Advanced Electronics Concepts
                                                                                                                                                                                                                                                                                                              • Capacitors in Circuits
                                                                                                                                                                                                                                                                                                              • Inductors and Coils
                                                                                                                                                                                                                                                                                                              • Diodes and Rectification
                                                                                                                                                                                                                                                                                                              • Voltage Regulation
                                                                                                                                                                                                                                                                                                              • Using Voltage Regulators
                                                                                                                                                                                                                                                                                                              • Building Power Supplies
                                                                                                                                                                                                                                                                                                              • Analog Signals vs. Digital Signals
                                                                                                                                                                                                                                                                                                              • Signal Conditioning
                                                                                                                                                                                                                                                                                                              • Filtering Noise in Circuits
                                                                                                                                                                                                                                                                                                              • Interference and Shielding
                                                                                                                                                                                                                                                                                                              • Electromagnetic Compatibility
                                                                                                                                                                                                                                                                                                              • Circuit Design Principles
                                                                                                                                                                                                                                                                                                              • Using Simulation Tools
                                                                                                                                                                                                                                                                                                              • Prototyping Techniques
                                                                                                                                                                                                                                                                                                              • Schematic Diagram Reading
                                                                                                                                                                                                                                                                                                              • Understanding Datasheets
                                                                                                                                                                                                                                                                                                              • Component Specifications
                                                                                                                                                                                                                                                                                                              • Safety in Electronics
                                                                                                                                                                                                                                                                                                              • Electrostatic Discharge Precautions
                                                                                                                                                                                                                                                                                                              • Soldering Techniques
                                                                                                                                                                                                                                                                                                              • Introduction to Printed Circuit Board Design
                                                                                                                                                                                                                                                                                                              • Using Printed Circuit Board Design Software
                                                                                                                                                                                                                                                                                                              • Fabricating Custom Printed Circuit Boards
                                                                                                                                                                                                                                                                                                              • Advanced Sensor Integration
                                                                                                                                                                                                                                                                                                              • Gesture Recognition Sensors
                                                                                                                                                                                                                                                                                                              • Touch Sensors
                                                                                                                                                                                                                                                                                                              • Environmental Monitoring
                                                                                                                                                                                                                                                                                                              • Robotics Basics
                                                                                                                                                                                                                                                                                                              • Building Simple Robots
                                                                                                                                                                                                                                                                                                              • Line-Following Robots
                                                                                                                                                                                                                                                                                                              • Obstacle Avoidance Robots
                                                                                                                                                                                                                                                                                                              • Control Systems Basics
                                                                                                                                                                                                                                                                                                              • Feedback Mechanisms
                                                                                                                                                                                                                                                                                                              • Proportional-Integral-Derivative Controllers
                                                                                                                                                                                                                                                                                                              • Machine Learning Concepts
                                                                                                                                                                                                                                                                                                              • Using MicroPython for Artificial Intelligence
                                                                                                                                                                                                                                                                                                              • Edge Computing
                                                                                                                                                                                                                                                                                                              • Ethics in Technology
                                                                                                                                                                                                                                                                                                              • Future Trends in Computing
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/","title":"Concept Taxonomy","text":""},{"location":"sims/knowledge-graphs/concept-taxonomy/#prompt","title":"Prompt","text":"
                                                                                                                                                                                                                                                                                                              I am very pleased with these results. Now, can you suggest a\ntaxonomy to classify each of these learning concepts? Perhaps\nabout 10 different classifications?\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#response","title":"Response","text":"

                                                                                                                                                                                                                                                                                                              ChatGPT o1-min Thought for a couple of seconds

                                                                                                                                                                                                                                                                                                              I'm glad to hear that you're pleased with the results so far! Creating a taxonomy to classify your 197 learning concepts will help organize the curriculum, ensure comprehensive coverage, and facilitate a logical progression of topics. Below is a suggested taxonomy with 10 classifications, each accompanied by a description and examples of relevant concepts from your list.

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#1-computational-thinking-foundations","title":"1. Computational Thinking Foundations","text":"

                                                                                                                                                                                                                                                                                                              Description: Covers the basic principles and strategies of computational thinking, essential for problem-solving and algorithm development.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Intro to Computational Thinking (1)
                                                                                                                                                                                                                                                                                                              • Problem Decomposition (2)
                                                                                                                                                                                                                                                                                                              • Pattern Recognition (3)
                                                                                                                                                                                                                                                                                                              • Abstraction (4)
                                                                                                                                                                                                                                                                                                              • Algorithm Design (5)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#2-programming-fundamentals","title":"2. Programming Fundamentals","text":"

                                                                                                                                                                                                                                                                                                              Description: Introduces the core concepts of programming that are applicable across various programming languages and environments.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Basic Programming Concepts (6)
                                                                                                                                                                                                                                                                                                              • Variables in Programming (7)
                                                                                                                                                                                                                                                                                                              • Data Types in Programming (8)
                                                                                                                                                                                                                                                                                                              • Operators (9)
                                                                                                                                                                                                                                                                                                              • Control Structures (10)
                                                                                                                                                                                                                                                                                                              • Conditional Statements (11)
                                                                                                                                                                                                                                                                                                              • Loops (12)
                                                                                                                                                                                                                                                                                                              • General Functions in Programming (13)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#3-micropython-programming","title":"3. MicroPython Programming","text":"

                                                                                                                                                                                                                                                                                                              Description: Focuses on programming using MicroPython, including syntax, environment setup, and MicroPython-specific features.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Introduction to MicroPython (14)
                                                                                                                                                                                                                                                                                                              • Setting Up MicroPython Environment (15)
                                                                                                                                                                                                                                                                                                              • Syntax in MicroPython (16)
                                                                                                                                                                                                                                                                                                              • Functions in MicroPython (17)
                                                                                                                                                                                                                                                                                                              • Modules in MicroPython (18)
                                                                                                                                                                                                                                                                                                              • Input and Output (19)
                                                                                                                                                                                                                                                                                                              • Working with Strings (20)
                                                                                                                                                                                                                                                                                                              • Working with Numbers (21)
                                                                                                                                                                                                                                                                                                              • Lists (22)
                                                                                                                                                                                                                                                                                                              • Tuples (23)
                                                                                                                                                                                                                                                                                                              • Dictionaries (24)
                                                                                                                                                                                                                                                                                                              • Exception Handling (25)
                                                                                                                                                                                                                                                                                                              • Advanced MicroPython Features (145)
                                                                                                                                                                                                                                                                                                              • Using MicroPython for Artificial Intelligence (193)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#4-hardware-components-and-interfacing","title":"4. Hardware Components and Interfacing","text":"

                                                                                                                                                                                                                                                                                                              Description: Explores the physical components used in projects and how to interface them with the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Microcontroller Basics (26)
                                                                                                                                                                                                                                                                                                              • The Raspberry Pi Pico (27)
                                                                                                                                                                                                                                                                                                              • Understanding GPIO Pins (28)
                                                                                                                                                                                                                                                                                                              • Solderless Breadboards (32)
                                                                                                                                                                                                                                                                                                              • Breadboard Usage (30)
                                                                                                                                                                                                                                                                                                              • Using Breadboard Jumpers (45)
                                                                                                                                                                                                                                                                                                              • LED Displays Overview (72)
                                                                                                                                                                                                                                                                                                              • Organic Light-Emitting Diode Displays (73)
                                                                                                                                                                                                                                                                                                              • WS2812B LED Strips (80)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#5-electronics-basics","title":"5. Electronics Basics","text":"

                                                                                                                                                                                                                                                                                                              Description: Introduces fundamental electronics concepts necessary for building and understanding circuits.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Circuit Basics (31)
                                                                                                                                                                                                                                                                                                              • Ohm's Law (32)
                                                                                                                                                                                                                                                                                                              • Resistors in Circuits (33)
                                                                                                                                                                                                                                                                                                              • LEDs in Circuits (34)
                                                                                                                                                                                                                                                                                                              • Using Resistors with LEDs (35)
                                                                                                                                                                                                                                                                                                              • Current Limiting Resistors (36)
                                                                                                                                                                                                                                                                                                              • Transistors as Switches (59)
                                                                                                                                                                                                                                                                                                              • Capacitors in Circuits (158)
                                                                                                                                                                                                                                                                                                              • Inductors and Coils (159)
                                                                                                                                                                                                                                                                                                              • Diodes and Rectification (160)
                                                                                                                                                                                                                                                                                                              • Voltage Regulation (161)
                                                                                                                                                                                                                                                                                                              • Analog Signals vs Digital Signals (164)
                                                                                                                                                                                                                                                                                                              • Signal Conditioning (165)
                                                                                                                                                                                                                                                                                                              • Filtering Noise in Circuits (166)
                                                                                                                                                                                                                                                                                                              • Interference and Shielding (167)
                                                                                                                                                                                                                                                                                                              • Electromagnetic Compatibility (168)
                                                                                                                                                                                                                                                                                                              • Circuit Design Principles (169)
                                                                                                                                                                                                                                                                                                              • Safety in Electronics (175)
                                                                                                                                                                                                                                                                                                              • Electrostatic Discharge Precautions (176)
                                                                                                                                                                                                                                                                                                              • Soldering Techniques (177)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#6-sensor-integration","title":"6. Sensor Integration","text":"

                                                                                                                                                                                                                                                                                                              Description: Covers various sensors, their functionalities, and how to integrate and interpret data from them.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Introduction to Sensors (99)
                                                                                                                                                                                                                                                                                                              • Temperature Sensors (100)
                                                                                                                                                                                                                                                                                                              • Interfacing Temperature Sensors (101)
                                                                                                                                                                                                                                                                                                              • Humidity Sensors (102)
                                                                                                                                                                                                                                                                                                              • Using DHT11 and DHT22 Sensors (103)
                                                                                                                                                                                                                                                                                                              • Reading Sensor Data (104)
                                                                                                                                                                                                                                                                                                              • Interpreting Sensor Data (105)
                                                                                                                                                                                                                                                                                                              • Calibrating Sensors (106)
                                                                                                                                                                                                                                                                                                              • Photocells (63)
                                                                                                                                                                                                                                                                                                              • Making a Night Light (64)
                                                                                                                                                                                                                                                                                                              • Voltage Dividers (65)
                                                                                                                                                                                                                                                                                                              • Voltage Dividers and Sensors (66)
                                                                                                                                                                                                                                                                                                              • Time-of-Flight Sensors (67)
                                                                                                                                                                                                                                                                                                              • Interfacing Time-of-Flight Sensors (68)
                                                                                                                                                                                                                                                                                                              • Gesture Recognition Sensors (182)
                                                                                                                                                                                                                                                                                                              • Touch Sensors (183)
                                                                                                                                                                                                                                                                                                              • Environmental Monitoring (184)
                                                                                                                                                                                                                                                                                                              • Ultrasonic Sensors (120)
                                                                                                                                                                                                                                                                                                              • Advanced Sensor Integration (181)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#7-actuator-control","title":"7. Actuator Control","text":"

                                                                                                                                                                                                                                                                                                              Description: Focuses on controlling various actuators such as motors, servos, and relays to perform physical actions.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Introduction to Actuators (107)
                                                                                                                                                                                                                                                                                                              • Controlling Relays (108)
                                                                                                                                                                                                                                                                                                              • Relays Overview (109)
                                                                                                                                                                                                                                                                                                              • Relays Safety (110)
                                                                                                                                                                                                                                                                                                              • Stepper Motors (111)
                                                                                                                                                                                                                                                                                                              • Controlling Stepper Motors (112)
                                                                                                                                                                                                                                                                                                              • Using Stepper Motor Drivers (113)
                                                                                                                                                                                                                                                                                                              • Servo Motors Overview (56)
                                                                                                                                                                                                                                                                                                              • Controlling Servo Motors (57)
                                                                                                                                                                                                                                                                                                              • DC Motors Overview (58)
                                                                                                                                                                                                                                                                                                              • Transistors as Switches (59)
                                                                                                                                                                                                                                                                                                              • Controlling Motors with Transistors (60)
                                                                                                                                                                                                                                                                                                              • Transistor Biasing Resistors (61)
                                                                                                                                                                                                                                                                                                              • Power Management with Transistors (62)
                                                                                                                                                                                                                                                                                                              • Generating Sound with Buzzers (114)
                                                                                                                                                                                                                                                                                                              • Using Piezoelectric Buzzers (115)
                                                                                                                                                                                                                                                                                                              • Generating Tones and Melodies (116)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#8-communication-protocols","title":"8. Communication Protocols","text":"

                                                                                                                                                                                                                                                                                                              Description: Details various communication protocols used for data transmission between devices and components.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Serial Communication Protocols (122)
                                                                                                                                                                                                                                                                                                              • I2C Protocol (69)
                                                                                                                                                                                                                                                                                                              • SPI Protocol (70)
                                                                                                                                                                                                                                                                                                              • Universal Serial Bus Communication (97)
                                                                                                                                                                                                                                                                                                              • Universal Asynchronous Receiver-Transmitter Communication (98)
                                                                                                                                                                                                                                                                                                              • Connecting I2C Devices (71)
                                                                                                                                                                                                                                                                                                              • Advanced I2C (78)
                                                                                                                                                                                                                                                                                                              • Advanced SPI (79)
                                                                                                                                                                                                                                                                                                              • Infrared Communication (117)
                                                                                                                                                                                                                                                                                                              • Using Infrared Sensors (118)
                                                                                                                                                                                                                                                                                                              • Infrared Remote Control (119)
                                                                                                                                                                                                                                                                                                              • I2C vs SPI vs UART (122)
                                                                                                                                                                                                                                                                                                              • Data Communication Principles (123)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#9-internet-of-things-iot","title":"9. Internet of Things (IoT)","text":"

                                                                                                                                                                                                                                                                                                              Description: Explores IoT concepts, connectivity, data transmission, and integration with cloud services.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Internet of Things Concepts (128)
                                                                                                                                                                                                                                                                                                              • Connecting to the Internet (129)
                                                                                                                                                                                                                                                                                                              • Sending Data to Web Servers (130)
                                                                                                                                                                                                                                                                                                              • Hypertext Transfer Protocol Basics (131)
                                                                                                                                                                                                                                                                                                              • Message Queuing Telemetry Transport Protocol (132)
                                                                                                                                                                                                                                                                                                              • IoT Applications (133)
                                                                                                                                                                                                                                                                                                              • Cloud Services Integration (134)
                                                                                                                                                                                                                                                                                                              • Data Visualization Tools (135)
                                                                                                                                                                                                                                                                                                              • Wireless Communication Basics (124)
                                                                                                                                                                                                                                                                                                              • Bluetooth Low Energy (125)
                                                                                                                                                                                                                                                                                                              • Wi-Fi Connectivity (126)
                                                                                                                                                                                                                                                                                                              • Edge Computing (194)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#10-advanced-topics-and-best-practices","title":"10. Advanced Topics and Best Practices","text":"

                                                                                                                                                                                                                                                                                                              Description: Includes advanced programming techniques, best practices, version control, and emerging technologies.

                                                                                                                                                                                                                                                                                                              Relevant Concepts:

                                                                                                                                                                                                                                                                                                              • Programming Best Practices (136)
                                                                                                                                                                                                                                                                                                              • Code Optimization Techniques (137)
                                                                                                                                                                                                                                                                                                              • Debugging Techniques (138)
                                                                                                                                                                                                                                                                                                              • Using Debugging Tools (139)
                                                                                                                                                                                                                                                                                                              • Version Control Systems (140)
                                                                                                                                                                                                                                                                                                              • Using Git for Code Management (141)
                                                                                                                                                                                                                                                                                                              • Collaborative Coding Practices (142)
                                                                                                                                                                                                                                                                                                              • Documentation Standards (143)
                                                                                                                                                                                                                                                                                                              • Commenting Code Effectively (144)
                                                                                                                                                                                                                                                                                                              • Object-Oriented Programming (146)
                                                                                                                                                                                                                                                                                                              • Classes and Objects (147)
                                                                                                                                                                                                                                                                                                              • Inheritance and Polymorphism (148)
                                                                                                                                                                                                                                                                                                              • Encapsulation in Object-Oriented Programming (149)
                                                                                                                                                                                                                                                                                                              • Designing Reusable Code (150)
                                                                                                                                                                                                                                                                                                              • Memory Management (151)
                                                                                                                                                                                                                                                                                                              • Managing Resources Efficiently (152)
                                                                                                                                                                                                                                                                                                              • Energy Efficiency in Programming (153)
                                                                                                                                                                                                                                                                                                              • Sleep Modes in Microcontrollers (154)
                                                                                                                                                                                                                                                                                                              • Battery-Powered Projects (155)
                                                                                                                                                                                                                                                                                                              • Power Management Techniques (156)
                                                                                                                                                                                                                                                                                                              • Control Systems Basics (189)
                                                                                                                                                                                                                                                                                                              • Feedback Mechanisms (190)
                                                                                                                                                                                                                                                                                                              • Proportional-Integral-Derivative Controllers (191)
                                                                                                                                                                                                                                                                                                              • Machine Learning Concepts (192)
                                                                                                                                                                                                                                                                                                              • Using MicroPython for Artificial Intelligence (193)
                                                                                                                                                                                                                                                                                                              • Ethics in Technology (195)
                                                                                                                                                                                                                                                                                                              • Future Trends in Computing (196)
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#additional-considerations","title":"Additional Considerations","text":"
                                                                                                                                                                                                                                                                                                              • Cross-Cutting Themes: Some concepts may span multiple categories. For example, \"Pulse Width Modulation\" could relate to both \"Electronics Basics\" and \"Actuator Control.\"

                                                                                                                                                                                                                                                                                                              • Prerequisites: Ensure that foundational categories like \"Computational Thinking Foundations\" and \"Programming Fundamentals\" are taught first, as they underpin many other topics.

                                                                                                                                                                                                                                                                                                              • Modular Organization: Consider organizing your curriculum into modules based on these classifications to provide a structured learning path.

                                                                                                                                                                                                                                                                                                              • Scalability: This taxonomy allows for the addition of new concepts or subcategories as the course evolves or as new technologies emerge.

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#visual-taxonomy-structure","title":"Visual Taxonomy Structure","text":"

                                                                                                                                                                                                                                                                                                              For better visualization, here's a hierarchical representation of the taxonomy:

                                                                                                                                                                                                                                                                                                              1. Computational Thinking Foundations
                                                                                                                                                                                                                                                                                                              2. Programming Fundamentals
                                                                                                                                                                                                                                                                                                              3. MicroPython Programming
                                                                                                                                                                                                                                                                                                              4. Hardware Components and Interfacing
                                                                                                                                                                                                                                                                                                              5. Electronics Basics
                                                                                                                                                                                                                                                                                                              6. Sensor Integration
                                                                                                                                                                                                                                                                                                              7. Actuator Control
                                                                                                                                                                                                                                                                                                              8. Communication Protocols
                                                                                                                                                                                                                                                                                                              9. Internet of Things (IoT)
                                                                                                                                                                                                                                                                                                              10. Advanced Topics and Best Practices
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/concept-taxonomy/#example-mapping-of-concepts-to-taxonomy","title":"Example Mapping of Concepts to Taxonomy","text":"

                                                                                                                                                                                                                                                                                                              Here's how some of the concepts map to the suggested taxonomy:

                                                                                                                                                                                                                                                                                                              Concept ID Concept Name Classification 1 Intro to Computational Thinking Computational Thinking Foundations --- --- --- 7 Variables in Programming Programming Fundamentals 14 Introduction to MicroPython MicroPython Programming 26 Microcontroller Basics Hardware Components and Interfacing 31 Circuit Basics Electronics Basics 99 Introduction to Sensors Sensor Integration 107 Introduction to Actuators Actuator Control 122 Serial Communication Protocols Communication Protocols 128 Internet of Things Concepts Internet of Things (IoT) 136 Programming Best Practices Advanced Topics and Best Practices"},{"location":"sims/knowledge-graphs/concept-taxonomy/#final-remarks","title":"Final Remarks","text":"

                                                                                                                                                                                                                                                                                                              This taxonomy provides a structured framework to classify and organize your 197 learning concepts effectively. It ensures that foundational knowledge is established before progressing to more advanced topics, facilitating a coherent and comprehensive learning experience for high school students. Feel free to adjust the classifications or add subcategories to better fit the specific needs and goals of your course.

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/","title":"Circuits Course Concept Dependency Graph","text":"

                                                                                                                                                                                                                                                                                                              HTML Page for Dependency Graph

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/#adjusting-visualization","title":"Adjusting Visualization","text":"

                                                                                                                                                                                                                                                                                                              In the JavaScript file you can change the display options. Here is the portion of the JavaScript that changes the options.

                                                                                                                                                                                                                                                                                                              var options = {\n    nodes: {\n        shape: 'dot',\n        size: 10,\n        font: {\n            size: 14,\n        },\n    },\n    edges: {\n        arrows: 'to',\n        smooth: true,\n    },\n    physics: {\n        stabilization: false,\n    },\n};\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/#left-to-right-layout","title":"Left to Right Layout","text":"

                                                                                                                                                                                                                                                                                                              HTML Page for Dependency Graph

                                                                                                                                                                                                                                                                                                              var options = {\nlayout: {\n        hierarchical: {\n          direction: 'LR',  // Left to right\n          sortMethod: 'directed',  // Sort nodes based on dependencies\n          nodeSpacing: 200,  // Adjust spacing if needed\n          levelSeparation: 150  // Adjust for horizontal space between levels\n        }\n      }\n}\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/#full-layout-options","title":"Full Layout Options","text":"
                                                                                                                                                                                                                                                                                                              layout: {\n    randomSeed: undefined,\n    improvedLayout:true,\n    clusterThreshold: 150,\n    hierarchical: {\n      enabled:false,\n      levelSeparation: 150,\n      nodeSpacing: 100,\n      treeSpacing: 200,\n      blockShifting: true,\n      edgeMinimization: true,\n      parentCentralization: true,\n      direction: 'LR',        // UD, DU, LR, RL\n      sortMethod: 'hubsize',  // hubsize, directed\n      shakeTowards: 'leaves'  // roots, leaves\n    }\n  }\n  ```\n\n## Hierarchical Layout User Defined\nhttps://visjs.github.io/vis-network/examples/network/layout/hierarchicalLayoutUserdefined.html\n\n```js\n  var options = {\n          edges: {\n            smooth: {\n              type: \"cubicBezier\",\n              forceDirection:\n                directionInput.value == \"UD\" || directionInput.value == \"DU\"\n                  ? \"vertical\"\n                  : \"horizontal\",\n              roundness: 0.4,\n            },\n          },\n          layout: {\n            hierarchical: {\n              direction: directionInput.value,\n            },\n          },\n          physics: false,\n        };\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/#category-colors","title":"Category Colors","text":"

                                                                                                                                                                                                                                                                                                              We can use generative AI to categorize each concept. Here are 11 categories of the concepts

                                                                                                                                                                                                                                                                                                              CategoryID Color CategoryLabel 1 red Fundamental Concepts 2 orange Passive Components 3 yellow Active Components and Semiconductor Devices 4 green Circuit Analysis Techniques 5 cyan AC Circuit Concepts 6 blue Transient Analysis 7 purple Signal Processing and Filters 8 pink Amplifiers and Analog Circuits 9 gray Power Electronics 10 olive Control Systems and Stability 11 brown Types of Circuits

                                                                                                                                                                                                                                                                                                              Category Colors Demo

                                                                                                                                                                                                                                                                                                              Cat Colors V3 DEBUG

                                                                                                                                                                                                                                                                                                              "},{"location":"sims/knowledge-graphs/graph/#reference","title":"Reference","text":"

                                                                                                                                                                                                                                                                                                              Vis.js Network Layout Methods

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/","title":"Introduction to Sound and Music in MicroPython","text":""},{"location":"sound/#how-microcontrollers-generate-sound","title":"How Microcontrollers Generate Sound","text":"

                                                                                                                                                                                                                                                                                                              Microcontrollers are really great at generating digital outputs on their GPIO pins. These digital signals that quickly switch between zero and a positive voltage like 3.3 or 5 volts. However, they are not designed to create \"analog\" output of a continuous varying voltage. However, we can use a technique called \"Pulse Width Modulation\" to simulate the various frequencies of sound using digital only outputs.

                                                                                                                                                                                                                                                                                                              Pulse Width Modulation is the process of changing not the height of a electrical signal, but the width between the pulses of digital signals. By changing the distance of the spaces between the digital signals we can generate a signal that will sound like it has a higher or lower frequency or pitch.

                                                                                                                                                                                                                                                                                                              MicroPython provides a powerful library of tools for you to easily generate pulses of different shapes. This is called the PWM library. Will will use this in our sound and music programs. Here is a sample of how this is called in our code:

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/#duty-cycle","title":"Duty Cycle","text":"

                                                                                                                                                                                                                                                                                                              The Duty Cycle is what percent of time a pulse is high.

                                                                                                                                                                                                                                                                                                              For working with sound, we want to generate smooth sound waves that are on 1/2 of the time and off 1/2 of the time. So our duty cycles will be set to be 50%. On the Raspberry Pi Pico we can achieve this by the following function:

                                                                                                                                                                                                                                                                                                              speaker.duty_u16(1000)\n

                                                                                                                                                                                                                                                                                                              When we are done playing a tone, we must always explicitly turn the duty cycle back to 0.

                                                                                                                                                                                                                                                                                                              speaker.duty_u16(0)\n

                                                                                                                                                                                                                                                                                                              If we forget to add this line, the tone will continue to play despite the main program stopping. This shows you that the part of the chip that generates the tone pulses is an independent processor that is not dependant on the main program running!

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n

                                                                                                                                                                                                                                                                                                              Note that we will also need to pause between notes, so will use the sleep library to pause execution of our sound generation.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/#connecting-a-sound-device","title":"Connecting a Sound Device","text":"

                                                                                                                                                                                                                                                                                                              There are several different ways that you can connect a sound device to you MicroController. Here are three options:

                                                                                                                                                                                                                                                                                                              1. Buzzers - These are small inexpensive devices that can mount directly on your breadboard.
                                                                                                                                                                                                                                                                                                              2. Piezoelectric Speaker - Wikipedia Page on Piezoelectric Speaker
                                                                                                                                                                                                                                                                                                              3. Speaker - A magnetic speaker with our without an amplifier is another way to hear sound. You can also purchase a small amplifier to increase the volume.
                                                                                                                                                                                                                                                                                                              4. Amplifier - For about $1.20 you can purchase a small amplifier for your speaker. eBay LM386 DC 5V-12V Mini Micro Audio Amplifier Module Board

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              1, Juke Phone in C - convert an old land-line telephone to an MP3-player Jukebox. Although this is written in C, it could be converted into MicroPython.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/02-play-tone/","title":"Play Tones Using the PWM","text":"

                                                                                                                                                                                                                                                                                                              Since we will be using the sleep function many times, we will import it by name from the Micropthon time library like this:

                                                                                                                                                                                                                                                                                                              from utime import sleep\n

                                                                                                                                                                                                                                                                                                              Now, instead of putting utime.sleep(.5) we can just reference sleep directly like this:

                                                                                                                                                                                                                                                                                                              sleep(.5)\n

                                                                                                                                                                                                                                                                                                              This will pause for 1/2 a second. This is how long we wait for a tone to stay on or go off. The nice thing about this menthod is that our code is a little smaller. However, you can't run other functions in the utime library. So if you want to add them later you will need to import them also, just like we did for the sleep function.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/02-play-tone/#lab-1-play-a-single-tone","title":"Lab 1: Play A Single Tone","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n# lower right corner with USB connector on top\nSPEAKER_PIN = 16\n\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n# set the duty cycle to be 50%\nspeaker.duty_u16(1000)\nspeaker.freq(1000) # 50% on and off\nsleep(1) # wait a second\nspeaker.duty_u16(0)\n# turn off the PWM circuits off with a zero duty cycle\nspeaker.duty_u16(0)\n

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              The tone will keep sounding until you turn the speaker duty to 0. This shows you that the circuitry that is generating the sound is independent of the main CPU.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/02-play-tone/#experiments","title":"Experiments","text":"
                                                                                                                                                                                                                                                                                                              1. Try changing the frequency for the first lab. This is the line speaker.freq(1000) and rerunning the program. Try using values from 10 to 10000. What values seem the loudest to your ear?
                                                                                                                                                                                                                                                                                                              2. What happens if you comment out the last line that sets the duty cycle to be 0? Make sure to set it back to zero again or the tone will continue playing until the device is powered off.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/03-play-three-tones/","title":"Play Three Tones","text":"

                                                                                                                                                                                                                                                                                                              In this lesson we will play three consecutive tones. Each tone will have a specific time on and we will put a time between the tones.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n# lower right corner with USB connector on top\nSPEAKER_PIN = 16\n\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\nspeaker.duty_u16(1000)\nspeaker.freq(300) # 1 Kilohertz\nsleep(.5) # wait a 1/4 second\nspeaker.duty_u16(0)\nsleep(.25)\n\nspeaker.duty_u16(1000)\nspeaker.freq(800)\nsleep(.5)\nspeaker.duty_u16(0)\nsleep(.25)\n\nspeaker.duty_u16(1000)\nspeaker.freq(400)\nsleep(.5)\n\n# turn off the PWM \nspeaker.duty_u16(0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/03-play-three-tones/#using-variables","title":"Using Variables","text":"

                                                                                                                                                                                                                                                                                                              We can also put the time each tone stays on and the space between the tones into variables so it is easier to modify the values in a single place.

                                                                                                                                                                                                                                                                                                              # set the time each tone will be on\nONTIME = .5\n# the time between the tones\nOFFTIME = .100\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/03-play-three-tones/#three-tones-with-variables","title":"Three Tones With Variables","text":"
                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n# lower right corner with USB connector on top\nSPEAKER_PIN = 16\n\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\n# the time each tone will be on\nON_TIME = .25\n# the time between the tones\nOFF_TIME = .1\n\n# Low tone\nspeaker.duty_u16(1000)\nspeaker.freq(300)\nsleep(ON_TIME)\nspeaker.duty_u16(0)\nsleep(OFF_TIME)\n\n# High tone\nspeaker.duty_u16(1000)\nspeaker.freq(800)\nsleep(ON_TIME)\nspeaker.duty_u16(0)\nsleep(OFF_TIME)\n\n# Medium tone\nspeaker.duty_u16(1000)\nspeaker.freq(400)\nsleep(ON_TIME)\n\n# turn off the PWM \nspeaker.duty_u16(0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/03-play-three-tones/#experiments","title":"Experiments","text":"
                                                                                                                                                                                                                                                                                                              1. Change the ON_TIME in the above program. What is the shortest time that you can still hear?
                                                                                                                                                                                                                                                                                                              2. Change the order of the Low, High, Medium around. What is the most pleasing to your ears?
                                                                                                                                                                                                                                                                                                              3. What order would you suggest for the start of a game and what order would you like for a \"Game Over\" sound?
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/04-play-scale/","title":"Play a Scale","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will learn about how to automatically generate various pitches. We will see that the spacing between lower pitches is different from the spacing between higher pitches.

                                                                                                                                                                                                                                                                                                              Here is a program that plays a scale of notes from a starting frequency of 30 hertz to an upper frequency of around 10,000 hertz. Note that

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n# lower right corner with USB connector on top\nSPEAKER_PIN = 16\n\n# create a Pulse Width Modulation Object on this pin\nspeaker = PWM(Pin(SPEAKER_PIN))\n\ndef playtone(frequency):\n    speaker.duty_u16(1000)\n    speaker.freq(frequency)\n    sleep(0.3)\n\ndef bequiet():\n    speaker.duty_u16(0)\n\nfreq = 30\n\nfor i in range(64):\n    print(freq)\n    playtone(freq)\n    freq = int(freq * 1.1)\n\n# Turn off the PWM\nspeaker.duty_u16(0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/04-play-scale/#new-frequency-spacing","title":"New Frequency Spacing","text":"

                                                                                                                                                                                                                                                                                                              When you run the prior example, note the frequencies printed to the console. Are they evenly spaced?

                                                                                                                                                                                                                                                                                                              Take a close look at the line that creates a new frequency:

                                                                                                                                                                                                                                                                                                              freq = int(freq * 1.1)\n

                                                                                                                                                                                                                                                                                                              The effect of this line is to create a new frequency that is 10% higher than the prior frequency.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/04-play-scale/#experiments","title":"Experiments","text":"
                                                                                                                                                                                                                                                                                                              1. What happens if you change the frequency update to be freq = freq +100
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/05-play-mario/","title":"Play Mario on MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This program will play the theme music from the Mario video game.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\nbuzzer = PWM(Pin(16))\n\ntones = {\n\"B0\": 31,\"C1\": 33,\"CS1\": 35,\"D1\": 37,\"DS1\": 39,\"E1\": 41,\"F1\": 44,\"FS1\": 46,\n\"G1\": 49,\"GS1\": 52,\"A1\": 55,\"AS1\": 58,\"B1\": 62,\"C2\": 65,\n\"CS2\": 69,\"D2\": 73,\"DS2\": 78,\"E2\": 82,\"F2\": 87,\"FS2\": 93,\"G2\": 98,\n\"GS2\": 104,\"A2\": 110,\"AS2\": 117,\"B2\": 123,\"C3\": 131,\"CS3\": 139,\n\"D3\": 147,\"DS3\": 156,\"E3\": 165,\"F3\": 175,\"FS3\": 185,\n\"G3\": 196,\"GS3\": 208,\"A3\": 220,\"AS3\": 233,\"B3\": 247,\"C4\": 262,\"CS4\": 277,\"D4\": 294,\"DS4\": 311,\n\"E4\": 330,\"F4\": 349,\"FS4\": 370,\"G4\": 392,\"GS4\": 415,\"A4\": 440,\"AS4\": 466,\"B4\": 494,\"C5\": 523,\"CS5\": 554,\"D5\": 587,\"DS5\": 622,\"E5\": 659,\"F5\": 698,\n\"FS5\": 740,\"G5\": 784,\"GS5\": 831,\"A5\": 880,\"AS5\": 932,\"B5\": 988,\"C6\": 1047,\"CS6\": 1109,\"D6\": 1175,\"DS6\": 1245,\"E6\": 1319,\"F6\": 1397,\"FS6\": 1480,\"G6\": 1568,\"GS6\": 1661,\n\"A6\": 1760,\"AS6\": 1865,\"B6\": 1976,\"C7\": 2093,\"CS7\": 2217,\"D7\": 2349,\"DS7\": 2489,\"E7\": 2637,\"F7\": 2794,\"FS7\": 2960,\"G7\": 3136,\"GS7\": 3322,\"A7\": 3520,\n\"AS7\": 3729,\"B7\": 3951,\"C8\": 4186,\"CS8\": 4435,\"D8\": 4699,\"DS8\": 4978\n}\n\nsong = [\"E5\",\"G5\",\"A5\",\"P\",\"E5\",\"G5\",\"B5\",\"A5\",\"P\",\"E5\",\"G5\",\"A5\",\"P\",\"G5\",\"E5\"]\nmario = [\"E7\", \"E7\", 0, \"E7\", 0, \"C7\", \"E7\", 0, \"G7\", 0, 0, 0, \"G6\", 0, 0, 0, \"C7\", 0, 0, \"G6\",\n         0, 0, \"E6\", 0, 0, \"A6\", 0, \"B6\", 0, \"AS6\", \"A6\", 0, \"G6\", \"E7\", 0, \"G7\", \"A7\", 0, \"F7\", \"G7\",\n         0, \"E7\", 0,\"C7\", \"D7\", \"B6\", 0, 0, \"C7\", 0, 0, \"G6\", 0, 0, \"E6\", 0, 0, \"A6\", 0, \"B6\", 0,\n         \"AS6\", \"A6\", 0, \"G6\", \"E7\", 0, \"G7\", \"A7\", 0, \"F7\", \"G7\", 0, \"E7\", 0,\"C7\", \"D7\", \"B6\", 0, 0]\n\ndef playtone(frequency):\n    buzzer.duty_u16(1000)\n    buzzer.freq(frequency)\n\ndef bequiet():\n    buzzer.duty_u16(0)\n\ndef playsong(mysong):\n    for i in range(len(mysong)):\n        if (mysong[i] == \"P\" or mysong[i] == 0 ):\n            bequiet()\n        else:\n            playtone(tones[mysong[i]])\n        sleep(0.3)\n    bequiet()\nplaysong(mario)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/06-eight-key-piano/","title":"Eight Key Piano","text":"

                                                                                                                                                                                                                                                                                                              In this lab we wire up eight momentary press buttons so that when each one is pressed it will play a different note.

                                                                                                                                                                                                                                                                                                              To create this project, you will need the following parts:

                                                                                                                                                                                                                                                                                                              1. A Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              2. A standard size breadboard or two 1/2 breadboards
                                                                                                                                                                                                                                                                                                              3. 8 momentary press buttons
                                                                                                                                                                                                                                                                                                              4. A speaker or a Piezo buzzer
                                                                                                                                                                                                                                                                                                              5. An optional sound amplifier such as the LM386 DC 5V-12V Mini Micro Audio Amplifier which can be purchased on e-bay for under $2 USD. If you are working in a quiet room you may not need the amplifier.

                                                                                                                                                                                                                                                                                                              Each \"key\" is a momentary press button that is wired up between a GPIO pin and the +3.3 volt rail on the breadboard connected to 3V3(OUT) pin. We do not need to use any resistors to pull the signals low since we configure the pins to be inputs with the PULL_DOWN resistor like this:

                                                                                                                                                                                                                                                                                                              button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/06-eight-key-piano/#the-play-tone-functions","title":"The Play Tone Functions","text":"

                                                                                                                                                                                                                                                                                                              We will use two Python functions, one for playing a tone of a given frequency and one for turning off the sound.

                                                                                                                                                                                                                                                                                                              def playtone(frequency):\n    speaker.duty_u16(1000) # turn the PWM duty to 50%\n    speaker.freq(frequency)\n    builtin_led.high() # turn builtin LED on\n\ndef bequiet():\n    speaker.duty_u16(0) # turn off the speaker PWM\n    builtin_led.low() # turn builtin LED off\n

                                                                                                                                                                                                                                                                                                              We will also use the .value() method on each pin to detect if it is HIGH (1) like this:

                                                                                                                                                                                                                                                                                                              if button_pin_1.value() == 1:\n        playtone(220) # A3\n

                                                                                                                                                                                                                                                                                                              We will be playing \"notes\" generating square waves with various frequencies from our lowest note of A3 at 220 Hz up to A4 at 440 Hz.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/06-eight-key-piano/#sample-code","title":"Sample Code","text":"
                                                                                                                                                                                                                                                                                                              # play a tone durning button down\nfrom machine import Pin, PWM\nfrom utime import sleep, ticks_ms\n\nSPEAKER_PIN = 22 # pass through a speaker and tie the other end to GND\nspeaker = PWM(Pin(SPEAKER_PIN))\n\nbuiltin_led = machine.Pin(25, Pin.OUT)\n\n# Connect these GP pins through a button to the +3.3 volt rail\nbutton_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_2 = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_3 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_4 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_5 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_6 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_7 = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)\nbutton_pin_8 = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN)\n\ndef playtone(frequency):\n    speaker.duty_u16(1000) # turn the PWM duty to 50%\n    speaker.freq(frequency)\n    builtin_led.high() # turn builtin LED on\n\ndef bequiet():\n    speaker.duty_u16(0) # turn off the speaker PWM\n    builtin_led.low() # turn builtin LED off\n\nwhile True:\n    if   button_pin_1.value() == 1:\n        playtone(220) # A3\n    elif button_pin_2.value() == 1:\n        playtone(247) # B3\n    elif button_pin_3.value() == 1:\n        playtone(262) # C4\n    elif button_pin_4.value() == 1:\n        playtone(294) # D4\n    elif button_pin_5.value() == 1:\n        playtone(330) # E4\n    elif button_pin_6.value() == 1:\n        playtone(349) # F4\n    elif button_pin_7.value() == 1:\n        playtone(392) # G4\n    elif button_pin_8.value() == 1:\n        playtone(440) # A4\n    else:\n        bequiet()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/06-eight-key-piano/#exercises","title":"Exercises","text":"
                                                                                                                                                                                                                                                                                                              1. Rewrite the code above using lists for the pin numbers and the notes.
                                                                                                                                                                                                                                                                                                              2. Try different notes with other scales.
                                                                                                                                                                                                                                                                                                              3. Add another button to change the \"octave\" of the notes.
                                                                                                                                                                                                                                                                                                              4. Add a display to show the notes as they are being played.
                                                                                                                                                                                                                                                                                                              5. Print the time each note is being pressed as well as the length of the pauses between the notes.
                                                                                                                                                                                                                                                                                                              6. Write the notes to a recording file.
                                                                                                                                                                                                                                                                                                              7. Add a menu system so you can do things like start a new song recording, save a recording and playback a recording.
                                                                                                                                                                                                                                                                                                              8. Eight keys are not enough for many songs. Use two full-size breadboards to expand the number of keys on your piano.
                                                                                                                                                                                                                                                                                                              9. Look into getting a MIDI keyboard such as the 32-key $40 MIDIPLUS AKM320 USB MIDI Keyboard Controller
                                                                                                                                                                                                                                                                                                              10. Read this blog about running MIDI on the Pico: MIDI, MicroPython and the Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/","title":"Playing an Audio File","text":"

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              This lesson is still a work in progress. The wavePlayer is in an early draft form and has unpredictable interactions with other components. See the wav file test results section below. We also are having problems when different GPIO pins are used. If you stick to pins for GPIO 2 and 3 for the two channels the test run OK.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#playing-sounds-on-the-rp2040-chip","title":"Playing Sounds on The RP2040 Chip","text":"

                                                                                                                                                                                                                                                                                                              Although we can play tones of various pitches on the PR2040 using the PMW to generate square waves, the quality of this sound is not close to high-fidelity sound like you would expect in a personal MP3 audio player.

                                                                                                                                                                                                                                                                                                              In this lesson we will demonstrate how to play a high-quality audio files that are stored on the two megabytes of non-volatile static memory of the Pico. According to the specification of the Raspberry Pi Pico, the system comes with 2MB on-board QSPI Flash that we can use to store sound files. By combining our Pico with an SD card reader we can also play many sounds and even full-length music and full albums.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#background-on-audio-encoding","title":"Background on Audio Encoding","text":"

                                                                                                                                                                                                                                                                                                              Audio files are encoded in many formats. For this lab there are two key concepts to understand:

                                                                                                                                                                                                                                                                                                              1. The Sampling Rate which is how frequently an audio signal is sampled. The more frequently we sample (up to 41K per second) the higher the fidelity of the recording. The downside is that the audio file takes more space.
                                                                                                                                                                                                                                                                                                              2. The audio bit depth is how many bits we used to encode the amplitude of the sound.

                                                                                                                                                                                                                                                                                                              For our labs, we will be using mono files (not stereo) a sampling rate of 8,000 samples per second (8K Hz) and a sampling rate of 16-bit depth. This is a good compromise between smaller size and sound fidelity in typical robots.

                                                                                                                                                                                                                                                                                                              Our robots typically will play a short 1-second sound to tell us they are performing an action like stopping, backing up or turning. This one-second 8K Hz WAV file will be about 20K. Our flash budget for the Raspberry Pi Pico is 2M, so we can easily store 10 sound effects in 200K or 1/10 of our available flash memory. We can also add a SD card if we need more flash memory.

                                                                                                                                                                                                                                                                                                              We will be using standard .WAV files with Pulse Code Modulation Encoding in .WAV files. WAV files do take more space than compressed MP3 files, but they are easier to play because the decoding steps are trivial for a microcontroller to perform.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#overall-architecture","title":"Overall Architecture","text":"
                                                                                                                                                                                                                                                                                                              1. We will be reading .wav files from the MicroPython non-volatile flash memory or an SD card. By convention we will store them in a directory called /sounds
                                                                                                                                                                                                                                                                                                              2. We will be using the wave.py module to read the .wav files
                                                                                                                                                                                                                                                                                                              3. We will be using the myPMW.py, chunk.py and myDMA.py modules to stream the data from the WAV files to the PWM controllers
                                                                                                                                                                                                                                                                                                              4. The metadata from the .wav files is used to change the sampling frequency of the .wav player
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#checking-your-sound-file-sizes","title":"Checking Your Sound File Sizes","text":"
                                                                                                                                                                                                                                                                                                              import os\n\nwaveFolder= \"/sounds\"\n\ntotal = 0\n# get a list of .wav files and their sizes\nfor file in os.listdir(waveFolder):\n    size = os.path.getsize(file)\n    print(file, size)\n    total += size\nprint('Total sound directory size:', total)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#connections","title":"Connections","text":"

                                                                                                                                                                                                                                                                                                              Some of this documentation was take from Dan Perron's Pico Audio GitHub Repo.

                                                                                                                                                                                                                                                                                                              In these tests we used GPIO pins 2 and 3 to drive the left and right channels of audio that are sent to a stereo amplifier. You can use both an amplifier or head phone with a 1K resistor in series on the pins to limit the current from the 3.3v output signals.

                                                                                                                                                                                                                                                                                                              The myPWM subclass set the maximum count to 255 (8 bits) or 1023(10bits) at a frequency around 122.5KHz.

                                                                                                                                                                                                                                                                                                              The PWM is now on 10 bits (0..1023)

                                                                                                                                                                                                                                                                                                              The myDMA class allows to use direct memory access to transfer each frame at the current sample rate.

                                                                                                                                                                                                                                                                                                              We will need to install the wave.py and chunk.py from Jokey GitHub Awesome MicroPython Repo on root file system or the /lib folder on the pico file system.

                                                                                                                                                                                                                                                                                                              Don't forget to increase the SPI clock up to 3Mhz. (TODO not sure what this means)

                                                                                                                                                                                                                                                                                                              The following documentation was take from Daniel Perron's Github page.

                                                                                                                                                                                                                                                                                                              1. We set the PWM to a range of 255 at 122Khz
                                                                                                                                                                                                                                                                                                              2. We read the wave file using the class wave.py which will set the sample rate and read the audio data by chunk
                                                                                                                                                                                                                                                                                                              3. Each chunk is converted to 16 bit signed to unsigned char with the middle at 128, (512 for 10 bits)
                                                                                                                                                                                                                                                                                                              4. We wait for the DMA to be completed. On first it will be anyway.
                                                                                                                                                                                                                                                                                                              5. The converted chunk is then pass to the DMA to be transfer at the sample rate using one of build in timer
                                                                                                                                                                                                                                                                                                              6. Go on step 2 until is done.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#steps-to-test-playing-a-wav-file","title":"Steps to test playing a wav file","text":""},{"location":"sound/07-play-audio-file/#clone-the-pico-audio-pwm-github-repository","title":"Clone the Pico Audio PWM GitHub Repository","text":"
                                                                                                                                                                                                                                                                                                              git clone https://github.com/danjperron/PicoAudioPWM\ncd PicoAudioPWM\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#download-some-test-robot-wav-files","title":"Download some test robot wav files","text":"

                                                                                                                                                                                                                                                                                                              The following GitHub location:

                                                                                                                                                                                                                                                                                                              https://github.com/CoderDojoTC/robot-media/tree/master/wav-8k

                                                                                                                                                                                                                                                                                                              contains a set of 8K Hz 16 bit robot sounds that you can use with your robot.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#converting-mp3-to-wav-files","title":"Converting .MP3 to .WAV files","text":"

                                                                                                                                                                                                                                                                                                              This software only currently support playing .wav files since it is easy to convert these files into a format that can be played. WAV files store uncompressed audio, so they are larger than MP3 files. Wav files are simple ways to store sound patterns. MP3 files are much more complex and require complex algorithms to convert into sound outputs.

                                                                                                                                                                                                                                                                                                              The usual bitstream encoding is the linear pulse-code modulation (LPCM) format.

                                                                                                                                                                                                                                                                                                              If you have just a few MP3 files, can use the following web-site to convert MP3 files into wave files:

                                                                                                                                                                                                                                                                                                              Cloud Convert Service that Converts MP3 to WAV files

                                                                                                                                                                                                                                                                                                              The next lab shows you how to convert an entire folder of MP3 files to 8K Hz 16-bit WAV files using a shell script.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#copy-sound-files-to-the-pico","title":"Copy Sound Files to the Pico","text":"

                                                                                                                                                                                                                                                                                                              Your pico has 2MB of static memory. A typical robot sound effect you want to play when you bump into and object will play for around 1 second. You can copy many sound effect files to the pico file system and play them. Some IDEs may allow you to do this or you can use the rshell program.

                                                                                                                                                                                                                                                                                                              Here is an example of using the rshell program to copy a directory of wav files to the pico. Lines that start with pc$ are commands that you type into your PC or MAC's terminal. Lines that start with rs$ are commands that you type into the rshell.

                                                                                                                                                                                                                                                                                                              # list the devices (only works on Mac and UNIX)\npc$ ls /dev/cu.modem*\n# start the rshell\npc$ rshell -p /dev/cu.modem*\n# change the name of the device to be \"pico\"\nrs$ echo 'name=\"pico\"' > /pyboard/board.py\n# exit from rshell - can also use exit\nCONTROL-C\n# reconnect with the rshell\n$pc rshell -p /dev/cu.modem*\n# go into the /pico file systems\n$rs cd /pico\n# create a directory for all our sound files\nmkdir sounds\n# copy files from hour PC's home ~/tmp/sounds dir to the pico\nrs$ cp ~/tmp/sounds/*.wav /pico/sounds\nrs$ ls /pico/sounds\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#listing-the-wave-files","title":"Listing the Wave Files","text":"

                                                                                                                                                                                                                                                                                                              After you have a list of Wave files loaded you can verify them by using the os listdir() function.

                                                                                                                                                                                                                                                                                                              import os\n\nwaveFolder= \"/sounds\"\nwavelist = []\n\n# get a list of .wav files\nfor i in os.listdir(waveFolder):\n    if i.find(\".wav\")>=0:\n        wavelist.append(waveFolder+\"/\"+i)\n    elif i.find(\".WAV\")>=0:\n        wavelist.append(waveFolder+\"/\"+i)\n\nif not wavelist :\n    print(\"Warning NO '.wav' files\")\nelse:\n    for i in wavelist:\n        print(i)\n

                                                                                                                                                                                                                                                                                                              Sample console output

                                                                                                                                                                                                                                                                                                              /sounds/cylon-attention.wav\n/sounds/cylon-by-your-command.wav\n/sounds/cylon-excellent.wav\n/sounds/cylon-eye-scanner.wav\n/sounds/cylon-see-that-the-humans.wav\n/sounds/cylon-those-are-not-the-sounds.wav\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#checking-the-wav-file-format","title":"Checking the WAV File Format","text":"

                                                                                                                                                                                                                                                                                                              There is a standard Python module called `wave.py that reads the .wav files and shows the metadata for the file. Wave files come in many formats, single channel, stereo and different bit rates. The wave player can show us all this data that describes the wave file.

                                                                                                                                                                                                                                                                                                              The report shows you how to use fixed-width formatting since the file names and data should fit in columns to make it easier to read.

                                                                                                                                                                                                                                                                                                              import os\nimport wave\n\nwaveFolder= \"/sounds\"\nwavelist = []\n\n# get a list of .wav files\nfor i in os.listdir(waveFolder):\n    if i.find(\".wav\")>=0:\n        wavelist.append(waveFolder+\"/\"+i)\n    elif i.find(\".WAV\")>=0:\n        wavelist.append(waveFolder+\"/\"+i)\n\nif not wavelist :\n    print(\"Warning NO '.wav' files\")\nelse:\n    print(\"{0:<45}\".format('File Path'), 'Frame Rate  Width Chans Frames')\n    for filename in wavelist:\n        f = wave.open(filename,'rb')\n        # the format string \"{0:<50}\" says print left justified from chars 0 to 50 in a fixed with string\n        print(\"{0:<50}\".format(filename),\n              \"{0:>5}\".format(f.getframerate()),\n              \"{0:>5}\".format(f.getsampwidth()),\n              \"{0:>6}\".format(f.getnchannels()),\n              \"{0:>6}\".format(f.getnframes())\n              )\n

                                                                                                                                                                                                                                                                                                              Sample Response

                                                                                                                                                                                                                                                                                                              File Path                                     Frame Rate  Width Chans Frames\n/sounds/cylon-attention.wav                         8000     1      1   6399\n/sounds/cylon-by-your-command.wav                  11025     1      1  12583\n/sounds/cylon-excellent.wav                        22050     1      1  48736\n/sounds/cylon-eye-scanner.wav                      16000     2      2  24768\n/sounds/cylon-see-that-the-humans.wav              11025     1      1  30743\n/sounds/cylon-those-are-not-the-sounds.wav         22050     1      1  64137\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#adding-an-interrupt","title":"Adding an Interrupt","text":"

                                                                                                                                                                                                                                                                                                              If you halt the RP2040 while it is playing a sound, the independent PWM controllers will continue to generate sound. In order to shut the independent PWM controllers, an interrupt controller system must be used to cleanly disable all the sound. Here is an example of this using a try/except block of code.

                                                                                                                                                                                                                                                                                                              import os as uos\nfrom wavePlayer import wavePlayer\nplayer = wavePlayer()\n\ntry:\n    while True:\n        # repeat this over and over until the keyboard shuts down the circuit\n        player.play('/sounds/cylon-eye-scanner.wav')\nexcept KeyboardInterrupt:\n    player.stop()\n    print(\"wave player terminated\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#playing-the-same-sound-repeatedly","title":"Playing the Same Sound Repeatedly","text":"
                                                                                                                                                                                                                                                                                                              import os as uos\nfrom wavePlayer import wavePlayer\nplayer = wavePlayer()\n\ntry:\n    while True:\n        player.play('/sounds/cylon-eye-scanner.wav')\nexcept KeyboardInterrupt:\n    player.stop()\n    print(\"wave player terminated\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#downloading-the-audio-libraries","title":"Downloading the Audio Libraries","text":"

                                                                                                                                                                                                                                                                                                              Both the wave.py and the chunck.py files are here:

                                                                                                                                                                                                                                                                                                              https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07-play-audio-file/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. Daniel Perron
                                                                                                                                                                                                                                                                                                              2. Wikipedia page for Wave Filec
                                                                                                                                                                                                                                                                                                              3. Web-Based Audio Conversion Service Convertio
                                                                                                                                                                                                                                                                                                              4. Wikipedia page for Audio Interchange File Format
                                                                                                                                                                                                                                                                                                              5. Wikipedia page for Pulse-code Modulation
                                                                                                                                                                                                                                                                                                              6. Raspberry Pi Pico Forum on Sounds Files
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07a-test-audio-ports/","title":"Testing Audio Ports","text":"

                                                                                                                                                                                                                                                                                                              In this lab, we will be testing stereo audio ports. We will be sending a 1 kilohertz square wave to the left and then right ports. This program allows you to test your stereo connections and make sure that both channels are working correctly.

                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM\nfrom utime import sleep\n\n# You will need to configure these two digital output ports\nAUDIO_LEFT_PIN = 18\nAUDIO_RIGHT_PIN = 19\n\n# create a Pulse Width Modulation Object on this pin\nleft_speaker = PWM(Pin(AUDIO_LEFT_PIN))\n# set the duty cycle to be 50%\nleft_speaker.duty_u16(1000)\nleft_speaker.freq(1000) # 50% on and off\nsleep(1) # wait a second\nleft_speaker.duty_u16(0)\n# turn off the PWM circuits off with a zero duty cycle\nleft_speaker.duty_u16(0)\nsleep(1)\n\n# create a Pulse Width Modulation Object on this pin\nright_speaker = PWM(Pin(AUDIO_RIGHT_PIN))\n# set the duty cycle to be 50%\nright_speaker.duty_u16(1000)\nright_speaker.freq(1000) # 50% on and off\nsleep(1) # wait a second\nright_speaker.duty_u16(0)\n# turn off the PWM circuits off with a zero duty cycle\nright_speaker.duty_u16(0)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/07a-test-audio-ports/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              https://en.wikipedia.org/wiki/Phone_connector_(audio)#Computer_sound

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/08-i2s-standard/","title":"I2S Standard","text":"

                                                                                                                                                                                                                                                                                                              I2S (Inter-IC Sound) pronounced \"eye-two-ess\", is an electrical serial bus interface standard used for connecting digital audio devices together. It is a general interface to communicate PCM audio data between integrated circuits in an electronic device.

                                                                                                                                                                                                                                                                                                              Note that I2S is unrelated to the similar sounding I2C bus protocol.

                                                                                                                                                                                                                                                                                                              Since MicroPython 1.17 we have a library that allows us to play

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/","title":"Converting MP3 to WAV formats","text":"

                                                                                                                                                                                                                                                                                                              In last lab we will learned how to play an audio file stored on the flash memory or SD card. We used an early version of a Python module that plays .WAV files in a fixed format: 8,000 samples per second using 16-bit encoding. Because there are hundreds of different formats of audio files, we need a consistent way to convert all of these formats to 8K samples/second 16-bit .WAV formats.

                                                                                                                                                                                                                                                                                                              The audio data file conversions are done on your host PC, not the microcontroller. This allows us to use a rich library of tools that don't need to run on our microcontroller.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#method-1-use-the-ffmpeg-command-line-tool","title":"Method 1: Use the ffmpeg Command Line Tool","text":"

                                                                                                                                                                                                                                                                                                              One of the easiest ways to get started is to go to the web site ffmpeg.org and download the program that does the conversion using a command line. Note that on a Mac you will need to go into your System Preferences and indicate that the following programs are trusted:

                                                                                                                                                                                                                                                                                                              Here are the direct links for MacOS

                                                                                                                                                                                                                                                                                                              1. ffmpeg (mac)
                                                                                                                                                                                                                                                                                                              2. ffprobe (mac)
                                                                                                                                                                                                                                                                                                              3. ffplay (mac)

                                                                                                                                                                                                                                                                                                              This will download a zip file which you will need to unzip and place in a location such as ~/bin. After you do this make sure you add `~/bin to your path by adding the following file to your .bash_profile:

                                                                                                                                                                                                                                                                                                              PATH=$PATH:~/bin

                                                                                                                                                                                                                                                                                                              After you source your .bash_profile type in the following:

                                                                                                                                                                                                                                                                                                              which ffmpeg

                                                                                                                                                                                                                                                                                                              This should return the location that it finds the ffmpeg shell script. You can then see the many file-format MPEG options:

                                                                                                                                                                                                                                                                                                              ffmpeg --help

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#converting-mp3-to-8k-16-bit-wav-files","title":"Converting MP3 to 8K 16 bit WAV Files","text":"

                                                                                                                                                                                                                                                                                                              To get the format we need for the MicroPython wave player class we just specific -i for the input file and use the -ar 8000 to specify the output bit rate of 8K samples per second. The final parameter is a file name that must in .wav so the command knows to use WAV PCM encoding. The default value is 16 gits per sample.

                                                                                                                                                                                                                                                                                                              ffmpeg -i r2d2-beeping.mp3 -ar 8000 r2d2-beeping-8k.wav\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#bulk-conversions","title":"Bulk Conversions","text":"

                                                                                                                                                                                                                                                                                                              We can use unix shell commands to do a batch conversion of all the . The following is an example of using awk and sed to convert all the .mp3 files in a directory and convert them to 8K Hz WAV files and put them in a sibling directory.

                                                                                                                                                                                                                                                                                                              ls -1 *.mp3 | awk '{print \"ffmpeg -i \" $1 \" -ar 8000 ../wav-8k/\"$1}' | sed s/mp3$/wav/ | sh\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#inspect-the-files-using-the-unix-file-command","title":"Inspect the Files Using the UNIX file command:","text":"
                                                                                                                                                                                                                                                                                                              cd ../wav-8k\nfile *.wav\n

                                                                                                                                                                                                                                                                                                              returns

                                                                                                                                                                                                                                                                                                              r2d2-another-beep.wav:          RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-beeping-2.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-beeping-4.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-beeping-8k.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-beeping-like-an-alarm.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-beeping.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-cheerful.wav:              RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-determined.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-excited.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-laughing.wav:              RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-more-chatter.wav:          RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-processing.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-sad.wav:                   RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-shocked.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-surprised.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-taking-to-himself.wav:     RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\nr2d2-unsure.wav:                RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz\n

                                                                                                                                                                                                                                                                                                              Note that these are WAVE audio, Pulse-code Modulated (PCM), 16 bit and mono at 8K Hz.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#method-2-use-the-pydub-python-module","title":"Method 2: Use the pydub Python Module","text":"

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              This section is only for experienced Python developers.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#install-conda-and-the-python-libraries","title":"Install Conda and the Python libraries","text":"
                                                                                                                                                                                                                                                                                                              conda create -n mp3-to-wav python=3\nconda activate mp3-to-wav\npip install pydub ffprobe ffmpeg\n

                                                                                                                                                                                                                                                                                                              Check your versions:

                                                                                                                                                                                                                                                                                                              pip freeze\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              ffmpeg==1.4\nffprobe==0.5\npydub==0.25.1\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#running-pydub","title":"Running pydub","text":"
                                                                                                                                                                                                                                                                                                              from pydub import AudioSegment\n\nsound = AudioSegment.from_mp3(\"r2d2-beeping.mp3\")\nsound.export(\"r2d2-beeping.wav\", format=\"wav\", tags={'Robot name': 'R2D2'})\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#transferring-the-files-with-rshell","title":"Transferring the Files with Rshell","text":"
                                                                                                                                                                                                                                                                                                              cd ../wav-8k\nrshell -p /dev/cu.usbmodem14101\ncp *.wav /pico/sounds\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/09-converting-mp3-to-wav/#references","title":"References","text":"
                                                                                                                                                                                                                                                                                                              1. PyDub Documentation
                                                                                                                                                                                                                                                                                                              2. File Formats for Audio from MPEG
                                                                                                                                                                                                                                                                                                              3. File Formats for motion picture experts group Python Library
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/10-midi/","title":"MIDI with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              Warnining

                                                                                                                                                                                                                                                                                                              I am not an expert on MIDI and I don't have any MIDI gear. This is mostly a collection of material I have for students that want to use MicroPython to generate music.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/10-midi/#sample-code","title":"Sample Code","text":""},{"location":"sound/10-midi/#ascending-notes","title":"Ascending Notes","text":"
                                                                                                                                                                                                                                                                                                              # Play Test MIDI Ascending Notes\nfrom machine import Pin, UART\nimport time\nuart = UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5))\nuart.init(bits=8, parity=None, stop=1)\nled=Pin(\"LED\", Pin.OUT)\nnote = 24\n\nwhile True:\n    midimessage = bytearray([0x90, note, 64])\n    uart.write(midimessage)\n    led.toggle()\n    # change third parameter to be 0\n    midimessage = bytearray([0x90, note, 0])\n    # pause 1/8 of a second\n    time.sleep(0.125)\n    note += 2\n    if note > 64:\n        note=24\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/10-midi/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Raspberry Pi Pico MIDI Development Board Midimuso for $20 US. This board has all the MIDI connectors on it.

                                                                                                                                                                                                                                                                                                              Simple DIY electromusic Project

                                                                                                                                                                                                                                                                                                              DIY Electro Music SDEMP MicroPython Code on GitHub

                                                                                                                                                                                                                                                                                                              Pico MIDI by Barb Arach

                                                                                                                                                                                                                                                                                                              PicoMIDI manual v1.0

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/11-sound-parts/","title":"Sound Parts","text":"
                                                                                                                                                                                                                                                                                                              • PAM8302A Miniature 2.5W Class D Mono Audio Power Amplifier Module Board

                                                                                                                                                                                                                                                                                                              • PAM8302A 10pcs

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/","title":"The I2S Bus","text":"

                                                                                                                                                                                                                                                                                                              The I2S (Inter-IC Sound) bus on the Raspberry Pi Pico is a versatile and high-quality interface for digital audio. Here are some compelling reasons to use it:

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#1-high-quality-digital-audio","title":"1. High-Quality Digital Audio","text":"
                                                                                                                                                                                                                                                                                                              • I2S allows for precise, lossless transfer of digital audio between devices, ensuring superior sound quality compared to analog signals that are susceptible to noise and distortion.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#2-low-pin-usage","title":"2. Low Pin Usage","text":"
                                                                                                                                                                                                                                                                                                              • I2S requires only a few pins to transmit high-quality audio data. This leaves other GPIO pins available for additional peripherals or projects.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#3-stereo-audio-support","title":"3. Stereo Audio Support","text":"
                                                                                                                                                                                                                                                                                                              • The I2S bus can handle stereo audio, making it ideal for projects requiring left and right channels, such as music players, audio recorders, or sound-based art installations.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#4-ease-of-integration-with-digital-audio-components","title":"4. Ease of Integration with Digital Audio Components","text":"
                                                                                                                                                                                                                                                                                                              • Many digital audio devices, such as DACs (Digital-to-Analog Converters), ADCs (Analog-to-Digital Converters), and codecs, natively support I2S. This simplifies the integration of audio into your projects.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#5-reduced-audio-interference","title":"5. Reduced Audio Interference","text":"
                                                                                                                                                                                                                                                                                                              • By keeping the audio in the digital domain until it reaches the final output stage (e.g., DAC), I2S reduces the risk of electromagnetic interference that analog signals might pick up.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#6-support-for-advanced-audio-formats","title":"6. Support for Advanced Audio Formats","text":"
                                                                                                                                                                                                                                                                                                              • I2S can transmit audio at various sample rates and bit depths (e.g., 16-bit, 24-bit), enabling support for high-fidelity audio formats used in modern applications.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#7-ideal-for-audio-projects","title":"7. Ideal for Audio Projects","text":"

                                                                                                                                                                                                                                                                                                              The I2S interface is perfect for: - Building audio streaming devices. - Implementing DIY digital radios or podcast recording setups. - Creating smart speakers or voice assistants.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#8-integration-with-micropython","title":"8. Integration with MicroPython","text":"
                                                                                                                                                                                                                                                                                                              • The Raspberry Pi Pico's support for MicroPython and C/C++ makes it easy to work with I2S in a high-level programming environment, reducing development complexity.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#9-applications-in-education-and-prototyping","title":"9. Applications in Education and Prototyping","text":"
                                                                                                                                                                                                                                                                                                              • For educational purposes, I2S offers an opportunity to learn about digital audio processing and signal transmission. It also facilitates prototyping of commercial audio equipment.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#example-applications","title":"Example Applications","text":"
                                                                                                                                                                                                                                                                                                              • DIY Digital Audio Player: Combine an I2S DAC with an SD card reader to create a custom MP3 or FLAC player.
                                                                                                                                                                                                                                                                                                              • Audio Signal Processing: Capture audio with an I2S ADC for real-time signal analysis or effects processing.
                                                                                                                                                                                                                                                                                                              • Voice Recognition Systems: Use I2S microphones for clear audio input in speech-to-text or voice control projects.

                                                                                                                                                                                                                                                                                                              The inclusion of I2S on the Raspberry Pi Pico opens up a world of opportunities for high-quality, efficient, and versatile audio processing in your projects.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#robot-sounds-project","title":"Robot Sounds Project","text":"

                                                                                                                                                                                                                                                                                                              Here we describe a simple project that plays robot sound files on the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#project-robot-sound-player-on-raspberry-pi-pico","title":"Project: Robot Sound Player on Raspberry Pi Pico","text":"

                                                                                                                                                                                                                                                                                                              This project will use the Raspberry Pi Pico with an I2S DAC to play pre-recorded robot sound files (e.g., \"beeps,\" \"boops,\" \"affirmative,\" \"error\") stored on a microSD card. The sounds will be triggered using a button or slider switch.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#components-needed","title":"Components Needed","text":"
                                                                                                                                                                                                                                                                                                              1. Raspberry Pi Pico (with headers for easy wiring)
                                                                                                                                                                                                                                                                                                              2. I2S DAC Module (e.g., PCM5102)
                                                                                                                                                                                                                                                                                                              3. MicroSD Card Module (for storing sound files)
                                                                                                                                                                                                                                                                                                              4. Speaker (connected to the DAC)
                                                                                                                                                                                                                                                                                                              5. Push Button or Slider Switch (to trigger sound effects)
                                                                                                                                                                                                                                                                                                              6. Wires and Breadboard
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#steps-to-build","title":"Steps to Build","text":""},{"location":"sound/20-i2s-bus/#1-prepare-the-sound-files","title":"1. Prepare the Sound Files","text":"
                                                                                                                                                                                                                                                                                                              • Convert your robot sound files to a compatible format like 16-bit PCM WAV files at 44.1 kHz.
                                                                                                                                                                                                                                                                                                              • Store the WAV files on a microSD card with filenames like robot1.wav, robot2.wav.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#2-connect-the-components","title":"2. Connect the Components","text":""},{"location":"sound/20-i2s-bus/#microsd-module-to-pico","title":"MicroSD Module to Pico","text":"
                                                                                                                                                                                                                                                                                                              • VCC \u2192 Pico 3.3V
                                                                                                                                                                                                                                                                                                              • GND \u2192 Pico GND
                                                                                                                                                                                                                                                                                                              • MISO \u2192 Pico GP16
                                                                                                                                                                                                                                                                                                              • MOSI \u2192 Pico GP19
                                                                                                                                                                                                                                                                                                              • SCK \u2192 Pico GP18
                                                                                                                                                                                                                                                                                                              • CS \u2192 Pico GP17
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#i2s-dac-to-pico","title":"I2S DAC to Pico","text":"
                                                                                                                                                                                                                                                                                                              • BCK \u2192 Pico GP10
                                                                                                                                                                                                                                                                                                              • LRCK \u2192 Pico GP11
                                                                                                                                                                                                                                                                                                              • DIN \u2192 Pico GP9
                                                                                                                                                                                                                                                                                                              • GND \u2192 Pico GND
                                                                                                                                                                                                                                                                                                              • VCC \u2192 Pico 3.3V or 5V (depending on the module)
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#speaker-to-dac","title":"Speaker to DAC**:","text":"
                                                                                                                                                                                                                                                                                                              -   Connect the speaker output from the DAC module to your speaker terminals.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#button-to-pico","title":"Button to Pico:**","text":"
                                                                                                                                                                                                                                                                                                              -   One side of the button \u2192 Pico `GP14`\n-   Other side of the button \u2192 `GND`\n-   Use a 10K pull-up resistor from `GP14` to `3.3V`.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#3-install-the-required-software","title":"3. Install the Required Software","text":"
                                                                                                                                                                                                                                                                                                              • Install MicroPython on your Pico.
                                                                                                                                                                                                                                                                                                              • Upload libraries for:
                                                                                                                                                                                                                                                                                                                • I2S Audio Playback: E.g., i2s_audio.py
                                                                                                                                                                                                                                                                                                                • SD Card Access: uos or os module with MicroPython SD card libraries.
                                                                                                                                                                                                                                                                                                              • Format the microSD card as FAT32.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#4-write-the-code","title":"4. Write the Code","text":"

                                                                                                                                                                                                                                                                                                              Below is an example MicroPython code for playing sound files using a button trigger:

                                                                                                                                                                                                                                                                                                              from machine import Pin, I2S, SPI\nimport uos\n\n# Initialize I2S for DAC\naudio_out = I2S(\n    0,\n    sck=Pin(10),   # Bit clock\n    ws=Pin(11),    # Word select\n    sd=Pin(9),     # Serial data\n    mode=I2S.TX,\n    bits=16,\n    format=I2S.MONO,\n    rate=44100\n)\n\n# Initialize SD Card\nspi = SPI(0, sck=Pin(18), mosi=Pin(19), miso=Pin(16))\nsd_cs = Pin(17, Pin.OUT)\nuos.mount(SDCard(spi, sd_cs), \"/sd\")\n\n# Button Input\nbutton = Pin(14, Pin.IN, Pin.PULL_UP)\n\ndef play_sound(file_path):\n    with open(file_path, \"rb\") as wav:\n        wav.seek(44)  # Skip WAV header\n        while True:\n            buf = wav.read(2048)\n            if not buf:\n                break\n            audio_out.write(buf)\n\nprint(\"Ready to play robot sounds!\")\nwhile True:\n    if not button.value():  # Button pressed\n        print(\"Playing sound!\")\n        play_sound(\"/sd/robot1.wav\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#5-test-the-setup","title":"5. Test the Setup","text":"
                                                                                                                                                                                                                                                                                                              • Power up the Pico.
                                                                                                                                                                                                                                                                                                              • Press the button to trigger playback of robot1.wav.
                                                                                                                                                                                                                                                                                                              • Swap out files or add more buttons to trigger additional sounds.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#extensions","title":"Extensions","text":"
                                                                                                                                                                                                                                                                                                              1. Multiple Buttons: Add more buttons to trigger different sound effects.
                                                                                                                                                                                                                                                                                                              2. Random Playback: Use the random module to pick a random sound from the SD card.
                                                                                                                                                                                                                                                                                                              3. Interactive Robot: Connect the sound system to sensors (e.g., distance or light sensors) to play sounds based on environmental triggers.

                                                                                                                                                                                                                                                                                                              This project is an engaging way to learn about I2S, digital audio, and MicroPython, while creating a fun and interactive robot sound player!

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#storing-the-sounds-on-the-picos-flash-memory","title":"Storing the Sounds on the Pico's Flash Memory","text":"

                                                                                                                                                                                                                                                                                                              We can store the sound files on the Raspberry Pi Pico's internal flash memory instead of using an external microSD card. However, there are a few considerations and limitations to keep in mind:

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#considerations-for-storing-sounds-in-flash-memory","title":"Considerations for Storing Sounds in Flash Memory","text":""},{"location":"sound/20-i2s-bus/#limited-flash-storage-space","title":"Limited Flash Storage Space","text":"
                                                                                                                                                                                                                                                                                                              • The Raspberry Pi Pico has 2 MB of onboard flash memory, which is shared with the MicroPython firmware and your code.
                                                                                                                                                                                                                                                                                                              • Sound files (e.g., WAV) can be quite large, so you'll need to ensure the files fit within the available space.
                                                                                                                                                                                                                                                                                                              • Use compressed or low-bitrate audio formats if possible (e.g., 8-bit, mono, low sample rate).
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#file-size-and-format","title":"File Size and Format","text":"
                                                                                                                                                                                                                                                                                                              • A typical PCM WAV file at 16-bit, 44.1 kHz uses ~88 KB per second of audio. Consider using a lower sample rate (e.g., 8 kHz) to save space.
                                                                                                                                                                                                                                                                                                              • Mono sound files consume less space than stereo.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#loading-files-into-flash","title":"Loading Files into Flash**","text":"
                                                                                                                                                                                                                                                                                                              • Store the audio files in the Pico's filesystem (accessible via MicroPython) by uploading them using a file transfer tool like Thonny or a command-line tool like ampy.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#playback-speed","title":"Playback Speed","text":"
                                                                                                                                                                                                                                                                                                              • Flash memory access is slower than an I2S DAC with buffered SD card reading. For short sound clips, this isn't usually an issue.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#steps-to-store-and-play-sounds-from-flash","title":"Steps to Store and Play Sounds from Flash","text":""},{"location":"sound/20-i2s-bus/#1prepare-the-sound-files","title":"1.Prepare the Sound Files","text":"
                                                                                                                                                                                                                                                                                                              • Convert your sound files to a smaller format:
                                                                                                                                                                                                                                                                                                                • Mono, 8-bit PCM WAV
                                                                                                                                                                                                                                                                                                                • Sample rate: 8 kHz or 16 kHz
                                                                                                                                                                                                                                                                                                              • Example tools for conversion:
                                                                                                                                                                                                                                                                                                                • Audacity
                                                                                                                                                                                                                                                                                                                • ffmpeg command-line tool:
                                                                                                                                                                                                                                                                                                              ffmpeg -i input.wav -ar 16000 -ac 1 -b:a 8k output.wav\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#2-upload-files-to-pico","title":"2. Upload Files to Pico","text":"
                                                                                                                                                                                                                                                                                                              • Open the Thonny IDE.
                                                                                                                                                                                                                                                                                                              • Connect your Pico.
                                                                                                                                                                                                                                                                                                              • In the File Explorer, upload your WAV file(s) to the Pico's flash memory.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#3-micropython-code-for-playback","title":"3. MicroPython Code for Playback","text":"
                                                                                                                                                                                                                                                                                                              • Below is an example code to play a short WAV file stored in the Pico's flash memory:
                                                                                                                                                                                                                                                                                                              from machine import I2S, Pin\n\n# Initialize I2S for DAC\naudio_out = I2S(\n    0,\n    sck=Pin(10),   # Bit clock\n    ws=Pin(11),    # Word select\n    sd=Pin(9),     # Serial data\n    mode=I2S.TX,\n    bits=16,\n    format=I2S.MONO,\n    rate=16000  # Match the WAV file's sample rate\n)\n\ndef play_sound(file_path):\n    try:\n        with open(file_path, \"rb\") as wav:\n            wav.seek(44)  # Skip WAV header\n            while True:\n                buf = wav.read(2048)\n                if not buf:\n                    break\n                audio_out.write(buf)\n    except Exception as e:\n        print(f\"Error playing sound: {e}\")\n\n# Play the sound file stored on the Pico\nprint(\"Playing robot sound...\")\nplay_sound(\"robot1.wav\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#4-optimize-and-test","title":"4. Optimize and Test","text":"
                                                                                                                                                                                                                                                                                                              • Use uos.listdir() to list files stored in flash memory.
                                                                                                                                                                                                                                                                                                              • Ensure the file format matches the I2S configuration (e.g., 8-bit or 16-bit, mono or stereo).
                                                                                                                                                                                                                                                                                                              • Test playback and confirm there are no buffer underruns.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#advantages","title":"Advantages","text":"
                                                                                                                                                                                                                                                                                                              • Eliminates the need for external storage hardware (microSD card module).
                                                                                                                                                                                                                                                                                                              • Simpler wiring and lower cost.
                                                                                                                                                                                                                                                                                                              • Suitable for small, self-contained projects where a few short sound clips are needed.
                                                                                                                                                                                                                                                                                                              "},{"location":"sound/20-i2s-bus/#limitations","title":"Limitations","text":"
                                                                                                                                                                                                                                                                                                              • Limited storage for audio files.
                                                                                                                                                                                                                                                                                                              • Requires careful management of the flash memory to avoid overwriting important files or the firmware.

                                                                                                                                                                                                                                                                                                              For projects with just a few short robot sound effects, storing the sounds on the Pico's flash memory is a practical and convenient option.

                                                                                                                                                                                                                                                                                                              "},{"location":"sound/dac/","title":"Using a Digital to Analog Converter","text":""},{"location":"wireless/01-intro/","title":"Introduction to Networking with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              These lessons are designed to give our students an understanding of how wireless communications work with MicroPython.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/01-intro/#raspberry-pi-pico-w","title":"Raspberry Pi Pico W","text":"

                                                                                                                                                                                                                                                                                                              One June 30th, 2022 the Raspberry Pi Foundation announced the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth.

                                                                                                                                                                                                                                                                                                              The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the lwip TCP/IP stack. This stack is accessible using the MicroPython network functions.

                                                                                                                                                                                                                                                                                                              The WiFi chip used is the Infineon CYW43439 chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication.

                                                                                                                                                                                                                                                                                                              You can read more about the capabilities of the WiFi/Bluetooth chip by reading the Infineon CYW43439 Datasheet. I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains!

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/01-intro/#esp32-wireless","title":"ESP32 Wireless","text":"

                                                                                                                                                                                                                                                                                                              We have not integrated the ESP32 into our labs. We suggest you try the following links:

                                                                                                                                                                                                                                                                                                              ESP32 MicroPython: Connecting to a WiFi Network on Tech Tutorials SX

                                                                                                                                                                                                                                                                                                              MicroPython: Wi-Fi Manager with ESP32 (ESP8266 compatible) on Random Nerd Tutorials

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/02-connecting-to-wifi/","title":"Connecting to a WiFi Network","text":""},{"location":"wireless/02-connecting-to-wifi/#setting-up-your-wifi-secretspy","title":"Setting Up Your WIFI secrets.py","text":"

                                                                                                                                                                                                                                                                                                              By convention, we put both our SSID and password in a python file called \"secrets.py\". This file should never be checked into a public source code repository. We can add secrets.py to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone.

                                                                                                                                                                                                                                                                                                              SSID = \"MY_WIFI_NETWORK_NAME\"\nPASSWORD = \"MY_WIFI_PASSWORD\"\n

                                                                                                                                                                                                                                                                                                              By importing the secrets.py file you can then reference your network name like this:

                                                                                                                                                                                                                                                                                                              print('Connecting to WiFi Network Name:', secrets.SSID)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/02-connecting-to-wifi/#testing-your-wifi-access-point-connection","title":"Testing Your WiFi Access Point Connection","text":"

                                                                                                                                                                                                                                                                                                              Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable.

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True) # power up the WiFi chip\nprint('Waiting for wifi chip to power up...')\nsleep(3) # wait three seconds for the chip to power up and initialize\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nprint('Waiting for access point to log us in.')\nsleep(2)\nif wlan.isconnected():\n  print('Success! We have connected to your access point!')\n  print('Try to ping the device at', wlan.ifconfig()[0])\nelse:\n  print('Failure! We have not connected to your access point!  Check your secrets.py file for errors.')\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME\nWaiting for wifi chip to power up...\nWaiting for access point to log us in...\nSuccess! We have connected to your access point!\nTry to ping the device at 10.0.0.70\n

                                                                                                                                                                                                                                                                                                              If the result is a Failure you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing.

                                                                                                                                                                                                                                                                                                              Note that we are using the sleep() function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/02-connecting-to-wifi/#waiting-for-a-valid-access-point-connection","title":"Waiting for a Valid Access Point Connection","text":"

                                                                                                                                                                                                                                                                                                              Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected.

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nstart = ticks_ms() # start a millisecond counter\n\nif not wlan.isconnected():\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    while not wlan.isconnected():\n        sleep(1)\n        print(counter, '.', sep='', end='', )\n        counter += 1\n\ndelta = ticks_diff(ticks_ms(), start)\nprint(\"Connect Time:\", delta, 'milliseconds')\nprint('IP Address:', wlan.ifconfig()[0])\n

                                                                                                                                                                                                                                                                                                              This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds.

                                                                                                                                                                                                                                                                                                              First run upon power on might take several seconds:

                                                                                                                                                                                                                                                                                                              >>> %Run -c $EDITOR_CONTENT\nConnecting to WiFi Network Name: MY_NETWORK_NAME\nWaiting for connection...\n0.1.2.3.Connect Time: 4640\nIP Address: 10.0.0.70\n

                                                                                                                                                                                                                                                                                                              The second and consecutive runs will use a cached connection.

                                                                                                                                                                                                                                                                                                              >>> %Run -c $EDITOR_CONTENT\nConnecting to WiFi Network Name: MY_NETWORK_NAME\nConnect Time: 0 milliseconds\nIP Address: 10.0.0.70\n>>>\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/02-connecting-to-wifi/#error-handling","title":"Error Handling","text":"
                                                                                                                                                                                                                                                                                                              lan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(ssid, password)\n\n# Wait for connect or fail\nmax_wait = 10\nwhile max_wait > 0:\n  if wlan.status() < 0 or wlan.status() >= 3:\n    break\n  max_wait -= 1\n  print('waiting for connection...')\n  time.sleep(1)\n\n# Handle connection error\nif wlan.status() != 3:\n   raise RuntimeError('network connection failed')\nelse:\n  print('connected')\n  status = wlan.ifconfig()\n  print( 'ip = ' + status[0] )\n

                                                                                                                                                                                                                                                                                                              The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/03-http-get/","title":"HTTP GET","text":""},{"location":"wireless/03-http-get/#testing-http-get","title":"Testing HTTP GET","text":"

                                                                                                                                                                                                                                                                                                              The following example was taken from Tom's Hardware

                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\nimport urequests\n\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\n\nstart = ticks_ms() # start a millisecond counter\n\nastronauts = urequests.get(\"http://api.open-notify.org/astros.json\").json()\n\ndelta = ticks_diff(ticks_ms(), start)\n\nnumber = astronauts['number']\nprint('There are', number, 'astronauts in space.')\nfor i in range(number):\n    print(i+1, astronauts['people'][i]['name'])\n\nprint(\"HTTP GET Time in milliseconds:\", delta)\n

                                                                                                                                                                                                                                                                                                              Returns:

                                                                                                                                                                                                                                                                                                              There are 10 astronauts in space.\n1 Oleg Artemyev\n2 Denis Matveev\n3 Sergey Korsakov\n4 Kjell Lindgren\n5 Bob Hines\n6 Samantha Cristoforetti\n7 Jessica Watkins\n8 Cai Xuzhe\n9 Chen Dong\n10 Liu Yang\nHTTP GET Time in milliseconds: 786\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/04-web-server/","title":"Web Server with MicroPython","text":"

                                                                                                                                                                                                                                                                                                              This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off.

                                                                                                                                                                                                                                                                                                              Screen image of Pico W Web Server:

                                                                                                                                                                                                                                                                                                              # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/\nimport network\nimport socket\nimport time\nimport secrets\n\nfrom machine import Pin\n\n# Select the onboard LED\nled = machine.Pin(\"LED\", machine.Pin.OUT)\n\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nstateis = \"LED is OFF\"\n\nhtml = \"\"\"<!DOCTYPE html>\n<html>\n   <head>\n     <title>Web Server On Pico W </title>\n   </head>\n  <body>\n      <h1>Pico Wireless Web Server</h1>\n      <p>%s</p>\n      <a href=\"/light/on\">Turn On</a>\n      <a href=\"/light/off\">Turn Off</a>\n  </body>\n</html>\n\"\"\"\n\n# Wait for connect or fail\nmax_wait = 10\nwhile max_wait > 0:\n  if wlan.status() < 0 or wlan.status() >= 3:\n    break\n  max_wait -= 1\n  print('waiting for connection...')\n  time.sleep(1)\n\n# Handle connection error\nif wlan.status() != 3:\n  raise RuntimeError('network connection failed')\nelse:\n  print('We are connected to WiFI access point:', secrets.SSID)\n  status = wlan.ifconfig()\n  print( 'The IP address of the pico W is:', status[0] )\n\n# Open socket\naddr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]\nprint('addr:', addr)\ns = socket.socket()\n#if not addr:\ns.bind(addr)\ns.listen(1)\n\nprint('listening on', addr)\n\n# Listen for connections\nwhile True:\n  try:\n    cl, addr = s.accept()\n    print('client connected from', addr)\n    request = cl.recv(1024)\n    print(request)\n    request = str(request)\n    led_on = request.find('/light/on')\n    led_off = request.find('/light/off')\n    print( 'led on = ' + str(led_on))\n    print( 'led off = ' + str(led_off))\n\n    if led_on == 6:\n      print(\"led on\")\n      led.value(1)\n      stateis = \"LED is ON\"\n\n    if led_off == 6:\n      print(\"led off\")\n      led.value(0)\n      stateis = \"LED is OFF\"\n    # generate the we page with the stateis as a parameter\n    response = html % stateis\n    cl.send('HTTP/1.0 200 OK\\r\\nContent-type: text/html\\r\\n\\r\\n')\n    cl.send(response)\n    cl.close()\n\n  except OSError as e:\n    cl.close()\n    print('connection closed')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/04-web-server/#references","title":"References","text":""},{"location":"wireless/05-mac-address/","title":"Getting Your MAC Address","text":""},{"location":"wireless/05-mac-address/#what-is-a-mac-address","title":"What is a MAC Address?","text":"

                                                                                                                                                                                                                                                                                                              Every device that works with Ethernet and WiFi must have a Wikipedia Page on MAC Address.

                                                                                                                                                                                                                                                                                                              A MAC address (media access control address) is a unique identifier assigned to a network interface controller (NIC) for use as a network address in communications within a network segment. This use is common in most IEEE 802 networking technologies, including Ethernet, Wi-Fi, and Bluetooth.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              The MAC address has nothing to do with the Apple Macintosh or Mac OS. They just use the same name to mean different things.

                                                                                                                                                                                                                                                                                                              Understanding how devices use MAC addresses is essential to understanding how networks work and debugging them.

                                                                                                                                                                                                                                                                                                              The MAC address is six bytes or \"octets\". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the Wikipedia Page on MAC Address for more information. If you run this on your Pico W the first octets should be similar.

                                                                                                                                                                                                                                                                                                              Here are the two MAC addresses for two different Pico W devices that were purchase together. They came on adjacent parts of a \"real\" of devices.

                                                                                                                                                                                                                                                                                                              28:cd:c1:1:35:54\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Because they were purchased together, their MAC address are very similar and only differ in the last few bits.

                                                                                                                                                                                                                                                                                                              This Pico W came from another distributer.

                                                                                                                                                                                                                                                                                                              28:cd:c1:0:9e:19\n

                                                                                                                                                                                                                                                                                                              You can see that the first three octets are the same. A MAC address often can give clues about the origins of packets on your network. They can also be used as \"serial numbers\" for each device that connects to WiFi or Ethernet since they are usually burned into ROM at device manufacturing time and are designed to be unique.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/05-mac-address/#getting-the-macethernet-access","title":"Getting the MAC/Ethernet Access","text":"

                                                                                                                                                                                                                                                                                                              You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function.

                                                                                                                                                                                                                                                                                                              import network\nfrom utime import sleep, ticks_us, ticks_diff\n\nprint('Getting MAC/Ethernet Address for this device.')\n\nstart = ticks_us() # start a millisecond counter\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True) # this line powers up the chip - it takes about 2.5 seconds\n\n# This returns a byte array of hex numbers\nmac_addess = wlan.config('mac')\nprint('Time in microseconds:', ticks_diff(ticks_us(), start))\n# each MAC address is 6 bytes or 48 bits\nprint(\"Hex byte array:\", mac_addess, 'length:', len(mac_addess))\n\n# This should be in hex per the Notational Conventions\n# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions\n# b'(\\xcd\\xc1\\x015X'\n# 28:cd:c1:1:35:58\n# format in MAC Notational Convention\nfor digit in range(0,5):\n    print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '')\nprint(str(hex(mac_addess[5]))[2:4] )\n

                                                                                                                                                                                                                                                                                                              First Time After Power On Results:

                                                                                                                                                                                                                                                                                                              Getting MAC/Ethernet Address for this device.\nTime in microseconds: 2584424\nHex byte array: b'(\\xcd\\xc1\\x015X' length: 6\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address.

                                                                                                                                                                                                                                                                                                              Subsequent Times

                                                                                                                                                                                                                                                                                                              Getting MAC/Ethernet Address for this device.\nTime in microseconds: 211\nHex byte array: b'(\\xcd\\xc1\\x015X' length: 6\n28:cd:c1:1:35:58\n

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              We must add the wlan.active(True) line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros.

                                                                                                                                                                                                                                                                                                              I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/05-mac-address/#mac-addresses-and-privacy","title":"MAC Addresses and Privacy","text":"

                                                                                                                                                                                                                                                                                                              MAC addresses are never sent to web servers to protect a clinet's privacy, but if you are debugging networks and looking at tools such as WireShark, they become visible to a local LAN administrator. MAC addresses are also visible to WiFi access points, so your local coffee shop that provides free WiFi could keep track of every time repeat customers use their WiFi access points.

                                                                                                                                                                                                                                                                                                              Some computers such as Apple generate a different MAC address for each different access point they connect to. This prevents multiple stores from connecting your profiles together. So Starbucks can't use your MAC address to offer you a free coffee every 10th visit to different stores, but if you visit a local coffee shop they can use their WiFi access logs to see their same-store repeat customers.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/06-upip/","title":"MicroPython PIP (UPIP)","text":"

                                                                                                                                                                                                                                                                                                              MicroPython also has a package manager called upip that can be run directly on the microcontroller. This means that every time you get a new microcontroller, you can automatically download all the python packages you need directly from the Internet using a single python program after upip has been installed.

                                                                                                                                                                                                                                                                                                              This also means that you don't need copies of these libraries installed on your local PC.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/06-upip/#install-upip-from-thonny-package-manager","title":"Install UPIP From Thonny Package Manager","text":"

                                                                                                                                                                                                                                                                                                              Go to the Thonny Tools -> Manage Packages... menu. Type \"upip\" in the search field and click the Search on PyPL button:

                                                                                                                                                                                                                                                                                                              The first search result will be for **micropython-upip\". Click on that link and you will see the details.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/06-upip/#install-a-package","title":"Install A Package","text":"

                                                                                                                                                                                                                                                                                                              The following program assumes that you have followed the steps in our Connecting to WiFi and have a secrets.py file that have your WiFi network name (SSID) and password (PASSWORD).

                                                                                                                                                                                                                                                                                                              import upip\nimport network\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nstart = ticks_ms() # start a millisecond counter\n\nif not wlan.isconnected():\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    while not wlan.isconnected():\n        sleep(1)\n        counter += 1\n        print(counter, '.', sep='', end='', )\n\ndelta = ticks_diff(ticks_ms(), start)\nprint(\"Connect Time:\", delta)\n\n# This is the line you must modify for each package you want to install\n# pystone is a CPU performance benchmarking tool that is easy to run to and test installation\n\nstart = ticks_ms()\n\nupip.install(\"micropython-pystone_lowmem\")\n\nprint(\"Download Time:\", ticks_diff(ticks_ms(), start), milliseconds)\n

                                                                                                                                                                                                                                                                                                              Results:

                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: MY_NETWORK_NAME\nWaiting for connection...\n1.2.3.4.Connect Time: 4641\nInstalling to: /lib/\nWarning: micropython.org SSL certificate is not validated\nInstalling micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz\nDownload Time: 4918 milliseconds\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/06-upip/#testing-your-newly-installed-library","title":"Testing Your Newly Installed Library","text":"
                                                                                                                                                                                                                                                                                                              import pystone_lowmem\npystone_lowmem.main()\n

                                                                                                                                                                                                                                                                                                              Results:

                                                                                                                                                                                                                                                                                                              Pystone(1.2) time for 500 passes = 410ms\nThis machine benchmarks at 1219 pystones/second\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/06-upip/#getting-upip-help","title":"Getting UPIP Help","text":"
                                                                                                                                                                                                                                                                                                              import upip\nupip.help()\n

                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                              upip - Simple PyPI package manager for MicroPython\nUsage: micropython -m upip install [-p <path>] <package>... | -r <requirements.txt>\nimport upip; upip.install(package_or_list, [<path>])\n\nIf <path> isn't given, packages will be installed to sys.path[1], or\nsys.path[2] if the former is .frozen (path can be set from MICROPYPATH\nenvironment variable if supported).\nDefault install path: /lib\n\nNote: only MicroPython packages (usually, named micropython-*) are supported\nfor installation, upip does not support arbitrary code in setup.py.\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/07-web-server-rgb-neopixels/","title":"Web Server NeoPixel RGB","text":""},{"location":"wireless/07-web-server-rgb-neopixels/#sample-code-with-css","title":"Sample Code with CSS","text":"
                                                                                                                                                                                                                                                                                                              # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/\nfrom machine import Pin\nfrom neopixel import NeoPixel\nimport network\nimport socket\nfrom time import sleep\nimport secrets\n\nNEOPIXEL_PIN = 0\nNUMBER_PIXELS = 30\nPERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS)\n\n# setup\nstrip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)\n\nred = (255,0,0)\ngreen = (0,255,0)\nblue = (0,0,255)\noff = (0,0,0)\n\ndef set_color(color):\n    for i in range(0, NUMBER_PIXELS):\n        strip[i] = color\n        strip.write()\n\n# Select the onboard LED\nled = machine.Pin(\"LED\", machine.Pin.OUT)\n\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\nwlan.connect(secrets.SSID, secrets.PASSWORD)\nstateis = \"LED is OFF\"\n\nhtml = \"\"\"<!DOCTYPE html>\n<html>\n   <head>\n     <title>Web Server On Pico W </title>\n     <style>\n        body {\n            font-size:24px;\n            font-family:'Helvetica'\n        }\n\n        .button-row {\n            display: inline-block;\n            padding: 2px 3px 6px 3px;\n            margin: 5px;\n        }\n\n        a:visited {\n          color: yellow;\n          background-color: transparent;\n          text-decoration: none;\n        }\n\n        a:hover {\n          color: orange;\n          background-color: transparent;\n          text-decoration: none;\n        }\n\n        .button {\n          font: bold 16px Arial;\n          text-decoration: none;\n          padding: 2px 6px 2px 6px;\n          border-top: 2px solid #CCCCCC;\n          border-right: 2px solid #333333;\n          border-bottom: 2px solid #333333;\n          border-left: 2px solid #CCCCCC;\n        }\n     </style>\n   </head>\n  <body>\n      <h1>Pico Wireless Web Server</h1>\n      <p>Onboard LED State: %s</p>\n\n\n      <div class=\"buttons\">\n\n          <span class=\"button-row\" style=\"background-color:gray\">\n              <a href=\"/light/on\" class=\"button\">Turn Onboard LED On</a>\n              <a href=\"/light/off\" class=\"button\">Turn Onboard LED Off</a>\n          </span><br/>\n\n          <span class=\"button-row\" style=\"background-color:red\">\n             <a href=\"/led/red/on\" class=\"button\">Red LED On</a>\n             <a href=\"/led/red/off\" class=\"button\">Red LED Off</a>\n          </span><br/>\n\n          <span class=\"button-row\" style=\"background-color:green\">\n              <a href=\"/led/green/on\" class=\"button\">Green LED On</a>\n              <a href=\"/led/green/off\" class=\"button\">Green LED Off</a>\n          </span><br/>\n\n          <span class=\"button-row\" style=\"background-color:blue\">\n              <a href=\"/led/blue/on\" class=\"button\">Blue LED On</a>\n              <a href=\"/led/blue/off\" class=\"button\">Blue LED Off</a>\n          </span>\n\n        </div>\n  </body>\n</html>\n\"\"\"\n\n# Wait for connect or fail\nmax_wait = 10\nwhile max_wait > 0:\n  if wlan.status() < 0 or wlan.status() >= 3:\n    break\n  max_wait -= 1\n  print('waiting for connection...')\n  sleep(1)\n  led.toggle()\n\n# Handle connection error\nif wlan.status() != 3:\n  raise RuntimeError('network connection failed')\nelse:\n  print('We are connected to WiFI access point:', secrets.SSID)\n  status = wlan.ifconfig()\n  print( 'The IP address of the pico W is:', status[0] )\n\n# Open socket\naddr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]\n# print('addr:', addr)\n\ns = socket.socket()\n# this prevents the \"OSError: [Errno 98] EADDRINUSE\" error for repeated tests\ns.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n# print('Got a sockert.  s:', s)\n\n#if not addr:\n\n# print('going to run bind to addr on the socket')\ns.bind(addr)\n\n# print('going to run listen(1) on socket')\ns.listen(1)\n\n# print('listening on', addr)\n\n# Listen for connections\nwhile True:\n  try:\n    cl, addr = s.accept()\n    # print('client connected from', addr)\n    request = cl.recv(1024)\n    # print(request)\n    request = str(request)\n    led_on = request.find('/light/on')\n    led_off = request.find('/light/off')\n\n    red_on = request.find('/led/red/on')\n    red_off = request.find('/led/red/off')\n\n    green_on = request.find('/led/green/on')\n    green_off = request.find('/led/green/off')\n\n    blue_on = request.find('/led/blue/on')\n    blue_off = request.find('/led/blue/off')\n\n    # print( 'led on = ' + str(led_on))\n    # print( 'led off = ' + str(led_off))\n\n    if led_on == 6:\n      print(\"led on\")\n      led.on()\n      stateis = \"LED is ON\"\n\n    if led_off == 6:\n        print(\"led off\")\n        led.off()\n        stateis = \"LED is OFF\"\n\n    if red_on == 6:\n        print(\"red on\")\n        set_color(red)\n    if red_off == 6:\n        print(\"red off\")\n        set_color(off)\n\n    if green_on == 6:\n        print(\"green on\")\n        set_color(green)\n    if green_off == 6:\n        print(\"green off\")\n        set_color(off)\n\n    if blue_on == 6:\n        print(\"blue on\")\n        set_color(blue)\n    if blue_off == 6:\n        print(\"blue off\")\n        set_color(off)\n\n    # generate the we page with the stateis as a parameter\n    response = html % stateis\n    cl.send('HTTP/1.0 200 OK\\r\\nContent-type: text/html\\r\\n\\r\\n')\n    cl.send(response)\n    cl.close()\n\n  except OSError as e:\n    cl.close()\n    s.close()\n    print('connection closed')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/07-web-server-rgb-neopixels/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              Clear Fix Floating Boxes Example

                                                                                                                                                                                                                                                                                                              https://www.w3schools.com/css/tryit.asp?filename=trycss_float_boxes

                                                                                                                                                                                                                                                                                                              <style>\n* {\n  box-sizing: border-box;\n}\n\n.box {\n  float: left;\n  width: 33.33%;\n  padding: 30px 20px;\n}\n\n.clearfix::after {\n  content: \"\";\n  clear: both;\n  display: table;\n}\n</style>\n</head>\n<body>\n\n  <h2>Grid of Boxes</h2>\n  <p>Float boxes side by side:</p>\n\n  <div class=\"clearfix\">\n    <div class=\"box\" style=\"background-color:silver\">\n    <p>Some text inside the box.</p>\n    </div>\n    <div class=\"box\" style=\"background-color:gray\">\n    <p>Some text inside the box.</p>\n    </div>\n  </div>\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/","title":"Get the Weather Forecast","text":"

                                                                                                                                                                                                                                                                                                              This demo uses the free web service Open Weather Map.

                                                                                                                                                                                                                                                                                                              The Open Weather Map service returns the predicted temperatures and conditions (sun, cloudy, rain etc.) for three-hour intervals for the next 40 intervals at your specified location.

                                                                                                                                                                                                                                                                                                              You can see this using the UNIX curl command:

                                                                                                                                                                                                                                                                                                              curl 'http://api.openweathermap.org/data/2.5/forecast?\\\n      units=imperial&\\\n      id=5037649&\\\n      appid=f2b1...'\n

                                                                                                                                                                                                                                                                                                              In this example, we are asking it to use US standard Fahrenheit (imperial units) for the city with id 5037649 which is Minneapolis, MN in the USA. You can use the Open Weather site to find the id for your city or specify the longitude and latitude of the point you want to get weather forecasts for. You can also use the GeoNames to find your city ID number.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#how-to-use-the-open-weather-map-api","title":"How to Use the Open Weather Map API","text":"

                                                                                                                                                                                                                                                                                                              To use this service, you must register and get an API key. You then put your key in the secrets.py file:

                                                                                                                                                                                                                                                                                                              Content of secrets.py

                                                                                                                                                                                                                                                                                                              appid='f2b1...'\n

                                                                                                                                                                                                                                                                                                              The secrets.py file is then imported into your program. Make sure to put secrets.py into your .gitignore file so it will not be checked into your public GitHub repo.

                                                                                                                                                                                                                                                                                                              The URL for the service is then created by concatenating the base URL, the city location ID and the application id:

                                                                                                                                                                                                                                                                                                              base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'\nlocation = '5037649' # GeoNames ID for Minneapolis in Minnesota, USA\nurl = base + 'id=' + location + '&appid=' + secrets.appid\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#parsing-the-json-file","title":"Parsing the JSON file","text":"

                                                                                                                                                                                                                                                                                                              The service returns a JSON file with the following format:

                                                                                                                                                                                                                                                                                                              {\n    \"cod\": \"200\",\n    \"message\": 0,\n    \"cnt\": 40,\n    \"list\": [\n        {\n            \"dt\": 1660078800,\n            \"main\": {\n                \"temp\": 80.83,\n                \"feels_like\": 81.23,\n                \"temp_min\": 80.83,\n                \"temp_max\": 84.67,\n                \"pressure\": 1019,\n                \"sea_level\": 1019,\n                \"grnd_level\": 988,\n                \"humidity\": 47,\n                \"temp_kf\": -2.13\n            },\n            \"weather\": [\n                {\n                    \"id\": 800,\n                    \"main\": \"Clear\",\n                    \"description\": \"clear sky\",\n                    \"icon\": \"01d\"\n                }\n            ],\n            \"clouds\": {\n                \"all\": 0\n            },\n            \"wind\": {\n                \"speed\": 6.08,\n                \"deg\": 226,\n                \"gust\": 6.38\n            },\n            \"visibility\": 10000,\n            \"pop\": 0,\n            \"sys\": {\n                \"pod\": \"d\"\n            },\n            \"dt_txt\": \"2022-08-09 21:00:00\"\n        }, \n        /* ...repeated 40 times */\n        ,\n    \"city\": {\n        \"id\": 5037649,\n        \"name\": \"Minneapolis\",\n        \"coord\": {\n            \"lat\": 44.98,\n            \"lon\": -93.2638\n        },\n        \"country\": \"US\",\n        \"population\": 0,\n        \"timezone\": -18000,\n        \"sunrise\": 1660043269,\n        \"sunset\": 1660094963\n    }\n}\n

                                                                                                                                                                                                                                                                                                              The bulk of the data is in the list structure with 40 items with a small set of data before and after the list. The data about the HTTP status (200) and the count (40) is before the list and the data about the city is after the list.

                                                                                                                                                                                                                                                                                                              Each block of data in the list JSON object contains data about the main data (temperature, min, max, pressure, humidity), cloud cover, wind speed and visibility. It is up to you to decide what data you would like to display within this data. Once you decide what data you want to access you can use JSON path statements to pull the right data out. For example, to get the main temperature for each time period you would run:

                                                                                                                                                                                                                                                                                                              # get the temp and humidity for the next 40 3-hour intervals\nfor i in range(0, 39):\n    print('temp:', weather['list'][i]['main']['temp'], end='')\n    print('humidity:', weather['list'][i]['main']['humidity'])\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#sample-output","title":"Sample Output","text":"

                                                                                                                                                                                                                                                                                                              Here is the output on the Thonny shell of the first 16 temperature values:

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#plotting-the-forecast-with-thonny-plot","title":"Plotting the Forecast with Thonny Plot","text":"

                                                                                                                                                                                                                                                                                                              Here is a plot of the temp and the \"feels like\" temp using the Thonny Plotter panel.

                                                                                                                                                                                                                                                                                                              Each line has:

                                                                                                                                                                                                                                                                                                              1. a label string
                                                                                                                                                                                                                                                                                                              2. a colon
                                                                                                                                                                                                                                                                                                              3. the numeric value

                                                                                                                                                                                                                                                                                                              for each value plotted. There can be multiple values per line.

                                                                                                                                                                                                                                                                                                              Here is that format:

                                                                                                                                                                                                                                                                                                              Temperature: 63 Feels Like:  63.52\nTemperature: 62 Feels Like:  62.56\nTemperature: 70 Feels Like:  69.69\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#sample-code","title":"Sample Code","text":"
                                                                                                                                                                                                                                                                                                              import network\nimport secrets\nimport urequests\nfrom utime import sleep, ticks_ms, ticks_diff\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nstart = ticks_ms() # start a millisecond counter\n\nif not wlan.isconnected():\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    while not wlan.isconnected():\n        sleep(1)\n        print(counter, '.', sep='', end='', )\n        counter += 1\n\ndelta = ticks_diff(ticks_ms(), start)\nprint(\"Connect Time:\", delta, 'milliseconds')\nprint(\"IP Address:\", wlan.ifconfig()[0])\n\nbase = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'\nlocation = '5037649' # twin cities\nurl = base + 'id=' + location + '&appid=' + secrets.appid\n\nweather = urequests.get(url).json()\nprint('City:', weather['city']['name'])\nprint('Timezone:', weather['city']['timezone'])\n\nmax_times = 16\n# for i in range(0, 39):\nfor i in range(0, max_times):\n    print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='')\nprint()\nfor i in range(0, max_times):    \n    print(round(weather['list'][i]['main']['temp']), '      ', end='')\n    # print('feels like:', weather['list'][i]['main']['feels_like'])\n    # print(weather['list'][i]['weather'][0]['description'])\n    # print(weather['list'][i]['dt_txt'])\n\n# print(weather)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/08-get-weather/#displaying-predicted-temperatures-in-a-thonny-plot","title":"Displaying Predicted Temperatures in a Thonny Plot","text":"

                                                                                                                                                                                                                                                                                                              Thonny has a Plot object that you can use to display the relative temperature for the next 40 3-hour cycles.

                                                                                                                                                                                                                                                                                                              To do this, we only need to print out the temperatures each on a separate line:

                                                                                                                                                                                                                                                                                                              print()\nfor i in range(0, max_times):    \n    print(round(weather['list'][i]['main']['temp']))\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/09-get-weather-display/","title":"Get Weather on an OLED Display","text":"

                                                                                                                                                                                                                                                                                                              In this lesson we will use the Pico W to get a weather forecast from a web service and display the current and forecasted temperatures on a 128x64 OLED display. The display above shows the city and current temperature on the top row of the display and then a plot of the predicted temperatures for the next 120 hours. The max temperature is 87 degrees and the minimum is 60 degrees Fahrenheit.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/09-get-weather-display/#calling-the-weather-api","title":"Calling the Weather API","text":"

                                                                                                                                                                                                                                                                                                              We will use the same method as in the previous lesson to get the weather forecast. However, in this lesson we will not just plot the temperature on the Thonny plot screen, we will use a OLED screen.

                                                                                                                                                                                                                                                                                                              To do this we will need to write a function that will display the temperature data. The function will display the current location city name, the current temperature, and then draw a plot of the next 40 3-hour intervals. This lesson is a bit harder because we have to manually do all the work of scaling and plotting our data. This is all done for us in the prior Thonny plotting lab.

                                                                                                                                                                                                                                                                                                              To achieve this we will need to scale the data to fit the display grid. We will reserve the top 10 pixels for the city and current temp and then draw the plot on the remaining 54 pixel high and 128 pixel wide plot region.

                                                                                                                                                                                                                                                                                                              To scale the data we will need to find the min and max temperatures. These will also be displayed on the screen. The scale is then the ratio of the graph height over the temperature range. For example if the range of temperatures is 27 degrees and the height of the display is 54 we will need to scale the temperature vertically by 2.

                                                                                                                                                                                                                                                                                                              The horizontal axis will go from 0 to 120. Since we have 40 points, each point will occur every 3rd pixel. We can then look at the difference between the current point and the next point to interpolate the dots between the two points.

                                                                                                                                                                                                                                                                                                              The math can be a little confusing since higher temperatures are closer to the top of the display, so they have a lower Y coordinate value. Note the y_delta is subtracted from the next value:

                                                                                                                                                                                                                                                                                                                  y_delta = -round((y - y_next)/3) # a small positive or negative number for interpolation\n
                                                                                                                                                                                                                                                                                                              def display_weather():\n    global weather, city, current_temp\n    oled.fill(0)\n    min = 120\n    max = -50\n    for i in range(0, 39):\n        temp = round(weather['list'][i]['main']['temp'])\n        if temp < min:\n            min = temp\n        if temp > max:\n            max = temp\n    min = round(min)\n    max = round(max)\n    temp_range_height = max - min\n    graph_height = 54\n    scale = graph_height/temp_range_height\n    print('min/max/range/scale:', min, max, temp_range_height, scale)\n\n    # display city name, current temp, min and max\n    oled.text(city + ': ' + str(current_temp), 0, 0, 1)\n    oled.text(str(min), 0, 57, 1) # bottom left corner\n    oled.text(str(max), 0, 10, 1) # under top row\n\n    max_points = 39\n\n    # graph temps for the next n periods\n    print('Date          Tmp TNx   Y  Y2  Del')\n    for i in range(0, max_points):\n        temp = round(weather['list'][i]['main']['temp'])\n        x = i * 3 # scaled x\n        y = 63 - round((temp - min)*scale)\n        oled.pixel(x, y, 1)\n\n        # now draw the next two points\n        if i < max_points:\n            temp_next = round(weather['list'][i+1]['main']['temp'])\n            y_next = 63 - round((temp_next - min)*scale)\n        y_delta = -round((y - y_next)/3) # a small positive or negative number\n\n        # for debugging - fixed with columns with leading spaces\n        print(weather['list'][i]['dt_txt'][0:13],\n              '{: 3.3d}'.format(temp),\n              '{: 3.3d}'.format(temp_next),\n              '{: 3.3d}'.format(y),\n              '{: 3.3d}'.format(y_next),\n              '{: 3.3d}'.format(y_delta))\n\n        # should be 1/3 of the way to the next point\n        oled.pixel(x+1, y + y_delta, 1)\n        # should be 2/3 of the way to the next point\n        oled.pixel(x+2, y + 2*y_delta, 1)\n    oled.show()\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/09-get-weather-display/#the-main-loop","title":"The Main Loop","text":"

                                                                                                                                                                                                                                                                                                              The main loop repeats forever, pausing every hour between updates. It gets first calls the rest service, extracts the city name and current temperature and then calls the display_weather() function using global variables for the JSON file, city and current temperature.

                                                                                                                                                                                                                                                                                                              while True:\n    # globals: weather, city, current_temp\n    weather = urequests.get(url).json()\n    # print(weather)\n    city = weather['city']['name']\n    current_temp = round(weather['list'][0]['main']['temp'])\n    display_weather()\n    print('Going to sleep for one hour')\n    sleep(3600) # sleep one hour\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/09-get-weather-display/#full-sample-code","title":"Full Sample Code","text":"
                                                                                                                                                                                                                                                                                                              import network\nimport ssd1306\nimport secrets\nimport urequests\nfrom utime import sleep, ticks_ms, ticks_diff\n\n# startup\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nWIDTH = 128\nHEIGHT = 64\nSCK=machine.Pin(2)\nSDL=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)\nCS = machine.Pin(0)\nDC = machine.Pin(1)\nRES = machine.Pin(4)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\noled.poweron()\n\ndef display_startup(counter):\n    oled.fill(0)\n    oled.text('Running startup', 0, 10, 1)\n    oled.text('Connecting to', 0, 20, 1)\n    oled.text(secrets.SSID, 0, 30, 1)\n    oled.text(str(counter), 0, 40, 1)\n    oled.show()\n\ndef display_status(counter):\n    oled.fill(0)\n    # display the network name\n    oled.text('n:' + secrets.SSID, 0, 0, 1)\n\n    # display the connection time\n    oled.text('t:', 0, 10, 1)\n    oled.text(str(connection_time)+ ' ms', 15, 10, 1)\n    oled.show()\n\ndef display_weather():\n    global weather, city, current_temp\n    oled.fill(0)\n    min = 120\n    max = -50\n    for i in range(0, 39):\n        temp = round(weather['list'][i]['main']['temp'])\n        if temp < min:\n            min = temp\n        if temp > max:\n            max = temp\n    min = round(min)\n    max = round(max)\n    temp_range_height = max - min\n    graph_height = 54\n    scale = graph_height/temp_range_height\n    print('min/max/range/scale:', min, max, temp_range_height, scale)\n\n    # display city name, current temp, min and max\n    oled.text(city + ': ' + str(current_temp), 0, 0, 1)\n    oled.text(str(min), 0, 57, 1) # bottom left corner\n    oled.text(str(max), 0, 10, 1) # under top row\n\n    max_points = 39\n\n    # graph temps for the next n periods\n    print('Date          Tmp TNx   Y  Y2  Del')\n    for i in range(0, max_points):\n        temp = round(weather['list'][i]['main']['temp'])\n        x = i * 3 # scaled x\n        y = 63 - round((temp - min)*scale)\n        oled.pixel(x, y, 1)\n\n        # now draw the next two points\n        if i < max_points:\n            temp_next = round(weather['list'][i+1]['main']['temp'])\n            y_next = 63 - round((temp_next - min)*scale)\n        y_delta = -round((y - y_next)/3) # a small positive or negative number\n\n        print(weather['list'][i]['dt_txt'][0:13],\n              '{: 3.3d}'.format(temp),\n              '{: 3.3d}'.format(temp_next),\n              '{: 3.3d}'.format(y),\n              '{: 3.3d}'.format(y_next),\n              '{: 3.3d}'.format(y_delta))\n\n        # should be 1/3 of the way to the next point\n        oled.pixel(x+1, y + y_delta, 1)\n        # should be 2/3 of the way to the next point\n        oled.pixel(x+2, y + 2*y_delta, 1)\n    oled.show()\n\nstart = ticks_ms() # start a millisecond counter\n\nif not wlan.isconnected():\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    while not wlan.isconnected():\n        sleep(1)\n        print(counter, '.', sep='', end='', )\n        counter += 1\n        display_startup(counter)\n\ndelta = ticks_diff(ticks_ms(), start)\n#print(\"Connect Time:\", delta, 'milliseconds')\n#print(\"IP Address:\", wlan.ifconfig()[0])\n\nbase = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'\nlocation = '5037649' # Minneapolis, MN USA\nurl = base + 'id=' + location + '&appid=' + secrets.appid\n#print(url)\n\nmax_times = 39\n#for i in range(0, max_times):    \n    #print(' Temp: ', weather['list'][i]['main']['temp'])\n\nwhile True:\n    # globals: weather, city, current_temp\n    weather = urequests.get(url).json()\n    # print(weather)\n    city = weather['city']['name']\n    current_temp = round(weather['list'][0]['main']['temp'])\n    display_weather()\n    print('Going to sleep for one hour.')\n    sleep(3600) # sleep one hour\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/09-get-weather-display/#sample-debugging","title":"Sample Debugging","text":"

                                                                                                                                                                                                                                                                                                              To allow you to see the math for the plotting and interpolation we have added a print that prints the temperatures and y coordinates in fixed with format. Here is an example of this output:

                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: anndan-2.4\nmin/max/range/scale: 60 87 27 2.0\nDate           Tmp Tnx  Y  Y2  Del\n2022-08-13 03  68  68  47  47   0\n2022-08-13 06  68  68  47  47   0\n2022-08-13 09  68  65  47  53   2\n2022-08-13 12  65  72  53  39  -5\n2022-08-13 15  72  83  39  17  -7\n2022-08-13 18  83  87  17   9  -3\n2022-08-13 21  87  82   9  19   3\n2022-08-14 00  82  71  19  41   7\n2022-08-14 03  71  66  41  51   3\n2022-08-14 06  66  62  51  59   3\n2022-08-14 09  62  60  59  63   1\n2022-08-14 12  60  71  63  41  -7\n2022-08-14 15  71  82  41  19  -7\n2022-08-14 18  82  85  19  13  -2\n2022-08-14 21  85  82  13  19   2\n2022-08-15 00  82  73  19  37   6\n2022-08-15 03  73  69  37  45   3\n2022-08-15 06  69  66  45  51   2\n2022-08-15 09  66  64  51  55   1\n2022-08-15 12  64  74  55  35  -7\n2022-08-15 15  74  83  35  17  -6\n2022-08-15 18  83  85  17  13  -1\n2022-08-15 21  85  81  13  21   3\n2022-08-16 00  81  75  21  33   4\n2022-08-16 03  75  70  33  43   3\n2022-08-16 06  70  69  43  45   1\n2022-08-16 09  69  66  45  51   2\n2022-08-16 12  66  66  51  51   0\n2022-08-16 15  66  79  51  25  -9\n2022-08-16 18  79  80  25  23  -1\n2022-08-16 21  80  70  23  43   7\n2022-08-17 00  70  65  43  53   3\n2022-08-17 03  65  64  53  55   1\n2022-08-17 06  64  63  55  57   1\n2022-08-17 09  63  61  57  61   1\n2022-08-17 12  61  72  61  39  -7\n2022-08-17 15  72  82  39  19  -7\n2022-08-17 18  82  85  19  13  -2\n2022-08-17 21  85  81  13  21   3\nGoing to sleep for one hour\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/10-wifi-clock/","title":"WiFi Clock","text":"

                                                                                                                                                                                                                                                                                                              In the US, we can access a service called the \"Network Time Protocol\" or NTP. This service allows you to get the precise time using your WiFi network.

                                                                                                                                                                                                                                                                                                              Calling the NTP service in MicroPython is simple once you have connected to your local wireless access point:

                                                                                                                                                                                                                                                                                                              import ntptime\nntptime.host = 'us.pool.ntp.org'\nntptime.timeout = 10\nntptime.settime()\n

                                                                                                                                                                                                                                                                                                              After running this code (and checking for errors) your internal Real-time Clock (RTC) will be synced to the NTP server.

                                                                                                                                                                                                                                                                                                              The rest of this code does the work of adjusting the clock to your local timezone and correcting for any changes in daylight savings time in your area.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/10-wifi-clock/#the-config-file","title":"The Config File","text":"

                                                                                                                                                                                                                                                                                                              We always put local credentials in a separate file so it does not get checked into GitHub.

                                                                                                                                                                                                                                                                                                              wifi_ssid = 'mywifinetworkname'\nwifi_pass = 'mypassword'\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/10-wifi-clock/#full-program","title":"Full Program","text":"
                                                                                                                                                                                                                                                                                                              import ntptime, network\nfrom machine import RTC\nfrom utime import sleep, sleep_ms, time, localtime, mktime\nimport config\n\n# US Central\ntimeZone = -6\n# try one of these\nntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org'\nntptime.timeout = 10\n\ndef wifiConnect():\n    wifi = network.WLAN(network.STA_IF)\n    wifi.active(True)\n    wifi.config(pm = 0xa11140) # disables wifi sleep mode\n    if not wifi.isconnected():\n        wifi.connect(config.wifi_ssid, config.wifi_pass)\n        print('Connecting..', end='')\n        max_wait = 10\n        while max_wait > 0:\n            if wifi.status() < 0 or wifi.status() >= 3: break\n            sleep_ms(1000)\n            print('.', end='')\n            max_wait -= 1\n        print()\n        if wifi.status() != 3: print('Could not connect to wifi!')\n    # print('Connected: ',wifi.isconnected(),'\\nIP: ',wifi.ifconfig()[0])\n    sleep_ms(100)\n    return wifi\n\n# daylight savings time\ndef dst():\n    year, weekday = localtime()[0], localtime()[6]\n    dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0))\n    dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0))\n    return dst_start <= time() < dst_end\n\ndef setRTC():\n    timeset = False\n    timetries = 0\n    maxtries = 5\n    while not timeset and timetries < maxtries:\n        timetries += 1\n        try:\n            ntptime.settime() # update time from ntp server\n            timeset = True\n        except:\n            print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.')\n            if timetries < maxtries: sleep_ms(15000)\n        if timeset:\n            sleep_ms(200)\n            rtc = RTC()\n            tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600\n            #tz_offset = timeZone * 3600 # without daylight savings\n            myt = localtime(time() + tz_offset)\n            rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0))\n            sleep_ms(200)\n            dtime = rtc.datetime()\n            timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm')\n            datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}'\n            # print('Time set to:', timestr, datestr)\n            print(timestr, datestr)\n            return True\n    print('ERROR! Unable to update time from server!')\n    return False\n\ndef update():\n    success = False\n    wifi = wifiConnect()\n    sleep_ms(100)\n    if wifi.isconnected():\n        success = setRTC()\n        sleep_ms(100)\n    return wifi, success\n\nif __name__ == '__main__':\n    while True:\n        update()\n        sleep(60)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/10-wifi-clock/#sample-output","title":"Sample Output:","text":"

                                                                                                                                                                                                                                                                                                              The console will display the following:

                                                                                                                                                                                                                                                                                                              Connecting.........\nConnected:  True \nIP:  10.0.0.118\nNTP update attempt # 1 of 5 failed! Retrying in 15 seconds..\n...\n7:41pm 9/10/23\n7:42pm 9/10/23\n7:43pm 9/10/23\n

                                                                                                                                                                                                                                                                                                              Note that connecting to the NTP server failed the first time but worked on the second attempt.

                                                                                                                                                                                                                                                                                                              This program assumes you have a config.py file in the same folder that the clock.py program runs.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/10-wifi-clock/#references","title":"References","text":"

                                                                                                                                                                                                                                                                                                              NikoKun

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/11-advanced-labs/","title":"Advanced Wireless Labs","text":""},{"location":"wireless/11-advanced-labs/#secure-communications-with-https","title":"Secure Communications with HTTPS","text":"

                                                                                                                                                                                                                                                                                                              In our documentation we frequently refer to secure communications as using a \"Secure Sockets Layer\". Although the term \"SSL\" is common, we are actually using a protocol called Transport Layer Security (TLS).

                                                                                                                                                                                                                                                                                                              TLS replaces SSL. It is an Internet Engineering Task Force (IETF) standard protocol that provides authentication, privacy and data integrity between two communicating computer applications.

                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                              The standard Python request library does not yet support HTTPS on urequest on the Pico W. This is because there are additional tools that require us to use keys and certificates to validate data on an encrypted SSL stream.

                                                                                                                                                                                                                                                                                                              See the MicroPython SSL/TLS Library

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/11-advanced-labs/#testing-ssltls-on-standard-python","title":"Testing SSL/TLS on Standard Python","text":"
                                                                                                                                                                                                                                                                                                              import socket\nimport ssl\n\nhostname = 'www.python.org'\ncontext = ssl.create_default_context()\n\nwith socket.create_connection((hostname, 443)) as sock:\n    with context.wrap_socket(sock, server_hostname=hostname) as ssock:\n        print(ssock.version())\n

                                                                                                                                                                                                                                                                                                              returns: TLSv1.3

                                                                                                                                                                                                                                                                                                              This tells you that the standard Python socket libraries use the TLS v1.3 protocol.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/11-advanced-labs/#performance-monitoring-with-uiperf3","title":"Performance Monitoring with uiperf3","text":"

                                                                                                                                                                                                                                                                                                              iperf3 is a standard Python program for internet performance testing. For micropython, we have our own stripped down version called uiperf3.

                                                                                                                                                                                                                                                                                                              IPerf3 uses a client-server testing model and measures networking performance between two system using various protocoos such as

                                                                                                                                                                                                                                                                                                              • UDP - User Datagram Protocol
                                                                                                                                                                                                                                                                                                              • TCP - Transmission Control Protocol
                                                                                                                                                                                                                                                                                                              • Streaming

                                                                                                                                                                                                                                                                                                              It can also be used to measure total wireless throughput.

                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/11-advanced-labs/#upip-install","title":"UPIP Install","text":"
                                                                                                                                                                                                                                                                                                              upip.install(\"uiperf3\")\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/11-advanced-labs/#testing-client-performance","title":"Testing Client Performance","text":"
                                                                                                                                                                                                                                                                                                              import uiperf3\n uiperf3.client('MY_IP_ADDRESS')\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/12-display-clock/","title":"Display Clock","text":"

                                                                                                                                                                                                                                                                                                              This is similar to the WiFi Clock but it uses an OLED display to show the time and date.

                                                                                                                                                                                                                                                                                                              from machine import Pin\nimport network\nimport ntptime\nimport ssd1306\n# where we keep the WiFi password\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\n\nWIDTH = 128\nHEIGHT = 64\nSCK=machine.Pin(2)\nSDL=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)\nCS = machine.Pin(4)\nDC = machine.Pin(5)\nRES = machine.Pin(6)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\noled.poweron()\n\n# US Central\ntimeZone = -6\n# try one of these\nntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org'\nntptime.timeout = 10\n\ndef wifiConnect():\n    wifi = network.WLAN(network.STA_IF)\n    wifi.active(True)\n    wifi.config(pm = 0xa11140) # disables wifi sleep mode\n    if not wifi.isconnected():\n        wifi.connect(config.wifi_ssid, config.wifi_pass)\n        print('Connecting..', end='')\n        max_wait = 10\n        while max_wait > 0:\n            if wifi.status() < 0 or wifi.status() >= 3: break\n            sleep_ms(1000)\n            print('.', end='')\n            max_wait -= 1\n        print()\n        if wifi.status() != 3: print('Could not connect to wifi!')\n    # print('Connected: ',wifi.isconnected(),'\\nIP: ',wifi.ifconfig()[0])\n    sleep_ms(100)\n    return wifi\n\n# daylight savings time\ndef dst():\n    year, weekday = localtime()[0], localtime()[6]\n    dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0))\n    dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0))\n    return dst_start <= time() < dst_end\n\ntimestr = ''\ndatestr = ''\ndtime = []\ndef setRTC():\n    global timestr, datestr, dtime\n    timeset = False\n    timetries = 0\n    maxtries = 5\n    while not timeset and timetries < maxtries:\n        timetries += 1\n        try:\n            ntptime.settime() # update time from ntp server\n            timeset = True\n        except:\n            print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.')\n            if timetries < maxtries: sleep_ms(15000)\n        if timeset:\n            sleep_ms(200)\n            rtc = RTC()\n            tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600\n            #tz_offset = timeZone * 3600 # without daylight savings\n            myt = localtime(time() + tz_offset)\n            rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0))\n            sleep_ms(200)\n            dtime = rtc.datetime()\n            # set globals\n            # hh:mm in 12hr am/pm format\n            timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm')\n            # mm/dd/yy\n            datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}'\n            # print('Time set to:', timestr, datestr)\n            print(timestr, datestr)\n            return True\n    print('ERROR! Unable to update time from server!')\n    return False\n\ndef update():\n    success = False\n    wifi = wifiConnect()\n    sleep_ms(100)\n    if wifi.isconnected():\n        success = setRTC()\n        sleep_ms(100)\n    return wifi, success\n\ndef update_display():\n    global timestr, datestr,dtime\n    oled.fill(0)\n    oled.text(timestr + ' ' + datestr, 0, 10, 1)\n    oled.show()\n\nwhile True:\n    update()\n    update_display()\n    sleep(60)\n
                                                                                                                                                                                                                                                                                                              "},{"location":"wireless/20-display/","title":"Wireless With Display","text":"

                                                                                                                                                                                                                                                                                                              In this lesson, we will add a 128x64 OLED display to our Pico \"W\" to display network information.

                                                                                                                                                                                                                                                                                                              The display we are using is a 2.42\" Diymore OLED display as describe in the Display Graphics.

                                                                                                                                                                                                                                                                                                              # make a number scroll to the right and increment the number and move down one pixel\n# this test patten shows the device is working and will not burn any single pixel if it runs a long time\nfrom machine import Pin\nimport network\nimport ssd1306\nimport secrets\nfrom utime import sleep, ticks_ms, ticks_diff\n\nWIDTH = 128\nHEIGHT = 64\nSCK=machine.Pin(2)\nSDL=machine.Pin(3)\nspi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)\nCS = machine.Pin(0)\nDC = machine.Pin(1)\nRES = machine.Pin(4)\noled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)\noled.poweron()\n\ndef mac_address_fmt():\n    mac_addess = wlan.config('mac')\n    s=\"\"\n    for digit in range(0,5):\n        s+=str(hex(mac_addess[digit]))[2:4] + ':'\n    s+= hex(mac_addess[5])[2:4]\n    return s\n\ndef display_startup(counter):\n    oled.fill(0)\n    oled.text('Running startup', 0, 10, 1)\n    oled.text('Connecting to', 0, 20, 1)\n    oled.text(secrets.SSID, 0, 30, 1)\n    oled.text(str(counter), 0, 40, 1)\n    oled.show()\n\ndef display_status(counter):\n    oled.fill(0)\n    # display the network name\n    oled.text('n:' + secrets.SSID, 0, 0, 1)\n\n    # display the connection time\n    oled.text('t:', 0, 10, 1)\n    oled.text(str(connection_time)+ ' ms', 15, 10, 1)\n\n    # display the MAC address\n    oled.text(mac_address_fmt(), 0, 20, 1)\n\n    # display the IP address\n    oled.text('ip:' + wlan.ifconfig()[0], 0, 30, 1)\n    oled.text('c:' + str(counter), 0, 40, 1)\n    oled.show()\n# startup\nled = Pin(\"LED\", Pin.OUT)\nled.on()\n\nstart = ticks_ms() # start a millisecond counter\n\nprint('Connecting to WiFi Network Name:', secrets.SSID)\nwlan = network.WLAN(network.STA_IF)\nwlan.active(True)\n\nif not wlan.isconnected():\n    # this should normally take 3-5 seconds...\n    wlan.connect(secrets.SSID, secrets.PASSWORD)\n    print(\"Waiting for connection...\")\n    counter = 0\n    display_startup(counter)\n    while not wlan.isconnected():\n        sleep(1)\n        counter += 1\n        led.toggle()\n        display_startup(counter)\n        print(counter, '.', sep='', end='')\n\nconnection_time = ticks_diff(ticks_ms(), start)\nmac_addess = wlan.config('mac')\nprint('Connected to', secrets.SSID)\nprint('Total connect milliseconds:', connection_time)\n\ncounter = 0\nwhile True:\n    led.toggle()\n    counter += 1\n    display_status(counter)\n    sleep(1)\n    print(counter, 'listening on', wlan.ifconfig()[0])\n
                                                                                                                                                                                                                                                                                                              "}]} \ No newline at end of file diff --git a/sensors/01-intro/index.html b/sensors/01-intro/index.html new file mode 100644 index 000000000..f30066b49 --- /dev/null +++ b/sensors/01-intro/index.html @@ -0,0 +1,1757 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + Introduction + + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                    • + + + Light Sensor + + + +
                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                    • + + + Ping + + + +
                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                    • + + + Temperature + + + +
                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                • + + + Light Sensor + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Ping + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                • + + + Temperature + + + +
                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                Sensors in MicroPython

                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                Light Sensor

                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                Ping

                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                Temperature

                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                + Wireless +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                + Photosensor +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/sensors/02-photosensor/index.html b/sensors/02-photosensor/index.html new file mode 100644 index 000000000..8c6b6fa1c --- /dev/null +++ b/sensors/02-photosensor/index.html @@ -0,0 +1,1809 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Photosensor - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + Photosensor + + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Photosensor + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                      • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                  • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                  • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                  • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                  Light Sensor with Raspberry Pi Pico in MicroPython

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  A photoresistor is a sensor that decreases resistance when light is shined on its surface. With no light a photoresistor has high resistance in the range of megaohms. As light shines on the surface the resistance drops to kiloohms. We can use this effect as a light sensor.

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  To convert the variable resistance of a photoresistor to something we can measure with our microcontroller we will need to build a small circuit that includes a 10K ohm resistor. We then measure the voltage between the photoresistor and the 10K resistor as light falls on the sensor. The top and bottom of the circuit are tied to ground and a power rail. This will move the voltage of the midpoint of the circuit.

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  Photoresistor on Breadboard

                                                                                                                                                                                                                                                                                                                  + + +

                                                                                                                                                                                                                                                                                                                  Circuit

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  Photoresistor Circuit

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  We want to make sure that we use the stable analog ground (AGND) and analog to reference voltage at either end of the circuit to protect the circuit from all the noise of the power in our processor. Using other power and ground pins will work, but power fluctuations will make the result noisy.

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  Sample Code

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  Our program will first use the Analog to Digital Circuit (ADC0) as an input. On the Pico this is on pin 26.

                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                                                                  +4
                                                                                                                                                                                                                                                                                                                  +5
                                                                                                                                                                                                                                                                                                                  +6
                                                                                                                                                                                                                                                                                                                  +7
                                                                                                                                                                                                                                                                                                                  +8
                                                                                                                                                                                                                                                                                                                  import machine
                                                                                                                                                                                                                                                                                                                  +import time
                                                                                                                                                                                                                                                                                                                  +photo_pin = machine.ADC(26)
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                                  +    val = photo_pin.read_u16()
                                                                                                                                                                                                                                                                                                                  +    print(val)
                                                                                                                                                                                                                                                                                                                  +    time.sleep(.2)
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  When you run the program a series of print values is displayed in the shell every 1/5th of a second. You can also use the Thonny plot window to see how the numbers change and you cover and uncover detector from a light source.

                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  Experiments

                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                  1. What types of devices could use a light detector?
                                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                                  3. How does a night-light work? How could you add an LED to the circuit so that the LED would turn on if the light level got too low?
                                                                                                                                                                                                                                                                                                                  4. +
                                                                                                                                                                                                                                                                                                                  5. Could you automatically adjust the brightness of LEDs on a costume to get brighter in a sunny room and dim if you enter a dark room? What would that code look like?
                                                                                                                                                                                                                                                                                                                  6. +
                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                  References

                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                  1. Wikipedia Page on Photoresistor
                                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                  + Introduction +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                  + Ping Distance +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/sensors/02-pot/index.html b/sensors/02-pot/index.html new file mode 100644 index 000000000..2a19757ff --- /dev/null +++ b/sensors/02-pot/index.html @@ -0,0 +1,1789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Potentiometer - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + Potentiometer + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + Potentiometer + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                        • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                        • + + + Sampling data + + + +
                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                    • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                    • + + + Sampling data + + + +
                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                    Reading a Potentiometer

                                                                                                                                                                                                                                                                                                                    + + +

                                                                                                                                                                                                                                                                                                                    Video Demo

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    In this lab we will hook up a Potentiometer to the Analog to Digital Converter of the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Connections

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Potentiometers have three wires:

                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                    1. The ground rail
                                                                                                                                                                                                                                                                                                                    2. +
                                                                                                                                                                                                                                                                                                                    3. The center tap
                                                                                                                                                                                                                                                                                                                    4. +
                                                                                                                                                                                                                                                                                                                    5. The positive rail
                                                                                                                                                                                                                                                                                                                    6. +
                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    The rails are hooked up to fixed reference voltages. As you turn the know, the center tap returns a value that varies between the ground and the positive rail voltages.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    On many microcontrollers, the positive voltage is very "noisy" in that it contains voltage that varies as the components draw power. The Raspberry Pi has a special region for high-quality data gathering that is isolated from this noise. To use this section you MUST hook the rails to the right pins.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and +terminating at this pin.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    <!-- -> +

                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                                                                                                    +5
                                                                                                                                                                                                                                                                                                                    +6
                                                                                                                                                                                                                                                                                                                    +7
                                                                                                                                                                                                                                                                                                                    graph LR
                                                                                                                                                                                                                                                                                                                    +p[Pico]-->|ADC_VREF 36 row=6| pos(Positive)
                                                                                                                                                                                                                                                                                                                    +p[Pico]-->|AGND 33 row=8| neg(Negative)
                                                                                                                                                                                                                                                                                                                    +p[Pico]-->|GP26 pin=26 ADC0 31 row=10| tap(Center Tap)
                                                                                                                                                                                                                                                                                                                    +    pos(Positive) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                                                                    +    neg(Negative) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                                                                    +    tap(Center Tap) --- pot(Potentiometer)
                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Sampling data

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values.

                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                    Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples.

                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                                    +4
                                                                                                                                                                                                                                                                                                                    +5
                                                                                                                                                                                                                                                                                                                    +6
                                                                                                                                                                                                                                                                                                                    def sample_pot(pin, count):
                                                                                                                                                                                                                                                                                                                    +    total = 0
                                                                                                                                                                                                                                                                                                                    +    for i in range(count):
                                                                                                                                                                                                                                                                                                                    +        total += int(pin.read_u16())
                                                                                                                                                                                                                                                                                                                    +        utime.sleep_ms(5)
                                                                                                                                                                                                                                                                                                                    +    return int(total / count)
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                                    pot_pin_1 = machine.ADC(26)
                                                                                                                                                                                                                                                                                                                    +# return a value after sampling 10 times
                                                                                                                                                                                                                                                                                                                    +sample_pot(pot_pin_1, 10)
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                                                    + DH11 Temp and Humidity +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                                                    + Temp, Humidity, Pres +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/sensors/03-ping/index.html b/sensors/03-ping/index.html new file mode 100644 index 000000000..8271ec281 --- /dev/null +++ b/sensors/03-ping/index.html @@ -0,0 +1,1829 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Ping Distance - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + Ping Distance + + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Ping Distance + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                          • + + + Wiring Diagram + + + +
                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                          • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                          • + + + OLED + + + +
                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                      • + + + Wiring Diagram + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      • + + + OLED + + + +
                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                      Ultrasonic Ping Sensor

                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      The HC-SR04 is a low cost ($4) sensor that measures the distance to an object in front of it.

                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      Wiring Diagram

                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                      1. Connect GND to any GND pin on the Pico
                                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                                      3. Connect VCC to VBUS or 5 Volt power
                                                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                                                      5. Connect Trigger to pin 15. With USB on the top, this pin is the bottom left corner.
                                                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                                                      7. Connect Echo to pin 14. One up from bottom left corner.
                                                                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      Sample Code

                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                                                                                                      # Sample code to test HC-SR04 Ultrasonice Ping Sensor
                                                                                                                                                                                                                                                                                                                      +# Connect GND to any GND pin on the Pico
                                                                                                                                                                                                                                                                                                                      +# Connnect VCC to VBUS or 5 Volt power
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +from machine import Pin, Timer
                                                                                                                                                                                                                                                                                                                      +import utime
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +TRIGGER_PIN = 15 # With USB on the top, this pin is the bottom left corner
                                                                                                                                                                                                                                                                                                                      +ECHO_PIN = 14 # One up from bottom left corner
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +# Init HC-SR04 pins
                                                                                                                                                                                                                                                                                                                      +trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
                                                                                                                                                                                                                                                                                                                      +echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +def ping():
                                                                                                                                                                                                                                                                                                                      +    trigger.low()
                                                                                                                                                                                                                                                                                                                      +    utime.sleep_us(2) # Wait 2 microseconds low
                                                                                                                                                                                                                                                                                                                      +    trigger.high()
                                                                                                                                                                                                                                                                                                                      +    utime.sleep_us(5) # Stay high for 5 miroseconds
                                                                                                                                                                                                                                                                                                                      +    trigger.low()
                                                                                                                                                                                                                                                                                                                      +    while echo.value() == 0:
                                                                                                                                                                                                                                                                                                                      +        signaloff = utime.ticks_us()
                                                                                                                                                                                                                                                                                                                      +    while echo.value() == 1:
                                                                                                                                                                                                                                                                                                                      +        signalon = utime.ticks_us()
                                                                                                                                                                                                                                                                                                                      +    timepassed = signalon - signaloff
                                                                                                                                                                                                                                                                                                                      +    distance = (timepassed * 0.0343) / 2
                                                                                                                                                                                                                                                                                                                      +    return distance
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                      +    print("Distance:", ping(), " cm")
                                                                                                                                                                                                                                                                                                                      +    utime.sleep(.25)
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      OLED

                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      If you have a small OLED screen, you can also display the results +of the distance measurement directly on an OLED screen.

                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                      See the OLED example here: OLED Ping Example

                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                      + Photosensor +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                      + IR Distance Sensor +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/sensors/04-temp-dht11/index.html b/sensors/04-temp-dht11/index.html new file mode 100644 index 000000000..f45cd6327 --- /dev/null +++ b/sensors/04-temp-dht11/index.html @@ -0,0 +1,1766 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Temp and Humidity - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + Temp and Humidity + + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Temp and Humidity + + + + + + + +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                            • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                        • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                        Sensing Temperature and Humidity with the DHT11 Sensor

                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                        Sample Code

                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                        from machine import Pin
                                                                                                                                                                                                                                                                                                                        +import utime as time
                                                                                                                                                                                                                                                                                                                        +from dht import DHT11, InvalidChecksum
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +DHT_PIN = 15
                                                                                                                                                                                                                                                                                                                        +# this is a bit odd, since although it is an input, we need a pull down set
                                                                                                                                                                                                                                                                                                                        +dhtSensor = DHT11(Pin(DHT_PIN, Pin.OUT, Pin.PULL_DOWN))
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                                                                                                                        +    temp = dhtSensor.temperature
                                                                                                                                                                                                                                                                                                                        +    humidity = dhtSensor.humidity/100
                                                                                                                                                                                                                                                                                                                        +    print("Temp: {}°C".format(temp),  "| Hum: {0:.1%}".format(humidity))
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                        References

                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                        • Peppe80's Example
                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                        • Axel Örn Sigurðsson's DHT11 Driver
                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                        + IR Distance Sensor +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                        + Temperature +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/sensors/05-temp-dsb20/index.html b/sensors/05-temp-dsb20/index.html new file mode 100644 index 000000000..ec024fa03 --- /dev/null +++ b/sensors/05-temp-dsb20/index.html @@ -0,0 +1,1678 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Temperature - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + Temperature + + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + Temperature + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                          Temp with DS18B20

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          https://randomnerdtutorials.com/micropython-ds18b20-esp32-esp8266/

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          ```py

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          Complete project details at https://RandomNerdTutorials.com

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          import machine, onewire, ds18x20, time

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          ds_pin = machine.Pin(4) +ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          roms = ds_sensor.scan() +print('Found DS devices: ', roms)

                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                          while True: + ds_sensor.convert_temp() + time.sleep_ms(750) + for rom in roms: + print(rom) + print(ds_sensor.read_temp(rom)) + time.sleep(5) + ```

                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                                                                                          + Temp and Humidity +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                                                                                          + Temp, Humidity, Pres +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/sensors/06-accelerometer-compass/index.html b/sensors/06-accelerometer-compass/index.html new file mode 100644 index 000000000..de35c0897 --- /dev/null +++ b/sensors/06-accelerometer-compass/index.html @@ -0,0 +1,2274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Accelerometer Compass - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + Accelerometer Compass + + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Accelerometer Compass + + + + + + + +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + + + Pinouts + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + I2C Scanner Results + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + MPU9250 Drivers + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + LSM6DS3 Accelerometer and Gyroscope + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Selecting the Accelerometer Sensitivity Range + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±2g Sensitivity Setting + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±4g Sensitivity Setting + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Selecting Gyroscope Sensitivity Ranges + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Gyroscope Sensitivity Ranges and Their Applications + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±125 DPS + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±245 DPS + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±500 DPS + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±1000 DPS + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + ±2000 DPS + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Settings for Robot Tracking Orientation and Position + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + 1. Accelerometer: + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + 2. Gyroscope: + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + 3. Magnetometer (if included in IMU): + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + 4. Sensor Fusion: + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + 5. Additional Considerations: + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                            • + + + Pinouts + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + I2C Scanner Results + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + MPU9250 Drivers + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + LSM6DS3 Accelerometer and Gyroscope + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + Selecting the Accelerometer Sensitivity Range + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                              • + + + ±2g Sensitivity Setting + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + ±4g Sensitivity Setting + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + Selecting Gyroscope Sensitivity Ranges + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + Gyroscope Sensitivity Ranges and Their Applications + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                              • + + + ±125 DPS + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + ±245 DPS + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + ±500 DPS + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + ±1000 DPS + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + ±2000 DPS + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + Settings for Robot Tracking Orientation and Position + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + 1. Accelerometer: + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + 2. Gyroscope: + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + 3. Magnetometer (if included in IMU): + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + 4. Sensor Fusion: + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + 5. Additional Considerations: + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                            MPU-9250 Accelerometer Gyroscope Compass

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            The MPU-9250 by InvenSense is a nine-axis motion tracking device. It includes:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            1. A MPU-6500, which contains a 3-axis accelerometer and a 3-axis gyroscope and
                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                            3. A AK8963, the market leading 3-axis digital compass that senses magnetic fields
                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            (Gyro + Accelerometer + Compass) MEMS MotionTracking™ Device

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            1PCS GY-91 10DOF Accelerometer Gyroscope Compass Temp/Pressure MPU-9250 BMP-280

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Art of Circuits
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Pinouts

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            1. VIN: Voltage Supply Pin
                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                            3. 3V3: 3.3v Regulator output
                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                            5. GND: 0V Power Supply
                                                                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                                                                            7. SCL: I2C Clock / SPI Clock
                                                                                                                                                                                                                                                                                                                            8. +
                                                                                                                                                                                                                                                                                                                            9. SDA: I2C Data or SPI Data Input
                                                                                                                                                                                                                                                                                                                            10. +
                                                                                                                                                                                                                                                                                                                            11. SDO/SAO: SPI Data output / I2C Slave Address configuration pin
                                                                                                                                                                                                                                                                                                                            12. +
                                                                                                                                                                                                                                                                                                                            13. NCS: Chip Select for SPI mode only for MPU-9250
                                                                                                                                                                                                                                                                                                                            14. +
                                                                                                                                                                                                                                                                                                                            15. CSB: Chip Select for BMP280
                                                                                                                                                                                                                                                                                                                            16. +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            You only need to hook the 3.3 to VIN, the GND to GND and the SCL and SDA. The other connections are not needed.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            I2C Scanner Results

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                            +4
                                                                                                                                                                                                                                                                                                                            +5
                                                                                                                                                                                                                                                                                                                            import machine
                                                                                                                                                                                                                                                                                                                            +sda=machine.Pin(16) # row one on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                            +scl=machine.Pin(17) # row two on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                            +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                            +print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Device found at decimal [104, 118]

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            MPU9250 Drivers

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            MicroPython Driver

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                             1
                                                                                                                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                                                                                                                            import utime
                                                                                                                                                                                                                                                                                                                            +from machine import I2C, Pin
                                                                                                                                                                                                                                                                                                                            +from mpu9250 import MPU9250
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +i2c = I2C(scl=Pin(22), sda=Pin(21))
                                                                                                                                                                                                                                                                                                                            +sensor = MPU9250(i2c)
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +print("MPU9250 id: " + hex(sensor.whoami))
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +while True:
                                                                                                                                                                                                                                                                                                                            +    print(sensor.acceleration)
                                                                                                                                                                                                                                                                                                                            +    print(sensor.gyro)
                                                                                                                                                                                                                                                                                                                            +    print(sensor.magnetic)
                                                                                                                                                                                                                                                                                                                            +    print(sensor.temperature)
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +    utime.sleep_ms(1000)
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            LSM6DS3 Accelerometer and Gyroscope

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            The LSM6DS3 is a combined 3-axis accelerometer gyroscope with an 8kb FIFO buffer and an embedded processing interrupt function for the gyro sensor, specifically for the mobile phone market. +Specifications:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            1. 3-axis accelerometer
                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                            3. 6 parameter gyroscope
                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                            5. 8K FIFO for buffering reads
                                                                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                                                                            7. Embedded temperature sensor
                                                                                                                                                                                                                                                                                                                            8. +
                                                                                                                                                                                                                                                                                                                            9. 3.3 logic. Any voltages above 3.3 will damage the board
                                                                                                                                                                                                                                                                                                                            10. +
                                                                                                                                                                                                                                                                                                                            11. Gyro read data speed: 6.7ks / s
                                                                                                                                                                                                                                                                                                                            12. +
                                                                                                                                                                                                                                                                                                                            13. Accelerometer read data speed: 1.7ks / s
                                                                                                                                                                                                                                                                                                                            14. +
                                                                                                                                                                                                                                                                                                                            15. Power consumption: 0.9 mA for standard rate, 1.25 mA for high-performance mode
                                                                                                                                                                                                                                                                                                                            16. +
                                                                                                                                                                                                                                                                                                                            17. Input supply voltage: 1.71V to 5V
                                                                                                                                                                                                                                                                                                                            18. +
                                                                                                                                                                                                                                                                                                                            19. Interfaces: IIC and SPI
                                                                                                                                                                                                                                                                                                                            20. +
                                                                                                                                                                                                                                                                                                                            21. Accelerometer Sensitivity Ranges: ±2/±4/±16/±8 g
                                                                                                                                                                                                                                                                                                                            22. +
                                                                                                                                                                                                                                                                                                                            23. Gyro Sensitivity Ranges: ± 125/245/500/1000/2000 degrees per second
                                                                                                                                                                                                                                                                                                                            24. +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            With LSM6DS3 breakout, you will be able to detect the motion, impact, and tilt.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Selecting the Accelerometer Sensitivity Range

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            The sensitivity ratings for an accelerometer specify the maximum measurable acceleration that the device can sense along its measurement axis (or axes). When an accelerometer states its sensitivity as ±2/±4/±16/±8 g, it usually means that the device can be set to different ranges or scales of measurement. Here's what each of those ratings mean:

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±2g Sensitivity Setting

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            The accelerometer can measure accelerations between -2g and +2g. This is a lower range, so it can detect small changes in acceleration with high precision. This range would be ideal for applications that require precise measurements of small movements. For example, the orientation of a screen as it is being tilted or rotated.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±4g Sensitivity Setting

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            In this setting, the accelerometer can measure accelerations between -4g and +4g. This provides a slightly larger range than the ±2g setting, making it suitable for applications that might experience slightly stronger forces or movements but still require a good amount of precision.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            One example is wearable fitness trackers, like smartwatches and sport bands, often have built-in accelerometers to monitor and analyze user movement. For regular walking or jogging, a ±2g accelerometer might suffice. However, for more intense activities like plyometric exercises, sprinting, or aggressive directional changes in sports like basketball or soccer, the forces exerted on the tracker can exceed 2g. These activities involve rapid starts, stops, jumps, and changes in direction.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Why ±4g?: The accelerometer needs to capture both the subtleties of everyday motion and the higher-intensity bursts of activity without saturating or clipping the data. A ±4g range provides a good balance between sensitivity and maximum measurable acceleration, making it suitable for wearable devices intended for diverse and dynamic physical activities.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            With this capability, fitness trackers can more accurately measure and analyze the user's movements across a wider range of activities, providing better data and feedback on their workouts and performance.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±16g: +The accelerometer can measure accelerations between -16g and +16g. This is a much broader range and is less sensitive to small movements. It's ideal for applications that are exposed to stronger forces or rapid movements, such as crash detection or certain sports applications.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±8g: The accelerometer can measure accelerations between -8g and +8g. This provides a balance between sensitivity and range, suitable for applications that might experience moderate forces.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            In practice, these settings allow the user (or designer) to choose the best range for their application. For applications where precision in detecting small accelerations is essential, a lower range (like ±2g) would be selected. In contrast, for applications where large accelerations may occur, a higher range (like ±16g) would be more appropriate to prevent the sensor from saturating or clipping the readings.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Selecting Gyroscope Sensitivity Ranges

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Gyroscopes measure the rate of angular change, often referred to as the angular velocity or angular rate. The unit for this rate of change is typically represented in degrees per second (DPS).

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            The sensitivity ranges for a gyroscope describe the maximum rate of rotation it can measure. When a gyroscope has sensitivity ranges listed as ±125/245/500/±1000/±2000 DPS, it means the device has multiple selectable scales or ranges of measurement. Let's break down each of these ranges:

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±125 DPS: At this setting, the gyroscope can measure angular velocities between -125 and +125 degrees per second. This is a low range and would provide high precision for slow rotational movements. For example, a slowly turning sailboat.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±245 DPS: The device can measure angular velocities between -245 and +245 degrees per second. This offers a slightly larger range than the ±125 DPS setting.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±500 DPS: This setting allows the gyroscope to measure between -500 and +500 degrees per second.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±1000 DPS: The device can measure angular velocities ranging between -1000 and +1000 degrees per second. This is suitable for applications that might experience moderately fast rotations.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±2000 DPS: At this maximum setting, the gyroscope can capture angular velocities between -2000 and +2000 degrees per second. It's best for very fast rotational movements. For example, inside a rapidly spinning ball thown in the air.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Gyroscope Sensitivity Ranges and Their Applications

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Here are some examples of different applications that might be used in each of these ranges.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±125 DPS

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Wearable Health Devices: Devices like posture trackers which monitor the orientation of a user to ensure they are maintaining a healthy posture.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Human Movement Analysis: In biomechanics or rehabilitation scenarios where slow and controlled movements are being assessed.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Precision Robotics: Robots that need to make very slow, controlled, and precise rotations.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±245 DPS

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Consumer Electronics: Gadgets like virtual reality (VR) headsets or augmented reality (AR) devices that track head movements, where moderate but not very rapid turns are common.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Gaming Controllers: For games where precise tracking of tilt and rotation is crucial for gameplay.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±500 DPS

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Drones: Hobby drones or quadcopters that don't perform aggressive maneuvers might fit into this range.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Camera Gimbal Systems: Devices that stabilize cameras may need to compensate for moderate motions.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±1000 DPS

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Advanced Drones: Racing drones or those designed for aerial acrobatics that require swift and agile movements.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Sports Analysis: Tracking rapid movements in sports training equipment, like baseball or golf swing analyzers.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Automotive Systems: Stability control systems in vehicles that monitor and counteract skidding or rollovers.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            ±2000 DPS

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • High-performance Aircraft: Certain maneuvers in aeronautical or aerospace applications might need this high range.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • High-speed Robotics: Robots designed for tasks that involve very rapid rotations.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Extreme Sports Equipment: Equipment used in scenarios where extreme rotational velocities can occur, like certain types of motorsport or action sports.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Module size: 13 * 18mm

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Package Include: +1 x GY-LSM6DS3 IIC/SPI Accelerometer Tilt Angle Gyro Sensor Breakout Transfer Module

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Settings for Robot Tracking Orientation and Position

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            If we are Tracking Orientation and Position for a Small Robot we need the following:

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            1. Accelerometer:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Sensitivity: Given the maximum speed of 6 inches per second, the accelerometer's main role is to capture any rapid starts, stops, or changes in direction. A ±2g setting is likely sufficient for most small robot applications. If uncertain about specific accelerations or possible bumps or drops, consider a ±4g setting.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Purpose: Measures acceleration and helps detect the robot's orientation with respect to the Earth's gravitational field.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            2. Gyroscope:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Sensitivity: For moderate speeds and non-rapid spins, a ±250 DPS setting might be adequate. For rapid turns, a higher setting might be needed.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • Purpose: Measures the rate of angular change to help determine the robot's orientation.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            3. Magnetometer (if included in IMU):

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Purpose: Measures the Earth's magnetic field to determine the robot's heading relative to magnetic north.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            4. Sensor Fusion:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Combine data from the accelerometer, gyroscope, and magnetometer (if available) for a comprehensive understanding of the robot's movement and orientation.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            5. Additional Considerations:

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • Wheel Encoders: Useful for position tracking by measuring wheel rotation.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • External Sensors: Consider infrared, ultrasonic sensors, or computer vision techniques for advanced navigation and localization.
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            Remember to test and calibrate in real-world scenarios for optimal performance.

                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                            References

                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                            • MEMS YouTube Video The ingenious micro mechanisms inside your phone
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • LSM6DS3 IIC/SPI 3 Axis Accelerometer Gyroscope 6 Degrees Sensor Transfer Module - on Ebay for $3 each - IIC and SPI
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            • SparkFun LSM6DS3 Breakout Hookup Guide
                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                                                                                            + Temp, Humidity, Pres +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                                                                                                            + Time of Flight Distance +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/sensors/06-bme280/index.html b/sensors/06-bme280/index.html new file mode 100644 index 000000000..4059dcc82 --- /dev/null +++ b/sensors/06-bme280/index.html @@ -0,0 +1,2038 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Temp, Humidity, Pres - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + Temp, Humidity, Pres + + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Temp, Humidity, Pres + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + I2C Scanner + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + BME280 Driver + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Test Code + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Code 2 + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Temp, Humidity, Pres + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + I2C Scanner + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + BME280 Driver + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Test Code + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Code 2 + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                              • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + I2C Scanner + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + BME280 Driver + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + Test Code + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + Code 2 + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                              BME280 Environmental Sensor

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              The Bosch BME280 is a low-cost ($2) temperature, and pressure sensor that has an I2C interface. This is an ideal way to learn how to use an I2C interface.

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Note mbe280 is different from the BMP280 and does not read humidity. The default address is Hex x76 or decimal 118.

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Circuit

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              The BME280 has a standard I2C interface with four wires:

                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                              • GND - connect to any of the GND pins
                                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                                              • VCC - connect this to the 3.3V output of the Pico
                                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                                              • SCL - clock
                                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                                              • SDA - data
                                                                                                                                                                                                                                                                                                                              • +
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              I2C Scanner

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              After you have connected your sensor you can check the connection by running a quick "I2C Scanner" to find the address of the sensor.

                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                              +4
                                                                                                                                                                                                                                                                                                                              +5
                                                                                                                                                                                                                                                                                                                              import machine
                                                                                                                                                                                                                                                                                                                              +sda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top
                                                                                                                                                                                                                                                                                                                              +scl=machine.Pin(1) # Row two of our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                              +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                              +print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Results: +

                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                              [118]
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              This is decimal of hex 0x76

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              If the scanner does not return a number then your connections might not be working.

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              BME280 Driver

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              You should be able to find the BME280 driver by using the Thonny Tool -> Manage Packages... menu. If that does not work you can try a github search:

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Search GitHub for MBE 280 Python Code

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Test Code

                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                                                              +18
                                                                                                                                                                                                                                                                                                                              +19
                                                                                                                                                                                                                                                                                                                              +20
                                                                                                                                                                                                                                                                                                                              +21
                                                                                                                                                                                                                                                                                                                              +22
                                                                                                                                                                                                                                                                                                                              +23
                                                                                                                                                                                                                                                                                                                              import machine
                                                                                                                                                                                                                                                                                                                              +from utime import sleep
                                                                                                                                                                                                                                                                                                                              +import BME280
                                                                                                                                                                                                                                                                                                                              +sda=machine.Pin(0) # This is GP0 on row one of our standard Pico breadboard with the USB on top
                                                                                                                                                                                                                                                                                                                              +scl=machine.Pin(1) # Row two of our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                              +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +# initialize the bme class using the default address
                                                                                                                                                                                                                                                                                                                              +bme = BME280()
                                                                                                                                                                                                                                                                                                                              +(chip_id, chip_version) = bme.getID()
                                                                                                                                                                                                                                                                                                                              +print( "Chip ID:", chip_id)
                                                                                                                                                                                                                                                                                                                              +print( "Version:", chip_version)
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +while True():
                                                                                                                                                                                                                                                                                                                              +    # get new data from the 
                                                                                                                                                                                                                                                                                                                              +    temperature,pressure,humidity = bme.getData()
                                                                                                                                                                                                                                                                                                                              +    #adj_bar = bme.adj_baro(pressure, temperature)
                                                                                                                                                                                                                                                                                                                              +    print("Adj {}".format(bme.adj_baro(pressure, temperature)))
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +    print( "Temperature: {}C".format(temperature))
                                                                                                                                                                                                                                                                                                                              +    print( "Pressure: {}hpa, {}In".format(pressure, round(pressure * 0.02953, 2)))
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +    sleep(1)
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Code 2

                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                                                              +18
                                                                                                                                                                                                                                                                                                                              +19
                                                                                                                                                                                                                                                                                                                              +20
                                                                                                                                                                                                                                                                                                                              +21
                                                                                                                                                                                                                                                                                                                              +22
                                                                                                                                                                                                                                                                                                                              +23
                                                                                                                                                                                                                                                                                                                              from machine import I2C
                                                                                                                                                                                                                                                                                                                              +import BME280
                                                                                                                                                                                                                                                                                                                              +from time import sleep
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +sda=machine.Pin(16)
                                                                                                                                                                                                                                                                                                                              +scl=machine.Pin(17)
                                                                                                                                                                                                                                                                                                                              +i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                              +bme = BME280.BME280(i2c=i2c)
                                                                                                                                                                                                                                                                                                                              +# print(i2c.scan())
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +while True:
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +  temp = bme.temperature
                                                                                                                                                                                                                                                                                                                              +  hum = bme.humidity
                                                                                                                                                                                                                                                                                                                              +  pres = bme.pressure
                                                                                                                                                                                                                                                                                                                              +  # uncomment for temperature in Fahrenheit
                                                                                                                                                                                                                                                                                                                              +  temp = (bme.read_temperature()/100) * (9/5) + 32
                                                                                                                                                                                                                                                                                                                              +  #temp = str(round(temp, 2)) + 'F'
                                                                                                                                                                                                                                                                                                                              +  print('Temperature: ', temp, end='')
                                                                                                                                                                                                                                                                                                                              +  print(' Humidity:', hum, end='')
                                                                                                                                                                                                                                                                                                                              +  print(' Pressure:', pres)
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +  sleep(5)
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              References

                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                              1. Robert HH BME280 Test Page
                                                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                                                              3. Official Datasheet
                                                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                                                              5. eBay BME280 Sensor Search
                                                                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                                                                              7. Driver Sample code
                                                                                                                                                                                                                                                                                                                              8. +
                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              Digital Barometric Pressure Sensor Board Swap I2C/SPI BMP280 BME280 3.3V

                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                              BME280 +4. BME280 logger +5. The Electronics India

                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                              + Potentiometer +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                              + Accelerometer Compass +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/sensors/07-VL53L0X_GY/index.html b/sensors/07-VL53L0X_GY/index.html new file mode 100644 index 000000000..15416d4cd --- /dev/null +++ b/sensors/07-VL53L0X_GY/index.html @@ -0,0 +1,1897 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Time of Flight Distance - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + Time of Flight Distance + + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Time of Flight Distance + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                    • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + I2C Scanner Test + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + Download The VL53L0X Driver + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + Create a Test Program + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + Use the Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + Reference Purchase links + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    • + + + eBay + + + +
                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + I2C Scanner Test + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Download The VL53L0X Driver + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Create a Test Program + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Use the Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + Reference Purchase links + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                • + + + eBay + + + +
                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                VL53L0X Time-of-Flight Laser Ranging Module IR Distance Sensor

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                +Figure: VL53L0X in the GY-530 package.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                The VL53L0X is a low-cost ($5) time-of-flight light-based distance sensor that is easy to use. It comes packaged in a I2C board and gives precise distance measurements up to 1.5 meters away. It measures the time that light pulses take to travel to an object and back to estimate distance. Light travels about 1 foot every nanosecond, so the timing inside this little chip must be very accurate.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                The VL53L0X integrates a group of Single Photon Avalanche Diodes (SPAD) and embeds ST Electronic's second generation FlightSense™ patented technology. The VL53L0X’s 940 nm emitter Vertical Cavity Surface-Emitting Laser (VCSEL), is safe for kids and totally invisible to the human eye. Coupled with internal physical infrared filters, the sensor enables longer ranging distance, higher immunity to ambient light, and better robustness to cover glass optical crosstalk.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Circuit

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Hook the VCC to the 3.3 out of the Pico, the GND of the sensor to andy of the GND pins of the Pico and then connect the Clock and Data to two pins such as GPIO pins 16 and 17.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                I2C Scanner Test

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                We first run the I2C scanner program to verify that the sensor is connected correctly and is responding to the I2C bus scan.

                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                                                import machine
                                                                                                                                                                                                                                                                                                                                +sda=machine.Pin(0) # row one on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                                +scl=machine.Pin(1) # row two on our standard Pico breadboard
                                                                                                                                                                                                                                                                                                                                +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                                +print("Device found at decimal", i2c.scan())
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                This should return a single decimal number.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Download The VL53L0X Driver

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                If you are using Thonny, you can try to use the "Manage Packages" menu and search for the driver.

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                We have a sample of the driver here

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Create a Test Program

                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                # Test program for VL53L0X
                                                                                                                                                                                                                                                                                                                                +import time
                                                                                                                                                                                                                                                                                                                                +from machine import Pin
                                                                                                                                                                                                                                                                                                                                +from machine import I2C
                                                                                                                                                                                                                                                                                                                                +import VL53L0X
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +sda=machine.Pin(16) # lower right pin
                                                                                                                                                                                                                                                                                                                                +scl=machine.Pin(17) # one up from lower right pin
                                                                                                                                                                                                                                                                                                                                +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +# Create a VL53L0X object
                                                                                                                                                                                                                                                                                                                                +tof = VL53L0X.VL53L0X(i2c)
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +while True:
                                                                                                                                                                                                                                                                                                                                +    tof.start()
                                                                                                                                                                                                                                                                                                                                +    tof.read()
                                                                                                                                                                                                                                                                                                                                +    print(tof.read())
                                                                                                                                                                                                                                                                                                                                +    tof.stop()
                                                                                                                                                                                                                                                                                                                                +    time.sleep(0.1)
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Use the Thonny Plot

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                Reference Purchase links

                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                1. ST Microelectronics
                                                                                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                                                                                3. User Manual
                                                                                                                                                                                                                                                                                                                                4. +
                                                                                                                                                                                                                                                                                                                                5. Ebay $4
                                                                                                                                                                                                                                                                                                                                6. +
                                                                                                                                                                                                                                                                                                                                7. Amazon $12
                                                                                                                                                                                                                                                                                                                                8. +
                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                eBay

                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                qty 10 for $25

                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                                + Accelerometer Compass +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                                + Rotary Encoder +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/sensors/08-ir-distance-sensor/index.html b/sensors/08-ir-distance-sensor/index.html new file mode 100644 index 000000000..1ce9f473e --- /dev/null +++ b/sensors/08-ir-distance-sensor/index.html @@ -0,0 +1,2228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + IR Distance Sensor - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + IR Distance Sensor + + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + IR Distance Sensor + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      + + + + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                      • + + + IR Distance Sensors + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Sample Python Code + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + The KY-032 + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Speaker Test + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Motor pins to the L293 H-Bridge + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + connections to the three IR distance sensors + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + create a Pulse Width Modulation Object on this pin + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + 0=stopped, 1=forward, 2=turing right, 3=turning left + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  + + + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                  • + + + IR Distance Sensors + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Sample Python Code + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + The KY-032 + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Speaker Test + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + Motor pins to the L293 H-Bridge + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + connections to the three IR distance sensors + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + create a Pulse Width Modulation Object on this pin + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  • + + + 0=stopped, 1=forward, 2=turing right, 3=turning left + + + +
                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                  IR Distance Sensors

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  IR distance sensors are low cost (five for $3) but may have problems working in rooms with outdoor lighting. They have an adjustable potentiometer on them that can be used to adjust a triggering distance call the threshold distance. The sensors return a HIGH signal if there is no object within the threshold distance and a LOW signal if there is an object within this distance. Since the sensor threshold distance can not be adjusted programmatically they are best suited when you can manually adjust the potentiometer to change the threshold.

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  IR Distance Sensor

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  Connections

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  These sensors have three wires:

                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                  1. GND - connect to a ground rail on your breadboard or directly to a GND ping on the Pico.
                                                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                                                  3. VCC - connect to the 5 volt power rail powered by the motor controller voltage regulator
                                                                                                                                                                                                                                                                                                                                  4. +
                                                                                                                                                                                                                                                                                                                                  5. OUT - a 5 volt digital signal that is usually 5 volts but is GND when triggered by an object
                                                                                                                                                                                                                                                                                                                                  6. +
                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  Sample Python Code

                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                                                                                  +4
                                                                                                                                                                                                                                                                                                                                  # connections to the three IR distance sensors
                                                                                                                                                                                                                                                                                                                                  +left = Pin(8, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +center = Pin(7, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +right = Pin(6, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  The KY-032

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  The KY-032 obstacle avoidance sensor is a four-wire distance-adjustable, infrared proximity sensor designed for wheeled robots. Also known as AD-032.

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  The sensor detection distance ranges from 2cm to 40cm, it can be adjusted by turning the potentiometer knob. The operating voltage is 3.3V-5V so it is suitable for a variety of microcontrollers like Arduino, ESP32, Teensy, ESP8266, Raspberry Pi, and others.

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  It has strong adaptability to ambient light and it is fairly accurate to sense changes in the surrounding environment.

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  Speaker Test

                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                                                  +29
                                                                                                                                                                                                                                                                                                                                  +30
                                                                                                                                                                                                                                                                                                                                  +31
                                                                                                                                                                                                                                                                                                                                  +32
                                                                                                                                                                                                                                                                                                                                  +33
                                                                                                                                                                                                                                                                                                                                  +34
                                                                                                                                                                                                                                                                                                                                  +35
                                                                                                                                                                                                                                                                                                                                  +36
                                                                                                                                                                                                                                                                                                                                  +37
                                                                                                                                                                                                                                                                                                                                  +38
                                                                                                                                                                                                                                                                                                                                  +39
                                                                                                                                                                                                                                                                                                                                  +40
                                                                                                                                                                                                                                                                                                                                  +41
                                                                                                                                                                                                                                                                                                                                  +42
                                                                                                                                                                                                                                                                                                                                  +43
                                                                                                                                                                                                                                                                                                                                  +44
                                                                                                                                                                                                                                                                                                                                  +45
                                                                                                                                                                                                                                                                                                                                  +46
                                                                                                                                                                                                                                                                                                                                  +47
                                                                                                                                                                                                                                                                                                                                  +48
                                                                                                                                                                                                                                                                                                                                  +49
                                                                                                                                                                                                                                                                                                                                  +50
                                                                                                                                                                                                                                                                                                                                  +51
                                                                                                                                                                                                                                                                                                                                  +52
                                                                                                                                                                                                                                                                                                                                  +53
                                                                                                                                                                                                                                                                                                                                  +54
                                                                                                                                                                                                                                                                                                                                  +55
                                                                                                                                                                                                                                                                                                                                  +56
                                                                                                                                                                                                                                                                                                                                  +57
                                                                                                                                                                                                                                                                                                                                  +58
                                                                                                                                                                                                                                                                                                                                  +59
                                                                                                                                                                                                                                                                                                                                  +60
                                                                                                                                                                                                                                                                                                                                  +61
                                                                                                                                                                                                                                                                                                                                  +62
                                                                                                                                                                                                                                                                                                                                  +63
                                                                                                                                                                                                                                                                                                                                  +64
                                                                                                                                                                                                                                                                                                                                  +65
                                                                                                                                                                                                                                                                                                                                  +66
                                                                                                                                                                                                                                                                                                                                  +67
                                                                                                                                                                                                                                                                                                                                  +68
                                                                                                                                                                                                                                                                                                                                  +69
                                                                                                                                                                                                                                                                                                                                  +70
                                                                                                                                                                                                                                                                                                                                  +71
                                                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                  +from utime import sleep
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +left = Pin(8, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +center = Pin(7, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +right = Pin(6, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +SPEAKER_PIN = 21
                                                                                                                                                                                                                                                                                                                                  +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                  +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def sound_off():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def left_tone():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(300) # 1 Kilohertz
                                                                                                                                                                                                                                                                                                                                  +    sleep(.5) # wait a 1/4 second
                                                                                                                                                                                                                                                                                                                                  +    sound_off()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def center_tone():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(800)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.5)
                                                                                                                                                                                                                                                                                                                                  +    sound_off()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def right_tone():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(400)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.5)
                                                                                                                                                                                                                                                                                                                                  +    sound_off()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def right_tone():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(800)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.25)
                                                                                                                                                                                                                                                                                                                                  +    sound_off()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +def forward_tone():
                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(400)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(900)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(1200)
                                                                                                                                                                                                                                                                                                                                  +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                  +    sound_off()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +# 0=stopped, 1=forward, 2=turing right, 3=turning left
                                                                                                                                                                                                                                                                                                                                  +drive_state = 0
                                                                                                                                                                                                                                                                                                                                  +while True:
                                                                                                                                                                                                                                                                                                                                  +    if left.value()==0:
                                                                                                                                                                                                                                                                                                                                  +        print('Left')
                                                                                                                                                                                                                                                                                                                                  +        left_tone()
                                                                                                                                                                                                                                                                                                                                  +        drive_state = 2
                                                                                                                                                                                                                                                                                                                                  +    if center.value()==0:
                                                                                                                                                                                                                                                                                                                                  +        print('Center')
                                                                                                                                                                                                                                                                                                                                  +        center_tone()
                                                                                                                                                                                                                                                                                                                                  +        drive_state = 0
                                                                                                                                                                                                                                                                                                                                  +    if right.value()==0:
                                                                                                                                                                                                                                                                                                                                  +        print('Right')
                                                                                                                                                                                                                                                                                                                                  +        right_tone()
                                                                                                                                                                                                                                                                                                                                  +        drive_state = 3
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +    # if (left.value()==1) and (center.value()==1) and (right.value()==1):
                                                                                                                                                                                                                                                                                                                                  +    if left.value() and center.value() and right.value():
                                                                                                                                                                                                                                                                                                                                  +        print('Go forward!')
                                                                                                                                                                                                                                                                                                                                  +        drive_state = 1
                                                                                                                                                                                                                                                                                                                                  +        forward_tone()
                                                                                                                                                                                                                                                                                                                                  +    sleep(.25)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  Full Program

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  ```py +from machine import Pin, PWM +from utime import sleep +import ssd1306

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  Motor pins to the L293 H-Bridge

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  RIGHT_FORWARD_PIN = 17 +RIGHT_REVERSE_PIN = 16 +LEFT_FORWARD_PIN = 18 +LEFT_REVERSE_PIN = 19

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) +right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) +left_forward = PWM(Pin(LEFT_FORWARD_PIN)) +left_reverse = PWM(Pin(LEFT_REVERSE_PIN))

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  connections to the three IR distance sensors

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  left = Pin(8, Pin.IN, Pin.PULL_DOWN) +center = Pin(7, Pin.IN, Pin.PULL_DOWN) +right = Pin(6, Pin.IN, Pin.PULL_DOWN)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  SPEAKER_PIN = 21

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  create a Pulse Width Modulation Object on this pin

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  speaker = PWM(Pin(SPEAKER_PIN))

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  WIDTH = 128 +HEIGHT = 64 +CS = machine.Pin(1) +SCL = machine.Pin(2) +SDA = machine.Pin(3) +DC = machine.Pin(4) +RES = machine.Pin(5) +spi=machine.SPI(0, sck=SCL, mosi=SDA) +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def turn_motor_on(pwm): + pwm.duty_u16(65025)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def turn_motor_off(pwm): + pwm.duty_u16(0)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def forward(): + turn_motor_on(right_forward) + turn_motor_on(left_forward)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def reverse(): + turn_motor_on(right_reverse) + turn_motor_on(left_reverse)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def turn_right(): + turn_motor_on(right_forward) + turn_motor_on(left_reverse)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def turn_left(): + turn_motor_on(right_reverse) + turn_motor_on(left_forward)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def sound_off(): + speaker.duty_u16(0)

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def left_tone(): + speaker.duty_u16(1000) + speaker.freq(700) # 1 Kilohertz + sleep(.5) # wait a 1/4 second + sound_off()

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def center_tone(): + speaker.duty_u16(1000) + speaker.freq(900) + sleep(.5) + sound_off()

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def right_tone(): + speaker.duty_u16(1000) + speaker.freq(600) + sleep(.5) + sound_off()

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def forward_tone(): + speaker.duty_u16(1000) + speaker.freq(400) + sleep(.1) + speaker.freq(900) + sleep(.1) + speaker.freq(1200) + sleep(.1) + sound_off()

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  def update_oled(): + oled.fill(0) + oled.text("CoderDojo Rocks!", 0, 0, 1)

                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                                                  +27
                                                                                                                                                                                                                                                                                                                                  +28
                                                                                                                                                                                                                                                                                                                                  oled.text("Left:", 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                  +oled.text(str(left.value()), 50, 10, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +oled.text("Center:", 0, 20, 1)
                                                                                                                                                                                                                                                                                                                                  +oled.text(str(center.value()), 60, 20, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +oled.text("Right:", 0, 30, 1)
                                                                                                                                                                                                                                                                                                                                  +oled.text(str(right.value()), 55, 30, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +BAR_WIDTH = 40
                                                                                                                                                                                                                                                                                                                                  +BAR_HEIGHT = 20
                                                                                                                                                                                                                                                                                                                                  +if left.value():
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                                                  +else:
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +if center.value():
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                                                  +else:
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +if right.value():
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0)
                                                                                                                                                                                                                                                                                                                                  +else:
                                                                                                                                                                                                                                                                                                                                  +    oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1)
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +oled.show()
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  0=stopped, 1=forward, 2=turing right, 3=turning left

                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                  drive_state = 0 +counter = 0 +while True: + if left.value()==0: + print('Left') + #left_tone() + turn_right() + update_oled() + drive_state = 2 + if center.value()==0: + print('Center') + center_tone() + reverse() + update_oled() + drive_state = 0 + if right.value()==0: + print('Right') + #right_tone() + turn_left() + update_oled() + drive_state = 3

                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                                                  # if (left.value()==1) and (center.value()==1) and (right.value()==1):
                                                                                                                                                                                                                                                                                                                                  +if left.value() and center.value() and right.value():
                                                                                                                                                                                                                                                                                                                                  +    print('Go forward!')    
                                                                                                                                                                                                                                                                                                                                  +    drive_state = 1
                                                                                                                                                                                                                                                                                                                                  +    # forward_tone()
                                                                                                                                                                                                                                                                                                                                  +    forward()
                                                                                                                                                                                                                                                                                                                                  +    update_oled()
                                                                                                                                                                                                                                                                                                                                  +print("counter: ", counter)
                                                                                                                                                                                                                                                                                                                                  +counter += 1
                                                                                                                                                                                                                                                                                                                                  +sleep(.25)
                                                                                                                                                                                                                                                                                                                                  +```
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +## More to Explore
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +1. Try to change the values of the potentiometers on the sensors.  What is the minimum and maximum distance you can detect and object?
                                                                                                                                                                                                                                                                                                                                  +2.  Does the reflectivity of the object impact the distance of the object?
                                                                                                                                                                                                                                                                                                                                  +3. If you put a small mirror in front of the sensor what happens to the distance measured?
                                                                                                                                                                                                                                                                                                                                  +4. Place the robot near bright sun in a window or try the robot outdoors on both a cloudy day and a sunny day?  What is the change is accuracy of the sensors under these conditions?  What about running the robot in the dark?
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                                  + Ping Distance +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                                  + Temp and Humidity +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/sensors/09-bme280/index.html b/sensors/09-bme280/index.html new file mode 100644 index 000000000..eb50a3f5a --- /dev/null +++ b/sensors/09-bme280/index.html @@ -0,0 +1,1286 @@ + + + + + + + + + + + + + + + + + + + + + + + 09 bme280 - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + 09 bme280 + + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                    09 bme280

                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/sensors/10-rotary-encoder/index.html b/sensors/10-rotary-encoder/index.html new file mode 100644 index 000000000..105ff2e6c --- /dev/null +++ b/sensors/10-rotary-encoder/index.html @@ -0,0 +1,2246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Rotary Encoder - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + Rotary Encoder + + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Rotary Encoder + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                          • + + + Learning How to Monitor the Rotary Switch Transitions + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + The Rotary Class + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Using a Scheduler + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Testing Script + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Adding Plot + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Mysterious Runtime Error on Scheduling Queue + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                      • + + + Learning How to Monitor the Rotary Switch Transitions + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + The Rotary Class + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Using a Scheduler + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Testing Script + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Adding Plot + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + Mysterious Runtime Error on Scheduling Queue + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                      Rotary Encoder

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Rotary Encoder

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      A rotary encoder, or more specifically a directional rotary encoder, may look similar to a potentiometer in some ways. Both have a knob that you turn to adjust a value. But unlike a potentiometer, a rotary encoder is far more flexible in the range and precision of values it can control. Our students love to use them in their projects to change the color or patterns in an LED strip.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Rotary encoders can be thought of as two concentric rings of switches that go on and off as you turn the knob. The switches are placed so that you can tell the direction of rotation by the order the two switches get turned on and off. They turn on and off quickly so we need a high-quality function to quickly detect their changes. And as we learned in the Button lab, switches can be noisy and have a complex state transition that must be debounced to get a good quality signal.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Directional Encoders

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Learning How to Monitor the Rotary Switch Transitions

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      We will be using a low-cost ($1 USD) encoder that has five connectors, three for the direction and one for a momentary switch that is closed when you press the knob in. Here is the circuit that we will be using:

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Rotary Encoder Circuit

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      We hooked up the outer pins of the encoder to GPIO pins 16 and 17 in the lower right corner of the Pico.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Then we hooked the center pin to the 3.3 volt rail. The Pico likes to pull switches down from the 3.3 volt rail. This means that we will not be connecting any of the pins to GND.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      We also hooked up the central press button to GPIO 22 and the 3.3 volt rail.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      We then ran this code and turned the knob:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      import time
                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                      +    print(rotaryA.value(), end='')
                                                                                                                                                                                                                                                                                                                                      +    print(rotaryB.value())
                                                                                                                                                                                                                                                                                                                                      +    time.sleep(.1)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      the results look like the following lines:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Note that the bit values the encoders switches (on or off as 0 and 1) are place next to each other on the same line. We did this by making the end of the first print statement be the null string not the default newline character.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      This program prints out a LONG stream of numbers, mostly of the value 00. The values are printed 10 times each second. Now let's take a closer look at only the values that change.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      What we would like to do is now only print numbers if there is a change. To do this we will "pack" binary values into a two bit number by shifting the A pin value to the left:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                      import time
                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +# we set the old value to zero for both bits being off
                                                                                                                                                                                                                                                                                                                                      +old_combined = 0
                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                      +    A_val = rotaryA.value()
                                                                                                                                                                                                                                                                                                                                      +    B_val = rotaryB.value()
                                                                                                                                                                                                                                                                                                                                      +    # a sifts by one bit and then is ORed with the B calue
                                                                                                                                                                                                                                                                                                                                      +    new_combined = (A_val << 1) | B_val
                                                                                                                                                                                                                                                                                                                                      +    if new_combined != old_combined:
                                                                                                                                                                                                                                                                                                                                      +            print(A_val, end='')
                                                                                                                                                                                                                                                                                                                                      +            print(B_val)
                                                                                                                                                                                                                                                                                                                                      +            old_combined = new_combined
                                                                                                                                                                                                                                                                                                                                      +    time.sleep(.1)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Now we get values that look like this:

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                      01
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +Turning the knob clockwise we see the 01 before the 11 frequently

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Turning the know counterclockwise:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +01
                                                                                                                                                                                                                                                                                                                                      +00
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Here we see the reverse 10 pattern occur more frequently. But there is noise in the switches as they open and close due to small variations in the contacts as they move.

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                      import time
                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +# we set the old value to zero for both bits being off
                                                                                                                                                                                                                                                                                                                                      +old_combined = 0
                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                      +    A_val = rotaryA.value()
                                                                                                                                                                                                                                                                                                                                      +    B_val = rotaryB.value()
                                                                                                                                                                                                                                                                                                                                      +    # a sifts by one bit and then is ORed with the B calue
                                                                                                                                                                                                                                                                                                                                      +    new_combined = (A_val << 1) | B_val
                                                                                                                                                                                                                                                                                                                                      +    if new_combined != old_combined:
                                                                                                                                                                                                                                                                                                                                      +            #print(A_val, end='')
                                                                                                                                                                                                                                                                                                                                      +            #print(B_val)
                                                                                                                                                                                                                                                                                                                                      +            old_combined = new_combined
                                                                                                                                                                                                                                                                                                                                      +    if A_val == 0 and B_val == 1:
                                                                                                                                                                                                                                                                                                                                      +        print('clock')
                                                                                                                                                                                                                                                                                                                                      +    elif A_val == 1 and B_val == 0:
                                                                                                                                                                                                                                                                                                                                      +        print('counter clock')
                                                                                                                                                                                                                                                                                                                                      +    time.sleep(.1)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      The Rotary Class

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Here is one rotary class:

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Mike Teachman Rotary Class. This is preferred since +it does not call a slow scheduler within an interrupt.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Using a Scheduler

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      There is another class Gurgle Apps Rotary Encoder that uses a scheduler within an interrupt which is not a best practice. However, we can show how this does work work with the one she created. The numbers incremented, but they didn't decrement. I had to change the pins to use the PULL_DOWN settings in the init method.

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                                                                                                                      +41
                                                                                                                                                                                                                                                                                                                                      +42
                                                                                                                                                                                                                                                                                                                                      +43
                                                                                                                                                                                                                                                                                                                                      +44
                                                                                                                                                                                                                                                                                                                                      +45
                                                                                                                                                                                                                                                                                                                                      +46
                                                                                                                                                                                                                                                                                                                                      +47
                                                                                                                                                                                                                                                                                                                                      +48
                                                                                                                                                                                                                                                                                                                                      +49
                                                                                                                                                                                                                                                                                                                                      import machine
                                                                                                                                                                                                                                                                                                                                      +import utime as time
                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                      +import micropython
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +class Rotary:
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    ROT_CW = 1
                                                                                                                                                                                                                                                                                                                                      +    ROT_CCW = 2
                                                                                                                                                                                                                                                                                                                                      +    SW_PRESS = 4
                                                                                                                                                                                                                                                                                                                                      +    SW_RELEASE = 8
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    def __init__(self,dt,clk,sw):
                                                                                                                                                                                                                                                                                                                                      +        self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +        self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +        self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +        self.last_status = (self.dt_pin.value() << 1) | self.clk_pin.value()
                                                                                                                                                                                                                                                                                                                                      +        self.dt_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )
                                                                                                                                                                                                                                                                                                                                      +        self.clk_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )
                                                                                                                                                                                                                                                                                                                                      +        self.sw_pin.irq(handler=self.switch_detect, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING )
                                                                                                                                                                                                                                                                                                                                      +        self.handlers = []
                                                                                                                                                                                                                                                                                                                                      +        self.last_button_status = self.sw_pin.value()
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    def rotary_change(self, pin):
                                                                                                                                                                                                                                                                                                                                      +        new_status = (self.dt_pin.value() << 1) | self.clk_pin.value()
                                                                                                                                                                                                                                                                                                                                      +        if new_status == self.last_status:
                                                                                                                                                                                                                                                                                                                                      +            return
                                                                                                                                                                                                                                                                                                                                      +        transition = (self.last_status << 2) | new_status
                                                                                                                                                                                                                                                                                                                                      +        if transition == 0b1110:
                                                                                                                                                                                                                                                                                                                                      +            micropython.schedule(self.call_handlers, Rotary.ROT_CW)
                                                                                                                                                                                                                                                                                                                                      +        elif transition == 0b1101:
                                                                                                                                                                                                                                                                                                                                      +            micropython.schedule(self.call_handlers, Rotary.ROT_CCW)
                                                                                                                                                                                                                                                                                                                                      +        self.last_status = new_status
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    def switch_detect(self,pin):
                                                                                                                                                                                                                                                                                                                                      +        if self.last_button_status == self.sw_pin.value():
                                                                                                                                                                                                                                                                                                                                      +            return
                                                                                                                                                                                                                                                                                                                                      +        self.last_button_status = self.sw_pin.value()
                                                                                                                                                                                                                                                                                                                                      +        if self.sw_pin.value():
                                                                                                                                                                                                                                                                                                                                      +            micropython.schedule(self.call_handlers, Rotary.SW_RELEASE)
                                                                                                                                                                                                                                                                                                                                      +        else:
                                                                                                                                                                                                                                                                                                                                      +            micropython.schedule(self.call_handlers, Rotary.SW_PRESS)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    def add_handler(self, handler):
                                                                                                                                                                                                                                                                                                                                      +        self.handlers.append(handler)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +    def call_handlers(self, type):
                                                                                                                                                                                                                                                                                                                                      +        for handler in self.handlers:
                                                                                                                                                                                                                                                                                                                                      +            handler(type)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      The following were the lines that I changed:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                                                                                                                                          self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +    self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +    self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Testing Script

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                                                      from rotary import Rotary
                                                                                                                                                                                                                                                                                                                                      +import utime as time
                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +# GPIO Pins 16 and 17 are for the encoder pins. 22 is the button press switch.
                                                                                                                                                                                                                                                                                                                                      +rotary = Rotary(16, 17, 22)
                                                                                                                                                                                                                                                                                                                                      +val = 0
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +def rotary_changed(change):
                                                                                                                                                                                                                                                                                                                                      +    global val
                                                                                                                                                                                                                                                                                                                                      +    if change == Rotary.ROT_CW:
                                                                                                                                                                                                                                                                                                                                      +        val = val + 1
                                                                                                                                                                                                                                                                                                                                      +        print(val)
                                                                                                                                                                                                                                                                                                                                      +    elif change == Rotary.ROT_CCW:
                                                                                                                                                                                                                                                                                                                                      +        val = val - 1
                                                                                                                                                                                                                                                                                                                                      +        print(val)
                                                                                                                                                                                                                                                                                                                                      +    elif change == Rotary.SW_PRESS:
                                                                                                                                                                                                                                                                                                                                      +        print('PRESS')
                                                                                                                                                                                                                                                                                                                                      +    elif change == Rotary.SW_RELEASE:
                                                                                                                                                                                                                                                                                                                                      +        print('RELEASE')
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +rotary.add_handler(rotary_changed)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                      +    time.sleep(0.1)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Adding Plot

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Now I can move the knob back and forth and get consistent values that go up and down. You can turn on the plot function of Thonny to see the values consistently go up and down.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Rotary Encoder Plot

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      Mysterious Runtime Error on Scheduling Queue

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      I did notice that the Shell output did register the following errors:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                                                                                                                                      Traceback (most recent call last):
                                                                                                                                                                                                                                                                                                                                      +  File "rotary.py", line 30, in rotary_change
                                                                                                                                                                                                                                                                                                                                      +RuntimeError: schedule queue full
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      The error also occurred on line 32.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      The following lines generated this error:

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                      micropython.schedule(self.call_handlers, Rotary.ROT_CW)
                                                                                                                                                                                                                                                                                                                                      +micropython.schedule(self.call_handlers, Rotary.ROT_CCW)
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      This error did not seem to impact the execution of the code. My suspicion is that this is a bug in the Micropython firmware.

                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      As a fix, you can use the try/except block an catch any runtime error. The pass function is a no-op (no operation)

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                          def rotary_change(self, pin):
                                                                                                                                                                                                                                                                                                                                      +        new_status = (self.dt_pin.value() << 1) | self.clk_pin.value()
                                                                                                                                                                                                                                                                                                                                      +        if new_status == self.last_status:
                                                                                                                                                                                                                                                                                                                                      +            return
                                                                                                                                                                                                                                                                                                                                      +        transition = (self.last_status << 2) | new_status
                                                                                                                                                                                                                                                                                                                                      +        try:
                                                                                                                                                                                                                                                                                                                                      +            if transition == 0b1110:
                                                                                                                                                                                                                                                                                                                                      +                micropython.schedule(self.call_handlers, Rotary.ROT_CW)
                                                                                                                                                                                                                                                                                                                                      +            elif transition == 0b1101:
                                                                                                                                                                                                                                                                                                                                      +                micropython.schedule(self.call_handlers, Rotary.ROT_CCW)
                                                                                                                                                                                                                                                                                                                                      +        except RuntimeError:
                                                                                                                                                                                                                                                                                                                                      +            pass
                                                                                                                                                                                                                                                                                                                                      +        self.last_status = new_status
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                      References

                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                      1. Counter get stuck on "schedule queue full" - suggest using a try/catch
                                                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                      + Time of Flight Distance +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                      + Compass +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/sensors/11-compass/index.html b/sensors/11-compass/index.html new file mode 100644 index 000000000..31d32a792 --- /dev/null +++ b/sensors/11-compass/index.html @@ -0,0 +1,1905 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Compass - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + Compass + + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Compass + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                            • + + + About the HML5883L + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + Pinout + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + Checking I2C Connections + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                        • + + + About the HML5883L + + + +
                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                        • + + + Pinout + + + +
                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                        • + + + Checking I2C Connections + + + +
                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                                        MicroPython Compass Lab

                                                                                                                                                                                                                                                                                                                                        + + +

                                                                                                                                                                                                                                                                                                                                        Digital Compass Lab Video

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        This lab will use the popular HML5883L chip to show how we can sense a magnetic field and allow our robots to sense the direction they are going.

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        About the HML5883L

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        The HMC5883L is a multi-chip module able to measure magnetic sensing. It can communicate with an I2C digital interface with other devices in order to let creating applications such as low-cost compass, being used in many electronic fields like mobile phones, netbooks, consumer electronics, auto navigation systems, and personal navigation devices.

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        The module works with a low voltage supply (from 2.16 to 3.6V) and also has a low power consumption (100 μA).

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        HMC5883L has a 1° to 2° degrees heading accuracy, which is enough for a wide number of applications. It also allows setting its internal gain to increase resolution with a 3-bit gain control register. But increasing gain also increases noise effects.

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        Pinout

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        The HMC5883L pinout has 5 PINs:

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                        1. Vcc: Connect to the 3.3 volt rail of the breadboard or power supply
                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                        3. GND: Ground
                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                        5. SCL: I2C clock
                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                        7. SDA: I2C data
                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                        9. DRDY: Data ready. You can use this to be notified if new data is ready in memory. We will not use this pin in our labs. The
                                                                                                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        Checking I2C Connections

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        You can use a standard i2c-scanner program to verify that the four pins are connected correctly:

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                                                                                                                                        import machine
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +# Change this if you are using other ports
                                                                                                                                                                                                                                                                                                                                        +I2C_SDA_PIN = 0
                                                                                                                                                                                                                                                                                                                                        +I2C_SCL_PIN = 1
                                                                                                                                                                                                                                                                                                                                        +i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +print('Scanning I2C bus.')
                                                                                                                                                                                                                                                                                                                                        +devices = i2c.scan() # this returns a list of devices
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +device_count = len(devices)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +if device_count == 0:
                                                                                                                                                                                                                                                                                                                                        +    print('No i2c device found.')
                                                                                                                                                                                                                                                                                                                                        +else:
                                                                                                                                                                                                                                                                                                                                        +    print(device_count, 'devices found.')
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +for device in devices:
                                                                                                                                                                                                                                                                                                                                        +    print('Decimal address:', device, ", Hex address: ", hex(device))
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        For my system this returns the following report:

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                        Scanning I2C bus.
                                                                                                                                                                                                                                                                                                                                        +1 devices found.
                                                                                                                                                                                                                                                                                                                                        +Decimal address: 30 , Hex address:  0x1e
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        You will notice that the scanner found a single device at hex address 0x1e.

                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        Like many sensors, this sensor uses a "memory map" to transmit it's data. You can write a quick test to verify that the values are changing by doing a read from this i2c address like this:

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                        data = array('B', [0] * 6)
                                                                                                                                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                                                                                                                                        +    i2c.readfrom_mem_into(0x1e, 0x03, data)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        Here is a program that will display the raw values. You can rotate the sensor to verify the raw values are changing.

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                        +4
                                                                                                                                                                                                                                                                                                                                        +5
                                                                                                                                                                                                                                                                                                                                        +6
                                                                                                                                                                                                                                                                                                                                        +7
                                                                                                                                                                                                                                                                                                                                        +8
                                                                                                                                                                                                                                                                                                                                        from array import array
                                                                                                                                                                                                                                                                                                                                        +# create an incomming data array of 6 bytes
                                                                                                                                                                                                                                                                                                                                        +I2C_SDA_PIN = 0
                                                                                                                                                                                                                                                                                                                                        +I2C_SCL_PIN = 1
                                                                                                                                                                                                                                                                                                                                        +i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
                                                                                                                                                                                                                                                                                                                                        +data = array('B', [0] * 6)
                                                                                                                                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                                                                                                                                        +    i2c.readfrom_mem_into(0x1e, 0x03, data)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        Note that these are "raw" values because they have not been converted to easy-to-understand values by the driver.

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                                                                                                                        from hmc5883l import HMC5883L
                                                                                                                                                                                                                                                                                                                                        +from utime import sleep
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +I2C_SDA_PIN = 0
                                                                                                                                                                                                                                                                                                                                        +I2C_SCL_PIN = 1
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +# i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +# The default address is address=0x1e
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +sensor = HMC5883L(scl=I2C_SDA_PIN, sda=I2C_SCL_PIN)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +while True:
                                                                                                                                                                                                                                                                                                                                        +    x, y, z = sensor.read()
                                                                                                                                                                                                                                                                                                                                        +    # print(sensor.format_result(x, y, z))
                                                                                                                                                                                                                                                                                                                                        +    if x <400:
                                                                                                                                                                                                                                                                                                                                        +        print(x)
                                                                                                                                                                                                                                                                                                                                        +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                        References

                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                        1. PPPPE80 Magnetometer Compass with Raspberry PI Pico: GY-271 HMC5883L wiring and use with MicroPython
                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                        3. PPPPE80 driver
                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                        5. Data Sheet
                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                                        + Rotary Encoder +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                                        + Gesture +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/sensors/13-gesture/index.html b/sensors/13-gesture/index.html new file mode 100644 index 000000000..6b0f23477 --- /dev/null +++ b/sensors/13-gesture/index.html @@ -0,0 +1,2129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Gesture - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + Gesture + + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + DH11 Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + Gesture + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                              • + + + Gesture detection + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + Code + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + Ambient Light + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + Reading RGB + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + RGB Display Graph + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                • + + + Using TinyML + + + +
                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                • + + + Datasheet + + + +
                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                • + + + Other References + + + +
                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                          • + + + Gesture detection + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Code + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Ambient Light + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + Reading RGB + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + RGB Display Graph + + + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                            • + + + Using TinyML + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + Datasheet + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + Other References + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                                          Avago APDS-9960 Gesture Sensor

                                                                                                                                                                                                                                                                                                                                          + + +

                                                                                                                                                                                                                                                                                                                                          The APDS-9960 is an I2C device with advanced Gesture detection, Proximity detection, Digital Ambient Light Sense (ALS) and Color Sense (RGBC). It incorporates an IR LED and factory-calibrated LED driver.

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Gesture detection

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Gesture detection utilizes four directional photodiodes to +sense reflected IR energy (sourced by the integrated LED) +to convert physical motion information (i.e. velocity, direction and distance) to a digital information. The architecture of the gesture engine features automatic activation +(based on Proximity engine results), ambient light subtraction, cross-talk cancelation, dual 8-bit data converters, power saving inter-conversion delay, 32-dataset FIFO, and interrupt driven I2C communication. The gesture engine +accommodates a wide range of mobile device gesturing +requirements: simple UP-DOWN-RIGHT-LEFT gestures or +more complex gestures can be accurately sensed. +Gesture Spectral Response

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Code

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                          import machine
                                                                                                                                                                                                                                                                                                                                          +from time import sleep_ms
                                                                                                                                                                                                                                                                                                                                          +from uPy_APDS9960.apds9960LITE import APDS9960LITE
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +#Init I2C Buss on RP2040
                                                                                                                                                                                                                                                                                                                                          +sda=machine.Pin(12)
                                                                                                                                                                                                                                                                                                                                          +scl=machine.Pin(13)
                                                                                                                                                                                                                                                                                                                                          +i2c =  machine.I2C(0,scl=scl, sda=sda)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +apds9960=APDS9960LITE(i2c)      # Enable sensor
                                                                                                                                                                                                                                                                                                                                          +apds9960.prox.enableSensor()    # Enable Proximit sensing
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                                                                                                                                          +        sleep_ms(25) # wait for readout to be ready
                                                                                                                                                                                                                                                                                                                                          +        print(apds9960.prox.proximityLevel)   #Print the proximity value
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Returns

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          1
                                                                                                                                                                                                                                                                                                                                          0 1 1 1 1 1 0 1 1 2 2 1 1 1 1 1 0 
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Ambient Light

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                                                                                                          # from https://github.com/rlangoy/uPy_APDS9960
                                                                                                                                                                                                                                                                                                                                          +import machine
                                                                                                                                                                                                                                                                                                                                          +from time import sleep,sleep_ms
                                                                                                                                                                                                                                                                                                                                          +from APDS9960LITE import APDS9960LITE
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +#Init I2C Buss on RP2040
                                                                                                                                                                                                                                                                                                                                          +sda=machine.Pin(12)
                                                                                                                                                                                                                                                                                                                                          +scl=machine.Pin(13)
                                                                                                                                                                                                                                                                                                                                          +i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +print(i2c)
                                                                                                                                                                                                                                                                                                                                          +# create the driver
                                                                                                                                                                                                                                                                                                                                          +apds9960=APDS9960LITE(i2c)
                                                                                                                                                                                                                                                                                                                                          +apds9960.als.enableSensor()           # Enable Light sensor
                                                                                                                                                                                                                                                                                                                                          +sleep_ms(25)                          # Wait for readout to be ready
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +#apds9960.powerOn(True)
                                                                                                                                                                                                                                                                                                                                          +#print(apds9960.statusRegister())
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                                                                                                                                          +    print(apds9960.als.ambientLightLevel, ' ', end='')
                                                                                                                                                                                                                                                                                                                                          +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          returns

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          1
                                                                                                                                                                                                                                                                                                                                          1  1  0  0  0  0  0  0  0  0  1  1  1  4  8  10  10  10  12  16  17  19  19  20  21  21  22  25  27  30  33  35  36  37  38  33  33  34  34  34  34  34  35  36  36  38  39  40  38  37  38  40  42  45  48  49  55  61  66  73  76  76  82  93  109  132  156  169  171  173  173  171  164  160  169  165  162  162  164  163  159  158  152  148  148  145  141  135  122  106  96  101  108  89  62  48  33  20  10  5  3  1  0  0  0  0  0  0  0  1  2  4  8  14  26  45  65  91  110  121  124  127  132  150  191  225  244  244  254  288  295  243  219  259  299  287  204  99  31  10  2  1  1  1  0
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Reading RGB

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          1
                                                                                                                                                                                                                                                                                                                                          +2
                                                                                                                                                                                                                                                                                                                                          +3
                                                                                                                                                                                                                                                                                                                                          +4
                                                                                                                                                                                                                                                                                                                                          +5
                                                                                                                                                                                                                                                                                                                                          +6
                                                                                                                                                                                                                                                                                                                                          while True:
                                                                                                                                                                                                                                                                                                                                          +    print(apds9960.als.ambientLightLevel,'', end='')
                                                                                                                                                                                                                                                                                                                                          +    print(apds9960.als.redLightLevel,'', end='')
                                                                                                                                                                                                                                                                                                                                          +    print(apds9960.als.greenLightLevel,'', end='')
                                                                                                                                                                                                                                                                                                                                          +    print(apds9960.als.blueLightLevel)
                                                                                                                                                                                                                                                                                                                                          +    sleep(.1)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                          1 0 0 0
                                                                                                                                                                                                                                                                                                                                          +2 0 0 1
                                                                                                                                                                                                                                                                                                                                          +4 1 0 1
                                                                                                                                                                                                                                                                                                                                          +8 3 2 2
                                                                                                                                                                                                                                                                                                                                          +17 6 5 5
                                                                                                                                                                                                                                                                                                                                          +28 14 10 8
                                                                                                                                                                                                                                                                                                                                          +38 19 12 11
                                                                                                                                                                                                                                                                                                                                          +37 27 15 12
                                                                                                                                                                                                                                                                                                                                          +38 30 15 12
                                                                                                                                                                                                                                                                                                                                          +43 29 15 14
                                                                                                                                                                                                                                                                                                                                          +35 22 11 11
                                                                                                                                                                                                                                                                                                                                          +26 17 9 7
                                                                                                                                                                                                                                                                                                                                          +18 12 6 5
                                                                                                                                                                                                                                                                                                                                          +13 7 4 3
                                                                                                                                                                                                                                                                                                                                          +9 4 3 2
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          RGB Display Graph

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          This program displays the red, green and blue light values as bars on an OLED display.

                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                                                                                                                                          +28
                                                                                                                                                                                                                                                                                                                                          +29
                                                                                                                                                                                                                                                                                                                                          +30
                                                                                                                                                                                                                                                                                                                                          +31
                                                                                                                                                                                                                                                                                                                                          +32
                                                                                                                                                                                                                                                                                                                                          +33
                                                                                                                                                                                                                                                                                                                                          +34
                                                                                                                                                                                                                                                                                                                                          +35
                                                                                                                                                                                                                                                                                                                                          +36
                                                                                                                                                                                                                                                                                                                                          +37
                                                                                                                                                                                                                                                                                                                                          +38
                                                                                                                                                                                                                                                                                                                                          +39
                                                                                                                                                                                                                                                                                                                                          +40
                                                                                                                                                                                                                                                                                                                                          +41
                                                                                                                                                                                                                                                                                                                                          +42
                                                                                                                                                                                                                                                                                                                                          +43
                                                                                                                                                                                                                                                                                                                                          +44
                                                                                                                                                                                                                                                                                                                                          +45
                                                                                                                                                                                                                                                                                                                                          +46
                                                                                                                                                                                                                                                                                                                                          +47
                                                                                                                                                                                                                                                                                                                                          +48
                                                                                                                                                                                                                                                                                                                                          +49
                                                                                                                                                                                                                                                                                                                                          +50
                                                                                                                                                                                                                                                                                                                                          +51
                                                                                                                                                                                                                                                                                                                                          +52
                                                                                                                                                                                                                                                                                                                                          +53
                                                                                                                                                                                                                                                                                                                                          # from https://github.com/rlangoy/uPy_APDS9960
                                                                                                                                                                                                                                                                                                                                          +from machine import Pin, I2C
                                                                                                                                                                                                                                                                                                                                          +import ssd1306
                                                                                                                                                                                                                                                                                                                                          +from time import sleep,sleep_ms
                                                                                                                                                                                                                                                                                                                                          +from APDS9960LITE import APDS9960LITE
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +#Init I2C Buss on RP2040
                                                                                                                                                                                                                                                                                                                                          +sda=Pin(12)
                                                                                                                                                                                                                                                                                                                                          +scl=Pin(13)
                                                                                                                                                                                                                                                                                                                                          +i2c=I2C(0, sda=sda, scl=scl, freq=400000)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +print(i2c)
                                                                                                                                                                                                                                                                                                                                          +# create the driver
                                                                                                                                                                                                                                                                                                                                          +apds9960=APDS9960LITE(i2c)
                                                                                                                                                                                                                                                                                                                                          +apds9960.als.enableSensor()           # Enable Light sensor
                                                                                                                                                                                                                                                                                                                                          +sleep_ms(25)                          # Wait for readout to be ready
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +# display
                                                                                                                                                                                                                                                                                                                                          +WIDTH = 128
                                                                                                                                                                                                                                                                                                                                          +ONE_THIRD_WIDTH = int(WIDTH/3)
                                                                                                                                                                                                                                                                                                                                          +HEIGHT = 64
                                                                                                                                                                                                                                                                                                                                          +clock=Pin(2)
                                                                                                                                                                                                                                                                                                                                          +data=Pin(3)
                                                                                                                                                                                                                                                                                                                                          +RES = machine.Pin(4)
                                                                                                                                                                                                                                                                                                                                          +DC = machine.Pin(5)
                                                                                                                                                                                                                                                                                                                                          +CS = machine.Pin(6)
                                                                                                                                                                                                                                                                                                                                          +spi=machine.SPI(0, sck=clock, mosi=data)
                                                                                                                                                                                                                                                                                                                                          +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +def update_display(red, green, blue):
                                                                                                                                                                                                                                                                                                                                          +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                          +    # scale red, green and blue to the height
                                                                                                                                                                                                                                                                                                                                          +    red = int(red*4)
                                                                                                                                                                                                                                                                                                                                          +    green = int(green*4)
                                                                                                                                                                                                                                                                                                                                          +    blue = int(blue*3)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                          +    # rect_fill(x, y, width, height)
                                                                                                                                                                                                                                                                                                                                          +    oled.fill_rect(0, HEIGHT - red, ONE_THIRD_WIDTH, red, 1)
                                                                                                                                                                                                                                                                                                                                          +    oled.fill_rect(ONE_THIRD_WIDTH, HEIGHT - green, ONE_THIRD_WIDTH, green, 1)
                                                                                                                                                                                                                                                                                                                                          +    oled.fill_rect(ONE_THIRD_WIDTH * 2, HEIGHT - blue, ONE_THIRD_WIDTH, blue, 1)
                                                                                                                                                                                                                                                                                                                                          +    oled.text(str(red), 0, 56, 0)
                                                                                                                                                                                                                                                                                                                                          +    oled.text(str(green), ONE_THIRD_WIDTH, 56, 0)
                                                                                                                                                                                                                                                                                                                                          +    oled.text(str(blue), ONE_THIRD_WIDTH*2, 56, 0)
                                                                                                                                                                                                                                                                                                                                          +    oled.show()
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                                                                                                                                          +    # print(apds9960.als.ambientLightLevel,'', end='')
                                                                                                                                                                                                                                                                                                                                          +    red = apds9960.als.redLightLevel
                                                                                                                                                                                                                                                                                                                                          +    green = apds9960.als.greenLightLevel
                                                                                                                                                                                                                                                                                                                                          +    blue = apds9960.als.blueLightLevel
                                                                                                                                                                                                                                                                                                                                          +    update_display(red, green, blue)
                                                                                                                                                                                                                                                                                                                                          +    sleep(.05)
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          References

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Using TinyML

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://www.hackster.io/mjrobot/tinyml-motion-recognition-using-raspberry-pi-pico-6b6071?f=1

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Datasheet

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          Other References

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://robojax.com/learn/arduino/?vid=robojax-gesture-APDS9960

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://upy-apds9960.readthedocs.io/en/latest/#

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://www.youtube.com/watch?v=wH9HpP9bKwE

                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                          https://github.com/rlangoy/uPy_APDS9960/blob/master/uPy_APDS9960/apds9960LITE.py

                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                                                                                                          + Compass +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                                                                                                          + Introduction +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/sensors/14-microphone/index.html b/sensors/14-microphone/index.html new file mode 100644 index 000000000..5d7069c3c --- /dev/null +++ b/sensors/14-microphone/index.html @@ -0,0 +1,1365 @@ + + + + + + + + + + + + + + + + + + + + + + + Microphone - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + Microphone + + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                            • + + + Basic Sound Sensor + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + INMP441 + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + INMP441 24-bit I2S Interface Omnidirectional Microphone Sensor Module + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                                            Microphone

                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            Basic Sound Sensor

                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            Pros:

                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                            • low cost ($2 or less)
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • able to detect if sound is present and send a digital signal
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • adjustable trim pot to adjust sound level trigger level
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            Cons:

                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                            • low quality sound
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • sound impacted by noise on the power supply
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • limited frequency response
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            INMP441

                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            Pros:

                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                            • high quality sound
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • excellent frequency response
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • I2C interface
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • strong isolation from power supply noise
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            Cons:

                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                            • slightly higher cost ($4)
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • triggers must be written in software
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            I2C Interface

                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            INMP441 24-bit I2S Interface Omnidirectional Microphone Sensor Module

                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                            References

                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                            • Sound Detector Board on eBay
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            • YouTube Video Raspberry Pi Pico Audio Recorder with INMP441 - MCU Application Lab
                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/sensors/dht11-temp-humidity/index.html b/sensors/dht11-temp-humidity/index.html new file mode 100644 index 000000000..0c8107d47 --- /dev/null +++ b/sensors/dht11-temp-humidity/index.html @@ -0,0 +1,1742 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + DH11 Temp and Humidity - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + DH11 Temp and Humidity + + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Photosensor + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Ping Distance + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + IR Distance Sensor + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Temp and Humidity + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Temperature + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + DH11 Temp and Humidity + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                  • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Potentiometer + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Temp, Humidity, Pres + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Accelerometer Compass + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Time of Flight Distance + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Rotary Encoder + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Compass + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Gesture + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                              • + + + Circuit + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                                              The DHT22 (AM2302) Temperature and Humidity Sensor

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              The DHT22 is a low-cost ($2) digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and transmits a digital signal on the data pin.

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              These devices are easy to use since they have an internal analog to digital conversion. They are good for 20-80% humidity readings with 5% accuracy and 0-50°C temperature readings with ±2°C accuracy. They are designed to be polled about once every two seconds.

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              Circuit

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              DHT22 or AM2302 Temperature and Humidity Sensor

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              References

                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                              DHT22 Datasheet (PDF)

                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                                              + Temp, Humidity, Pres +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                                              + Potentiometer +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/sims/breadboard/index.html b/sims/breadboard/index.html new file mode 100644 index 000000000..8e90b4259 --- /dev/null +++ b/sims/breadboard/index.html @@ -0,0 +1,1437 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Breadboard - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + Breadboard + + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Knowledge Graphs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + Breadboard + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                Breadboard Simulator

                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                Breadboard Simulator Over Image - simulator written in P5.js

                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                Vector Breadboard With Zoom

                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                Vector Drawn Breadboard Simulator

                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                                                + Graph Demo +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                                                + Glossary +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/sims/index.html b/sims/index.html new file mode 100644 index 000000000..a30b67a08 --- /dev/null +++ b/sims/index.html @@ -0,0 +1,1432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + Introduction + + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Knowledge Graphs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                  Simulators for Learning MicroPython

                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                                                                                                                                    Knowledge Graph

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                                                                                                                                    Wokwi

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                                                  + RFID RC522 +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                                                  + Introduction +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/sims/knowledge-graphs/concept-dependency/index.html b/sims/knowledge-graphs/concept-dependency/index.html new file mode 100644 index 000000000..52ac366cf --- /dev/null +++ b/sims/knowledge-graphs/concept-dependency/index.html @@ -0,0 +1,2150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Concept Dependency - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + Concept Dependency + + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + Knowledge Graphs + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Concept Enumeration + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Concept Dependency + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Explanation of Dependencies for Selected Concepts + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Final Remarks + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Concept Taxonomy + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Graph Demo + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                    • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                    • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                      • + + + Explanation of Dependencies for Selected Concepts + + + +
                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                      • + + + Final Remarks + + + +
                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                    Concept Dependency

                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Prompt

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                                                                                                                                    Our next step is to create a fully connected dependency graph.
                                                                                                                                                                                                                                                                                                                                                    +In this step, for each line or concept on this list, 
                                                                                                                                                                                                                                                                                                                                                    +please create a new list of other concepts on which it depends.
                                                                                                                                                                                                                                                                                                                                                    +If a concept depends on a specific concept that is not listed,
                                                                                                                                                                                                                                                                                                                                                    +then we must add it as a new concept.
                                                                                                                                                                                                                                                                                                                                                    +This will help us determine the teaching order of the concepts.
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +Return the new list as a CSV file using the following format:
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +The first column is a numeric concept ID you assigned,  
                                                                                                                                                                                                                                                                                                                                                    +the second column is the concept name,
                                                                                                                                                                                                                                                                                                                                                    +and the third column is a pipe-delimited list of the concept IDs
                                                                                                                                                                                                                                                                                                                                                    +that the concept depends upon.
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +Check your results to make sure that all concepts are
                                                                                                                                                                                                                                                                                                                                                    +connected to at least one other concept.
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Response

                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    ChatGPT o1-mini Thought for 53 seconds

                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Here is the CSV file containing the concepts along with their dependencies:

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                    +  2
                                                                                                                                                                                                                                                                                                                                                    +  3
                                                                                                                                                                                                                                                                                                                                                    +  4
                                                                                                                                                                                                                                                                                                                                                    +  5
                                                                                                                                                                                                                                                                                                                                                    +  6
                                                                                                                                                                                                                                                                                                                                                    +  7
                                                                                                                                                                                                                                                                                                                                                    +  8
                                                                                                                                                                                                                                                                                                                                                    +  9
                                                                                                                                                                                                                                                                                                                                                    + 10
                                                                                                                                                                                                                                                                                                                                                    + 11
                                                                                                                                                                                                                                                                                                                                                    + 12
                                                                                                                                                                                                                                                                                                                                                    + 13
                                                                                                                                                                                                                                                                                                                                                    + 14
                                                                                                                                                                                                                                                                                                                                                    + 15
                                                                                                                                                                                                                                                                                                                                                    + 16
                                                                                                                                                                                                                                                                                                                                                    + 17
                                                                                                                                                                                                                                                                                                                                                    + 18
                                                                                                                                                                                                                                                                                                                                                    + 19
                                                                                                                                                                                                                                                                                                                                                    + 20
                                                                                                                                                                                                                                                                                                                                                    + 21
                                                                                                                                                                                                                                                                                                                                                    + 22
                                                                                                                                                                                                                                                                                                                                                    + 23
                                                                                                                                                                                                                                                                                                                                                    + 24
                                                                                                                                                                                                                                                                                                                                                    + 25
                                                                                                                                                                                                                                                                                                                                                    + 26
                                                                                                                                                                                                                                                                                                                                                    + 27
                                                                                                                                                                                                                                                                                                                                                    + 28
                                                                                                                                                                                                                                                                                                                                                    + 29
                                                                                                                                                                                                                                                                                                                                                    + 30
                                                                                                                                                                                                                                                                                                                                                    + 31
                                                                                                                                                                                                                                                                                                                                                    + 32
                                                                                                                                                                                                                                                                                                                                                    + 33
                                                                                                                                                                                                                                                                                                                                                    + 34
                                                                                                                                                                                                                                                                                                                                                    + 35
                                                                                                                                                                                                                                                                                                                                                    + 36
                                                                                                                                                                                                                                                                                                                                                    + 37
                                                                                                                                                                                                                                                                                                                                                    + 38
                                                                                                                                                                                                                                                                                                                                                    + 39
                                                                                                                                                                                                                                                                                                                                                    + 40
                                                                                                                                                                                                                                                                                                                                                    + 41
                                                                                                                                                                                                                                                                                                                                                    + 42
                                                                                                                                                                                                                                                                                                                                                    + 43
                                                                                                                                                                                                                                                                                                                                                    + 44
                                                                                                                                                                                                                                                                                                                                                    + 45
                                                                                                                                                                                                                                                                                                                                                    + 46
                                                                                                                                                                                                                                                                                                                                                    + 47
                                                                                                                                                                                                                                                                                                                                                    + 48
                                                                                                                                                                                                                                                                                                                                                    + 49
                                                                                                                                                                                                                                                                                                                                                    + 50
                                                                                                                                                                                                                                                                                                                                                    + 51
                                                                                                                                                                                                                                                                                                                                                    + 52
                                                                                                                                                                                                                                                                                                                                                    + 53
                                                                                                                                                                                                                                                                                                                                                    + 54
                                                                                                                                                                                                                                                                                                                                                    + 55
                                                                                                                                                                                                                                                                                                                                                    + 56
                                                                                                                                                                                                                                                                                                                                                    + 57
                                                                                                                                                                                                                                                                                                                                                    + 58
                                                                                                                                                                                                                                                                                                                                                    + 59
                                                                                                                                                                                                                                                                                                                                                    + 60
                                                                                                                                                                                                                                                                                                                                                    + 61
                                                                                                                                                                                                                                                                                                                                                    + 62
                                                                                                                                                                                                                                                                                                                                                    + 63
                                                                                                                                                                                                                                                                                                                                                    + 64
                                                                                                                                                                                                                                                                                                                                                    + 65
                                                                                                                                                                                                                                                                                                                                                    + 66
                                                                                                                                                                                                                                                                                                                                                    + 67
                                                                                                                                                                                                                                                                                                                                                    + 68
                                                                                                                                                                                                                                                                                                                                                    + 69
                                                                                                                                                                                                                                                                                                                                                    + 70
                                                                                                                                                                                                                                                                                                                                                    + 71
                                                                                                                                                                                                                                                                                                                                                    + 72
                                                                                                                                                                                                                                                                                                                                                    + 73
                                                                                                                                                                                                                                                                                                                                                    + 74
                                                                                                                                                                                                                                                                                                                                                    + 75
                                                                                                                                                                                                                                                                                                                                                    + 76
                                                                                                                                                                                                                                                                                                                                                    + 77
                                                                                                                                                                                                                                                                                                                                                    + 78
                                                                                                                                                                                                                                                                                                                                                    + 79
                                                                                                                                                                                                                                                                                                                                                    + 80
                                                                                                                                                                                                                                                                                                                                                    + 81
                                                                                                                                                                                                                                                                                                                                                    + 82
                                                                                                                                                                                                                                                                                                                                                    + 83
                                                                                                                                                                                                                                                                                                                                                    + 84
                                                                                                                                                                                                                                                                                                                                                    + 85
                                                                                                                                                                                                                                                                                                                                                    + 86
                                                                                                                                                                                                                                                                                                                                                    + 87
                                                                                                                                                                                                                                                                                                                                                    + 88
                                                                                                                                                                                                                                                                                                                                                    + 89
                                                                                                                                                                                                                                                                                                                                                    + 90
                                                                                                                                                                                                                                                                                                                                                    + 91
                                                                                                                                                                                                                                                                                                                                                    + 92
                                                                                                                                                                                                                                                                                                                                                    + 93
                                                                                                                                                                                                                                                                                                                                                    + 94
                                                                                                                                                                                                                                                                                                                                                    + 95
                                                                                                                                                                                                                                                                                                                                                    + 96
                                                                                                                                                                                                                                                                                                                                                    + 97
                                                                                                                                                                                                                                                                                                                                                    + 98
                                                                                                                                                                                                                                                                                                                                                    + 99
                                                                                                                                                                                                                                                                                                                                                    +100
                                                                                                                                                                                                                                                                                                                                                    +101
                                                                                                                                                                                                                                                                                                                                                    +102
                                                                                                                                                                                                                                                                                                                                                    +103
                                                                                                                                                                                                                                                                                                                                                    +104
                                                                                                                                                                                                                                                                                                                                                    +105
                                                                                                                                                                                                                                                                                                                                                    +106
                                                                                                                                                                                                                                                                                                                                                    +107
                                                                                                                                                                                                                                                                                                                                                    +108
                                                                                                                                                                                                                                                                                                                                                    +109
                                                                                                                                                                                                                                                                                                                                                    +110
                                                                                                                                                                                                                                                                                                                                                    +111
                                                                                                                                                                                                                                                                                                                                                    +112
                                                                                                                                                                                                                                                                                                                                                    +113
                                                                                                                                                                                                                                                                                                                                                    +114
                                                                                                                                                                                                                                                                                                                                                    +115
                                                                                                                                                                                                                                                                                                                                                    +116
                                                                                                                                                                                                                                                                                                                                                    +117
                                                                                                                                                                                                                                                                                                                                                    +118
                                                                                                                                                                                                                                                                                                                                                    +119
                                                                                                                                                                                                                                                                                                                                                    +120
                                                                                                                                                                                                                                                                                                                                                    +121
                                                                                                                                                                                                                                                                                                                                                    +122
                                                                                                                                                                                                                                                                                                                                                    +123
                                                                                                                                                                                                                                                                                                                                                    +124
                                                                                                                                                                                                                                                                                                                                                    +125
                                                                                                                                                                                                                                                                                                                                                    +126
                                                                                                                                                                                                                                                                                                                                                    +127
                                                                                                                                                                                                                                                                                                                                                    +128
                                                                                                                                                                                                                                                                                                                                                    +129
                                                                                                                                                                                                                                                                                                                                                    +130
                                                                                                                                                                                                                                                                                                                                                    +131
                                                                                                                                                                                                                                                                                                                                                    +132
                                                                                                                                                                                                                                                                                                                                                    +133
                                                                                                                                                                                                                                                                                                                                                    +134
                                                                                                                                                                                                                                                                                                                                                    +135
                                                                                                                                                                                                                                                                                                                                                    +136
                                                                                                                                                                                                                                                                                                                                                    +137
                                                                                                                                                                                                                                                                                                                                                    +138
                                                                                                                                                                                                                                                                                                                                                    +139
                                                                                                                                                                                                                                                                                                                                                    +140
                                                                                                                                                                                                                                                                                                                                                    +141
                                                                                                                                                                                                                                                                                                                                                    +142
                                                                                                                                                                                                                                                                                                                                                    +143
                                                                                                                                                                                                                                                                                                                                                    +144
                                                                                                                                                                                                                                                                                                                                                    +145
                                                                                                                                                                                                                                                                                                                                                    +146
                                                                                                                                                                                                                                                                                                                                                    +147
                                                                                                                                                                                                                                                                                                                                                    +148
                                                                                                                                                                                                                                                                                                                                                    +149
                                                                                                                                                                                                                                                                                                                                                    +150
                                                                                                                                                                                                                                                                                                                                                    +151
                                                                                                                                                                                                                                                                                                                                                    +152
                                                                                                                                                                                                                                                                                                                                                    +153
                                                                                                                                                                                                                                                                                                                                                    +154
                                                                                                                                                                                                                                                                                                                                                    +155
                                                                                                                                                                                                                                                                                                                                                    +156
                                                                                                                                                                                                                                                                                                                                                    +157
                                                                                                                                                                                                                                                                                                                                                    +158
                                                                                                                                                                                                                                                                                                                                                    +159
                                                                                                                                                                                                                                                                                                                                                    +160
                                                                                                                                                                                                                                                                                                                                                    +161
                                                                                                                                                                                                                                                                                                                                                    +162
                                                                                                                                                                                                                                                                                                                                                    +163
                                                                                                                                                                                                                                                                                                                                                    +164
                                                                                                                                                                                                                                                                                                                                                    +165
                                                                                                                                                                                                                                                                                                                                                    +166
                                                                                                                                                                                                                                                                                                                                                    +167
                                                                                                                                                                                                                                                                                                                                                    +168
                                                                                                                                                                                                                                                                                                                                                    +169
                                                                                                                                                                                                                                                                                                                                                    +170
                                                                                                                                                                                                                                                                                                                                                    +171
                                                                                                                                                                                                                                                                                                                                                    +172
                                                                                                                                                                                                                                                                                                                                                    +173
                                                                                                                                                                                                                                                                                                                                                    +174
                                                                                                                                                                                                                                                                                                                                                    +175
                                                                                                                                                                                                                                                                                                                                                    +176
                                                                                                                                                                                                                                                                                                                                                    +177
                                                                                                                                                                                                                                                                                                                                                    +178
                                                                                                                                                                                                                                                                                                                                                    +179
                                                                                                                                                                                                                                                                                                                                                    +180
                                                                                                                                                                                                                                                                                                                                                    +181
                                                                                                                                                                                                                                                                                                                                                    +182
                                                                                                                                                                                                                                                                                                                                                    +183
                                                                                                                                                                                                                                                                                                                                                    +184
                                                                                                                                                                                                                                                                                                                                                    +185
                                                                                                                                                                                                                                                                                                                                                    +186
                                                                                                                                                                                                                                                                                                                                                    +187
                                                                                                                                                                                                                                                                                                                                                    +188
                                                                                                                                                                                                                                                                                                                                                    +189
                                                                                                                                                                                                                                                                                                                                                    +190
                                                                                                                                                                                                                                                                                                                                                    +191
                                                                                                                                                                                                                                                                                                                                                    +192
                                                                                                                                                                                                                                                                                                                                                    +193
                                                                                                                                                                                                                                                                                                                                                    +194
                                                                                                                                                                                                                                                                                                                                                    +195
                                                                                                                                                                                                                                                                                                                                                    +196
                                                                                                                                                                                                                                                                                                                                                    +197
                                                                                                                                                                                                                                                                                                                                                    ID,Concept Name,Dependencies (IDs)
                                                                                                                                                                                                                                                                                                                                                    +1,Intro to Computational Thinking,
                                                                                                                                                                                                                                                                                                                                                    +2,Problem Decomposition,1
                                                                                                                                                                                                                                                                                                                                                    +3,Pattern Recognition,1
                                                                                                                                                                                                                                                                                                                                                    +4,Abstraction,1
                                                                                                                                                                                                                                                                                                                                                    +5,Algorithm Design,1|2|3|4
                                                                                                                                                                                                                                                                                                                                                    +6,Basic Programming Concepts,1|5
                                                                                                                                                                                                                                                                                                                                                    +7,Variables in Programming,6
                                                                                                                                                                                                                                                                                                                                                    +8,Data Types in Programming,6|7
                                                                                                                                                                                                                                                                                                                                                    +9,Operators,6|7|8
                                                                                                                                                                                                                                                                                                                                                    +10,Control Structures,6|7|8|9
                                                                                                                                                                                                                                                                                                                                                    +11,Conditional Statements,10|9
                                                                                                                                                                                                                                                                                                                                                    +12,Loops,10
                                                                                                                                                                                                                                                                                                                                                    +13,General Functions in Programming,6|7|8|10
                                                                                                                                                                                                                                                                                                                                                    +14,Introduction to MicroPython,6
                                                                                                                                                                                                                                                                                                                                                    +15,Setting Up MicroPython Environment,14
                                                                                                                                                                                                                                                                                                                                                    +16,Syntax in MicroPython,14|15
                                                                                                                                                                                                                                                                                                                                                    +17,Functions in MicroPython,13|16
                                                                                                                                                                                                                                                                                                                                                    +18,Modules in MicroPython,16|17
                                                                                                                                                                                                                                                                                                                                                    +19,Input and Output,16|7|8
                                                                                                                                                                                                                                                                                                                                                    +20,Working with Strings,8|16
                                                                                                                                                                                                                                                                                                                                                    +21,Working with Numbers,8|16
                                                                                                                                                                                                                                                                                                                                                    +22,Lists,8|16
                                                                                                                                                                                                                                                                                                                                                    +23,Tuples,8|16
                                                                                                                                                                                                                                                                                                                                                    +24,Dictionaries,8|16
                                                                                                                                                                                                                                                                                                                                                    +25,Exception Handling,16|10
                                                                                                                                                                                                                                                                                                                                                    +26,Microcontroller Basics,
                                                                                                                                                                                                                                                                                                                                                    +27,The Raspberry Pi Pico,26
                                                                                                                                                                                                                                                                                                                                                    +28,Understanding GPIO Pins,26|27
                                                                                                                                                                                                                                                                                                                                                    +29,Solderless Breadboards,32
                                                                                                                                                                                                                                                                                                                                                    +30,Breadboard Usage,29|32
                                                                                                                                                                                                                                                                                                                                                    +31,Circuit Basics,
                                                                                                                                                                                                                                                                                                                                                    +32,Ohm's Law,31
                                                                                                                                                                                                                                                                                                                                                    +33,Resistors in Circuits,31|32
                                                                                                                                                                                                                                                                                                                                                    +34,LEDs in Circuits,31
                                                                                                                                                                                                                                                                                                                                                    +35,Using Resistors with LEDs,33|34|32
                                                                                                                                                                                                                                                                                                                                                    +36,Current Limiting Resistors,33|35
                                                                                                                                                                                                                                                                                                                                                    +37,Connecting LEDs,34|30
                                                                                                                                                                                                                                                                                                                                                    +38,Blinking an LED with MicroPython,37|16|28
                                                                                                                                                                                                                                                                                                                                                    +39,Digital Output Signals,28|16
                                                                                                                                                                                                                                                                                                                                                    +40,Digital Input Signals,28|16
                                                                                                                                                                                                                                                                                                                                                    +41,Reading Button Inputs,40|30
                                                                                                                                                                                                                                                                                                                                                    +42,Debouncing Switches,41|10
                                                                                                                                                                                                                                                                                                                                                    +43,Pull-up and Pull-down Resistors,33|41
                                                                                                                                                                                                                                                                                                                                                    +44,Controlling Multiple LEDs,37|38|16
                                                                                                                                                                                                                                                                                                                                                    +45,Using Breadboard Jumpers,30
                                                                                                                                                                                                                                                                                                                                                    +46,Potentiometers in Circuits,31|33
                                                                                                                                                                                                                                                                                                                                                    +47,Reading Analog Inputs,46|28
                                                                                                                                                                                                                                                                                                                                                    +48,Analog-to-Digital Conversion,47
                                                                                                                                                                                                                                                                                                                                                    +49,Using ADC in MicroPython,48|16
                                                                                                                                                                                                                                                                                                                                                    +50,Reading Potentiometer Values,49|46
                                                                                                                                                                                                                                                                                                                                                    +51,Pulse Width Modulation Fundamentals,6|10
                                                                                                                                                                                                                                                                                                                                                    +52,Implementing Pulse Width Modulation in MicroPython,51|16
                                                                                                                                                                                                                                                                                                                                                    +53,LED Brightness Control with Pulse Width Modulation,52|37
                                                                                                                                                                                                                                                                                                                                                    +54,Fading LEDs Using Pulse Width Modulation,53|12
                                                                                                                                                                                                                                                                                                                                                    +55,Advanced Pulse Width Modulation Techniques,54|52
                                                                                                                                                                                                                                                                                                                                                    +56,Servo Motors Overview,31
                                                                                                                                                                                                                                                                                                                                                    +57,Controlling Servo Motors,52|28|56
                                                                                                                                                                                                                                                                                                                                                    +58,DC Motors Overview,31
                                                                                                                                                                                                                                                                                                                                                    +59,Transistors as Switches,31|33
                                                                                                                                                                                                                                                                                                                                                    +60,Controlling Motors with Transistors,59|58
                                                                                                                                                                                                                                                                                                                                                    +61,Transistor Biasing Resistors,59|33
                                                                                                                                                                                                                                                                                                                                                    +62,Power Management with Transistors,59|61
                                                                                                                                                                                                                                                                                                                                                    +63,Photocells,31|33
                                                                                                                                                                                                                                                                                                                                                    +64,Making a Night Light,63|28|16
                                                                                                                                                                                                                                                                                                                                                    +65,Voltage Dividers,33|31
                                                                                                                                                                                                                                                                                                                                                    +66,Voltage Dividers and Sensors,65|63
                                                                                                                                                                                                                                                                                                                                                    +67,Time-of-Flight Sensors,31|28
                                                                                                                                                                                                                                                                                                                                                    +68,Interfacing Time-of-Flight Sensors,67|16
                                                                                                                                                                                                                                                                                                                                                    +69,I2C Protocol,70|16
                                                                                                                                                                                                                                                                                                                                                    +70,SPI Protocol,28|16
                                                                                                                                                                                                                                                                                                                                                    +71,Connecting I2C Devices,69|28
                                                                                                                                                                                                                                                                                                                                                    +72,LED Displays Overview,34|31
                                                                                                                                                                                                                                                                                                                                                    +73,Organic Light-Emitting Diode Displays,72
                                                                                                                                                                                                                                                                                                                                                    +74,Display Drawing,73|16
                                                                                                                                                                                                                                                                                                                                                    +75,Drawing Circles and Ellipses,74
                                                                                                                                                                                                                                                                                                                                                    +76,Drawing Polygons,74
                                                                                                                                                                                                                                                                                                                                                    +77,Changing Fonts,74
                                                                                                                                                                                                                                                                                                                                                    +78,Advanced I2C,69|16
                                                                                                                                                                                                                                                                                                                                                    +79,Advanced SPI,70|16
                                                                                                                                                                                                                                                                                                                                                    +80,WS2812B LED Strips,34|31
                                                                                                                                                                                                                                                                                                                                                    +81,LED Strip Code,80|16
                                                                                                                                                                                                                                                                                                                                                    +82,Moving Pixels on LED Strips,81|12
                                                                                                                                                                                                                                                                                                                                                    +83,LED Strip Patterns,81|82
                                                                                                                                                                                                                                                                                                                                                    +84,LED Strip Button Demos,83|41
                                                                                                                                                                                                                                                                                                                                                    +85,Sensors and Actuators,31|28
                                                                                                                                                                                                                                                                                                                                                    +86,Integrating Multiple Sensors,85|16
                                                                                                                                                                                                                                                                                                                                                    +87,Event-Driven Programming,6|10
                                                                                                                                                                                                                                                                                                                                                    +88,Interrupts,28|87
                                                                                                                                                                                                                                                                                                                                                    +89,Using Interrupts with GPIO Pins,88|28
                                                                                                                                                                                                                                                                                                                                                    +90,Debouncing with Interrupts,89|42
                                                                                                                                                                                                                                                                                                                                                    +91,Timers,6|16
                                                                                                                                                                                                                                                                                                                                                    +92,Delays and Timing Functions,91|16
                                                                                                                                                                                                                                                                                                                                                    +93,Using the Time Module,92|16
                                                                                                                                                                                                                                                                                                                                                    +94,Data Logging with MicroPython,16|97
                                                                                                                                                                                                                                                                                                                                                    +95,Storing Data on Raspberry Pi Pico,94|27
                                                                                                                                                                                                                                                                                                                                                    +96,File Handling,16|95
                                                                                                                                                                                                                                                                                                                                                    +97,Universal Serial Bus Communication,27|16
                                                                                                                                                                                                                                                                                                                                                    +98,Universal Asynchronous Receiver-Transmitter Communication,27|16
                                                                                                                                                                                                                                                                                                                                                    +99,Introduction to Sensors,31
                                                                                                                                                                                                                                                                                                                                                    +100,Temperature Sensors,99|28
                                                                                                                                                                                                                                                                                                                                                    +101,Interfacing Temperature Sensors,100|16
                                                                                                                                                                                                                                                                                                                                                    +102,Humidity Sensors,99|28
                                                                                                                                                                                                                                                                                                                                                    +103,Using DHT11 and DHT22 Sensors,101|102
                                                                                                                                                                                                                                                                                                                                                    +104,Reading Sensor Data,103|16
                                                                                                                                                                                                                                                                                                                                                    +105,Interpreting Sensor Data,104
                                                                                                                                                                                                                                                                                                                                                    +106,Calibrating Sensors,105
                                                                                                                                                                                                                                                                                                                                                    +107,Introduction to Actuators,31
                                                                                                                                                                                                                                                                                                                                                    +108,Controlling Relays,107|16
                                                                                                                                                                                                                                                                                                                                                    +109,Relays Overview,107
                                                                                                                                                                                                                                                                                                                                                    +110,Relays Safety,109
                                                                                                                                                                                                                                                                                                                                                    +111,Stepper Motors,31
                                                                                                                                                                                                                                                                                                                                                    +112,Controlling Stepper Motors,111|16
                                                                                                                                                                                                                                                                                                                                                    +113,Using Stepper Motor Drivers,112|28
                                                                                                                                                                                                                                                                                                                                                    +114,Generating Sound with Buzzers,31|28
                                                                                                                                                                                                                                                                                                                                                    +115,Using Piezoelectric Buzzers,114|16
                                                                                                                                                                                                                                                                                                                                                    +116,Generating Tones and Melodies,115|12
                                                                                                                                                                                                                                                                                                                                                    +117,Infrared Communication,28|16
                                                                                                                                                                                                                                                                                                                                                    +118,Using Infrared Sensors,117|31
                                                                                                                                                                                                                                                                                                                                                    +119,Infrared Remote Control,118|16
                                                                                                                                                                                                                                                                                                                                                    +120,Ultrasonic Sensors,99|28
                                                                                                                                                                                                                                                                                                                                                    +121,Serial Communication Protocols,27|16
                                                                                                                                                                                                                                                                                                                                                    +122,I2C vs SPI vs UART,69|70|98
                                                                                                                                                                                                                                                                                                                                                    +123,Data Communication Principles,121
                                                                                                                                                                                                                                                                                                                                                    +124,Wireless Communication Basics,123
                                                                                                                                                                                                                                                                                                                                                    +125,Bluetooth Low Energy,124|27
                                                                                                                                                                                                                                                                                                                                                    +126,Wi-Fi Connectivity,124|27
                                                                                                                                                                                                                                                                                                                                                    +127,Python Modules Overview,16
                                                                                                                                                                                                                                                                                                                                                    +128,Internet of Things Concepts,124|27
                                                                                                                                                                                                                                                                                                                                                    +129,Connecting to the Internet,126|16
                                                                                                                                                                                                                                                                                                                                                    +130,Sending Data to Web Servers,129|16
                                                                                                                                                                                                                                                                                                                                                    +131,Hypertext Transfer Protocol Basics,130
                                                                                                                                                                                                                                                                                                                                                    +132,Message Queuing Telemetry Transport Protocol,130
                                                                                                                                                                                                                                                                                                                                                    +133,IoT Applications,128|130
                                                                                                                                                                                                                                                                                                                                                    +134,Cloud Services Integration,133
                                                                                                                                                                                                                                                                                                                                                    +135,Data Visualization Tools,134
                                                                                                                                                                                                                                                                                                                                                    +136,Programming Best Practices,6
                                                                                                                                                                                                                                                                                                                                                    +137,Code Optimization Techniques,136
                                                                                                                                                                                                                                                                                                                                                    +138,Debugging Techniques,16|136
                                                                                                                                                                                                                                                                                                                                                    +139,Using Debugging Tools,138
                                                                                                                                                                                                                                                                                                                                                    +140,Version Control Systems,6
                                                                                                                                                                                                                                                                                                                                                    +141,Using Git for Code Management,140
                                                                                                                                                                                                                                                                                                                                                    +142,Collaborative Coding Practices,141
                                                                                                                                                                                                                                                                                                                                                    +143,Documentation Standards,136
                                                                                                                                                                                                                                                                                                                                                    +144,Commenting Code Effectively,136
                                                                                                                                                                                                                                                                                                                                                    +145,Advanced MicroPython Features,16
                                                                                                                                                                                                                                                                                                                                                    +146,Object-Oriented Programming,6|136
                                                                                                                                                                                                                                                                                                                                                    +147,Classes and Objects,146
                                                                                                                                                                                                                                                                                                                                                    +148,Inheritance and Polymorphism,147
                                                                                                                                                                                                                                                                                                                                                    +149,Encapsulation in Object-Oriented Programming,147
                                                                                                                                                                                                                                                                                                                                                    +150,Designing Reusable Code,146|149
                                                                                                                                                                                                                                                                                                                                                    +151,Memory Management,16|136
                                                                                                                                                                                                                                                                                                                                                    +152,Managing Resources Efficiently,151
                                                                                                                                                                                                                                                                                                                                                    +153,Energy Efficiency in Programming,152
                                                                                                                                                                                                                                                                                                                                                    +154,Sleep Modes in Microcontrollers,153|27
                                                                                                                                                                                                                                                                                                                                                    +155,Battery-Powered Projects,154
                                                                                                                                                                                                                                                                                                                                                    +156,Power Management Techniques,155
                                                                                                                                                                                                                                                                                                                                                    +157,Advanced Electronics Concepts,31
                                                                                                                                                                                                                                                                                                                                                    +158,Capacitors in Circuits,157
                                                                                                                                                                                                                                                                                                                                                    +159,Inductors and Coils,157
                                                                                                                                                                                                                                                                                                                                                    +160,Diodes and Rectification,157
                                                                                                                                                                                                                                                                                                                                                    +161,Voltage Regulation,160
                                                                                                                                                                                                                                                                                                                                                    +162,Using Voltage Regulators,161
                                                                                                                                                                                                                                                                                                                                                    +163,Building Power Supplies,162
                                                                                                                                                                                                                                                                                                                                                    +164,Analog Signals vs Digital Signals,31|157
                                                                                                                                                                                                                                                                                                                                                    +165,Signal Conditioning,164|157
                                                                                                                                                                                                                                                                                                                                                    +166,Filtering Noise in Circuits,165
                                                                                                                                                                                                                                                                                                                                                    +167,Interference and Shielding,166
                                                                                                                                                                                                                                                                                                                                                    +168,Electromagnetic Compatibility,167
                                                                                                                                                                                                                                                                                                                                                    +169,Circuit Design Principles,157
                                                                                                                                                                                                                                                                                                                                                    +170,Using Simulation Tools,169
                                                                                                                                                                                                                                                                                                                                                    +171,Prototyping Techniques,169
                                                                                                                                                                                                                                                                                                                                                    +172,Schematic Diagram Reading,169
                                                                                                                                                                                                                                                                                                                                                    +173,Understanding Datasheets,169
                                                                                                                                                                                                                                                                                                                                                    +174,Component Specifications,173
                                                                                                                                                                                                                                                                                                                                                    +175,Safety in Electronics,157
                                                                                                                                                                                                                                                                                                                                                    +176,Electrostatic Discharge Precautions,175
                                                                                                                                                                                                                                                                                                                                                    +177,Soldering Techniques,175
                                                                                                                                                                                                                                                                                                                                                    +178,Printed Circuit Board Design,169
                                                                                                                                                                                                                                                                                                                                                    +179,Using PCB Design Software,178
                                                                                                                                                                                                                                                                                                                                                    +180,Fabricating Custom PCBs,179
                                                                                                                                                                                                                                                                                                                                                    +181,Advanced Sensor Integration,85|157
                                                                                                                                                                                                                                                                                                                                                    +182,Gesture Recognition Sensors,181|28
                                                                                                                                                                                                                                                                                                                                                    +183,Touch Sensors,181|28
                                                                                                                                                                                                                                                                                                                                                    +184,Environmental Monitoring,181|105
                                                                                                                                                                                                                                                                                                                                                    +185,Robotics Basics,31|157
                                                                                                                                                                                                                                                                                                                                                    +186,Building Simple Robots,185|16
                                                                                                                                                                                                                                                                                                                                                    +187,Line-Following Robots,186|83
                                                                                                                                                                                                                                                                                                                                                    +188,Obstacle Avoidance Robots,186|120
                                                                                                                                                                                                                                                                                                                                                    +189,Control Systems Basics,185
                                                                                                                                                                                                                                                                                                                                                    +190,Feedback Mechanisms,189
                                                                                                                                                                                                                                                                                                                                                    +191,Proportional-Integral-Derivative Controllers,190
                                                                                                                                                                                                                                                                                                                                                    +192,Machine Learning Concepts,6|136
                                                                                                                                                                                                                                                                                                                                                    +193,Using MicroPython for Artificial Intelligence,192|16
                                                                                                                                                                                                                                                                                                                                                    +194,Edge Computing,193|128
                                                                                                                                                                                                                                                                                                                                                    +195,Ethics in Technology,6
                                                                                                                                                                                                                                                                                                                                                    +196,Future Trends in Computing,195
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Notes:

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                    • Added Concepts: No additional concepts were required as dependencies were within the provided list.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    • Connectivity Check: All concepts are connected to at least one other concept through dependencies.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    • Formatting: The dependencies are listed using concept IDs, separated by a pipe (|) as per your instructions.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Explanation of Dependencies for Selected Concepts

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                    • +

                                                                                                                                                                                                                                                                                                                                                      Concept 1: Intro to Computational Thinking

                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • Dependencies: None (foundational concept).
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 26: Microcontroller Basics

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: None (introduces the hardware aspect).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 27: The Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Depends on Microcontroller Basics (26) for understanding microcontrollers.

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 38: Blinking an LED with MicroPython

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Connecting LEDs (37), Syntax in MicroPython (16), Understanding GPIO Pins (28).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 57: Controlling Servo Motors

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Implementing PWM in MicroPython (52), Understanding GPIO Pins (28), Servo Motors Overview (56).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 95: Storing Data on Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Data Logging with MicroPython (94), The Raspberry Pi Pico (27).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 128: Internet of Things Concepts

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Wireless Communication Basics (124), The Raspberry Pi Pico (27).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Concept 193: Using MicroPython for Artificial Intelligence

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • +

                                                                                                                                                                                                                                                                                                                                                        Dependencies: Machine Learning Concepts (192), Syntax in MicroPython (16).

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                    Final Remarks

                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                    • The dependencies are designed to ensure that each concept builds upon the necessary foundational knowledge.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    • This structure will aid in determining an effective teaching order for the course, ensuring that students have the requisite background before approaching more advanced topics.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    • By maintaining clear dependencies, the course can be structured to enhance learning progression and retention.
                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                                                                                    + Concept Enumeration +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                                                                                    + Concept Taxonomy +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/sims/knowledge-graphs/concept-enumeration/index.html b/sims/knowledge-graphs/concept-enumeration/index.html new file mode 100644 index 000000000..403308935 --- /dev/null +++ b/sims/knowledge-graphs/concept-enumeration/index.html @@ -0,0 +1,2047 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Concept Enumeration - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + Concept Enumeration + + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + Knowledge Graphs + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Concept Enumeration + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Original List + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Concept Dependency + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Concept Taxonomy + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Graph Demo + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                      • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                      • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                      • + + + Original List + + + +
                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                      Learning Concept Enumeration

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      Prompt

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      ```linenums="0" +Raspberry Pi Pico, and solderless breadboards. +In our labs, we also use many parts such as photosensors, potentiometers, LEDs, resistors, transistors, time-0f-flight sensors, WS2812B LED strips, 128x64 OLED displays, motors, and the Cytron Maker Pi RP2040, which has the same RP2040 microcontroller.

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      We have a lot of material and lesson plans right now, but I would like an overall list of the 200 key concepts we need to cover in this course.

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      For this course, please create a list of the core learning concepts that we need to present in this course and the order in which they should be taught.

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      Please create a list of the 200 most essential concepts +in this course. +Return the concept's preferred label in a numbered list for each learning concept. +Make sure that the concept names are distinct and not synonyms. Don't repeat

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      Start with the most basic foundational concepts and then +proceed to the most complex concepts. Return just one concept label per line. +Avoid using acronyms or abbreviations.

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      Response

                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      ChatGPT o1-preview Thought for 22 seconds

                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      1. Intro to Computational Thinking
                                                                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                                                                      3. Problem Decomposition
                                                                                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                                                                                      5. Pattern Recognition
                                                                                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                                                                                      7. Abstraction
                                                                                                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                                                                                                      9. Algorithm Design
                                                                                                                                                                                                                                                                                                                                                      10. +
                                                                                                                                                                                                                                                                                                                                                      11. Basic Programming Concepts
                                                                                                                                                                                                                                                                                                                                                      12. +
                                                                                                                                                                                                                                                                                                                                                      13. Variables
                                                                                                                                                                                                                                                                                                                                                      14. +
                                                                                                                                                                                                                                                                                                                                                      15. Data Types
                                                                                                                                                                                                                                                                                                                                                      16. +
                                                                                                                                                                                                                                                                                                                                                      17. Operators
                                                                                                                                                                                                                                                                                                                                                      18. +
                                                                                                                                                                                                                                                                                                                                                      19. Control Structures
                                                                                                                                                                                                                                                                                                                                                      20. +
                                                                                                                                                                                                                                                                                                                                                      21. Conditional Statements
                                                                                                                                                                                                                                                                                                                                                      22. +
                                                                                                                                                                                                                                                                                                                                                      23. Loops
                                                                                                                                                                                                                                                                                                                                                      24. +
                                                                                                                                                                                                                                                                                                                                                      25. Functions
                                                                                                                                                                                                                                                                                                                                                      26. +
                                                                                                                                                                                                                                                                                                                                                      27. Introduction to MicroPython
                                                                                                                                                                                                                                                                                                                                                      28. +
                                                                                                                                                                                                                                                                                                                                                      29. Setting Up MicroPython Environment
                                                                                                                                                                                                                                                                                                                                                      30. +
                                                                                                                                                                                                                                                                                                                                                      31. Syntax
                                                                                                                                                                                                                                                                                                                                                      32. +
                                                                                                                                                                                                                                                                                                                                                      33. Variables
                                                                                                                                                                                                                                                                                                                                                      34. +
                                                                                                                                                                                                                                                                                                                                                      35. Data Types
                                                                                                                                                                                                                                                                                                                                                      36. +
                                                                                                                                                                                                                                                                                                                                                      37. Input and Output
                                                                                                                                                                                                                                                                                                                                                      38. +
                                                                                                                                                                                                                                                                                                                                                      39. Working with Strings
                                                                                                                                                                                                                                                                                                                                                      40. +
                                                                                                                                                                                                                                                                                                                                                      41. Working with Numbers
                                                                                                                                                                                                                                                                                                                                                      42. +
                                                                                                                                                                                                                                                                                                                                                      43. Lists
                                                                                                                                                                                                                                                                                                                                                      44. +
                                                                                                                                                                                                                                                                                                                                                      45. Tuples
                                                                                                                                                                                                                                                                                                                                                      46. +
                                                                                                                                                                                                                                                                                                                                                      47. Dictionaries
                                                                                                                                                                                                                                                                                                                                                      48. +
                                                                                                                                                                                                                                                                                                                                                      49. Functions
                                                                                                                                                                                                                                                                                                                                                      50. +
                                                                                                                                                                                                                                                                                                                                                      51. Modules
                                                                                                                                                                                                                                                                                                                                                      52. +
                                                                                                                                                                                                                                                                                                                                                      53. Exception Handling
                                                                                                                                                                                                                                                                                                                                                      54. +
                                                                                                                                                                                                                                                                                                                                                      55. The Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      56. +
                                                                                                                                                                                                                                                                                                                                                      57. The Thonny IDE
                                                                                                                                                                                                                                                                                                                                                      58. +
                                                                                                                                                                                                                                                                                                                                                      59. Microcontroller Basics
                                                                                                                                                                                                                                                                                                                                                      60. +
                                                                                                                                                                                                                                                                                                                                                      61. Understanding GPIO Pins
                                                                                                                                                                                                                                                                                                                                                      62. +
                                                                                                                                                                                                                                                                                                                                                      63. Solderless Breadboards
                                                                                                                                                                                                                                                                                                                                                      64. +
                                                                                                                                                                                                                                                                                                                                                      65. Breadboard Usage
                                                                                                                                                                                                                                                                                                                                                      66. +
                                                                                                                                                                                                                                                                                                                                                      67. Circuit Basics
                                                                                                                                                                                                                                                                                                                                                      68. +
                                                                                                                                                                                                                                                                                                                                                      69. Ohm's Law
                                                                                                                                                                                                                                                                                                                                                      70. +
                                                                                                                                                                                                                                                                                                                                                      71. Resistors in Circuits
                                                                                                                                                                                                                                                                                                                                                      72. +
                                                                                                                                                                                                                                                                                                                                                      73. LEDs in Circuits
                                                                                                                                                                                                                                                                                                                                                      74. +
                                                                                                                                                                                                                                                                                                                                                      75. Using Resistors with LEDs
                                                                                                                                                                                                                                                                                                                                                      76. +
                                                                                                                                                                                                                                                                                                                                                      77. Current Limiting Resistors
                                                                                                                                                                                                                                                                                                                                                      78. +
                                                                                                                                                                                                                                                                                                                                                      79. Connecting LEDs
                                                                                                                                                                                                                                                                                                                                                      80. +
                                                                                                                                                                                                                                                                                                                                                      81. Blinking an LED with MicroPython
                                                                                                                                                                                                                                                                                                                                                      82. +
                                                                                                                                                                                                                                                                                                                                                      83. Digital Output Signals
                                                                                                                                                                                                                                                                                                                                                      84. +
                                                                                                                                                                                                                                                                                                                                                      85. Digital Input Signals
                                                                                                                                                                                                                                                                                                                                                      86. +
                                                                                                                                                                                                                                                                                                                                                      87. Reading Button Inputs
                                                                                                                                                                                                                                                                                                                                                      88. +
                                                                                                                                                                                                                                                                                                                                                      89. Debouncing Switches
                                                                                                                                                                                                                                                                                                                                                      90. +
                                                                                                                                                                                                                                                                                                                                                      91. Pull-up and Pull-down Resistors
                                                                                                                                                                                                                                                                                                                                                      92. +
                                                                                                                                                                                                                                                                                                                                                      93. Controlling Multiple LEDs
                                                                                                                                                                                                                                                                                                                                                      94. +
                                                                                                                                                                                                                                                                                                                                                      95. Using Breadboard Jumpers
                                                                                                                                                                                                                                                                                                                                                      96. +
                                                                                                                                                                                                                                                                                                                                                      97. Potentiometers in Circuits
                                                                                                                                                                                                                                                                                                                                                      98. +
                                                                                                                                                                                                                                                                                                                                                      99. Reading Analog Inputs
                                                                                                                                                                                                                                                                                                                                                      100. +
                                                                                                                                                                                                                                                                                                                                                      101. Analog-to-Digital Conversion
                                                                                                                                                                                                                                                                                                                                                      102. +
                                                                                                                                                                                                                                                                                                                                                      103. Using ADC
                                                                                                                                                                                                                                                                                                                                                      104. +
                                                                                                                                                                                                                                                                                                                                                      105. Reading Potentiometer Values
                                                                                                                                                                                                                                                                                                                                                      106. +
                                                                                                                                                                                                                                                                                                                                                      107. LED Brightness with PWM
                                                                                                                                                                                                                                                                                                                                                      108. +
                                                                                                                                                                                                                                                                                                                                                      109. Pulse Width Modulation
                                                                                                                                                                                                                                                                                                                                                      110. +
                                                                                                                                                                                                                                                                                                                                                      111. Using Pulse Width Modulation
                                                                                                                                                                                                                                                                                                                                                      112. +
                                                                                                                                                                                                                                                                                                                                                      113. Fading an LED with PWM
                                                                                                                                                                                                                                                                                                                                                      114. +
                                                                                                                                                                                                                                                                                                                                                      115. Controlling Servo Motors
                                                                                                                                                                                                                                                                                                                                                      116. +
                                                                                                                                                                                                                                                                                                                                                      117. Servo Motors
                                                                                                                                                                                                                                                                                                                                                      118. +
                                                                                                                                                                                                                                                                                                                                                      119. DC Motors
                                                                                                                                                                                                                                                                                                                                                      120. +
                                                                                                                                                                                                                                                                                                                                                      121. Transistors as Switches
                                                                                                                                                                                                                                                                                                                                                      122. +
                                                                                                                                                                                                                                                                                                                                                      123. Transistors Motors Control
                                                                                                                                                                                                                                                                                                                                                      124. +
                                                                                                                                                                                                                                                                                                                                                      125. Transistor Bias Resistors
                                                                                                                                                                                                                                                                                                                                                      126. +
                                                                                                                                                                                                                                                                                                                                                      127. Transistors Power
                                                                                                                                                                                                                                                                                                                                                      128. +
                                                                                                                                                                                                                                                                                                                                                      129. Photocells
                                                                                                                                                                                                                                                                                                                                                      130. +
                                                                                                                                                                                                                                                                                                                                                      131. Making a Night Light
                                                                                                                                                                                                                                                                                                                                                      132. +
                                                                                                                                                                                                                                                                                                                                                      133. Voltage Dividers
                                                                                                                                                                                                                                                                                                                                                      134. +
                                                                                                                                                                                                                                                                                                                                                      135. Voltage Dividers and Sensors
                                                                                                                                                                                                                                                                                                                                                      136. +
                                                                                                                                                                                                                                                                                                                                                      137. Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                                                                      138. +
                                                                                                                                                                                                                                                                                                                                                      139. Interfacing Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                                                                      140. +
                                                                                                                                                                                                                                                                                                                                                      141. I2C Protocol
                                                                                                                                                                                                                                                                                                                                                      142. +
                                                                                                                                                                                                                                                                                                                                                      143. SPI Protocol
                                                                                                                                                                                                                                                                                                                                                      144. +
                                                                                                                                                                                                                                                                                                                                                      145. Connecting Inter-Integrated Circuit Devices
                                                                                                                                                                                                                                                                                                                                                      146. +
                                                                                                                                                                                                                                                                                                                                                      147. LED Displays
                                                                                                                                                                                                                                                                                                                                                      148. +
                                                                                                                                                                                                                                                                                                                                                      149. OLED Displays
                                                                                                                                                                                                                                                                                                                                                      150. +
                                                                                                                                                                                                                                                                                                                                                      151. Display Drawing
                                                                                                                                                                                                                                                                                                                                                      152. +
                                                                                                                                                                                                                                                                                                                                                      153. Drawing Circles and Ellipse
                                                                                                                                                                                                                                                                                                                                                      154. +
                                                                                                                                                                                                                                                                                                                                                      155. Drawing Polygons
                                                                                                                                                                                                                                                                                                                                                      156. +
                                                                                                                                                                                                                                                                                                                                                      157. Changing Fonts
                                                                                                                                                                                                                                                                                                                                                      158. +
                                                                                                                                                                                                                                                                                                                                                      159. Advanced I2C
                                                                                                                                                                                                                                                                                                                                                      160. +
                                                                                                                                                                                                                                                                                                                                                      161. Advanced SPI
                                                                                                                                                                                                                                                                                                                                                      162. +
                                                                                                                                                                                                                                                                                                                                                      163. WS2812B LED Strips
                                                                                                                                                                                                                                                                                                                                                      164. +
                                                                                                                                                                                                                                                                                                                                                      165. LED Strip Code
                                                                                                                                                                                                                                                                                                                                                      166. +
                                                                                                                                                                                                                                                                                                                                                      167. Moving Pixels on LED Strips
                                                                                                                                                                                                                                                                                                                                                      168. +
                                                                                                                                                                                                                                                                                                                                                      169. LED Strip Patterns
                                                                                                                                                                                                                                                                                                                                                      170. +
                                                                                                                                                                                                                                                                                                                                                      171. LED Strip Button Demos
                                                                                                                                                                                                                                                                                                                                                      172. +
                                                                                                                                                                                                                                                                                                                                                      173. Sensors and Actuators
                                                                                                                                                                                                                                                                                                                                                      174. +
                                                                                                                                                                                                                                                                                                                                                      175. Integrating Multiple Sensors
                                                                                                                                                                                                                                                                                                                                                      176. +
                                                                                                                                                                                                                                                                                                                                                      177. Event-Driven Programming
                                                                                                                                                                                                                                                                                                                                                      178. +
                                                                                                                                                                                                                                                                                                                                                      179. Interrupts
                                                                                                                                                                                                                                                                                                                                                      180. +
                                                                                                                                                                                                                                                                                                                                                      181. Using Interrupts with GPIO Pins
                                                                                                                                                                                                                                                                                                                                                      182. +
                                                                                                                                                                                                                                                                                                                                                      183. Debouncing with Interrupts
                                                                                                                                                                                                                                                                                                                                                      184. +
                                                                                                                                                                                                                                                                                                                                                      185. Timers
                                                                                                                                                                                                                                                                                                                                                      186. +
                                                                                                                                                                                                                                                                                                                                                      187. Delays and Timing Functions
                                                                                                                                                                                                                                                                                                                                                      188. +
                                                                                                                                                                                                                                                                                                                                                      189. Using the Time Module
                                                                                                                                                                                                                                                                                                                                                      190. +
                                                                                                                                                                                                                                                                                                                                                      191. Data Logging with MicroPython
                                                                                                                                                                                                                                                                                                                                                      192. +
                                                                                                                                                                                                                                                                                                                                                      193. Storing Data on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      194. +
                                                                                                                                                                                                                                                                                                                                                      195. File Handling
                                                                                                                                                                                                                                                                                                                                                      196. +
                                                                                                                                                                                                                                                                                                                                                      197. USB
                                                                                                                                                                                                                                                                                                                                                      198. +
                                                                                                                                                                                                                                                                                                                                                      199. UART
                                                                                                                                                                                                                                                                                                                                                      200. +
                                                                                                                                                                                                                                                                                                                                                      201. Introduction to Sensors
                                                                                                                                                                                                                                                                                                                                                      202. +
                                                                                                                                                                                                                                                                                                                                                      203. Temperature Sensors
                                                                                                                                                                                                                                                                                                                                                      204. +
                                                                                                                                                                                                                                                                                                                                                      205. Interfacing Temperature Sensors
                                                                                                                                                                                                                                                                                                                                                      206. +
                                                                                                                                                                                                                                                                                                                                                      207. Humidity Sensors
                                                                                                                                                                                                                                                                                                                                                      208. +
                                                                                                                                                                                                                                                                                                                                                      209. Using DHT11 and DHT22 Sensors
                                                                                                                                                                                                                                                                                                                                                      210. +
                                                                                                                                                                                                                                                                                                                                                      211. Reading Sensor Data
                                                                                                                                                                                                                                                                                                                                                      212. +
                                                                                                                                                                                                                                                                                                                                                      213. Interpreting Sensor Data
                                                                                                                                                                                                                                                                                                                                                      214. +
                                                                                                                                                                                                                                                                                                                                                      215. Calibrating Sensors
                                                                                                                                                                                                                                                                                                                                                      216. +
                                                                                                                                                                                                                                                                                                                                                      217. Introduction to Actuators
                                                                                                                                                                                                                                                                                                                                                      218. +
                                                                                                                                                                                                                                                                                                                                                      219. Controlling Relays
                                                                                                                                                                                                                                                                                                                                                      220. +
                                                                                                                                                                                                                                                                                                                                                      221. Relays
                                                                                                                                                                                                                                                                                                                                                      222. +
                                                                                                                                                                                                                                                                                                                                                      223. Relays Safety
                                                                                                                                                                                                                                                                                                                                                      224. +
                                                                                                                                                                                                                                                                                                                                                      225. Stepper Motors
                                                                                                                                                                                                                                                                                                                                                      226. +
                                                                                                                                                                                                                                                                                                                                                      227. Controlling Stepper Motors
                                                                                                                                                                                                                                                                                                                                                      228. +
                                                                                                                                                                                                                                                                                                                                                      229. Using Stepper Motor Drivers
                                                                                                                                                                                                                                                                                                                                                      230. +
                                                                                                                                                                                                                                                                                                                                                      231. Advanced PWM
                                                                                                                                                                                                                                                                                                                                                      232. +
                                                                                                                                                                                                                                                                                                                                                      233. Generating Sound with Buzzers
                                                                                                                                                                                                                                                                                                                                                      234. +
                                                                                                                                                                                                                                                                                                                                                      235. Using Piezoelectric Buzzers
                                                                                                                                                                                                                                                                                                                                                      236. +
                                                                                                                                                                                                                                                                                                                                                      237. Generating Tones and Melodies
                                                                                                                                                                                                                                                                                                                                                      238. +
                                                                                                                                                                                                                                                                                                                                                      239. Infrared Communication
                                                                                                                                                                                                                                                                                                                                                      240. +
                                                                                                                                                                                                                                                                                                                                                      241. Using Infrared Sensors
                                                                                                                                                                                                                                                                                                                                                      242. +
                                                                                                                                                                                                                                                                                                                                                      243. Infrared Remote Control
                                                                                                                                                                                                                                                                                                                                                      244. +
                                                                                                                                                                                                                                                                                                                                                      245. Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                                                                      246. +
                                                                                                                                                                                                                                                                                                                                                      247. Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                                                                      248. +
                                                                                                                                                                                                                                                                                                                                                      249. Serial Communication Protocols
                                                                                                                                                                                                                                                                                                                                                      250. +
                                                                                                                                                                                                                                                                                                                                                      251. I2C vs SPI vs UART
                                                                                                                                                                                                                                                                                                                                                      252. +
                                                                                                                                                                                                                                                                                                                                                      253. Data Communication Principles
                                                                                                                                                                                                                                                                                                                                                      254. +
                                                                                                                                                                                                                                                                                                                                                      255. Wireless Communication Basics
                                                                                                                                                                                                                                                                                                                                                      256. +
                                                                                                                                                                                                                                                                                                                                                      257. Bluetooth Low Energy
                                                                                                                                                                                                                                                                                                                                                      258. +
                                                                                                                                                                                                                                                                                                                                                      259. Wi-Fi Connectivity
                                                                                                                                                                                                                                                                                                                                                      260. +
                                                                                                                                                                                                                                                                                                                                                      261. Python Modules
                                                                                                                                                                                                                                                                                                                                                      262. +
                                                                                                                                                                                                                                                                                                                                                      263. IoT
                                                                                                                                                                                                                                                                                                                                                      264. +
                                                                                                                                                                                                                                                                                                                                                      265. Connecting to the Internet
                                                                                                                                                                                                                                                                                                                                                      266. +
                                                                                                                                                                                                                                                                                                                                                      267. Sending Data to Web Servers
                                                                                                                                                                                                                                                                                                                                                      268. +
                                                                                                                                                                                                                                                                                                                                                      269. Hypertext Transfer Protocol Basics
                                                                                                                                                                                                                                                                                                                                                      270. +
                                                                                                                                                                                                                                                                                                                                                      271. MQTT
                                                                                                                                                                                                                                                                                                                                                      272. +
                                                                                                                                                                                                                                                                                                                                                      273. IoT Applications
                                                                                                                                                                                                                                                                                                                                                      274. +
                                                                                                                                                                                                                                                                                                                                                      275. Cloud Services Integration
                                                                                                                                                                                                                                                                                                                                                      276. +
                                                                                                                                                                                                                                                                                                                                                      277. Data Visualization Tools
                                                                                                                                                                                                                                                                                                                                                      278. +
                                                                                                                                                                                                                                                                                                                                                      279. Programming Best Practices
                                                                                                                                                                                                                                                                                                                                                      280. +
                                                                                                                                                                                                                                                                                                                                                      281. Code Optimization Techniques
                                                                                                                                                                                                                                                                                                                                                      282. +
                                                                                                                                                                                                                                                                                                                                                      283. Debugging Techniques
                                                                                                                                                                                                                                                                                                                                                      284. +
                                                                                                                                                                                                                                                                                                                                                      285. Using Debugging Tools
                                                                                                                                                                                                                                                                                                                                                      286. +
                                                                                                                                                                                                                                                                                                                                                      287. Version Control Systems
                                                                                                                                                                                                                                                                                                                                                      288. +
                                                                                                                                                                                                                                                                                                                                                      289. Using Git for Code Management
                                                                                                                                                                                                                                                                                                                                                      290. +
                                                                                                                                                                                                                                                                                                                                                      291. Collaborative Coding Practices
                                                                                                                                                                                                                                                                                                                                                      292. +
                                                                                                                                                                                                                                                                                                                                                      293. Documentation Standards
                                                                                                                                                                                                                                                                                                                                                      294. +
                                                                                                                                                                                                                                                                                                                                                      295. Commenting Code Effectively
                                                                                                                                                                                                                                                                                                                                                      296. +
                                                                                                                                                                                                                                                                                                                                                      297. Advanced MicroPython Features
                                                                                                                                                                                                                                                                                                                                                      298. +
                                                                                                                                                                                                                                                                                                                                                      299. Object-Oriented Programming
                                                                                                                                                                                                                                                                                                                                                      300. +
                                                                                                                                                                                                                                                                                                                                                      301. Classes and Objects
                                                                                                                                                                                                                                                                                                                                                      302. +
                                                                                                                                                                                                                                                                                                                                                      303. Inheritance and Polymorphism
                                                                                                                                                                                                                                                                                                                                                      304. +
                                                                                                                                                                                                                                                                                                                                                      305. Encapsulation in OOP
                                                                                                                                                                                                                                                                                                                                                      306. +
                                                                                                                                                                                                                                                                                                                                                      307. Designing Reusable Code
                                                                                                                                                                                                                                                                                                                                                      308. +
                                                                                                                                                                                                                                                                                                                                                      309. Memory Management
                                                                                                                                                                                                                                                                                                                                                      310. +
                                                                                                                                                                                                                                                                                                                                                      311. Managing Resources Efficiently
                                                                                                                                                                                                                                                                                                                                                      312. +
                                                                                                                                                                                                                                                                                                                                                      313. Energy Efficiency
                                                                                                                                                                                                                                                                                                                                                      314. +
                                                                                                                                                                                                                                                                                                                                                      315. Sleep Modes in Microcontrollers
                                                                                                                                                                                                                                                                                                                                                      316. +
                                                                                                                                                                                                                                                                                                                                                      317. Battery-Powered Projects
                                                                                                                                                                                                                                                                                                                                                      318. +
                                                                                                                                                                                                                                                                                                                                                      319. Power Management Techniques
                                                                                                                                                                                                                                                                                                                                                      320. +
                                                                                                                                                                                                                                                                                                                                                      321. Advanced Electronics Concepts
                                                                                                                                                                                                                                                                                                                                                      322. +
                                                                                                                                                                                                                                                                                                                                                      323. Capacitors in Circuits
                                                                                                                                                                                                                                                                                                                                                      324. +
                                                                                                                                                                                                                                                                                                                                                      325. Inductors and Coils
                                                                                                                                                                                                                                                                                                                                                      326. +
                                                                                                                                                                                                                                                                                                                                                      327. Diodes and Rectification
                                                                                                                                                                                                                                                                                                                                                      328. +
                                                                                                                                                                                                                                                                                                                                                      329. Voltage Regulation
                                                                                                                                                                                                                                                                                                                                                      330. +
                                                                                                                                                                                                                                                                                                                                                      331. Using Voltage Regulators
                                                                                                                                                                                                                                                                                                                                                      332. +
                                                                                                                                                                                                                                                                                                                                                      333. Building Power Supplies
                                                                                                                                                                                                                                                                                                                                                      334. +
                                                                                                                                                                                                                                                                                                                                                      335. Analog Signals vs. Digital Signals
                                                                                                                                                                                                                                                                                                                                                      336. +
                                                                                                                                                                                                                                                                                                                                                      337. Signal Conditioning
                                                                                                                                                                                                                                                                                                                                                      338. +
                                                                                                                                                                                                                                                                                                                                                      339. Filtering Noise in Circuits
                                                                                                                                                                                                                                                                                                                                                      340. +
                                                                                                                                                                                                                                                                                                                                                      341. Interference and Shielding
                                                                                                                                                                                                                                                                                                                                                      342. +
                                                                                                                                                                                                                                                                                                                                                      343. Electromagnetic Compatibility
                                                                                                                                                                                                                                                                                                                                                      344. +
                                                                                                                                                                                                                                                                                                                                                      345. Circuit Design Principles
                                                                                                                                                                                                                                                                                                                                                      346. +
                                                                                                                                                                                                                                                                                                                                                      347. Using Simulation Tools
                                                                                                                                                                                                                                                                                                                                                      348. +
                                                                                                                                                                                                                                                                                                                                                      349. Prototyping Techniques
                                                                                                                                                                                                                                                                                                                                                      350. +
                                                                                                                                                                                                                                                                                                                                                      351. Schematic Diagram Reading
                                                                                                                                                                                                                                                                                                                                                      352. +
                                                                                                                                                                                                                                                                                                                                                      353. Understanding Datasheets
                                                                                                                                                                                                                                                                                                                                                      354. +
                                                                                                                                                                                                                                                                                                                                                      355. Component Specifications
                                                                                                                                                                                                                                                                                                                                                      356. +
                                                                                                                                                                                                                                                                                                                                                      357. Safety in Electronics
                                                                                                                                                                                                                                                                                                                                                      358. +
                                                                                                                                                                                                                                                                                                                                                      359. Electrostatic Discharge Precautions
                                                                                                                                                                                                                                                                                                                                                      360. +
                                                                                                                                                                                                                                                                                                                                                      361. Soldering Techniques
                                                                                                                                                                                                                                                                                                                                                      362. +
                                                                                                                                                                                                                                                                                                                                                      363. Printed Circuit Board Design
                                                                                                                                                                                                                                                                                                                                                      364. +
                                                                                                                                                                                                                                                                                                                                                      365. Using PCB Design Software
                                                                                                                                                                                                                                                                                                                                                      366. +
                                                                                                                                                                                                                                                                                                                                                      367. Fabricating Custom PCB
                                                                                                                                                                                                                                                                                                                                                      368. +
                                                                                                                                                                                                                                                                                                                                                      369. Advanced Sensor Integration
                                                                                                                                                                                                                                                                                                                                                      370. +
                                                                                                                                                                                                                                                                                                                                                      371. Gesture Recognition Sensors
                                                                                                                                                                                                                                                                                                                                                      372. +
                                                                                                                                                                                                                                                                                                                                                      373. Touch Sensors
                                                                                                                                                                                                                                                                                                                                                      374. +
                                                                                                                                                                                                                                                                                                                                                      375. Environmental Monitoring
                                                                                                                                                                                                                                                                                                                                                      376. +
                                                                                                                                                                                                                                                                                                                                                      377. Robotics Basics
                                                                                                                                                                                                                                                                                                                                                      378. +
                                                                                                                                                                                                                                                                                                                                                      379. Building Simple Robots
                                                                                                                                                                                                                                                                                                                                                      380. +
                                                                                                                                                                                                                                                                                                                                                      381. Line-Following Robots
                                                                                                                                                                                                                                                                                                                                                      382. +
                                                                                                                                                                                                                                                                                                                                                      383. Obstacle Avoidance Robots
                                                                                                                                                                                                                                                                                                                                                      384. +
                                                                                                                                                                                                                                                                                                                                                      385. Control Systems Basics
                                                                                                                                                                                                                                                                                                                                                      386. +
                                                                                                                                                                                                                                                                                                                                                      387. Feedback Mechanisms
                                                                                                                                                                                                                                                                                                                                                      388. +
                                                                                                                                                                                                                                                                                                                                                      389. PID Controllers
                                                                                                                                                                                                                                                                                                                                                      390. +
                                                                                                                                                                                                                                                                                                                                                      391. Machine Learning Concepts
                                                                                                                                                                                                                                                                                                                                                      392. +
                                                                                                                                                                                                                                                                                                                                                      393. Using MicroPython for AI
                                                                                                                                                                                                                                                                                                                                                      394. +
                                                                                                                                                                                                                                                                                                                                                      395. Edge Computing
                                                                                                                                                                                                                                                                                                                                                      396. +
                                                                                                                                                                                                                                                                                                                                                      397. Ethics in Technology
                                                                                                                                                                                                                                                                                                                                                      398. +
                                                                                                                                                                                                                                                                                                                                                      399. Future Trends in Computing
                                                                                                                                                                                                                                                                                                                                                      400. +
                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                      Original List

                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to Computational Thinking
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Problem Decomposition
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Pattern Recognition
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Abstraction
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Algorithm Design
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Basic Programming Concepts
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Variables in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Data Types in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Operators in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Control Structures in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Conditional Statements
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Loops in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Functions in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Setting Up MicroPython Environment
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Syntax in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Variables in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Data Types in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Input and Output in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Working with Strings in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Working with Numbers in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Lists in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Tuples in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Dictionaries in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Functions in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Modules in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Exception Handling in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Setting Up Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Microcontroller Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Understanding GPIO Pins
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Breadboard Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Solderless Breadboard Usage
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Circuit Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Ohm's Law
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Resistors in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • LEDs in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Resistors with LEDs
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Current Limiting Resistors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Connecting LEDs to Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Blinking an LED with MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Digital Output Signals
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Digital Input Signals
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Reading Button Inputs
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Debouncing Switches
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Pull-up and Pull-down Resistors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling Multiple LEDs
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Breadboard Jumpers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Potentiometers in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Reading Analog Inputs
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Analog-to-Digital Conversion
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using the ADC on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Reading Potentiometer Values
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling LED Brightness with Pulse Width Modulation
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Pulse Width Modulation
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Pulse Width Modulation in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Fading an LED with Pulse Width Modulation
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling Servo Motors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Servo Motors with Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interfacing Direct Current Motors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Transistors as Switches
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Transistors to Control Motors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Understanding NPN Transistors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Understanding PNP Transistors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Photocells in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Reading Light Levels with Photocells
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Voltage Dividers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Voltage Dividers with Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interfacing Time-of-Flight Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Inter-Integrated Circuit Communication Protocol
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Inter-Integrated Circuit in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Connecting Inter-Integrated Circuit Devices
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using 128x64 Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Displaying Text on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Displaying Graphics on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Understanding Display Coordinates
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Fonts on Organic Light-Emitting Diode Displays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Serial Peripheral Interface Communication Protocol
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Serial Peripheral Interface in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • WS2812B Light-Emitting Diode Strips
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling WS2812B Light-Emitting Diodes
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Neopixel Library
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Creating Color Effects on WS2812B Light-Emitting Diodes
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Programming Color Patterns
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Sensors and Actuators
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Integrating Multiple Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Event-Driven Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interrupts in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Interrupts with GPIO Pins
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Debouncing with Interrupts
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Timers in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Delays and Timing Functions
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using the Time Module
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Data Logging with MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Storing Data on Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • File Handling in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Communicating with Personal Computer over Serial
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Universal Asynchronous Receiver-Transmitter Communication
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Temperature Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interfacing Temperature Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Humidity Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using DHT11 and DHT22 Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Reading Sensor Data
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interpreting Sensor Data
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Calibrating Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to Actuators
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling Relays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Relays with Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Safety Precautions with Relays
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Stepper Motors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Controlling Stepper Motors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Stepper Motor Drivers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Advanced Pulse Width Modulation Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Generating Sound with Buzzers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Piezoelectric Buzzers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Generating Tones and Melodies
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Infrared Communication
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Infrared Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Infrared Remote Control
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Measuring Distance with Ultrasonic Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Serial Communication Protocols
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Inter-Integrated Circuit vs Serial Peripheral Interface vs Universal Asynchronous Receiver-Transmitter
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Data Communication Principles
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Wireless Communication Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Bluetooth Low Energy
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Wi-Fi Connectivity
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using ESP8266 Modules
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Internet of Things Concepts
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Connecting to the Internet
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Sending Data to Web Servers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Hypertext Transfer Protocol Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Message Queuing Telemetry Transport Protocol
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Building Internet of Things Applications
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Cloud Services Integration
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Data Visualization Tools
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Programming Best Practices
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Code Optimization Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Debugging Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Debugging Tools
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Version Control Systems
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Git for Code Management
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Collaborative Coding Practices
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Documentation Standards
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Commenting Code Effectively
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Advanced MicroPython Features
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Object-Oriented Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Classes and Objects in MicroPython
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Inheritance and Polymorphism
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Encapsulation in Object-Oriented Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Designing Reusable Code
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Memory Management
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Managing Resources Efficiently
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Energy Efficiency in Programming
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Sleep Modes in Microcontrollers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Battery-Powered Projects
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Power Management Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Advanced Electronics Concepts
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Capacitors in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Inductors and Coils
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Diodes and Rectification
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Voltage Regulation
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Voltage Regulators
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Building Power Supplies
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Analog Signals vs. Digital Signals
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Signal Conditioning
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Filtering Noise in Circuits
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Interference and Shielding
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Electromagnetic Compatibility
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Circuit Design Principles
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Simulation Tools
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Prototyping Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Schematic Diagram Reading
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Understanding Datasheets
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Component Specifications
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Safety in Electronics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Electrostatic Discharge Precautions
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Soldering Techniques
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Introduction to Printed Circuit Board Design
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using Printed Circuit Board Design Software
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Fabricating Custom Printed Circuit Boards
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Advanced Sensor Integration
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Gesture Recognition Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Touch Sensors
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Environmental Monitoring
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Robotics Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Building Simple Robots
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Line-Following Robots
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Obstacle Avoidance Robots
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Control Systems Basics
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Feedback Mechanisms
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Proportional-Integral-Derivative Controllers
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Machine Learning Concepts
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Using MicroPython for Artificial Intelligence
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Edge Computing
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Ethics in Technology
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      • Future Trends in Computing
                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                                      + Introduction +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                                      + Concept Dependency +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/sims/knowledge-graphs/concept-taxonomy/index.html b/sims/knowledge-graphs/concept-taxonomy/index.html new file mode 100644 index 000000000..1f2db80cd --- /dev/null +++ b/sims/knowledge-graphs/concept-taxonomy/index.html @@ -0,0 +1,2190 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Concept Taxonomy - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + Concept Taxonomy + + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + Knowledge Graphs + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Concept Enumeration + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Concept Dependency + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + Concept Taxonomy + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                              • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 1. Computational Thinking Foundations + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 2. Programming Fundamentals + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 3. MicroPython Programming + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 4. Hardware Components and Interfacing + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 5. Electronics Basics + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 6. Sensor Integration + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 7. Actuator Control + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 8. Communication Protocols + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 9. Internet of Things (IoT) + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + 10. Advanced Topics and Best Practices + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Additional Considerations + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Visual Taxonomy Structure + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Example Mapping of Concepts to Taxonomy + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Final Remarks + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Graph Demo + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                        • + + + Prompt + + + +
                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                        • + + + Response + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 1. Computational Thinking Foundations + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 2. Programming Fundamentals + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 3. MicroPython Programming + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 4. Hardware Components and Interfacing + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 5. Electronics Basics + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 6. Sensor Integration + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 7. Actuator Control + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 8. Communication Protocols + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 9. Internet of Things (IoT) + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + 10. Advanced Topics and Best Practices + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Additional Considerations + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Visual Taxonomy Structure + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Example Mapping of Concepts to Taxonomy + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Final Remarks + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                        Concept Taxonomy

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Prompt

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        I am very pleased with these results. Now, can you suggest a
                                                                                                                                                                                                                                                                                                                                                        +taxonomy to classify each of these learning concepts? Perhaps
                                                                                                                                                                                                                                                                                                                                                        +about 10 different classifications?
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Response

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        ChatGPT o1-min Thought for a couple of seconds

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        I'm glad to hear that you're pleased with the results so far! Creating a taxonomy to classify your 197 learning concepts will help organize the curriculum, ensure comprehensive coverage, and facilitate a logical progression of topics. Below is a suggested taxonomy with 10 classifications, each accompanied by a description and examples of relevant concepts from your list.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        1. Computational Thinking Foundations

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Covers the basic principles and strategies of computational thinking, essential for problem-solving and algorithm development.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Intro to Computational Thinking (1)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Problem Decomposition (2)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Pattern Recognition (3)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Abstraction (4)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Algorithm Design (5)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        2. Programming Fundamentals

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Introduces the core concepts of programming that are applicable across various programming languages and environments.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Basic Programming Concepts (6)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Variables in Programming (7)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Data Types in Programming (8)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Operators (9)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Control Structures (10)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Conditional Statements (11)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Loops (12)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • General Functions in Programming (13)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        3. MicroPython Programming

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Focuses on programming using MicroPython, including syntax, environment setup, and MicroPython-specific features.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Introduction to MicroPython (14)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Setting Up MicroPython Environment (15)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Syntax in MicroPython (16)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Functions in MicroPython (17)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Modules in MicroPython (18)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Input and Output (19)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Working with Strings (20)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Working with Numbers (21)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Lists (22)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Tuples (23)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Dictionaries (24)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Exception Handling (25)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Advanced MicroPython Features (145)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using MicroPython for Artificial Intelligence (193)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        4. Hardware Components and Interfacing

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Explores the physical components used in projects and how to interface them with the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Microcontroller Basics (26)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • The Raspberry Pi Pico (27)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Understanding GPIO Pins (28)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Solderless Breadboards (32)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Breadboard Usage (30)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Breadboard Jumpers (45)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • LED Displays Overview (72)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Organic Light-Emitting Diode Displays (73)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • WS2812B LED Strips (80)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        5. Electronics Basics

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Introduces fundamental electronics concepts necessary for building and understanding circuits.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Circuit Basics (31)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Ohm's Law (32)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Resistors in Circuits (33)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • LEDs in Circuits (34)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Resistors with LEDs (35)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Current Limiting Resistors (36)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Transistors as Switches (59)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Capacitors in Circuits (158)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Inductors and Coils (159)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Diodes and Rectification (160)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Voltage Regulation (161)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Analog Signals vs Digital Signals (164)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Signal Conditioning (165)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Filtering Noise in Circuits (166)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Interference and Shielding (167)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Electromagnetic Compatibility (168)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Circuit Design Principles (169)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Safety in Electronics (175)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Electrostatic Discharge Precautions (176)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Soldering Techniques (177)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        6. Sensor Integration

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Covers various sensors, their functionalities, and how to integrate and interpret data from them.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Introduction to Sensors (99)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Temperature Sensors (100)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Interfacing Temperature Sensors (101)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Humidity Sensors (102)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using DHT11 and DHT22 Sensors (103)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Reading Sensor Data (104)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Interpreting Sensor Data (105)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Calibrating Sensors (106)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Photocells (63)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Making a Night Light (64)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Voltage Dividers (65)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Voltage Dividers and Sensors (66)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Time-of-Flight Sensors (67)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Interfacing Time-of-Flight Sensors (68)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Gesture Recognition Sensors (182)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Touch Sensors (183)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Environmental Monitoring (184)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Ultrasonic Sensors (120)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Advanced Sensor Integration (181)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        7. Actuator Control

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Focuses on controlling various actuators such as motors, servos, and relays to perform physical actions.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Introduction to Actuators (107)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Controlling Relays (108)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Relays Overview (109)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Relays Safety (110)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Stepper Motors (111)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Controlling Stepper Motors (112)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Stepper Motor Drivers (113)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Servo Motors Overview (56)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Controlling Servo Motors (57)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • DC Motors Overview (58)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Transistors as Switches (59)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Controlling Motors with Transistors (60)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Transistor Biasing Resistors (61)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Power Management with Transistors (62)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Generating Sound with Buzzers (114)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Piezoelectric Buzzers (115)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Generating Tones and Melodies (116)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        8. Communication Protocols

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Details various communication protocols used for data transmission between devices and components.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Serial Communication Protocols (122)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • I2C Protocol (69)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • SPI Protocol (70)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Universal Serial Bus Communication (97)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Universal Asynchronous Receiver-Transmitter Communication (98)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Connecting I2C Devices (71)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Advanced I2C (78)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Advanced SPI (79)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Infrared Communication (117)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Infrared Sensors (118)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Infrared Remote Control (119)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • I2C vs SPI vs UART (122)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Data Communication Principles (123)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        9. Internet of Things (IoT)

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Explores IoT concepts, connectivity, data transmission, and integration with cloud services.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Internet of Things Concepts (128)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Connecting to the Internet (129)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Sending Data to Web Servers (130)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Hypertext Transfer Protocol Basics (131)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Message Queuing Telemetry Transport Protocol (132)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • IoT Applications (133)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Cloud Services Integration (134)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Data Visualization Tools (135)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Wireless Communication Basics (124)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Bluetooth Low Energy (125)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Wi-Fi Connectivity (126)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Edge Computing (194)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        10. Advanced Topics and Best Practices

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Description: +Includes advanced programming techniques, best practices, version control, and emerging technologies.

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Relevant Concepts:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • Programming Best Practices (136)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Code Optimization Techniques (137)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Debugging Techniques (138)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Debugging Tools (139)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Version Control Systems (140)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using Git for Code Management (141)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Collaborative Coding Practices (142)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Documentation Standards (143)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Commenting Code Effectively (144)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Object-Oriented Programming (146)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Classes and Objects (147)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Inheritance and Polymorphism (148)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Encapsulation in Object-Oriented Programming (149)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Designing Reusable Code (150)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Memory Management (151)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Managing Resources Efficiently (152)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Energy Efficiency in Programming (153)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Sleep Modes in Microcontrollers (154)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Battery-Powered Projects (155)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Power Management Techniques (156)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Control Systems Basics (189)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Feedback Mechanisms (190)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Proportional-Integral-Derivative Controllers (191)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Machine Learning Concepts (192)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Using MicroPython for Artificial Intelligence (193)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Ethics in Technology (195)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • Future Trends in Computing (196)
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Additional Considerations

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • +

                                                                                                                                                                                                                                                                                                                                                          Cross-Cutting Themes: Some concepts may span multiple categories. For example, "Pulse Width Modulation" could relate to both "Electronics Basics" and "Actuator Control."

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • +

                                                                                                                                                                                                                                                                                                                                                          Prerequisites: Ensure that foundational categories like "Computational Thinking Foundations" and "Programming Fundamentals" are taught first, as they underpin many other topics.

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • +

                                                                                                                                                                                                                                                                                                                                                          Modular Organization: Consider organizing your curriculum into modules based on these classifications to provide a structured learning path.

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        • +

                                                                                                                                                                                                                                                                                                                                                          Scalability: This taxonomy allows for the addition of new concepts or subcategories as the course evolves or as new technologies emerge.

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        • +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Visual Taxonomy Structure

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        For better visualization, here's a hierarchical representation of the taxonomy:

                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                        1. Computational Thinking Foundations
                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                        3. Programming Fundamentals
                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                        5. MicroPython Programming
                                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                                        7. Hardware Components and Interfacing
                                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                                        9. Electronics Basics
                                                                                                                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                                                                                                                        11. Sensor Integration
                                                                                                                                                                                                                                                                                                                                                        12. +
                                                                                                                                                                                                                                                                                                                                                        13. Actuator Control
                                                                                                                                                                                                                                                                                                                                                        14. +
                                                                                                                                                                                                                                                                                                                                                        15. Communication Protocols
                                                                                                                                                                                                                                                                                                                                                        16. +
                                                                                                                                                                                                                                                                                                                                                        17. Internet of Things (IoT)
                                                                                                                                                                                                                                                                                                                                                        18. +
                                                                                                                                                                                                                                                                                                                                                        19. Advanced Topics and Best Practices
                                                                                                                                                                                                                                                                                                                                                        20. +
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Example Mapping of Concepts to Taxonomy

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Here's how some of the concepts map to the suggested taxonomy:

                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        Concept IDConcept NameClassification
                                                                                                                                                                                                                                                                                                                                                        1Intro to Computational ThinkingComputational Thinking Foundations
                                                                                                                                                                                                                                                                                                                                                        ---------
                                                                                                                                                                                                                                                                                                                                                        7Variables in ProgrammingProgramming Fundamentals
                                                                                                                                                                                                                                                                                                                                                        14Introduction to MicroPythonMicroPython Programming
                                                                                                                                                                                                                                                                                                                                                        26Microcontroller BasicsHardware Components and Interfacing
                                                                                                                                                                                                                                                                                                                                                        31Circuit BasicsElectronics Basics
                                                                                                                                                                                                                                                                                                                                                        99Introduction to SensorsSensor Integration
                                                                                                                                                                                                                                                                                                                                                        107Introduction to ActuatorsActuator Control
                                                                                                                                                                                                                                                                                                                                                        122Serial Communication ProtocolsCommunication Protocols
                                                                                                                                                                                                                                                                                                                                                        128Internet of Things ConceptsInternet of Things (IoT)
                                                                                                                                                                                                                                                                                                                                                        136Programming Best PracticesAdvanced Topics and Best Practices
                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        Final Remarks

                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                        This taxonomy provides a structured framework to classify +and organize your 197 learning concepts effectively. +It ensures that foundational knowledge is established +before progressing to more advanced topics, facilitating +a coherent and comprehensive learning experience for high +school students. Feel free to adjust the classifications +or add subcategories to better fit the specific needs and goals of your course.

                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                                                        + Concept Dependency +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                                                        + Graph Demo +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/docs/sims/knowledge-graphs/graph/cat-colors-3.html b/sims/knowledge-graphs/graph/cat-colors-3.html similarity index 100% rename from docs/sims/knowledge-graphs/graph/cat-colors-3.html rename to sims/knowledge-graphs/graph/cat-colors-3.html diff --git a/docs/sims/knowledge-graphs/graph/cat-colors-3.js b/sims/knowledge-graphs/graph/cat-colors-3.js similarity index 100% rename from docs/sims/knowledge-graphs/graph/cat-colors-3.js rename to sims/knowledge-graphs/graph/cat-colors-3.js diff --git a/docs/sims/knowledge-graphs/graph/category-colors.csv b/sims/knowledge-graphs/graph/category-colors.csv similarity index 100% rename from docs/sims/knowledge-graphs/graph/category-colors.csv rename to sims/knowledge-graphs/graph/category-colors.csv diff --git a/docs/sims/knowledge-graphs/graph/category-colors.html b/sims/knowledge-graphs/graph/category-colors.html similarity index 100% rename from docs/sims/knowledge-graphs/graph/category-colors.html rename to sims/knowledge-graphs/graph/category-colors.html diff --git a/docs/sims/knowledge-graphs/graph/category-colors.js b/sims/knowledge-graphs/graph/category-colors.js similarity index 100% rename from docs/sims/knowledge-graphs/graph/category-colors.js rename to sims/knowledge-graphs/graph/category-colors.js diff --git a/docs/sims/knowledge-graphs/graph/dep-graph.html b/sims/knowledge-graphs/graph/dep-graph.html similarity index 100% rename from docs/sims/knowledge-graphs/graph/dep-graph.html rename to sims/knowledge-graphs/graph/dep-graph.html diff --git a/docs/sims/knowledge-graphs/graph/graph-data-2.csv b/sims/knowledge-graphs/graph/graph-data-2.csv similarity index 100% rename from docs/sims/knowledge-graphs/graph/graph-data-2.csv rename to sims/knowledge-graphs/graph/graph-data-2.csv diff --git a/docs/sims/knowledge-graphs/graph/graph-data-3.csv b/sims/knowledge-graphs/graph/graph-data-3.csv similarity index 100% rename from docs/sims/knowledge-graphs/graph/graph-data-3.csv rename to sims/knowledge-graphs/graph/graph-data-3.csv diff --git a/docs/sims/knowledge-graphs/graph/graph-data.csv b/sims/knowledge-graphs/graph/graph-data.csv similarity index 100% rename from docs/sims/knowledge-graphs/graph/graph-data.csv rename to sims/knowledge-graphs/graph/graph-data.csv diff --git a/sims/knowledge-graphs/graph/index.html b/sims/knowledge-graphs/graph/index.html new file mode 100644 index 000000000..89eeb9c02 --- /dev/null +++ b/sims/knowledge-graphs/graph/index.html @@ -0,0 +1,1877 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Graph Demo - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + Graph Demo + + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + Knowledge Graphs + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Concept Enumeration + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Concept Dependency + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Concept Taxonomy + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Graph Demo + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Adjusting Visualization + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Left to Right Layout + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Full Layout Options + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Category Colors + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Reference + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Adjusting Visualization + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Left to Right Layout + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Full Layout Options + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Category Colors + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          • + + + Reference + + + +
                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                          Circuits Course Concept Dependency Graph

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          HTML Page for Dependency Graph

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Adjusting Visualization

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          In the JavaScript file you can change the display options. +Here is the portion of the JavaScript that changes the options.

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                                          var options = {
                                                                                                                                                                                                                                                                                                                                                          +    nodes: {
                                                                                                                                                                                                                                                                                                                                                          +        shape: 'dot',
                                                                                                                                                                                                                                                                                                                                                          +        size: 10,
                                                                                                                                                                                                                                                                                                                                                          +        font: {
                                                                                                                                                                                                                                                                                                                                                          +            size: 14,
                                                                                                                                                                                                                                                                                                                                                          +        },
                                                                                                                                                                                                                                                                                                                                                          +    },
                                                                                                                                                                                                                                                                                                                                                          +    edges: {
                                                                                                                                                                                                                                                                                                                                                          +        arrows: 'to',
                                                                                                                                                                                                                                                                                                                                                          +        smooth: true,
                                                                                                                                                                                                                                                                                                                                                          +    },
                                                                                                                                                                                                                                                                                                                                                          +    physics: {
                                                                                                                                                                                                                                                                                                                                                          +        stabilization: false,
                                                                                                                                                                                                                                                                                                                                                          +    },
                                                                                                                                                                                                                                                                                                                                                          +};
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Left to Right Layout

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          HTML Page for Dependency Graph

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                                          var options = {
                                                                                                                                                                                                                                                                                                                                                          +layout: {
                                                                                                                                                                                                                                                                                                                                                          +        hierarchical: {
                                                                                                                                                                                                                                                                                                                                                          +          direction: 'LR',  // Left to right
                                                                                                                                                                                                                                                                                                                                                          +          sortMethod: 'directed',  // Sort nodes based on dependencies
                                                                                                                                                                                                                                                                                                                                                          +          nodeSpacing: 200,  // Adjust spacing if needed
                                                                                                                                                                                                                                                                                                                                                          +          levelSeparation: 150  // Adjust for horizontal space between levels
                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                          +      }
                                                                                                                                                                                                                                                                                                                                                          +}
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Full Layout Options

                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                                                                                                                                                          +28
                                                                                                                                                                                                                                                                                                                                                          +29
                                                                                                                                                                                                                                                                                                                                                          +30
                                                                                                                                                                                                                                                                                                                                                          +31
                                                                                                                                                                                                                                                                                                                                                          +32
                                                                                                                                                                                                                                                                                                                                                          +33
                                                                                                                                                                                                                                                                                                                                                          +34
                                                                                                                                                                                                                                                                                                                                                          +35
                                                                                                                                                                                                                                                                                                                                                          +36
                                                                                                                                                                                                                                                                                                                                                          +37
                                                                                                                                                                                                                                                                                                                                                          +38
                                                                                                                                                                                                                                                                                                                                                          +39
                                                                                                                                                                                                                                                                                                                                                          +40
                                                                                                                                                                                                                                                                                                                                                          +41
                                                                                                                                                                                                                                                                                                                                                          layout: {
                                                                                                                                                                                                                                                                                                                                                          +    randomSeed: undefined,
                                                                                                                                                                                                                                                                                                                                                          +    improvedLayout:true,
                                                                                                                                                                                                                                                                                                                                                          +    clusterThreshold: 150,
                                                                                                                                                                                                                                                                                                                                                          +    hierarchical: {
                                                                                                                                                                                                                                                                                                                                                          +      enabled:false,
                                                                                                                                                                                                                                                                                                                                                          +      levelSeparation: 150,
                                                                                                                                                                                                                                                                                                                                                          +      nodeSpacing: 100,
                                                                                                                                                                                                                                                                                                                                                          +      treeSpacing: 200,
                                                                                                                                                                                                                                                                                                                                                          +      blockShifting: true,
                                                                                                                                                                                                                                                                                                                                                          +      edgeMinimization: true,
                                                                                                                                                                                                                                                                                                                                                          +      parentCentralization: true,
                                                                                                                                                                                                                                                                                                                                                          +      direction: 'LR',        // UD, DU, LR, RL
                                                                                                                                                                                                                                                                                                                                                          +      sortMethod: 'hubsize',  // hubsize, directed
                                                                                                                                                                                                                                                                                                                                                          +      shakeTowards: 'leaves'  // roots, leaves
                                                                                                                                                                                                                                                                                                                                                          +    }
                                                                                                                                                                                                                                                                                                                                                          +  }
                                                                                                                                                                                                                                                                                                                                                          +  ```
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +## Hierarchical Layout User Defined
                                                                                                                                                                                                                                                                                                                                                          +https://visjs.github.io/vis-network/examples/network/layout/hierarchicalLayoutUserdefined.html
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +```js
                                                                                                                                                                                                                                                                                                                                                          +  var options = {
                                                                                                                                                                                                                                                                                                                                                          +          edges: {
                                                                                                                                                                                                                                                                                                                                                          +            smooth: {
                                                                                                                                                                                                                                                                                                                                                          +              type: "cubicBezier",
                                                                                                                                                                                                                                                                                                                                                          +              forceDirection:
                                                                                                                                                                                                                                                                                                                                                          +                directionInput.value == "UD" || directionInput.value == "DU"
                                                                                                                                                                                                                                                                                                                                                          +                  ? "vertical"
                                                                                                                                                                                                                                                                                                                                                          +                  : "horizontal",
                                                                                                                                                                                                                                                                                                                                                          +              roundness: 0.4,
                                                                                                                                                                                                                                                                                                                                                          +            },
                                                                                                                                                                                                                                                                                                                                                          +          },
                                                                                                                                                                                                                                                                                                                                                          +          layout: {
                                                                                                                                                                                                                                                                                                                                                          +            hierarchical: {
                                                                                                                                                                                                                                                                                                                                                          +              direction: directionInput.value,
                                                                                                                                                                                                                                                                                                                                                          +            },
                                                                                                                                                                                                                                                                                                                                                          +          },
                                                                                                                                                                                                                                                                                                                                                          +          physics: false,
                                                                                                                                                                                                                                                                                                                                                          +        };
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Category Colors

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          We can use generative AI to categorize each concept. +Here are 11 categories of the concepts

                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          CategoryIDColorCategoryLabel
                                                                                                                                                                                                                                                                                                                                                          1redFundamental Concepts
                                                                                                                                                                                                                                                                                                                                                          2orangePassive Components
                                                                                                                                                                                                                                                                                                                                                          3yellowActive Components and Semiconductor Devices
                                                                                                                                                                                                                                                                                                                                                          4greenCircuit Analysis Techniques
                                                                                                                                                                                                                                                                                                                                                          5cyanAC Circuit Concepts
                                                                                                                                                                                                                                                                                                                                                          6blueTransient Analysis
                                                                                                                                                                                                                                                                                                                                                          7purpleSignal Processing and Filters
                                                                                                                                                                                                                                                                                                                                                          8pinkAmplifiers and Analog Circuits
                                                                                                                                                                                                                                                                                                                                                          9grayPower Electronics
                                                                                                                                                                                                                                                                                                                                                          10oliveControl Systems and Stability
                                                                                                                                                                                                                                                                                                                                                          11brownTypes of Circuits
                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Category Colors Demo

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Cat Colors V3 DEBUG

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Reference

                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                          Vis.js Network Layout Methods

                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                                                                                                                          + Concept Taxonomy +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                                                                                                                          + Breadboard +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/docs/sims/knowledge-graphs/graph/lr-layout.html b/sims/knowledge-graphs/graph/lr-layout.html similarity index 100% rename from docs/sims/knowledge-graphs/graph/lr-layout.html rename to sims/knowledge-graphs/graph/lr-layout.html diff --git a/docs/sims/knowledge-graphs/graph/ohms-law-concept-graph.html b/sims/knowledge-graphs/graph/ohms-law-concept-graph.html similarity index 100% rename from docs/sims/knowledge-graphs/graph/ohms-law-concept-graph.html rename to sims/knowledge-graphs/graph/ohms-law-concept-graph.html diff --git a/docs/sims/knowledge-graphs/graph/script-lr.js b/sims/knowledge-graphs/graph/script-lr.js similarity index 100% rename from docs/sims/knowledge-graphs/graph/script-lr.js rename to sims/knowledge-graphs/graph/script-lr.js diff --git a/docs/sims/knowledge-graphs/graph/script.js b/sims/knowledge-graphs/graph/script.js similarity index 100% rename from docs/sims/knowledge-graphs/graph/script.js rename to sims/knowledge-graphs/graph/script.js diff --git a/sims/knowledge-graphs/index.html b/sims/knowledge-graphs/index.html new file mode 100644 index 000000000..2771e31a3 --- /dev/null +++ b/sims/knowledge-graphs/index.html @@ -0,0 +1,1562 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + Introduction + + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + Sims + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + Knowledge Graphs + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Concept Enumeration + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Concept Dependency + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Concept Taxonomy + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Graph Demo + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Breadboard + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Prompt Engineering + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            • + + + Demo Graphs + + + +
                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                            Knowledge Graphs

                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                            Prompt Engineering

                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                            • Concept Enumeration
                                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                                            • Concept Dependency
                                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                                            • Concept Taxonomy
                                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                            Demo Graphs

                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                            • Dependency Graph
                                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                                            • Taxonomy Colored Dependency Graph
                                                                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                                                                                                                            + Introduction +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                                                                                                                                            + Concept Enumeration +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 000000000..0f8724efd --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz new file mode 100644 index 000000000..14d876df1 Binary files /dev/null and b/sitemap.xml.gz differ diff --git a/sound/02-play-tone/index.html b/sound/02-play-tone/index.html new file mode 100644 index 000000000..397c89eae --- /dev/null +++ b/sound/02-play-tone/index.html @@ -0,0 +1,1625 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Playing a Tone - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + Playing a Tone + + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Playing a Tone + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + Lab 1: Play A Single Tone + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                              • + + + Lab 1: Play A Single Tone + + + +
                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                              • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                              Play Tones Using the PWM

                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              Since we will be using the sleep function many times, we will import it by name from the Micropthon time library like this:

                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                              from utime import sleep
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              Now, instead of putting utime.sleep(.5) we can just reference sleep directly like this:

                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                              sleep(.5)
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              This will pause for 1/2 a second. This is how long we wait for a tone to stay on or go off. The nice thing about this menthod is that our code is a little smaller. However, you can't run other functions in the utime library. So if you want to add them later you will need to import them also, just like we did for the sleep function.

                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              Lab 1: Play A Single Tone

                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                                                              from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                              +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +# lower right corner with USB connector on top
                                                                                                                                                                                                                                                                                                                                                              +SPEAKER_PIN = 16
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                              +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                                              +# set the duty cycle to be 50%
                                                                                                                                                                                                                                                                                                                                                              +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                              +speaker.freq(1000) # 50% on and off
                                                                                                                                                                                                                                                                                                                                                              +sleep(1) # wait a second
                                                                                                                                                                                                                                                                                                                                                              +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                              +# turn off the PWM circuits off with a zero duty cycle
                                                                                                                                                                                                                                                                                                                                                              +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              The tone will keep sounding until you turn the speaker duty to 0. This shows you that the circuitry that is generating the sound is independent of the main CPU.

                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                              Experiments

                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                              1. Try changing the frequency for the first lab. This is the line speaker.freq(1000) and rerunning the program. Try using values from 10 to 10000. What values seem the loudest to your ear?
                                                                                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                                                                                              3. What happens if you comment out the last line that sets the duty cycle to be 0? Make sure to set it back to zero again or the tone will continue playing until the device is powered off.
                                                                                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                                                              + Introduction +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                                                              + Playing Three Tones +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/sound/03-play-three-tones/index.html b/sound/03-play-three-tones/index.html new file mode 100644 index 000000000..fc1e5c5ad --- /dev/null +++ b/sound/03-play-three-tones/index.html @@ -0,0 +1,1738 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Playing Three Tones - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + Playing Three Tones + + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Playing Three Tones + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + Using Variables + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + Three Tones With Variables + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Using Variables + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Three Tones With Variables + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                Play Three Tones

                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                In this lesson we will play three consecutive tones. Each tone will have a specific time on and we will put a time between the tones.

                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                +20
                                                                                                                                                                                                                                                                                                                                                                +21
                                                                                                                                                                                                                                                                                                                                                                +22
                                                                                                                                                                                                                                                                                                                                                                +23
                                                                                                                                                                                                                                                                                                                                                                +24
                                                                                                                                                                                                                                                                                                                                                                +25
                                                                                                                                                                                                                                                                                                                                                                +26
                                                                                                                                                                                                                                                                                                                                                                +27
                                                                                                                                                                                                                                                                                                                                                                from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# lower right corner with USB connector on top
                                                                                                                                                                                                                                                                                                                                                                +SPEAKER_PIN = 16
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                                +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(300) # 1 Kilohertz
                                                                                                                                                                                                                                                                                                                                                                +sleep(.5) # wait a 1/4 second
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +sleep(.25)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(800)
                                                                                                                                                                                                                                                                                                                                                                +sleep(.5)
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +sleep(.25)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(400)
                                                                                                                                                                                                                                                                                                                                                                +sleep(.5)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# turn off the PWM 
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                Using Variables

                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                We can also put the time each tone stays on and the space between the tones into variables so it is easier to modify the values in a single place.

                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                # set the time each tone will be on
                                                                                                                                                                                                                                                                                                                                                                +ONTIME = .5
                                                                                                                                                                                                                                                                                                                                                                +# the time between the tones
                                                                                                                                                                                                                                                                                                                                                                +OFFTIME = .100
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                Three Tones With Variables

                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                +20
                                                                                                                                                                                                                                                                                                                                                                +21
                                                                                                                                                                                                                                                                                                                                                                +22
                                                                                                                                                                                                                                                                                                                                                                +23
                                                                                                                                                                                                                                                                                                                                                                +24
                                                                                                                                                                                                                                                                                                                                                                +25
                                                                                                                                                                                                                                                                                                                                                                +26
                                                                                                                                                                                                                                                                                                                                                                +27
                                                                                                                                                                                                                                                                                                                                                                +28
                                                                                                                                                                                                                                                                                                                                                                +29
                                                                                                                                                                                                                                                                                                                                                                +30
                                                                                                                                                                                                                                                                                                                                                                +31
                                                                                                                                                                                                                                                                                                                                                                +32
                                                                                                                                                                                                                                                                                                                                                                +33
                                                                                                                                                                                                                                                                                                                                                                +34
                                                                                                                                                                                                                                                                                                                                                                +35
                                                                                                                                                                                                                                                                                                                                                                from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# lower right corner with USB connector on top
                                                                                                                                                                                                                                                                                                                                                                +SPEAKER_PIN = 16
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                                +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# the time each tone will be on
                                                                                                                                                                                                                                                                                                                                                                +ON_TIME = .25
                                                                                                                                                                                                                                                                                                                                                                +# the time between the tones
                                                                                                                                                                                                                                                                                                                                                                +OFF_TIME = .1
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# Low tone
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(300)
                                                                                                                                                                                                                                                                                                                                                                +sleep(ON_TIME)
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +sleep(OFF_TIME)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# High tone
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(800)
                                                                                                                                                                                                                                                                                                                                                                +sleep(ON_TIME)
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +sleep(OFF_TIME)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# Medium tone
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                +speaker.freq(400)
                                                                                                                                                                                                                                                                                                                                                                +sleep(ON_TIME)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +# turn off the PWM 
                                                                                                                                                                                                                                                                                                                                                                +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                Experiments

                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                1. Change the ON_TIME in the above program. What is the shortest time that you can still hear?
                                                                                                                                                                                                                                                                                                                                                                2. +
                                                                                                                                                                                                                                                                                                                                                                3. Change the order of the Low, High, Medium around. What is the most pleasing to your ears?
                                                                                                                                                                                                                                                                                                                                                                4. +
                                                                                                                                                                                                                                                                                                                                                                5. What order would you suggest for the start of a game and what order would you like for a "Game Over" sound?
                                                                                                                                                                                                                                                                                                                                                                6. +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                + Playing a Tone +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                                                                + Playing a Scale +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/sound/04-play-scale/index.html b/sound/04-play-scale/index.html new file mode 100644 index 000000000..5a0d30100 --- /dev/null +++ b/sound/04-play-scale/index.html @@ -0,0 +1,1642 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Playing a Scale - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + Playing a Scale + + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Playing a Scale + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + New Frequency Spacing + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + New Frequency Spacing + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                  • + + + Experiments + + + +
                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                  Play a Scale

                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  In this lesson, we will learn about how to automatically generate various pitches. We will see that the spacing between lower pitches is different from the spacing between higher pitches.

                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  Here is a program that plays a scale of notes from a starting frequency of 30 hertz to an upper frequency of around 10,000 hertz. Note that

                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                                                                                  +22
                                                                                                                                                                                                                                                                                                                                                                  +23
                                                                                                                                                                                                                                                                                                                                                                  +24
                                                                                                                                                                                                                                                                                                                                                                  +25
                                                                                                                                                                                                                                                                                                                                                                  +26
                                                                                                                                                                                                                                                                                                                                                                  from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                  +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +# lower right corner with USB connector on top
                                                                                                                                                                                                                                                                                                                                                                  +SPEAKER_PIN = 16
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                                  +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +def playtone(frequency):
                                                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                  +    speaker.freq(frequency)
                                                                                                                                                                                                                                                                                                                                                                  +    sleep(0.3)
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +def bequiet():
                                                                                                                                                                                                                                                                                                                                                                  +    speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +freq = 30
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +for i in range(64):
                                                                                                                                                                                                                                                                                                                                                                  +    print(freq)
                                                                                                                                                                                                                                                                                                                                                                  +    playtone(freq)
                                                                                                                                                                                                                                                                                                                                                                  +    freq = int(freq * 1.1)
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +# Turn off the PWM
                                                                                                                                                                                                                                                                                                                                                                  +speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  New Frequency Spacing

                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  When you run the prior example, note the frequencies printed to the console. Are they evenly spaced?

                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  Take a close look at the line that creates a new frequency:

                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                                                                  freq = int(freq * 1.1)
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  The effect of this line is to create a new frequency that is 10% higher than the prior frequency.

                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                  Experiments

                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                  1. What happens if you change the frequency update to be freq = freq +100
                                                                                                                                                                                                                                                                                                                                                                  2. +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                  + Playing Three Tones +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                                                                  + Play Mario +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/sound/05-play-mario/index.html b/sound/05-play-mario/index.html new file mode 100644 index 000000000..8f44724af --- /dev/null +++ b/sound/05-play-mario/index.html @@ -0,0 +1,1583 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Play Mario - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + Play Mario + + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + Play Mario + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                    Play Mario on MicroPython

                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                    This program will play the theme music from the Mario video game.

                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                                                                                                                                                    +20
                                                                                                                                                                                                                                                                                                                                                                    +21
                                                                                                                                                                                                                                                                                                                                                                    +22
                                                                                                                                                                                                                                                                                                                                                                    +23
                                                                                                                                                                                                                                                                                                                                                                    +24
                                                                                                                                                                                                                                                                                                                                                                    +25
                                                                                                                                                                                                                                                                                                                                                                    +26
                                                                                                                                                                                                                                                                                                                                                                    +27
                                                                                                                                                                                                                                                                                                                                                                    +28
                                                                                                                                                                                                                                                                                                                                                                    +29
                                                                                                                                                                                                                                                                                                                                                                    +30
                                                                                                                                                                                                                                                                                                                                                                    +31
                                                                                                                                                                                                                                                                                                                                                                    +32
                                                                                                                                                                                                                                                                                                                                                                    +33
                                                                                                                                                                                                                                                                                                                                                                    +34
                                                                                                                                                                                                                                                                                                                                                                    +35
                                                                                                                                                                                                                                                                                                                                                                    +36
                                                                                                                                                                                                                                                                                                                                                                    +37
                                                                                                                                                                                                                                                                                                                                                                    +38
                                                                                                                                                                                                                                                                                                                                                                    +39
                                                                                                                                                                                                                                                                                                                                                                    from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                    +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                    +buzzer = PWM(Pin(16))
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +tones = {
                                                                                                                                                                                                                                                                                                                                                                    +"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46,
                                                                                                                                                                                                                                                                                                                                                                    +"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65,
                                                                                                                                                                                                                                                                                                                                                                    +"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98,
                                                                                                                                                                                                                                                                                                                                                                    +"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139,
                                                                                                                                                                                                                                                                                                                                                                    +"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185,
                                                                                                                                                                                                                                                                                                                                                                    +"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311,
                                                                                                                                                                                                                                                                                                                                                                    +"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698,
                                                                                                                                                                                                                                                                                                                                                                    +"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661,
                                                                                                                                                                                                                                                                                                                                                                    +"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520,
                                                                                                                                                                                                                                                                                                                                                                    +"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978
                                                                                                                                                                                                                                                                                                                                                                    +}
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"]
                                                                                                                                                                                                                                                                                                                                                                    +mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6",
                                                                                                                                                                                                                                                                                                                                                                    +         0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7",
                                                                                                                                                                                                                                                                                                                                                                    +         0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0,
                                                                                                                                                                                                                                                                                                                                                                    +         "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0]
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +def playtone(frequency):
                                                                                                                                                                                                                                                                                                                                                                    +    buzzer.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                    +    buzzer.freq(frequency)
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +def bequiet():
                                                                                                                                                                                                                                                                                                                                                                    +    buzzer.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +def playsong(mysong):
                                                                                                                                                                                                                                                                                                                                                                    +    for i in range(len(mysong)):
                                                                                                                                                                                                                                                                                                                                                                    +        if (mysong[i] == "P" or mysong[i] == 0 ):
                                                                                                                                                                                                                                                                                                                                                                    +            bequiet()
                                                                                                                                                                                                                                                                                                                                                                    +        else:
                                                                                                                                                                                                                                                                                                                                                                    +            playtone(tones[mysong[i]])
                                                                                                                                                                                                                                                                                                                                                                    +        sleep(0.3)
                                                                                                                                                                                                                                                                                                                                                                    +    bequiet()
                                                                                                                                                                                                                                                                                                                                                                    +playsong(mario)
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                    + Playing a Scale +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                                                                                                    + Eight Key Piano +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/sound/06-eight-key-piano/index.html b/sound/06-eight-key-piano/index.html new file mode 100644 index 000000000..75965f1c5 --- /dev/null +++ b/sound/06-eight-key-piano/index.html @@ -0,0 +1,1743 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Eight Key Piano - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + Eight Key Piano + + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + Eight Key Piano + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + The Play Tone Functions + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + Exercises + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + The Play Tone Functions + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                      • + + + Exercises + + + +
                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                      Eight Key Piano

                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      In this lab we wire up eight momentary press buttons so that when each one is pressed it will play a different note.

                                                                                                                                                                                                                                                                                                                                                                      + + +

                                                                                                                                                                                                                                                                                                                                                                      To create this project, you will need the following parts:

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                      1. A Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                                                                                      3. A standard size breadboard or two 1/2 breadboards
                                                                                                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                                                                                                      5. 8 momentary press buttons
                                                                                                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                                                                                                      7. A speaker or a Piezo buzzer
                                                                                                                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                                                                                                                      9. An optional sound amplifier such as the LM386 DC 5V-12V Mini Micro Audio Amplifier which can be purchased on e-bay for under $2 USD. If you are working in a quiet room you may not need the amplifier.
                                                                                                                                                                                                                                                                                                                                                                      10. +
                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      Eight Key Piano

                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      Each "key" is a momentary press button that is wired up between a GPIO pin and the +3.3 volt rail on the breadboard connected to 3V3(OUT) pin. We do not need to use any resistors to pull the signals low since we configure the pins to be inputs with the PULL_DOWN resistor like this:

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                      button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      The Play Tone Functions

                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      We will use two Python functions, one for playing a tone of a given frequency and one for turning off the sound.

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                                                                                                                                                                      +4
                                                                                                                                                                                                                                                                                                                                                                      +5
                                                                                                                                                                                                                                                                                                                                                                      +6
                                                                                                                                                                                                                                                                                                                                                                      +7
                                                                                                                                                                                                                                                                                                                                                                      +8
                                                                                                                                                                                                                                                                                                                                                                      def playtone(frequency):
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.duty_u16(1000) # turn the PWM duty to 50%
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.freq(frequency)
                                                                                                                                                                                                                                                                                                                                                                      +    builtin_led.high() # turn builtin LED on
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +def bequiet():
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.duty_u16(0) # turn off the speaker PWM
                                                                                                                                                                                                                                                                                                                                                                      +    builtin_led.low() # turn builtin LED off
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      We will also use the .value() method on each pin to detect if it is HIGH (1) like this:

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                                                      if button_pin_1.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(220) # A3
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      We will be playing "notes" generating square waves with various frequencies from our lowest note of A3 at 220 Hz up to A4 at 440 Hz.

                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      Sample Code

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                                                                                                                                                      +41
                                                                                                                                                                                                                                                                                                                                                                      +42
                                                                                                                                                                                                                                                                                                                                                                      +43
                                                                                                                                                                                                                                                                                                                                                                      +44
                                                                                                                                                                                                                                                                                                                                                                      +45
                                                                                                                                                                                                                                                                                                                                                                      +46
                                                                                                                                                                                                                                                                                                                                                                      +47
                                                                                                                                                                                                                                                                                                                                                                      # play a tone durning button down
                                                                                                                                                                                                                                                                                                                                                                      +from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                      +from utime import sleep, ticks_ms
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +SPEAKER_PIN = 22 # pass through a speaker and tie the other end to GND
                                                                                                                                                                                                                                                                                                                                                                      +speaker = PWM(Pin(SPEAKER_PIN))
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +builtin_led = machine.Pin(25, Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +# Connect these GP pins through a button to the +3.3 volt rail
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_2 = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_3 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_4 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_5 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_6 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_7 = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +button_pin_8 = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN)
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +def playtone(frequency):
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.duty_u16(1000) # turn the PWM duty to 50%
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.freq(frequency)
                                                                                                                                                                                                                                                                                                                                                                      +    builtin_led.high() # turn builtin LED on
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +def bequiet():
                                                                                                                                                                                                                                                                                                                                                                      +    speaker.duty_u16(0) # turn off the speaker PWM
                                                                                                                                                                                                                                                                                                                                                                      +    builtin_led.low() # turn builtin LED off
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                                                      +    if   button_pin_1.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(220) # A3
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_2.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(247) # B3
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_3.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(262) # C4
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_4.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(294) # D4
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_5.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(330) # E4
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_6.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(349) # F4
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_7.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(392) # G4
                                                                                                                                                                                                                                                                                                                                                                      +    elif button_pin_8.value() == 1:
                                                                                                                                                                                                                                                                                                                                                                      +        playtone(440) # A4
                                                                                                                                                                                                                                                                                                                                                                      +    else:
                                                                                                                                                                                                                                                                                                                                                                      +        bequiet()
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                      Exercises

                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                      1. Rewrite the code above using lists for the pin numbers and the notes.
                                                                                                                                                                                                                                                                                                                                                                      2. +
                                                                                                                                                                                                                                                                                                                                                                      3. Try different notes with other scales.
                                                                                                                                                                                                                                                                                                                                                                      4. +
                                                                                                                                                                                                                                                                                                                                                                      5. Add another button to change the "octave" of the notes.
                                                                                                                                                                                                                                                                                                                                                                      6. +
                                                                                                                                                                                                                                                                                                                                                                      7. Add a display to show the notes as they are being played.
                                                                                                                                                                                                                                                                                                                                                                      8. +
                                                                                                                                                                                                                                                                                                                                                                      9. Print the time each note is being pressed as well as the length of the pauses between the notes.
                                                                                                                                                                                                                                                                                                                                                                      10. +
                                                                                                                                                                                                                                                                                                                                                                      11. Write the notes to a recording file.
                                                                                                                                                                                                                                                                                                                                                                      12. +
                                                                                                                                                                                                                                                                                                                                                                      13. Add a menu system so you can do things like start a new song recording, save a recording and playback a recording.
                                                                                                                                                                                                                                                                                                                                                                      14. +
                                                                                                                                                                                                                                                                                                                                                                      15. Eight keys are not enough for many songs. Use two full-size breadboards to expand the number of keys on your piano.
                                                                                                                                                                                                                                                                                                                                                                      16. +
                                                                                                                                                                                                                                                                                                                                                                      17. Look into getting a MIDI keyboard such as the 32-key $40 MIDIPLUS AKM320 USB MIDI Keyboard Controller
                                                                                                                                                                                                                                                                                                                                                                      18. +
                                                                                                                                                                                                                                                                                                                                                                      19. Read this blog about running MIDI on the Pico: MIDI, MicroPython and the Raspberry Pi Pico
                                                                                                                                                                                                                                                                                                                                                                      20. +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                      + Play Mario +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                                                      + Playing Audio File +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/sound/07-play-audio-file/index.html b/sound/07-play-audio-file/index.html new file mode 100644 index 000000000..85b19c023 --- /dev/null +++ b/sound/07-play-audio-file/index.html @@ -0,0 +1,2140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Playing Audio File - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + Playing Audio File + + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + Playing Audio File + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Playing Sounds on The RP2040 Chip + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Background on Audio Encoding + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Overall Architecture + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Checking Your Sound File Sizes + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Steps to test playing a wav file + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Clone the Pico Audio PWM GitHub Repository + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Download some test robot wav files + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Converting .MP3 to .WAV files + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Copy Sound Files to the Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Listing the Wave Files + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Checking the WAV File Format + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Adding an Interrupt + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Playing the Same Sound Repeatedly + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + Downloading the Audio Libraries + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Playing Sounds on The RP2040 Chip + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Background on Audio Encoding + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Overall Architecture + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Checking Your Sound File Sizes + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Connections + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Steps to test playing a wav file + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + Clone the Pico Audio PWM GitHub Repository + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Download some test robot wav files + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Converting .MP3 to .WAV files + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Copy Sound Files to the Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Listing the Wave Files + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Checking the WAV File Format + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Adding an Interrupt + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Playing the Same Sound Repeatedly + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + Downloading the Audio Libraries + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                        Playing an Audio File

                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Note

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        This lesson is still a work in progress. The wavePlayer is in an early draft form and has unpredictable interactions with other components. See the wav file test results section below. We also are having problems when different GPIO pins are used. If you stick to pins for GPIO 2 and 3 for the two channels the test run OK.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Playing Sounds on The RP2040 Chip

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Although we can play tones of various pitches on the PR2040 using the PMW to generate square waves, the quality of this sound is not close to high-fidelity sound like you would expect in a personal MP3 audio player.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        In this lesson we will demonstrate how to play a high-quality audio files that are stored on the two megabytes of non-volatile static memory of the Pico. According to the specification of the Raspberry Pi Pico, the system comes with 2MB on-board QSPI Flash that we can use to store sound files. By combining our Pico with an SD card reader we can also play many sounds and even full-length music and full albums.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Background on Audio Encoding

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        PCM Encoding Example

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Audio files are encoded in many formats. For this lab there are two key concepts to understand:

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                        1. The Sampling Rate which is how frequently an audio signal is sampled. The more frequently we sample (up to 41K per second) the higher the fidelity of the recording. The downside is that the audio file takes more space.
                                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                                        3. The audio bit depth is how many bits we used to encode the amplitude of the sound.
                                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        For our labs, we will be using mono files (not stereo) a sampling rate of 8,000 samples per second (8K Hz) and a sampling rate of 16-bit depth. This is a good compromise between smaller size and sound fidelity in typical robots.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Our robots typically will play a short 1-second sound to tell us they are performing an action like stopping, backing up or turning. This one-second 8K Hz WAV file will be about 20K. Our flash budget for the Raspberry Pi Pico is 2M, so we can easily store 10 sound effects in 200K or 1/10 of our available flash memory. We can also add a SD card if we need more flash memory.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        We will be using standard .WAV files with Pulse Code Modulation Encoding in .WAV files. WAV files do take more space than compressed MP3 files, but they are easier to play because the decoding steps are trivial for a microcontroller to perform.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Overall Architecture

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                        1. We will be reading .wav files from the MicroPython non-volatile flash memory or an SD card. By convention we will store them in a directory called /sounds
                                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                                        3. We will be using the wave.py module to read the .wav files
                                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                                        5. We will be using the myPMW.py, chunk.py and myDMA.py modules to stream the data from the WAV files to the PWM controllers
                                                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                                                        7. The metadata from the .wav files is used to change the sampling frequency of the .wav player
                                                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Checking Your Sound File Sizes

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                        import os
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +waveFolder= "/sounds"
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +total = 0
                                                                                                                                                                                                                                                                                                                                                                        +# get a list of .wav files and their sizes
                                                                                                                                                                                                                                                                                                                                                                        +for file in os.listdir(waveFolder):
                                                                                                                                                                                                                                                                                                                                                                        +    size = os.path.getsize(file)
                                                                                                                                                                                                                                                                                                                                                                        +    print(file, size)
                                                                                                                                                                                                                                                                                                                                                                        +    total += size
                                                                                                                                                                                                                                                                                                                                                                        +print('Total sound directory size:', total)
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Connections

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Some of this documentation was take from Dan Perron's Pico Audio GitHub Repo.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        In these tests we used GPIO pins 2 and 3 to drive the left and right channels of audio that are sent to a stereo amplifier. You can use both an amplifier or head phone with a 1K resistor in series on the pins to limit the current from the 3.3v output signals.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The myPWM subclass set the maximum count to 255 (8 bits) or 1023(10bits) at a frequency +around 122.5KHz.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The PWM is now on 10 bits (0..1023)

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The myDMA class allows to use direct memory access to transfer each frame at the current +sample rate.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        We will need to install the wave.py and chunk.py from Jokey GitHub Awesome MicroPython Repo on root file system or the /lib folder on the pico file system.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Don't forget to increase the SPI clock up to 3Mhz. (TODO not sure what this means)

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The following documentation was take from Daniel Perron's Github page.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                        1. We set the PWM to a range of 255 at 122Khz
                                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                                        3. We read the wave file using the class wave.py which will set the + sample rate and read the audio data by chunk
                                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                                        5. Each chunk is converted to 16 bit signed to unsigned char with the middle at 128, (512 for 10 bits)
                                                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                                                        7. We wait for the DMA to be completed. On first it will be anyway.
                                                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                                                        9. The converted chunk is then pass to the DMA to be transfer at the sample rate using one of build in timer
                                                                                                                                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                                                                                                                                        11. Go on step 2 until is done.
                                                                                                                                                                                                                                                                                                                                                                        12. +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Steps to test playing a wav file

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Clone the Pico Audio PWM GitHub Repository

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                        git clone https://github.com/danjperron/PicoAudioPWM
                                                                                                                                                                                                                                                                                                                                                                        +cd PicoAudioPWM
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Download some test robot wav files

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The following GitHub location:

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        https://github.com/CoderDojoTC/robot-media/tree/master/wav-8k

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        contains a set of 8K Hz 16 bit robot sounds that you can use with your robot.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Converting .MP3 to .WAV files

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        This software only currently support playing .wav files since it is easy to convert these files into a format that can be played. WAV files store uncompressed audio, so they are larger than MP3 files. Wav files are simple ways to store sound patterns. MP3 files are much more complex and require complex algorithms to convert into sound outputs.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The usual bitstream encoding is the linear pulse-code modulation (LPCM) format.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        If you have just a few MP3 files, can use the following web-site to convert MP3 files into wave files:

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Cloud Convert Service that Converts MP3 to WAV files

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The next lab shows you how to convert an entire folder of MP3 files to 8K Hz 16-bit WAV files using a shell script.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Copy Sound Files to the Pico

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Your pico has 2MB of static memory. A typical robot sound effect you want to play when you bump into and object will play for around 1 second. You can copy many sound effect files to the pico file system and play them. Some IDEs may allow you to do this or you can use the rshell program.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Here is an example of using the rshell program to copy a directory of wav files to the pico. Lines that start with pc$ are commands that you type into your PC or MAC's terminal. Lines that start with rs$ are commands that you type into the rshell.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                                                        # list the devices (only works on Mac and UNIX)
                                                                                                                                                                                                                                                                                                                                                                        +pc$ ls /dev/cu.modem*
                                                                                                                                                                                                                                                                                                                                                                        +# start the rshell
                                                                                                                                                                                                                                                                                                                                                                        +pc$ rshell -p /dev/cu.modem*
                                                                                                                                                                                                                                                                                                                                                                        +# change the name of the device to be "pico"
                                                                                                                                                                                                                                                                                                                                                                        +rs$ echo 'name="pico"' > /pyboard/board.py
                                                                                                                                                                                                                                                                                                                                                                        +# exit from rshell - can also use exit
                                                                                                                                                                                                                                                                                                                                                                        +CONTROL-C
                                                                                                                                                                                                                                                                                                                                                                        +# reconnect with the rshell
                                                                                                                                                                                                                                                                                                                                                                        +$pc rshell -p /dev/cu.modem*
                                                                                                                                                                                                                                                                                                                                                                        +# go into the /pico file systems
                                                                                                                                                                                                                                                                                                                                                                        +$rs cd /pico
                                                                                                                                                                                                                                                                                                                                                                        +# create a directory for all our sound files
                                                                                                                                                                                                                                                                                                                                                                        +mkdir sounds
                                                                                                                                                                                                                                                                                                                                                                        +# copy files from hour PC's home ~/tmp/sounds dir to the pico
                                                                                                                                                                                                                                                                                                                                                                        +rs$ cp ~/tmp/sounds/*.wav /pico/sounds
                                                                                                                                                                                                                                                                                                                                                                        +rs$ ls /pico/sounds
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Listing the Wave Files

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        After you have a list of Wave files loaded you can verify them by using the os listdir() function.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                                                        import os
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +waveFolder= "/sounds"
                                                                                                                                                                                                                                                                                                                                                                        +wavelist = []
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +# get a list of .wav files
                                                                                                                                                                                                                                                                                                                                                                        +for i in os.listdir(waveFolder):
                                                                                                                                                                                                                                                                                                                                                                        +    if i.find(".wav")>=0:
                                                                                                                                                                                                                                                                                                                                                                        +        wavelist.append(waveFolder+"/"+i)
                                                                                                                                                                                                                                                                                                                                                                        +    elif i.find(".WAV")>=0:
                                                                                                                                                                                                                                                                                                                                                                        +        wavelist.append(waveFolder+"/"+i)
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +if not wavelist :
                                                                                                                                                                                                                                                                                                                                                                        +    print("Warning NO '.wav' files")
                                                                                                                                                                                                                                                                                                                                                                        +else:
                                                                                                                                                                                                                                                                                                                                                                        +    for i in wavelist:
                                                                                                                                                                                                                                                                                                                                                                        +        print(i)
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Sample console output

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                                                        +4
                                                                                                                                                                                                                                                                                                                                                                        +5
                                                                                                                                                                                                                                                                                                                                                                        +6
                                                                                                                                                                                                                                                                                                                                                                        /sounds/cylon-attention.wav
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-by-your-command.wav
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-excellent.wav
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-eye-scanner.wav
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-see-that-the-humans.wav
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-those-are-not-the-sounds.wav
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Checking the WAV File Format

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        There is a standard Python module called `wave.py that reads the .wav files and shows the metadata for the file. Wave files come in many formats, single channel, stereo and different bit rates. The wave player can show us all this data that describes the wave file.

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        The report shows you how to use fixed-width formatting since the file names and data should fit in columns to make it easier to read.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                                                                                                                                                                        +20
                                                                                                                                                                                                                                                                                                                                                                        +21
                                                                                                                                                                                                                                                                                                                                                                        +22
                                                                                                                                                                                                                                                                                                                                                                        +23
                                                                                                                                                                                                                                                                                                                                                                        +24
                                                                                                                                                                                                                                                                                                                                                                        +25
                                                                                                                                                                                                                                                                                                                                                                        +26
                                                                                                                                                                                                                                                                                                                                                                        import os
                                                                                                                                                                                                                                                                                                                                                                        +import wave
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +waveFolder= "/sounds"
                                                                                                                                                                                                                                                                                                                                                                        +wavelist = []
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +# get a list of .wav files
                                                                                                                                                                                                                                                                                                                                                                        +for i in os.listdir(waveFolder):
                                                                                                                                                                                                                                                                                                                                                                        +    if i.find(".wav")>=0:
                                                                                                                                                                                                                                                                                                                                                                        +        wavelist.append(waveFolder+"/"+i)
                                                                                                                                                                                                                                                                                                                                                                        +    elif i.find(".WAV")>=0:
                                                                                                                                                                                                                                                                                                                                                                        +        wavelist.append(waveFolder+"/"+i)
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +if not wavelist :
                                                                                                                                                                                                                                                                                                                                                                        +    print("Warning NO '.wav' files")
                                                                                                                                                                                                                                                                                                                                                                        +else:
                                                                                                                                                                                                                                                                                                                                                                        +    print("{0:<45}".format('File Path'), 'Frame Rate  Width Chans Frames')
                                                                                                                                                                                                                                                                                                                                                                        +    for filename in wavelist:
                                                                                                                                                                                                                                                                                                                                                                        +        f = wave.open(filename,'rb')
                                                                                                                                                                                                                                                                                                                                                                        +        # the format string "{0:<50}" says print left justified from chars 0 to 50 in a fixed with string
                                                                                                                                                                                                                                                                                                                                                                        +        print("{0:<50}".format(filename),
                                                                                                                                                                                                                                                                                                                                                                        +              "{0:>5}".format(f.getframerate()),
                                                                                                                                                                                                                                                                                                                                                                        +              "{0:>5}".format(f.getsampwidth()),
                                                                                                                                                                                                                                                                                                                                                                        +              "{0:>6}".format(f.getnchannels()),
                                                                                                                                                                                                                                                                                                                                                                        +              "{0:>6}".format(f.getnframes())
                                                                                                                                                                                                                                                                                                                                                                        +              )
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Sample Response

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                                                        +4
                                                                                                                                                                                                                                                                                                                                                                        +5
                                                                                                                                                                                                                                                                                                                                                                        +6
                                                                                                                                                                                                                                                                                                                                                                        +7
                                                                                                                                                                                                                                                                                                                                                                        File Path                                     Frame Rate  Width Chans Frames
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-attention.wav                         8000     1      1   6399
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-by-your-command.wav                  11025     1      1  12583
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-excellent.wav                        22050     1      1  48736
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-eye-scanner.wav                      16000     2      2  24768
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-see-that-the-humans.wav              11025     1      1  30743
                                                                                                                                                                                                                                                                                                                                                                        +/sounds/cylon-those-are-not-the-sounds.wav         22050     1      1  64137
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Adding an Interrupt

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        If you halt the RP2040 while it is playing a sound, the independent PWM controllers will continue to generate sound. In order to shut the independent PWM controllers, an interrupt controller system must be used to cleanly disable all the sound. Here is an example of this using a try/except block of code.

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                        import os as uos
                                                                                                                                                                                                                                                                                                                                                                        +from wavePlayer import wavePlayer
                                                                                                                                                                                                                                                                                                                                                                        +player = wavePlayer()
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +try:
                                                                                                                                                                                                                                                                                                                                                                        +    while True:
                                                                                                                                                                                                                                                                                                                                                                        +        # repeat this over and over until the keyboard shuts down the circuit
                                                                                                                                                                                                                                                                                                                                                                        +        player.play('/sounds/cylon-eye-scanner.wav')
                                                                                                                                                                                                                                                                                                                                                                        +except KeyboardInterrupt:
                                                                                                                                                                                                                                                                                                                                                                        +    player.stop()
                                                                                                                                                                                                                                                                                                                                                                        +    print("wave player terminated")
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Playing the Same Sound Repeatedly

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                        import os as uos
                                                                                                                                                                                                                                                                                                                                                                        +from wavePlayer import wavePlayer
                                                                                                                                                                                                                                                                                                                                                                        +player = wavePlayer()
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +try:
                                                                                                                                                                                                                                                                                                                                                                        +    while True:
                                                                                                                                                                                                                                                                                                                                                                        +        player.play('/sounds/cylon-eye-scanner.wav')
                                                                                                                                                                                                                                                                                                                                                                        +except KeyboardInterrupt:
                                                                                                                                                                                                                                                                                                                                                                        +    player.stop()
                                                                                                                                                                                                                                                                                                                                                                        +    print("wave player terminated")
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Downloading the Audio Libraries

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        Both the wave.py and the chunck.py files are here:

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio

                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                        References

                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                        1. Daniel Perron
                                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                                        3. Wikipedia page for Wave Filec
                                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                                        5. Web-Based Audio Conversion Service Convertio
                                                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                                                        7. Wikipedia page for Audio Interchange File Format
                                                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                                                        9. Wikipedia page for Pulse-code Modulation
                                                                                                                                                                                                                                                                                                                                                                        10. +
                                                                                                                                                                                                                                                                                                                                                                        11. Raspberry Pi Pico Forum on Sounds Files
                                                                                                                                                                                                                                                                                                                                                                        12. +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                        + Eight Key Piano +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                                                                        + Converting Audio Files +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/sound/07a-test-audio-ports/index.html b/sound/07a-test-audio-ports/index.html new file mode 100644 index 000000000..368240027 --- /dev/null +++ b/sound/07a-test-audio-ports/index.html @@ -0,0 +1,1362 @@ + + + + + + + + + + + + + + + + + + + + + + + Testing Audio Ports - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + Testing Audio Ports + + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                          Testing Audio Ports

                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                          In this lab, we will be testing stereo audio ports. We will be sending a 1 kilohertz square wave to the left and then right ports. This program allows you to test your stereo connections and make sure that both channels are working correctly.

                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                                                                                                                                                                          from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                          +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +# You will need to configure these two digital output ports
                                                                                                                                                                                                                                                                                                                                                                          +AUDIO_LEFT_PIN = 18
                                                                                                                                                                                                                                                                                                                                                                          +AUDIO_RIGHT_PIN = 19
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                                          +left_speaker = PWM(Pin(AUDIO_LEFT_PIN))
                                                                                                                                                                                                                                                                                                                                                                          +# set the duty cycle to be 50%
                                                                                                                                                                                                                                                                                                                                                                          +left_speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                          +left_speaker.freq(1000) # 50% on and off
                                                                                                                                                                                                                                                                                                                                                                          +sleep(1) # wait a second
                                                                                                                                                                                                                                                                                                                                                                          +left_speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                          +# turn off the PWM circuits off with a zero duty cycle
                                                                                                                                                                                                                                                                                                                                                                          +left_speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                          +sleep(1)
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +# create a Pulse Width Modulation Object on this pin
                                                                                                                                                                                                                                                                                                                                                                          +right_speaker = PWM(Pin(AUDIO_RIGHT_PIN))
                                                                                                                                                                                                                                                                                                                                                                          +# set the duty cycle to be 50%
                                                                                                                                                                                                                                                                                                                                                                          +right_speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                          +right_speaker.freq(1000) # 50% on and off
                                                                                                                                                                                                                                                                                                                                                                          +sleep(1) # wait a second
                                                                                                                                                                                                                                                                                                                                                                          +right_speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                          +# turn off the PWM circuits off with a zero duty cycle
                                                                                                                                                                                                                                                                                                                                                                          +right_speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                          References

                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                          https://en.wikipedia.org/wiki/Phone_connector_(audio)#Computer_sound

                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/sound/08-i2s-standard/index.html b/sound/08-i2s-standard/index.html new file mode 100644 index 000000000..b6e590a13 --- /dev/null +++ b/sound/08-i2s-standard/index.html @@ -0,0 +1,1291 @@ + + + + + + + + + + + + + + + + + + + + + + + I2S Standard - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + I2S Standard + + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                            I2S Standard

                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                            I2S (Inter-IC Sound) pronounced "eye-two-ess", is an electrical serial bus interface standard used for connecting digital audio devices together. It is a general interface to communicate PCM audio data between integrated circuits in an electronic device.

                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                            Note that I2S is unrelated to the similar sounding I2C bus protocol.

                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                            Since MicroPython 1.17 we have a library that allows us to play

                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/sound/09-converting-mp3-to-wav/index.html b/sound/09-converting-mp3-to-wav/index.html new file mode 100644 index 000000000..efecb8efc --- /dev/null +++ b/sound/09-converting-mp3-to-wav/index.html @@ -0,0 +1,1825 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Converting Audio Files - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + Converting Audio Files + + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Converting Audio Files + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Method 1: Use the ffmpeg Command Line Tool + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Converting MP3 to 8K 16 bit WAV Files + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Bulk Conversions + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Inspect the Files Using the UNIX file command: + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Method 2: Use the pydub Python Module + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + Install Conda and the Python libraries + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + Running pydub + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Transferring the Files with Rshell + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Method 1: Use the ffmpeg Command Line Tool + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Converting MP3 to 8K 16 bit WAV Files + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Bulk Conversions + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Inspect the Files Using the UNIX file command: + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Method 2: Use the pydub Python Module + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + Install Conda and the Python libraries + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + Running pydub + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + Transferring the Files with Rshell + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                              Converting MP3 to WAV formats

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              In last lab we will learned how to play an audio file stored on the flash memory or SD card. We used an early version of a Python module that plays .WAV files in a fixed format: 8,000 samples per second using 16-bit encoding. Because there are hundreds of different formats of audio files, we need a consistent way to convert all of these formats to 8K samples/second 16-bit .WAV formats.

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              The audio data file conversions are done on your host PC, not the microcontroller. This allows us to use a rich library of tools that don't need to run on our microcontroller.

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Method 1: Use the ffmpeg Command Line Tool

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              One of the easiest ways to get started is to go to the web site ffmpeg.org and download the program that does the conversion using a command line. Note that on a Mac you will need to go into your System Preferences and indicate that the following programs are trusted:

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Here are the direct links for MacOS

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                              1. ffmpeg (mac)
                                                                                                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                                                                                                              3. ffprobe (mac)
                                                                                                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                                                                                                              5. ffplay (mac)
                                                                                                                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              This will download a zip file which you will need to unzip and place in a location such as ~/bin. After you do this make sure you add `~/bin to your path by adding the following file to your .bash_profile:

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              PATH=$PATH:~/bin

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              After you source your .bash_profile type in the following:

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              which ffmpeg

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              This should return the location that it finds the ffmpeg shell script. You can then see the many file-format MPEG options:

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              ffmpeg --help

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Converting MP3 to 8K 16 bit WAV Files

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              To get the format we need for the MicroPython wave player class we just specific -i for the input file and use the -ar 8000 to specify the output bit rate of 8K samples per second. The final parameter is a file name that must in .wav so the command knows to use WAV PCM encoding. The default value is 16 gits per sample.

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              ffmpeg -i r2d2-beeping.mp3 -ar 8000 r2d2-beeping-8k.wav
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Bulk Conversions

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              We can use unix shell commands to do a batch conversion of all the . The following is an example of using awk and sed to convert all the .mp3 files in a directory and convert them to 8K Hz WAV files and put them in a sibling directory.

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              ls -1 *.mp3 | awk '{print "ffmpeg -i " $1 " -ar 8000 ../wav-8k/"$1}' | sed s/mp3$/wav/ | sh
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Inspect the Files Using the UNIX file command:

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                              cd ../wav-8k
                                                                                                                                                                                                                                                                                                                                                                              +file *.wav
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              returns +

                                                                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                                                                                                              r2d2-another-beep.wav:          RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-beeping-2.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-beeping-4.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-beeping-8k.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-beeping-like-an-alarm.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-beeping.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-cheerful.wav:              RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-determined.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-excited.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-laughing.wav:              RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-more-chatter.wav:          RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-processing.wav:            RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-sad.wav:                   RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-shocked.wav:               RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-surprised.wav:             RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-taking-to-himself.wav:     RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +r2d2-unsure.wav:                RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Note that these are WAVE audio, Pulse-code Modulated (PCM), 16 bit and mono at 8K Hz.

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Method 2: Use the pydub Python Module

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Note

                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              This section is only for experienced Python developers.

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Install Conda and the Python libraries

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                                                                              conda create -n mp3-to-wav python=3
                                                                                                                                                                                                                                                                                                                                                                              +conda activate mp3-to-wav
                                                                                                                                                                                                                                                                                                                                                                              +pip install pydub ffprobe ffmpeg
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Check your versions:

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              pip freeze
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              returns:

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                                                                              ffmpeg==1.4
                                                                                                                                                                                                                                                                                                                                                                              +ffprobe==0.5
                                                                                                                                                                                                                                                                                                                                                                              +pydub==0.25.1
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Running pydub

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                                                                              +4
                                                                                                                                                                                                                                                                                                                                                                              from pydub import AudioSegment
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +sound = AudioSegment.from_mp3("r2d2-beeping.mp3")
                                                                                                                                                                                                                                                                                                                                                                              +sound.export("r2d2-beeping.wav", format="wav", tags={'Robot name': 'R2D2'})
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              Transferring the Files with Rshell

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                                                                              cd ../wav-8k
                                                                                                                                                                                                                                                                                                                                                                              +rshell -p /dev/cu.usbmodem14101
                                                                                                                                                                                                                                                                                                                                                                              +cp *.wav /pico/sounds
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                              References

                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                              1. PyDub Documentation
                                                                                                                                                                                                                                                                                                                                                                              2. +
                                                                                                                                                                                                                                                                                                                                                                              3. File Formats for Audio from MPEG
                                                                                                                                                                                                                                                                                                                                                                              4. +
                                                                                                                                                                                                                                                                                                                                                                              5. File Formats for motion picture experts group Python Library
                                                                                                                                                                                                                                                                                                                                                                              6. +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                              + Playing Audio File +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                                                                              + Introduction +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/sound/10-midi/index.html b/sound/10-midi/index.html new file mode 100644 index 000000000..43c488564 --- /dev/null +++ b/sound/10-midi/index.html @@ -0,0 +1,1381 @@ + + + + + + + + + + + + + + + + + + + + + + + MIDI with MicroPython - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + MIDI with MicroPython + + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + Ascending Notes + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                MIDI with MicroPython

                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Warnining

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                I am not an expert on MIDI and I don't have any MIDI gear. This is +mostly a collection of material I have for students that want +to use MicroPython to generate music.

                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Sample Code

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Ascending Notes

                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                                # Play Test MIDI Ascending Notes
                                                                                                                                                                                                                                                                                                                                                                                +from machine import Pin, UART
                                                                                                                                                                                                                                                                                                                                                                                +import time
                                                                                                                                                                                                                                                                                                                                                                                +uart = UART(1, baudrate=31250, tx=Pin(4), rx=Pin(5))
                                                                                                                                                                                                                                                                                                                                                                                +uart.init(bits=8, parity=None, stop=1)
                                                                                                                                                                                                                                                                                                                                                                                +led=Pin("LED", Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                                +note = 24
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +while True:
                                                                                                                                                                                                                                                                                                                                                                                +    midimessage = bytearray([0x90, note, 64])
                                                                                                                                                                                                                                                                                                                                                                                +    uart.write(midimessage)
                                                                                                                                                                                                                                                                                                                                                                                +    led.toggle()
                                                                                                                                                                                                                                                                                                                                                                                +    # change third parameter to be 0
                                                                                                                                                                                                                                                                                                                                                                                +    midimessage = bytearray([0x90, note, 0])
                                                                                                                                                                                                                                                                                                                                                                                +    # pause 1/8 of a second
                                                                                                                                                                                                                                                                                                                                                                                +    time.sleep(0.125)
                                                                                                                                                                                                                                                                                                                                                                                +    note += 2
                                                                                                                                                                                                                                                                                                                                                                                +    if note > 64:
                                                                                                                                                                                                                                                                                                                                                                                +        note=24
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                References

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Raspberry Pi Pico MIDI Development Board Midimuso for $20 US. This board has all the MIDI connectors on it.

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Simple DIY electromusic Project

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                DIY Electro Music SDEMP MicroPython Code on GitHub

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                Pico MIDI by Barb Arach

                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                PicoMIDI manual v1.0

                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/sound/11-sound-parts/index.html b/sound/11-sound-parts/index.html new file mode 100644 index 000000000..f1b225320 --- /dev/null +++ b/sound/11-sound-parts/index.html @@ -0,0 +1,1296 @@ + + + + + + + + + + + + + + + + + + + + + + + Sound Parts - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + Sound Parts + + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                  Sound Parts

                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                                                                                                                                                                    PAM8302A Miniature 2.5W Class D Mono Audio Power Amplifier Module Board

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                                                  • +

                                                                                                                                                                                                                                                                                                                                                                                    PAM8302A 10pcs

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/sound/20-i2s-bus/index.html b/sound/20-i2s-bus/index.html new file mode 100644 index 000000000..93d5a117d --- /dev/null +++ b/sound/20-i2s-bus/index.html @@ -0,0 +1,1980 @@ + + + + + + + + + + + + + + + + + + + + + + + The I2S Bus - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + The I2S Bus + + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 1. High-Quality Digital Audio + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 2. Low Pin Usage + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 3. Stereo Audio Support + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 4. Ease of Integration with Digital Audio Components + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 5. Reduced Audio Interference + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 6. Support for Advanced Audio Formats + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 7. Ideal for Audio Projects + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 8. Integration with MicroPython + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + 9. Applications in Education and Prototyping + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + Example Applications + + + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    • + + + Robot Sounds Project + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Project: Robot Sound Player on Raspberry Pi Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Components Needed + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Steps to Build + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 1. Prepare the Sound Files + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 2. Connect the Components + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + MicroSD Module to Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + I2S DAC to Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + Speaker to DAC**: + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + Button to Pico:** + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 3. Install the Required Software + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 4. Write the Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 5. Test the Setup + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Extensions + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Storing the Sounds on the Pico's Flash Memory + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Considerations for Storing Sounds in Flash Memory + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Limited Flash Storage Space + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + File Size and Format + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Loading Files into Flash** + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Playback Speed + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Steps to Store and Play Sounds from Flash + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 1.Prepare the Sound Files + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 2. Upload Files to Pico + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 3. MicroPython Code for Playback + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + 4. Optimize and Test + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Advantages + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + Limitations + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                    The I2S Bus

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    The I2S (Inter-IC Sound) bus on the Raspberry Pi Pico is a versatile and high-quality interface for digital audio. Here are some compelling reasons to use it:

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    1. High-Quality Digital Audio

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • I2S allows for precise, lossless transfer of digital audio between devices, ensuring superior sound quality compared to analog signals that are susceptible to noise and distortion.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    2. Low Pin Usage

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • I2S requires only a few pins to transmit high-quality audio data. This leaves other GPIO pins available for additional peripherals or projects.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    3. Stereo Audio Support

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • The I2S bus can handle stereo audio, making it ideal for projects requiring left and right channels, such as music players, audio recorders, or sound-based art installations.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    4. Ease of Integration with Digital Audio Components

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Many digital audio devices, such as DACs (Digital-to-Analog Converters), ADCs (Analog-to-Digital Converters), and codecs, natively support I2S. This simplifies the integration of audio into your projects.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    5. Reduced Audio Interference

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • By keeping the audio in the digital domain until it reaches the final output stage (e.g., DAC), I2S reduces the risk of electromagnetic interference that analog signals might pick up.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    6. Support for Advanced Audio Formats

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • I2S can transmit audio at various sample rates and bit depths (e.g., 16-bit, 24-bit), enabling support for high-fidelity audio formats used in modern applications.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    7. Ideal for Audio Projects

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    The I2S interface is perfect for: +- Building audio streaming devices. +- Implementing DIY digital radios or podcast recording setups. +- Creating smart speakers or voice assistants.

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    8. Integration with MicroPython

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • The Raspberry Pi Pico's support for MicroPython and C/C++ makes it easy to work with I2S in a high-level programming environment, reducing development complexity.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    9. Applications in Education and Prototyping

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • For educational purposes, I2S offers an opportunity to learn about digital audio processing and signal transmission. It also facilitates prototyping of commercial audio equipment.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Example Applications

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • DIY Digital Audio Player: Combine an I2S DAC with an SD card reader to create a custom MP3 or FLAC player.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Audio Signal Processing: Capture audio with an I2S ADC for real-time signal analysis or effects processing.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Voice Recognition Systems: Use I2S microphones for clear audio input in speech-to-text or voice control projects.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    The inclusion of I2S on the Raspberry Pi Pico opens up a world of opportunities for high-quality, efficient, and versatile audio processing in your projects.

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Robot Sounds Project

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Here we describe a simple project that plays robot sound files on the Raspberry Pi Pico.

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Project: Robot Sound Player on Raspberry Pi Pico

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    This project will use the Raspberry Pi Pico with an I2S DAC to play pre-recorded robot sound files (e.g., "beeps," "boops," "affirmative," "error") stored on a microSD card. The sounds will be triggered using a button or slider switch.

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Components Needed

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    1. Raspberry Pi Pico (with headers for easy wiring)
                                                                                                                                                                                                                                                                                                                                                                                    2. +
                                                                                                                                                                                                                                                                                                                                                                                    3. I2S DAC Module (e.g., PCM5102)
                                                                                                                                                                                                                                                                                                                                                                                    4. +
                                                                                                                                                                                                                                                                                                                                                                                    5. MicroSD Card Module (for storing sound files)
                                                                                                                                                                                                                                                                                                                                                                                    6. +
                                                                                                                                                                                                                                                                                                                                                                                    7. Speaker (connected to the DAC)
                                                                                                                                                                                                                                                                                                                                                                                    8. +
                                                                                                                                                                                                                                                                                                                                                                                    9. Push Button or Slider Switch (to trigger sound effects)
                                                                                                                                                                                                                                                                                                                                                                                    10. +
                                                                                                                                                                                                                                                                                                                                                                                    11. Wires and Breadboard
                                                                                                                                                                                                                                                                                                                                                                                    12. +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Steps to Build

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    1. Prepare the Sound Files

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Convert your robot sound files to a compatible format like 16-bit PCM WAV files at 44.1 kHz.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Store the WAV files on a microSD card with filenames like robot1.wav, robot2.wav.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    2. Connect the Components

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    MicroSD Module to Pico
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • VCC → Pico 3.3V
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • GND → Pico GND
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • MISO → Pico GP16
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • MOSI → Pico GP19
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • SCK → Pico GP18
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • CS → Pico GP17
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    I2S DAC to Pico
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • BCK → Pico GP10
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • LRCK → Pico GP11
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • DIN → Pico GP9
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • GND → Pico GND
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • VCC → Pico 3.3V or 5V (depending on the module)
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    Speaker to DAC**:
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                                                                                    -   Connect the speaker output from the DAC module to your speaker terminals.
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    Button to Pico:**
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                                                                                    +2
                                                                                                                                                                                                                                                                                                                                                                                    +3
                                                                                                                                                                                                                                                                                                                                                                                    -   One side of the button → Pico `GP14`
                                                                                                                                                                                                                                                                                                                                                                                    +-   Other side of the button → `GND`
                                                                                                                                                                                                                                                                                                                                                                                    +-   Use a 10K pull-up resistor from `GP14` to `3.3V`.
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    3. Install the Required Software

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Install MicroPython on your Pico.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Upload libraries for:
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                      • I2S Audio Playback: E.g., i2s_audio.py
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      • SD Card Access: uos or os module with MicroPython SD card libraries.
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Format the microSD card as FAT32.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    4. Write the Code

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Below is an example MicroPython code for playing sound files using a button trigger:

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                                                                                                                                                                    +20
                                                                                                                                                                                                                                                                                                                                                                                    +21
                                                                                                                                                                                                                                                                                                                                                                                    +22
                                                                                                                                                                                                                                                                                                                                                                                    +23
                                                                                                                                                                                                                                                                                                                                                                                    +24
                                                                                                                                                                                                                                                                                                                                                                                    +25
                                                                                                                                                                                                                                                                                                                                                                                    +26
                                                                                                                                                                                                                                                                                                                                                                                    +27
                                                                                                                                                                                                                                                                                                                                                                                    +28
                                                                                                                                                                                                                                                                                                                                                                                    +29
                                                                                                                                                                                                                                                                                                                                                                                    +30
                                                                                                                                                                                                                                                                                                                                                                                    +31
                                                                                                                                                                                                                                                                                                                                                                                    +32
                                                                                                                                                                                                                                                                                                                                                                                    +33
                                                                                                                                                                                                                                                                                                                                                                                    +34
                                                                                                                                                                                                                                                                                                                                                                                    +35
                                                                                                                                                                                                                                                                                                                                                                                    +36
                                                                                                                                                                                                                                                                                                                                                                                    +37
                                                                                                                                                                                                                                                                                                                                                                                    from machine import Pin, I2S, SPI
                                                                                                                                                                                                                                                                                                                                                                                    +import uos
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +# Initialize I2S for DAC
                                                                                                                                                                                                                                                                                                                                                                                    +audio_out = I2S(
                                                                                                                                                                                                                                                                                                                                                                                    +    0,
                                                                                                                                                                                                                                                                                                                                                                                    +    sck=Pin(10),   # Bit clock
                                                                                                                                                                                                                                                                                                                                                                                    +    ws=Pin(11),    # Word select
                                                                                                                                                                                                                                                                                                                                                                                    +    sd=Pin(9),     # Serial data
                                                                                                                                                                                                                                                                                                                                                                                    +    mode=I2S.TX,
                                                                                                                                                                                                                                                                                                                                                                                    +    bits=16,
                                                                                                                                                                                                                                                                                                                                                                                    +    format=I2S.MONO,
                                                                                                                                                                                                                                                                                                                                                                                    +    rate=44100
                                                                                                                                                                                                                                                                                                                                                                                    +)
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +# Initialize SD Card
                                                                                                                                                                                                                                                                                                                                                                                    +spi = SPI(0, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
                                                                                                                                                                                                                                                                                                                                                                                    +sd_cs = Pin(17, Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                                    +uos.mount(SDCard(spi, sd_cs), "/sd")
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +# Button Input
                                                                                                                                                                                                                                                                                                                                                                                    +button = Pin(14, Pin.IN, Pin.PULL_UP)
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +def play_sound(file_path):
                                                                                                                                                                                                                                                                                                                                                                                    +    with open(file_path, "rb") as wav:
                                                                                                                                                                                                                                                                                                                                                                                    +        wav.seek(44)  # Skip WAV header
                                                                                                                                                                                                                                                                                                                                                                                    +        while True:
                                                                                                                                                                                                                                                                                                                                                                                    +            buf = wav.read(2048)
                                                                                                                                                                                                                                                                                                                                                                                    +            if not buf:
                                                                                                                                                                                                                                                                                                                                                                                    +                break
                                                                                                                                                                                                                                                                                                                                                                                    +            audio_out.write(buf)
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +print("Ready to play robot sounds!")
                                                                                                                                                                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                                                                                                                                                                    +    if not button.value():  # Button pressed
                                                                                                                                                                                                                                                                                                                                                                                    +        print("Playing sound!")
                                                                                                                                                                                                                                                                                                                                                                                    +        play_sound("/sd/robot1.wav")
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    5. Test the Setup

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Power up the Pico.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Press the button to trigger playback of robot1.wav.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Swap out files or add more buttons to trigger additional sounds.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Extensions

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    1. Multiple Buttons: Add more buttons to trigger different sound effects.
                                                                                                                                                                                                                                                                                                                                                                                    2. +
                                                                                                                                                                                                                                                                                                                                                                                    3. Random Playback: Use the random module to pick a random sound from the SD card.
                                                                                                                                                                                                                                                                                                                                                                                    4. +
                                                                                                                                                                                                                                                                                                                                                                                    5. Interactive Robot: Connect the sound system to sensors (e.g., distance or light sensors) to play sounds based on environmental triggers.
                                                                                                                                                                                                                                                                                                                                                                                    6. +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    This project is an engaging way to learn about I2S, digital audio, and MicroPython, while creating a fun and interactive robot sound player!

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    Storing the Sounds on the Pico's Flash Memory
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    We can store the sound files on the Raspberry Pi Pico's internal flash memory instead of using an external microSD card. However, there are a few considerations and limitations to keep in mind:

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Considerations for Storing Sounds in Flash Memory

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Limited Flash Storage Space

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • The Raspberry Pi Pico has 2 MB of onboard flash memory, which is shared with the MicroPython firmware and your code.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Sound files (e.g., WAV) can be quite large, so you'll need to ensure the files fit within the available space.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Use compressed or low-bitrate audio formats if possible (e.g., 8-bit, mono, low sample rate).
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    File Size and Format

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • A typical PCM WAV file at 16-bit, 44.1 kHz uses ~88 KB per second of audio. Consider using a lower sample rate (e.g., 8 kHz) to save space.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Mono sound files consume less space than stereo.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Loading Files into Flash**

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Store the audio files in the Pico's filesystem (accessible via MicroPython) by uploading them using a file transfer tool like Thonny or a command-line tool like ampy.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Playback Speed

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Flash memory access is slower than an I2S DAC with buffered SD card reading. For short sound clips, this isn't usually an issue.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Steps to Store and Play Sounds from Flash

                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    1.Prepare the Sound Files

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Convert your sound files to a smaller format:
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                      • Mono, 8-bit PCM WAV
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      • Sample rate: 8 kHz or 16 kHz
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Example tools for conversion:
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                      • Audacity
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      • ffmpeg command-line tool:
                                                                                                                                                                                                                                                                                                                                                                                      • +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    1
                                                                                                                                                                                                                                                                                                                                                                                    ffmpeg -i input.wav -ar 16000 -ac 1 -b:a 8k output.wav
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    2. Upload Files to Pico

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Open the Thonny IDE.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Connect your Pico.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • In the File Explorer, upload your WAV file(s) to the Pico's flash memory.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    3. MicroPython Code for Playback

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Below is an example code to play a short WAV file stored in the Pico's flash memory:
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                                                                                                                                                                    +20
                                                                                                                                                                                                                                                                                                                                                                                    +21
                                                                                                                                                                                                                                                                                                                                                                                    +22
                                                                                                                                                                                                                                                                                                                                                                                    +23
                                                                                                                                                                                                                                                                                                                                                                                    +24
                                                                                                                                                                                                                                                                                                                                                                                    +25
                                                                                                                                                                                                                                                                                                                                                                                    +26
                                                                                                                                                                                                                                                                                                                                                                                    +27
                                                                                                                                                                                                                                                                                                                                                                                    +28
                                                                                                                                                                                                                                                                                                                                                                                    +29
                                                                                                                                                                                                                                                                                                                                                                                    from machine import I2S, Pin
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +# Initialize I2S for DAC
                                                                                                                                                                                                                                                                                                                                                                                    +audio_out = I2S(
                                                                                                                                                                                                                                                                                                                                                                                    +    0,
                                                                                                                                                                                                                                                                                                                                                                                    +    sck=Pin(10),   # Bit clock
                                                                                                                                                                                                                                                                                                                                                                                    +    ws=Pin(11),    # Word select
                                                                                                                                                                                                                                                                                                                                                                                    +    sd=Pin(9),     # Serial data
                                                                                                                                                                                                                                                                                                                                                                                    +    mode=I2S.TX,
                                                                                                                                                                                                                                                                                                                                                                                    +    bits=16,
                                                                                                                                                                                                                                                                                                                                                                                    +    format=I2S.MONO,
                                                                                                                                                                                                                                                                                                                                                                                    +    rate=16000  # Match the WAV file's sample rate
                                                                                                                                                                                                                                                                                                                                                                                    +)
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +def play_sound(file_path):
                                                                                                                                                                                                                                                                                                                                                                                    +    try:
                                                                                                                                                                                                                                                                                                                                                                                    +        with open(file_path, "rb") as wav:
                                                                                                                                                                                                                                                                                                                                                                                    +            wav.seek(44)  # Skip WAV header
                                                                                                                                                                                                                                                                                                                                                                                    +            while True:
                                                                                                                                                                                                                                                                                                                                                                                    +                buf = wav.read(2048)
                                                                                                                                                                                                                                                                                                                                                                                    +                if not buf:
                                                                                                                                                                                                                                                                                                                                                                                    +                    break
                                                                                                                                                                                                                                                                                                                                                                                    +                audio_out.write(buf)
                                                                                                                                                                                                                                                                                                                                                                                    +    except Exception as e:
                                                                                                                                                                                                                                                                                                                                                                                    +        print(f"Error playing sound: {e}")
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +# Play the sound file stored on the Pico
                                                                                                                                                                                                                                                                                                                                                                                    +print("Playing robot sound...")
                                                                                                                                                                                                                                                                                                                                                                                    +play_sound("robot1.wav")
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    4. Optimize and Test

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Use uos.listdir() to list files stored in flash memory.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Ensure the file format matches the I2S configuration (e.g., 8-bit or 16-bit, mono or stereo).
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Test playback and confirm there are no buffer underruns.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Advantages

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Eliminates the need for external storage hardware (microSD card module).
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Simpler wiring and lower cost.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Suitable for small, self-contained projects where a few short sound clips are needed.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    Limitations

                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                    • Limited storage for audio files.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    • Requires careful management of the flash memory to avoid overwriting important files or the firmware.
                                                                                                                                                                                                                                                                                                                                                                                    • +
                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                    For projects with just a few short robot sound effects, storing the sounds on the Pico's flash memory is a practical and convenient option.

                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/docs/sound/dac/dac-pcm5102.png b/sound/dac/dac-pcm5102.png similarity index 100% rename from docs/sound/dac/dac-pcm5102.png rename to sound/dac/dac-pcm5102.png diff --git a/sound/dac/index.html b/sound/dac/index.html new file mode 100644 index 000000000..c3757ddfc --- /dev/null +++ b/sound/dac/index.html @@ -0,0 +1,1288 @@ + + + + + + + + + + + + + + + + + + + + + + + Using a Digital to Analog Converter - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + Using a Digital to Analog Converter + + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                      Using a Digital to Analog Converter

                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/sound/index.html b/sound/index.html new file mode 100644 index 000000000..4417770b3 --- /dev/null +++ b/sound/index.html @@ -0,0 +1,1570 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + Introduction + + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + Sound and Music + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing a Tone + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing Three Tones + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing a Scale + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Play Mario + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Eight Key Piano + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Playing Audio File + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Converting Audio Files + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + How Microcontrollers Generate Sound + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Duty Cycle + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + Connecting a Sound Device + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                        Introduction to Sound and Music in MicroPython

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        How Microcontrollers Generate Sound

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Microcontrollers are really great at generating digital outputs on their GPIO pins. These digital signals that quickly switch between zero and a positive voltage like 3.3 or 5 volts. However, they are not designed to create "analog" output of a continuous varying voltage. However, we can use a technique called "Pulse Width Modulation" to simulate the various frequencies of sound using digital only outputs.

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Pulse Width Modulation is the process of changing not the height of a electrical signal, but the width between the pulses of digital signals. By changing the distance of the spaces between the digital signals we can generate a signal that will sound like it has a higher or lower frequency or pitch.

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        MicroPython provides a powerful library of tools for you to easily generate pulses of different shapes. This is called the PWM library. Will will use this in our sound and music programs. Here is a sample of how this is called in our code:

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Duty Cycle

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        The Duty Cycle is what percent of time a pulse is high.

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Duty Cycle

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        For working with sound, we want to generate smooth sound waves that are on 1/2 of the time and off 1/2 of the time. So our duty cycles will be set to be 50%. On the Raspberry Pi Pico we can achieve this by the following function:

                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                        speaker.duty_u16(1000)
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        When we are done playing a tone, we must always explicitly turn the duty cycle back to 0.

                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                        speaker.duty_u16(0)
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        If we forget to add this line, the tone will continue to play despite the main program stopping. This shows you that the part of the chip that generates the tone pulses is an independent processor that is not dependant on the main program running!

                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                                        from machine import Pin, PWM
                                                                                                                                                                                                                                                                                                                                                                                        +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Note that we will also need to pause between notes, so will use the sleep library to pause execution of our sound generation.

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        Connecting a Sound Device

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        There are several different ways that you can connect a sound device to you MicroController. Here are three options:

                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                        1. Buzzers - These are small inexpensive devices that can mount directly on your breadboard.
                                                                                                                                                                                                                                                                                                                                                                                        2. +
                                                                                                                                                                                                                                                                                                                                                                                        3. Piezoelectric Speaker - Wikipedia Page on Piezoelectric Speaker
                                                                                                                                                                                                                                                                                                                                                                                        4. +
                                                                                                                                                                                                                                                                                                                                                                                        5. Speaker - A magnetic speaker with our without an amplifier is another way to hear sound. You can also purchase a small amplifier to increase the volume.
                                                                                                                                                                                                                                                                                                                                                                                        6. +
                                                                                                                                                                                                                                                                                                                                                                                        7. Amplifier - For about $1.20 you can purchase a small amplifier for your speaker. eBay LM386 DC 5V-12V Mini Micro Audio Amplifier Module Board
                                                                                                                                                                                                                                                                                                                                                                                        8. +
                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        References

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                        1, Juke Phone in C - convert an old land-line telephone to an MP3-player Jukebox. Although this is written in C, it could be converted into MicroPython.

                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                        + OLED References +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                        + Playing a Tone +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/docs/sound/midi-code.png b/sound/midi-code.png similarity index 100% rename from docs/sound/midi-code.png rename to sound/midi-code.png diff --git a/docs/sound/midi/01-play-test.py b/sound/midi/01-play-test.py similarity index 100% rename from docs/sound/midi/01-play-test.py rename to sound/midi/01-play-test.py diff --git a/sound/midi/index.html b/sound/midi/index.html new file mode 100644 index 000000000..00db64807 --- /dev/null +++ b/sound/midi/index.html @@ -0,0 +1,1283 @@ + + + + + + + + + + + + + + + + + + + + + + + Index - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + Index + + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                          Index

                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/src/20-sound-test.py b/src/20-sound-test.py deleted file mode 100644 index cae2fc7db..000000000 --- a/src/20-sound-test.py +++ /dev/null @@ -1,51 +0,0 @@ -import machine -import utime -from machine import Pin, ADC, SPI -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for GPIO26 (ADC0) -adc = ADC(Pin(26)) - -min=64000 -def plot_signal(): - global min - display.fill(0) # Clear the display - old_x = 0 - old_y = HEIGHT // 2 - - # For simplicity, we're plotting every other pixel - for x in range(0, WIDTH): - # Read from ADC (values will be from 0 to 4095) - val = adc.read_u16() - if val < min: - min = val - # print(val-min) - # Scale the ADC value to fit the OLED height - y = int(((val-min) / 500) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - # Draw a line from the last point to the new point - display.line(old_x, old_y, x, y, 1) - old_x, old_y = x, y - - display.show() # Update the display with the new data - -while True: - plot_signal() - utime.sleep(0.1) # Small delay to reduce flickering - diff --git a/src/YD-RP2040/01-blink.py b/src/YD-RP2040/01-blink.py deleted file mode 100644 index 43c52498d..000000000 --- a/src/YD-RP2040/01-blink.py +++ /dev/null @@ -1,11 +0,0 @@ -# blink the builtin blue LED -from machine import Pin -from utime import sleep - -# hardware config parameters -BUILTIN_LED_PIN = 25 -led = Pin(BUILTIN_LED_PIN, Pin.OUT) - -while True: - led.toggle() - sleep(.5) diff --git a/src/YD-RP2040/02-button.py b/src/YD-RP2040/02-button.py deleted file mode 100644 index 17efc2fec..000000000 --- a/src/YD-RP2040/02-button.py +++ /dev/null @@ -1,16 +0,0 @@ -from machine import Pin -import time - -# GPIO is the internal built-in LED. It is an output pin. -led = Pin(25, Pin.OUT) -# The button is is an input and must have a pull up -button = Pin(24, Pin.IN, Pin.PULL_UP) - -while True: - # the unpressed button.value() is normally high (True) - if button.value(): - led.off() - # when the button is pressed, value of the button is low (0) False we turn the LED on - else: - led.on() - diff --git a/src/YD-RP2040/25-modes.py b/src/YD-RP2040/25-modes.py deleted file mode 100644 index d470e6527..000000000 --- a/src/YD-RP2040/25-modes.py +++ /dev/null @@ -1,220 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 8 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# The YP-RP2040 board defines these pins -BUTTON_PIN = 24 -BUILTIN_LED_PIN = 25 - -builtin_led = machine.Pin(BUILTIN_LED_PIN, Pin.OUT) - - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 64, 16, 4, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def rainbow_cycle(counter, wait): - for i in range(NUMBER_PIXELS): - color = i * int(255/NUMBER_PIXELS) - strip[i] = wheel((color + counter*10) & 255) - strip.write() - sleep(wait) - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, level_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle(delay): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -def random_color(delay): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, wait): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -base_delay = 0.1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - rainbow_cycle(counter, base_delay) - elif mode == 1: - move_dot(counter, red, base_delay) - elif mode == 2: - move_dot(counter, green, base_delay) - elif mode == 3: - move_dot(counter, blue, base_delay) - elif mode == 4: - comet_tail(counter, red, base_delay) - elif mode == 5: - comet_tail(counter, green, base_delay) - elif mode == 6: - comet_tail(counter, blue, base_delay) - elif mode == 7: - candle(base_delay) - elif mode == 8: - random_color(base_delay) - elif mode == 9: - bounce(counter, red, base_delay) - elif mode == 10: - running_lights(counter, blue, 3, base_delay*2) - elif mode == 11: - rainbow_cycle(counter, base_delay) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS \ No newline at end of file diff --git a/src/advanced/analog-read.py b/src/advanced/analog-read.py deleted file mode 100644 index 27973b323..000000000 --- a/src/advanced/analog-read.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copied from awonak https://gist.github.com/awonak/aa49c9ac2f339a4e62fbf4beeb50546d -# good example of bit shifting to get rid of the 4 least significant bits - -from machine import Pin, ADC, PWM -from utime import sleep_ms, ticks_add, ticks_diff -from math import sqrt -import time - - -#DROP_LEAST_SIG_BITS = False -#SMPS_MODE = False -##StdDev: StdDev: 150.8483 Spread: 656 - -#DROP_LEAST_SIG_BITS = True -#SMPS_MODE = False -##StdDev: 136.7275 Spread: 672 - -#DROP_LEAST_SIG_BITS = False -#SMPS_MODE = True -##StdDev: 37.1131 Spread: 208 - -#DROP_LEAST_SIG_BITS = True -#SMPS_MODE = True -##StdDev: 38.12705 Spread: 208 - - -a0 = ADC(28) -g23 = Pin(23, Pin.OUT) - -if SMPS_MODE: - g23.value(1) -else: - g23.value(0) - -_shift = 4 - -samples = [a0.read_u16()] * 100 -_min = 65535 -_max = 0 - - -def stdev(samples): - mean = sum(samples) / len(samples) - dev = [(x-mean) ** 2 for x in samples] - return sqrt(sum(dev) / len(samples)) - - -deadline = ticks_add(time.ticks_ms(), 1000*30) - -while ticks_diff(deadline, time.ticks_ms()) > 0: - r = a0.read_u16() - if DROP_LEAST_SIG_BITS: - r = (r >> _shift) << _shift - samples.append(r) - del samples[0] - d = stdev(samples) - _min = min(r, _min) - _max = max(r, _max) - s = (_max - _min) - print("A0: {}\tStdDev: {}\t Spread: {}".format(r, d, s)) - sleep_ms(50) diff --git a/src/advanced/file-system.py b/src/advanced/file-system.py deleted file mode 100644 index 0c77dbee7..000000000 --- a/src/advanced/file-system.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -Print the statistics from the virtual file system (vfs) - -https://docs.micropython.org/en/latest/library/os.html?highlight=os#os.statvfs - -0 f_bsize – file system block size -1 f_frsize – fragment size -2 f_blocks – size of fs in f_frsize units -3 f_bfree – number of free blocks -4 f_bavail – number of free blocks for unprivileged users -5 f_files – number of inodes -6 f_ffree – number of free inodes -7 f_favail – number of free inodes for unprivileged users -8 f_flag – mount flags -9 f_namemax – maximum filename length -""" - -import os - -stats = os.statvfs("/") -print(stats) - -block_size = stats[0] -fragment_size = stats[1] -total_blocks = stats[2] -free_blocks = stats[3] -available_blocks = stats[4] -# these return null -total_inodes = stats[5] -free_inodes = stats[6] -available_inodes = stats[7] -mount_flags = stats[8] -# this seems valid -max_filename_length = stats[9] - -total_size = total_blocks * fragment_size -free_size = free_blocks * fragment_size -available_size = available_blocks * fragment_size - -print("File system block size: {:,} bytes".format(block_size)) -print("Fragment size: {:,} bytes".format(fragment_size)) -print("Size of entire file system in fragment size units: {:,}".format(total_blocks)) -print("Free blocks: {:,}".format(free_blocks)) -print("Available blocks: {:,}".format(available_blocks)) -print("Total size: {:,} bytes".format(total_size)) -print("Number of free blocks for unprivileged users: {:,} bytes".format(available_size)) -print("Total inodes: {:,}".format(total_inodes)) -print("Free inodes: {:,}".format(free_inodes)) -print("Available inodes: {:,}".format(available_inodes)) -print("Mount flags: {:,}".format(mount_flags)) -print("Max filename length: {:,}".format(max_filename_length)) - -""" -Pico Output: - -(4096, 4096, 352, 348, 348, 0, 0, 0, 0, 255) -File system block size: 4,096 bytes -Fragment size: 4,096 bytes -Size of entire file system in fragment units: 352 -Free blocks: 348 -Available blocks: 348 -Total size: 1,441,792 bytes -Free size: 1,425,408 bytes -Number of free blocks for unprivileged users: 1,425,408 bytes -Total inodes: 0 -Free inodes: 0 -Available inodes: 0 -Mount flags: 0 -Max filename length: 255 -""" \ No newline at end of file diff --git a/src/advanced/flash-size.py b/src/advanced/flash-size.py deleted file mode 100644 index 493696ae6..000000000 --- a/src/advanced/flash-size.py +++ /dev/null @@ -1,20 +0,0 @@ -import os - -stat = os.statvfs("/") -size = stat[1] * stat[2] -free = stat[0] * stat[3] -used = size - free - -KB = 1024 -MB = 1024 * 1024 - -print("Size : {:,} bytes, {:,} KB, {} MB".format(size, size / KB, size / MB)) -print("Used : {:,} bytes, {:,} KB, {} MB".format(used, used / KB, used / MB)) -print("Free : {:,} bytes, {:,} KB, {} MB".format(free, free / KB, free / MB)) - -if size > 8 * MB : board, flash = "Unknown", 16 * MB -elif size > 4 * MB : board, flash = "Unknown", 8 * MB -elif size > 2 * MB : board, flash = "Unknown", 4 * MB -elif size > 1 * MB : board, flash = "Pico", 2 * MB -else : board, flash = "Pico W", 2 * MB -print("{} board with {} MB Flash".format(board, flash // MB)) \ No newline at end of file diff --git a/src/advanced/memory-dump.py b/src/advanced/memory-dump.py deleted file mode 100644 index 2368b7db1..000000000 --- a/src/advanced/memory-dump.py +++ /dev/null @@ -1,2 +0,0 @@ -h='MhhhBDhhBTTBDhTBDBBBh===DBDh====B=BBBBBBTB=BTB=BBBTB=TBTB=Bh==' -print(len(h)) \ No newline at end of file diff --git a/src/advanced/real-time-clock.py b/src/advanced/real-time-clock.py deleted file mode 100644 index 7ddd57652..000000000 --- a/src/advanced/real-time-clock.py +++ /dev/null @@ -1,77 +0,0 @@ -# from NikoKun -# https://www.reddit.com/r/raspberrypipico/comments/11r9yck/raspberry_pi_pico_micropython_is_missing_several/ -import ntptime, network -from machine import RTC -from utime import sleep_ms, time, localtime, mktime -import secrets - -timeZone = -6 -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 5 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - #wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(secrets.SSID, secrets.PASS) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -def setRTCtime(): - timeset = False - timetries = 0 - while not timeset and timetries < 5: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print('NTP update attempt #',timetries,'of 5 failed, retrying in 5 seconds..' if timetries < 5 else 'failed! Check connection/config.') - if timetries < 5: sleep_ms(5000) - if timeset: - sleep_ms(100) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'AM' if dtime[4] < 12 else 'PM') - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - print('Time set to:',timestr,datestr) - return True - print('Unable to update time.') - return False - - -def update(): - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTCtime() - sleep_ms(100) - wifi.disconnect() # If wifi is needed later, - wifi.active(False) # comment these line out. - if success: return True - return False - -if __name__ == '__main__': - update() \ No newline at end of file diff --git a/src/advanced/spectrum-analyzer/01-snd-test.py b/src/advanced/spectrum-analyzer/01-snd-test.py deleted file mode 100644 index bd106f7be..000000000 --- a/src/advanced/spectrum-analyzer/01-snd-test.py +++ /dev/null @@ -1,46 +0,0 @@ -import machine -import utime -from machine import Pin, ADC, SPI -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for GPIO26 (ADC0) -adc = ADC(Pin(26)) - -def plot_signal(): - display.fill(0) # Clear the display - old_x = 0 - old_y = HEIGHT // 2 - - # For simplicity, we're plotting every other pixel - for x in range(0, WIDTH, 2): - # Read from ADC (values will be from 0 to 4095) - val = adc.read_u16() - # Scale the ADC value to fit the OLED height - y = int((val / 65535) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - # Draw a line from the last point to the new point - display.line(old_x, old_y, x, y, 1) - old_x, old_y = x, y - - display.show() # Update the display with the new data - -while True: - plot_signal() - utime.sleep(0.1) # Small delay to reduce flickering - diff --git a/src/advanced/spectrum-analyzer/02-pot-gain.py b/src/advanced/spectrum-analyzer/02-pot-gain.py deleted file mode 100644 index 69e6f1b23..000000000 --- a/src/advanced/spectrum-analyzer/02-pot-gain.py +++ /dev/null @@ -1,53 +0,0 @@ -import machine -import utime -from machine import Pin, ADC, SPI -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for sound input (GPIO26) and gain control (GPIO27) -sound = ADC(Pin(26)) -gain = ADC(Pin(27)) - -def plot_signal_with_gain(): - display.fill(0) # Clear the display - old_x = 0 - old_y = HEIGHT // 2 - - # Read gain control (potentiometer) value - gain_value = gain.read_u16() + 1 # Adding 1 to avoid division by zero - - for x in range(0, WIDTH, 2): - # Read from ADC (sound input) - val = sound.read_u16() - - # Adjust the sound value based on the gain - # Note: This scaling might need adjustment depending on your specific potentiometer and desired sensitivity - adjusted_val = min(((val * gain_value) >> 16), 65535) # Ensure the adjusted value does not exceed ADC's max value - - # Scale the adjusted value to fit the OLED height - y = int((adjusted_val / 65535) * HEIGHT) - # Invert y to plot correctly on the OLED - y = HEIGHT - y - # Draw a line from the last point to the new point - display.line(old_x, old_y, x, y, 1) - old_x, old_y = x, y - - display.show() # Update the display with the new data - -while True: - plot_signal_with_gain() - utime.sleep(0.1) # Small delay to reduce flickering diff --git a/src/advanced/spectrum-analyzer/23-average-plot.py b/src/advanced/spectrum-analyzer/23-average-plot.py deleted file mode 100644 index 1b1e976fa..000000000 --- a/src/advanced/spectrum-analyzer/23-average-plot.py +++ /dev/null @@ -1,62 +0,0 @@ -import machine -import utime -from machine import Pin, ADC, SPI -# https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html -import ssd1306 - -# OLED display width and height -WIDTH = 128 -HEIGHT = 64 - -# SPI pins for OLED -clock = Pin(2) # SCL -data = Pin(3) # SDA -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -# Initialize SPI and OLED Display -spi = SPI(0, sck=clock, mosi=data) -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Initialize ADC for GPIO26 (ADC0) -adc = ADC(Pin(26)) - - - -def plot_signal(new_val, min): - # Scroll the display content to the left by one pixel - display.scroll(-1, 0) - y = HEIGHT - new_val//4 - if y > HEIGHT: - y = HEIGHT - if y < 0: - y = 0 - - for clear_y in range(HEIGHT): - display.pixel(WIDTH - 2, y, 1) - - # Update the display with the new data - # display.fill_rect(0, 54, 100, 63, 0) - # display.text(str(min), 0, 54, 1) - # display.text(str(new_val), 0, 54, 1) - display.show() - -min = 53000 -avg = 50 -display.fill(0) -while True: - - # add up the ave number of points - val=0 - for i in range(0,avg): - val += (adc.read_u16() - min) - avg_val = val//avg - - # if the average val is negative, lower the minimum by that amoun - if avg_val < 0: - min += avg_val - - plot_signal(avg_val, min) - # utime.sleep(0.1) # Small delay to reduce flickering - diff --git a/src/advanced/tinyml.py b/src/advanced/tinyml.py deleted file mode 100644 index 7eabe0893..000000000 --- a/src/advanced/tinyml.py +++ /dev/null @@ -1,325 +0,0 @@ - -## MicroPython implementation of Multi-layer Perceptron (MLP) -## Artificial Neural network-Fully connected Dense layer -## Trained hyperparameters are collected from tensorflow-keras -# and fed to our Neural network for testing and prediction -## Version:1.0.1 -## Date 14/06/2022 - -def zeros1d(x): # 1d zero matrix - z = [0 for i in range(len(x))] - return z - - -def add1d(x, y): - if len(x) != len(y): - print("Dimension mismatch") - exit() - else: - z = [x[i] + y[i] for i in range(len(x))] - return z - - -def relu(x): # Relu activation function - # print(x) - y = [] - for i in range(len(x)): - if x[i] >= 0: - y.append(x[i]) - else: - y.append(0) - - # print(y) - return y - - -##Sigmoid function -def sigmoid(x): - import math - z = [1 / (1 + math.exp(-x[kk])) for kk in range(len(x))] - return z - - -def dot(A, B): - """ - Returns the product of the matrix A * B where A is m by n and B is n by 1 matrix - :param A: The first matrix - ORDER MATTERS! - :param B: The second matrix - :return: The product of the two matrices - """ - # Section 1: Ensure A & B dimensions are correct for multiplication - rowsA = len(A) - colsA = len(A[0]) - rowsB = len(B) - colsB = 1 - if colsA != rowsB: - raise ArithmeticError('Number of A columns must equal number of B rows.') - - # Section 2: Store matrix multiplication in a new matrix - C = zeros(rowsA, colsB) - for i in range(rowsA): - total = 0 - for ii in range(colsA): - total += A[i][ii] * B[ii] - C[i] = total - - return C - - -def zeros(rows, cols): - """ - Creates a matrix filled with zeros. - :param rows: the number of rows the matrix should have - :param cols: the number of columns the matrix should have - :return: list of lists that form the matrix - """ - M = [] - while len(M) < rows: - M.append([]) - while len(M[-1]) < cols: - M[-1].append(0.0) - - return M - - -def transpose(M): - """ - Returns a transpose of a matrix. - :param M: The matrix to be transposed - :return: The transpose of the given matrix - """ - # Section 1: if a 1D array, convert to a 2D array = matrix - if not isinstance(M[0], list): - M = [M] - - # Section 2: Get dimensions - rows = len(M) - cols = len(M[0]) - - # Section 3: MT is zeros matrix with transposed dimensions - MT = zeros(cols, rows) - - # Section 4: Copy values from M to it's transpose MT - for i in range(rows): - for j in range(cols): - MT[j][i] = M[i][j] - - return MT - - -##Sigmoid function - -def neuron(x, w, b, activation): # perform operation on a single neuron and return a 1d array - - tmp = zeros1d(x[0]) - - for i in range(len(x)): - tmp = add1d(tmp, [(float(w[i]) * float(x[i][j])) for j in range(len(x[0]))]) - - if activation == "sigmoid": - yp = sigmoid([tmp[i] + b for i in range(len(tmp))]) - elif activation == "relu": - yp = relu([tmp[i] + b for i in range(len(tmp))]) - else: - print("Invalid activation function--->") - - return yp - - -def dense(nunit, x, w, b, activation): # define a single dense layer followed by activation - res = [] - for i in range(nunit): - z = neuron(x, w[i], b[i], activation) - # print(z) - res.append(z) - return res - -def print_matrix(M, decimals=3): - """ - Print a matrix one row at a time - :param M: The matrix to be printed - """ - for row in M: - print([round(x, decimals) + 0 for x in row]) - -def classification_report(ytrue, ypred): # print prediction results in terms of metrics and confusion matrix - tmp = 0 - TP = 0 - TN = 0 - FP = 0 - FN = 0 - for i in range(len(ytrue)): - if ytrue[i] == ypred[i]: # For accuracy calculation - tmp += 1 - ##True positive and negative count - if ytrue[i] == 1 and ypred[i] == 1: # find true positive - TP += 1 - if ytrue[i] == 0 and ypred[i] == 0: # find true negative - TN += 1 - if ytrue[i] == 0 and ypred[i] == 1: # find false positive - FP += 1 - if ytrue[i] == 1 and ypred[i] == 0: # find false negative - FN += 1 - accuracy = tmp / len(ytrue) - conf_matrix = [[TN, FP], [FN, TP]] - #print(TP, FP, FN, TN) - - print("Accuracy: " + str(accuracy)) - print("Confusion Matrix:") - print(print_matrix(conf_matrix)) -## Test function - -# Build a Dense layer -# Structure: Input layer 4 neuron with 8 feature, Relu activation -# 1st hidden layer: 2 neuron with 4 input each, Relu activation -# output layer: 1 neuron with 2 input, Sigmoid activation -w1 = [[-0.0921422 , -0.02542371, 0.30698848, -0.25456974], - [-0.50550294, -1.0066229 , 0.9122949 , -0.26058084], - [ 0.51205075, 0.43376786, -0.07458406, -0.37492675], - [-0.6911025 , 0.6660218 , -0.0747927 , -0.18643615], - [ 0.30719382, 0.519332 , 0.52301043, -0.15813994], - [-0.1978444 , -0.0485612 , 0.60282296, -1.2380371 ], - [-0.260084 , -0.00271817, 0.7422599 , 0.00921784], - [-1.2720652 , -0.08174618, -0.15088758, 0.68464226]] -b1 = [ 0.03986932, 0.7178214 , 0.10937195, -0.07356258] -w2 = [[ 1.000371 , 1.5499793 ], - [-2.840075 , 0.2513094 ], - [ 0.07223273, -0.5448719 ], - [ 0.25136417, 0.60296375]] -b2 = [0.4844855 , 0.61291546] -w3 = [[1.1305474],[-1.3455248]] -b3 = [0.91277504] -#Transpose all weight matrix -w1 = transpose(w1) -w2 = transpose(w2) -w3 = transpose(w3) -# Test data -Xtest = [[-8.44885053e-01, 2.44447821e+00, 3.56431752e-01, - 1.40909441e+00, -6.92890572e-01, 1.38436175e+00, - 2.78492300e+00, -9.56461683e-01], - [-5.47918591e-01, -4.34859164e-01, 2.53036252e-01, - 5.93629620e-01, 1.75399020e-01, 2.04012771e-01, - -2.04994488e-01, -8.71373930e-01], - [4.60143347e-02, -1.40507067e+00, -3.67336746e-01, - -1.28821221e+00, -6.92890572e-01, 2.54780469e-01, - -2.44256030e-01, -7.01198424e-01], - [3.42980797e-01, 1.41167241e+00, 1.49640753e-01, - -9.63790522e-02, 8.26616214e-01, -7.85957342e-01, - 3.47687230e-01, 1.51108316e+00], - [-1.14185152e+00, -3.09670582e-01, -2.12243497e-01, - -1.28821221e+00, -6.92890572e-01, -9.38260437e-01, - 5.68155894e-01, -1.90671905e-01], - [-8.44885053e-01, -1.24858494e+00, 1.49640753e-01, - -1.59107113e-01, -3.45574735e-01, -6.84421946e-01, - -5.70428848e-01, -7.86286177e-01], - [1.53084665e+00, 9.73512376e-01, 4.59827252e-01, - 8.44541864e-01, 7.91884630e-01, 2.80164319e-01, - 1.27184355e+00, -2.04963989e-02], - [-2.50952128e-01, 1.72464386e+00, 8.73409251e-01, - 4.05445437e-01, 6.61641192e-01, 1.65936998e-01, - 2.06009452e+00, 1.59617091e+00], - [-5.47918591e-01, 1.91083743e-01, -5.74127746e-01, - 2.17261253e-01, 1.69490581e+00, -5.44810776e-01, - 3.40706745e+00, -7.01198424e-01], - [6.39947260e-01, -5.60047745e-01, 1.49640753e-01, - 7.19085742e-01, 9.56859653e-01, 7.24381677e-01, - -4.46603982e-01, 1.85143417e+00], - [-2.50952128e-01, 1.16129525e+00, 3.56431752e-01, - 9.69997986e-01, 1.43441893e+00, -4.98257194e-02, - 1.14499856e+00, -4.45935165e-01], - [3.42980797e-01, 2.06891246e+00, 3.56431752e-01, - 4.05445437e-01, 1.10446888e+00, 1.47320522e+00, - 1.69768028e+00, 1.68125866e+00], - [3.42980797e-01, -2.15779146e-01, 2.53036252e-01, - -1.28821221e+00, -6.92890572e-01, -9.00184663e-01, - 8.21845863e-01, 2.02160968e+00], - [-5.47918591e-01, -1.21728780e+00, -8.84314245e-01, - 9.18051311e-02, 3.05642459e-01, -4.43275380e-01, - 3.70605920e+00, -7.01198424e-01], - [1.23388019e+00, -1.74933927e+00, 1.49640753e-01, - 1.54533192e-01, -6.92890572e-01, 9.41978774e-04, - 3.86948773e-01, 7.45293379e-01], - [-1.14185152e+00, -4.03562018e-01, -5.71502470e-02, - -3.36509911e-02, -6.92890572e-01, -5.95578474e-01, - 9.51710966e-01, -1.05584152e-01], - [1.23388019e+00, 1.81853530e+00, 1.49640753e-01, - 1.34636635e+00, 4.35885898e-01, 8.97854505e-02, - 7.46342896e-01, 2.34766861e-01], - [-8.44885053e-01, -1.49896210e+00, -9.87709745e-01, - -6.60931602e-01, -6.92890572e-01, -1.14133123e+00, - -6.76133001e-01, -1.04154944e+00], - [4.60143347e-02, 3.47569469e-01, 8.73409251e-01, - 6.56357681e-01, -6.92890572e-01, -5.06735003e-01, - -1.59692708e-01, 2.53213620e+00], - [3.42980797e-01, -6.85236326e-01, -7.80918745e-01, - 4.68173498e-01, 2.77897893e-02, 2.54780469e-01, - 8.19167867e-02, -2.75759658e-01], - [4.60143347e-02, 7.23135213e-01, 6.66618252e-01, - 7.19085742e-01, -6.92890572e-01, 8.25917074e-01, - 2.48023314e-01, 3.19854614e-01], - [-5.47918591e-01, -9.05905652e-02, 5.63222752e-01, - -1.28821221e+00, -6.92890572e-01, 1.38436175e+00, - 6.67819810e-01, -1.04154944e+00], - [-5.47918591e-01, -1.06080207e+00, -3.57259724e+00, - 1.54533192e-01, -6.92890572e-01, -3.92507682e-01, - 9.09429304e-01, -7.01198424e-01], - [-2.50952128e-01, -1.87452785e+00, 6.66618252e-01, - 4.68173498e-01, -6.92890572e-01, 3.05548168e-01, - -6.91233595e-01, 1.08564439e+00], - [-8.44885053e-01, -7.47830617e-01, -1.60545747e-01, - -3.47291297e-01, 5.22714857e-01, -1.11594738e+00, - 4.56753625e-02, -9.56461683e-01], - [-8.44885053e-01, 9.71923068e-02, -4.70732246e-01, - 7.19085742e-01, -6.92890572e-01, 4.83235111e-01, - 1.27218567e-01, -1.04154944e+00], - [-1.14185152e+00, -5.28750600e-01, 3.56431752e-01, - -1.28821221e+00, -6.92890572e-01, -1.72515976e+00, - 3.32586637e-01, -5.31022918e-01], - [2.71871250e+00, 1.00480952e+00, 9.76804751e-01, - 1.03272605e+00, 5.22714857e-01, 1.09244749e+00, - 2.12049689e+00, 4.90030120e-01], - [-5.47918591e-01, -2.78373437e-01, -1.60545747e-01, - 9.18051311e-02, -6.92890572e-01, -8.87492739e-01, - -4.97945999e-01, -7.86286177e-01], - [3.42980797e-01, -3.40967728e-01, -5.71502470e-02, - -1.28821221e+00, -6.92890572e-01, -7.60573493e-01, - -5.43247780e-01, -2.75759658e-01], - [9.36913723e-01, 4.72758051e-01, 2.53036252e-01, - 3.42717375e-01, 4.79300377e-01, -7.60573493e-01, - 5.28894351e-01, 1.51108316e+00], - [-1.14185152e+00, -5.91344890e-01, -2.63941247e-01, - 1.59727860e+00, -1.56246903e-02, 1.09244749e+00, - 7.28564306e-02, -1.04154944e+00], - [-1.14185152e+00, -5.91344890e-01, 8.73409251e-01, - -2.21835174e-01, 2.18813500e-01, -3.41739984e-01, - 6.73860047e-01, -5.31022918e-01], - [-5.47918591e-01, 3.45980161e-02, -8.84314245e-01, - 1.40909441e+00, 6.79006984e-01, 5.34002809e-01, - 1.03929441e+00, -4.45935165e-01], - [-8.44885053e-01, -5.92934199e-02, -7.80918745e-01, - -4.72747419e-01, -2.58745776e-01, -1.23017470e+00, - -8.05998104e-01, -7.86286177e-01], - [3.42980797e-01, 1.47426670e+00, -2.63941247e-01, - -1.28821221e+00, -6.92890572e-01, 1.15169300e-01, - -1.01740641e+00, 6.60205626e-01], - [2.12477957e+00, 4.72758051e-01, 7.70013751e-01, - 9.07269925e-01, 4.35885898e-01, -4.68659229e-01, - -6.39891577e-01, 7.45293379e-01], - [-5.47918591e-01, -1.21887711e-01, 1.08020025e+00, - -9.63790522e-02, -7.64049618e-02, -8.62108890e-01, - -4.79825287e-01, -1.04154944e+00], - [-8.44885053e-01, -5.92934199e-02, -1.29789624e+00, - 1.66000666e+00, -1.45868129e-01, 4.45159338e-01, - -5.79489204e-01, -7.01198424e-01]] -ytrue = [1,0,0,1,0,0,1,1,0,0,1,1,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0] -print(len(ytrue)) -#Transpose Xtest before feeding to NN -yout1 = dense(4, transpose(Xtest), w1, b1, 'relu') #input layer with 4 neuron -yout2 = dense(2, yout1, w2, b2, 'relu') #hidden layer with 2 neuron -ypred = dense(1, yout2, w3, b3,'sigmoid') #output layer -print(ypred) -ypred_class = [1 if i > 0.5 else 0 for i in ypred[0]] -print(ypred_class) -print(classification_report(ytrue,ypred_class)) - -# view rawann_micropython.py hosted with ❤ by GitHub \ No newline at end of file diff --git a/src/character-lcd/i2c_lcd.py b/src/character-lcd/i2c_lcd.py deleted file mode 100644 index 1342882be..000000000 --- a/src/character-lcd/i2c_lcd.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# This is a port of https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight -# (c) 2017 Alex Bucknall - -from machine import I2C -import i2c_lcd_backlight -import i2c_lcd_screen - -class Display(object): - backlight = None - screen = None - - i2c = I2C(0, I2C.MASTER) - - def __init__(self, i2c, lcd_addr=0x3e, rgb_addr=0x62): - self.backlight = i2c_lcd_backlight.Backlight(i2c, rgb_addr) - self.screen = i2c_lcd_screen.Screen(i2c, lcd_addr) - - def write(self, text): - self.screen.write(text) - - def cursor(self, state): - self.screen.cursor(state) - - def blink(self, state): - self.screen.blink(state) - - def blinkLed(self): - self.backlight.blinkLed() - - def autoscroll(self, state): - self.screen.autoscroll(state) - - def display(self, state): - self.screen.display(state) - - def clear(self): - self.screen.clear() - - def home(self): - self.screen.home() - - def color(self, r, g, b): - self.backlight.set_color(r, g, b) - - def move(self, col, row): - self.screen.setCursor(col, row) diff --git a/src/character-lcd/i2clcd.py b/src/character-lcd/i2clcd.py deleted file mode 100644 index 328f3e829..000000000 --- a/src/character-lcd/i2clcd.py +++ /dev/null @@ -1,210 +0,0 @@ -""" -LCD1602/2002/2004 I2C adapter driver for Raspberry Pi or other devices - -Copyright (C) 2019 SiYu Wu . All Rights Reserved. - -""" - -__author__ = 'SiYu Wu ' - -import smbus -import time - -name = 'i2clcd' - -# Note for developers -# -# I2C byte: [H ------------------------ L] -# [ data ] [ ctrl_bits ] -# PCA8574: P7 P6 P5 P4 P3 P2 P1 P0 -# LCD1602: D7 D6 D5 D4 BT E R/W RS - -# Define some device constants -LCD_DAT = 0x01 # Mode - Sending data -LCD_CMD = 0x00 # Mode - Sending command - -# LINE_1 = 0x80 # LCD RAM address for the 1st line -# LINE_2 = 0xC0 # LCD RAM address for the 2nd line -# LINE_3 = 0x94 # LCD RAM address for the 3rd line -# LINE_4 = 0xD4 # LCD RAM address for the 4th line -LCD_LINES = (0x80, 0xC0, 0x94, 0xD4) - -# Character code for custom characters in CGRAM -CGRAM_CHR = (b'\x00', b'\x01', b'\x02', b'\x03', b'\x04', b'\x05', b'\x06', b'\x07') - - -class i2clcd(): - def __init__(self, i2c_bus=1, i2c_addr=0x27, lcd_width=16): - """ - initialize the connection with the LCD - - i2c_bus: the smbus where the LCD connected to, - for Raspberry Pi, it should be 1 or 0 (depending on the model) - i2c_addr: I2C address of the adapter, usually 0x27, 0x20 or 0x3f - lcd_width: the width of the LCD, e.g. 16 for LCD1602, 20 for LCD2002/2004 - """ - self._bus = smbus.SMBus(i2c_bus) - self._i2c_addr = i2c_addr - self._lcd_width = lcd_width - - self._backlight = True - self._last_data = 0x00 - - def _i2c_write(self, data): - """write one byte to I2C bus""" - self._last_data = data - self._bus.write_byte(self._i2c_addr, data) - - def _pluse_en(self): - """proform a high level pulse to EN""" - - time.sleep(0) - self._i2c_write(self._last_data | 0b00000100) - time.sleep(0) - self._i2c_write(self._last_data & ~0b00000100) - time.sleep(0) - - def write_byte(self, data, mode): - """write one byte to LCD""" - - data_H = (data & 0xF0) | self._backlight * 0x08 | mode - data_L = ((data << 4) & 0xF0) | self._backlight * 0x08 | mode - - self._i2c_write(data_H) - self._pluse_en() - - self._i2c_write(data_L) - self._pluse_en() - - time.sleep(0.0001) - - def init(self): - """ - Initialize the LCD - """ - - # setting LCD data interface to 4 bit - self._i2c_write(0x30) - self._pluse_en() - time.sleep(0.0041) - self._i2c_write(0x30) - self._pluse_en() - time.sleep(0.0001) - self._i2c_write(0x30) - self._pluse_en() - time.sleep(0.0001) - self._i2c_write(0x20) - self._pluse_en() - - self.write_byte(0x28, LCD_CMD) # 00101000 Function set: interface 4bit, 2 lines, 5x8 font - self.write_byte(0x0C, LCD_CMD) # 00001100 Display ON/OFF: display on, cursor off, cursor blink off - self.write_byte(0x06, LCD_CMD) # 00000110 Entry Mode set: cursor move right, display not shift - self.clear() - - def clear(self): - """ - Clear the display and reset the cursor position - """ - self.write_byte(0x01, LCD_CMD) - time.sleep(0.002) - - def set_backlight(self, on_off): - """ - Set whether the LCD backlight is on or off - """ - self._backlight = on_off - i2c_data = (self._last_data & 0xF7) + self._backlight * 0x08 - self._i2c_write(i2c_data) - - def set_cursor(self, cursor_visible, cursor_blink): - """ - Set whether the cursor is visible and whether it will blink - """ - cmd = 0x0C + cursor_visible * 0x02 + cursor_blink * 0x01 - self.write_byte(cmd, LCD_CMD) - - def move_cursor(self, line, column): - """ - Move the cursor to a new posotion - - line: line number starts from 0 - column: column number starts from 0 - """ - cmd = LCD_LINES[line] + column - self.write_byte(cmd, LCD_CMD) - - def shift(self, direction='RIGHT', move_display=False): - """ - Move the cursor and display left or right - - direction: could be 'RIGHT' (default) or 'LEFT' - move_display: move the entire display and cursor, or only move the cursor - """ - direction = 0x04 if direction == 'RIGHT' else 0x00 - cmd = 0x10 + direction + move_display * 0x08 - self.write_byte(cmd, LCD_CMD) - - def return_home(self): - """ - Reset cursor and display to the original position. - """ - self.write_byte(0x02, LCD_CMD) - time.sleep(0.002) - - def write_CGRAM(self, chr_data, CGRAM_solt=0): - """ - Write a custom character to CGRAM - - chr_data: a tuple that stores the character model data - CGRAM_solt: int from 0 to 7 to determine where the font data is written - - NOTICE: re-setting the cursor position after calling this method, e.g. - - lcd.write_CGRAM((0x10, 0x06, 0x09, 0x08, 0x08, 0x09, 0x06, 0x00), 2) - lcd.move_cursor(1, 0) - lcd.print(b'New char: ' + i2clcd.CGRAM_CHR[2]) - """ - cmd = 0x40 + CGRAM_solt * 8 - self.write_byte(cmd, LCD_CMD) - - for dat in chr_data: - self.write_byte(dat, LCD_DAT) - - def print(self, text): - """ - Print a string at the current cursor position - - text: bytes or str object, str object will be encoded with ASCII - """ - if isinstance(text, str): - text = text.encode('ascii') - - for b in text: - self.write_byte(b, LCD_DAT) - - def print_line(self, text, line, align='LEFT'): - """ - Fill a whole line of the LCD with a string - - text: bytes or str object, str object will be encoded with ASCII - line: line number starts from 0 - align: could be 'LEFT' (default), 'RIGHT' or 'CENTER' - """ - - if isinstance(text, str): - text = text.encode('ascii') - - text_length = len(text) - if text_length < self._lcd_width: - blank_space = self._lcd_width - text_length - if align == 'LEFT': - text = text + b' ' * blank_space - elif align == 'RIGHT': - text = b' ' * blank_space + text - else: - text = b' ' * (blank_space // 2) + text + b' ' * (blank_space - blank_space // 2) - else: - text = text[:self._lcd_width] - - self.write_byte(LCD_LINES[line], LCD_CMD) - self.print(text) diff --git a/src/character-lcd/test-char-move.py b/src/character-lcd/test-char-move.py deleted file mode 100644 index f41727a26..000000000 --- a/src/character-lcd/test-char-move.py +++ /dev/null @@ -1,21 +0,0 @@ -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd -from utime import sleep - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -i2c = I2C(0, sda=machine.Pin(16), scl=machine.Pin(17), freq=400000) -lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) - -while True: - lcd.clear() - lcd.move_to(0, 0) - lcd.putstr("CoderDojo Rocks!") - sleep(1) - lcd.clear() - lcd.move_to(0, 1) - lcd.putstr("CoderDojo Rocks!") - sleep(1) \ No newline at end of file diff --git a/src/displays/8x8-led-matrix/display-counter.py b/src/displays/8x8-led-matrix/display-counter.py deleted file mode 100644 index c7cc2359b..000000000 --- a/src/displays/8x8-led-matrix/display-counter.py +++ /dev/null @@ -1,22 +0,0 @@ -from machine import SPI, Pin -import max7219 -from utime import sleep -CLOCK_PIN = 2 -DATA_PIN = 3 -CS_PIN = 4 -spi=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN)) - -cs = Pin(CS_PIN, Pin.OUT) - -display = max7219.Matrix8x8(spi, cs , 4) - -counter = 0 -while True: - # right justify in a field of 4 spaces - print('{:>4}'.format(counter)) - # string, x, y, ? - display.text('{:>4}'.format(counter),0,1,1) - display.show() - sleep(.2) - display.fill(0) - counter += 1 diff --git a/src/displays/8x8-led-matrix/display-test.py b/src/displays/8x8-led-matrix/display-test.py deleted file mode 100644 index 4035b10a4..000000000 --- a/src/displays/8x8-led-matrix/display-test.py +++ /dev/null @@ -1,13 +0,0 @@ -from machine import SPI, Pin -import max7219 -from utime import sleep -CLOCK_PIN = 2 -DATA_PIN = 3 -CS_PIN = 4 -spi=SPI(0,baudrate=10000000, polarity=1, phase=0, sck=Pin(CLOCK_PIN), mosi=Pin(DATA_PIN)) - -cs = Pin(CS_PIN, Pin.OUT) - -display = max7219.Matrix8x8(spi, cs , 4) -display.text('1234',0,0,1) -display.show() \ No newline at end of file diff --git a/src/displays/coderdojo-logo-64x64.py b/src/displays/coderdojo-logo-64x64.py deleted file mode 100644 index 3963a6840..000000000 --- a/src/displays/coderdojo-logo-64x64.py +++ /dev/null @@ -1,37 +0,0 @@ -from machine import Pin, Timer -import ssd1306 -import time -import framebuf - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -fb = framebuf.FrameBuffer(bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), - 64, 64, framebuf.MONO_VLSB) - -oled.fill(0) -oled.blit(fb, 64, 0) -oled.show() \ No newline at end of file diff --git a/src/displays/display-coderdojo-logo-64x64.py b/src/displays/display-coderdojo-logo-64x64.py deleted file mode 100644 index 4314aec33..000000000 --- a/src/displays/display-coderdojo-logo-64x64.py +++ /dev/null @@ -1,44 +0,0 @@ -from machine import Pin, Timer -import machine -import ssd1306 -import time -import framebuf - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') - -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -while True: - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text('CoderDojo', 0, 0) - oled.text('Robots', 0, 10) - oled.text('Standby', 0, 54) - oled.show() diff --git a/src/displays/display-coderdojo-logo.py b/src/displays/display-coderdojo-logo.py deleted file mode 100644 index 927dc8c1a..000000000 --- a/src/displays/display-coderdojo-logo.py +++ /dev/null @@ -1,71 +0,0 @@ -# This code displays pi image & text on I2C OLED display, then repeats forever. -# Also print out the OLED's I2C address on serial at program start. -# --- -# Connection: SCL = GP1, SDA = GP0 -# --- -# Hardware: -# 1. Cytron Maker Pi RP2040 (www.cytron.io/p-MAKER-PI-RP2040) -# - Any RP2040 boards should work too. -# 2. Grove OLED Display 0.96 inch (www.cytron.io/p-grove-oled-display-0p96-inch-ssd1315) -# --- -from machine import Pin, I2C -import framebuf -import utime -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -# Raspberry Pi logo as 32x32 bytearray -# pi_logo = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - -# 32X32 = 1024, 1024 / 8 = 128 bytes -# print(len(pi_logo)) - -# coderdojo_logo = bytearray(b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD\xFD\xFE\x0E\xE6\xF6\xF6\x06\xFC\xFD\xF9\xF1\xC3\x03\x07\x0F\x1F\x3F\x7F\xFF\xFF\xFF\x0F\xF9\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF9\xFB\xFB\xFC\x7F\x7F\x3F\x1F\x07\x00\x00\x00\x00\x00\x00\x00\x07\xFF\xF0\xDF\x7F\xFF\xFF\xFF\xFF\xFF\x1F\x07\x03\x01\x01\x00\x10\x10\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xE0\xFF\xFF\xFF\xFF\xFD\xFB\xF7\xEF\xEF\xDC\xF0\xA0\x80\x80\x00\x08\x08\x0F\x08\x8E\x80\x80\xC0\xC0\xC0\xE0\xF0\xF8\xFC\xFE\xFF\xFF\xFF") - -my_bytearray = (b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD\xFD\xFE\x0E\xE6\xF6\xF6\x06\xFC\xFD\xF9\xF1\xC3\x03\x07\x0F\x1F\x3F\x7F\xFF\xFF\xFF\x0F\xF9\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF9\xFB\xFB\xFC\x7F\x7F\x3F\x1F\x07\x00\x00\x00\x00\x00\x00\x00\x07\xFF\xF0\xDF\x7F\xFF\xFF\xFF\xFF\xFF\x1F\x07\x03\x01\x01\x00\x10\x10\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xE0\xFF\xFF\xFF\xFF\xFD\xFB\xF7\xEF\xEF\xDC\xF0\xA0\x80\x80\x00\x08\x08\x0F\x08\x8E\x80\x80\xC0\xC0\xC0\xE0\xF0\xF8\xFC\xFE\xFF\xFF\xFF") - -coderdojo_logo = bytearray(my_bytearray) -fb_len = len(coderdojo_logo) -inv_fb = [] - -for i in range(0, fb_len): - inv_fb.append(255 - my_bytearray[i]) - -inv_fb = bytearray(inv_fb) - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -# Monochrome Horizontal least significant bit encoding is MONO_HLSB -# https://docs.micropython.org/en/latest/library/framebuf.html#framebuf.framebuf.MONO_VLSB -# fb = framebuf.FrameBuffer(pi_logo, 32, 32, framebuf.MONO_HLSB) -fb2 = framebuf.FrameBuffer(coderdojo_logo, 32, 32, framebuf.MONO_VLSB) -fbi = framebuf.FrameBuffer(inv_fb, 32, 32, framebuf.MONO_VLSB) - -#print(coderdojo_logo) -#print('') -#print(inv_fb) - -oled.fill(0) -# oled.rect(0, 0, 34, 34, 1) -# oled.blit(fb, 1, 1) -# oled.rect(0, 0, 34, 34, 1) -oled.blit(fb2, 1, 1) -# oled.rect(50, 0, 34, 34, 1) -oled.blit(fbi, 50, 1) -oled.show() - - \ No newline at end of file diff --git a/src/displays/display-rpi-logo-v2.py b/src/displays/display-rpi-logo-v2.py deleted file mode 100644 index 144b08f52..000000000 --- a/src/displays/display-rpi-logo-v2.py +++ /dev/null @@ -1,54 +0,0 @@ -# This code displays pi image & text on I2C OLED display, then repeats forever. -# Also print out the OLED's I2C address on serial at program start. -# --- -# Connection: SCL = GP1, SDA = GP0 -# --- -# Hardware: -# 1. Cytron Maker Pi RP2040 (www.cytron.io/p-MAKER-PI-RP2040) -# - Any RP2040 boards should work too. -# 2. Grove OLED Display 0.96 inch (www.cytron.io/p-grove-oled-display-0p96-inch-ssd1315) -# --- -from machine import Pin, I2C -import framebuf -import utime -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -# Raspberry Pi logo as 32x32 bytearray - -my_bytearray = (b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD\xFD\xFE\x0E\xE6\xF6\xF6\x06\xFC\xFD\xF9\xF1\xC3\x03\x07\x0F\x1F\x3F\x7F\xFF\xFF\xFF\x0F\xF9\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF9\xFB\xFB\xFC\x7F\x7F\x3F\x1F\x07\x00\x00\x00\x00\x00\x00\x00\x07\xFF\xF0\xDF\x7F\xFF\xFF\xFF\xFF\xFF\x1F\x07\x03\x01\x01\x00\x10\x10\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xE0\xFF\xFF\xFF\xFF\xFD\xFB\xF7\xEF\xEF\xDC\xF0\xA0\x80\x80\x00\x08\x08\x0F\x08\x8E\x80\x80\xC0\xC0\xC0\xE0\xF0\xF8\xFC\xFE\xFF\xFF\xFF") - -coderdojo_logo = bytearray(my_bytearray) -fb_len = len(coderdojo_logo) -inv_fb = [] - -for i in range(0, fb_len): - inv_fb.append(255 - my_bytearray[i]) - -inv_fb = bytearray(inv_fb) - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -# Monochrome Horizontal least significant bit encoding is MONO_HLSB -# https://docs.micropython.org/en/latest/library/framebuf.html#framebuf.framebuf.MONO_VLSB -# fb = framebuf.FrameBuffer(pi_logo, 32, 32, framebuf.MONO_HLSB) -fbi = framebuf.FrameBuffer(inv_fb, 32, 32, framebuf.MONO_VLSB) - -oled.fill(0) -oled.blit(fbi, 0, 1) -oled.show() - - \ No newline at end of file diff --git a/src/displays/drawing-library/coderdojo-face.py b/src/displays/drawing-library/coderdojo-face.py deleted file mode 100644 index 518261965..000000000 --- a/src/displays/drawing-library/coderdojo-face.py +++ /dev/null @@ -1,48 +0,0 @@ -import machine -from utime import sleep -from math import sqrt -from ssd1306 import SSD1306_I2C -OLED_RESET = machine.Pin(15, machine.Pin.OUT) -OLED_RESET.low() -sleep(.1) -OLED_RESET.high() -i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1)) - -oled = SSD1306_I2C(128, 64, i2c) - -def draw_circle(cx, cy, r, color): - print('cx=', cx, ' cy=', cy, ' r=', r, sep='') - diameter = r*2 - oled.pixel(cx, cy, 1) - # outline the circile - #oled.rect(cx-r, cy-r, r*2, r*2, 1) - upper_left_x = cx - r - upper_left_y = cy - r - - print('ul-x=', upper_left_x, ' ul-y=', upper_left_y, ' d=', diameter, sep='') - - # scan through all pixels and only turn on pixels within r of the center - for i in range(upper_left_x, upper_left_x + diameter): - for j in range(upper_left_y, upper_left_y + diameter): - # distance of the current point (i, j) from the center (cx, cy) - d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 ) - fill = 0 - if d < r: - oled.pixel(i, j, color) - fill = 1 - # print(i, j, d, fill) - -oled.text('CoderDojo Rocks!', 0, 0, 1) - -# left eye -draw_circle(40, 30, 15, 1) -draw_circle(40, 30, 5, 0) -# right eye -draw_circle(80, 30, 15, 1) -draw_circle(80, 30, 5, 0) - -oled.fill_rect(35, 50, 10, 5, 1) -oled.fill_rect(75, 50, 10, 5, 1) -oled.fill_rect(40, 55, 40, 5, 1) - -oled.show() \ No newline at end of file diff --git a/src/displays/drawing-library/draw-circle.py b/src/displays/drawing-library/draw-circle.py deleted file mode 100644 index 4cef11ad7..000000000 --- a/src/displays/drawing-library/draw-circle.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin -from utime import sleep -from math import sqrt -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def circle(cx, cy, r, color): - diameter = r*2 - upper_left_x = cx - r - upper_left_y = cy - r - # scan through all pixels and only turn on pixels within r of the center - for i in range(upper_left_x, upper_left_x + diameter): - for j in range(upper_left_y, upper_left_y + diameter): - # distance of the current point (i, j) from the center (cx, cy) - d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 ) - if d < r: - oled.pixel(i, j, color) - -HALF_WIDTH = int(WIDTH/2) -HALF_HEIGHT = int(HEIGHT/2) -while True: - for rad in range(1,HALF_HEIGHT+2): - circle(HALF_WIDTH, HALF_HEIGHT, rad, 1) - oled.show() - sleep(.1) - sleep(3) - oled.fill(1) - for rad in range(1,HALF_HEIGHT+2): - circle(HALF_WIDTH, HALF_HEIGHT, rad, 0) - oled.show() - sleep(.1) - oled.fill(0) - sleep(3) \ No newline at end of file diff --git a/src/displays/drawing-library/draw-face-01.py b/src/displays/drawing-library/draw-face-01.py deleted file mode 100644 index 3ee35497b..000000000 --- a/src/displays/drawing-library/draw-face-01.py +++ /dev/null @@ -1,74 +0,0 @@ -from machine import Pin -from utime import sleep -from math import sqrt -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# Do these calculations just once cause we have 264K RAM! -HALF_WIDTH = int(WIDTH/2) -QUARTER_WIDTH = int(WIDTH/4) -HALF_HEIGHT = int(HEIGHT/2) -QUARTER_HEIGHT = int(HEIGHT/4) - - - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def fill_circle(cx, cy, r, color): - diameter = r*2 - upper_left_x = cx - r - upper_left_y = cy - r - # scan through all pixels and only turn on pixels within r of the center - for i in range(upper_left_x, upper_left_x + diameter): - for j in range(upper_left_y, upper_left_y + diameter): - # distance of the current point (i, j) from the center (cx, cy) - d = sqrt( (i - cx) ** 2 + (j - cy) ** 2 ) - if d < r: - oled.pixel(i, j, color) - -def fill_ellipse(x, y, a, b, color): - x_min = max(0, int(x - a)) - x_max = min(128, int(x + a + 1)) - y_min = max(0, int(y - b)) - y_max = min(64, int(y + b + 1)) - - for y_pos in range(y_min, y_max): - for x_pos in range(x_min, x_max): - if ((x_pos - x) ** 2 / a ** 2 + (y_pos - y) ** 2 / b ** 2 <= 1): - oled.pixel(x_pos, y_pos, color) - -# EYE PARAMETERS -EYE_WIDTH = int(WIDTH/5) -EYE_PLACEMENT_Y = int(HEIGHT/3) -EYE_HEIGHT = int(HEIGHT/6) -PUPLE_RADIUS = 5 -def draw_eyes(look_offset): - # outline - LEFT_EYE_X = QUARTER_WIDTH - RIGHT_EYE_X = QUARTER_WIDTH*3 - - fill_ellipse(LEFT_EYE_X, EYE_PLACEMENT_Y, EYE_WIDTH, EYE_HEIGHT, 1) - fill_ellipse(RIGHT_EYE_X, EYE_PLACEMENT_Y, EYE_WIDTH, EYE_HEIGHT, 1) - # puples - fill_circle(LEFT_EYE_X+look_offset, EYE_PLACEMENT_Y, PUPLE_RADIUS, 0) - fill_circle(RIGHT_EYE_X+look_offset, EYE_PLACEMENT_Y, PUPLE_RADIUS, 0) - -delay = .000 -while True: - for look_offset in range(-15, 15, 2): - draw_eyes(look_offset) - oled.show() - sleep(delay) - for look_offset in range(15, -15, -2): - draw_eyes(look_offset) - oled.show() - sleep(delay) \ No newline at end of file diff --git a/src/displays/drawing-library/draw-fill-circle.py b/src/displays/drawing-library/draw-fill-circle.py deleted file mode 100644 index 77eb15a65..000000000 --- a/src/displays/drawing-library/draw-fill-circle.py +++ /dev/null @@ -1,55 +0,0 @@ -from machine import Pin -from utime import sleep -import math -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# x and y represent the center of the ellipse -# a represents the semi-major axis, -# and b represents the semi-minor axis. -# The fill_ellipse function checks for each pixel on the screen -# if it falls within the boundaries of the ellipse and -# sets the corresponding pixel on the screen to black if it does. -# The check is done by evaluating the equation of an -# ellipse ((x_pos - x) ** 2 / a ** 2 + (y_pos - y) ** 2 / b ** 2 <= 1). -def fill_circle(x, y, r, color): - if r == 1: - oled.pixel(x, y, color) - else: - # we adjust the distance to keep the small circles rounded - r_squared = r ** 2 - 1.1 - x_min = max(0, int(x - r)) - x_max = min(128, int(x + r + 1)) - y_min = max(0, int(y - r)) - y_max = min(64, int(y + r + 1)) - - for y_pos in range(y_min, y_max): - for x_pos in range(x_min, x_max): - if ((x_pos - x) ** 2 + (y_pos - y) ** 2 <= r_squared): - oled.pixel(x_pos, y_pos, color) - - -for r in range(1, 11): - x = int(r * r + 1 * r) - y = r - fill_circle(x, y, r, 1) - -for r in range(11, 16): - x = int(r * r + 1 * r) - 120 - y = r * 2 + 10 - fill_circle(x, y, r, 1) - -oled.show() diff --git a/src/displays/drawing-library/draw-fill-ellipse.py b/src/displays/drawing-library/draw-fill-ellipse.py deleted file mode 100644 index cc3fd8a82..000000000 --- a/src/displays/drawing-library/draw-fill-ellipse.py +++ /dev/null @@ -1,45 +0,0 @@ -from machine import Pin -from utime import sleep -import math -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# x and y represent the center of the ellipse -# a represents the semi-major axis, -# and b represents the semi-minor axis. -# The fill_ellipse function checks for each pixel on the screen -# if it falls within the boundaries of the ellipse and -# sets the corresponding pixel on the screen to black if it does. -# The check is done by evaluating the equation of an -# ellipse ((x_pos - x) ** 2 / a ** 2 + (y_pos - y) ** 2 / b ** 2 <= 1). -def fill_ellipse(x, y, a, b, color): - x_min = max(0, int(x - a)) - x_max = min(128, int(x + a + 1)) - y_min = max(0, int(y - b)) - y_max = min(64, int(y + b + 1)) - - for y_pos in range(y_min, y_max): - for x_pos in range(x_min, x_max): - if ((x_pos - x) ** 2 / a ** 2 + (y_pos - y) ** 2 / b ** 2 <= 1): - oled.pixel(x_pos, y_pos, color) - -# oled.rect(50-6, 10-6, 12, 12, 1) -fill_ellipse(20, 20, 4, 8, 1) -fill_ellipse(40, 30, 15, 10, 1) -fill_ellipse(70, 40, 5, 8, 1) -fill_ellipse(100, 20, 15, 20, 1) -fill_ellipse(100, 20, 5, 3, 0) -oled.show() diff --git a/src/displays/drawing-library/print-circle-bits.py b/src/displays/drawing-library/print-circle-bits.py deleted file mode 100644 index 2c826c78b..000000000 --- a/src/displays/drawing-library/print-circle-bits.py +++ /dev/null @@ -1,23 +0,0 @@ -from math import sqrt - -def fill_circle_array(r): - r_sq = r**2 + 1 - print('CIRCLE_', r, ' = [', sep='') - # scan through all pixels and only turn on pixels within r of the center - for y in range(-r, r+1): - print('[', end='') - for x in range(-r, r+1): - if x**2 + y**2 <= r_sq: - print('1', end='') - else: - print('0', end='') - if x < r: - print(',', end='') - print(']', end='') - if y < r: - print(',', end='') - print('') - print(']') - -for i in range(0, 20): - fill_circle_array(i) diff --git a/src/displays/drawing-library/time-circle-with-blit.py b/src/displays/drawing-library/time-circle-with-blit.py deleted file mode 100644 index 772238ad9..000000000 --- a/src/displays/drawing-library/time-circle-with-blit.py +++ /dev/null @@ -1,52 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 -import urandom - -WIDTH = 128 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# create an 8X8 array of bits for drawing a circle -CIRCLE = [ - [ 0, 0, 0, 1, 1, 0, 0, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 0, 1, 1, 0, 0, 0], -] - -# convert the bit array into a byte array -circle_bytearray = bytearray() -for row in CIRCLE: - byte = 0 - for bit in row: - byte = (byte << 1) | bit - circle_bytearray.append(byte) - -circle_buf = framebuf.FrameBuffer(circle_bytearray, 8, 8, framebuf.MONO_HLSB) - -oled.fill(0) -start = ticks_us() -oled.blit(circle_buf, 64, 32) -end1 = ticks_us() -oled.show() -end2 = ticks_us() -# Blit time: 168 -# Show time: 2692 -print('Blit time:', end1 - start) -print('Show time:', end2 - start) - diff --git a/src/displays/ili934x/bounce-ball.py b/src/displays/ili934x/bounce-ball.py deleted file mode 100644 index 106afdac0..000000000 --- a/src/displays/ili934x/bounce-ball.py +++ /dev/null @@ -1,61 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep - -WIDTH = 320 -HEIGHT = 240 -ROTATION = 3 # landscape with 0,0 in upper left and pins on left -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.erase() - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, color): - if size == 1: - display.pixel(x, y, color) # draw a single pixel - else: - display.fill_rectangle(x, y, size, size, color) - -ball_size = 20 -# start in the middle of the screen -current_x = int(WIDTH / 2) -current_y = int(HEIGHT / 2) -# start going down to the right -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - draw_ball(current_x,current_y, ball_size, white) - sleep(.1) - draw_ball(current_x,current_y,ball_size, black) - if current_x < 2: - direction_x = 1 - # right edge test - if current_x > WIDTH - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 2: - direction_y = 1 - # bottom edge test - if current_y > HEIGHT - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y diff --git a/src/displays/ili934x/font-tiny-test.py b/src/displays/ili934x/font-tiny-test.py deleted file mode 100644 index 92c2eb895..000000000 --- a/src/displays/ili934x/font-tiny-test.py +++ /dev/null @@ -1,54 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -# use a very small 5x7 font -import glcdfont - -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=320, h=240, r=3) -display.erase() -# use the largest 32-bit font -display.set_font(glcdfont) - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) - -# the default is white on black -display.set_pos(0,0) -display.print('Hello World!') - -display.set_color(red, black) -display.set_pos(0,40) -display.print('Hello World Red!') - -display.set_color(green, black) -display.set_pos(0,80) -display.print('Hello World Green!') - -display.set_color(blue, black) -display.set_pos(0,120) -display.print('Hello World Blue!') - -display.set_color(red, white) -display.set_pos(0,160) -display.print('Red') - -display.set_color(green, white) -display.set_pos(100,160) -display.print('Green') - -display.set_color(blue, white) -display.set_pos(230,160) -display.print('Blue') \ No newline at end of file diff --git a/src/displays/ili934x/hello-world-rgb.py b/src/displays/ili934x/hello-world-rgb.py deleted file mode 100644 index 185dff936..000000000 --- a/src/displays/ili934x/hello-world-rgb.py +++ /dev/null @@ -1,52 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -import tt32 - -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=320, h=240, r=3) -display.erase() -display.set_font(tt32) - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) - -# the default is white on black -display.set_pos(0,0) -display.print('Hello World!') - -display.set_color(red, black) -display.set_pos(0,40) -display.print('Hello World Red!') - -display.set_color(green, black) -display.set_pos(0,80) -display.print('Hello World Green!') - -display.set_color(blue, black) -display.set_pos(0,120) -display.print('Hello World Blue!') - -display.set_color(red, white) -display.set_pos(0,160) -display.print('Red') - -display.set_color(green, white) -display.set_pos(100,160) -display.print('Green') - -display.set_color(blue, white) -display.set_pos(230,160) -display.print('Blue') \ No newline at end of file diff --git a/src/displays/ili934x/hello-world.py b/src/displays/ili934x/hello-world.py deleted file mode 100644 index 223619002..000000000 --- a/src/displays/ili934x/hello-world.py +++ /dev/null @@ -1,21 +0,0 @@ -# print out "Hello World!" using the rotation=3 using 32-bit high font -# the default is white text on a black background -from ili934x import ILI9341 -from machine import Pin, SPI -import tt32 - -# Use these PIN definitions. SCK must be on 2 and data (SDL) on 3 -SCK_PIN = 2 -MOSI_PIN = 3 # labeled SDI(MOSI) on the back of the display -DC_PIN = 4 -RESET_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MOSI_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RESET_PIN), w=320, h=240, r=3) -display.erase() -display.set_font(tt32) -display.set_pos(0,0) -display.print('Hello World!') diff --git a/src/displays/ili934x/list-colors.py b/src/displays/ili934x/list-colors.py deleted file mode 100644 index 64b722826..000000000 --- a/src/displays/ili934x/list-colors.py +++ /dev/null @@ -1,71 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -from random import randint -import tt32 - -WIDTH = 320 -HALF_WIDTH = int(WIDTH/2) -HEIGHT = 240 -HALF_HEIGHT = int(HEIGHT/2) -ROTATION = 3 # landscape with 0,0 in upper left and pins on left -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.set_font(tt32) -display.erase() - -# color defintions convered to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) -yellow = color565(255, 255, 0) -cyan = color565(0, 255, 255) -magenta = color565(255, 0, 255) -gray = color565(128, 128, 128) -light_gray = color565(192, 192, 192) -dark_gray = color565(64, 64, 64) -brown = color565(165, 42, 42) -orange = color565(255, 60, 0) -# 150 for the green and blue wash out the colors -pink = color565(255, 130, 130) -purple = color565(128, 0, 128) -lavender = color565(150, 150, 200) -beige = color565(200, 200, 150) -# by definition, maroon is 50% of the red on, but 128 is way too bright -maroon = color565(105, 0, 0) -olive = color565(128, 128, 0) -turquoise = color565(64, 224, 208) -dark_green = color565(0,100,0) -color_list = [white, red, green, blue, yellow, cyan, magenta, - gray, light_gray, dark_gray, brown, orange, pink, purple, lavender, - beige, maroon, olive, turquoise, dark_green, black] -color_names = ['white (255,255,255)', 'red (255,0,0)', 'green (0,255,0)', 'blue (0,0,255)', 'yellow (255,255,0)', - 'cyan (0,255,255)', 'magenta (255,0,255)', - 'gray (128,128,128)', 'light gray (192,192,192)', 'dark gray (64,64,64)', - 'brown (165,42,42)', 'orange (255,60,0)', 'pink (255,130,130)', 'purple (128,0,128)', - 'lavender (150,150,200)', - 'beige (200,200,150)', 'maroon (105,0,0)', 'olive (128,128,0)', 'turquoise (64,224,208)', - 'dark green (0,100,0)', 'black (0,0,0)'] -color_num = len(color_list) - -display.fill_rectangle(0, 0, WIDTH, HEIGHT, black) -while True: - for i in range(0, color_num): - display.fill_rectangle(0, 0, WIDTH, HEIGHT-33, color_list[i]) - # black behind the white text - display.fill_rectangle(0, HEIGHT-32, WIDTH, 32, black) - - display.set_pos(0,HEIGHT-32) - display.print(color_names[i]) - print(color_names[i]) - sleep(1) diff --git a/src/displays/ili934x/rectangle-fill-test.py b/src/displays/ili934x/rectangle-fill-test.py deleted file mode 100644 index 9774d3226..000000000 --- a/src/displays/ili934x/rectangle-fill-test.py +++ /dev/null @@ -1,62 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -from random import randint - -WIDTH = 320 -HALF_WIDTH = int(WIDTH/2) -HEIGHT = 240 -HALF_HEIGHT = int(HEIGHT/2) -ROTATION = 3 # landscape with 0,0 in upper left and pins on left - -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN), sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=WIDTH, h=HEIGHT, r=ROTATION) -display.erase() - -# color defintions converted to 565 represnetations -black = color565(0, 0, 0) -white = color565(255, 255, 255) -red = color565(255, 0, 0) -green = color565(0, 255, 0) -blue = color565(0, 0, 255) -yellow = color565(255, 255, 0) -cyan = color565(0, 255, 255) -magenta = color565(255, 0, 255) -gray = color565(128, 128, 128) -light_gray = color565(192, 192, 192) -dark_gray = color565(64, 64, 64) -brown = color565(165, 42, 42) -orange = color565(255, 60, 0) -# 150 for the green and blue wash out the colors -pink = color565(255, 130, 130) -purple = color565(128, 0, 128) -lavender = color565(150, 150, 200) -beige = color565(200, 200, 150) -# by definition, maroon is 50% of the red on, but 128 is way too bright -maroon = color565(105, 0, 0) -olive = color565(128, 128, 0) -turquoise = color565(64, 224, 208) -dark_green = color565(0,100,0) -color_list = [white, red, green, blue, yellow, cyan, magenta, - gray, light_gray, dark_gray, brown, orange, pink, purple, lavender, - beige, maroon, olive, turquoise, dark_green, black] -color_num = len(color_list) - -# Draw forever -while True: - # rect_fill(x, y, width, height, color) - x = randint(0, HALF_WIDTH) - y = randint(0, HALF_HEIGHT) - width = randint(0, HALF_WIDTH) - height = randint(0, HALF_HEIGHT) - color = color_list[randint(0, color_num-1)] - print('fill_rectangle(', x, y, width, height, color) - display.fill_rectangle(x, y, width, height, color) \ No newline at end of file diff --git a/src/displays/ili934x/rotation-test.py b/src/displays/ili934x/rotation-test.py deleted file mode 100644 index 95226a448..000000000 --- a/src/displays/ili934x/rotation-test.py +++ /dev/null @@ -1,25 +0,0 @@ -from ili934x import ILI9341, color565 -from machine import Pin, SPI -from utime import sleep -import tt32 - -SCK_PIN = 2 -MISO_PIN = 3 -DC_PIN = 4 -RST_PIN = 5 -CS_PIN = 6 - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) - -while True: - for r in range(0, 8): - display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RST_PIN), w=320, h=240, r=r) - display.erase() - display.set_font(tt32) - display.set_pos(0,0) - display.print('Rotation ' + str(r)) - display.set_pos(0,40) - display.print('LIL934x') - sleep(3) diff --git a/src/displays/ili934x/test-all-fonts.py b/src/displays/ili934x/test-all-fonts.py deleted file mode 100644 index 446f6adc2..000000000 --- a/src/displays/ili934x/test-all-fonts.py +++ /dev/null @@ -1,32 +0,0 @@ -# test of printing multiple fonts to the ILI9341 on an M5Stack using H/W SP -# MIT License; Copyright (c) 2017 Jeffrey N. Magee - -from ili934x import ILI9341, color565 -from machine import Pin, SPI -import glcdfont -import tt14 -import tt24 -import tt32 - -# Use these PIN definitions. SCK must be on 2 and data (SDL) on 3 -SCK_PIN = const(2) -MISO_PIN = const(3) # labeled SDI(MOSI) on the back of the display -DC_PIN = const(4) -RESET_PIN = const(5) -CS_PIN = const(6) - -# mosi=Pin(23) -# miso=Pin(MISO_PIN) -spi = SPI(0, baudrate=20000000, mosi=Pin(MISO_PIN),sck=Pin(SCK_PIN)) -display = ILI9341(spi, cs=Pin(CS_PIN), dc=Pin(DC_PIN), rst=Pin(RESET_PIN), w=320, h=240, r=3) - -fonts = [glcdfont,tt14,tt24,tt32] - -text = 'Now is the time for all good men to come to the aid of the party.' - -display.erase() -display.set_pos(0,0) -for ff in fonts: - display.set_font(ff) - display.print(text) - diff --git a/src/displays/lcd-1602-i2c/cycle-demo.py b/src/displays/lcd-1602-i2c/cycle-demo.py deleted file mode 100644 index 4f930f893..000000000 --- a/src/displays/lcd-1602-i2c/cycle-demo.py +++ /dev/null @@ -1,73 +0,0 @@ -import utime - -import machine -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000) -lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) - -while True: - print("Running tests") - - lcd.putstr("CoderDojo Rocks!") - utime.sleep(3) - lcd.clear() - - string = "" - for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS): - string += chr(x) - lcd.putstr(string) - utime.sleep(3) - lcd.clear() - - time = utime.localtime() - lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format( - year=time[0], month=time[1], day=time[2], - HH=time[3], MM=time[4], SS=time[5])) - utime.sleep(3) - lcd.clear() - -# count = 0 -# -# lcd.clear() -# time = utime.localtime() -# lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format( -# year=time[0], month=time[1], day=time[2], -# HH=time[3], MM=time[4], SS=time[5])) -# if count % 10 == 0: -# print("Turning cursor on") -# lcd.show_cursor() -# if count % 10 == 1: -# print("Turning cursor off") -# lcd.hide_cursor() -# if count % 10 == 2: -# print("Turning blink cursor on") -# lcd.blink_cursor_on() -# if count % 10 == 3: -# print("Turning blink cursor off") -# lcd.blink_cursor_off() -# if count % 10 == 4: -# print("Turning backlight off") -# lcd.backlight_off() -# if count % 10 == 5: -# print("Turning backlight on") -# lcd.backlight_on() -# if count % 10 == 6: -# print("Turning display off") -# lcd.display_off() -# if count % 10 == 7: -# print("Turning display on") -# lcd.display_on() -# if count % 10 == 8: -# print("Filling display") -# lcd.clear() -# string = "" -# for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS): -# string += chr(x) -# lcd.putstr(string) diff --git a/src/displays/lcd-1602-i2c/display-coderdojo-rocks.py b/src/displays/lcd-1602-i2c/display-coderdojo-rocks.py deleted file mode 100644 index 039465d4a..000000000 --- a/src/displays/lcd-1602-i2c/display-coderdojo-rocks.py +++ /dev/null @@ -1,11 +0,0 @@ -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000) -lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) -lcd.putstr("CoderDojo Rocks!") diff --git a/src/displays/lcd-1602-i2c/lcd-1602-i2c-test.py b/src/displays/lcd-1602-i2c/lcd-1602-i2c-test.py deleted file mode 100644 index 774c13702..000000000 --- a/src/displays/lcd-1602-i2c/lcd-1602-i2c-test.py +++ /dev/null @@ -1,62 +0,0 @@ -import utime - -import machine -from machine import I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd - -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 - -def test_main(): - #Test function for verifying basic functionality - print("Running test_main") - i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000) - lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) - lcd.putstr("CoderDojo Rocks!") - utime.sleep(10) - lcd.clear() - count = 0 - while True: - lcd.clear() - time = utime.localtime() - lcd.putstr("{year:>04d}/{month:>02d}/{day:>02d} {HH:>02d}:{MM:>02d}:{SS:>02d}".format( - year=time[0], month=time[1], day=time[2], - HH=time[3], MM=time[4], SS=time[5])) - if count % 10 == 0: - print("Turning cursor on") - lcd.show_cursor() - if count % 10 == 1: - print("Turning cursor off") - lcd.hide_cursor() - if count % 10 == 2: - print("Turning blink cursor on") - lcd.blink_cursor_on() - if count % 10 == 3: - print("Turning blink cursor off") - lcd.blink_cursor_off() - if count % 10 == 4: - print("Turning backlight off") - lcd.backlight_off() - if count % 10 == 5: - print("Turning backlight on") - lcd.backlight_on() - if count % 10 == 6: - print("Turning display off") - lcd.display_off() - if count % 10 == 7: - print("Turning display on") - lcd.display_on() - if count % 10 == 8: - print("Filling display") - lcd.clear() - string = "" - for x in range(32, 32+I2C_NUM_ROWS*I2C_NUM_COLS): - string += chr(x) - lcd.putstr(string) - count += 1 - utime.sleep(2) - -#if __name__ == "__main__": -test_main() \ No newline at end of file diff --git a/src/displays/led-st7789/lcd-hello-v2.py b/src/displays/led-st7789/lcd-hello-v2.py deleted file mode 100644 index 287ac0f89..000000000 --- a/src/displays/led-st7789/lcd-hello-v2.py +++ /dev/null @@ -1,27 +0,0 @@ -from machine import Pin, SPI -import st7789 - -BACKLIGHT_PIN = 10 -RESET_PIN = 11 -DC_PIN = 12 -CS_PIN = 13 -CLK_PIN = 14 -DIN_PIN = 15 # lower left corner - -import st7789 - -import vga1_bold_16x32 as font - -spi = SPI(1, baudrate=31250000, sck=Pin(CLK_PIN), mosi=Pin(DIN_PIN)) -tft = st7789.ST7789(spi, 240, 320, - reset=Pin(RESET_PIN, Pin.OUT), - cs=Pin(CS_PIN, Pin.OUT), - dc=Pin(DC_PIN, Pin.OUT), - backlight=Pin(BACKLIGHT_PIN, Pin.OUT), - rotation=3) -tft.init() - -tft.text(font, "Hello World!",10, 0, st7789.color565(255,255,255), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 50, st7789.color565(255,0,0), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 100, st7789.color565(0,255,0), st7789.color565(0,0,0)) -tft.text(font, "Hello World!",10, 150, st7789.color565(0,0,255), st7789.color565(0,0,0)) diff --git a/src/displays/led-st7789/sdcard-list-dir.py b/src/displays/led-st7789/sdcard-list-dir.py deleted file mode 100644 index 3267a0d71..000000000 --- a/src/displays/led-st7789/sdcard-list-dir.py +++ /dev/null @@ -1,48 +0,0 @@ -import machine, os, sdcard - -# Assign chip select (CS) pin (and start it high) -cs = machine.Pin(15, machine.Pin.OUT) -# Intialize SPI peripheral (start with 1 MHz) -spi = machine.SPI(1, - baudrate=1000000, - polarity=0, - phase=0, - bits=8, - firstbit=machine.SPI.MSB, - sck=machine.Pin(10), - mosi=machine.Pin(11), - miso=machine.Pin(12)) -# Initialize SD card -sd = sdcard.SDCard(spi, cs) - -def print_directory(path, tabs = 0): - for file in os.listdir(path): - stats = os.stat(path+"/"+file) - filesize = stats[6] - isdir = stats[0] & 0x4000 - - if filesize < 1000: - sizestr = str(filesize) + " by" - elif filesize < 1000000: - sizestr = "%0.1f KB" % (filesize/1000) - else: - sizestr = "%0.1f MB" % (filesize/1000000) - - prettyprintname = "" - for i in range(tabs): - prettyprintname += " " - prettyprintname += file - if isdir: - prettyprintname += "/" - print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr)) - - # recursively print directory contents - if isdir: - print_directory(path+"/"+file, tabs+1) - -os.mount(sd, '/sd') -# check the content -directory = os.listdir('/sd') -print(directory) - -print_directory('/sd') \ No newline at end of file diff --git a/src/displays/oled-i2c/i2c-oled-test.py b/src/displays/oled-i2c/i2c-oled-test.py deleted file mode 100644 index e82bc8acf..000000000 --- a/src/displays/oled-i2c/i2c-oled-test.py +++ /dev/null @@ -1,18 +0,0 @@ -import machine -from time import sleep -from ssd1306 import SSD1306_I2C - -# reset the display on setup -OLEDinit = machine.Pin(15, machine.Pin.OUT) -OLEDinit.low() -sleep(0.1) -OLEDinit.high() - -#now we can get to the I2C interface -i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1)) -print (i2c.scan()) - -# setup the display driver using the i2c interface -oled = SSD1306_I2C(128, 64, i2c) -oled.text('CoderDojo Rocks!', 0, 0) -oled.show() \ No newline at end of file diff --git a/src/displays/oled-i2c/pixel-draw-speed-test.py b/src/displays/oled-i2c/pixel-draw-speed-test.py deleted file mode 100644 index 1e6a0bc12..000000000 --- a/src/displays/oled-i2c/pixel-draw-speed-test.py +++ /dev/null @@ -1,33 +0,0 @@ -import machine -from utime import sleep, ticks_us -from ssd1306 import SSD1306_I2C -OLED_RESET = machine.Pin(15, machine.Pin.OUT) -OLED_RESET.low() -sleep(.1) -OLED_RESET.high() -i2c = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1)) - -oled = SSD1306_I2C(128, 64, i2c) -oled.text('CoderDojo Rocks!', 0, 0) -oled.show() -print (i2c.scan()) - -# test the draw speed -# on the 133 Mhz RP2040 i get 27.7 milliseconds to draw a 128X64 display using I2C -# this is 128X64 = 8192 bits in 27.7 msec or 295.74 bits/msec = 300 kbits/sec -while True: - # record the time we start drawing - start_time = ticks_us() - # draw a horizontal line 1 pixel at a time - for i in range(0,127): - oled.pixel(i, 11, 1) - oled.show() - for i in range(0,127): - oled.pixel(i, 11, 0) - oled.show() - end_time = ticks_us() - elapsed_time = end_time - start_time - print('Total time in microseconds', elapsed_time) - time_per_show = elapsed_time / 256 - print('Time per show:', time_per_show) - diff --git a/src/displays/sh1106/sh1106-i2c-display-test.py b/src/displays/sh1106/sh1106-i2c-display-test.py deleted file mode 100644 index e87ee3e83..000000000 --- a/src/displays/sh1106/sh1106-i2c-display-test.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin, I2C -import sh1106 - -OLED_SDA_PIN=16 -OLED_SCL_PIN=17 -sda=machine.Pin(OLED_SDA_PIN) -scl=machine.Pin(OLED_SCL_PIN) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) -print(i2c) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(20), 0x3c) -display.sleep(False) -display.fill(0) -display.text('Testing 1', 0, 0, 1) -display.show() diff --git a/src/displays/sh1106/sh1106.py b/src/displays/sh1106/sh1106.py deleted file mode 100644 index 7c932b9df..000000000 --- a/src/displays/sh1106/sh1106.py +++ /dev/null @@ -1,236 +0,0 @@ -# -# MicroPython SH1106 OLED driver, I2C and SPI interfaces -# -# The MIT License (MIT) -# -# Copyright (c) 2016 Radomir Dopieralski (@deshipu), -# 2017-2021 Robert Hammelrath (@robert-hh) -# 2021 Tim Weber (@scy) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Sample code sections for ESP8266 pin assignments -# ------------ SPI ------------------ -# Pin Map SPI -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D7 - GPIO 13 - Din / MOSI fixed -# - D5 - GPIO 14 - Clk / Sck fixed -# - D8 - GPIO 4 - CS (optional, if the only connected device) -# - D2 - GPIO 5 - D/C -# - D1 - GPIO 2 - Res -# -# for CS, D/C and Res other ports may be chosen. -# -# from machine import Pin, SPI -# import sh1106 - -# spi = SPI(1, baudrate=1000000) -# display = sh1106.SH1106_SPI(128, 64, spi, Pin(5), Pin(2), Pin(4)) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() -# -# --------------- I2C ------------------ -# -# Pin Map I2C -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D2 - GPIO 5 - SCK / SCL -# - D1 - GPIO 4 - DIN / SDA -# - D0 - GPIO 16 - Res -# - G - xxxxxx CS -# - G - xxxxxx D/C -# -# Pin's for I2C can be set almost arbitrary -# -# from machine import Pin, I2C -# import sh1106 -# -# i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) -# display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() - -from micropython import const -import utime as time -import framebuf - - -# a few register definitions -_SET_CONTRAST = const(0x81) -_SET_NORM_INV = const(0xa6) -_SET_DISP = const(0xae) -_SET_SCAN_DIR = const(0xc0) -_SET_SEG_REMAP = const(0xa0) -_LOW_COLUMN_ADDRESS = const(0x00) -_HIGH_COLUMN_ADDRESS = const(0x10) -_SET_PAGE_ADDRESS = const(0xB0) - - -class SH1106(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc, rotate=0): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.flip_en = rotate == 180 or rotate == 270 - self.rotate90 = rotate == 90 or rotate == 270 - self.pages = self.height // 8 - self.bufsize = self.pages * self.width - self.renderbuf = bytearray(self.bufsize) - if self.rotate90: - self.displaybuf = bytearray(self.bufsize) - # HMSB is required to keep the bit order in the render buffer - # compatible with byte-for-byte remapping to the display buffer, - # which is in VLSB. Else we'd have to copy bit-by-bit! - super().__init__(self.renderbuf, self.height, self.width, - framebuf.MONO_HMSB) - else: - self.displaybuf = self.renderbuf - super().__init__(self.renderbuf, self.width, self.height, - framebuf.MONO_VLSB) - - # flip() was called rotate() once, provide backwards compatibility. - self.rotate = self.flip - self.init_display() - - def init_display(self): - self.reset() - self.fill(0) - self.poweron() - # rotate90 requires a call to flip() for setting up. - self.flip(self.flip_en) - - def poweroff(self): - self.write_cmd(_SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(_SET_DISP | 0x01) - - def flip(self, flag=None, update=True): - if flag is None: - flag = not self.flip_en - mir_v = flag ^ self.rotate90 - mir_h = flag - self.write_cmd(_SET_SEG_REMAP | (0x01 if mir_v else 0x00)) - self.write_cmd(_SET_SCAN_DIR | (0x08 if mir_h else 0x00)) - self.flip_en = flag - if update: - self.show() - - def sleep(self, value): - self.write_cmd(_SET_DISP | (not value)) - - def contrast(self, contrast): - self.write_cmd(_SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(_SET_NORM_INV | (invert & 1)) - - def show(self): - # self.* lookups in loops take significant time (~4fps). - (w, p, db, rb) = (self.width, self.pages, - self.displaybuf, self.renderbuf) - if self.rotate90: - for i in range(self.bufsize): - db[w * (i % p) + (i // p)] = rb[i] - for page in range(self.height // 8): - self.write_cmd(_SET_PAGE_ADDRESS | page) - self.write_cmd(_LOW_COLUMN_ADDRESS | 2) - self.write_cmd(_HIGH_COLUMN_ADDRESS | 0) - self.write_data(db[(w*page):(w*page+w)]) - - def reset(self, res): - if res is not None: - res(1) - time.sleep_ms(1) - res(0) - time.sleep_ms(20) - res(1) - time.sleep_ms(20) - - -class SH1106_I2C(SH1106): - def __init__(self, width, height, i2c, res=None, addr=0x3c, - rotate=0, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.res = res - self.temp = bytearray(2) - if res is not None: - res.init(res.OUT, value=1) - super().__init__(width, height, external_vcc, rotate) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.i2c.writeto(self.addr, b'\x40'+buf) - - def reset(self): - super().reset(self.res) - - -class SH1106_SPI(SH1106): - def __init__(self, width, height, spi, dc, res=None, cs=None, - rotate=0, external_vcc=False): - self.rate = 10 * 1000 * 1000 - dc.init(dc.OUT, value=0) - if res is not None: - res.init(res.OUT, value=0) - if cs is not None: - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - super().__init__(width, height, external_vcc, rotate) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - else: - self.dc(0) - self.spi.write(bytearray([cmd])) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) - else: - self.dc(1) - self.spi.write(buf) - - def reset(self): - super().reset(self.res) diff --git a/src/displays/ssd1306/09-display-test.py b/src/displays/ssd1306/09-display-test.py deleted file mode 100644 index 58bd47620..000000000 --- a/src/displays/ssd1306/09-display-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Test display connections - -from machine import Pin, I2C -from utime import sleep -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# for SPI0, the clock should be on 2 and data on 3 -# https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#pinout-and-design-files -SCL = machine.Pin(2) -SDA = machine.Pin(3) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -counter = 0 -while True: - oled.fill(0) - oled.text(str(counter), 0, 1) - oled.show() - sleep(1) - counter += 1 - - \ No newline at end of file diff --git a/src/displays/ssd1306/display-coderdojo-logo.py b/src/displays/ssd1306/display-coderdojo-logo.py deleted file mode 100644 index d0de1ff14..000000000 --- a/src/displays/ssd1306/display-coderdojo-logo.py +++ /dev/null @@ -1,47 +0,0 @@ -# This code displays pi image & text on I2C OLED display, then repeats forever. -# Also print out the OLED's I2C address on serial at program start. -# --- -# Connection: SCL = GP1, SDA = GP0 -# --- -# Hardware: -# 1. Cytron Maker Pi RP2040 (www.cytron.io/p-MAKER-PI-RP2040) -# - Any RP2040 boards should work too. -# 2. Grove OLED Display 0.96 inch (www.cytron.io/p-grove-oled-display-0p96-inch-ssd1315) -# --- -from machine import Pin, I2C -import framebuf -import utime -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -# Raspberry Pi logo as 32x32 bytearray - -my_bytearray = (b'\x00\x00\x00@ \x10\x08\x00\x04\x00\x02\x02\x01\xf1\x19\t\t\xf9\x03\x02\x06\x0e<\xfc\xf8\xf0\xe0\xc0\x80\x00\x00\x00\xf0\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x06\x04\x04\x03\x80\x80\xc0\xe0\xf8\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x0f \x80\x00\x00\x00\x00\x00\xe0\xf8\xfc\xfe\xfe\xff\xef\xef\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x00\x00\x00\x00\x02\x04\x08\x10\x10#\x0f_\x7f\x7f\xff\xf7\xf7\xf0\xf7q\x7f\x7f???\x1f\x0f\x07\x03\x01\x00\x00\x00') -coderdojo_logo = bytearray(my_bytearray) - - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -# Monochrome Horizontal least significant bit encoding is MONO_HLSB -# https://docs.micropython.org/en/latest/library/framebuf.html#framebuf.framebuf.MONO_VLSB -# fb = framebuf.FrameBuffer(pi_logo, 32, 32, framebuf.MONO_HLSB) -fbi = framebuf.FrameBuffer(coderdojo_logo, 32, 32, framebuf.MONO_VLSB) - -oled.fill(0) -oled.blit(fbi, 0, 1) -oled.show() - - \ No newline at end of file diff --git a/src/displays/ssd1306/display-test-47.py b/src/displays/ssd1306/display-test-47.py deleted file mode 100644 index b5cc88c9d..000000000 --- a/src/displays/ssd1306/display-test-47.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(counter): - oled.fill(0) - oled.text('Running', 0, 0) - oled.text("Dan McCreary's", 0, 10) - oled.text('Robot Lab 47', 0, 20) - oled.text(str(counter), 0, 30) - oled.show() - -counter = 0 -# repeat forever -while True: - update_display(counter) - led.toggle() - sleep(.5) - counter += 1 \ No newline at end of file diff --git a/src/displays/ssd1306/display-test-cytron.py b/src/displays/ssd1306/display-test-cytron.py deleted file mode 100644 index 7fa59fd40..000000000 --- a/src/displays/ssd1306/display-test-cytron.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin(0, Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(counter): - oled.fill(0) - oled.text('Running', 0, 0) - oled.text("Dan McCreary's", 0, 10) - oled.text('Robot Lab 47', 0, 20) - oled.text(str(counter), 0, 30) - oled.show() - -counter = 0 -# repeat forever -while True: - update_display(counter) - led.toggle() - sleep(.5) - counter += 1 \ No newline at end of file diff --git a/src/displays/ssd1306/i2c/02-hello-world.py b/src/displays/ssd1306/i2c/02-hello-world.py deleted file mode 100644 index c3a5f9b5d..000000000 --- a/src/displays/ssd1306/i2c/02-hello-world.py +++ /dev/null @@ -1,13 +0,0 @@ -# Hello world ssd1306 on I2C -import machine -import time -from ssd1306 import SSD1306_I2C -sda=machine.Pin(2) -scl=machine.Pin(3) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=400000) - -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -print('Done') \ No newline at end of file diff --git a/src/displays/ssd1306/i2c/03-rect-test.py b/src/displays/ssd1306/i2c/03-rect-test.py deleted file mode 100644 index 29b05357c..000000000 --- a/src/displays/ssd1306/i2c/03-rect-test.py +++ /dev/null @@ -1,77 +0,0 @@ -# I2C Scanner -import machine -from time import sleep -from ssd1306 import SSD1306_I2C -sda=machine.Pin(2) -scl=machine.Pin(3) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=400000) - -WIDTH=128 -HEIGHT=64 -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) - -delay = 3 -while True: - oled.fill(0) - oled.text("Rect fill test", 0, 0) - oled.text("white on black", 0, 10) - oled.show() - sleep(delay) - - oled.fill(1) - oled.text("Rect fill test", 0, 0, 0) - oled.text("black on white", 0, 10, 0) - oled.show() - sleep(delay) - - - oled.fill(0) - oled.text("rect(x,y,wid,ht)", 0, 0, 1) - oled.rect(10,10, WIDTH-20, HEIGHT-20, 1) - oled.show() - sleep(delay) - - oled.fill(1) - oled.text("rect(x,y,wid,ht)", 0, 0, 0) - oled.rect(10,10, WIDTH-20, HEIGHT-20, 0) - oled.show() - sleep(delay) - - - oled.fill(0) - oled.text("fill_rect(x,y,w,h)", 0, 0, 1) - oled.fill_rect(10,10, WIDTH-20, HEIGHT-20, 1) - oled.show() - sleep(delay) - - oled.fill(1) - oled.text("fill_rect(x,y,w,h)", 0, 0, 0) - oled.fill_rect(10,10, WIDTH-20, HEIGHT-20, 0) - oled.show() - sleep(delay) - - - oled.fill(0) - oled.text("hline(x,y,w)", 0, 0, 1) - oled.hline(10,20, WIDTH-20, 1) - oled.show() - sleep(delay) - - oled.fill(1) - oled.text("hline(x,y,w)", 0, 0, 0) - oled.hline(10,20, WIDTH-20, 0) - oled.show() - sleep(delay) - - - oled.fill(1) - oled.text("vline(x,y,h)", 0, 0, 0) - oled.vline(int(WIDTH/2),10, HEIGHT-20, 0) - oled.show() - sleep(delay) - - oled.fill(0) - oled.text("vline(x,y,h)", 0, 0, 1) - oled.vline(int(WIDTH/2),10, HEIGHT-20, 1) - oled.show() - sleep(delay) \ No newline at end of file diff --git a/src/displays/ssd1306/i2c/06-bounce-circles.py b/src/displays/ssd1306/i2c/06-bounce-circles.py deleted file mode 100644 index 60bcf839d..000000000 --- a/src/displays/ssd1306/i2c/06-bounce-circles.py +++ /dev/null @@ -1,58 +0,0 @@ -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(2) -scl=machine.Pin(3) -i2c=machine.I2C(1,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.fill(0) - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, state): - if size == 1: - oled.pixel(x, y, state) # draw a single pixel - else: - oled.ellipse(x, y, size, size, state, 1) - # TODO: for size above 4 round the corners - -#border -# oled.rect(0,0, width-1, height,-1, 1) - -# start in the middle of the screen -current_x = int(width/2) -current_y = int(height/2) -# start going down to the right -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - for ball_size in range(2,20): - for i in range(0,100): - draw_ball(current_x,current_y, ball_size, 1) - oled.show() - # utime.sleep(delay_time) - draw_ball(current_x, current_y, ball_size, 0) - - # reverse at the edges - # left edge test - if current_x < ball_size: - direction_x = 1 - # right edge test - if current_x > width - ball_size -2: - direction_x = -1 - # top edge test - if current_y < ball_size: - direction_y = 1 - # bottom edge test - if current_y > height - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y diff --git a/src/displays/ssd1306/i2c/06-bounce-sizes.py b/src/displays/ssd1306/i2c/06-bounce-sizes.py deleted file mode 100644 index d9bfeaabc..000000000 --- a/src/displays/ssd1306/i2c/06-bounce-sizes.py +++ /dev/null @@ -1,66 +0,0 @@ -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(2) -scl=machine.Pin(3) -i2c=machine.I2C(1,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 1, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, state): - if size == 1: - oled.pixel(x, y, state) # draw a single pixel - else: - for i in range(0,size): # draw a box of pixels of the right size - for j in range(0,size): - oled.pixel(x + i, y + j, state) - # TODO: for size above 4 round the corners - -border(width, height) - -ball_size = 5 -# start in the middle of the screen -current_x = int(width / 2) -current_y = int(height / 2) -# start going down to the right -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - for ball_size in range(2,20): - for i in range(0,100): - draw_ball(current_x,current_y, ball_size,1) - oled.show() - # utime.sleep(delay_time) - draw_ball(current_x,current_y,ball_size,0) - # reverse at the edges - # left edge test - if current_x < 2: - direction_x = 1 - # right edge test - if current_x > width - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 2: - direction_y = 1 - # bottom edge test - if current_y > height - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y diff --git a/src/displays/ssd1306/i2c/09-elipse-text.py b/src/displays/ssd1306/i2c/09-elipse-text.py deleted file mode 100644 index 2304c6824..000000000 --- a/src/displays/ssd1306/i2c/09-elipse-text.py +++ /dev/null @@ -1,47 +0,0 @@ -# I2C Scanner -import machine -from time import sleep -from ssd1306 import SSD1306_I2C -sda=machine.Pin(2) -scl=machine.Pin(3) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=400000) - -WIDTH=128 -HEIGHT=64 -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) - -HALF_WIDTH = int(WIDTH/2) -HALF_HEIGHT = int(HEIGHT/2) - -OFF = 0 -ON = 1 -FILL_OFF = 0 -FILL_ON = 1 -QUAD_CODE = 1 - -delay = 1 -while True: - for quad_code in range(1,16): - oled.fill(0) - oled.text("elipse " + str(quad_code), 0, 0, 1) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, 50, 20, ON, FILL_OFF, quad_code) - oled.show() - sleep(delay) - for quad_code in range(1,16): - oled.fill(1) - oled.text("elipse " + str(quad_code), 0, 0, 0) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, 50, 20, OFF, FILL_OFF, quad_code) - oled.show() - sleep(delay) - for quad_code in range(1,16): - oled.fill(0) - oled.text("elipse " + str(quad_code), 0, 0, 1) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, 50, 20, ON, FILL_ON, quad_code) - oled.show() - sleep(delay) - for quad_code in range(1,16): - oled.fill(1) - oled.text("elipse " + str(quad_code), 0, 0, 0) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, 50, 20, OFF, FILL_ON, quad_code) - oled.show() - sleep(delay) \ No newline at end of file diff --git a/src/displays/ssd1306/i2c/i2c-scanner.py b/src/displays/ssd1306/i2c/i2c-scanner.py deleted file mode 100644 index b7225cbbf..000000000 --- a/src/displays/ssd1306/i2c/i2c-scanner.py +++ /dev/null @@ -1,19 +0,0 @@ -# I2C Scanner -import machine -import time - -sda=machine.Pin(2) # row one on our standard Pico breadboard -scl=machine.Pin(3) # row two on our standard Pico breadboard -i2c=machine.I2C(1,sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -device_id = i2c.scan() -print("Device list:", device_id) - -if device_id[0] == 60: - print("Found I2C OLED Display at 60") -else: - print("No display found. Check your wiring.") - - diff --git a/src/displays/waveshare-round/LCD_1inch28.py b/src/displays/waveshare-round/LCD_1inch28.py deleted file mode 100644 index 445a66c96..000000000 --- a/src/displays/waveshare-round/LCD_1inch28.py +++ /dev/null @@ -1,447 +0,0 @@ -from machine import Pin,I2C,SPI,PWM,ADC -import framebuf -import time - - - -I2C_SDA = 6 -I2C_SDL = 7 - -DC = 8 -CS = 9 -SCK = 10 -MOSI = 11 -RST = 12 - -BL = 25 - -Vbat_Pin = 29 - - - -class LCD_1inch28(framebuf.FrameBuffer): - def __init__(self): - self.width = 240 - self.height = 240 - - self.cs = Pin(CS,Pin.OUT) - self.rst = Pin(RST,Pin.OUT) - - self.cs(1) - self.spi = SPI(1,100_000_000,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None) - self.dc = Pin(DC,Pin.OUT) - self.dc(1) - self.buffer = bytearray(self.height * self.width * 2) - super().__init__(self.buffer, self.width, self.height, framebuf.RGB565) - self.init_display() - - self.red = 0x07E0 - self.green = 0x001f - self.blue = 0xf800 - self.white = 0xffff - - self.fill(self.white) - self.show() - - self.pwm = PWM(Pin(BL)) - self.pwm.freq(5000) - - def write_cmd(self, cmd): - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(bytearray([buf])) - self.cs(1) - def set_bl_pwm(self,duty): - self.pwm.duty_u16(duty)#max 65535 - def init_display(self): - """Initialize dispaly""" - self.rst(1) - time.sleep(0.01) - self.rst(0) - time.sleep(0.01) - self.rst(1) - time.sleep(0.05) - - self.write_cmd(0xEF) - self.write_cmd(0xEB) - self.write_data(0x14) - - self.write_cmd(0xFE) - self.write_cmd(0xEF) - - self.write_cmd(0xEB) - self.write_data(0x14) - - self.write_cmd(0x84) - self.write_data(0x40) - - self.write_cmd(0x85) - self.write_data(0xFF) - - self.write_cmd(0x86) - self.write_data(0xFF) - - self.write_cmd(0x87) - self.write_data(0xFF) - - self.write_cmd(0x88) - self.write_data(0x0A) - - self.write_cmd(0x89) - self.write_data(0x21) - - self.write_cmd(0x8A) - self.write_data(0x00) - - self.write_cmd(0x8B) - self.write_data(0x80) - - self.write_cmd(0x8C) - self.write_data(0x01) - - self.write_cmd(0x8D) - self.write_data(0x01) - - self.write_cmd(0x8E) - self.write_data(0xFF) - - self.write_cmd(0x8F) - self.write_data(0xFF) - - - self.write_cmd(0xB6) - self.write_data(0x00) - self.write_data(0x20) - - self.write_cmd(0x36) - self.write_data(0x98) - - self.write_cmd(0x3A) - self.write_data(0x05) - - - self.write_cmd(0x90) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x08) - - self.write_cmd(0xBD) - self.write_data(0x06) - - self.write_cmd(0xBC) - self.write_data(0x00) - - self.write_cmd(0xFF) - self.write_data(0x60) - self.write_data(0x01) - self.write_data(0x04) - - self.write_cmd(0xC3) - self.write_data(0x13) - self.write_cmd(0xC4) - self.write_data(0x13) - - self.write_cmd(0xC9) - self.write_data(0x22) - - self.write_cmd(0xBE) - self.write_data(0x11) - - self.write_cmd(0xE1) - self.write_data(0x10) - self.write_data(0x0E) - - self.write_cmd(0xDF) - self.write_data(0x21) - self.write_data(0x0c) - self.write_data(0x02) - - self.write_cmd(0xF0) - self.write_data(0x45) - self.write_data(0x09) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x26) - self.write_data(0x2A) - - self.write_cmd(0xF1) - self.write_data(0x43) - self.write_data(0x70) - self.write_data(0x72) - self.write_data(0x36) - self.write_data(0x37) - self.write_data(0x6F) - - - self.write_cmd(0xF2) - self.write_data(0x45) - self.write_data(0x09) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x26) - self.write_data(0x2A) - - self.write_cmd(0xF3) - self.write_data(0x43) - self.write_data(0x70) - self.write_data(0x72) - self.write_data(0x36) - self.write_data(0x37) - self.write_data(0x6F) - - self.write_cmd(0xED) - self.write_data(0x1B) - self.write_data(0x0B) - - self.write_cmd(0xAE) - self.write_data(0x77) - - self.write_cmd(0xCD) - self.write_data(0x63) - - - self.write_cmd(0x70) - self.write_data(0x07) - self.write_data(0x07) - self.write_data(0x04) - self.write_data(0x0E) - self.write_data(0x0F) - self.write_data(0x09) - self.write_data(0x07) - self.write_data(0x08) - self.write_data(0x03) - - self.write_cmd(0xE8) - self.write_data(0x34) - - self.write_cmd(0x62) - self.write_data(0x18) - self.write_data(0x0D) - self.write_data(0x71) - self.write_data(0xED) - self.write_data(0x70) - self.write_data(0x70) - self.write_data(0x18) - self.write_data(0x0F) - self.write_data(0x71) - self.write_data(0xEF) - self.write_data(0x70) - self.write_data(0x70) - - self.write_cmd(0x63) - self.write_data(0x18) - self.write_data(0x11) - self.write_data(0x71) - self.write_data(0xF1) - self.write_data(0x70) - self.write_data(0x70) - self.write_data(0x18) - self.write_data(0x13) - self.write_data(0x71) - self.write_data(0xF3) - self.write_data(0x70) - self.write_data(0x70) - - self.write_cmd(0x64) - self.write_data(0x28) - self.write_data(0x29) - self.write_data(0xF1) - self.write_data(0x01) - self.write_data(0xF1) - self.write_data(0x00) - self.write_data(0x07) - - self.write_cmd(0x66) - self.write_data(0x3C) - self.write_data(0x00) - self.write_data(0xCD) - self.write_data(0x67) - self.write_data(0x45) - self.write_data(0x45) - self.write_data(0x10) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - - self.write_cmd(0x67) - self.write_data(0x00) - self.write_data(0x3C) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x01) - self.write_data(0x54) - self.write_data(0x10) - self.write_data(0x32) - self.write_data(0x98) - - self.write_cmd(0x74) - self.write_data(0x10) - self.write_data(0x85) - self.write_data(0x80) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x4E) - self.write_data(0x00) - - self.write_cmd(0x98) - self.write_data(0x3e) - self.write_data(0x07) - - self.write_cmd(0x35) - self.write_cmd(0x21) - - self.write_cmd(0x11) - time.sleep(0.12) - self.write_cmd(0x29) - time.sleep(0.02) - - self.write_cmd(0x21) - - self.write_cmd(0x11) - - self.write_cmd(0x29) - - def show(self): - self.write_cmd(0x2A) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0xef) - - self.write_cmd(0x2B) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0xEF) - - self.write_cmd(0x2C) - - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(self.buffer) - self.cs(1) - - -class QMI8658(object): - def __init__(self,address=0X6B): - self._address = address - self._bus = I2C(id=1,scl=Pin(I2C_SDL),sda=Pin(I2C_SDA),freq=100_000) - bRet=self.WhoAmI() - if bRet : - self.Read_Revision() - else : - return NULL - self.Config_apply() - - def _read_byte(self,cmd): - rec=self._bus.readfrom_mem(int(self._address),int(cmd),1) - return rec[0] - def _read_block(self, reg, length=1): - rec=self._bus.readfrom_mem(int(self._address),int(reg),length) - return rec - def _read_u16(self,cmd): - LSB = self._bus.readfrom_mem(int(self._address),int(cmd),1) - MSB = self._bus.readfrom_mem(int(self._address),int(cmd)+1,1) - return (MSB[0] << 8) + LSB[0] - def _write_byte(self,cmd,val): - self._bus.writeto_mem(int(self._address),int(cmd),bytes([int(val)])) - - def WhoAmI(self): - bRet=False - if (0x05) == self._read_byte(0x00): - bRet = True - return bRet - def Read_Revision(self): - return self._read_byte(0x01) - def Config_apply(self): - # REG CTRL1 - self._write_byte(0x02,0x60) - # REG CTRL2 : QMI8658AccRange_8g and QMI8658AccOdr_1000Hz - self._write_byte(0x03,0x23) - # REG CTRL3 : QMI8658GyrRange_512dps and QMI8658GyrOdr_1000Hz - self._write_byte(0x04,0x53) - # REG CTRL4 : No - self._write_byte(0x05,0x00) - # REG CTRL5 : Enable Gyroscope And Accelerometer Low-Pass Filter - self._write_byte(0x06,0x11) - # REG CTRL6 : Disables Motion on Demand. - self._write_byte(0x07,0x00) - # REG CTRL7 : Enable Gyroscope And Accelerometer - self._write_byte(0x08,0x03) - - def Read_Raw_XYZ(self): - xyz=[0,0,0,0,0,0] - raw_timestamp = self._read_block(0x30,3) - raw_acc_xyz=self._read_block(0x35,6) - raw_gyro_xyz=self._read_block(0x3b,6) - raw_xyz=self._read_block(0x35,12) - timestamp = (raw_timestamp[2]<<16)|(raw_timestamp[1]<<8)|(raw_timestamp[0]) - for i in range(6): - # xyz[i]=(raw_acc_xyz[(i*2)+1]<<8)|(raw_acc_xyz[i*2]) - # xyz[i+3]=(raw_gyro_xyz[((i+3)*2)+1]<<8)|(raw_gyro_xyz[(i+3)*2]) - xyz[i] = (raw_xyz[(i*2)+1]<<8)|(raw_xyz[i*2]) - if xyz[i] >= 32767: - xyz[i] = xyz[i]-65535 - return xyz - def Read_XYZ(self): - xyz=[0,0,0,0,0,0] - raw_xyz=self.Read_Raw_XYZ() - #QMI8658AccRange_8g - acc_lsb_div=(1<<12) - #QMI8658GyrRange_512dps - gyro_lsb_div = 64 - for i in range(3): - xyz[i]=raw_xyz[i]/acc_lsb_div#(acc_lsb_div/1000.0) - xyz[i+3]=raw_xyz[i+3]*1.0/gyro_lsb_div - return xyz - - - -if __name__=='__main__': - - LCD = LCD_1inch28() - LCD.set_bl_pwm(65535) - qmi8658=QMI8658() - Vbat= ADC(Pin(Vbat_Pin)) - - while(True): - #read QMI8658 - xyz=qmi8658.Read_XYZ() - - LCD.fill(LCD.white) - - LCD.fill_rect(0,0,240,40,LCD.red) - LCD.text("RP2040-LCD-1.28",60,25,LCD.white) - - LCD.fill_rect(0,40,240,40,LCD.blue) - LCD.text("Code Savvy Rocks!",60,57,LCD.white) - - LCD.fill_rect(0,80,120,120,0x1805) - LCD.text("ACC_X={:+.2f}".format(xyz[0]),20,100-3,LCD.white) - LCD.text("ACC_Y={:+.2f}".format(xyz[1]),20,140-3,LCD.white) - LCD.text("ACC_Z={:+.2f}".format(xyz[2]),20,180-3,LCD.white) - - LCD.fill_rect(120,80,120,120,0xF073) - LCD.text("GYR_X={:+3.2f}".format(xyz[3]),125,100-3,LCD.white) - LCD.text("GYR_Y={:+3.2f}".format(xyz[4]),125,140-3,LCD.white) - LCD.text("GYR_Z={:+3.2f}".format(xyz[5]),125,180-3,LCD.white) - - LCD.fill_rect(0,200,240,40,0x180f) - reading = Vbat.read_u16()*3.3/65535*2 - LCD.text("Vbat={:.2f}".format(reading),80,215,LCD.white) - - LCD.show() - time.sleep(0.1) - - diff --git a/src/displays/waveshare-round/RP2040-LEC-1.28.py b/src/displays/waveshare-round/RP2040-LEC-1.28.py deleted file mode 100644 index 445a66c96..000000000 --- a/src/displays/waveshare-round/RP2040-LEC-1.28.py +++ /dev/null @@ -1,447 +0,0 @@ -from machine import Pin,I2C,SPI,PWM,ADC -import framebuf -import time - - - -I2C_SDA = 6 -I2C_SDL = 7 - -DC = 8 -CS = 9 -SCK = 10 -MOSI = 11 -RST = 12 - -BL = 25 - -Vbat_Pin = 29 - - - -class LCD_1inch28(framebuf.FrameBuffer): - def __init__(self): - self.width = 240 - self.height = 240 - - self.cs = Pin(CS,Pin.OUT) - self.rst = Pin(RST,Pin.OUT) - - self.cs(1) - self.spi = SPI(1,100_000_000,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None) - self.dc = Pin(DC,Pin.OUT) - self.dc(1) - self.buffer = bytearray(self.height * self.width * 2) - super().__init__(self.buffer, self.width, self.height, framebuf.RGB565) - self.init_display() - - self.red = 0x07E0 - self.green = 0x001f - self.blue = 0xf800 - self.white = 0xffff - - self.fill(self.white) - self.show() - - self.pwm = PWM(Pin(BL)) - self.pwm.freq(5000) - - def write_cmd(self, cmd): - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(bytearray([buf])) - self.cs(1) - def set_bl_pwm(self,duty): - self.pwm.duty_u16(duty)#max 65535 - def init_display(self): - """Initialize dispaly""" - self.rst(1) - time.sleep(0.01) - self.rst(0) - time.sleep(0.01) - self.rst(1) - time.sleep(0.05) - - self.write_cmd(0xEF) - self.write_cmd(0xEB) - self.write_data(0x14) - - self.write_cmd(0xFE) - self.write_cmd(0xEF) - - self.write_cmd(0xEB) - self.write_data(0x14) - - self.write_cmd(0x84) - self.write_data(0x40) - - self.write_cmd(0x85) - self.write_data(0xFF) - - self.write_cmd(0x86) - self.write_data(0xFF) - - self.write_cmd(0x87) - self.write_data(0xFF) - - self.write_cmd(0x88) - self.write_data(0x0A) - - self.write_cmd(0x89) - self.write_data(0x21) - - self.write_cmd(0x8A) - self.write_data(0x00) - - self.write_cmd(0x8B) - self.write_data(0x80) - - self.write_cmd(0x8C) - self.write_data(0x01) - - self.write_cmd(0x8D) - self.write_data(0x01) - - self.write_cmd(0x8E) - self.write_data(0xFF) - - self.write_cmd(0x8F) - self.write_data(0xFF) - - - self.write_cmd(0xB6) - self.write_data(0x00) - self.write_data(0x20) - - self.write_cmd(0x36) - self.write_data(0x98) - - self.write_cmd(0x3A) - self.write_data(0x05) - - - self.write_cmd(0x90) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x08) - - self.write_cmd(0xBD) - self.write_data(0x06) - - self.write_cmd(0xBC) - self.write_data(0x00) - - self.write_cmd(0xFF) - self.write_data(0x60) - self.write_data(0x01) - self.write_data(0x04) - - self.write_cmd(0xC3) - self.write_data(0x13) - self.write_cmd(0xC4) - self.write_data(0x13) - - self.write_cmd(0xC9) - self.write_data(0x22) - - self.write_cmd(0xBE) - self.write_data(0x11) - - self.write_cmd(0xE1) - self.write_data(0x10) - self.write_data(0x0E) - - self.write_cmd(0xDF) - self.write_data(0x21) - self.write_data(0x0c) - self.write_data(0x02) - - self.write_cmd(0xF0) - self.write_data(0x45) - self.write_data(0x09) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x26) - self.write_data(0x2A) - - self.write_cmd(0xF1) - self.write_data(0x43) - self.write_data(0x70) - self.write_data(0x72) - self.write_data(0x36) - self.write_data(0x37) - self.write_data(0x6F) - - - self.write_cmd(0xF2) - self.write_data(0x45) - self.write_data(0x09) - self.write_data(0x08) - self.write_data(0x08) - self.write_data(0x26) - self.write_data(0x2A) - - self.write_cmd(0xF3) - self.write_data(0x43) - self.write_data(0x70) - self.write_data(0x72) - self.write_data(0x36) - self.write_data(0x37) - self.write_data(0x6F) - - self.write_cmd(0xED) - self.write_data(0x1B) - self.write_data(0x0B) - - self.write_cmd(0xAE) - self.write_data(0x77) - - self.write_cmd(0xCD) - self.write_data(0x63) - - - self.write_cmd(0x70) - self.write_data(0x07) - self.write_data(0x07) - self.write_data(0x04) - self.write_data(0x0E) - self.write_data(0x0F) - self.write_data(0x09) - self.write_data(0x07) - self.write_data(0x08) - self.write_data(0x03) - - self.write_cmd(0xE8) - self.write_data(0x34) - - self.write_cmd(0x62) - self.write_data(0x18) - self.write_data(0x0D) - self.write_data(0x71) - self.write_data(0xED) - self.write_data(0x70) - self.write_data(0x70) - self.write_data(0x18) - self.write_data(0x0F) - self.write_data(0x71) - self.write_data(0xEF) - self.write_data(0x70) - self.write_data(0x70) - - self.write_cmd(0x63) - self.write_data(0x18) - self.write_data(0x11) - self.write_data(0x71) - self.write_data(0xF1) - self.write_data(0x70) - self.write_data(0x70) - self.write_data(0x18) - self.write_data(0x13) - self.write_data(0x71) - self.write_data(0xF3) - self.write_data(0x70) - self.write_data(0x70) - - self.write_cmd(0x64) - self.write_data(0x28) - self.write_data(0x29) - self.write_data(0xF1) - self.write_data(0x01) - self.write_data(0xF1) - self.write_data(0x00) - self.write_data(0x07) - - self.write_cmd(0x66) - self.write_data(0x3C) - self.write_data(0x00) - self.write_data(0xCD) - self.write_data(0x67) - self.write_data(0x45) - self.write_data(0x45) - self.write_data(0x10) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - - self.write_cmd(0x67) - self.write_data(0x00) - self.write_data(0x3C) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x01) - self.write_data(0x54) - self.write_data(0x10) - self.write_data(0x32) - self.write_data(0x98) - - self.write_cmd(0x74) - self.write_data(0x10) - self.write_data(0x85) - self.write_data(0x80) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x4E) - self.write_data(0x00) - - self.write_cmd(0x98) - self.write_data(0x3e) - self.write_data(0x07) - - self.write_cmd(0x35) - self.write_cmd(0x21) - - self.write_cmd(0x11) - time.sleep(0.12) - self.write_cmd(0x29) - time.sleep(0.02) - - self.write_cmd(0x21) - - self.write_cmd(0x11) - - self.write_cmd(0x29) - - def show(self): - self.write_cmd(0x2A) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0xef) - - self.write_cmd(0x2B) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0x00) - self.write_data(0xEF) - - self.write_cmd(0x2C) - - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(self.buffer) - self.cs(1) - - -class QMI8658(object): - def __init__(self,address=0X6B): - self._address = address - self._bus = I2C(id=1,scl=Pin(I2C_SDL),sda=Pin(I2C_SDA),freq=100_000) - bRet=self.WhoAmI() - if bRet : - self.Read_Revision() - else : - return NULL - self.Config_apply() - - def _read_byte(self,cmd): - rec=self._bus.readfrom_mem(int(self._address),int(cmd),1) - return rec[0] - def _read_block(self, reg, length=1): - rec=self._bus.readfrom_mem(int(self._address),int(reg),length) - return rec - def _read_u16(self,cmd): - LSB = self._bus.readfrom_mem(int(self._address),int(cmd),1) - MSB = self._bus.readfrom_mem(int(self._address),int(cmd)+1,1) - return (MSB[0] << 8) + LSB[0] - def _write_byte(self,cmd,val): - self._bus.writeto_mem(int(self._address),int(cmd),bytes([int(val)])) - - def WhoAmI(self): - bRet=False - if (0x05) == self._read_byte(0x00): - bRet = True - return bRet - def Read_Revision(self): - return self._read_byte(0x01) - def Config_apply(self): - # REG CTRL1 - self._write_byte(0x02,0x60) - # REG CTRL2 : QMI8658AccRange_8g and QMI8658AccOdr_1000Hz - self._write_byte(0x03,0x23) - # REG CTRL3 : QMI8658GyrRange_512dps and QMI8658GyrOdr_1000Hz - self._write_byte(0x04,0x53) - # REG CTRL4 : No - self._write_byte(0x05,0x00) - # REG CTRL5 : Enable Gyroscope And Accelerometer Low-Pass Filter - self._write_byte(0x06,0x11) - # REG CTRL6 : Disables Motion on Demand. - self._write_byte(0x07,0x00) - # REG CTRL7 : Enable Gyroscope And Accelerometer - self._write_byte(0x08,0x03) - - def Read_Raw_XYZ(self): - xyz=[0,0,0,0,0,0] - raw_timestamp = self._read_block(0x30,3) - raw_acc_xyz=self._read_block(0x35,6) - raw_gyro_xyz=self._read_block(0x3b,6) - raw_xyz=self._read_block(0x35,12) - timestamp = (raw_timestamp[2]<<16)|(raw_timestamp[1]<<8)|(raw_timestamp[0]) - for i in range(6): - # xyz[i]=(raw_acc_xyz[(i*2)+1]<<8)|(raw_acc_xyz[i*2]) - # xyz[i+3]=(raw_gyro_xyz[((i+3)*2)+1]<<8)|(raw_gyro_xyz[(i+3)*2]) - xyz[i] = (raw_xyz[(i*2)+1]<<8)|(raw_xyz[i*2]) - if xyz[i] >= 32767: - xyz[i] = xyz[i]-65535 - return xyz - def Read_XYZ(self): - xyz=[0,0,0,0,0,0] - raw_xyz=self.Read_Raw_XYZ() - #QMI8658AccRange_8g - acc_lsb_div=(1<<12) - #QMI8658GyrRange_512dps - gyro_lsb_div = 64 - for i in range(3): - xyz[i]=raw_xyz[i]/acc_lsb_div#(acc_lsb_div/1000.0) - xyz[i+3]=raw_xyz[i+3]*1.0/gyro_lsb_div - return xyz - - - -if __name__=='__main__': - - LCD = LCD_1inch28() - LCD.set_bl_pwm(65535) - qmi8658=QMI8658() - Vbat= ADC(Pin(Vbat_Pin)) - - while(True): - #read QMI8658 - xyz=qmi8658.Read_XYZ() - - LCD.fill(LCD.white) - - LCD.fill_rect(0,0,240,40,LCD.red) - LCD.text("RP2040-LCD-1.28",60,25,LCD.white) - - LCD.fill_rect(0,40,240,40,LCD.blue) - LCD.text("Code Savvy Rocks!",60,57,LCD.white) - - LCD.fill_rect(0,80,120,120,0x1805) - LCD.text("ACC_X={:+.2f}".format(xyz[0]),20,100-3,LCD.white) - LCD.text("ACC_Y={:+.2f}".format(xyz[1]),20,140-3,LCD.white) - LCD.text("ACC_Z={:+.2f}".format(xyz[2]),20,180-3,LCD.white) - - LCD.fill_rect(120,80,120,120,0xF073) - LCD.text("GYR_X={:+3.2f}".format(xyz[3]),125,100-3,LCD.white) - LCD.text("GYR_Y={:+3.2f}".format(xyz[4]),125,140-3,LCD.white) - LCD.text("GYR_Z={:+3.2f}".format(xyz[5]),125,180-3,LCD.white) - - LCD.fill_rect(0,200,240,40,0x180f) - reading = Vbat.read_u16()*3.3/65535*2 - LCD.text("Vbat={:.2f}".format(reading),80,215,LCD.white) - - LCD.show() - time.sleep(0.1) - - diff --git a/src/drawing/blit-8-and-16-circles.py b/src/drawing/blit-8-and-16-circles.py deleted file mode 100644 index 602a0a3a1..000000000 --- a/src/drawing/blit-8-and-16-circles.py +++ /dev/null @@ -1,96 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 -import urandom - -WIDTH = 128 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# create an 8X8 array of bits for drawing a circle -CIRCLE8 = [ - [ 0, 0, 0, 1, 1, 0, 0, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 0, 1, 1, 0, 0, 0], -] - -CIRCLE16 = [ -[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0] -] - -# convert the bit array into a byte array -cba8 = bytearray() -for row in CIRCLE8: - byte = 0 - for bit in row: - byte = (byte << 1) | bit - cba8.append(byte) - -circle_buf_8 = framebuf.FrameBuffer(cba8, 8, 8, framebuf.MONO_HLSB) - -cba16 = bytearray() -row_count = len(CIRCLE16) -col_count = int(len(CIRCLE16[0]) / 8) # eight bits in a byte -print('rows:', row_count, ' 8-byte columns:', col_count, sep='') -for row in range(0, row_count): - for col in range(0, col_count): - print('at (', row, ',', col, ') ', sep='', end='') - byte = 0 - for bit in range(8): - print(CIRCLE16[row][col*8+bit], end='') - byte = (byte << 1) | CIRCLE16[row][col*8+bit] - cba16.append(byte) - print('') - -print("length of CIRCLE8:", len(CIRCLE8)) -print("length of cba8:", len(cba8)) -print(cba8) -print("length of CIRCLE16:", len(CIRCLE16)) -print("length of cba16 should be 32 bytes:", len(cba16)) -print(cba16) - -circle_buf_16 = framebuf.FrameBuffer(cba16, 16, 16, framebuf.MONO_HLSB) - -oled.fill(0) -start = ticks_us() -oled.blit(circle_buf_8, 10, 10) -oled.blit(circle_buf_8, 20, 10) -oled.blit(circle_buf_8, 30, 10) -oled.blit(circle_buf_16, 64, 30) -oled.blit(circle_buf_16, 100, 45) -end1 = ticks_us() -oled.show() -end2 = ticks_us() -print('Blit time:', end1 - start) -print('Show time:', end2 - start) - diff --git a/src/drawing/blit-eyes.py b/src/drawing/blit-eyes.py deleted file mode 100644 index cc1941945..000000000 --- a/src/drawing/blit-eyes.py +++ /dev/null @@ -1,47 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 -import urandom - -WIDTH = 128 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -circle16 = bytearray(b'\x01\x80\x0f\xf0\x1f\xf8?\xfc\x7f\xfe\x7f\xfe\x7f\xfe\xff\xff\xff\xff\x7f\xfe\x7f\xfe\x7f\xfe?\xfc\x1f\xf8\x0f\xf0\x01\x80') - -circle_buf_16 = framebuf.FrameBuffer(circle16, 16, 16, framebuf.MONO_HLSB) - -eye_dist_from_top = 20 -counter = 0 -direction = 1 -while True: - oled.fill(0) - start1 = ticks_us() - oled.blit(circle_buf_16, 32+counter, eye_dist_from_top) - oled.blit(circle_buf_16, 96+counter, eye_dist_from_top) - end1 = ticks_us() - start2 = ticks_us() - oled.show() - end2 = ticks_us() - if counter > 16: - direction = -1 - elif counter < -30: - direction = 1 - counter = counter + direction - sleep(.05) - blit_time = end1 - start1 - show_time = end2 - start2 - print('blit time:', blit_time, 'show time:', show_time) - print('blit to show ratio:', round(blit_time / show_time, 2)) - - diff --git a/src/drawing/circle-matricies.py b/src/drawing/circle-matricies.py deleted file mode 100644 index 48550ce00..000000000 --- a/src/drawing/circle-matricies.py +++ /dev/null @@ -1,440 +0,0 @@ -# Circle matricies for convertint to blit operations for fast drawing -# These matricies were created by print-circle-bits.py -CIRCLE_0=[[1,1],[1,1]] -CIRCLE_1 = [ -[1,1,1], -[1,1,1], -[1,1,1] -] -CIRCLE_2 = [ -[0,1,1,1,0], -[1,1,1,1,1], -[1,1,1,1,1], -[1,1,1,1,1], -[0,1,1,1,0] -] -CIRCLE_3 = [ -[0,0,1,1,1,0,0], -[0,1,1,1,1,1,0], -[1,1,1,1,1,1,1], -[1,1,1,1,1,1,1], -[1,1,1,1,1,1,1], -[0,1,1,1,1,1,0], -[0,0,1,1,1,0,0] -] -CIRCLE_4 = [ -[0,0,0,1,1,1,0,0,0], -[0,0,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,0,0], -[0,0,0,1,1,1,0,0,0] -] -CIRCLE_5 = [ -[0,0,0,0,1,1,1,0,0,0,0], -[0,0,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,0,0], -[0,0,0,0,1,1,1,0,0,0,0] -] -CIRCLE_6 = [ -[0,0,0,0,0,1,1,1,0,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,0,1,1,1,0,0,0,0,0] -] -CIRCLE_7 = [ -[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0] -] -CIRCLE_8 = [ -[0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0] -] -CIRCLE_9 = [ -[0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0] -] -CIRCLE_10 = [ -[0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0] -] -CIRCLE_11 = [ -[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_12 = [ -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_13 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_14 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_15 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_16 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_17 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_18 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_19 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] diff --git a/src/drawing/convert-matrix-to-byte-array.py b/src/drawing/convert-matrix-to-byte-array.py deleted file mode 100644 index 6a6efba3a..000000000 --- a/src/drawing/convert-matrix-to-byte-array.py +++ /dev/null @@ -1,474 +0,0 @@ -# Array of circles to byte arrays -# The CIRCLT_N where N is the number of pixels next to the center to the edge -CIRCLE_0 = [ - [1,1], - [1,1] -] -CIRCLE_1 = [ -[1,1,1], -[1,1,1], -[1,1,1] -] -CIRCLE_2 = [ -[0,1,1,1,0], -[1,1,1,1,1], -[1,1,1,1,1], -[1,1,1,1,1], -[0,1,1,1,0] -] -CIRCLE_3 = [ -[0,0,1,1,1,0,0], -[0,1,1,1,1,1,0], -[1,1,1,1,1,1,1], -[1,1,1,1,1,1,1], -[1,1,1,1,1,1,1], -[0,1,1,1,1,1,0], -[0,0,1,1,1,0,0] -] -CIRCLE_4 = [ -[0,0,0,1,1,1,0,0,0], -[0,0,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,0,0], -[0,0,0,1,1,1,0,0,0] -] -CIRCLE_5 = [ -[0,0,0,0,1,1,1,0,0,0,0], -[0,0,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,0,0], -[0,0,0,0,1,1,1,0,0,0,0] -] -CIRCLE_6 = [ -[0,0,0,0,0,1,1,1,0,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,0,1,1,1,0,0,0,0,0] -] -CIRCLE_7 = [ -[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,0,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,0,0,0,0,0,0] -] -CIRCLE_8 = [ -[0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0] -] -CIRCLE_9 = [ -[0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0] -] -CIRCLE_10 = [ -[0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0] -] -CIRCLE_11 = [ -[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_12 = [ -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_13 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_14 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_15 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_16 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_17 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_18 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] -CIRCLE_19 = [ -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0], -[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0], -[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0], -[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], -[0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], -[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] -] - -def array_to_byte_array(ba: bytearray): - new_bytes = bytearray() - for row in ba: - byte = 0 - for bit in row: - byte = (byte << 1) | bit - new_bytes.append(byte) - # ba += bytearray(new_bytes) - print('CIR', len(ba), '=', new_bytes, sep='') - -array_to_byte_array(CIRCLE_0) -array_to_byte_array(CIRCLE_1) -array_to_byte_array(CIRCLE_2) -array_to_byte_array(CIRCLE_3) -array_to_byte_array(CIRCLE_4) -array_to_byte_array(CIRCLE_5) -array_to_byte_array(CIRCLE_6) -array_to_byte_array(CIRCLE_7) -array_to_byte_array(CIRCLE_8) -array_to_byte_array(CIRCLE_9) -array_to_byte_array(CIRCLE_10) -array_to_byte_array(CIRCLE_11) -array_to_byte_array(CIRCLE_12) -array_to_byte_array(CIRCLE_13) -array_to_byte_array(CIRCLE_14) -array_to_byte_array(CIRCLE_15) -array_to_byte_array(CIRCLE_16) -array_to_byte_array(CIRCLE_17) -array_to_byte_array(CIRCLE_18) -array_to_byte_array(CIRCLE_19) diff --git a/src/drawing/draw-circle-turtle.py b/src/drawing/draw-circle-turtle.py deleted file mode 100644 index ad3022f59..000000000 --- a/src/drawing/draw-circle-turtle.py +++ /dev/null @@ -1,72 +0,0 @@ -# Import turtle package -import turtle -from time import sleep - -# Creating a turtle object(pen) -pen = turtle.Turtle() - -# Defining a method to draw curve -def curve(): - for i in range(200): - - # Defining step by step curve motion - pen.right(1) - pen.forward(1) - -# Defining method to draw a full heart -def heart(): - - # Set the fill color to red - pen.fillcolor('red') - - # Start filling the color - pen.begin_fill() - - # Draw the left line - pen.left(140) - pen.forward(113) - - # Draw the left curve - curve() - pen.left(120) - - # Draw the right curve - curve() - - # Draw the right line - pen.forward(112) - - # Ending the filling of the color - pen.end_fill() - -# Defining method to write text -def txt(): - - # Move turtle to air - pen.up() - - # Move turtle to a given position - pen.setpos(-68, 95) - - # Move the turtle to the ground - pen.down() - - # Set the text color to lightgreen - pen.color('lightgreen') - - # Write the specified text in - # specified font style and size - pen.write("GeeksForGeeks", font=( - "Verdana", 12, "bold")) - - -# Draw a heart -heart() - -# Write text -txt() - -# To hide turtle -pen.ht() - -sleep(5) diff --git a/src/drawing/draw-face-with-eyebrows.py b/src/drawing/draw-face-with-eyebrows.py deleted file mode 100644 index 51674a045..000000000 --- a/src/drawing/draw-face-with-eyebrows.py +++ /dev/null @@ -1,97 +0,0 @@ -''' -Test of the MicroPython framebuf poly drawing function - - from array import array - - my_array = array('h', [60,10, 50,60, 40,30]) - display.poly(0,0, my_array, ON, FILL) - -''' - -from machine import Pin -from utime import sleep, ticks_us -from array import array -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - - -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement -eye_dist_from_top = 25 -eyeWidth = 27 -eyeWidth_half = int(eyeWidth/2) -eyeHeight = 7 -mouth_vpos = 40 -mouth_width = 40 -pupil_width = 5 - -left_eyebrow = array('h', [-eyeWidth_half,-1, 15,-5, eyeWidth_half+10,1, 15,-2]) -right_eyebrow = array('h', [-eyeWidth_half-10, 1, -15,-5, eyeWidth_half,0, -15,-2]) - -def draw_eye(x): - oled.ellipse(x, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - # draw a black pupil on the white eye - oled.ellipse(x, eye_dist_from_top, pupil_width, pupil_width, OFF, FILL) - - -def draw_face(eye_direction): - - # draw_face_grid() - start = ticks_us() - # left eye - draw_eye(QUARTER_WIDTH) - - # eyebrow - oled.poly(QUARTER_WIDTH,eye_dist_from_top-10, left_eyebrow, ON, FILL) - - # right eye - draw_eye(QUARTER_WIDTH*3) - oled.poly(QUARTER_WIDTH*3,eye_dist_from_top-10, right_eyebrow, ON, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - end = ticks_us() - drawTime = end - start - # oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - -# outline box - -oled.fill(0) -oled.rect(0,0, WIDTH, HEIGHT, 1) -draw_face(0) - - diff --git a/src/drawing/draw-heart-turtle.py b/src/drawing/draw-heart-turtle.py deleted file mode 100644 index c12cdb5ab..000000000 --- a/src/drawing/draw-heart-turtle.py +++ /dev/null @@ -1,69 +0,0 @@ -# Import turtle package -import turtle - -# Creating a turtle object(pen) -pen = turtle.Turtle() - -# Defining a method to draw curve -def curve(): - for i in range(200): - - # Defining step by step curve motion - pen.right(1) - pen.forward(1) - -# Defining method to draw a full heart -def heart(): - - # Set the fill color to red - pen.fillcolor('red') - - # Start filling the color - pen.begin_fill() - - # Draw the left line - pen.left(140) - pen.forward(113) - - # Draw the left curve - curve() - pen.left(120) - - # Draw the right curve - curve() - - # Draw the right line - pen.forward(112) - - # Ending the filling of the color - pen.end_fill() - -# Defining method to write text -def txt(): - - # Move turtle to air - pen.up() - - # Move turtle to a given position - pen.setpos(-68, 95) - - # Move the turtle to the ground - pen.down() - - # Set the text color to lightgreen - pen.color('lightgreen') - - # Write the specified text in - # specified font style and size - pen.write("GeeksForGeeks", font=( - "Verdana", 12, "bold")) - - -# Draw a heart -heart() - -# Write text -txt() - -# To hide turtle -pen.ht() diff --git a/src/drawing/elipse-quadrant-test.py b/src/drawing/elipse-quadrant-test.py deleted file mode 100644 index b65d593d4..000000000 --- a/src/drawing/elipse-quadrant-test.py +++ /dev/null @@ -1,61 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_us -from array import array -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# quadrant text -# 0 - all off -# 1 - upper right on -# 2 - upper left on -# 3 - top half on -# 4 - lower left on -# 5 - lower left and upper right on -# 6 - left side on -# 7 - lower right off - rest on -# 9 - right side on -# 10 - upper left and lower right are on -# 11 - all but lower left are on -# 12 - lower half on -# 13 - all but upper left are on -# 14 - all but upper right are on -# 15 - all four are on - -while True: - # x, y, major-axis, minor-axis - for i in range(0, 16): - oled.fill(0) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, HALF_WIDTH-1, HALF_HEIGHT-1, ON, FILL, i) - oled.text(str(i), 0, 53, 1) - oled.show() - sleep(1) - for i in range(0, 16): - oled.fill(0) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, HALF_WIDTH-1, HALF_HEIGHT-1, ON, NO_FILL, i) - oled.text(str(i), 0, 53, 1) - oled.show() - sleep(1) \ No newline at end of file diff --git a/src/drawing/elipse-spin-test.py b/src/drawing/elipse-spin-test.py deleted file mode 100644 index ded2de986..000000000 --- a/src/drawing/elipse-spin-test.py +++ /dev/null @@ -1,46 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_us -from array import array -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# quadrant text - -# 1 - upper right on -# 2 - upper left on -# 4 - lower left on -# 8 - lower right on - -while True: - index = 0 - for i in range(0, 4): - index = 2**i - oled.fill(0) - oled.ellipse(HALF_WIDTH, HALF_HEIGHT, HALF_WIDTH-1, HALF_HEIGHT-1, ON, FILL, index) - oled.text(str(index), 0, 54, 1) - oled.show() - sleep(.05) \ No newline at end of file diff --git a/src/drawing/ellipse.py b/src/drawing/ellipse.py deleted file mode 100644 index a2b39643b..000000000 --- a/src/drawing/ellipse.py +++ /dev/null @@ -1,48 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# make an fb for an eye -eye = bytearray(32 * 24) -eyeBuf = framebuf.FrameBuffer(eye, 32, 24, framebuf.MONO_HLSB) -eyeBuf.ellipse(0, 0, 32, 24, 1) - -eye_dist_from_top = 30 -# copy onto display -oled.fill(0) -# left eye -oled.blit(eyeBuf, 32, eye_dist_from_top) -# right eye -oled.blit(eyeBuf, 96, eye_dist_from_top) -oled.show() \ No newline at end of file diff --git a/src/drawing/robot-faces-expressions-v1.py b/src/drawing/robot-faces-expressions-v1.py deleted file mode 100644 index 47de980df..000000000 --- a/src/drawing/robot-faces-expressions-v1.py +++ /dev/null @@ -1,159 +0,0 @@ -''' -Test of the MicroPython framebuf poly drawing function - - from array import array - - my_array = array('h', [60,10, 50,60, 40,30]) - display.poly(0,0, my_array, ON, FILL) - -''' - -from machine import Pin -from utime import sleep, ticks_us -from array import array -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - - -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement -eye_dist_from_top = 25 -eyeWidth = 27 -eyeWidth_half = int(eyeWidth/2) -eyeHeight = 7 -mouth_vpos = 50 -mouth_width = 40 -mouth_curve_max = 10 -pupil_width = 5 - -left_eyebrow = array('h', [-eyeWidth_half,-1, 15,-5, eyeWidth_half+10,1, 15,-2]) -right_eyebrow = array('h', [-eyeWidth_half-10, 1, -15,-5, eyeWidth_half,0, -15,-2]) - -def draw_eye(x, pupil_offset, blink_level): - # white eye - oled.ellipse(x, eye_dist_from_top, eyeWidth, eyeHeight - blink_level, ON, FILL) - # draw a black pupil on the white eye - oled.ellipse(x+pupil_offset, eye_dist_from_top, pupil_width, pupil_width, OFF, FILL) - -def draw_mouth(curve_up): - # curve_up = 10 is a smile - # curve_up = 0 is neutral - # curve_up = -10 is a frown - if curve_up > 0: - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, curve_up, ON, NO_FILL, 12) - # neutral sentiment - elif curve_up == 0: - # hline, x, y, length - oled.hline(mouth_width - int(mouth_width/2), mouth_vpos, mouth_width*2, 1) - elif curve_up < 0: # we have a frown - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, -curve_up, ON, NO_FILL, 3) - else: - print('Error: invalid mouth value') - # oled.text(str(curve_up), 0, 57, 1) - -def draw_face(eye_direction, blink_level, mouth_curve_up): - - # draw_face_grid() - start = ticks_us() - oled.fill(0) - - # left eye - draw_eye(QUARTER_WIDTH, eye_direction, blink_level) - - # eyebrow - oled.poly(QUARTER_WIDTH,eye_dist_from_top-10, left_eyebrow, ON, FILL) - - # right eye - draw_eye(QUARTER_WIDTH*3, eye_direction, blink_level) - oled.poly(QUARTER_WIDTH*3,eye_dist_from_top-10, right_eyebrow, ON, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - # curve is the height of the mouth - draw_mouth(mouth_curve_up) - - end = ticks_us() - drawTime = end - start - # oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - -# outline box - -eye_scan_delay = 0.05 -blink_delay = 0.1 -mouth_delay = 0.1 - -while True: - # look left - for i in range(0, 10): - draw_face(i, 0, 10) - sleep(eye_scan_delay) - # scan to right - for i in range(10, -10, -1): - draw_face(i, 0, 10) - sleep(eye_scan_delay) - # look back to center - for i in range(-10, 10): - draw_face(i, 0, 10) - sleep(eye_scan_delay) - - # blink - # 0 is eye open - 7 is eyes closed - for i in range(0, 7): - draw_face(0, i, 10) - sleep(blink_delay) - for i in range(7, 0, -1): - draw_face(0, i, 10) - sleep(blink_delay) - - # smile to neutral to frown and back - # decreasing smile - for i in range(mouth_curve_max, 1, -1): - draw_face(0, 0, i) - sleep(mouth_delay) - sleep(1) - # neurtal face - draw_face(0, 0, 0) - sleep(1) - # neural to max frown - for i in range(-1, -mouth_curve_max + 1, -1): - draw_face(0, 0, i) - sleep(mouth_delay) - sleep(1) - # frown to smile - for i in range(-mouth_curve_max + 1, mouth_curve_max, 1): - draw_face(0, 0, i) - sleep(mouth_delay) - sleep(1) \ No newline at end of file diff --git a/src/drivers/APDS9960.py b/src/drivers/APDS9960.py deleted file mode 100644 index debfe42ae..000000000 --- a/src/drivers/APDS9960.py +++ /dev/null @@ -1,732 +0,0 @@ -# MicroPython apds9960 motion detection device driver. - -#NOTE: This code is derived from a mix of Sparkfun and Adafruit arduino drivers. - -#todo: Have a mix of styles here. Some use properties for setters while others use functions. - -import pyb -from utime import * - -def setvalue( aOriginal, aPosBits, aValue ) : - '''Set a specific bit on a variable. aPosBits = 0xpm (p = pos, m = # mask bits).''' - mask = (1 << (aPosBits & 0xf)) - 1 - pos = aPosBits >> 4 - aOriginal &= ~(mask << pos) - return aOriginal | (aValue & mask) << pos - -def getvalue( aOriginal, aPosBits ) : - '''Get a specific bit from a variable. aPosBits = 0xpm (p = pos, m = # mask bits).''' - mask = (1 << (aPosBits & 0xf)) - 1 - pos = aPosBits >> 4 - return (aOriginal >> pos) & mask - -class apds9960(object) : - - _ADDRESS = const(0x39) - _RAM = const(0x00) - _ENABLE = const(0x80) - _ATIME = const(0x81) - _WTIME = const(0x83) - _AILTL = const(0x84) - _AILTH = const(0x85) - _AIHTL = const(0x86) - _AIHTH = const(0x87) - _PILT = const(0x89) - _PIHT = const(0x8B) - _PERS = const(0x8C) - _CONFIG1 = const(0x8D) - _PPULSE = const(0x8E) - _CONTROL = const(0x8F) - _CONFIG2 = const(0x90) - _ID = const(0x92) - _STATUS = const(0x93) - _CDATAL = const(0x94) - _CDATAH = const(0x95) - _RDATAL = const(0x96) - _RDATAH = const(0x97) - _GDATAL = const(0x98) - _GDATAH = const(0x99) - _BDATAL = const(0x9A) - _BDATAH = const(0x9B) - _PDATA = const(0x9C) - _POFFSET_UR = const(0x9D) - _POFFSET_DL = const(0x9E) - _CONFIG3 = const(0x9F) - _GPENTH = const(0xA0) - _GEXTH = const(0xA1) - _GCONF1 = const(0xA2) - _GCONF2 = const(0xA3) - _GOFFSET_U = const(0xA4) - _GOFFSET_D = const(0xA5) - _GOFFSET_L = const(0xA7) - _GOFFSET_R = const(0xA9) - _GPULSE = const(0xA6) - _GCONF3 = const(0xAA) - _GCONF4 = const(0xAB) - _GFLVL = const(0xAE) - _GSTATUS = const(0xAF) - _IFORCE = const(0xE4) - _PICLEAR = const(0xE5) - _CICLEAR = const(0xE6) - _AICLEAR = const(0xE7) - _GFIFO_U = const(0xFC) - _GFIFO_D = const(0xFD) - _GFIFO_L = const(0xFE) - _GFIFO_R = const(0xFF) - - #Device IDs - _ID_1 = const(0xAB) - _ID_2 = const(0x9C) - - #A Gain - _AGAIN_1X = const(0) #No gain - _AGAIN_4X = const(1) #2x gain - _AGAIN_16X = const(2) #16x gain - _AGAIN_64X = const(3) #64x gain - - #P Gain - _PGAIN_1X = const(0) #1x gain - _PGAIN_2X = const(1) #2x gain - _PGAIN_4X = const(2) #4x gain - _PGAIN_8X = const(3) #8x gain - - #Pulse Length - _PPULSELEN_4US = const(0) #4uS - _PPULSELEN_8US = const(1) #8uS - _PPULSELEN_16US = const(2) #16uS - _PPULSELEN_32US = const(3) #32uS - - #LED Drive - _LEDDRIVE_100MA = const(0) #100mA - _LEDDRIVE_50MA = const(1) #50mA - _LEDDRIVE_25MA = const(2) #25mA - _LEDDRIVE_12MA = const(3) #12.5mA - - #LED Boost - _LEDBOOST_100 = const(0) #100% - _LEDBOOST_150 = const(1) #150% - _LEDBOOST_200 = const(2) #200% - _LEDBOOST_300 = const(3) #300% - - #Dimensions - _DIMENSIONS_ALL = const(0) - _DIMENSIONS_UP_DOWM = const(1) - _DIMENSIONS_LEFT_RIGHT = const(2) - - #FIFO - _GFIFO_1 = const(0) - _GFIFO_4 = const(1) - _GFIFO_8 = const(2) - _GFIFO_16 = const(3) - - #G Gain - _GGAIN_1 = const(0) - _GGAIN_2 = const(1) - _GGAIN_4 = const(2) - _GGAIN_8 = const(3) - - #G Pulse - _GPULSE_4US = const(0) - _GPULSE_8US = const(1) - _GPULSE_16US = const(2) - _GPULSE_32US = const(3) - - #Value Location data. - #Following are the bytes describing the data packed into each 8 bit value on the chip. - #Nibble 1 = position, 0 = bits - #NOTE: Commented out currently unused locations. - - _ENABLE_PON = const(0x01) - _ENABLE_AEN = const(0x11) - _ENABLE_PEN = const(0x21) -# _ENABLE_WEN = const(0x31) -# _ENABLE_AIEN = const(0x41) - _ENABLE_PIEN = const(0x51) - _ENABLE_GEN = const(0x61) - -# _PERS_APERS = const(0x04) - _PERS_PPERS = const(0x44) - - _PPULSE_PPULSE = const(0x06) - _PPULSE_PPLEN = const(0x62) - - _CONTROL_AGAIN = const(0x02) - _CONTROL_PGAIN = const(0x22) - _CONTROL_LDRIVE = const(0x42) - - _CONFIG2_LED_BOOST = const(0x42) -# _CONFIG2_CPSIEN = const(0x61) #Clear photo diode saturation int enable. -# _CONFIG2_PSIEN = const(0x71) #Proximity saturation interrupt enable. - -# _CONFIG3_PMASK_R = const(0x01) -# _CONFIG3_PMASK_L = const(0x11) -# _CONFIG3_PMASK_D = const(0x21) -# _CONFIG3_PMASK_U = const(0x31) -# _CONFIG3_SAI = const(0x41) -# _CONFIG3_PCMP = const(0x51) - -# _GCONFIG1_GEXPERS = const(0x02) -# _GCONFIG1_GEXMSK = const(0x24) - _GCONFIG1_GFIFOTH = const(0x62) - - _GCONFIG2_GWTIME = const(0x03) -# _GCONFIG2_GLDRIVE = const(0x32) - _GCONFIG2_GGAIN = const(0x52) - - _GCONFIG3_GDIMS = const(0x02) - -# _GCONFIG4_GMODE = const(0x01) -# _GCONFIG4_GIEN = const(0x12) - - _GPULSE_GPULSE = const(0x06) - _GPULSE_GPLEN = const(0x62) - - _STATUS_AVALID = const(0x01) -# _STATUS_PVALID = const(0x11) -# _STATUS_GINT = const(0x21) -# _STATUS_AINT = const(0x41) -# _STATUS_PINT = const(0x51) -# _STATUS_PGSTAT = const(0x61) -# _STATUS_CPSTAT = const(0x71) - - _GSTATUS_GVALID = const(0x01) -# _GSTATUS_GFOV = const(0x11) - -# Gesture wait time values - _GWTIME_0MS = const(0) - _GWTIME_2_8MS = const(1) - _GWTIME_5_6MS = const(2) - _GWTIME_8_4MS = const(3) - _GWTIME_14_0MS = const(4) - _GWTIME_22_4MS = const(5) - _GWTIME_30_8MS = const(6) - _GWTIME_39_2MS = const(7) - - _THRESHOLD_OUT = const(10) - _SENSITIVITY_1 = const(50) - _SENSITIVITY_2 = const(20) - - _DIR_NONE = const(0) - _DIR_UP = const(1) - _DIR_DOWN = const(2) - _DIR_LEFT = const(3) - _DIR_RIGHT = const(4) - _DIR_NEAR = const(5) - _DIR_FAR = const(6) - _DIR_ALL = const(7) - - _NA_STATE = const(0) - _NEAR_STATE = const(1) - _FAR_STATE = const(2) - _ALL_STATE = const(3) - - _DefaultIntTimeMS = const(10) - - def __init__( self, aLoc ) : - '''aLoc I2C pin location is either 1, 'X', 2 or'Y'.''' - self._i2c = pyb.I2C(aLoc, pyb.I2C.MASTER) - - #Mirrors data on the controller in order to eliminate need to read data from the controller on modification. - self._enable = 0 #Enable - self._pers = 0 #Pers - self._ppulse = 0 #PPulse - self._gpulse = 0 #GPulse - self._control = 0 #Control - self._config2 = 0 #Config 2. - self._config3 = 0 #Config 3. - self._gconfig1 = 0 #Gesture Config 1. - self._gconfig2 = 0 #Gesture Config 2 - self._gconfig3 = 0 #Gesture Config 3 - self._gconfig4 = 0 #Gesture Config 4. - self._status = 0 #Status - self._gstatus = 0 #GStatus - - #gesture read variables. - self._ud_delta = 0 - self._lr_delta = 0 - self._ud_count = 0 - self._lr_count = 0 - self._near_count = 0 - self._far_count = 0 - self._state = 0 - self._motion = _DIR_NONE - self._udata = bytearray(32) - self._ddata = bytearray(32) - self._ldata = bytearray(32) - self._rdata = bytearray(32) - self._index = 0 - self._total_gestures= 0 - self._fifo_data = bytearray(128) - - self.resetcounts() - - self._b1 = bytearray(1) - self._b2 = bytearray(2) - - sleep_us(50) - self.begin() - - def read( self, aLoc ) : - '''Read 8 bit value and return.''' - self._i2c.mem_read(self._b1, _ADDRESS, aLoc) - return self._b1[0] - - def readbuffer( self, aBuffer, aLoc ) : - '''Read 8 bit values into given buffer.''' - self._i2c.mem_read(aBuffer, _ADDRESS, aLoc) - - def read16( self, aLoc ) : - '''Read 16 bit value and return.''' - self._i2c.mem_read(self._b2, _ADDRESS, aLoc) - return (self._b2[1] << 8) | self._b2[0] - - def write( self, aLoc, aVal ) : - '''Write 8 bit value to given address. aVal may be a byte array.''' - self._i2c.mem_write(aVal, _ADDRESS, aLoc) - - def write16( self, aLoc, aVal ) : - '''Write 16 bit value to given address.''' - self._b2[0] = aVal - self._b2[1] = aVal >> 8 - self._i2c.mem_write(self._b2, _ADDRESS, aLoc) - - def reset( self ): - '''Reset the controller and set default frequency.''' - self.write(0, _MODE1) - self.setfreq(_DEFAULTFREQ) - - #Enable - def setenable( self, aMember, aValue ) : - self._enable = setvalue(self._enable, aMember, aValue) - self.write(_ENABLE, self._enable) - - def getenable( self, aMember ) : - return getvalue(self._enable, aMember) - - #Pers - def setpers( self, aMember, aValue ) : - self._pers = setvalue(self._pers, aMember, aValue) - self.write(_PERS, self._pers) - - def getpers( self, aMember ) : - return getvalue(self._pers, aMember) - - #Control - def setcontrol( self, aMember, aValue ) : - self._control = setvalue(self._control, aMember, aValue) - self.write(_CONTROL, self._control) - - def getcontrol( self, aMember ) : - return getvalue(self._control, aMember) - - #Config 3 - def setconfig2( self, aMember, aValue ) : - self._config2 = setvalue(self._config2, aMember, aValue) - self.write(_CONFIG2, self._config2) - - def getconfig2( self, aMember ) : - return getvalue(self._config2, aMember) - - #Config 3 - def setconfig3( self, aMember, aValue ) : - self._config3 = setvalue(self._config3, aMember, aValue) - self.write(_CONFIG3, self._config3) - - def getconfig3( self, aMember ) : - return getvalue(self._config3, aMember) - - #GConfig 1 - def setgconfig1( self, aMember, aValue ) : - self._gconfig1 = setvalue(self._gconfig1, aMember, aValue) - self.write(_GCONF1, self._gconfig1) - - def getgconfig1( self, aMember ) : - return getvalue(self._gconfig1, aMember) - - #GConfig 2 - def setgconfig2( self, aMember, aValue ) : - self._gconfig2 = setvalue(self._gconfig2, aMember, aValue) - self.write(_GCONF2, self._gconfig2) - - def getgconfig2( self, aMember ) : - return getvalue(self._gconfig2, aMember) - - #GConfig 3 - def setgconfig3( self, aMember, aValue ) : - self._gconfig3 = setvalue(self._gconfig3, aMember, aValue) - self.write(_GCONF3, self._gconfig3) - - def getgconfig3( self, aMember ) : - return getvalue(self._gconfig3, aMember) - - #GConfig 4 - def setgconfig4( self, aMember, aValue ) : - self._gconfig4 = setvalue(self._gconfig4, aMember, aValue) - self.write(_GCONF4, self._gconfig4) - - def getgconfig4( self, aMember ) : - return getvalue(self._gconfig4, aMember) - - #Status - def getstatus( self, aMember ) : - '''Get member of status''' - self._status = self.read(_STATUS) - return getvalue(self._status, aMember) - - #GStatus - def getgstatus( self, aMember ) : - '''Get member of gstatus''' - self._gstatus = self.read(_GSTATUS) - return getvalue(self._gstatus, aMember) - - def resetcounts( self ) : - '''Reset the gesture reading counters.''' - self._gestCnt = 0 - #todo - put these in an array. - self._ucount = 0 - self._dcount = 0 - self._lcount = 0 - self._rcount = 0 - - def enableproximityint( self, aValue ) : - self.setenable(_ENABLE_PIEN, aValue) - self.clearInterrupt() - - def proximityintthreshold( self, aValue, aPersistance ) : - self.write(_PILT, aValue & 0xFF) - self.write(_PIHT, aValue >> 8) - self.setpers(_PERS_PPERS, min(aPersistance, 7)) - - def proximity( self ) : - return self.read(_PDATA) - - def gestureenterthreshold( self, aValue ) : - self.write(_GPENTH, aValue) - - def gestureexitthreshold( self, aValue ) : - self.write(_GEXTH, aValue) - - def gestureoffset( self, aUp, aDown, aLeft, aRight ) : - self.write(_GOFFSET_U, aUp) - self.write(_GOFFSET_D, aDown) - self.write(_GOFFSET_L, aLeft) - self.write(_GOFFSET_R, aRight) - - def enablegesture( self, aEnable ) : - #If disabling make sure we aren't currently in gesture mode. - # Gesture mode is auto entered when proximity enter threshold is hit - # so we don't need to enable it even though we disable on gesture disable. - if not aEnable : - self.setgconfig4(GCONFIG4_GMODE, False) - self.setenable(_ENABLE_GEN, aEnable) - self.resetcounts() - - @property - def gesturevalid( self ) : - '''Return True if gesture data exists.''' - return self.getgstatus(_GSTATUS_GVALID) - - def gesturedata( self ) : - '''Read gesture data and return as (u,d,l,r). Returns None of no data ready.''' - level = self.read(_GFLVL) - if level == 0 : - return # no data - fifo_u = self.read(_GFIFO_U) - fifo_d = self.read(_GFIFO_D) - fifo_l = self.read(_GFIFO_L) - fifo_r = self.read(_GFIFO_R) - - return (fifo_u, fifo_d, fifo_l, fifo_r) - - @property - def colordataready( self ) : - '''Return true if color data ready to read.''' - return self.getstatus(_STATUS_AVALID) - - def colordata( self ) : - '''Return color data as (c,r,g,b).''' - c = self.read16(_CDATAL) - r = self.read16(_RDATAL) - g = self.read16(_GDATAL) - b = self.read16(_BDATAL) - - return (c, r, g, b) - - def clearInterrupt( self ) : - #NOTE: The .ccp writes 0 bytes to this address. I don't know how - # to do that so I'm writing a 0 to AICLEAR. - self.write(_AICLEAR, 0) - - def intlimits( self, aLow, aHigh ) : - self.write16(_AILTL, aLow) - self.write16(_AIHTL, aHigh) - - def adcintegrationtime( self, aValue ) : - t = max(0.0, min(255.0, 256.0 - (aValue / 2.78))) - self.write(_ATIME, int(t)) - - @property - def enabled( self ) : - return self.getenable(_ENABLE_PON) - - @enabled.setter - def enabled( self, aValue ) : - self.setenable(_ENABLE_PON, aValue) - - def proxpulse( self, aLen, aPulses ) : - setvalue(self._ppulse, _PPULSE_PPULSE, min(64, max(aPulses, 1)) - 1) - setvalue(self._ppulse, _PPULSE_PPLEN, aLen) - self.write(_PPULSE_PPULSE, self._ppulse) - - def gpulse( self, aLen, aPulses ) : - setvalue(self._gpulse, _GPULSE_GPULSE, min(64, max(aPulses, 1)) - 1) - setvalue(self._gpulse, _GPULSE_GPLEN, aLen) - self.write(_GPULSE_GPULSE, self._gpulse) - - def begin( self ) : - '''Initialize the board for use.''' - id = self.read(_ID) - if id != _ID_1 and id != _ID_2: - raise Exception('Incorrect apds9960 ID {}.'.format(id)) - - self.enabled = False - sleep_us(50) - - # Set default integration time and gain - self.adcintegrationtime(_DefaultIntTimeMS) - self.write(_WTIME, 249) - self.write(_POFFSET_UR, 0) - self.write(_POFFSET_DL, 0) - self.write(_CONFIG1, 0x60) - self.setcontrol(_CONTROL_LDRIVE, _LEDDRIVE_100MA) - self.setcontrol(_CONTROL_AGAIN, _AGAIN_16X) - self.setcontrol(_CONTROL_PGAIN, _PGAIN_8X) - - self.proxpulse(_PPULSELEN_16US, 10) - self.gpulse(_GPULSE_32US, 9) - - self.proximityintthreshold(0x3200, 1) - self.enableproximityint(False) #Proximity Interrupt - - #100 makes the results a bit more erratic, No value boosts distance. It seems - # the higher the boost the more stable the data is. - self.setconfig2(_CONFIG2_LED_BOOST, _LEDBOOST_300) - - #NOTE: This must be 1 if enter threshold is < exit or we will never get gesture input because we - # won't stay in the gesture state for more than 1 cycle. - self.setgconfig1(_GCONFIG1_GFIFOTH, _GFIFO_1) - self.setgconfig2(_GCONFIG2_GWTIME, _GWTIME_2_8MS) - self.setgconfig2(_GCONFIG2_GGAIN, _GGAIN_4) - self.setgconfig3(_GCONFIG3_GDIMS, _DIMENSIONS_ALL) - #NOTE: An enter value lower than the exit value means we are constantly entering/exiting the state machine. - # If we don't do this we will not get proximity and color input because those are not updated when in gesture state. - self.gestureenterthreshold(5) #When proximity value is above this we enter the gesture state machine. - self.gestureexitthreshold(255) #When all gesture values are below this we exit the gesture state machine. - self.gestureoffset(0, 0, 0, 0) - - self.setenable(_ENABLE_PEN, True) #enable proximity - self.setenable(_ENABLE_AEN, True) #enable color - self.enablegesture(True) - - self.enabled = True - sleep_us(50) - - def resetgestureparams( self ) : - #NOTE: This function could probably be merged with resetcounts(). - self._index = 0 - self._total_gestures = 0 - self._ud_delta = 0 - self._lr_delta = 0 - self._ud_count = 0 - self._lr_count = 0 - self._near_count = 0 - self._far_count = 0 - self._state = 0 - self._motion = _DIR_NONE - - def readgesture( self ) : - '''Read gesture data and process for up, down, left, right movement. - Returns _DIR_???.''' - #NOTE: This function currently doesn't seem to return very accurate results. - if self.gesturevalid : - while True : - sleep_us(30) #Wait a bit to make sure fifo buffer is full. - - gstatus = self.getgstatus(_GSTATUS_GVALID) - if gstatus : - fifo_level = self.read(_GFLVL) - if fifo_level > 0 : - bread = fifo_level * 4 - self.readbuffer(self._fifo_data, _GFIFO_U) - - for i in range(0, fifo_level): - i2 = i * 4 - self._udata[i] = self._fifo_data[i2] - self._ddata[i] = self._fifo_data[i2 + 1] - self._ldata[i] = self._fifo_data[i2 + 2] - self._rdata[i] = self._fifo_data[i2 + 3] - - self._index += fifo_level - 1 - self._total_gestures += fifo_level - 1 - - if self.processgesturedata() : - self._index = 0 - self._total_gestures = 0 - else: - sleep_us(30) - self.decodegesture() - self.resetgestureparams() - return self._motion - - return _DIR_NONE - - def processgesturedata( self ) : - if self._total_gestures > 4 : - ufirst = 0 - dfirst = 0 - lfirst = 0 - rfirst = 0 - ulast = 0 - dlast = 0 - llast = 0 - rlast = 0 - - if 0 < self._total_gestures <= 32 : - for i in range(0, self._total_gestures) : - u = self._udata[i] - d = self._ddata[i] - l = self._ldata[i] - r = self._rdata[i] - if u > _THRESHOLD_OUT and d > _THRESHOLD_OUT and l > _THRESHOLD_OUT and r > _THRESHOLD_OUT : - ufirst = u - dfirst = d - lfirst = l - rfirst = r - break - - if ufirst == 0 or dfirst == 0 or lfirst == 0 or rfirst == 0 : - return False - - for i in range(self._total_gestures - 1, -1, -1) : - u = self._udata[i] - d = self._ddata[i] - l = self._ldata[i] - r = self._rdata[i] - if u > _THRESHOLD_OUT and d > _THRESHOLD_OUT and l > _THRESHOLD_OUT and r > _THRESHOLD_OUT : - ulast = u - dlast = d - llast = l - rlast = r - break - - ud_ratio_first = ((ufirst - dfirst) * 100) // (ufirst + dfirst) - lr_ratio_first = ((lfirst - rfirst) * 100) // (lfirst + rfirst) - ud_ratio_last = ((ulast - dlast) * 100) // (ulast + dlast) - lr_ratio_last = ((llast - rlast) * 100) // (llast + rlast) - - ud_delta = ud_ratio_last - ud_ratio_first - lr_delta = lr_ratio_last - lr_ratio_first - - self._ud_delta += ud_delta - self._lr_delta += lr_delta - - if self._ud_delta >= _SENSITIVITY_1 : - self._ud_count = 1 - elif self._ud_delta <= -_SENSITIVITY_1 : - self._ud_count = -1 - else: - self._ud_count = 0 - - if self._lr_delta >= _SENSITIVITY_1 : - self._lr_count = 1 - elif self._lr_delta <= -_SENSITIVITY_1 : - self._lr_count = -1 - else: - self._lr_count = 0 - - if self._ud_count == 0 and self._lr_count == 0 : - if abs(ud_delta) < _SENSITIVITY_2 and abs(lr_delta) < _SENSITIVITY_2 : - if ud_delta == 0 and lr_delta == 0 : - self._near_count += 1 - elif ud_delta != 0 and lr_delta != 0 : - self._far_count += 1 - - if self._near_count >= 10 and self._far_count >= 2 : - if ud_delta == 0 and lr_delta == 0 : - self._state = _NEAR_STATE - elif ud_delta != 0 and lr_delta != 0 : - self._state = _FAR_STATE - - return True - else: - if abs(ud_delta) < _SENSITIVITY_2 and abs(lr_delta) < _SENSITIVITY_2 : - if ud_delta == 0 and lr_delta == 0 : - self._near_count += 1 - - if self._near_count >= 10 : - self._ud_count = 0 - self._lr_count = 0 - self._ud_delta = 0 - self._lr_delta = 0 - - return False - - def decodegesture( self ) : - if self._state == _NEAR_STATE : - self._motion = _DIR_NEAR - return True - elif self._state == _FAR_STATE : - self._motion = _DIR_FAR - return True - - if self._ud_count == -1 and self._lr_count == 0 : - self._motion = _DIR_UP - elif self._ud_count == 1 and self._lr_count == 0 : - self._motion = _DIR_DOWN - elif self._ud_count == 0 and self._lr_count == 1 : - self._motion == _DIR_RIGHT - elif self._ud_count == 0 and self._lr_count == -1 : - self._motion == _DIR_LEFT - elif self._ud_count == -1 and self._lr_count == 1 : - if abs(self._ud_delta) > abs(self._lr_delta) : - self._motion = _DIR_UP - else: - self._motion = _DIR_RIGHT - elif self._ud_count == 1 and self._lr_count == -1 : - if abs(self._ud_delta) > abs(self._lr_delta) : - self._motion = _DIR_DOWN - else: - self._motion = _DIR_LEFT - elif self._ud_count == -1 and self._lr_count == -1 : - if abs(self._ud_delta) > abs(self._lr_delta) : - self._motion = _DIR_UP - else: - self._motion = _DIR_LEFT - elif self._ud_count == 1 and self._lr_count == 1 : - if abs(self._ud_delta) > abs(self._lr_delta) : - self._motion = _DIR_DOWN - else: - self._motion = _DIR_RIGHT - else: - return False - - return True - -# def calculatecolortemp( self, aRed, aGreen, aBlue ) : -# x = (-0.14282 * aRed) + (1.54924 * aGreen) + (-0.95641 * aBlue) -# y = self.calculatelux(aRed, aGreen, aBlue) -# z = (-0.68202 * aRed) + (0.77073 * aGreen) + (0.56332 * aBlue) -# -# den = x + y + z -# xc = x / den -# yc = y / den -# -# n = (xc - 0.332) / (0.1858 - yc) -# -# cct = (449.0 * pow(n, 3)) + (35250 * pow(n, 2)) + (6823.3 * n) + 5520.33 -# -# return cct -# -# def calculatelux( self, aRed, aGreen, aBlue ) : -# return (-0.32466 * aRed) + (1.57837 * aGreen) + (-0.73191 * aBlue) - diff --git a/src/drivers/APDS9960LITE.py b/src/drivers/APDS9960LITE.py deleted file mode 100644 index 1c2e5074a..000000000 --- a/src/drivers/APDS9960LITE.py +++ /dev/null @@ -1,457 +0,0 @@ -"""`APDS9960LITE` -==================================================== - -Low memory Driver class for the APDS9960 - - Author: Rune Langøy 2019 - - Licence GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html -""" -from time import sleep -from micropython import const -#APDS9960_ADDR = const(0x39) - -class I2CEX: - """micropython i2c adds functions for reading / writing byte to a register - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - - def __init__(self, - i2c, - address): - self.__i2c=i2c - self.__address=address - - def __regWriteBit(self,reg,bitPos,bitVal): - """Reads a I2C register byte changes a bit and writes the new value - - :param reg: The I2C register that is writen to - :type reg: int - - :param bitPos: The bit position (0 - 7) - :type bitPos: int - - :param value: True = set-bit / False =clear bit - :type value: bool - """ - val=self.__readByte(reg) # read reg - if bitVal == True: - val=val | (1<>8) & 0xff - self.__i2c.writeto_mem(self.__address,reg,b) - - def __read2Byte(self,reg): - """Reads a I2C byte from the address APDS9960_ADDR (0x39) - - :param reg: The I2C register to read - :type reg: int - - :returns: a value in the range (0- 65535) - :rtype: int - """ - val =self.__i2c.readfrom_mem(self.__address,reg, 2) - return int.from_bytes(val, 'little', True) - - - -class ALS(I2CEX): - """APDS9960 Digital Ambient Light Sense (ALS) and Color Sense (RGBC) functionalities - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - def __init__(self, - i2c): - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - def enableSensor(self,on=True): - """Enable/Disable the Light sensor - - :param on: Enables / Disables the Light sensor - (Default True) - :type on: bool - """ - AEN=1 #ALS enable bit 1 (AEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=AEN,bitVal=on) - - @property - def eLightGain(self): - """Sets the receiver gain for light measurements. - - :getter: Returns the reciever gain (0 -3) - :setter: Sets the reciever gain (0 -3) - :type: int - - :: - - eGain Gain - 0 1x - 1 2x - 2 16x - 3 64x - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val= val & 0b00000011 - return val - - @eLightGain.setter - def eLightGain(self, eGain): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - # set bits in register to given value - eGain &= 0b00000011 - val &= 0b11111100 - val |= eGain - - super().__writeByte(0x8f,val) - - - @property - def ambientLightLevel(self): - """Reads the APDS9960 ambient light level (apds9960 clear channel data) - - :getter: Returns the ambient light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x94) #returns CDATAL and CDATAH - - @property - def redLightLevel(self): - """Reads the APDS9960 red light level (apds9960 red channel data) - - :getter: Returns the red light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x96) #returns RDATAL and RDATAH - - @property - def greenLightLevel(self): - """Reads the APDS9960 green light level (apds9960 green channel data) - - :getter: Returns the green light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x98) #returns GDATAL and GDATAH - - @property - def blueLightLevel(self): - """Reads the APDS9960 blue light level (apds9960 blue channel data) - - :getter: Returns the blue light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x9A) #returns BDATAL and BDATAH - - def setInterruptThreshold(self,high=0,low=20,persistance=4): - """Enable/Disable the proimity sensor - - :param high: high level for generating light hardware interrupt (Range 0 - 1025) - :type high: int - - :param low: low level for generating light hardware interrupt (Range 0 - 1025) - :type low: int - - :param persistance: Number of consecutive reads before IRQ is raised (Range 0 - 7) - :type persistance: int - - """ - #ALS low threshold, lower byte - super().__write2Byte(0x84, low); #set ALS low threshold - super().__write2Byte(0x86, high); #set ALS low threshold - - - if (persistance>7) : - persistance=7 - - val=super().__readByte(0x8C) #APDS9960_PERS 0x8C<3:0> Proximity Interrupt Persistence - val=val & 0b11111000 # Clear APERS - val=val | persistance # Set APERS - super().__writeByte(0x8C,val) # Update APDS9960_PERS - - def clearInterrupt(self): - """Crears the proimity interrupt - IRQ HW output goes low (enables triggering of new IRQ) - """ - super().__readByte(0xe6) #All Non-Gesture Interrupt Clear - - def enableInterrupt(self,on=True): - """Enables/Disables IRQ dependent on limits given by setLightInterruptThreshold() - - :param on: Enable / Disable Hardware IRQ - :type on: bool - """ - #ENABLE 0x80<4> ALS Interrupt Enable - AIEN=4 #ALS Interrupt Enable bit 4 (AIEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=AIEN,bitVal=on) - self.clearInterrupt(); - - -class PROX(I2CEX): - """APDS9960 proximity functons - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - def __init__(self, - i2c): - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - def enableSensor(self,on=True): - """Enable/Disable the proimity sensor - - :param on: Enables / Disables the proximity sensor - (Default True) - :type on: bool - """ - # PEN - bit 2 - PEN=2 #Proximity enable bit 2 (PEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=PEN,bitVal=on) - - def setInterruptThreshold(self,high=0,low=20,persistance=4): - """Enable/Disable the proimity sensor - - :param high: high level for generating proximity hardware interrupt (Range 0 - 255) - :type high: int - - :param low: low level for generating proximity hardware interrupt (Range 0 - 255) - :type low: int - - :param persistance: Number of consecutive reads before IRQ is raised (Range 0 - 7) - :type persistance: int - - """ - super().__writeByte(0x89, low); #set low proximity threshold APDS9960_PILT - super().__writeByte(0x8B, high); #set high proximity threshold APDS9960_PIHT - - if (persistance>7) : - persistance=7 - - val=super().__readByte(0x8C) #APDS9960_PERS 0x8C<7:4> Proximity Interrupt Persistence - val=val & 0b00011111 # Clear PERS - val=val | (persistance << 4) # Set PERS - super().__writeByte(0x8C,val) # Update APDS9960_PERS - - def clearInterrupt(self): - """Crears the proimity interrupt - IRQ HW output goes low (enables triggering of new IRQ) - """ - super().__writeByte(0xE7,0) # APDS9960_AICLEAR clear all interrupts - super().__readByte(0xE5)#(APDS9960_PICLEAR) - - def enableInterrupt(self,on=True): - """Enables/Disables IRQ dependent on limits given by setProximityInterruptThreshold() - - :param on: Enable / Disable Hardware IRQ - :type on: bool - """ - PIEN=5 #Proximity interrupt enable bit 5 (PIEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=PIEN,bitVal=on) - self.clearInterrupt(); - - @property - def eProximityGain(self): - """Sets the receiver gain for proximity detection. - - :getter: Returns the reciever gain (0 -3) - :setter: Sets the reciever gain (0 -3) - :type: int - - :: - - eGain Gain - 0 1x - 1 2x - 2 4x - 3 8x - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val=((val >>2) & 0b00000011) - return val - - @eProximityGain.setter - def eProximityGain(self, eGain): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - # set bits in register to given value - eGain &= 0b00000011 - eGain = eGain << 2 - val &= 0b11110011 - val |= eGain - - #i2c.writeto_mem(APDS9960_ADDR,APDS9960_REG_CONTROL,bytes((val,))) - super().__writeByte(0x8f,val) - - @property - def eLEDCurrent(self): - """ - Sets LED current for proximity and ALS. - - :getter: Returns the LED current (0 -3) - :setter: Sets the LED current(0 -3) - :type: int - - :: - - eCurent LED Current - 0 100 mA - 1 50 mA - 2 25 mA - 3 12.5 mA - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val=val >>6 - return val - - - @eLEDCurrent.setter - def eLEDCurrent(self, eCurent): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - - # set bits in register to given value - eCurent &= 0b00000011 - eCurent = eCurent << 6 - val &= 0b00111111 - val |= eCurent - - super().__writeByte(0x8f,val) - - @property - def proximityLevel(self): - """Reads the APDS9960 proximity level - - :getter: Returns the proximity level (0 - 255 ) - :type: int - """ - return super().__readByte(0x9c) - - -class APDS9960LITE(I2CEX) : - """APDS9960LITE low memory driver for ASDS9960 - - :param i2c: The I2C driver - :type i2C: machine.i2c - - :example: - .. code:: python - - import machine - from uPy_APDS9960.APDS9960LITE import APDS9960LITE - - i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4)) # Creates I2C Driver on Pin 5 / 6 - adps9960=APDS9960LITE(i2c) # Create APDS9960 Driver - """ - def __init__(self, - i2c): - """Construct the APDS9960 driver class - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - self.powerOn(False) # APDS9960_ENABLE PON=0 - sleep(.05) - self.powerOn(True) # APDS9960_ENABLE PON=1 - self.prox=PROX(i2c) - self.als=ALS(i2c) - - prox = None - """Prvides APDS9960 Proximity functions.See class: :class:`.PROX` - - :type PROX: - - :example: - .. code:: python - - apds9960=APDS9960LITE(i2c) # Enable sensor - apds9960.prox.enableProximity() # Enable Proximit sensing - - """ - als = None - """Prvides APDS9960 Light sensor functions.See class: :class:`.ALS` - - :type PROX: - """ - def powerOn(self,on=True): - """Enable/Disable the apds9960 sensor - - :param on: Enables / Disables the proximity sensor - (Default True) - :type on: bool - """ - - PON=0 - super().__regWriteBit(reg=0x80,bitPos=PON,bitVal=on) - - - @property - def statusRegister(self): - """ - Status Register (0x93) - The read-only Status Register provides the status of the device. The register is set to 0x04 at power-up. - Returns the device status. - - :getter: Status register content byte - - ====== ===== ============================= - Field Bits Description - ====== ===== ============================= - CPSAT 7 Clear Photodiode Saturation. - PGSAT 6 Analog saturation event. - PINT 5 Proximity Interrupt. - AINT 4 ALS Interrupt. - DNC 3 Do not care. - GINT 2 Gesture Interrupt. - PVALID 1 Proximity Valid. - AVALID 0 ALS Valid. - ====== ===== ============================= - - :rtype: int - """ - return super().__readByte(0x93) \ No newline at end of file diff --git a/src/drivers/VL53L0X.py b/src/drivers/VL53L0X.py deleted file mode 100644 index b91eb2396..000000000 --- a/src/drivers/VL53L0X.py +++ /dev/null @@ -1,648 +0,0 @@ -from micropython import const -import ustruct -import utime -from machine import Timer -import time - -_IO_TIMEOUT = 1000 -_SYSRANGE_START = const(0x00) -_EXTSUP_HV = const(0x89) -_MSRC_CONFIG = const(0x60) -_FINAL_RATE_RTN_LIMIT = const(0x44) -_SYSTEM_SEQUENCE = const(0x01) -_SPAD_REF_START = const(0x4f) -_SPAD_ENABLES = const(0xb0) -_REF_EN_START_SELECT = const(0xb6) -_SPAD_NUM_REQUESTED = const(0x4e) -_INTERRUPT_GPIO = const(0x0a) -_INTERRUPT_CLEAR = const(0x0b) -_GPIO_MUX_ACTIVE_HIGH = const(0x84) -_RESULT_INTERRUPT_STATUS = const(0x13) -_RESULT_RANGE_STATUS = const(0x14) -_OSC_CALIBRATE = const(0xf8) -_MEASURE_PERIOD = const(0x04) - -SYSRANGE_START = 0x00 - -SYSTEM_THRESH_HIGH = 0x0C -SYSTEM_THRESH_LOW = 0x0E - -SYSTEM_SEQUENCE_CONFIG = 0x01 -SYSTEM_RANGE_CONFIG = 0x09 -SYSTEM_INTERMEASUREMENT_PERIOD = 0x04 - -SYSTEM_INTERRUPT_CONFIG_GPIO = 0x0A - -GPIO_HV_MUX_ACTIVE_HIGH = 0x84 - -SYSTEM_INTERRUPT_CLEAR = 0x0B - -RESULT_INTERRUPT_STATUS = 0x13 -RESULT_RANGE_STATUS = 0x14 - -RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN = 0xBC -RESULT_CORE_RANGING_TOTAL_EVENTS_RTN = 0xC0 -RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF = 0xD0 -RESULT_CORE_RANGING_TOTAL_EVENTS_REF = 0xD4 -RESULT_PEAK_SIGNAL_RATE_REF = 0xB6 - -ALGO_PART_TO_PART_RANGE_OFFSET_MM = 0x28 - -I2C_SLAVE_DEVICE_ADDRESS = 0x8A - -MSRC_CONFIG_CONTROL = 0x60 - -PRE_RANGE_CONFIG_MIN_SNR = 0x27 -PRE_RANGE_CONFIG_VALID_PHASE_LOW = 0x56 -PRE_RANGE_CONFIG_VALID_PHASE_HIGH = 0x57 -PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT = 0x64 - -FINAL_RANGE_CONFIG_MIN_SNR = 0x67 -FINAL_RANGE_CONFIG_VALID_PHASE_LOW = 0x47 -FINAL_RANGE_CONFIG_VALID_PHASE_HIGH = 0x48 -FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT = 0x44 - -PRE_RANGE_CONFIG_SIGMA_THRESH_HI = 0x61 -PRE_RANGE_CONFIG_SIGMA_THRESH_LO = 0x62 - -PRE_RANGE_CONFIG_VCSEL_PERIOD = 0x50 -PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x51 -PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x52 - -SYSTEM_HISTOGRAM_BIN = 0x81 -HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT = 0x33 -HISTOGRAM_CONFIG_READOUT_CTRL = 0x55 - -FINAL_RANGE_CONFIG_VCSEL_PERIOD = 0x70 -FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x71 -FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x72 -CROSSTALK_COMPENSATION_PEAK_RATE_MCPS = 0x20 - -MSRC_CONFIG_TIMEOUT_MACROP = 0x46 - -SOFT_RESET_GO2_SOFT_RESET_N = 0xBF -IDENTIFICATION_MODEL_ID = 0xC0 -IDENTIFICATION_REVISION_ID = 0xC2 - -OSC_CALIBRATE_VAL = 0xF8 - -GLOBAL_CONFIG_VCSEL_WIDTH = 0x32 -GLOBAL_CONFIG_SPAD_ENABLES_REF_0 = 0xB0 -GLOBAL_CONFIG_SPAD_ENABLES_REF_1 = 0xB1 -GLOBAL_CONFIG_SPAD_ENABLES_REF_2 = 0xB2 -GLOBAL_CONFIG_SPAD_ENABLES_REF_3 = 0xB3 -GLOBAL_CONFIG_SPAD_ENABLES_REF_4 = 0xB4 -GLOBAL_CONFIG_SPAD_ENABLES_REF_5 = 0xB5 - -GLOBAL_CONFIG_REF_EN_START_SELECT = 0xB6 -DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD = 0x4E -DYNAMIC_SPAD_REF_EN_START_OFFSET = 0x4F -POWER_MANAGEMENT_GO1_POWER_FORCE = 0x80 - -VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV = 0x89 - -ALGO_PHASECAL_LIM = 0x30 -ALGO_PHASECAL_CONFIG_TIMEOUT = 0x30 - - -class TimeoutError(RuntimeError): - pass - - -class VL53L0X: - def __init__(self, i2c, address=0x29): - self.i2c = i2c - self.address = address - self.init() - self._started = False - self.measurement_timing_budget_us = 0 - self.set_measurement_timing_budget(self.measurement_timing_budget_us) - self.enables = {"tcc": 0, - "dss": 0, - "msrc": 0, - "pre_range": 0, - "final_range": 0} - self.timeouts = {"pre_range_vcsel_period_pclks": 0, - "msrc_dss_tcc_mclks": 0, - "msrc_dss_tcc_us": 0, - "pre_range_mclks": 0, - "pre_range_us": 0, - "final_range_vcsel_period_pclks": 0, - "final_range_mclks": 0, - "final_range_us": 0 - } - self.vcsel_period_type = ["VcselPeriodPreRange", "VcselPeriodFinalRange"] - - def _registers(self, register, values=None, struct='B'): - if values is None: - size = ustruct.calcsize(struct) - data = self.i2c.readfrom_mem(self.address, register, size) - values = ustruct.unpack(struct, data) - return values - data = ustruct.pack(struct, *values) - self.i2c.writeto_mem(self.address, register, data) - - def _register(self, register, value=None, struct='B'): - if value is None: - return self._registers(register, struct=struct)[0] - self._registers(register, (value,), struct=struct) - - def _flag(self, register=0x00, bit=0, value=None): - data = self._register(register) - mask = 1 << bit - if value is None: - return bool(data & mask) - elif value: - data |= mask - else: - data &= ~mask - self._register(register, data) - - def _config(self, *config): - for register, value in config: - self._register(register, value) - - def init(self, power2v8=True): - self._flag(_EXTSUP_HV, 0, power2v8) - - # I2C standard mode - self._config( - (0x88, 0x00), - - (0x80, 0x01), - (0xff, 0x01), - (0x00, 0x00), - ) - self._stop_variable = self._register(0x91) - self._config( - (0x00, 0x01), - (0xff, 0x00), - (0x80, 0x00), - ) - - # disable signal_rate_msrc and signal_rate_pre_range limit checks - self._flag(_MSRC_CONFIG, 1, True) - self._flag(_MSRC_CONFIG, 4, True) - - # rate_limit = 0.25 - self._register(_FINAL_RATE_RTN_LIMIT, int(0.1 * (1 << 7)), - struct='>H') - - self._register(_SYSTEM_SEQUENCE, 0xff) - - spad_count, is_aperture = self._spad_info() - spad_map = bytearray(self._registers(_SPAD_ENABLES, struct='6B')) - - # set reference spads - self._config( - (0xff, 0x01), - (_SPAD_REF_START, 0x00), - (_SPAD_NUM_REQUESTED, 0x2c), - (0xff, 0x00), - (_REF_EN_START_SELECT, 0xb4), - ) - - spads_enabled = 0 - for i in range(48): - if i < 12 and is_aperture or spads_enabled >= spad_count: - spad_map[i // 8] &= ~(1 << (i >> 2)) - elif spad_map[i // 8] & (1 << (i >> 2)): - spads_enabled += 1 - - self._registers(_SPAD_ENABLES, spad_map, struct='6B') - - self._config( - (0xff, 0x01), - (0x00, 0x00), - - (0xff, 0x00), - (0x09, 0x00), - (0x10, 0x00), - (0x11, 0x00), - - (0x24, 0x01), - (0x25, 0xFF), - (0x75, 0x00), - - (0xFF, 0x01), - (0x4E, 0x2C), - (0x48, 0x00), - (0x30, 0x20), - - (0xFF, 0x00), - (0x30, 0x09), - (0x54, 0x00), - (0x31, 0x04), - (0x32, 0x03), - (0x40, 0x83), - (0x46, 0x25), - (0x60, 0x00), - (0x27, 0x00), - (0x50, 0x06), - (0x51, 0x00), - (0x52, 0x96), - (0x56, 0x08), - (0x57, 0x30), - (0x61, 0x00), - (0x62, 0x00), - (0x64, 0x00), - (0x65, 0x00), - (0x66, 0xA0), - - (0xFF, 0x01), - (0x22, 0x32), - (0x47, 0x14), - (0x49, 0xFF), - (0x4A, 0x00), - - (0xFF, 0x00), - (0x7A, 0x0A), - (0x7B, 0x00), - (0x78, 0x21), - - (0xFF, 0x01), - (0x23, 0x34), - (0x42, 0x00), - (0x44, 0xFF), - (0x45, 0x26), - (0x46, 0x05), - (0x40, 0x40), - (0x0E, 0x06), - (0x20, 0x1A), - (0x43, 0x40), - - (0xFF, 0x00), - (0x34, 0x03), - (0x35, 0x44), - - (0xFF, 0x01), - (0x31, 0x04), - (0x4B, 0x09), - (0x4C, 0x05), - (0x4D, 0x04), - - (0xFF, 0x00), - (0x44, 0x00), - (0x45, 0x20), - (0x47, 0x08), - (0x48, 0x28), - (0x67, 0x00), - (0x70, 0x04), - (0x71, 0x01), - (0x72, 0xFE), - (0x76, 0x00), - (0x77, 0x00), - - (0xFF, 0x01), - (0x0D, 0x01), - - (0xFF, 0x00), - (0x80, 0x01), - (0x01, 0xF8), - - (0xFF, 0x01), - (0x8E, 0x01), - (0x00, 0x01), - (0xFF, 0x00), - (0x80, 0x00), - ) - - self._register(_INTERRUPT_GPIO, 0x04) - self._flag(_GPIO_MUX_ACTIVE_HIGH, 4, False) - self._register(_INTERRUPT_CLEAR, 0x01) - - # XXX Need to implement this. - # budget = self._timing_budget() - # self._register(_SYSTEM_SEQUENCE, 0xe8) - # self._timing_budget(budget) - - self._register(_SYSTEM_SEQUENCE, 0x01) - self._calibrate(0x40) - self._register(_SYSTEM_SEQUENCE, 0x02) - self._calibrate(0x00) - - self._register(_SYSTEM_SEQUENCE, 0xe8) - - def _spad_info(self): - self._config( - (0x80, 0x01), - (0xff, 0x01), - (0x00, 0x00), - - (0xff, 0x06), - ) - self._flag(0x83, 3, True) - self._config( - (0xff, 0x07), - (0x81, 0x01), - - (0x80, 0x01), - - (0x94, 0x6b), - (0x83, 0x00), - ) - for timeout in range(_IO_TIMEOUT): - if self._register(0x83): - break - utime.sleep_ms(1) - else: - raise TimeoutError() - self._config( - (0x83, 0x01), - ) - value = self._register(0x92) - self._config( - (0x81, 0x00), - (0xff, 0x06), - ) - self._flag(0x83, 3, False) - self._config( - (0xff, 0x01), - (0x00, 0x01), - - (0xff, 0x00), - (0x80, 0x00), - ) - count = value & 0x7f - is_aperture = bool(value & 0b10000000) - return count, is_aperture - - def _calibrate(self, vhv_init_byte): - self._register(_SYSRANGE_START, 0x01 | vhv_init_byte) - for timeout in range(_IO_TIMEOUT): - if self._register(_RESULT_INTERRUPT_STATUS) & 0x07: - break - utime.sleep_ms(1) - else: - raise TimeoutError() - self._register(_INTERRUPT_CLEAR, 0x01) - self._register(_SYSRANGE_START, 0x00) - - def start(self, period=0): - self._config( - (0x80, 0x01), - (0xFF, 0x01), - (0x00, 0x00), - (0x91, self._stop_variable), - (0x00, 0x01), - (0xFF, 0x00), - (0x80, 0x00), - ) - if period: - oscilator = self._register(_OSC_CALIBRATE, struct='>H') - if oscilator: - period *= oscilator - self._register(_MEASURE_PERIOD, period, struct='>H') - self._register(_SYSRANGE_START, 0x04) - else: - self._register(_SYSRANGE_START, 0x02) - self._started = True - - def stop(self): - self._register(_SYSRANGE_START, 0x01) - self._config( - (0xFF, 0x01), - (0x00, 0x00), - (0x91, self._stop_variable), - (0x00, 0x01), - (0xFF, 0x00), - ) - self._started = False - - def read(self): - if not self._started: - self._config( - (0x80, 0x01), - (0xFF, 0x01), - (0x00, 0x00), - (0x91, self._stop_variable), - (0x00, 0x01), - (0xFF, 0x00), - (0x80, 0x00), - (_SYSRANGE_START, 0x01), - ) - for timeout in range(_IO_TIMEOUT): - if not self._register(_SYSRANGE_START) & 0x01: - break - utime.sleep_ms(1) - else: - raise TimeoutError() - for timeout in range(_IO_TIMEOUT): - if self._register(_RESULT_INTERRUPT_STATUS) & 0x07: - break - utime.sleep_ms(1) - else: - raise TimeoutError() - value = self._register(_RESULT_RANGE_STATUS + 10, struct='>H') - self._register(_INTERRUPT_CLEAR, 0x01) - return value - - def set_signal_rate_limit(self, limit_Mcps): - if limit_Mcps < 0 or limit_Mcps > 511.99: - return False - self._register(0x44, limit_Mcps * (1 << 7)) - return True - - def decode_Vcsel_period(self, reg_val): - return (((reg_val) + 1) << 1) - - def encode_Vcsel_period(self, period_pclks): - return (((period_pclks) >> 1) - 1) - - def set_Vcsel_pulse_period(self, type, period_pclks): - vcsel_period_reg = self.encode_Vcsel_period(period_pclks) - - self.get_sequence_step_enables() - self.get_sequence_step_timeouts() - - if type == self.vcsel_period_type[0]: - if period_pclks == 12: - self._register(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x18) - elif period_pclks == 14: - self._register(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x30) - elif period_pclks == 16: - self._register(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x40) - elif period_pclks == 18: - self._register(PRE_RANGE_CONFIG_VALID_PHASE_HIGH, 0x50) - else: - return False - - self._register(PRE_RANGE_CONFIG_VALID_PHASE_LOW, 0x08) - self._register(PRE_RANGE_CONFIG_VCSEL_PERIOD, vcsel_period_reg) - - new_pre_range_timeout_mclks = self.timeout_microseconds_to_Mclks(self.timeouts["pre_range_us"], - period_pclks) - self._register(PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI, self.encode_timeout(new_pre_range_timeout_mclks)) - - new_msrc_timeout_mclks = self.timeout_microseconds_to_Mclks(self.timeouts["msrc_dss_tcc_us"], - period_pclks) - self._register(MSRC_CONFIG_TIMEOUT_MACROP, 255 if new_msrc_timeout_mclks > 256 else (new_msrc_timeout_mclks - 1)) - elif type == self.vcsel_period_type[1]: - if period_pclks == 8: - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x10) - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08) - self._register(GLOBAL_CONFIG_VCSEL_WIDTH, 0x02) - self._(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x0C) - self._register(0xFF, 0x01) - self._register(ALGO_PHASECAL_LIM, 0x30) - self._register(0xFF, 0x00) - elif period_pclks == 10: - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x28) - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08) - self._register(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03) - self._register(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x09) - self._register(0xFF, 0x01) - self._register(ALGO_PHASECAL_LIM, 0x20) - self._register(0xFF, 0x00) - elif period_pclks == 12: - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x38) - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08) - self._register(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03) - self._register(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x08) - self._register(0xFF, 0x01) - self._register(ALGO_PHASECAL_LIM, 0x20) - self._register(0xFF, 0x00) - elif period_pclks == 14: - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_HIGH, 0x48) - self._register(FINAL_RANGE_CONFIG_VALID_PHASE_LOW, 0x08) - self._register(GLOBAL_CONFIG_VCSEL_WIDTH, 0x03) - self._register(ALGO_PHASECAL_CONFIG_TIMEOUT, 0x07) - self._register(0xFF, 0x01) - self._register(ALGO_PHASECAL_LIM, 0x20) - self._register(0xFF, 0x00) - else: - return False - - self._register(FINAL_RANGE_CONFIG_VCSEL_PERIOD, vcsel_period_reg) - - new_final_range_timeout_mclks = self.timeout_microseconds_to_Mclks(self.timeouts["final_range_us"], period_pclks) - - if self.enables["pre_range"]: - new_final_range_timeout_mclks += 1 - self._register(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI, self.encode_timeout(new_final_range_timeout_mclks)) - else: - return False - self.set_measurement_timing_budget(self.measurement_timing_budget_us) - sequence_config = self._register(SYSTEM_SEQUENCE_CONFIG) - self._register(SYSTEM_SEQUENCE_CONFIG, 0x02) - self.perform_single_ref_calibration(0x0) - self._register(SYSTEM_SEQUENCE_CONFIG, sequence_config) - - return True - - def get_sequence_step_enables(self): - sequence_config = self._register(0x01) - - self.enables["tcc"] = (sequence_config >> 4) & 0x1 - self.enables["dss"] = (sequence_config >> 3) & 0x1 - self.enables["msrc"] = (sequence_config >> 2) & 0x1 - self.enables["pre_range"] = (sequence_config >> 6) & 0x1 - self.enables["final_range"] = (sequence_config >> 7) & 0x1 - - def get_vcsel_pulse_period(self, type): - if type == self.vcsel_period_type[0]: - return self.decode_Vcsel_period(0x50) - elif type == self.vcsel_period_type[1]: - return self.decode_Vcsel_period(0x70) - else: - return 255 - - def get_sequence_step_timeouts(self): - self.timeouts["pre_range_vcsel_period_pclks"] = self.get_vcsel_pulse_period(self.vcsel_period_type[0]) - self.timeouts["msrc_dss_tcc_mclks"] = int(self._register(MSRC_CONFIG_TIMEOUT_MACROP)) + 1 - self.timeouts["msrc_dss_tcc_us"] = self.timeout_Mclks_to_microseconds(self.timeouts["msrc_dss_tcc_mclks"], - self.timeouts[ - "pre_range_vcsel_period_pclks"]) - self.timeouts["pre_range_mclks"] = self.decode_timeout(PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI) - self.timeouts["pre_range_us"] = self.timeout_Mclks_to_microseconds(self.timeouts["pre_range_mclks"], - self.timeouts[ - "pre_range_vcsel_period_pclks"]) - self.timeouts["final_range_vcsel_period_pclks"] = self.get_vcsel_pulse_period(self.vcsel_period_type[1]) - self.timeouts["final_range_mclks"] = self.decode_timeout(self._register(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI)) - - if self.enables["pre_range"]: - self.timeouts["final_range_mclks"] -= self.timeouts["pre_range_mclks"] - self.timeouts["final_range_us"] = self.timeout_Mclks_to_microseconds(self.timeouts["final_range_mclks"], - self.timeouts[ - "final_range_vcsel_period_pclks"]) - - def timeout_Mclks_to_microseconds(self, timeout_period_mclks, vcsel_period_pclks): - macro_period_ns = self.calc_macro_period(vcsel_period_pclks) - return ((timeout_period_mclks * macro_period_ns) + (macro_period_ns / 2)) / 1000 - - def timeout_microseconds_to_Mclks(self, timeout_period_us, vcsel_period_pclks): - macro_period_ns = self.calc_macro_period(vcsel_period_pclks) - return (((timeout_period_us * 1000) + (macro_period_ns / 2)) / macro_period_ns) - - def calc_macro_period(self, vcsel_period_pclks): - return (((2304 * (vcsel_period_pclks) * 1655) + 500) / 1000) - - def decode_timeout(self, reg_val): - return ((reg_val & 0x00FF) << ((reg_val & 0xFF00) >> 8)) + 1 - - def encode_timeout(self, timeout_mclks): - timeout_mclks = int(timeout_mclks) - ls_byte = 0 - ms_byte = 0 - - if timeout_mclks > 0: - ls_byte = timeout_mclks - 1 - - while (ls_byte & 0xFFFFFF00) > 0: - ls_byte >>= 1 - ms_byte += 1 - return (ms_byte << 8) or (ls_byte & 0xFF) - else: - return 0 - - def set_measurement_timing_budget(self, budget_us): - start_overhead = 1320 - end_overhead = 960 - msrc_overhead = 660 - tcc_overhead = 590 - dss_overhead = 690 - pre_range_overhead = 660 - final_range_overhead = 550 - - min_timing_budget = 20000 - - if budget_us < min_timing_budget: - return False - used_budget_us = start_overhead + end_overhead - - self.get_sequence_step_enables() - self.get_sequence_step_timeouts() - - if self.enables["tcc"]: - used_budget_us += self.timeouts["msrc_dss_tcc_us"] + tcc_overhead - if self.enables["dss"]: - used_budget_us += 2* self.timeouts["msrc_dss_tcc_us"] + dss_overhead - if self.enables["msrc"]: - used_budget_us += self.timeouts["msrc_dss_tcc_us"] + msrc_overhead - if self.enables["pre_range"]: - used_budget_us += self.timeouts["pre_range_us"] + pre_range_overhead - if self.enables["final_range"]: - used_budget_us += final_range_overhead - - if used_budget_us > budget_us: - return False - final_range_timeout_us = budget_us - used_budget_us - final_range_timeout_mclks = self.timeout_microseconds_to_Mclks(final_range_timeout_us, self.timeouts["final_range_vcsel_period_pclks"]) - - if self.enables["pre_range"]: - final_range_timeout_mclks += self.timeouts["pre_range_mclks"] - self._register(FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI, self.encode_timeout(final_range_timeout_mclks)) - self.measurement_timing_budget_us = budget_us - return True - - def perform_single_ref_calibration(self, vhv_init_byte): - chrono = Timer.Chrono() - self._register(SYSRANGE_START, 0x01|vhv_init_byte) - chrono.start() - while self._register((RESULT_INTERRUPT_STATUS & 0x07) == 0): - time_elapsed = chrono.read_ms() - if time_elapsed > _IO_TIMEOUT: - return False - self._register(SYSTEM_INTERRUPT_CLEAR, 0x01) - self._register(SYSRANGE_START, 0x00) - return True diff --git a/src/drivers/hcsr04.py b/src/drivers/hcsr04.py deleted file mode 100644 index d38aebd1c..000000000 --- a/src/drivers/hcsr04.py +++ /dev/null @@ -1,82 +0,0 @@ -from machine import Pin, time_pulse_us -from utime import sleep_us - -__version__ = '0.2.1' -__author__ = 'Roberto Sánchez' -__license__ = "Apache License 2.0. https://www.apache.org/licenses/LICENSE-2.0" - -class HCSR04: - """ - Driver to use the untrasonic sensor HC-SR04. - The sensor range is between 2cm and 4m. - - The timeouts received listening to echo pin are converted to OSError('Out of range') - - """ - # echo_timeout_us is based in chip range limit (400cm) - def __init__(self, trigger_pin, echo_pin, echo_timeout_us=500*2*30): - """ - trigger_pin: Output pin to send pulses - echo_pin: Readonly pin to measure the distance. The pin should be protected with 1k resistor - echo_timeout_us: Timeout in microseconds to listen to echo pin. - By default is based in sensor limit range (4m) - """ - self.echo_timeout_us = echo_timeout_us - # Init trigger pin (out) - self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None) - self.trigger.value(0) - - # Init echo pin (in) - self.echo = Pin(echo_pin, mode=Pin.IN, pull=None) - - def _send_pulse_and_wait(self): - """ - Send the pulse to trigger and listen on echo pin. - We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received. - """ - self.trigger.value(0) # Stabilize the sensor - sleep_us(5) - self.trigger.value(1) - # Send a 10us pulse. - sleep_us(10) - self.trigger.value(0) - try: - pulse_time = time_pulse_us(self.echo, 1, self.echo_timeout_us) - # time_pulse_us returns -2 if there was timeout waiting for condition; and -1 if there was timeout during the main measurement. It DOES NOT raise an exception - # ...as of MicroPython 1.17: http://docs.micropython.org/en/v1.17/library/machine.html#machine.time_pulse_us - if pulse_time < 0: - MAX_RANGE_IN_CM = const(500) # it's really ~400 but I've read people say they see it working up to ~460 - pulse_time = int(MAX_RANGE_IN_CM * 29.1) # 1cm each 29.1us - return pulse_time - except OSError as ex: - if ex.args[0] == 110: # 110 = ETIMEDOUT - raise OSError('Out of range') - raise ex - - def distance_mm(self): - """ - Get the distance in milimeters without floating point operations. - """ - pulse_time = self._send_pulse_and_wait() - - # To calculate the distance we get the pulse_time and divide it by 2 - # (the pulse walk the distance twice) and by 29.1 becasue - # the sound speed on air (343.2 m/s), that It's equivalent to - # 0.34320 mm/us that is 1mm each 2.91us - # pulse_time // 2 // 2.91 -> pulse_time // 5.82 -> pulse_time * 100 // 582 - mm = pulse_time * 100 // 582 - return mm - - def distance_cm(self): - """ - Get the distance in centimeters with floating point operations. - It returns a float - """ - pulse_time = self._send_pulse_and_wait() - - # To calculate the distance we get the pulse_time and divide it by 2 - # (the pulse walk the distance twice) and by 29.1 becasue - # the sound speed on air (343.2 m/s), that It's equivalent to - # 0.034320 cm/us that is 1cm each 29.1us - cms = (pulse_time / 2) / 29.1 - return cms \ No newline at end of file diff --git a/src/drivers/hmc5883l-new.py b/src/drivers/hmc5883l-new.py deleted file mode 100644 index cb505c121..000000000 --- a/src/drivers/hmc5883l-new.py +++ /dev/null @@ -1,122 +0,0 @@ -# .';:cc;. -# .,',;lol::c. -# ;';lddddlclo -# lcloxxoddodxdool:,. -# cxdddxdodxdkOkkkkkkkd:. -# .ldxkkOOOOkkOO000Okkxkkkkx:. -# .lddxkkOkOOO0OOO0000Okxxxxkkkk: -# 'ooddkkkxxkO0000KK00Okxdoodxkkkko -# .ooodxkkxxxOO000kkkO0KOxolooxkkxxkl -# lolodxkkxxkOx,. .lkdolodkkxxxO. -# doloodxkkkOk .... .,cxO; -# ddoodddxkkkk: ,oxxxkOdc'..o' -# :kdddxxxxd, ,lolccldxxxkkOOOkkkko, -# lOkxkkk; :xkkkkkkkkOOO000OOkkOOk. -# ;00Ok' 'O000OO0000000000OOOO0Od. -# .l0l.;OOO000000OOOOOO000000x, -# .'OKKKK00000000000000kc. -# .:ox0KKKKKKK0kdc,. -# ... -# -# Author: peppe8o -# https://peppe8o.com -# -# G-271 HMC5883L library to use magnetometer with Raspberry PI Pico (MicroPython) -# Ported from gvalkov/micropython-esp8266-hmc5883l code (ESP8266) -> https://github.com/gvalkov/micropython-esp8266-hmc5883l -# X and Y calibration offsets added - -import math -import machine - -from ustruct import pack -from array import array - -class HMC5883L: - __gain__ = { - '0.88': (0 << 5, 0.73), - '1.3': (1 << 5, 0.92), - '1.9': (2 << 5, 1.22), - '2.5': (3 << 5, 1.52), - '4.0': (4 << 5, 2.27), - '4.7': (5 << 5, 2.56), - '5.6': (6 << 5, 3.03), - '8.1': (7 << 5, 4.35) - } - - # Correction to be set after calibration - xs=1 - ys=1 - xb=0 - yb=0 - - def __init__(self, scl=15, sda=14, address=0x1e, gauss='1.9', declination=(0, 0)): - self.i2c = i2c = machine.SoftI2C(scl=machine.Pin(scl), sda=machine.Pin(sda), freq=15000) - - # Initialize sensor. - i2c.start() - - # Configuration register A: - # 0bx11xxxxx -> 8 samples averaged per measurement - # 0bxxx100xx -> 15 Hz, rate at which data is written to output registers - # 0bxxxxxx00 -> Normal measurement mode - i2c.writeto_mem(0x1e, 0x00, pack('B', 0b111000)) - - # Configuration register B: - reg_value, self.gain = self.__gain__[gauss] - i2c.writeto_mem(0x1e, 0x01, pack('B', reg_value)) - - # Set mode register to continuous mode. - i2c.writeto_mem(0x1e, 0x02, pack('B', 0x00)) - i2c.stop() - - # Convert declination (tuple of degrees and minutes) to radians. - self.declination = (declination[0] + declination[1] / 60) * math.pi / 180 - - # Reserve some memory for the raw xyz measurements. - self.data = array('B', [0] * 6) - - def read(self): - data = self.data - gain = self.gain - - self.i2c.readfrom_mem_into(0x1e, 0x03, data) - - x = (data[0] << 8) | data[1] - y = (data[4] << 8) | data[5] - z = (data[2] << 8) | data[3] - - x = x - (1 << 16) if x & (1 << 15) else x - y = y - (1 << 16) if y & (1 << 15) else y - z = z - (1 << 16) if z & (1 << 15) else z - - x = x * gain - y = y * gain - z = z * gain - - # Apply calibration corrections - x = x * self.xs + self.xb - y = y * self.ys + self.yb - - return x, y, z - - def heading(self, x, y): - heading_rad = math.atan2(y, x) - heading_rad += self.declination - - # Correct reverse heading. - if heading_rad < 0: - heading_rad += 2 * math.pi - - # Compensate for wrapping. - elif heading_rad > 2 * math.pi: - heading_rad -= 2 * math.pi - - # Convert from radians to degrees. - heading = heading_rad * 180 / math.pi - degrees = math.floor(heading) - minutes = round((heading - degrees) * 60) - return degrees, minutes - - def format_result(self, x, y, z): - degrees, minutes = self.heading(x, y) - return 'X: {:.4f}, Y: {:.4f}, Z: {:.4f}, Heading: {}° {}′ '.format(x, y, z, degrees, minutes) diff --git a/src/drivers/hmc5883l.py b/src/drivers/hmc5883l.py deleted file mode 100644 index 5d7afb78e..000000000 --- a/src/drivers/hmc5883l.py +++ /dev/null @@ -1,86 +0,0 @@ -import math -import machine - -from ustruct import pack -from array import array - - -class HMC5883L: - __gain__ = { - '0.88': (0 << 5, 0.73), - '1.3': (1 << 5, 0.92), - '1.9': (2 << 5, 1.22), - '2.5': (3 << 5, 1.52), - '4.0': (4 << 5, 2.27), - '4.7': (5 << 5, 2.56), - '5.6': (6 << 5, 3.03), - '8.1': (7 << 5, 4.35) - } - - def __init__(self, scl=4, sda=5, address=30, gauss='1.3', declination=(0, 0)): - self.i2c = i2c = machine.I2C(scl=machine.Pin(scl), sda=machine.Pin(sda), freq=100000) - - # Initialize sensor. - i2c.start() - - # Configuration register A: - # 0bx11xxxxx -> 8 samples averaged per measurement - # 0bxxx100xx -> 15 Hz, rate at which data is written to output registers - # 0bxxxxxx00 -> Normal measurement mode - i2c.writeto_mem(30, 0x00, pack('B', 0b111000)) - - # Configuration register B: - reg_value, self.gain = self.__gain__[gauss] - i2c.writeto_mem(30, 0x01, pack('B', reg_value)) - - # Set mode register to continuous mode. - i2c.writeto_mem(30, 0x02, pack('B', 0x00)) - i2c.stop() - - # Convert declination (tuple of degrees and minutes) to radians. - self.declination = (declination[0] + declination[1] / 60) * math.pi / 180 - - # Reserve some memory for the raw xyz measurements. - self.data = array('B', [0] * 6) - - def read(self): - data = self.data - gain = self.gain - - self.i2c.readfrom_mem_into(30, 0x03, data) - - x = (data[0] << 8) | data[1] - z = (data[2] << 8) | data[3] - y = (data[4] << 8) | data[5] - - x = x - (1 << 16) if x & (1 << 15) else x - y = y - (1 << 16) if y & (1 << 15) else y - z = z - (1 << 16) if z & (1 << 15) else z - - x = round(x * gain, 4) - y = round(y * gain, 4) - z = round(z * gain, 4) - - return x, y, z - - def heading(self, x, y): - heading_rad = math.atan2(y, x) - heading_rad += self.declination - - # Correct reverse heading. - if heading_rad < 0: - heading_rad += 2 * math.pi - - # Compensate for wrapping. - elif heading_rad > 2 * math.pi: - heading_rad -= 2 * math.pi - - # Convert from radians to degrees. - heading = heading_rad * 180 / math.pi - degrees = math.floor(heading) - minutes = round((heading - degrees) * 60) - return degrees, minutes - - def format_result(self, x, y, z): - degrees, minutes = self.heading(x, y) - return 'X: {:.4f}, Y: {:.4f}, Z: {:.4f}, Heading: {}° {}′ '.format(x, y, z, degrees, minutes) \ No newline at end of file diff --git a/src/drivers/lcd160cr.py b/src/drivers/lcd160cr.py deleted file mode 100644 index f792418aa..000000000 --- a/src/drivers/lcd160cr.py +++ /dev/null @@ -1,482 +0,0 @@ -# Driver for official MicroPython LCD160CR display -# MIT license; Copyright (c) 2017 Damien P. George - -from micropython import const -from utime import sleep_ms -from ustruct import calcsize, pack_into -import uerrno, machine - -# for set_orient -PORTRAIT = const(0) -LANDSCAPE = const(1) -PORTRAIT_UPSIDEDOWN = const(2) -LANDSCAPE_UPSIDEDOWN = const(3) - -# for set_startup_deco; can be or'd -STARTUP_DECO_NONE = const(0) -STARTUP_DECO_MLOGO = const(1) -STARTUP_DECO_INFO = const(2) - -_uart_baud_table = { - 2400: 0, - 4800: 1, - 9600: 2, - 19200: 3, - 38400: 4, - 57600: 5, - 115200: 6, - 230400: 7, - 460800: 8, -} - - -class LCD160CR: - def __init__(self, connect=None, *, pwr=None, i2c=None, spi=None, i2c_addr=98): - if connect in ("X", "Y", "XY", "YX"): - i = connect[-1] - j = connect[0] - y = j + "4" - elif connect == "C": - i = 2 - j = 2 - y = "A7" - else: - if pwr is None or i2c is None or spi is None: - raise ValueError('must specify valid "connect" or all of "pwr", "i2c" and "spi"') - - if pwr is None: - pwr = machine.Pin(y, machine.Pin.OUT) - if i2c is None: - i2c = machine.I2C(i, freq=1000000) - if spi is None: - spi = machine.SPI(j, baudrate=13500000, polarity=0, phase=0) - - if not pwr.value(): - pwr(1) - sleep_ms(10) - # else: - # alread have power - # lets be optimistic... - - # set connections - self.pwr = pwr - self.i2c = i2c - self.spi = spi - self.i2c_addr = i2c_addr - - # create temp buffers and memoryviews - self.buf16 = bytearray(16) - self.buf19 = bytearray(19) - self.buf = [None] * 10 - for i in range(1, 10): - self.buf[i] = memoryview(self.buf16)[0:i] - self.buf1 = self.buf[1] - self.array4 = [0, 0, 0, 0] - - # set default orientation and window - self.set_orient(PORTRAIT) - self._fcmd2b("= n: - self.i2c.readfrom_into(self.i2c_addr, buf) - return - t -= 1 - sleep_ms(1) - raise OSError(uerrno.ETIMEDOUT) - - def oflush(self, n=255): - t = 5000 - while t: - self.i2c.readfrom_into(self.i2c_addr + 1, self.buf1) - r = self.buf1[0] - if r >= n: - return - t -= 1 - machine.idle() - raise OSError(uerrno.ETIMEDOUT) - - def iflush(self): - t = 5000 - while t: - self.i2c.readfrom_into(self.i2c_addr, self.buf16) - if self.buf16[0] == 0: - return - t -= 1 - sleep_ms(1) - raise OSError(uerrno.ETIMEDOUT) - - #### MISC METHODS #### - - @staticmethod - def rgb(r, g, b): - return ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3) - - @staticmethod - def clip_line(c, w, h): - while True: - ca = ce = 0 - if c[1] < 0: - ca |= 8 - elif c[1] > h: - ca |= 4 - if c[0] < 0: - ca |= 1 - elif c[0] > w: - ca |= 2 - if c[3] < 0: - ce |= 8 - elif c[3] > h: - ce |= 4 - if c[2] < 0: - ce |= 1 - elif c[2] > w: - ce |= 2 - if ca & ce: - return False - elif ca | ce: - ca |= ce - if ca & 1: - if c[2] < c[0]: - c[0], c[2] = c[2], c[0] - c[1], c[3] = c[3], c[1] - c[1] += ((-c[0]) * (c[3] - c[1])) // (c[2] - c[0]) - c[0] = 0 - elif ca & 2: - if c[2] < c[0]: - c[0], c[2] = c[2], c[0] - c[1], c[3] = c[3], c[1] - c[3] += ((w - 1 - c[2]) * (c[3] - c[1])) // (c[2] - c[0]) - c[2] = w - 1 - elif ca & 4: - if c[0] == c[2]: - if c[1] >= h: - c[1] = h - 1 - if c[3] >= h: - c[3] = h - 1 - else: - if c[3] < c[1]: - c[0], c[2] = c[2], c[0] - c[1], c[3] = c[3], c[1] - c[2] += ((h - 1 - c[3]) * (c[2] - c[0])) // (c[3] - c[1]) - c[3] = h - 1 - else: - if c[0] == c[2]: - if c[1] < 0: - c[1] = 0 - if c[3] < 0: - c[3] = 0 - else: - if c[3] < c[1]: - c[0], c[2] = c[2], c[0] - c[1], c[3] = c[3], c[1] - c[0] += ((-c[1]) * (c[2] - c[0])) // (c[3] - c[1]) - c[1] = 0 - else: - return True - - #### SETUP COMMANDS #### - - def set_power(self, on): - self.pwr(on) - sleep_ms(15) - - def set_orient(self, orient): - self._fcmd2("= 2: - self.i2c.readfrom_into(self.i2c_addr, self.buf[3]) - return self.buf[3][1] | self.buf[3][2] << 8 - t -= 1 - sleep_ms(1) - raise OSError(uerrno.ETIMEDOUT) - - def get_line(self, x, y, buf): - l = len(buf) // 2 - self._fcmd2b("= l: - self.i2c.readfrom_into(self.i2c_addr, buf) - return - t -= 1 - sleep_ms(1) - raise OSError(uerrno.ETIMEDOUT) - - def screen_dump(self, buf, x=0, y=0, w=None, h=None): - if w is None: - w = self.w - x - if h is None: - h = self.h - y - if w <= 127: - line = bytearray(2 * w + 1) - line2 = None - else: - # split line if more than 254 bytes needed - buflen = (w + 1) // 2 - line = bytearray(2 * buflen + 1) - line2 = memoryview(line)[: 2 * (w - buflen) + 1] - for i in range(min(len(buf) // (2 * w), h)): - ix = i * w * 2 - self.get_line(x, y + i, line) - buf[ix : ix + len(line) - 1] = memoryview(line)[1:] - ix += len(line) - 1 - if line2: - self.get_line(x + buflen, y + i, line2) - buf[ix : ix + len(line2) - 1] = memoryview(line2)[1:] - ix += len(line2) - 1 - - def screen_load(self, buf): - l = self.w * self.h * 2 + 2 - self._fcmd2b("= 0x200: - self._send(ar[n : n + 0x200]) - n += 0x200 - else: - self._send(ar[n:]) - while n < self.w * self.h * 2: - self._send(b"\x00") - n += 1 - - #### TEXT COMMANDS #### - - def set_pos(self, x, y): - self._fcmd2("= self.w or y >= self.h: - return - elif x < 0 or y < 0: - left = top = True - if x < 0: - left = False - w += x - x = 0 - if y < 0: - top = False - h += y - y = 0 - if cmd == 0x51 or cmd == 0x72: - # draw interior - self._fcmd2b("> 7 != 0 - - def get_touch(self): - self._send(b"\x02T") # implicit LCD output flush - b = self.buf[4] - self._waitfor(3, b) - return b[1] >> 7, b[2], b[3] - - #### ADVANCED COMMANDS #### - - def set_spi_win(self, x, y, w, h): - pack_into( - " 32: - raise ValueError("length must be 32 or less") - self._fcmd2(" 0xFFFF: - raise ValueError("length must be 65535 or less") - self.oflush() - self._fcmd2(" move cursor) - LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left) - - LCD_FUNCTION = 0x20 # DB5: function set - LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode) - LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line) - LCD_FUNCTION_10DOTS = 0x04 # --DB2: 5x10 font (0->5x7 font) - LCD_FUNCTION_RESET = 0x30 # See "Initializing by Instruction" section - - LCD_CGRAM = 0x40 # DB6: set CG RAM address - LCD_DDRAM = 0x80 # DB7: set DD RAM address - - LCD_RS_CMD = 0 - LCD_RS_DATA = 1 - - LCD_RW_WRITE = 0 - LCD_RW_READ = 1 - - def __init__(self, num_lines, num_columns): - self.num_lines = num_lines - if self.num_lines > 4: - self.num_lines = 4 - self.num_columns = num_columns - if self.num_columns > 40: - self.num_columns = 40 - self.cursor_x = 0 - self.cursor_y = 0 - self.implied_newline = False - self.backlight = True - self.display_off() - self.backlight_on() - self.clear() - self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC) - self.hide_cursor() - self.display_on() - - def clear(self): - """Clears the LCD display and moves the cursor to the top left - corner. - """ - self.hal_write_command(self.LCD_CLR) - self.hal_write_command(self.LCD_HOME) - self.cursor_x = 0 - self.cursor_y = 0 - - def show_cursor(self): - """Causes the cursor to be made visible.""" - self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | - self.LCD_ON_CURSOR) - - def hide_cursor(self): - """Causes the cursor to be hidden.""" - self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) - - def blink_cursor_on(self): - """Turns on the cursor, and makes it blink.""" - self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | - self.LCD_ON_CURSOR | self.LCD_ON_BLINK) - - def blink_cursor_off(self): - """Turns on the cursor, and makes it no blink (i.e. be solid).""" - self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | - self.LCD_ON_CURSOR) - - def display_on(self): - """Turns on (i.e. unblanks) the LCD.""" - self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) - - def display_off(self): - """Turns off (i.e. blanks) the LCD.""" - self.hal_write_command(self.LCD_ON_CTRL) - - def backlight_on(self): - """Turns the backlight on. - - This isn't really an LCD command, but some modules have backlight - controls, so this allows the hal to pass through the command. - """ - self.backlight = True - self.hal_backlight_on() - - def backlight_off(self): - """Turns the backlight off. - - This isn't really an LCD command, but some modules have backlight - controls, so this allows the hal to pass through the command. - """ - self.backlight = False - self.hal_backlight_off() - - def move_to(self, cursor_x, cursor_y): - """Moves the cursor position to the indicated position. The cursor - position is zero based (i.e. cursor_x == 0 indicates first column). - """ - self.cursor_x = cursor_x - self.cursor_y = cursor_y - addr = cursor_x & 0x3f - if cursor_y & 1: - addr += 0x40 # Lines 1 & 3 add 0x40 - if cursor_y & 2: # Lines 2 & 3 add number of columns - addr += self.num_columns - self.hal_write_command(self.LCD_DDRAM | addr) - - def putchar(self, char): - """Writes the indicated character to the LCD at the current cursor - position, and advances the cursor by one position. - """ - if char == '\n': - if self.implied_newline: - # self.implied_newline means we advanced due to a wraparound, - # so if we get a newline right after that we ignore it. - self.implied_newline = False - else: - self.cursor_x = self.num_columns - else: - self.hal_write_data(ord(char)) - self.cursor_x += 1 - if self.cursor_x >= self.num_columns: - self.cursor_x = 0 - self.cursor_y += 1 - self.implied_newline = (char != '\n') - if self.cursor_y >= self.num_lines: - self.cursor_y = 0 - self.move_to(self.cursor_x, self.cursor_y) - - def putstr(self, string): - """Write the indicated string to the LCD at the current cursor - position and advances the cursor position appropriately. - """ - for char in string: - self.putchar(char) - - def custom_char(self, location, charmap): - """Write a character to one of the 8 CGRAM locations, available - as chr(0) through chr(7). - """ - location &= 0x7 - self.hal_write_command(self.LCD_CGRAM | (location << 3)) - self.hal_sleep_us(40) - for i in range(8): - self.hal_write_data(charmap[i]) - self.hal_sleep_us(40) - self.move_to(self.cursor_x, self.cursor_y) - - def hal_backlight_on(self): - """Allows the hal layer to turn the backlight on. - - If desired, a derived HAL class will implement this function. - """ - pass - - def hal_backlight_off(self): - """Allows the hal layer to turn the backlight off. - - If desired, a derived HAL class will implement this function. - """ - pass - - def hal_write_command(self, cmd): - """Write a command to the LCD. - - It is expected that a derived HAL class will implement this - function. - """ - raise NotImplementedError - - def hal_write_data(self, data): - """Write data to the LCD. - - It is expected that a derived HAL class will implement this - function. - """ - raise NotImplementedError - - # This is a default implementation of hal_sleep_us which is suitable - # for most micropython implementations. For platforms which don't - # support `time.sleep_us()` they should provide their own implementation - # of hal_sleep_us in their hal layer and it will be used instead. - def hal_sleep_us(self, usecs): - """Sleep for some time (given in microseconds).""" - time.sleep_us(usecs) # NOTE this is not part of Standard Python library, specific hal layers will need to override this \ No newline at end of file diff --git a/src/drivers/max7219.py b/src/drivers/max7219.py deleted file mode 100644 index 3817914ab..000000000 --- a/src/drivers/max7219.py +++ /dev/null @@ -1,99 +0,0 @@ -""" -MicroPython max7219 cascadable 8x8 LED matrix driver -https://github.com/mcauser/micropython-max7219 - -MIT License -Copyright (c) 2017 Mike Causer - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" - -from micropython import const -import framebuf - -_NOOP = const(0) -_DIGIT0 = const(1) -_DECODEMODE = const(9) -_INTENSITY = const(10) -_SCANLIMIT = const(11) -_SHUTDOWN = const(12) -_DISPLAYTEST = const(15) - -class Matrix8x8: - def __init__(self, spi, cs, num): - """ - Driver for cascading MAX7219 8x8 LED matrices. - - >>> import max7219 - >>> from machine import Pin, SPI - >>> spi = SPI(1) - >>> display = max7219.Matrix8x8(spi, Pin('X5'), 4) - >>> display.text('1234',0,0,1) - >>> display.show() - - """ - self.spi = spi - self.cs = cs - self.cs.init(cs.OUT, True) - self.buffer = bytearray(8 * num) - self.num = num - fb = framebuf.FrameBuffer(self.buffer, 8 * num, 8, framebuf.MONO_HLSB) - self.framebuf = fb - # Provide methods for accessing FrameBuffer graphics primitives. This is a workround - # because inheritance from a native class is currently unsupported. - # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html - self.fill = fb.fill # (col) - self.pixel = fb.pixel # (x, y[, c]) - self.hline = fb.hline # (x, y, w, col) - self.vline = fb.vline # (x, y, h, col) - self.line = fb.line # (x1, y1, x2, y2, col) - self.rect = fb.rect # (x, y, w, h, col) - self.fill_rect = fb.fill_rect # (x, y, w, h, col) - self.text = fb.text # (string, x, y, col=1) - self.scroll = fb.scroll # (dx, dy) - self.blit = fb.blit # (fbuf, x, y[, key]) - self.init() - - def _write(self, command, data): - self.cs(0) - for m in range(self.num): - self.spi.write(bytearray([command, data])) - self.cs(1) - - def init(self): - for command, data in ( - (_SHUTDOWN, 0), - (_DISPLAYTEST, 0), - (_SCANLIMIT, 7), - (_DECODEMODE, 0), - (_SHUTDOWN, 1), - ): - self._write(command, data) - - def brightness(self, value): - if not 0 <= value <= 15: - raise ValueError("Brightness out of range") - self._write(_INTENSITY, value) - - def show(self): - for y in range(8): - self.cs(0) - for m in range(self.num): - self.spi.write(bytearray([_DIGIT0 + y, self.buffer[(y * self.num) + m]])) - self.cs(1) \ No newline at end of file diff --git a/src/drivers/mpu9250.py b/src/drivers/mpu9250.py deleted file mode 100644 index 9f58ad12b..000000000 --- a/src/drivers/mpu9250.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2018-2020 Mika Tuupola -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copied of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -# https://github.com/tuupola/micropython-mpu9250 - -""" -MicroPython I2C driver for MPU9250 9-axis motion tracking device -""" - -# pylint: disable=import-error -from micropython import const -from mpu6500 import MPU6500 -from ak8963 import AK8963 -# pylint: enable=import-error - -__version__ = "0.3.0" - -# Used for enabling and disabling the I2C bypass access -_INT_PIN_CFG = const(0x37) -_I2C_BYPASS_MASK = const(0b00000010) -_I2C_BYPASS_EN = const(0b00000010) -_I2C_BYPASS_DIS = const(0b00000000) - -class MPU9250: - """Class which provides interface to MPU9250 9-axis motion tracking device.""" - def __init__(self, i2c, mpu6500 = None, ak8963 = None): - if mpu6500 is None: - self.mpu6500 = MPU6500(i2c) - else: - self.mpu6500 = mpu6500 - - # Enable I2C bypass to access AK8963 directly. - char = self.mpu6500._register_char(_INT_PIN_CFG) - char &= ~_I2C_BYPASS_MASK # clear I2C bits - char |= _I2C_BYPASS_EN - self.mpu6500._register_char(_INT_PIN_CFG, char) - - if ak8963 is None: - self.ak8963 = AK8963(i2c) - else: - self.ak8963 = ak8963 - - @property - def acceleration(self): - """ - Acceleration measured by the sensor. By default will return a - 3-tuple of X, Y, Z axis values in m/s^2 as floats. To get values in g - pass `accel_fs=SF_G` parameter to the MPU6500 constructor. - """ - return self.mpu6500.acceleration - - @property - def gyro(self): - """ - Gyro measured by the sensor. By default will return a 3-tuple of - X, Y, Z axis values in rad/s as floats. To get values in deg/s pass - `gyro_sf=SF_DEG_S` parameter to the MPU6500 constructor. - """ - return self.mpu6500.gyro - - @property - def temperature(self): - """ - Die temperature in celcius as a float. - """ - return self.mpu6500.temperature - - @property - def magnetic(self): - """ - X, Y, Z axis micro-Tesla (uT) as floats. - """ - return self.ak8963.magnetic - - @property - def whoami(self): - return self.mpu6500.whoami - - def __enter__(self): - return self - - def __exit__(self, exception_type, exception_value, traceback): - pass \ No newline at end of file diff --git a/src/drivers/neopixelgrb.py b/src/drivers/neopixelgrb.py deleted file mode 100644 index 2627dfeef..000000000 --- a/src/drivers/neopixelgrb.py +++ /dev/null @@ -1,49 +0,0 @@ -# NeoPixel driver for MicroPython -# MIT license; Copyright (c) 2016 Damien P. George, 2021 Jim Mussared - -from machine import bitstream - -class NeoPixel2: - # G R B W - ORDER = (0, 1, 2, 3) - - def __init__(self, pin, n, bpp=3, timing=1): - self.pin = pin - self.n = n - self.bpp = bpp - self.buf = bytearray(n * bpp) - self.pin.init(pin.OUT) - # Timing arg can either be 1 for 800kHz or 0 for 400kHz, - # or a user-specified timing ns tuple (high_0, low_0, high_1, low_1). - self.timing = ( - ((400, 850, 800, 450) if timing else (800, 1700, 1600, 900)) - if isinstance(timing, int) - else timing - ) - - def __len__(self): - return self.n - - def __setitem__(self, i, v): - offset = i * self.bpp - for i in range(self.bpp): - self.buf[offset + self.ORDER[i]] = v[i] - - def __getitem__(self, i): - offset = i * self.bpp - return tuple(self.buf[offset + self.ORDER[i]] for i in range(self.bpp)) - - def fill(self, v): - b = self.buf - l = len(self.buf) - bpp = self.bpp - for i in range(bpp): - c = v[i] - j = self.ORDER[i] - while j < l: - b[j] = c - j += bpp - - def write(self): - # BITSTREAM_TYPE_HIGH_LOW = 0 - bitstream(self.pin, 0, self.timing, self.buf) diff --git a/src/drivers/pico_i2c_lcd.py b/src/drivers/pico_i2c_lcd.py deleted file mode 100644 index 8b02619d3..000000000 --- a/src/drivers/pico_i2c_lcd.py +++ /dev/null @@ -1,86 +0,0 @@ -import utime -import gc - -from lcd_api import LcdApi -from machine import I2C - -# PCF8574 pin definitions -MASK_RS = 0x01 # P0 -MASK_RW = 0x02 # P1 -MASK_E = 0x04 # P2 - -SHIFT_BACKLIGHT = 3 # P3 -SHIFT_DATA = 4 # P4-P7 - -class I2cLcd(LcdApi): - - #Implements a HD44780 character LCD connected via PCF8574 on I2C - - def __init__(self, i2c, i2c_addr, num_lines, num_columns): - self.i2c = i2c - self.i2c_addr = i2c_addr - self.i2c.writeto(self.i2c_addr, bytes([0])) - utime.sleep_ms(20) # Allow LCD time to powerup - # Send reset 3 times - self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) - utime.sleep_ms(5) # Need to delay at least 4.1 msec - self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) - utime.sleep_ms(1) - self.hal_write_init_nibble(self.LCD_FUNCTION_RESET) - utime.sleep_ms(1) - # Put LCD into 4-bit mode - self.hal_write_init_nibble(self.LCD_FUNCTION) - utime.sleep_ms(1) - LcdApi.__init__(self, num_lines, num_columns) - cmd = self.LCD_FUNCTION - if num_lines > 1: - cmd |= self.LCD_FUNCTION_2LINES - self.hal_write_command(cmd) - gc.collect() - - def hal_write_init_nibble(self, nibble): - # Writes an initialization nibble to the LCD. - # This particular function is only used during initialization. - byte = ((nibble >> 4) & 0x0f) << SHIFT_DATA - self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) - self.i2c.writeto(self.i2c_addr, bytes([byte])) - gc.collect() - - def hal_backlight_on(self): - # Allows the hal layer to turn the backlight on - self.i2c.writeto(self.i2c_addr, bytes([1 << SHIFT_BACKLIGHT])) - gc.collect() - - def hal_backlight_off(self): - #Allows the hal layer to turn the backlight off - self.i2c.writeto(self.i2c_addr, bytes([0])) - gc.collect() - - def hal_write_command(self, cmd): - # Write a command to the LCD. Data is latched on the falling edge of E. - byte = ((self.backlight << SHIFT_BACKLIGHT) | - (((cmd >> 4) & 0x0f) << SHIFT_DATA)) - self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) - self.i2c.writeto(self.i2c_addr, bytes([byte])) - byte = ((self.backlight << SHIFT_BACKLIGHT) | - ((cmd & 0x0f) << SHIFT_DATA)) - self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) - self.i2c.writeto(self.i2c_addr, bytes([byte])) - if cmd <= 3: - # The home and clear commands require a worst case delay of 4.1 msec - utime.sleep_ms(5) - gc.collect() - - def hal_write_data(self, data): - # Write data to the LCD. Data is latched on the falling edge of E. - byte = (MASK_RS | - (self.backlight << SHIFT_BACKLIGHT) | - (((data >> 4) & 0x0f) << SHIFT_DATA)) - self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) - self.i2c.writeto(self.i2c_addr, bytes([byte])) - byte = (MASK_RS | - (self.backlight << SHIFT_BACKLIGHT) | - ((data & 0x0f) << SHIFT_DATA)) - self.i2c.writeto(self.i2c_addr, bytes([byte | MASK_E])) - self.i2c.writeto(self.i2c_addr, bytes([byte])) - gc.collect() \ No newline at end of file diff --git a/src/drivers/rotary.py b/src/drivers/rotary.py deleted file mode 100644 index 2608dc252..000000000 --- a/src/drivers/rotary.py +++ /dev/null @@ -1,61 +0,0 @@ -import machine -import utime as time -from machine import Pin -import micropython - -class Rotary: - - ROT_CW = 1 - ROT_CCW = 2 - SW_PRESS = 4 - SW_RELEASE = 8 - - def __init__(self, dt, clk, sw): - self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN) - self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN) - self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN) - self.last_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - self.dt_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.clk_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.sw_pin.irq(handler=self.switch_detect, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.handlers = [] - self.last_button_status = self.sw_pin.value() - - def rotary_change(self, pin): - new_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - if new_status == self.last_status: - return - transition = (self.last_status << 2) | new_status - if transition == 0b1110: - try: - micropython.schedule(self.call_handlers, Rotary.ROT_CW) - except RuntimeError: - pass # ignore the error - elif transition == 0b1101: - try: - micropython.schedule(self.call_handlers, Rotary.ROT_CCW) - except RuntimeError: - pass # ignore the error - self.last_status = new_status - - def switch_detect(self,pin): - if self.last_button_status == self.sw_pin.value(): - return - self.last_button_status = self.sw_pin.value() - if self.sw_pin.value(): - micropython.schedule(self.call_handlers, Rotary.SW_RELEASE) - else: - micropython.schedule(self.call_handlers, Rotary.SW_PRESS) - - def add_handler(self, handler): - self.handlers.append(handler) - - def call_handlers(self, type): - for handler in self.handlers: - handler(type) - -#try: -# if old_value != self._value and len(self._listener) != 0: -# micropython.schedule(_trigger, self) -# except RuntimeError: -# self._value = 1 if not self.value else 0 \ No newline at end of file diff --git a/src/drivers/sh1106.py b/src/drivers/sh1106.py deleted file mode 100644 index 7c932b9df..000000000 --- a/src/drivers/sh1106.py +++ /dev/null @@ -1,236 +0,0 @@ -# -# MicroPython SH1106 OLED driver, I2C and SPI interfaces -# -# The MIT License (MIT) -# -# Copyright (c) 2016 Radomir Dopieralski (@deshipu), -# 2017-2021 Robert Hammelrath (@robert-hh) -# 2021 Tim Weber (@scy) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Sample code sections for ESP8266 pin assignments -# ------------ SPI ------------------ -# Pin Map SPI -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D7 - GPIO 13 - Din / MOSI fixed -# - D5 - GPIO 14 - Clk / Sck fixed -# - D8 - GPIO 4 - CS (optional, if the only connected device) -# - D2 - GPIO 5 - D/C -# - D1 - GPIO 2 - Res -# -# for CS, D/C and Res other ports may be chosen. -# -# from machine import Pin, SPI -# import sh1106 - -# spi = SPI(1, baudrate=1000000) -# display = sh1106.SH1106_SPI(128, 64, spi, Pin(5), Pin(2), Pin(4)) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() -# -# --------------- I2C ------------------ -# -# Pin Map I2C -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D2 - GPIO 5 - SCK / SCL -# - D1 - GPIO 4 - DIN / SDA -# - D0 - GPIO 16 - Res -# - G - xxxxxx CS -# - G - xxxxxx D/C -# -# Pin's for I2C can be set almost arbitrary -# -# from machine import Pin, I2C -# import sh1106 -# -# i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) -# display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() - -from micropython import const -import utime as time -import framebuf - - -# a few register definitions -_SET_CONTRAST = const(0x81) -_SET_NORM_INV = const(0xa6) -_SET_DISP = const(0xae) -_SET_SCAN_DIR = const(0xc0) -_SET_SEG_REMAP = const(0xa0) -_LOW_COLUMN_ADDRESS = const(0x00) -_HIGH_COLUMN_ADDRESS = const(0x10) -_SET_PAGE_ADDRESS = const(0xB0) - - -class SH1106(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc, rotate=0): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.flip_en = rotate == 180 or rotate == 270 - self.rotate90 = rotate == 90 or rotate == 270 - self.pages = self.height // 8 - self.bufsize = self.pages * self.width - self.renderbuf = bytearray(self.bufsize) - if self.rotate90: - self.displaybuf = bytearray(self.bufsize) - # HMSB is required to keep the bit order in the render buffer - # compatible with byte-for-byte remapping to the display buffer, - # which is in VLSB. Else we'd have to copy bit-by-bit! - super().__init__(self.renderbuf, self.height, self.width, - framebuf.MONO_HMSB) - else: - self.displaybuf = self.renderbuf - super().__init__(self.renderbuf, self.width, self.height, - framebuf.MONO_VLSB) - - # flip() was called rotate() once, provide backwards compatibility. - self.rotate = self.flip - self.init_display() - - def init_display(self): - self.reset() - self.fill(0) - self.poweron() - # rotate90 requires a call to flip() for setting up. - self.flip(self.flip_en) - - def poweroff(self): - self.write_cmd(_SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(_SET_DISP | 0x01) - - def flip(self, flag=None, update=True): - if flag is None: - flag = not self.flip_en - mir_v = flag ^ self.rotate90 - mir_h = flag - self.write_cmd(_SET_SEG_REMAP | (0x01 if mir_v else 0x00)) - self.write_cmd(_SET_SCAN_DIR | (0x08 if mir_h else 0x00)) - self.flip_en = flag - if update: - self.show() - - def sleep(self, value): - self.write_cmd(_SET_DISP | (not value)) - - def contrast(self, contrast): - self.write_cmd(_SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(_SET_NORM_INV | (invert & 1)) - - def show(self): - # self.* lookups in loops take significant time (~4fps). - (w, p, db, rb) = (self.width, self.pages, - self.displaybuf, self.renderbuf) - if self.rotate90: - for i in range(self.bufsize): - db[w * (i % p) + (i // p)] = rb[i] - for page in range(self.height // 8): - self.write_cmd(_SET_PAGE_ADDRESS | page) - self.write_cmd(_LOW_COLUMN_ADDRESS | 2) - self.write_cmd(_HIGH_COLUMN_ADDRESS | 0) - self.write_data(db[(w*page):(w*page+w)]) - - def reset(self, res): - if res is not None: - res(1) - time.sleep_ms(1) - res(0) - time.sleep_ms(20) - res(1) - time.sleep_ms(20) - - -class SH1106_I2C(SH1106): - def __init__(self, width, height, i2c, res=None, addr=0x3c, - rotate=0, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.res = res - self.temp = bytearray(2) - if res is not None: - res.init(res.OUT, value=1) - super().__init__(width, height, external_vcc, rotate) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.i2c.writeto(self.addr, b'\x40'+buf) - - def reset(self): - super().reset(self.res) - - -class SH1106_SPI(SH1106): - def __init__(self, width, height, spi, dc, res=None, cs=None, - rotate=0, external_vcc=False): - self.rate = 10 * 1000 * 1000 - dc.init(dc.OUT, value=0) - if res is not None: - res.init(res.OUT, value=0) - if cs is not None: - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - super().__init__(width, height, external_vcc, rotate) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - else: - self.dc(0) - self.spi.write(bytearray([cmd])) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) - else: - self.dc(1) - self.spi.write(buf) - - def reset(self): - super().reset(self.res) diff --git a/src/drivers/ssd1306.py b/src/drivers/ssd1306.py deleted file mode 100644 index 85e2bf0cb..000000000 --- a/src/drivers/ssd1306.py +++ /dev/null @@ -1,159 +0,0 @@ -# MicroPython SSD1306 OLED driver, I2C and SPI interfaces - -from micropython import const -import framebuf - - -# register definitions -SET_CONTRAST = const(0x81) -SET_ENTIRE_ON = const(0xA4) -SET_NORM_INV = const(0xA6) -SET_DISP = const(0xAE) -SET_MEM_ADDR = const(0x20) -SET_COL_ADDR = const(0x21) -SET_PAGE_ADDR = const(0x22) -SET_DISP_START_LINE = const(0x40) -SET_SEG_REMAP = const(0xA0) -SET_MUX_RATIO = const(0xA8) -SET_COM_OUT_DIR = const(0xC0) -SET_DISP_OFFSET = const(0xD3) -SET_COM_PIN_CFG = const(0xDA) -SET_DISP_CLK_DIV = const(0xD5) -SET_PRECHARGE = const(0xD9) -SET_VCOM_DESEL = const(0xDB) -SET_CHARGE_PUMP = const(0x8D) - -# Subclassing FrameBuffer provides support for graphics primitives -# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html -class SSD1306(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB) - self.init_display() - - def init_display(self): - for cmd in ( - SET_DISP, # display off - # address setting - SET_MEM_ADDR, - 0x00, # horizontal - # resolution and layout - SET_DISP_START_LINE, # start at line 0 - SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 - SET_MUX_RATIO, - self.height - 1, - SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0 - SET_DISP_OFFSET, - 0x00, - SET_COM_PIN_CFG, - 0x02 if self.width > 2 * self.height else 0x12, - # timing and driving scheme - SET_DISP_CLK_DIV, - 0x80, - SET_PRECHARGE, - 0x22 if self.external_vcc else 0xF1, - SET_VCOM_DESEL, - 0x30, # 0.83*Vcc - # display - SET_CONTRAST, - 0xFF, # maximum - SET_ENTIRE_ON, # output follows RAM contents - SET_NORM_INV, # not inverted - # charge pump - SET_CHARGE_PUMP, - 0x10 if self.external_vcc else 0x14, - SET_DISP | 0x01, # display on - ): # on - self.write_cmd(cmd) - self.fill(0) - self.show() - - def poweroff(self): - self.write_cmd(SET_DISP) - - def poweron(self): - self.write_cmd(SET_DISP | 0x01) - - def contrast(self, contrast): - self.write_cmd(SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(SET_NORM_INV | (invert & 1)) - - def rotate(self, rotate): - self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3)) - self.write_cmd(SET_SEG_REMAP | (rotate & 1)) - - def show(self): - x0 = 0 - x1 = self.width - 1 - if self.width == 64: - # displays with width of 64 pixels are shifted by 32 - x0 += 32 - x1 += 32 - self.write_cmd(SET_COL_ADDR) - self.write_cmd(x0) - self.write_cmd(x1) - self.write_cmd(SET_PAGE_ADDR) - self.write_cmd(0) - self.write_cmd(self.pages - 1) - self.write_data(self.buffer) - - -class SSD1306_I2C(SSD1306): - def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.temp = bytearray(2) - self.write_list = [b"\x40", None] # Co=0, D/C#=1 - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.write_list[1] = buf - self.i2c.writevto(self.addr, self.write_list) - - -class SSD1306_SPI(SSD1306): - def __init__(self, width, height, spi, dc, res, cs, external_vcc=False): - self.rate = 10 * 1024 * 1024 - dc.init(dc.OUT, value=0) - res.init(res.OUT, value=0) - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - import time - - self.res(1) - time.sleep_ms(1) - self.res(0) - time.sleep_ms(10) - self.res(1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) diff --git a/src/drivers/tt14.py b/src/drivers/tt14.py deleted file mode 100644 index 47113abc0..000000000 --- a/src/drivers/tt14.py +++ /dev/null @@ -1,159 +0,0 @@ -# Code generated by font-to-py.py. -# Font: CM Sans Serif 2012.ttf -version = '0.2' - -def height(): - return 15 - -def max_width(): - return 12 - -def hmap(): - return False - -def reverse(): - return False - -def monospaced(): - return False - -def min_ch(): - return 32 - -def max_ch(): - return 126 - -_font =\ -b'\x08\x00\x08\x00\x0c\x00\x8c\x07\xcc\x07\xcc\x00\x7c\x00\x38\x00'\ -b'\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\xfc\x06'\ -b'\xfc\x06\x00\x00\x05\x00\x1c\x00\x3c\x00\x00\x00\x3c\x00\x00\x00'\ -b'\x07\x00\x40\x03\xf0\x03\xf0\x03\x30\x03\xf0\x03\x30\x03\x30\x00'\ -b'\x07\x00\x30\x00\x78\x03\x6c\x02\xfc\x07\xd8\x03\x90\x03\x00\x00'\ -b'\x0b\x00\x18\x00\x3c\x00\x3c\x04\x3c\x03\xd8\x01\xf0\x03\xd8\x07'\ -b'\xc4\x06\xc0\x07\x80\x03\x00\x00\x09\x00\x80\x03\xf8\x07\x7c\x06'\ -b'\x4c\x06\xfc\x06\x98\x07\xc0\x07\xc0\x05\x00\x04\x02\x00\x1c\x00'\ -b'\x3c\x00\x04\x00\xf0\x03\xfc\x0f\x0e\x1c\x02\x10\x05\x00\x02\x10'\ -b'\x0e\x1c\xfc\x0f\xf0\x03\x00\x00\x05\x00\x0c\x00\x3c\x00\x18\x00'\ -b'\x2c\x00\x0c\x00\x07\x00\xc0\x00\xc0\x00\xf0\x03\xf0\x03\xc0\x00'\ -b'\xc0\x00\x00\x00\x03\x00\x00\x16\x00\x0e\x00\x00\x04\x00\xc0\x00'\ -b'\xc0\x00\xc0\x00\xc0\x00\x03\x00\x00\x06\x00\x06\x00\x00\x04\x00'\ -b'\x00\x06\xe0\x07\xfc\x00\x0e\x00\x08\x00\xf0\x01\xf8\x03\x1c\x07'\ -b'\x0c\x06\x1c\x07\xf8\x03\xf0\x01\x00\x00\x04\x00\x18\x00\xfc\x07'\ -b'\xfc\x07\x00\x00\x08\x00\x18\x04\x1c\x07\x8c\x06\x8c\x06\x4c\x06'\ -b'\x7c\x06\x38\x06\x00\x00\x07\x00\x08\x02\x0c\x06\x0c\x06\x6c\x06'\ -b'\x6c\x06\xfc\x07\xd8\x03\x07\x00\x80\x01\xe0\x01\xb0\x01\x9c\x01'\ -b'\xfc\x07\xfc\x07\x80\x01\x07\x00\x00\x02\xfc\x06\x6c\x06\x6c\x06'\ -b'\x6c\x06\xcc\x03\xc0\x03\x08\x00\xf0\x01\xf8\x03\x6c\x06\x6c\x06'\ -b'\x6c\x06\xe8\x07\xc0\x03\x00\x00\x06\x00\x0c\x00\x0c\x07\xcc\x07'\ -b'\xfc\x00\x1c\x00\x0c\x00\x07\x00\x98\x03\xfc\x07\x6c\x06\x6c\x06'\ -b'\x6c\x06\xfc\x07\x98\x03\x08\x00\x78\x02\xfc\x06\xcc\x06\xcc\x06'\ -b'\xcc\x06\xf8\x03\xf0\x01\x00\x00\x03\x00\x30\x06\x30\x06\x00\x00'\ -b'\x03\x00\x30\x16\x30\x0e\x00\x00\x06\x00\xc0\x01\xc0\x01\x60\x03'\ -b'\x60\x03\x30\x06\x00\x00\x06\x00\x60\x03\x60\x03\x60\x03\x60\x03'\ -b'\x60\x03\x60\x03\x06\x00\x30\x06\x60\x03\x60\x03\x40\x01\xc0\x01'\ -b'\x00\x00\x08\x00\x08\x00\x0c\x00\x8c\x07\xcc\x07\xcc\x00\x7c\x00'\ -b'\x38\x00\x00\x00\x0b\x00\xe0\x00\xf8\x01\x18\x03\xec\x07\xbc\x07'\ -b'\xfc\x06\xfc\x07\x9c\x03\xf8\x01\xf0\x00\x00\x00\x08\x00\x00\x06'\ -b'\x80\x07\xf0\x01\x9c\x01\x8c\x01\xf8\x01\xc0\x07\x00\x07\x08\x00'\ -b'\xfc\x07\xfc\x07\x6c\x06\x6c\x06\x6c\x06\xfc\x07\xd8\x03\x00\x00'\ -b'\x09\x00\xe0\x00\xf8\x03\x18\x03\x0c\x06\x0c\x06\x0c\x06\x1c\x07'\ -b'\x18\x03\x20\x01\x09\x00\xfc\x07\xfc\x07\x0c\x06\x0c\x06\x1c\x07'\ -b'\xf8\x03\xf0\x01\x00\x00\x00\x00\x08\x00\xfc\x07\xfc\x07\x6c\x06'\ -b'\x6c\x06\x6c\x06\x6c\x06\x0c\x06\x00\x00\x07\x00\xfc\x07\xfc\x07'\ -b'\xcc\x00\xcc\x00\xcc\x00\xcc\x00\x0c\x00\x0a\x00\xe0\x01\xf8\x03'\ -b'\x18\x07\x0c\x06\x0c\x06\xcc\x06\xdc\x02\xd8\x07\xe0\x07\x00\x00'\ -b'\x09\x00\xfc\x07\xfc\x07\x60\x00\x60\x00\x60\x00\xfc\x07\xfc\x07'\ -b'\x00\x00\x00\x00\x03\x00\xfc\x07\xfc\x07\x00\x00\x07\x00\x80\x03'\ -b'\x80\x07\x00\x06\x00\x06\xfc\x07\xfc\x03\x00\x00\x08\x00\xfc\x07'\ -b'\xfc\x07\x60\x00\xf0\x00\xd8\x01\x0c\x07\x04\x06\x04\x04\x07\x00'\ -b'\xfc\x07\xfc\x07\x00\x06\x00\x06\x00\x06\x00\x06\x00\x00\x0b\x00'\ -b'\xfc\x07\xfc\x07\x3c\x00\xe0\x03\x00\x06\xe0\x03\x3c\x00\xfc\x07'\ -b'\xfc\x07\x00\x00\x00\x00\x09\x00\xfc\x07\xfc\x07\x38\x00\xe0\x00'\ -b'\x80\x03\xfc\x07\xfc\x07\x00\x00\x00\x00\x0a\x00\xf0\x01\xf8\x03'\ -b'\x1c\x07\x0c\x06\x0c\x06\x0c\x06\x1c\x07\xf8\x03\xf0\x01\x00\x00'\ -b'\x09\x00\xfc\x07\xfc\x07\xcc\x00\xcc\x00\xcc\x00\xfc\x00\x78\x00'\ -b'\x00\x00\x00\x00\x0a\x00\xf0\x01\xf8\x03\x1c\x07\x0c\x06\x8c\x06'\ -b'\x8c\x07\x1c\x07\xf8\x07\xf0\x05\x00\x00\x09\x00\xfc\x07\xfc\x07'\ -b'\xcc\x00\xcc\x00\xcc\x03\x7c\x07\x78\x04\x00\x00\x00\x00\x09\x00'\ -b'\x38\x01\x3c\x03\x4c\x06\x4c\x06\x4c\x06\x4c\x06\x98\x07\x90\x03'\ -b'\x00\x00\x07\x00\x0c\x00\x0c\x00\xfc\x07\xfc\x07\x0c\x00\x0c\x00'\ -b'\x00\x00\x09\x00\xfc\x03\xfc\x07\x00\x06\x00\x06\x00\x06\xfc\x07'\ -b'\xfc\x01\x00\x00\x00\x00\x08\x00\x0c\x00\x7c\x00\xe0\x03\x00\x07'\ -b'\x80\x07\xf8\x01\x3c\x00\x04\x00\x0b\x00\x0c\x00\xfc\x00\xe0\x07'\ -b'\x80\x07\xf8\x03\x1c\x00\xfc\x00\xc0\x07\x80\x07\xfc\x01\x1c\x00'\ -b'\x08\x00\x04\x04\x0c\x07\xb8\x03\xf0\x00\xf0\x01\x9c\x07\x0c\x06'\ -b'\x04\x04\x08\x00\x04\x00\x1c\x00\x78\x00\xe0\x07\xe0\x07\x78\x00'\ -b'\x1c\x00\x04\x00\x07\x00\x0c\x06\x0c\x07\x8c\x07\xcc\x06\x2c\x06'\ -b'\x1c\x06\x0c\x06\x04\x00\xff\x1f\xff\x1f\x03\x18\x00\x00\x04\x00'\ -b'\x0e\x00\xfe\x00\xe0\x07\x00\x07\x04\x00\x03\x18\xff\x1f\xff\x1f'\ -b'\x00\x00\x07\x00\x80\x00\xe0\x00\x7c\x00\x0c\x00\x7c\x00\xe0\x00'\ -b'\x80\x00\x0a\x00\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18\x00\x18'\ -b'\x00\x18\x00\x18\x00\x18\x00\x18\x05\x00\x04\x00\x0c\x00\x08\x00'\ -b'\x00\x00\x00\x00\x08\x00\x00\x03\xe0\x07\xb0\x06\xb0\x06\xb0\x02'\ -b'\xf0\x07\xe0\x07\x00\x00\x09\x00\xfe\x07\xfe\x07\x30\x02\x30\x06'\ -b'\x30\x06\xe0\x07\xc0\x01\x00\x00\x00\x00\x07\x00\xc0\x01\xe0\x03'\ -b'\x30\x06\x30\x06\x30\x06\x60\x03\x40\x01\x08\x00\xc0\x01\xf0\x07'\ -b'\x30\x06\x30\x06\x30\x06\xfe\x07\xfe\x07\x00\x00\x07\x00\xc0\x01'\ -b'\xe0\x03\xb0\x07\xb0\x07\xb0\x07\xe0\x03\xc0\x01\x04\x00\x20\x00'\ -b'\xfc\x07\xfe\x07\x00\x00\x08\x00\xc0\x11\xf0\x1f\x30\x36\x30\x36'\ -b'\x20\x36\xf0\x1f\xf0\x0f\x00\x00\x08\x00\xfe\x07\xfe\x07\x30\x00'\ -b'\x30\x00\xf0\x07\xe0\x07\x00\x00\x00\x00\x03\x00\xfc\x07\xfc\x07'\ -b'\x00\x00\x03\x00\xec\x7f\xec\x3f\x00\x00\x07\x00\xfe\x07\xfe\x07'\ -b'\xc0\x00\xe0\x01\xb0\x07\x10\x06\x10\x04\x03\x00\xfe\x07\xfe\x07'\ -b'\x00\x00\x0c\x00\xf0\x07\xf0\x07\x30\x00\x30\x00\xf0\x07\xe0\x07'\ -b'\x30\x00\x30\x00\xf0\x07\xe0\x07\x00\x00\x00\x00\x08\x00\xf0\x07'\ -b'\xf0\x07\x30\x00\x30\x00\xf0\x07\xe0\x07\x00\x00\x00\x00\x08\x00'\ -b'\xc0\x01\xe0\x03\x30\x06\x30\x06\x30\x06\xe0\x03\xc0\x01\x00\x00'\ -b'\x09\x00\xf0\x3f\xf0\x3f\x30\x06\x30\x06\x30\x06\xf0\x07\xc0\x01'\ -b'\x00\x00\x00\x00\x08\x00\xc0\x01\xf0\x07\x30\x06\x30\x06\x30\x06'\ -b'\xf0\x3f\xf0\x3f\x00\x00\x04\x00\xf0\x07\xf0\x07\x30\x00\x30\x00'\ -b'\x08\x00\x60\x00\x70\x03\xb0\x07\xf0\x06\xb0\x06\xa0\x07\x00\x03'\ -b'\x00\x00\x04\x00\x30\x00\xfe\x03\xfe\x07\x00\x00\x08\x00\xf0\x03'\ -b'\xf0\x07\x00\x06\x00\x06\xf0\x07\xf0\x07\x00\x00\x00\x00\x07\x00'\ -b'\x30\x00\xf0\x00\x80\x07\x00\x06\xc0\x03\xf0\x00\x10\x00\x0a\x00'\ -b'\x30\x00\xf0\x01\x80\x07\xc0\x07\xf0\x00\xf0\x00\x80\x07\x80\x07'\ -b'\xf0\x01\x30\x00\x07\x00\x10\x04\x30\x07\xe0\x03\xc0\x01\x70\x07'\ -b'\x10\x06\x00\x04\x07\x00\x30\x00\xf0\x30\xc0\x3f\x00\x1f\xe0\x03'\ -b'\x70\x00\x10\x00\x06\x00\x30\x06\x30\x07\xb0\x07\xf0\x06\x70\x06'\ -b'\x30\x06\x05\x00\x40\x00\xbe\x0f\xbe\x0f\x00\x00\x00\x00\x04\x00'\ -b'\xfe\x07\xfe\x07\x00\x00\x00\x00\x04\x00\xbe\x0f\xbe\x0f\x40\x00'\ -b'\x00\x00\x05\x00\x04\x00\x04\x00\x04\x00\x06\x00\x04\x00' - -_index =\ -b'\x00\x00\x12\x00\x1c\x00\x24\x00\x30\x00\x40\x00\x50\x00\x68\x00'\ -b'\x7c\x00\x82\x00\x8c\x00\x98\x00\xa4\x00\xb4\x00\xbc\x00\xc6\x00'\ -b'\xce\x00\xd8\x00\xea\x00\xf4\x00\x06\x01\x16\x01\x26\x01\x36\x01'\ -b'\x48\x01\x56\x01\x66\x01\x78\x01\x80\x01\x88\x01\x96\x01\xa4\x01'\ -b'\xb2\x01\xc4\x01\xdc\x01\xee\x01\x00\x02\x14\x02\x28\x02\x3a\x02'\ -b'\x4a\x02\x60\x02\x74\x02\x7c\x02\x8c\x02\x9e\x02\xae\x02\xc6\x02'\ -b'\xda\x02\xf0\x02\x04\x03\x1a\x03\x2e\x03\x42\x03\x52\x03\x66\x03'\ -b'\x78\x03\x90\x03\xa2\x03\xb4\x03\xc4\x03\xce\x03\xd8\x03\xe2\x03'\ -b'\xf2\x03\x08\x04\x14\x04\x26\x04\x3a\x04\x4a\x04\x5c\x04\x6c\x04'\ -b'\x76\x04\x88\x04\x9a\x04\xa2\x04\xaa\x04\xba\x04\xc2\x04\xdc\x04'\ -b'\xee\x04\x00\x05\x14\x05\x26\x05\x30\x05\x42\x05\x4c\x05\x5e\x05'\ -b'\x6e\x05\x84\x05\x94\x05\xa4\x05\xb2\x05\xbe\x05\xc8\x05\xd2\x05'\ -b'\xde\x05' - -_mvfont = memoryview(_font) - -def _chr_addr(ordch): - offset = 2 * (ordch - 32) - return int.from_bytes(_index[offset:offset + 2], 'little') - -def get_width(s): - width = 0 - for ch in s: - ordch = ord(ch) - ordch = ordch + 1 if ordch >= 32 and ordch <= 126 else 32 - offset = _chr_addr(ordch) - width += int.from_bytes(_font[offset:offset + 2], 'little') - return width - -def get_ch(ch): - ordch = ord(ch) - ordch = ordch + 1 if ordch >= 32 and ordch <= 126 else 32 - offset = _chr_addr(ordch) - width = int.from_bytes(_font[offset:offset + 2], 'little') - next_offs = _chr_addr(ordch +1) - return _mvfont[offset + 2:next_offs], width - \ No newline at end of file diff --git a/src/handlers/control-c-handler.py b/src/handlers/control-c-handler.py deleted file mode 100644 index 3a364e6ac..000000000 --- a/src/handlers/control-c-handler.py +++ /dev/null @@ -1,14 +0,0 @@ -import time - -def myMain(): - while True: - print('in myMain') - time.sleep(.5) - -try: - myMain() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('cleaning up') \ No newline at end of file diff --git a/src/i2c/i2c-oled-on-16-17-scanner.py b/src/i2c/i2c-oled-on-16-17-scanner.py deleted file mode 100644 index 6936acc6d..000000000 --- a/src/i2c/i2c-oled-on-16-17-scanner.py +++ /dev/null @@ -1,20 +0,0 @@ -import machine -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -device_id_list = i2c.scan() -for device_id in device_id_list: - print("Found I2C Device at:", device_id) - -print("Device found at decimal", device_id) - -if device_id_list[0] == 41: - print("TEST PASS!") - print("We have found an Time of Flight Sensor using pins 16 and 17 for SDA and SCL.") - print("Your SDA and SCL lines are connected correctly.") -else: - print("No device found at decimal 60") - print("TEST FAIL") diff --git a/src/i2c/i2c-scanner.py b/src/i2c/i2c-scanner.py deleted file mode 100644 index 8f9516b89..000000000 --- a/src/i2c/i2c-scanner.py +++ /dev/null @@ -1,17 +0,0 @@ -# I2C Scanner -import machine - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -device_id = i2c.scan()[0] -print("Device found at decimal", device_id) - -if device_id == 60: - print("TEST PASS") -else: - print("No device found at decimal 41") - print("TEST FAIL") diff --git a/src/i2c/i2c-tof-detection-test.py b/src/i2c/i2c-tof-detection-test.py deleted file mode 100644 index 7d8106458..000000000 --- a/src/i2c/i2c-tof-detection-test.py +++ /dev/null @@ -1,27 +0,0 @@ -import machine - -# Change these pin number to match your hardware setup -SDA_PIN = 16 -SCL_PIN = 17 -sda=machine.Pin(SDA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(SCL_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found - -print("Using I2C SDA Pin:", SDA_PIN) -print("Using I2C SCL Pin:", SCL_PIN) -device_id_list = i2c.scan() -for device_id in device_id_list: - print("Found I2C Device at:", device_id) - -print("Device found at decimal", device_id) - -if device_id_list[0] == 41: - print("TEST PASS!") - print("We have found an Time of Flight Sensor using pins 16 and 17 for SDA and SCL.") - print("Your SDA and SCL lines are connected correctly.") -else: - print("No Time of Flight device found at decimal 41 using these SDA and SCL pins.") - print("TEST FAIL") diff --git a/src/intro/blink-onboard-led.py b/src/intro/blink-onboard-led.py deleted file mode 100644 index afa2e577f..000000000 --- a/src/intro/blink-onboard-led.py +++ /dev/null @@ -1,6 +0,0 @@ -import machine -import utime -led_onboard = machine.Pin(25, machine.Pin.OUT) -while True: - led_onboard.toggle() - utime.sleep(.1) \ No newline at end of file diff --git a/src/intro/button-test.py b/src/intro/button-test.py deleted file mode 100644 index 7eed88849..000000000 Binary files a/src/intro/button-test.py and /dev/null differ diff --git a/src/intro/fade-in-and-out.py b/src/intro/fade-in-and-out.py deleted file mode 100644 index 2ef4bf099..000000000 --- a/src/intro/fade-in-and-out.py +++ /dev/null @@ -1,15 +0,0 @@ -# program to fade the builtin LED slowly on and off -from machine import PWM, Pin -from time import sleep - -pwm = PWM(Pin(25)) - -pwm.freq(100) - -while True: - for duty in range(65025): - pwm.duty_u16(duty) - sleep(0.0001) - for duty in range(65025, 0, -1): - pwm.duty_u16(duty) - sleep(0.0001) \ No newline at end of file diff --git a/src/intro/l293d-motor-test.py b/src/intro/l293d-motor-test.py deleted file mode 100644 index 82a0b2918..000000000 --- a/src/intro/l293d-motor-test.py +++ /dev/null @@ -1,16 +0,0 @@ -from machine import Pin, PWM - -import time -FORWARD_PIN = 16 # lower right corner -REVERSE_PIN = 17 -POT_PIN = machine.ADC(26) # ADC0 -MAX_POWER = 65025 - -forward_pwm = PWM(Pin(FORWARD_PIN)) -reverse_pwm = PWM(Pin(REVERSE_PIN)) - -while True: - val = POT_PIN.read_u16() - print(val) - forward_pwm.duty_u16(val) - time.sleep(.1) \ No newline at end of file diff --git a/src/intro/motor-cycle-on-off.py b/src/intro/motor-cycle-on-off.py deleted file mode 100644 index a30a4b4fb..000000000 --- a/src/intro/motor-cycle-on-off.py +++ /dev/null @@ -1,18 +0,0 @@ -import machine -import time - -# lower right corner -motor_pin = machine.Pin(16, machine.Pin.OUT) -# allocate a PWM object for controlling the motor speed -#motor_pwm = machine.PWM(motor_pin) -#motor_pwm.freq(50) # 50 hertz -#motor_pwm.duty(51) - -while True: - print('on') - motor_pin.high() - time.sleep(3) - - print('off') - motor_pin.low() - time.sleep(3) \ No newline at end of file diff --git a/src/intro/pot-display-test.py b/src/intro/pot-display-test.py deleted file mode 100644 index 8f2b1c351..000000000 --- a/src/intro/pot-display-test.py +++ /dev/null @@ -1,82 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 -import framebuf - -# this is the built-in LED on the Pico -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -fb = framebuf.FrameBuffer(bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), - 64, 64, framebuf.MONO_VLSB) - -def update_display(counter, pot_value, delay): - oled.fill(0) - oled.blit(fb, 64, 0) - oled.text('CoderDojo', 0, 0) - oled.text('Robots', 0, 10) - oled.text('& Sound ', 0, 20) - - oled.text('P:', 0, 34) - oled.text(str(pot_value), 20, 34) - - oled.text('D:', 0, 44) - oled.text(str(round(delay, 3)), 20, 44) - - oled.text('C:', 0, 54) - oled.text(str(counter), 20, 54) - oled.show() - -counter = 0 - -# repeat forever -while True: - pot_value = pot.read_u16() >> 8 # read the value from the pot - print("pot_value:", pot_value) - # max of 16 bit value is 65025 but max of 2 to 12th is 4096 - # 12 bits is 4096 (shift 4) - # 10 bits is 1024 (shift 6) - # 8 is 256 (shift 8) - delay = pot_value/256 * MAX_DELAY - print("delay seconds:", delay) - #if delay > 0: - # print("frequency (toggles per second):", 1/delay) - update_display(counter, pot_value, delay) - led.high() # turn on the LED - sleep(delay) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(delay) # leave it off for 1/2 second - counter += 1 \ No newline at end of file diff --git a/src/kits/10-bar-led/button-test.py b/src/kits/10-bar-led/button-test.py deleted file mode 100644 index fa8a8f5f0..000000000 --- a/src/kits/10-bar-led/button-test.py +++ /dev/null @@ -1,32 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_UP) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/kits/10-bar-led/main.py b/src/kits/10-bar-led/main.py deleted file mode 100644 index cfba72700..000000000 --- a/src/kits/10-bar-led/main.py +++ /dev/null @@ -1,94 +0,0 @@ -from machine import Pin -from utime import sleep, ticks_ms - -# note these are out-of-order to keep the wiring looking pretty -pin_ids = [12,13,14,15,21,20,19,18,17,16] -pin_count = len(pin_ids) -pins = [] -mode_names = ["dot up", "dot down", "swip up", "swipe down", "chase up", "chase down"] -mode_count = len(mode_names) - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -mode = 0 # the count of times the button has been pressed - - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_UP) - -for i in range(0, pin_count): - pins.append(machine.Pin(pin_ids[i], machine.Pin.OUT)) - -last_time = 0 # the last time we pressed the button -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/2 of a second since the last event, we have a new event - if (new_time - last_time) > 500: - mode +=1 - # print('new mode', mode) - last_time = new_time - if mode >= mode_count: - mode = 0 - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_RISING, handler = button_pressed_handler) - -old_mode = -1 -delay = .1 -print('found ', mode_count, 'modes') -while True: - - if mode >= mode_count: - mode_count = 0 - if mode != old_mode: - print('new mode:', mode) - print(mode_names[mode]) - builtin_led.toggle() - old_mode = mode - - # dot up - if mode == 0: - for i in range(0, pin_count): - pins[i].on() - sleep(delay) - pins[i].off() - # dot down - elif mode == 1: - for i in range(pin_count-1, -1, -1): - pins[i].on() - sleep(delay) - pins[i].off() - # swipe up - elif mode == 2: - for i in range(0, pin_count): - pins[i].on() - sleep(delay) - for i in range(0, pin_count): - pins[i].off() - # swipe down - elif mode == 3: - for i in range(pin_count-1, -1, -1): - pins[i].on() - sleep(delay) - for i in range(pin_count-1, -1, -1): - pins[i].off() - elif mode == 4: - for i in range(0, 4): - for j in range(0, pin_count-1, 3): - if i+j < 10: - pins[i+j].on() - sleep(delay) - for i in range(0, pin_count): - pins[i].off() - elif mode == 5: - for i in range(0, 4): - for j in range(0, pin_count, 3): - tmp = pin_count - (i+j) - if tmp >= 0 and tmp < pin_count: - pins[tmp].on() - sleep(delay) - for i in range(0, pin_count): - pins[i].off() diff --git a/src/kits/elecrow-adv/4-digit-display-test.py b/src/kits/elecrow-adv/4-digit-display-test.py deleted file mode 100644 index 3fd74f32b..000000000 --- a/src/kits/elecrow-adv/4-digit-display-test.py +++ /dev/null @@ -1,262 +0,0 @@ -from machine import Pin -from time import sleep -import tm1637 - -CLK_PIN = 1 -DIO_PIN = 0 -DELAY = 0.5 - -tm = tm1637.TM1637(clk=Pin(CLK_PIN), dio=Pin(DIO_PIN)) - -# all segments on "88:88" -tm.write([127, 255, 127, 127]) -tm.write(bytearray([127, 255, 127, 127])) -tm.write(b'\x7F\xFF\x7F\x7F') -tm.show('8888', True) -tm.numbers(88, 88, True) -sleep(DELAY) - -# all segments off -tm.write([0, 0, 0, 0]) -tm.show(' ') -sleep(DELAY) - -# write to the 2nd and 3rd segments only -tm.write([119, 124], 1) # _Ab_ -sleep(DELAY) -tm.write([0, 0, 0, 0]) -tm.write([124], 2) # __b_ -sleep(DELAY) -tm.write([119], 1) # _A__ -sleep(DELAY) - -# display "0123" -tm.write([63, 6, 91, 79]) -tm.write(bytearray([63, 6, 91, 79])) -tm.write(b'\x3F\x06\x5B\x4F') -sleep(DELAY) -tm.show('1234') -tm.number(1234) -tm.numbers(12, 34, False) -sleep(DELAY) - -# display "4567" -tm.write([102, 109, 125, 7]) -sleep(DELAY) -tm.write([0, 0, 0, 0]) -tm.write([102], 0) # 4___ -sleep(DELAY) -tm.write([109], 1) # _5__ -sleep(DELAY) -tm.write([125], 2) # __6_ -sleep(DELAY) -tm.write([7], 3) # ___7 -sleep(DELAY) - -# set middle two segments to "12", ie "4127" -tm.write([6, 91], 1) # _12_ -sleep(DELAY) - -# set last segment to "9", ie "4129" -tm.write([111], 3) # ___9 -sleep(DELAY) - -# walk through all possible LED combinations -for i in range(128): - tm.number(i) - tm.write([i]) - sleep(0.1) - -# show "AbCd" -tm.write([119, 124, 57, 94]) -tm.show('abcd') -sleep(DELAY) - -# show "COOL" -tm.write([0b00111001, 0b00111111, 0b00111111, 0b00111000]) -tm.write([0x39, 0x3F, 0x3F, 0x38]) -tm.write(b'\x39\x3F\x3F\x38') -tm.write([57, 63, 63, 56]) -tm.show('cool') -tm.show('COOL') -sleep(DELAY) - -# display "dEAd", "bEEF" -tm.hex(0xdead) -sleep(DELAY) -tm.hex(0xbeef) -sleep(DELAY) -tm.show('dead') -sleep(DELAY) -tm.show('Beef') -sleep(DELAY) - -# show "12:59" -tm.numbers(12, 59) -tm.show('1259', True) -sleep(DELAY) - -# show "-123" -tm.number(-123) -tm.show('-123') -sleep(DELAY) - -# Show Help -tm.show('Help') -tm.write(tm.encode_string('Help')) -tm.write([tm.encode_char('H'), tm.encode_char('e'), tm.encode_char('l'), tm.encode_char('p')]) -sleep(DELAY) - -# Scroll Hello World from right to left -tm.scroll('Hello World') # 4 fps -tm.scroll('Hello World', 1000) # 1 fps - -# Scroll all available characters -tm.scroll(list(tm1637._SEGMENTS)) - -# all LEDs dim -tm.brightness(0) -sleep(DELAY) - -# all LEDs bright -tm.brightness(7) -sleep(DELAY) - -# converts a digit 0-0x0f to a byte representing a single segment -# use write() to render the byte on a single segment -tm.encode_digit(0) -# 63 - -tm.encode_digit(8) -# 127 - -tm.encode_digit(0x0f) -# 113 - -# 15 or 0x0f generates a segment that can output a F character -tm.encode_digit(15) -# 113 - -tm.encode_digit(0x0f) -# 113 - -# used to convert a 1-4 length string to an array of segments -tm.encode_string(' 1') -# bytearray(b'\x00\x00\x00\x06') - -tm.encode_string('2 ') -# bytearray(b'[\x00\x00\x00') - -tm.encode_string('1234') -# bytearray(b'\x06[Of') - -tm.encode_string('-12-') -# bytearray(b'@\x06[@') - -tm.encode_string('cafe') -# bytearray(b'9wqy') - -tm.encode_string('CAFE') -# bytearray(b'9wqy') - -tm.encode_string('a') -# bytearray(b'w\x00\x00\x00') - -tm.encode_string('ab') -# bytearray(b'w|\x00\x00') - -# used to convert a single character to a segment byte -tm.encode_char('1') -# 6 - -tm.encode_char('9') -# 111 - -tm.encode_char('-') -# 64 - -tm.encode_char('a') -# 119 - -tm.encode_char('F') -# 113 - -# display "dEAd", "bEEF", "CAFE" and "bAbE" -tm.hex(0xdead) -sleep(DELAY) -tm.hex(0xbeef) -sleep(DELAY) -tm.hex(0xcafe) -sleep(DELAY) -tm.hex(0xbabe) -sleep(DELAY) - -# show "00FF" (hex right aligned) -tm.hex(0xff) -sleep(DELAY) - -# show " 1" (numbers right aligned) -tm.number(1) -sleep(DELAY) - -# show " 12" -tm.number(12) -sleep(DELAY) - -# show " 123" -tm.number(123) -sleep(DELAY) - -# show "9999" capped at 9999 -tm.number(20000) -sleep(DELAY) - -# show " -1" -tm.number(-1) -sleep(DELAY) - -# show " -12" -tm.number(-12) -sleep(DELAY) - -# show "-123" -tm.number(-123) -sleep(DELAY) - -# show "-999" capped at -999 -tm.number(-1234) -sleep(DELAY) - -# show "01:02" -tm.numbers(1, 2) -sleep(DELAY) - -# show "0102" -tm.numbers(1, 2, False) -sleep(DELAY) - -# show "-5:11" -tm.numbers(-5, 11) -sleep(DELAY) - -# show "12:59" -tm.numbers(12, 59) -sleep(DELAY) - -# show temperature '24*C' -tm.temperature(24) -sleep(DELAY) -tm.show('24*C') -sleep(DELAY) - -# show temperature works for range -9 to +99 -tm.temperature(-10) # LO*C -sleep(DELAY) -tm.temperature(-9) # -9*C -sleep(DELAY) -tm.temperature(5) # 5*C -sleep(DELAY) -tm.temperature(99) # 99*C -sleep(DELAY) -tm.temperature(100) # HI*C -sleep(DELAY) diff --git a/src/kits/elecrow-adv/PIR-photo-sensors.py b/src/kits/elecrow-adv/PIR-photo-sensors.py deleted file mode 100644 index a784a5bc3..000000000 --- a/src/kits/elecrow-adv/PIR-photo-sensors.py +++ /dev/null @@ -1,28 +0,0 @@ -from machine import Pin,PWM ADC -light_sensor_pin = 0 -PIR_pin = 1 -Led_R_pin = 2 -Led_G_Pin = 3 -Led_B_pin = 4 -# ADC0 multiplexing pin is GP26 - -light_sensor_ADC = ADC(light_sensor_pin) PIR = Pin(PIR_pin, Pin.IN, Pin.PULL_DOWN) Led_R = PWM(Pin(Led_R_pin)) -Led_G = PWM(Pin(Led_G_Pin)) -Led_B = PWM(Pin(Led_B_pin)) Led_R.freq(2000) -Led_G.freq(2000) -Led_B.freq(2000) - -while True: - print('light_sensor Value: ', light_sensor_ADC.read_u16()) - print('PIR Value: ',PIR.value()) - if PIR.value() == 1 and light_sensor_ADC.read_u16() > 35000: - Led_R.duty_u16(65535) - Led_G.duty_u16(65535) - Led_B.duty_u16(65535) - else: - Led_R.duty_u16(0) - Led_G.duty_u16(0) - Led_B.duty_u16(0) - - -loop() \ No newline at end of file diff --git a/src/kits/elecrow-adv/clock.py b/src/kits/elecrow-adv/clock.py deleted file mode 100644 index c56d69a65..000000000 --- a/src/kits/elecrow-adv/clock.py +++ /dev/null @@ -1,25 +0,0 @@ -import tm1637 -from machine import Pin -from utime import sleep, localtime -tm = tm1637.TM1637(clk=Pin(1), dio=Pin(0)) -now = localtime() -hour = now[3] -if hour > 12: - hour = hour - 12 -minute = now[4] -sec = now[5] -print(hour, ':', minute, ' ', sec, sep='') -while True: - tm.numbers(hour,minute,colon=True) - sleep(0.5) - tm.numbers(hour,minute,colon=False) - sleep(0.5) - sec = sec + 1 - if sec == 60: - minute = minute + 1 - sec = 0 - if minute == 60: - hour = hour + 1 - minute = 0 - if hour == 24: - hour = 0 \ No newline at end of file diff --git a/src/kits/elecrow-adv/laser-sight.py b/src/kits/elecrow-adv/laser-sight.py deleted file mode 100644 index 32b05567c..000000000 --- a/src/kits/elecrow-adv/laser-sight.py +++ /dev/null @@ -1,44 +0,0 @@ -from machine import Pin,ADC,PWM -from utime import sleep - -photo = 0 -LaserPin = 15 -Led_R = PWM(Pin(11)) -Led_G = PWM(Pin(12)) -Led_B = PWM(Pin(13)) -Led_R.freq(2000) -Led_G.freq(2000) -Led_B.freq(2000) - -def setup(): -global Laser -global photo_ADC -photo_ADC = ADC(photo) -Laser = Pin(LaserPin,machine.Pin.OUT) Laser.value(0) - -aim_time = 0 - -while True: - Laser.value(1) - Led_R.duty_u16(0) - Led_G.duty_u16(65535) - Led_B.duty_u16(0) - print("time:",aim_time) - sleep(0.1) - aim_time += 0.1 - if photo_ADC.read_u16() < 15000: - print("Aimed:",aim_time) - aim_time = 0 - for i in range(10): - Led_R.duty_u16(65535) - Led_G.duty_u16(0) - Led_B.duty_u16(0) - sleep(0.1) - Led_R.duty_u16(0) - # Hit by a red laser, the light flashes - # red light - # blue light - Led_G.duty_u16(0) - Led_B.duty_u16(65535) - sleep(0.1) - sleep(2) diff --git a/src/kits/elecrow-adv/police-car-v2.py b/src/kits/elecrow-adv/police-car-v2.py deleted file mode 100644 index f94f143d5..000000000 --- a/src/kits/elecrow-adv/police-car-v2.py +++ /dev/null @@ -1,30 +0,0 @@ -from utime import sleep -from machine import Pin,PWM - -# Pins -RED_PIN = 13 -BLUE_PIN = 14 -BUZZER_PIN = 15 - -# pin objects -red_led = machine.Pin(RED_PIN, machine.Pin.OUT) -blue_led = machine.Pin(BLUE_PIN, machine.Pin.OUT) -buzzer = PWM(Pin(BUZZER_PIN)) -buzzer.duty_u16(1000) - -def main(): - while True: - buzzer.freq(750) # low frequence tone - red_led.on() - blue_led.off() - sleep(.2) - buzzer.freq(1200) # high frequence tone - red_led.off() - blue_led.on() - sleep(.2) - -try: - main() -except KeyboardInterrupt: - buzzer.duty_u16(0) - print("sound off") \ No newline at end of file diff --git a/src/kits/elecrow-adv/police-car.py b/src/kits/elecrow-adv/police-car.py deleted file mode 100644 index 24ec9ee87..000000000 --- a/src/kits/elecrow-adv/police-car.py +++ /dev/null @@ -1,29 +0,0 @@ -from utime import sleep -from machine import Pin,PWM -Led_R = PWM(Pin(4)) -Led_G = PWM(Pin(3)) -Led_B = PWM(Pin(2)) -buzzer = PWM(Pin(15)) -Led_R.freq(2000) -Led_G.freq(2000) -Led_B.freq(2000) -buzzer.duty_u16(1000) - -def main(): - while True: - buzzer.freq(750) - Led_R.duty_u16(0) - Led_G.duty_u16(0) - Led_B.duty_u16(65535) - sleep(.23) - buzzer.freq(1550) - Led_R.duty_u16(65535) - Led_G.duty_u16(0) - Led_B.duty_u16(0) - sleep(.1) - -try: - main() -except KeyboardInterrupt: - buzzer.duty_u16(0) - print("sound off") \ No newline at end of file diff --git a/src/kits/elecrow-adv/rfid-read.py b/src/kits/elecrow-adv/rfid-read.py deleted file mode 100644 index ce6077619..000000000 --- a/src/kits/elecrow-adv/rfid-read.py +++ /dev/null @@ -1,58 +0,0 @@ -# https://github.com/wendlers/micropython-mfrc522/blob/master/examples/read.py -import mfrc522 -from machine import Pin -from servo import Servo -import utime - -s1 = Servo(0) -sck = 6 -mosi = 7 -miso = 4 -cs = 5 #SDA pin -rst = 22 - -def servo_Angle(angle): - if angle < 0: - angle = 0 - if angle > 180: - angle = 180 - s1.goto(round(angle * 1024 / 180)) - -def do_read(): - rdr = mfrc522.MFRC522(sck=sck, mosi=mosi, miso=miso, rst=rst, cs=cs) - print("") - print("Place card before reader to read from address 0x08") - print("") - - try: - while True: - num = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] - (stat, tag_type) = rdr.request(rdr.REQIDL) - if stat == rdr.OK: - (stat, raw_uid) = rdr.anticoll() - if stat == rdr.OK: # Access code - print("New card detected") - print(" - tag type: 0x%02x" % tag_type) - print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) - print("") - if rdr.select_tag(raw_uid) == rdr.OK: - key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] - if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: - if rdr.read(8) == num: - for i in range(0,180,10): - servo_Angle(i) - utime.sleep(0.05) - utime.sleep(1) - for i in range(180,0,-10): - servo_Angle(i) - utime.sleep(0.05) - else: - servo_Angle(0) - rdr.stop_crypto1() - else: - print("Authentication error") else: - print("Failed to select tag") - except KeyboardInterrupt: - print("Bye") - -do_read() # Read success, return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] \ No newline at end of file diff --git a/src/kits/elecrow-adv/rfid-write.py b/src/kits/elecrow-adv/rfid-write.py deleted file mode 100644 index 089627d72..000000000 --- a/src/kits/elecrow-adv/rfid-write.py +++ /dev/null @@ -1,40 +0,0 @@ -# RFID from https://github.com/wendlers/micropython-mfrc522/blob/master/examples/write.py -import mfrc522 -from machine import Pin - -sck = 6 -mosi = 7 -miso = 4 -cs = 5 #SDA pin rst = 22 - -def do_write(): - rdr = mfrc522.MFRC522(sck=sck, mosi=mosi, miso=miso, rst=rst, cs=cs) print("") - print("Place card before reader to write address 0x08") - print("") - try: - while True: - (stat, tag_type) = rdr.request(rdr.REQIDL) - if stat == rdr.OK: - (stat, raw_uid) = rdr.anticoll() - if stat == rdr.OK: - print("New card detected") - print(" - tag type: 0x%02x" % tag_type) - print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) - print("") - if rdr.select_tag(raw_uid) == rdr.OK: - key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] - if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: - stat = rdr.write(8, b"\ x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0a \x0b \x0c \x0d \x0e \x0f") - rdr.stop_crypto1() - if stat == rdr.OK: - print("Data written to card") - else: - print("Failed to write data to card") - else: - print("Authentication error") - else: - print("Failed to select tag") - except KeyboardInterrupt: - print("Bye") - -do_write() # write [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] diff --git a/src/kits/elecrow-adv/rfid.py b/src/kits/elecrow-adv/rfid.py deleted file mode 100644 index fc74e6b90..000000000 --- a/src/kits/elecrow-adv/rfid.py +++ /dev/null @@ -1,39 +0,0 @@ -import mfrc522 -from machine import Pin - -sck = 6 -mosi = 7 -miso = 4 -cs = 5 #SDA pin rst = 22 - -def do_write(): - rdr = mfrc522.MFRC522(sck=sck, mosi=mosi, miso=miso, rst=rst, cs=cs) print("") - print("Place card before reader to write address 0x08") - print("") - try: - while True: - (stat, tag_type) = rdr.request(rdr.REQIDL) - if stat == rdr.OK: - (stat, raw_uid) = rdr.anticoll() - if stat == rdr.OK: - print("New card detected") - print(" - tag type: 0x%02x" % tag_type) - print(" - uid : 0x%02x%02x%02x%02x" % (raw_uid[0], raw_uid[1], raw_uid[2], raw_uid[3])) - print("") - if rdr.select_tag(raw_uid) == rdr.OK: - key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] - if rdr.auth(rdr.AUTHENT1A, 8, key, raw_uid) == rdr.OK: - stat = rdr.write(8, b"\ x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \x09 \x0a \x0b \x0c \x0d \x0e \x0f") - rdr.stop_crypto1() - if stat == rdr.OK: - print("Data written to card") - else: - print("Failed to write data to card") - else: - print("Authentication error") - else: - print("Failed to select tag") - except KeyboardInterrupt: - print("Bye") - -do_write() # write [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] diff --git a/src/kits/elecrow-adv/rotery-timer.py b/src/kits/elecrow-adv/rotery-timer.py deleted file mode 100644 index 05d8c9af4..000000000 --- a/src/kits/elecrow-adv/rotery-timer.py +++ /dev/null @@ -1,71 +0,0 @@ -import tm1637 -from machine import Pin -from utime import sleep - -DATA_PIN = 0 -CLOCK_PIN = 1 - -tm = tm1637.TM1637(clk=Pin(CLOCK_PIN), dio=Pin(DATA_PIN)) - -RoA_Pin = 0 -RoB_Pin = 1 -Btn_Pin = 2 -globalCounter = 0 -flag = 0 -Last_RoB_Status = 0 -Current_RoB_Status = 0 - -# CLK # DT # SW -# counter value -# Whether the rotation flag occurs -# DT state # CLK state -clk_RoA = Pin(RoA_Pin, Pin.IN) -dt_RoB = Pin(RoB_Pin, Pin.IN) -sw_BtN = Pin(Btn_Pin, Pin.IN, Pin.PULL_UP) - -# Initialize the interrupt function, when the SW pin is 0, the interrupt is enabled -sw_BtN.irq(trigger=Pin.IRQ_FALLING, handler=btnISR) - -# Rotation code direction bit judgment function -def rotaryDeal(): - global flag - global Last_RoB_Status - global Current_RoB_Status - global globalCounter - - Last_RoB_Status = dt_RoB.value() - - # Judging the level change of the CLK pin to distinguish the direction - while(not clk_RoA.value()): - Current_RoB_Status = dt_RoB.value() - - flag = 1 - if flag == 1: - flag = 0 - # Rotation mark occurs - # The flag bit is 1 and a rotation has occurred - # Reset flag bit - if (Last_RoB_Status == 0) and (Current_RoB_Status == 1): - globalCounter = globalCounter + 1 # counterclockwise, positive - if (Last_RoB_Status == 1) and (Current_RoB_Status == 0): - globalCounter = globalCounter - 1 # Clockwise, negative - -# Interrupt function, when the SW pin is 0, the interrupt is enabled -def btnISR(chn): - global globalCounter - globalCounter = 0 - print ('globalCounter = %d' %globalCounter) - -tmp = 0 - -while True: - rotaryDeal() - if tmp != globalCounter: - print('globalCounter = %d' % globalCounter) - tmp = globalCounter - tm.number(globalCounter) - - if globalCounter == 0: - break - - diff --git a/src/kits/elecrow-adv/sound-activate-light.py b/src/kits/elecrow-adv/sound-activate-light.py deleted file mode 100644 index 772381b14..000000000 --- a/src/kits/elecrow-adv/sound-activate-light.py +++ /dev/null @@ -1,24 +0,0 @@ -# Elcrow Voice-activated Light -# so -from machine import Pin,PWM -from utime import sleep_ms - -sound = Pin(0, Pin.IN, Pin.PULL_DOWN) Led_R = PWM(Pin(2)) - -Led_G = PWM(Pin(3)) -Led_B = PWM(Pin(4)) -Led_R.freq(2000) -Led_G.freq(2000) -Led_B.freq(2000) - -while True: - print(sound.value()) - if sound.value() == 1: - Led_R.duty_u16(65535) - Led_G.duty_u16(65535) - Led_B.duty_u16(65535) - sleep_ms(2000) - else: - Led_R.duty_u16(0) - Led_G.duty_u16(0) - Led_B.duty_u16(0) \ No newline at end of file diff --git a/src/kits/elecrow-adv/sound-level-print.py b/src/kits/elecrow-adv/sound-level-print.py deleted file mode 100644 index d95c3712d..000000000 --- a/src/kits/elecrow-adv/sound-level-print.py +++ /dev/null @@ -1,12 +0,0 @@ -# Elcrow Voice-activated Light -# Connect OUT to GP0 -from machine import Pin,PWM -from utime import sleep_ms - -sound = Pin(0, Pin.IN, Pin.PULL_DOWN) - -while True: - print(sound.value()) - if sound.value() == 1: - print(1) - sleep_ms(50) \ No newline at end of file diff --git a/src/kits/elecrow-adv/stoplight-with-timer.py b/src/kits/elecrow-adv/stoplight-with-timer.py deleted file mode 100644 index ef7fbfec1..000000000 --- a/src/kits/elecrow-adv/stoplight-with-timer.py +++ /dev/null @@ -1,29 +0,0 @@ -import tm1637 -from machine import Pin -from utime import sleep - -DATA_PIN = 0 -CLOCK_PIN = 1 - -tm = tm1637.TM1637(clk=Pin(CLOCK_PIN), dio=Pin(DATA_PIN)) - -Led_R = Pin(0, Pin.OUT) -Led_Y = Pin(1, Pin.OUT) -Led_G = Pin(2, Pin.OUT) - -while True: - num = 30 - Led_R.value(1) - for i in range(30): - num=num-1 - tm.number(num) - sleep(1) - Led_R.value(0) - for i in range(5): - Led_Y.value(1) - sleep(0.3) - Led_Y.value(0) - sleep(0.3) - Led_G.value(1) - sleep(10) - Led_G.value(0) \ No newline at end of file diff --git a/src/kits/elecrow-adv/tm1637.py b/src/kits/elecrow-adv/tm1637.py deleted file mode 100644 index 2cc9d6dba..000000000 --- a/src/kits/elecrow-adv/tm1637.py +++ /dev/null @@ -1,196 +0,0 @@ -from micropython import const -from machine import Pin -from time import sleep_us, sleep_ms - -TM1637_CMD1 = const(64) # 0x40 data command -TM1637_CMD2 = const(192) # 0xC0 address command -TM1637_CMD3 = const(128) # 0x80 display control command -TM1637_DSP_ON = const(8) # 0x08 display on -TM1637_DELAY = const(10) # 10us delay between clk/dio pulses -TM1637_MSB = const(128) # msb is the decimal point or the colon depending on your display - -# 0-9, a-z, blank, dash, star -_SEGMENTS = bytearray(b'\x3F\x06\x5B\x4F\x66\x6D\x7D\x07\x7F\x6F\x77\x7C\x39\x5E\x79\x71\x3D\x76\x06\x1E\x76\x38\x55\x54\x3F\x73\x67\x50\x6D\x78\x3E\x1C\x2A\x76\x6E\x5B\x00\x40\x63') - -class TM1637(object): - """Library for quad 7-segment LED modules based on the TM1637 LED driver.""" - def __init__(self, clk, dio, brightness=7): - self.clk = clk - self.dio = dio - - if not 0 <= brightness <= 7: - raise ValueError("Brightness out of range") - self._brightness = brightness - - self.clk.init(Pin.OUT, value=0) - self.dio.init(Pin.OUT, value=0) - sleep_us(TM1637_DELAY) - - self._write_data_cmd() - self._write_dsp_ctrl() - - def _start(self): - self.dio(0) - sleep_us(TM1637_DELAY) - self.clk(0) - sleep_us(TM1637_DELAY) - - def _stop(self): - self.dio(0) - sleep_us(TM1637_DELAY) - self.clk(1) - sleep_us(TM1637_DELAY) - self.dio(1) - - def _write_data_cmd(self): - # automatic address increment, normal mode - self._start() - self._write_byte(TM1637_CMD1) - self._stop() - - def _write_dsp_ctrl(self): - # display on, set brightness - self._start() - self._write_byte(TM1637_CMD3 | TM1637_DSP_ON | self._brightness) - self._stop() - - def _write_byte(self, b): - for i in range(8): - self.dio((b >> i) & 1) - sleep_us(TM1637_DELAY) - self.clk(1) - sleep_us(TM1637_DELAY) - self.clk(0) - sleep_us(TM1637_DELAY) - self.clk(0) - sleep_us(TM1637_DELAY) - self.clk(1) - sleep_us(TM1637_DELAY) - self.clk(0) - sleep_us(TM1637_DELAY) - - def brightness(self, val=None): - """Set the display brightness 0-7.""" - # brightness 0 = 1/16th pulse width - # brightness 7 = 14/16th pulse width - if val is None: - return self._brightness - if not 0 <= val <= 7: - raise ValueError("Brightness out of range") - - self._brightness = val - self._write_data_cmd() - self._write_dsp_ctrl() - - def write(self, segments, pos=0): - """Display up to 6 segments moving right from a given position. - The MSB in the 2nd segment controls the colon between the 2nd - and 3rd segments.""" - if not 0 <= pos <= 5: - raise ValueError("Position out of range") - self._write_data_cmd() - self._start() - - self._write_byte(TM1637_CMD2 | pos) - for seg in segments: - self._write_byte(seg) - self._stop() - self._write_dsp_ctrl() - - def encode_digit(self, digit): - """Convert a character 0-9, a-f to a segment.""" - return _SEGMENTS[digit & 0x0f] - - def encode_string(self, string): - """Convert an up to 4 character length string containing 0-9, a-z, - space, dash, star to an array of segments, matching the length of the - source string.""" - segments = bytearray(len(string)) - for i in range(len(string)): - segments[i] = self.encode_char(string[i]) - return segments - - def encode_char(self, char): - """Convert a character 0-9, a-z, space, dash or star to a segment.""" - o = ord(char) - if o == 32: - return _SEGMENTS[36] # space - if o == 42: - return _SEGMENTS[38] # star/degrees - if o == 45: - return _SEGMENTS[37] # dash - if o >= 65 and o <= 90: - return _SEGMENTS[o-55] # uppercase A-Z - if o >= 97 and o <= 122: - return _SEGMENTS[o-87] # lowercase a-z - if o >= 48 and o <= 57: - return _SEGMENTS[o-48] # 0-9 - raise ValueError("Character out of range: {:d} '{:s}'".format(o, chr(o))) - - def hex(self, val): - """Display a hex value 0x0000 through 0xffff, right aligned.""" - string = '{:04x}'.format(val & 0xffff) - self.write(self.encode_string(string)) - - def number(self, num): - """Display a numeric value -999 through 9999, right aligned.""" - # limit to range -999 to 9999 - num = max(-999, min(num, 9999)) - string = '{0: >4d}'.format(num) - self.write(self.encode_string(string)) - - def numbers(self, num1, num2, colon=True): - """Display two numeric values -9 through 99, with leading zeros - and separated by a colon.""" - num1 = max(-9, min(num1, 99)) - num2 = max(-9, min(num2, 99)) - segments = self.encode_string('{0:0>2d}{1:0>2d}'.format(num1, num2)) - if colon: - segments[1] |= 0x80 # colon on - self.write(segments) - - def temperature(self, num): - if num < -9: - self.show('lo') # low - elif num > 99: - self.show('hi') # high - else: - string = '{0: >2d}'.format(num) - self.write(self.encode_string(string)) - self.write([_SEGMENTS[38], _SEGMENTS[12]], 2) # degrees C - - def show(self, string, colon=False): - segments = self.encode_string(string) - if len(segments) > 1 and colon: - segments[1] |= 128 - self.write(segments[:4]) - - def scroll(self, string, delay=250): - segments = string if isinstance(string, list) else self.encode_string(string) - data = [0] * 8 - data[4:0] = list(segments) - for i in range(len(segments) + 5): - self.write(data[0+i:4+i]) - sleep_ms(delay) - - -class TM1637Decimal(TM1637): - """Library for quad 7-segment LED modules based on the TM1637 LED driver. - This class is meant to be used with decimal display modules (modules - that have a decimal point after each 7-segment LED). - """ - - def encode_string(self, string): - """Convert a string to LED segments. - Convert an up to 4 character length string containing 0-9, a-z, - space, dash, star and '.' to an array of segments, matching the length of - the source string.""" - segments = bytearray(len(string.replace('.',''))) - j = 0 - for i in range(len(string)): - if string[i] == '.' and j > 0: - segments[j-1] |= TM1637_MSB - continue - segments[j] = self.encode_char(string[i]) - j += 1 - return segments diff --git a/src/kits/farm-animal-tracker/DesignnSpark_hotfix_DS_11.0.1.exe b/src/kits/farm-animal-tracker/DesignnSpark_hotfix_DS_11.0.1.exe deleted file mode 100644 index 9682ba044..000000000 Binary files a/src/kits/farm-animal-tracker/DesignnSpark_hotfix_DS_11.0.1.exe and /dev/null differ diff --git a/src/kits/farm-animal-tracker/Farm Animal Manager.mp4 b/src/kits/farm-animal-tracker/Farm Animal Manager.mp4 deleted file mode 100644 index b35945c20..000000000 Binary files a/src/kits/farm-animal-tracker/Farm Animal Manager.mp4 and /dev/null differ diff --git a/src/kits/farm-animal-tracker/FarmAnimalManager Holder.3mf b/src/kits/farm-animal-tracker/FarmAnimalManager Holder.3mf deleted file mode 100644 index c7fc9a65f..000000000 Binary files a/src/kits/farm-animal-tracker/FarmAnimalManager Holder.3mf and /dev/null differ diff --git a/src/kits/farm-animal-tracker/FarmAnimalManager Holder.stl b/src/kits/farm-animal-tracker/FarmAnimalManager Holder.stl deleted file mode 100644 index 379377916..000000000 Binary files a/src/kits/farm-animal-tracker/FarmAnimalManager Holder.stl and /dev/null differ diff --git a/src/kits/farm-animal-tracker/OLED_RFID_WireDiagram.png b/src/kits/farm-animal-tracker/OLED_RFID_WireDiagram.png deleted file mode 100644 index 9da2f7869..000000000 Binary files a/src/kits/farm-animal-tracker/OLED_RFID_WireDiagram.png and /dev/null differ diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_prl b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_prl deleted file mode 100644 index 29559b5e0..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_prl +++ /dev/null @@ -1,77 +0,0 @@ -{ - "board": { - "active_layer": 0, - "active_layer_preset": "", - "auto_track_width": true, - "hidden_netclasses": [], - "hidden_nets": [], - "high_contrast_mode": 0, - "net_color_mode": 1, - "opacity": { - "images": 0.6, - "pads": 1.0, - "tracks": 1.0, - "vias": 1.0, - "zones": 0.6 - }, - "selection_filter": { - "dimensions": true, - "footprints": true, - "graphics": true, - "keepouts": true, - "lockedItems": false, - "otherItems": true, - "pads": true, - "text": true, - "tracks": true, - "vias": true, - "zones": true - }, - "visible_items": [ - 0, - 1, - 2, - 3, - 4, - 5, - 8, - 9, - 10, - 11, - 12, - 13, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 32, - 33, - 34, - 35, - 36, - 39, - 40 - ], - "visible_layers": "fffffff_ffffffff", - "zone_display_mode": 0 - }, - "meta": { - "filename": "PICO_FarmAnimalManager_V2.kicad_prl", - "version": 3 - }, - "project": { - "files": [] - } -} diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_pro b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_pro deleted file mode 100644 index 209006c70..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_V2.kicad_pro +++ /dev/null @@ -1,229 +0,0 @@ -{ - "board": { - "3dviewports": [], - "design_settings": { - "defaults": { - "board_outline_line_width": 0.049999999999999996, - "copper_line_width": 0.19999999999999998, - "copper_text_italic": false, - "copper_text_size_h": 1.5, - "copper_text_size_v": 1.5, - "copper_text_thickness": 0.3, - "copper_text_upright": false, - "courtyard_line_width": 0.049999999999999996, - "dimension_precision": 4, - "dimension_units": 3, - "dimensions": { - "arrow_length": 1270000, - "extension_offset": 500000, - "keep_text_aligned": true, - "suppress_zeroes": false, - "text_position": 0, - "units_format": 1 - }, - "fab_line_width": 0.09999999999999999, - "fab_text_italic": false, - "fab_text_size_h": 1.0, - "fab_text_size_v": 1.0, - "fab_text_thickness": 0.15, - "fab_text_upright": false, - "other_line_width": 0.09999999999999999, - "other_text_italic": false, - "other_text_size_h": 1.0, - "other_text_size_v": 1.0, - "other_text_thickness": 0.15, - "other_text_upright": false, - "pads": { - "drill": 0.762, - "height": 1.524, - "width": 1.524 - }, - "silk_line_width": 0.09999999999999999, - "silk_text_italic": false, - "silk_text_size_h": 1.0, - "silk_text_size_v": 1.0, - "silk_text_thickness": 0.09999999999999999, - "silk_text_upright": false, - "zones": { - "min_clearance": 0.5 - } - }, - "diff_pair_dimensions": [], - "drc_exclusions": [], - "meta": { - "version": 2 - }, - "rule_severities": { - "annular_width": "error", - "clearance": "error", - "connection_width": "warning", - "copper_edge_clearance": "error", - "copper_sliver": "warning", - "courtyards_overlap": "error", - "diff_pair_gap_out_of_range": "error", - "diff_pair_uncoupled_length_too_long": "error", - "drill_out_of_range": "error", - "duplicate_footprints": "warning", - "extra_footprint": "warning", - "footprint": "error", - "footprint_type_mismatch": "ignore", - "hole_clearance": "error", - "hole_near_hole": "error", - "invalid_outline": "error", - "isolated_copper": "warning", - "item_on_disabled_layer": "error", - "items_not_allowed": "error", - "length_out_of_range": "error", - "lib_footprint_issues": "warning", - "lib_footprint_mismatch": "warning", - "malformed_courtyard": "error", - "microvia_drill_out_of_range": "error", - "missing_courtyard": "ignore", - "missing_footprint": "warning", - "net_conflict": "warning", - "npth_inside_courtyard": "ignore", - "padstack": "warning", - "pth_inside_courtyard": "ignore", - "shorting_items": "error", - "silk_edge_clearance": "warning", - "silk_over_copper": "warning", - "silk_overlap": "warning", - "skew_out_of_range": "error", - "solder_mask_bridge": "error", - "starved_thermal": "error", - "text_height": "warning", - "text_thickness": "warning", - "through_hole_pad_without_hole": "error", - "too_many_vias": "error", - "track_dangling": "warning", - "track_width": "error", - "tracks_crossing": "error", - "unconnected_items": "error", - "unresolved_variable": "error", - "via_dangling": "warning", - "zones_intersect": "error" - }, - "rules": { - "max_error": 0.005, - "min_clearance": 0.0, - "min_connection": 0.0, - "min_copper_edge_clearance": 0.5, - "min_hole_clearance": 0.25, - "min_hole_to_hole": 0.25, - "min_microvia_diameter": 0.19999999999999998, - "min_microvia_drill": 0.09999999999999999, - "min_resolved_spokes": 2, - "min_silk_clearance": 0.0, - "min_text_height": 0.7999999999999999, - "min_text_thickness": 0.08, - "min_through_hole_diameter": 0.3, - "min_track_width": 0.0, - "min_via_annular_width": 0.09999999999999999, - "min_via_diameter": 0.5, - "solder_mask_to_copper_clearance": 0.0, - "use_height_for_length_calcs": true - }, - "teardrop_options": [ - { - "td_allow_use_two_tracks": true, - "td_curve_segcount": 5, - "td_on_pad_in_zone": false, - "td_onpadsmd": true, - "td_onroundshapesonly": false, - "td_ontrackend": false, - "td_onviapad": true - } - ], - "teardrop_parameters": [ - { - "td_curve_segcount": 0, - "td_height_ratio": 1.0, - "td_length_ratio": 0.5, - "td_maxheight": 2.0, - "td_maxlen": 1.0, - "td_target_name": "td_round_shape", - "td_width_to_size_filter_ratio": 0.9 - }, - { - "td_curve_segcount": 0, - "td_height_ratio": 1.0, - "td_length_ratio": 0.5, - "td_maxheight": 2.0, - "td_maxlen": 1.0, - "td_target_name": "td_rect_shape", - "td_width_to_size_filter_ratio": 0.9 - }, - { - "td_curve_segcount": 0, - "td_height_ratio": 1.0, - "td_length_ratio": 0.5, - "td_maxheight": 2.0, - "td_maxlen": 1.0, - "td_target_name": "td_track_end", - "td_width_to_size_filter_ratio": 0.9 - } - ], - "track_widths": [], - "via_dimensions": [], - "zones_allow_external_fillets": false - }, - "layer_presets": [], - "viewports": [] - }, - "boards": [], - "cvpcb": { - "equivalence_files": [] - }, - "libraries": { - "pinned_footprint_libs": [], - "pinned_symbol_libs": [] - }, - "meta": { - "filename": "PICO_FarmAnimalManager_V2.kicad_pro", - "version": 1 - }, - "net_settings": { - "classes": [ - { - "bus_width": 12, - "clearance": 0.2, - "diff_pair_gap": 0.25, - "diff_pair_via_gap": 0.25, - "diff_pair_width": 0.2, - "line_style": 0, - "microvia_diameter": 0.3, - "microvia_drill": 0.1, - "name": "Default", - "pcb_color": "rgba(0, 0, 0, 0.000)", - "schematic_color": "rgba(0, 0, 0, 0.000)", - "track_width": 0.2, - "via_diameter": 0.6, - "via_drill": 0.3, - "wire_width": 6 - } - ], - "meta": { - "version": 3 - }, - "net_colors": null, - "netclass_assignments": null, - "netclass_patterns": [] - }, - "pcbnew": { - "last_paths": { - "gencad": "", - "idf": "", - "netlist": "./", - "specctra_dsn": "", - "step": "", - "vrml": "" - }, - "page_layout_descr_file": "" - }, - "schematic": { - "legacy_lib_dir": "", - "legacy_lib_list": [] - }, - "sheets": [], - "text_variables": {} -} diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (PCB - Design Rule Check Report).txt b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (PCB - Design Rule Check Report).txt deleted file mode 100644 index 227687fb1..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (PCB - Design Rule Check Report).txt +++ /dev/null @@ -1,73 +0,0 @@ -Design Rule Check Report ------------------------- - -Report Written: Thursday, November 16, 2023 -Design Path: C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5.pcb -Design Title: -Created: 10/19/2023 10:11:24 AM -Last Saved: 11/16/2023 10:09:12 PM -Editing Time: 362 min -Units: thou (precision 0) - - -Results -======= - -Gap in Net "N0004" between (9150,10750) and (9150,10650) - N0004. -Gap in Net "N0012" between (10050,11000) and (10750,11000) - N0012. -Gap in Net "N0015" between (10050,10600) and (10050,11200) - N0015. -Dangling Track from (9150,10050) to (9195,10050) on layer Top Copper - -Number of errors found : 4 - - -Settings -======== - - -Spacings - -========= - -Tracks Yes -Pads and Vias Yes -Shapes Yes -Text Yes -Board Yes -Drills Yes -Components Yes - - -Manufacturing - -============== - -Drill Breakout Yes -Drill Backoff Yes -Silkscreen Overlap Yes -Copper Text In Board Yes -Min Track Width Yes -Min Annular Ring Yes -Min Paste Size Yes -Vias In Pads Yes -Unplated Vias Yes -Unplated Pads With Inner Tracks Yes - - -Nets - -===== - -Net Completion Yes -Dangling Tracks Yes -Net Track Length Differences No -Nets without Components No -Nets on No Connect pins No -Nets on No Connect pins No - - - -End Of Report. diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (Plot Report).txt b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (Plot Report).txt deleted file mode 100644 index 70d7990e7..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 (Plot Report).txt +++ /dev/null @@ -1,210 +0,0 @@ -Plot Report ------------ - -Report Written: Thursday, November 16, 2023 -Design Path: C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5.pcb -Design Title: -Created: 10/19/2023 10:11:24 AM -Last Saved: 11/16/2023 10:12:49 PM -Editing Time: 364 min -Units: thou (precision 0) - - -Device Settings -=============== - - -Gerber Settings -=============== - - Leading zero suppression. - G01 assumed throughout. - Line termination <*> . - 3.5 format absolute inches. - Format commands defined in Gerber file. - Aperture table defined in Gerber file. - Hardware arcs allowed. - - -Drill Settings -============== - - Excellon Format 2 - Format 2.4 absolute in inches. - Zero suppression Leading - - - -Plots Output -============ - - Plot Job: "C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5.mop" - - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Top Silkscreen.gbr - - Layers: - ------------------ - Top Silkscreen - - D-Code Shape (thou) - ----------------------- - D10 Round 5.00 - D11 Round 1.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Top Copper.gbr - - Layers: - -------------- - Top Copper - - D-Code Shape (thou) - ---------------------------------------------- - D13 Round 15.00 - D23 Rectangle 55.00 X 75.00 Rotation 90 - D24 Rectangle 55.00 X 75.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Top Copper (Resist).gbr - - Layers: - -------------- - Top Copper - - D-Code Shape (thou) - ---------------------------------------------- - D25 Rectangle 65.00 X 85.00 Rotation 90 - D26 Rectangle 65.00 X 85.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Top Assembly.gbr - - Layers: - ---------------- - Top Assembly - - D-Code Shape (thou) - ---------------------------------------------- - D10 Round 5.00 - D23 Rectangle 55.00 X 75.00 Rotation 90 - D24 Rectangle 55.00 X 75.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Bottom Copper.gbr - - Layers: - ----------------- - Bottom Copper - - D-Code Shape (thou) - ---------------------------------------------- - D13 Round 15.00 - D23 Rectangle 55.00 X 75.00 Rotation 90 - D24 Rectangle 55.00 X 75.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Bottom Resist.gbr - - Layers: - ----------------- - Bottom Resist - - D-Code Shape (thou) - ---------------------------------------------- - D28 Rectangle 61.00 X 81.00 Rotation 90 - D29 Rectangle 61.00 X 81.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Gerber Drill Data - [Through Hole].gbr - - Layers: - ------------------ - [Through Hole] - - D-Code Shape (thou) - ----------------------- - D73 Round 35.00 - -NC Drill Output -=============== - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - NC Drill Data - [Through Hole].drl - - Output: - --------------------------- - Plated Round Drill Holes - Plated Slots - - Tool Size Count ID - ------------------------------------- - T001 0.0350 inches 92 D - ------------------------------------- - Total 92 - ------------------------------------- - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - NC Drill Data - [Through Hole] (Unplated).drl - - Output: - ----------------------------- - Unplated Round Drill Holes - Unplated Slots - - Tool Size Count ID - ---------------------------- - ---------------------------- - Total 0 - ---------------------------- - - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Drill Ident Drawing - [Through Hole].gbr - - Layers: - ------------------ - [Through Hole] - - -Drill Ident Drawing -=================== - - Drill Plated Size Shape ID - ----------------------------------- - 35 Y 100 Round D - - D-Code Shape (thou) - ----------------------- - D10 Round 5.00 - D21 Round 100.00 - -Gerber Output -============= - -C:\Users\carlb\OneDrive\Documents\GitHub\micropython\src\kits\farm-animal-tracker\PICO_FarmAnimalManager_v5 - Board Outline.gbr - - Layers: - ------------------ - Board Outlines - - D-Code Shape (thou) - ----------------------- - D10 Round 5.00 - -End Of Report. diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Board Outline.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Board Outline.gbr deleted file mode 100644 index 749170570..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Board Outline.gbr +++ /dev/null @@ -1,14 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD10C,0.00500*% -X0Y0D02* -D02* -D10* -X250Y250D02* -X360250D01* -Y250250D01* -X250D01* -Y250D01* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Copper.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Copper.gbr deleted file mode 100644 index 1007ee607..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Copper.gbr +++ /dev/null @@ -1,125 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD24R,0.05500X0.07500*% -%ADD13C,0.01500*% -%ADD23R,0.07500X0.05500*% -X0Y0D02* -D02* -D13* -X45250Y115250D02* -X70250D01* -Y120250D01* -X90250Y140250D01* -X104750D01* -X105250Y140750D01* -X45250Y135250D02* -X55250D01* -X90250Y170250D01* -X105250D01* -X45250Y155250D02* -X59750D01* -X105250Y200750D01* -Y140750D02* -Y140250D01* -X135250D01* -X105250Y170250D02* -X135250D01* -D02* -D23* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -D02* -D24* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Resist.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Resist.gbr deleted file mode 100644 index 8aa36094f..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Bottom Resist.gbr +++ /dev/null @@ -1,104 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD29R,0.06100X0.08100*% -%ADD28R,0.08100X0.06100*% -X0Y0D02* -D02* -D28* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -D02* -D29* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Drill Ident Drawing - [Through Hole].gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Drill Ident Drawing - [Through Hole].gbr deleted file mode 100644 index 5573b972c..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Drill Ident Drawing - [Through Hole].gbr +++ /dev/null @@ -1,1116 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD10C,0.00500*% -%ADD21C,0.10000*% -X0Y0D02* -D02* -D10* -X55250Y111187D02* -Y114937D01* -X57125D01* -X57750Y114625D01* -X58063Y114313D01* -X58375Y113687D01* -Y112437D01* -X58063Y111813D01* -X57750Y111500D01* -X57125Y111187D01* -X55250D01* -Y121187D02* -Y124937D01* -X57125D01* -X57750Y124625D01* -X58063Y124313D01* -X58375Y123687D01* -Y122437D01* -X58063Y121813D01* -X57750Y121500D01* -X57125Y121187D01* -X55250D01* -Y131187D02* -Y134937D01* -X57125D01* -X57750Y134625D01* -X58063Y134313D01* -X58375Y133687D01* -Y132437D01* -X58063Y131813D01* -X57750Y131500D01* -X57125Y131187D01* -X55250D01* -Y141187D02* -Y144937D01* -X57125D01* -X57750Y144625D01* -X58063Y144313D01* -X58375Y143687D01* -Y142437D01* -X58063Y141813D01* -X57750Y141500D01* -X57125Y141187D01* -X55250D01* -Y151187D02* -Y154937D01* -X57125D01* -X57750Y154625D01* -X58063Y154313D01* -X58375Y153687D01* -Y152437D01* -X58063Y151813D01* -X57750Y151500D01* -X57125Y151187D01* -X55250D01* -Y161187D02* -Y164937D01* -X57125D01* -X57750Y164625D01* -X58063Y164313D01* -X58375Y163687D01* -Y162437D01* -X58063Y161813D01* -X57750Y161500D01* -X57125Y161187D01* -X55250D01* -Y171187D02* -Y174937D01* -X57125D01* -X57750Y174625D01* -X58063Y174313D01* -X58375Y173687D01* -Y172437D01* -X58063Y171813D01* -X57750Y171500D01* -X57125Y171187D01* -X55250D01* -Y181187D02* -Y184937D01* -X57125D01* -X57750Y184625D01* -X58063Y184313D01* -X58375Y183687D01* -Y182437D01* -X58063Y181813D01* -X57750Y181500D01* -X57125Y181187D01* -X55250D01* -X115250Y36687D02* -Y40437D01* -X117125D01* -X117750Y40125D01* -X118063Y39813D01* -X118375Y39187D01* -Y37937D01* -X118063Y37313D01* -X117750Y37000D01* -X117125Y36687D01* -X115250D01* -Y46687D02* -Y50437D01* -X117125D01* -X117750Y50125D01* -X118063Y49813D01* -X118375Y49187D01* -Y47937D01* -X118063Y47313D01* -X117750Y47000D01* -X117125Y46687D01* -X115250D01* -Y56687D02* -Y60437D01* -X117125D01* -X117750Y60125D01* -X118063Y59813D01* -X118375Y59187D01* -Y57937D01* -X118063Y57313D01* -X117750Y57000D01* -X117125Y56687D01* -X115250D01* -Y66687D02* -Y70437D01* -X117125D01* -X117750Y70125D01* -X118063Y69813D01* -X118375Y69187D01* -Y67937D01* -X118063Y67313D01* -X117750Y67000D01* -X117125Y66687D01* -X115250D01* -Y76687D02* -Y80437D01* -X117125D01* -X117750Y80125D01* -X118063Y79813D01* -X118375Y79187D01* -Y77937D01* -X118063Y77313D01* -X117750Y77000D01* -X117125Y76687D01* -X115250D01* -Y86687D02* -Y90437D01* -X117125D01* -X117750Y90125D01* -X118063Y89813D01* -X118375Y89187D01* -Y87937D01* -X118063Y87313D01* -X117750Y87000D01* -X117125Y86687D01* -X115250D01* -Y96687D02* -Y100437D01* -X117125D01* -X117750Y100125D01* -X118063Y99813D01* -X118375Y99187D01* -Y97937D01* -X118063Y97313D01* -X117750Y97000D01* -X117125Y96687D01* -X115250D01* -Y106687D02* -Y110437D01* -X117125D01* -X117750Y110125D01* -X118063Y109813D01* -X118375Y109187D01* -Y107937D01* -X118063Y107313D01* -X117750Y107000D01* -X117125Y106687D01* -X115250D01* -Y116687D02* -Y120437D01* -X117125D01* -X117750Y120125D01* -X118063Y119813D01* -X118375Y119187D01* -Y117937D01* -X118063Y117313D01* -X117750Y117000D01* -X117125Y116687D01* -X115250D01* -Y126687D02* -Y130437D01* -X117125D01* -X117750Y130125D01* -X118063Y129813D01* -X118375Y129187D01* -Y127937D01* -X118063Y127313D01* -X117750Y127000D01* -X117125Y126687D01* -X115250D01* -Y136687D02* -Y140437D01* -X117125D01* -X117750Y140125D01* -X118063Y139813D01* -X118375Y139187D01* -Y137937D01* -X118063Y137313D01* -X117750Y137000D01* -X117125Y136687D01* -X115250D01* -Y146687D02* -Y150437D01* -X117125D01* -X117750Y150125D01* -X118063Y149813D01* -X118375Y149187D01* -Y147937D01* -X118063Y147313D01* -X117750Y147000D01* -X117125Y146687D01* -X115250D01* -Y156687D02* -Y160437D01* -X117125D01* -X117750Y160125D01* -X118063Y159813D01* -X118375Y159187D01* -Y157937D01* -X118063Y157313D01* -X117750Y157000D01* -X117125Y156687D01* -X115250D01* -Y166687D02* -Y170437D01* -X117125D01* -X117750Y170125D01* -X118063Y169813D01* -X118375Y169187D01* -Y167937D01* -X118063Y167313D01* -X117750Y167000D01* -X117125Y166687D01* -X115250D01* -Y176187D02* -Y179937D01* -X117125D01* -X117750Y179625D01* -X118063Y179313D01* -X118375Y178687D01* -Y177437D01* -X118063Y176813D01* -X117750Y176500D01* -X117125Y176187D01* -X115250D01* -Y186687D02* -Y190437D01* -X117125D01* -X117750Y190125D01* -X118063Y189813D01* -X118375Y189187D01* -Y187937D01* -X118063Y187313D01* -X117750Y187000D01* -X117125Y186687D01* -X115250D01* -Y196687D02* -Y200437D01* -X117125D01* -X117750Y200125D01* -X118063Y199813D01* -X118375Y199187D01* -Y197937D01* -X118063Y197313D01* -X117750Y197000D01* -X117125Y196687D01* -X115250D01* -Y206687D02* -Y210437D01* -X117125D01* -X117750Y210125D01* -X118063Y209813D01* -X118375Y209187D01* -Y207937D01* -X118063Y207313D01* -X117750Y207000D01* -X117125Y206687D01* -X115250D01* -Y216687D02* -Y220437D01* -X117125D01* -X117750Y220125D01* -X118063Y219813D01* -X118375Y219187D01* -Y217937D01* -X118063Y217313D01* -X117750Y217000D01* -X117125Y216687D01* -X115250D01* -Y226687D02* -Y230437D01* -X117125D01* -X117750Y230125D01* -X118063Y229813D01* -X118375Y229187D01* -Y227937D01* -X118063Y227313D01* -X117750Y227000D01* -X117125Y226687D01* -X115250D01* -X145250Y36187D02* -Y39937D01* -X147125D01* -X147750Y39625D01* -X148063Y39313D01* -X148375Y38687D01* -Y37437D01* -X148063Y36813D01* -X147750Y36500D01* -X147125Y36187D01* -X145250D01* -Y46187D02* -Y49937D01* -X147125D01* -X147750Y49625D01* -X148063Y49313D01* -X148375Y48687D01* -Y47437D01* -X148063Y46813D01* -X147750Y46500D01* -X147125Y46187D01* -X145250D01* -Y56187D02* -Y59937D01* -X147125D01* -X147750Y59625D01* -X148063Y59313D01* -X148375Y58687D01* -Y57437D01* -X148063Y56813D01* -X147750Y56500D01* -X147125Y56187D01* -X145250D01* -Y66187D02* -Y69937D01* -X147125D01* -X147750Y69625D01* -X148063Y69313D01* -X148375Y68687D01* -Y67437D01* -X148063Y66813D01* -X147750Y66500D01* -X147125Y66187D01* -X145250D01* -Y76187D02* -Y79937D01* -X147125D01* -X147750Y79625D01* -X148063Y79313D01* -X148375Y78687D01* -Y77437D01* -X148063Y76813D01* -X147750Y76500D01* -X147125Y76187D01* -X145250D01* -Y86187D02* -Y89937D01* -X147125D01* -X147750Y89625D01* -X148063Y89313D01* -X148375Y88687D01* -Y87437D01* -X148063Y86813D01* -X147750Y86500D01* -X147125Y86187D01* -X145250D01* -Y96187D02* -Y99937D01* -X147125D01* -X147750Y99625D01* -X148063Y99313D01* -X148375Y98687D01* -Y97437D01* -X148063Y96813D01* -X147750Y96500D01* -X147125Y96187D01* -X145250D01* -Y106187D02* -Y109937D01* -X147125D01* -X147750Y109625D01* -X148063Y109313D01* -X148375Y108687D01* -Y107437D01* -X148063Y106813D01* -X147750Y106500D01* -X147125Y106187D01* -X145250D01* -Y116187D02* -Y119937D01* -X147125D01* -X147750Y119625D01* -X148063Y119313D01* -X148375Y118687D01* -Y117437D01* -X148063Y116813D01* -X147750Y116500D01* -X147125Y116187D01* -X145250D01* -Y126187D02* -Y129937D01* -X147125D01* -X147750Y129625D01* -X148063Y129313D01* -X148375Y128687D01* -Y127437D01* -X148063Y126813D01* -X147750Y126500D01* -X147125Y126187D01* -X145250D01* -Y136187D02* -Y139937D01* -X147125D01* -X147750Y139625D01* -X148063Y139313D01* -X148375Y138687D01* -Y137437D01* -X148063Y136813D01* -X147750Y136500D01* -X147125Y136187D01* -X145250D01* -Y146187D02* -Y149937D01* -X147125D01* -X147750Y149625D01* -X148063Y149313D01* -X148375Y148687D01* -Y147437D01* -X148063Y146813D01* -X147750Y146500D01* -X147125Y146187D01* -X145250D01* -Y156187D02* -Y159937D01* -X147125D01* -X147750Y159625D01* -X148063Y159313D01* -X148375Y158687D01* -Y157437D01* -X148063Y156813D01* -X147750Y156500D01* -X147125Y156187D01* -X145250D01* -Y166187D02* -Y169937D01* -X147125D01* -X147750Y169625D01* -X148063Y169313D01* -X148375Y168687D01* -Y167437D01* -X148063Y166813D01* -X147750Y166500D01* -X147125Y166187D01* -X145250D01* -Y176187D02* -Y179937D01* -X147125D01* -X147750Y179625D01* -X148063Y179313D01* -X148375Y178687D01* -Y177437D01* -X148063Y176813D01* -X147750Y176500D01* -X147125Y176187D01* -X145250D01* -Y186187D02* -Y189937D01* -X147125D01* -X147750Y189625D01* -X148063Y189313D01* -X148375Y188687D01* -Y187437D01* -X148063Y186813D01* -X147750Y186500D01* -X147125Y186187D01* -X145250D01* -Y196187D02* -Y199937D01* -X147125D01* -X147750Y199625D01* -X148063Y199313D01* -X148375Y198687D01* -Y197437D01* -X148063Y196813D01* -X147750Y196500D01* -X147125Y196187D01* -X145250D01* -Y206187D02* -Y209937D01* -X147125D01* -X147750Y209625D01* -X148063Y209313D01* -X148375Y208687D01* -Y207437D01* -X148063Y206813D01* -X147750Y206500D01* -X147125Y206187D01* -X145250D01* -Y216187D02* -Y219937D01* -X147125D01* -X147750Y219625D01* -X148063Y219313D01* -X148375Y218687D01* -Y217437D01* -X148063Y216813D01* -X147750Y216500D01* -X147125Y216187D01* -X145250D01* -Y226187D02* -Y229937D01* -X147125D01* -X147750Y229625D01* -X148063Y229313D01* -X148375Y228687D01* -Y227437D01* -X148063Y226813D01* -X147750Y226500D01* -X147125Y226187D01* -X145250D01* -X215250Y36187D02* -Y39937D01* -X217125D01* -X217750Y39625D01* -X218063Y39313D01* -X218375Y38687D01* -Y37437D01* -X218063Y36813D01* -X217750Y36500D01* -X217125Y36187D01* -X215250D01* -Y46187D02* -Y49937D01* -X217125D01* -X217750Y49625D01* -X218063Y49313D01* -X218375Y48687D01* -Y47437D01* -X218063Y46813D01* -X217750Y46500D01* -X217125Y46187D01* -X215250D01* -Y56187D02* -Y59937D01* -X217125D01* -X217750Y59625D01* -X218063Y59313D01* -X218375Y58687D01* -Y57437D01* -X218063Y56813D01* -X217750Y56500D01* -X217125Y56187D01* -X215250D01* -Y66187D02* -Y69937D01* -X217125D01* -X217750Y69625D01* -X218063Y69313D01* -X218375Y68687D01* -Y67437D01* -X218063Y66813D01* -X217750Y66500D01* -X217125Y66187D01* -X215250D01* -Y76187D02* -Y79937D01* -X217125D01* -X217750Y79625D01* -X218063Y79313D01* -X218375Y78687D01* -Y77437D01* -X218063Y76813D01* -X217750Y76500D01* -X217125Y76187D01* -X215250D01* -Y86187D02* -Y89937D01* -X217125D01* -X217750Y89625D01* -X218063Y89313D01* -X218375Y88687D01* -Y87437D01* -X218063Y86813D01* -X217750Y86500D01* -X217125Y86187D01* -X215250D01* -Y96187D02* -Y99937D01* -X217125D01* -X217750Y99625D01* -X218063Y99313D01* -X218375Y98687D01* -Y97437D01* -X218063Y96813D01* -X217750Y96500D01* -X217125Y96187D01* -X215250D01* -Y106187D02* -Y109937D01* -X217125D01* -X217750Y109625D01* -X218063Y109313D01* -X218375Y108687D01* -Y107437D01* -X218063Y106813D01* -X217750Y106500D01* -X217125Y106187D01* -X215250D01* -Y116187D02* -Y119937D01* -X217125D01* -X217750Y119625D01* -X218063Y119313D01* -X218375Y118687D01* -Y117437D01* -X218063Y116813D01* -X217750Y116500D01* -X217125Y116187D01* -X215250D01* -Y126187D02* -Y129937D01* -X217125D01* -X217750Y129625D01* -X218063Y129313D01* -X218375Y128687D01* -Y127437D01* -X218063Y126813D01* -X217750Y126500D01* -X217125Y126187D01* -X215250D01* -Y136187D02* -Y139937D01* -X217125D01* -X217750Y139625D01* -X218063Y139313D01* -X218375Y138687D01* -Y137437D01* -X218063Y136813D01* -X217750Y136500D01* -X217125Y136187D01* -X215250D01* -Y146187D02* -Y149937D01* -X217125D01* -X217750Y149625D01* -X218063Y149313D01* -X218375Y148687D01* -Y147437D01* -X218063Y146813D01* -X217750Y146500D01* -X217125Y146187D01* -X215250D01* -Y156187D02* -Y159937D01* -X217125D01* -X217750Y159625D01* -X218063Y159313D01* -X218375Y158687D01* -Y157437D01* -X218063Y156813D01* -X217750Y156500D01* -X217125Y156187D01* -X215250D01* -Y166187D02* -Y169937D01* -X217125D01* -X217750Y169625D01* -X218063Y169313D01* -X218375Y168687D01* -Y167437D01* -X218063Y166813D01* -X217750Y166500D01* -X217125Y166187D01* -X215250D01* -Y176187D02* -Y179937D01* -X217125D01* -X217750Y179625D01* -X218063Y179313D01* -X218375Y178687D01* -Y177437D01* -X218063Y176813D01* -X217750Y176500D01* -X217125Y176187D01* -X215250D01* -Y186187D02* -Y189937D01* -X217125D01* -X217750Y189625D01* -X218063Y189313D01* -X218375Y188687D01* -Y187437D01* -X218063Y186813D01* -X217750Y186500D01* -X217125Y186187D01* -X215250D01* -Y196187D02* -Y199937D01* -X217125D01* -X217750Y199625D01* -X218063Y199313D01* -X218375Y198687D01* -Y197437D01* -X218063Y196813D01* -X217750Y196500D01* -X217125Y196187D01* -X215250D01* -Y206187D02* -Y209937D01* -X217125D01* -X217750Y209625D01* -X218063Y209313D01* -X218375Y208687D01* -Y207437D01* -X218063Y206813D01* -X217750Y206500D01* -X217125Y206187D01* -X215250D01* -Y216187D02* -Y219937D01* -X217125D01* -X217750Y219625D01* -X218063Y219313D01* -X218375Y218687D01* -Y217437D01* -X218063Y216813D01* -X217750Y216500D01* -X217125Y216187D01* -X215250D01* -Y226187D02* -Y229937D01* -X217125D01* -X217750Y229625D01* -X218063Y229313D01* -X218375Y228687D01* -Y227437D01* -X218063Y226813D01* -X217750Y226500D01* -X217125Y226187D01* -X215250D01* -X245250Y36687D02* -Y40437D01* -X247125D01* -X247750Y40125D01* -X248063Y39813D01* -X248375Y39187D01* -Y37937D01* -X248063Y37313D01* -X247750Y37000D01* -X247125Y36687D01* -X245250D01* -Y46687D02* -Y50437D01* -X247125D01* -X247750Y50125D01* -X248063Y49813D01* -X248375Y49187D01* -Y47937D01* -X248063Y47313D01* -X247750Y47000D01* -X247125Y46687D01* -X245250D01* -Y56687D02* -Y60437D01* -X247125D01* -X247750Y60125D01* -X248063Y59813D01* -X248375Y59187D01* -Y57937D01* -X248063Y57313D01* -X247750Y57000D01* -X247125Y56687D01* -X245250D01* -Y66687D02* -Y70437D01* -X247125D01* -X247750Y70125D01* -X248063Y69813D01* -X248375Y69187D01* -Y67937D01* -X248063Y67313D01* -X247750Y67000D01* -X247125Y66687D01* -X245250D01* -Y76687D02* -Y80437D01* -X247125D01* -X247750Y80125D01* -X248063Y79813D01* -X248375Y79187D01* -Y77937D01* -X248063Y77313D01* -X247750Y77000D01* -X247125Y76687D01* -X245250D01* -Y86687D02* -Y90437D01* -X247125D01* -X247750Y90125D01* -X248063Y89813D01* -X248375Y89187D01* -Y87937D01* -X248063Y87313D01* -X247750Y87000D01* -X247125Y86687D01* -X245250D01* -Y96687D02* -Y100437D01* -X247125D01* -X247750Y100125D01* -X248063Y99813D01* -X248375Y99187D01* -Y97937D01* -X248063Y97313D01* -X247750Y97000D01* -X247125Y96687D01* -X245250D01* -Y106687D02* -Y110437D01* -X247125D01* -X247750Y110125D01* -X248063Y109813D01* -X248375Y109187D01* -Y107937D01* -X248063Y107313D01* -X247750Y107000D01* -X247125Y106687D01* -X245250D01* -Y116687D02* -Y120437D01* -X247125D01* -X247750Y120125D01* -X248063Y119813D01* -X248375Y119187D01* -Y117937D01* -X248063Y117313D01* -X247750Y117000D01* -X247125Y116687D01* -X245250D01* -Y126687D02* -Y130437D01* -X247125D01* -X247750Y130125D01* -X248063Y129813D01* -X248375Y129187D01* -Y127937D01* -X248063Y127313D01* -X247750Y127000D01* -X247125Y126687D01* -X245250D01* -Y136687D02* -Y140437D01* -X247125D01* -X247750Y140125D01* -X248063Y139813D01* -X248375Y139187D01* -Y137937D01* -X248063Y137313D01* -X247750Y137000D01* -X247125Y136687D01* -X245250D01* -Y146687D02* -Y150437D01* -X247125D01* -X247750Y150125D01* -X248063Y149813D01* -X248375Y149187D01* -Y147937D01* -X248063Y147313D01* -X247750Y147000D01* -X247125Y146687D01* -X245250D01* -Y156687D02* -Y160437D01* -X247125D01* -X247750Y160125D01* -X248063Y159813D01* -X248375Y159187D01* -Y157937D01* -X248063Y157313D01* -X247750Y157000D01* -X247125Y156687D01* -X245250D01* -Y166687D02* -Y170437D01* -X247125D01* -X247750Y170125D01* -X248063Y169813D01* -X248375Y169187D01* -Y167937D01* -X248063Y167313D01* -X247750Y167000D01* -X247125Y166687D01* -X245250D01* -Y176687D02* -Y180437D01* -X247125D01* -X247750Y180125D01* -X248063Y179813D01* -X248375Y179187D01* -Y177937D01* -X248063Y177313D01* -X247750Y177000D01* -X247125Y176687D01* -X245250D01* -Y186687D02* -Y190437D01* -X247125D01* -X247750Y190125D01* -X248063Y189813D01* -X248375Y189187D01* -Y187937D01* -X248063Y187313D01* -X247750Y187000D01* -X247125Y186687D01* -X245250D01* -Y196687D02* -Y200437D01* -X247125D01* -X247750Y200125D01* -X248063Y199813D01* -X248375Y199187D01* -Y197937D01* -X248063Y197313D01* -X247750Y197000D01* -X247125Y196687D01* -X245250D01* -Y206687D02* -Y210437D01* -X247125D01* -X247750Y210125D01* -X248063Y209813D01* -X248375Y209187D01* -Y207937D01* -X248063Y207313D01* -X247750Y207000D01* -X247125Y206687D01* -X245250D01* -Y216687D02* -Y220437D01* -X247125D01* -X247750Y220125D01* -X248063Y219813D01* -X248375Y219187D01* -Y217937D01* -X248063Y217313D01* -X247750Y217000D01* -X247125Y216687D01* -X245250D01* -Y226687D02* -Y230437D01* -X247125D01* -X247750Y230125D01* -X248063Y229813D01* -X248375Y229187D01* -Y227937D01* -X248063Y227313D01* -X247750Y227000D01* -X247125Y226687D01* -X245250D01* -X315250Y226187D02* -Y229937D01* -X317125D01* -X317750Y229625D01* -X318063Y229313D01* -X318375Y228687D01* -Y227437D01* -X318063Y226813D01* -X317750Y226500D01* -X317125Y226187D01* -X315250D01* -X325250D02* -Y229937D01* -X327125D01* -X327750Y229625D01* -X328063Y229313D01* -X328375Y228687D01* -Y227437D01* -X328063Y226813D01* -X327750Y226500D01* -X327125Y226187D01* -X325250D01* -X335250D02* -Y229937D01* -X337125D01* -X337750Y229625D01* -X338063Y229313D01* -X338375Y228687D01* -Y227437D01* -X338063Y226813D01* -X337750Y226500D01* -X337125Y226187D01* -X335250D01* -X345250D02* -Y229937D01* -X347125D01* -X347750Y229625D01* -X348063Y229313D01* -X348375Y228687D01* -Y227437D01* -X348063Y226813D01* -X347750Y226500D01* -X347125Y226187D01* -X345250D01* -D02* -D21* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Gerber Drill Data - [Through Hole].gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Gerber Drill Data - [Through Hole].gbr deleted file mode 100644 index d9130e64c..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Gerber Drill Data - [Through Hole].gbr +++ /dev/null @@ -1,101 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD73C,0.03500*% -X0Y0D02* -D02* -D73* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - NC Drill Data - [Through Hole].drl b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - NC Drill Data - [Through Hole].drl deleted file mode 100644 index 2c7c7f266..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - NC Drill Data - [Through Hole].drl +++ /dev/null @@ -1,105 +0,0 @@ -G05 -M48 -;#@! TF.GenerationSoftware,DesignSpark,DesignSpark PCB,11.0.5875 -;#@! TF.CreationDate,2023-11-17T04:14:13+06:00* -;#@! TF.FileFunction,Plated,1,2,PTH -;FILE_FORMAT=2:4 -;TYPE=PLATED -INCH,TZ -FMAT,2 -T1C00.0350 -% -T001 -X4525Y10525 -X4525Y11525 -X4525Y12525 -X4525Y13525 -X4525Y14525 -X4525Y15525 -X4525Y16525 -X4525Y17525 -X10525Y3075 -X10525Y4075 -X10525Y5075 -X10525Y6075 -X10525Y7075 -X10525Y8075 -X10525Y9075 -X10525Y10075 -X10525Y11075 -X10525Y12075 -X10525Y13075 -X10525Y14075 -X10525Y15075 -X10525Y16075 -X10525Y17025 -X10525Y18075 -X10525Y19075 -X10525Y20075 -X10525Y21075 -X10525Y22075 -X13525Y3025 -X13525Y4025 -X13525Y5025 -X13525Y6025 -X13525Y7025 -X13525Y8025 -X13525Y9025 -X13525Y10025 -X13525Y11025 -X13525Y12025 -X13525Y13025 -X13525Y14025 -X13525Y15025 -X13525Y16025 -X13525Y17025 -X13525Y18025 -X13525Y19025 -X13525Y20025 -X13525Y21025 -X13525Y22025 -X20525Y3025 -X20525Y4025 -X20525Y5025 -X20525Y6025 -X20525Y7025 -X20525Y8025 -X20525Y9025 -X20525Y10025 -X20525Y11025 -X20525Y12025 -X20525Y13025 -X20525Y14025 -X20525Y15025 -X20525Y16025 -X20525Y17025 -X20525Y18025 -X20525Y19025 -X20525Y20025 -X20525Y21025 -X20525Y22025 -X23525Y3075 -X23525Y4075 -X23525Y5075 -X23525Y6075 -X23525Y7075 -X23525Y8075 -X23525Y9075 -X23525Y10075 -X23525Y11075 -X23525Y12075 -X23525Y13075 -X23525Y14075 -X23525Y15075 -X23525Y16075 -X23525Y17075 -X23525Y18075 -X23525Y19075 -X23525Y20075 -X23525Y21075 -X23525Y22075 -X30525Y22025 -X31525Y22025 -X32525Y22025 -X33525Y22025 -M30 diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Assembly.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Assembly.gbr deleted file mode 100644 index 4fe6a7f84..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Assembly.gbr +++ /dev/null @@ -1,112 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD24R,0.05500X0.07500*% -%ADD10C,0.00500*% -%ADD23R,0.07500X0.05500*% -X0Y0D02* -D02* -D10* -X212250Y227250D02* -Y23250D01* -X128250D01* -Y227250D01* -X212250D01* -D02* -D23* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -D02* -D24* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper (Resist).gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper (Resist).gbr deleted file mode 100644 index fe58ce9ec..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper (Resist).gbr +++ /dev/null @@ -1,104 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD26R,0.06500X0.08500*% -%ADD25R,0.08500X0.06500*% -X0Y0D02* -D02* -D25* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -D02* -D26* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper.gbr deleted file mode 100644 index 72da429b3..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Copper.gbr +++ /dev/null @@ -1,255 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD24R,0.05500X0.07500*% -%ADD13C,0.01500*% -%ADD23R,0.07500X0.05500*% -X0Y0D02* -D02* -D13* -X45250Y105250D02* -X49750D01* -X45250Y125250D02* -X65250D01* -X70250Y130250D01* -X104750D01* -X105250Y130750D01* -X45250Y175250D02* -X145250D01* -X190250Y220250D01* -X205250D01* -X135250Y30250D02* -X105250D01* -Y30750D01* -X135250Y40250D02* -X105250D01* -Y40750D01* -X135250Y50250D02* -X105250D01* -Y50750D01* -X135250Y60250D02* -X105250D01* -Y60750D01* -X135250Y70250D02* -X105250D01* -Y70750D01* -X135250Y80250D02* -X105250D01* -Y80750D01* -X135250Y90250D02* -X105250D01* -Y90750D01* -X135250Y100250D02* -X105250D01* -Y100750D01* -X135250Y110250D02* -X105250D01* -Y110750D01* -X135250Y120250D02* -X105250D01* -Y120750D01* -X135250Y130250D02* -X105250D01* -Y130750D01* -X135250Y150250D02* -X105250D01* -Y150750D01* -X135250Y160250D02* -X145250D01* -Y105250D01* -X45250D01* -X135250Y160250D02* -X105250D01* -Y160750D01* -X135250Y180250D02* -X105250D01* -Y180750D01* -X135250Y190250D02* -X105250D01* -Y190750D01* -X135250Y200250D02* -X105250D01* -Y200750D01* -X135250Y210250D02* -X105250D01* -Y210750D01* -X135250Y220250D02* -X105250D01* -Y220750D01* -X205250Y30250D02* -X235250D01* -Y30750D01* -X205250Y70250D02* -X235250D01* -Y70750D01* -X205250Y110250D02* -X190250D01* -Y165250D01* -X45250D01* -X235250Y30750D02* -X330750D01* -X335250Y35250D01* -Y220250D01* -X235250Y40750D02* -X325250D01* -Y220250D01* -X235250Y40750D02* -Y40250D01* -X205250D01* -X235250Y50750D02* -X305250D01* -Y220250D01* -X235250Y50750D02* -Y50250D01* -X205250D01* -X235250Y60750D02* -Y60250D01* -X205250D01* -X235250Y80750D02* -Y80250D01* -X205250D01* -X235250Y90750D02* -Y90250D01* -X205250D01* -X235250Y100750D02* -Y100250D01* -X205250D01* -X235250Y110750D02* -X205750D01* -X205250Y110250D01* -X235250Y120750D02* -Y120250D01* -X205250D01* -X235250Y130750D02* -Y130250D01* -X205250D01* -X235250Y140750D02* -Y140250D01* -X205250D01* -X235250Y150750D02* -Y150250D01* -X205250D01* -X235250Y160750D02* -Y160250D01* -X205250D01* -X235250Y170750D02* -Y170250D01* -X205250D01* -X235250Y180750D02* -Y180250D01* -X205250D01* -X235250Y190750D02* -Y190250D01* -X205250D01* -X235250Y200750D02* -Y200250D01* -X205250D01* -X235250Y210750D02* -X280250D01* -Y230250D01* -X315250D01* -Y220250D01* -X235250Y210750D02* -Y210250D01* -X205250D01* -X235250Y220750D02* -Y220250D01* -X205250D01* -D02* -D23* -X45250Y105250D03* -Y115250D03* -Y125250D03* -Y135250D03* -Y145250D03* -Y155250D03* -Y165250D03* -Y175250D03* -X105250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170250D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -X135250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X205250Y30250D03* -Y40250D03* -Y50250D03* -Y60250D03* -Y70250D03* -Y80250D03* -Y90250D03* -Y100250D03* -Y110250D03* -Y120250D03* -Y130250D03* -Y140250D03* -Y150250D03* -Y160250D03* -Y170250D03* -Y180250D03* -Y190250D03* -Y200250D03* -Y210250D03* -Y220250D03* -X235250Y30750D03* -Y40750D03* -Y50750D03* -Y60750D03* -Y70750D03* -Y80750D03* -Y90750D03* -Y100750D03* -Y110750D03* -Y120750D03* -Y130750D03* -Y140750D03* -Y150750D03* -Y160750D03* -Y170750D03* -Y180750D03* -Y190750D03* -Y200750D03* -Y210750D03* -Y220750D03* -D02* -D24* -X305250Y220250D03* -X315250D03* -X325250D03* -X335250D03* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Silkscreen.gbr b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Silkscreen.gbr deleted file mode 100644 index 20fc476b3..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5 - Top Silkscreen.gbr +++ /dev/null @@ -1,14950 +0,0 @@ -G04 DesignSpark PCB Gerber Version 11.0 Build 5877* -%FSLAX35Y35*% -%MOIN*% -%ADD11C,0.00100*% -%ADD10C,0.00500*% -X0Y0D02* -D02* -D10* -X55250Y185250D02* -X35250D01* -Y95250D01* -X55250D01* -Y185250D01* -X61187Y160250D02* -X64937D01* -Y158063D01* -X64625Y157437D01* -X64000Y157125D01* -X63375Y157437D01* -X63063Y158063D01* -Y160250D01* -Y158063D02* -X61187Y157125D01* -Y155250D02* -X64937D01* -Y152125D01* -X63063Y152750D02* -Y155250D01* -X61187Y149313D02* -Y148063D01* -Y148687D02* -X64937D01* -Y149313D02* -Y148063D01* -X61187Y145250D02* -X64937D01* -Y143375D01* -X64625Y142750D01* -X64313Y142437D01* -X63687Y142125D01* -X62437D01* -X61813Y142437D01* -X61500Y142750D01* -X61187Y143375D01* -Y145250D01* -X62437Y140250D02* -Y137750D01* -X61187Y135250D02* -X64937D01* -Y133063D01* -X64625Y132437D01* -X64000Y132125D01* -X63375Y132437D01* -X63063Y133063D01* -Y135250D01* -Y133063D02* -X61187Y132125D01* -X61813Y127125D02* -X61500Y127437D01* -X61187Y128063D01* -Y129000D01* -X61500Y129625D01* -X61813Y129937D01* -X62437Y130250D01* -X63687D01* -X64313Y129937D01* -X64625Y129625D01* -X64937Y129000D01* -Y128063D01* -X64625Y127437D01* -X64313Y127125D01* -X61500Y125250D02* -X61187Y124625D01* -Y123687D01* -X61500Y123063D01* -X62125Y122750D01* -X62437D01* -X63063Y123063D01* -X63375Y123687D01* -Y125250D01* -X64937D01* -Y122750D01* -X61187Y117750D02* -Y120250D01* -X63375Y118063D01* -X64000Y117750D01* -X64625Y118063D01* -X64937Y118687D01* -Y119625D01* -X64625Y120250D01* -X61187Y112750D02* -Y115250D01* -X63375Y113063D01* -X64000Y112750D01* -X64625Y113063D01* -X64937Y113687D01* -Y114625D01* -X64625Y115250D01* -X167125Y215250D02* -X174625D01* -Y210875D01* -X174000Y209625D01* -X172750Y209000D01* -X171500Y209625D01* -X170875Y210875D01* -Y215250D01* -Y210875D02* -X167125Y209000D01* -X171500Y205250D02* -X172125Y204000D01* -Y202125D01* -X171500Y200875D01* -X170250Y200250D01* -X168375D01* -X167750Y200875D01* -X167125Y202125D01* -Y203375D01* -X167750Y204625D01* -X168375Y205250D01* -X169000D01* -X169625Y204625D01* -X170250Y203375D01* -Y202125D01* -X169625Y200875D01* -X169000Y200250D01* -X168375D02* -X167125D01* -X167750Y195250D02* -X167125Y194000D01* -Y191500D01* -X167750Y190250D01* -X169000D01* -X169625Y191500D01* -Y194000D01* -X170250Y195250D01* -X171500D01* -X172125Y194000D01* -Y191500D01* -X171500Y190250D01* -X172125Y185250D02* -X165250D01* -X169000D02* -X167750Y184625D01* -X167125Y183375D01* -Y182125D01* -X167750Y180875D01* -X169000Y180250D01* -X170250D01* -X171500Y180875D01* -X172125Y182125D01* -Y183375D01* -X171500Y184625D01* -X170250Y185250D01* -X169000D01* -Y175250D02* -X167750Y174625D01* -X167125Y173375D01* -Y172125D01* -X167750Y170875D01* -X169000Y170250D01* -X170250D01* -X171500Y170875D01* -X172125Y172125D01* -Y173375D01* -X171500Y174625D01* -X170250Y175250D01* -X167125D02* -X174625D01* -X167750Y160250D02* -X167125Y160875D01* -Y162125D01* -Y163375D01* -X167750Y164625D01* -X169000Y165250D01* -X170875D01* -X171500Y164625D01* -X172125Y163375D01* -Y162125D01* -X171500Y160875D01* -X170875Y160250D01* -X170250D01* -X169625Y160875D01* -X169000Y162125D01* -Y163375D01* -X169625Y164625D01* -X170250Y165250D01* -X167125Y155250D02* -X172125D01* -X170250D02* -X171500Y154625D01* -X172125Y153375D01* -Y152125D01* -X171500Y150875D01* -X167125Y145250D02* -X172125D01* -X170250D02* -X171500Y144625D01* -X172125Y143375D01* -Y142125D01* -X171500Y140875D01* -X172125Y135250D02* -X169625Y134625D01* -X168375Y133375D01* -Y132125D01* -X169625Y130875D01* -X172125Y130250D01* -X169625Y130875D02* -X167125Y131500D01* -X165875Y132125D01* -X165250Y133375D01* -X165875Y134625D01* -X167125Y115250D02* -X174625D01* -Y110875D01* -X174000Y109625D01* -X172750Y109000D01* -X171500Y109625D01* -X170875Y110875D01* -Y115250D01* -X167125Y103375D02* -Y100875D01* -Y102125D02* -X174625D01* -Y103375D02* -Y100875D01* -X167125Y85250D02* -X174625D01* -Y80875D01* -X174000Y79625D01* -X172750Y79000D01* -X171500Y79625D01* -X170875Y80875D01* -Y85250D01* -X167125Y73375D02* -Y70875D01* -Y72125D02* -X174625D01* -Y73375D02* -Y70875D01* -X168375Y59000D02* -X167750Y59625D01* -X167125Y60875D01* -Y62750D01* -X167750Y64000D01* -X168375Y64625D01* -X169625Y65250D01* -X172125D01* -X173375Y64625D01* -X174000Y64000D01* -X174625Y62750D01* -Y60875D01* -X174000Y59625D01* -X173375Y59000D01* -X169625Y55250D02* -X172125D01* -X173375Y54625D01* -X174000Y54000D01* -X174625Y52750D01* -Y51500D01* -X174000Y50250D01* -X173375Y49625D01* -X172125Y49000D01* -X169625D01* -X168375Y49625D01* -X167750Y50250D01* -X167125Y51500D01* -Y52750D01* -X167750Y54000D01* -X168375Y54625D01* -X169625Y55250D01* -X82750Y6656D02* -Y12281D01* -X87437D01* -X86500Y9469D02* -X82750D01* -X90250Y6656D02* -X92594Y12281D01* -X94937Y6656D01* -X91187Y9000D02* -X94000D01* -X97750Y6656D02* -Y12281D01* -X101031D01* -X101969Y11813D01* -X102437Y10875D01* -X101969Y9937D01* -X101031Y9469D01* -X97750D01* -X101031D02* -X102437Y6656D01* -X105250D02* -Y12281D01* -X107594Y9469D01* -X109937Y12281D01* -Y6656D01* -X120250D02* -X122594Y12281D01* -X124937Y6656D01* -X121187Y9000D02* -X124000D01* -X127750Y6656D02* -Y12281D01* -X132437Y6656D01* -Y12281D01* -X136656Y6656D02* -X138531D01* -X137594D02* -Y12281D01* -X136656D02* -X138531D01* -X142750Y6656D02* -Y12281D01* -X145094Y9469D01* -X147437Y12281D01* -Y6656D01* -X150250D02* -X152594Y12281D01* -X154937Y6656D01* -X151187Y9000D02* -X154000D01* -X157750Y12281D02* -Y6656D01* -X162437D01* -X172750D02* -Y12281D01* -X175094Y9469D01* -X177437Y12281D01* -Y6656D01* -X180250D02* -X182594Y12281D01* -X184937Y6656D01* -X181187Y9000D02* -X184000D01* -X187750Y6656D02* -Y12281D01* -X192437Y6656D01* -Y12281D01* -X195250Y6656D02* -X197594Y12281D01* -X199937Y6656D01* -X196187Y9000D02* -X199000D01* -X206031D02* -X207437D01* -Y8531D01* -X206969Y7594D01* -X206500Y7125D01* -X205563Y6656D01* -X204625D01* -X203687Y7125D01* -X203219Y7594D01* -X202750Y8531D01* -Y10406D01* -X203219Y11344D01* -X203687Y11813D01* -X204625Y12281D01* -X205563D01* -X206500Y11813D01* -X206969Y11344D01* -X207437Y10406D01* -X210250Y6656D02* -Y12281D01* -X214937D01* -X214000Y9469D02* -X210250D01* -Y6656D02* -X214937D01* -X217750D02* -Y12281D01* -X220094Y9469D01* -X222437Y12281D01* -Y6656D01* -X225250D02* -Y12281D01* -X229937D01* -X229000Y9469D02* -X225250D01* -Y6656D02* -X229937D01* -X232750D02* -Y12281D01* -X237437Y6656D01* -Y12281D01* -X242594Y6656D02* -Y12281D01* -X240250D02* -X244937D01* -X262750Y10406D02* -X264625Y6656D01* -X266500Y10406D01* -X270250Y7125D02* -X271187Y6656D01* -X272594D01* -X273531Y7125D01* -X274000Y8063D01* -Y8531D01* -X273531Y9469D01* -X272594Y9937D01* -X270250D01* -Y12281D01* -X274000D01* -X278219Y6656D02* -X278687Y7125D01* -X278219Y7594D01* -X277750Y7125D01* -X278219Y6656D01* -X285719Y7125D02* -X286656Y6656D01* -X287594D01* -X288531Y7125D01* -X289000Y8063D01* -Y10875D01* -X288531Y11813D01* -X287594Y12281D01* -X286656D01* -X285719Y11813D01* -X285250Y10875D01* -Y8063D01* -X285719Y7125D01* -X288531Y11813D01* -X293219Y6656D02* -X293687Y7125D01* -X293219Y7594D01* -X292750Y7125D01* -X293219Y6656D01* -X300719Y7125D02* -X301656Y6656D01* -X302594D01* -X303531Y7125D01* -X304000Y8063D01* -Y10875D01* -X303531Y11813D01* -X302594Y12281D01* -X301656D01* -X300719Y11813D01* -X300250Y10875D01* -Y8063D01* -X300719Y7125D01* -X303531Y11813D01* -X219750Y234750D02* -Y15750D01* -X120750D01* -Y234750D01* -X166250D01* -Y230750D01* -X174250D01* -Y234750D01* -X219750D01* -X290250Y175250D02* -X350250D01* -Y230250D01* -X290250D01* -Y175250D01* -X306500Y239156D02* -Y238687D01* -X306344D01* -X306031Y238844D01* -X305875Y239000D01* -X305719Y239313D01* -Y239625D01* -X305875Y239937D01* -X306031Y240094D01* -X306344Y240250D01* -X306969D01* -X307281Y240094D01* -X307437Y239937D01* -X307594Y239625D01* -Y239313D01* -X307437Y239000D01* -X307281Y238844D01* -X306969Y238687D01* -X305719Y237750D02* -X307594D01* -X305719Y236187D01* -X307594D01* -X305719Y235250D02* -X307594D01* -Y234313D01* -X307437Y234000D01* -X307281Y233844D01* -X306969Y233687D01* -X306344D01* -X306031Y233844D01* -X305875Y234000D01* -X305719Y234313D01* -Y235250D01* -X317594Y240250D02* -X315719Y239469D01* -X317594Y238687D01* -X316031Y236187D02* -X315875Y236344D01* -X315719Y236656D01* -Y237125D01* -X315875Y237437D01* -X316031Y237594D01* -X316344Y237750D01* -X316969D01* -X317281Y237594D01* -X317437Y237437D01* -X317594Y237125D01* -Y236656D01* -X317437Y236344D01* -X317281Y236187D01* -X316031Y233687D02* -X315875Y233844D01* -X315719Y234156D01* -Y234625D01* -X315875Y234937D01* -X316031Y235094D01* -X316344Y235250D01* -X316969D01* -X317281Y235094D01* -X317437Y234937D01* -X317594Y234625D01* -Y234156D01* -X317437Y233844D01* -X317281Y233687D01* -X310250Y192437D02* -Y193687D01* -X310563Y194313D01* -X310875Y194625D01* -X311500Y194937D01* -X312125D01* -X312750Y194625D01* -X313063Y194313D01* -X313375Y193687D01* -Y192437D01* -X313063Y191813D01* -X312750Y191500D01* -X312125Y191187D01* -X311500D01* -X310875Y191500D01* -X310563Y191813D01* -X310250Y192437D01* -X315250Y194937D02* -Y191187D01* -X318375D01* -X320250D02* -Y194937D01* -X323375D01* -X322750Y193063D02* -X320250D01* -Y191187D02* -X323375D01* -X325250D02* -Y194937D01* -X327125D01* -X327750Y194625D01* -X328063Y194313D01* -X328375Y193687D01* -Y192437D01* -X328063Y191813D01* -X327750Y191500D01* -X327125Y191187D01* -X325250D01* -X302750Y202125D02* -X303063Y201500D01* -X303687Y201187D01* -X304937D01* -X305563Y201500D01* -X305875Y202125D01* -X305563Y202750D01* -X304937Y203063D01* -X303687D01* -X303063Y203375D01* -X302750Y204000D01* -X303063Y204625D01* -X303687Y204937D01* -X304937D01* -X305563Y204625D01* -X305875Y204000D01* -X307750Y202125D02* -X308063Y201500D01* -X308687Y201187D01* -X309937D01* -X310563Y201500D01* -X310875Y202125D01* -X310563Y202750D01* -X309937Y203063D01* -X308687D01* -X308063Y203375D01* -X307750Y204000D01* -X308063Y204625D01* -X308687Y204937D01* -X309937D01* -X310563Y204625D01* -X310875Y204000D01* -X312750Y201187D02* -Y204937D01* -X314625D01* -X315250Y204625D01* -X315563Y204313D01* -X315875Y203687D01* -Y202437D01* -X315563Y201813D01* -X315250Y201500D01* -X314625Y201187D01* -X312750D01* -X318375D02* -X319625D01* -X319000D02* -Y204937D01* -X318375Y204313D01* -X323063Y201500D02* -X323687Y201187D01* -X324313D01* -X324937Y201500D01* -X325250Y202125D01* -X324937Y202750D01* -X324313Y203063D01* -X323687D01* -X324313D02* -X324937Y203375D01* -X325250Y204000D01* -X324937Y204625D01* -X324313Y204937D01* -X323687D01* -X323063Y204625D01* -X328063Y201500D02* -X328687Y201187D01* -X329313D01* -X329937Y201500D01* -X330250Y202125D01* -Y204000D01* -X329937Y204625D01* -X329313Y204937D01* -X328687D01* -X328063Y204625D01* -X327750Y204000D01* -Y202125D01* -X328063Y201500D01* -X329937Y204625D01* -X332750Y202125D02* -X333063Y202750D01* -X333687Y203063D01* -X334313D01* -X334937Y202750D01* -X335250Y202125D01* -X334937Y201500D01* -X334313Y201187D01* -X333687D01* -X333063Y201500D01* -X332750Y202125D01* -Y203063D01* -X333063Y204000D01* -X333687Y204625D01* -X334313Y204937D01* -X326187Y240250D02* -X325875Y240094D01* -X325719Y239781D01* -Y239156D01* -X325875Y238844D01* -X326187Y238687D01* -X326500Y238844D01* -X326656Y239156D01* -Y239781D01* -X326813Y240094D01* -X327125Y240250D01* -X327437Y240094D01* -X327594Y239781D01* -Y239156D01* -X327437Y238844D01* -X327125Y238687D01* -X326031Y236187D02* -X325875Y236344D01* -X325719Y236656D01* -Y237125D01* -X325875Y237437D01* -X326031Y237594D01* -X326344Y237750D01* -X326969D01* -X327281Y237594D01* -X327437Y237437D01* -X327594Y237125D01* -Y236656D01* -X327437Y236344D01* -X327281Y236187D01* -X327594Y235250D02* -X325719D01* -Y233687D01* -X336187Y240250D02* -X335875Y240094D01* -X335719Y239781D01* -Y239156D01* -X335875Y238844D01* -X336187Y238687D01* -X336500Y238844D01* -X336656Y239156D01* -Y239781D01* -X336813Y240094D01* -X337125Y240250D01* -X337437Y240094D01* -X337594Y239781D01* -Y239156D01* -X337437Y238844D01* -X337125Y238687D01* -X335719Y237750D02* -X337594D01* -Y236813D01* -X337437Y236500D01* -X337281Y236344D01* -X336969Y236187D01* -X336344D01* -X336031Y236344D01* -X335875Y236500D01* -X335719Y236813D01* -Y237750D01* -Y235250D02* -X337594Y234469D01* -X335719Y233687D01* -X336500Y234937D02* -Y234000D01* -D02* -D11* -X25250Y106187D02* -X25406Y105875D01* -X25719Y105719D01* -X26344D01* -X26656Y105875D01* -X26813Y106187D01* -X26656Y106500D01* -X26344Y106656D01* -X25719D01* -X25406Y106813D01* -X25250Y107125D01* -X25406Y107437D01* -X25719Y107594D01* -X26344D01* -X26656Y107437D01* -X26813Y107125D01* -X27750Y105719D02* -Y107594D01* -X28687D01* -X29000Y107437D01* -X29156Y107281D01* -X29313Y106969D01* -Y106344D01* -X29156Y106031D01* -X29000Y105875D01* -X28687Y105719D01* -X27750D01* -X30250D02* -X31031Y107594D01* -X31813Y105719D01* -X30563Y106500D02* -X31500D01* -X25250Y116187D02* -X25406Y115875D01* -X25719Y115719D01* -X26344D01* -X26656Y115875D01* -X26813Y116187D01* -X26656Y116500D01* -X26344Y116656D01* -X25719D01* -X25406Y116813D01* -X25250Y117125D01* -X25406Y117437D01* -X25719Y117594D01* -X26344D01* -X26656Y117437D01* -X26813Y117125D01* -X29313Y116031D02* -X29156Y115875D01* -X28844Y115719D01* -X28375D01* -X28063Y115875D01* -X27906Y116031D01* -X27750Y116344D01* -Y116969D01* -X27906Y117281D01* -X28063Y117437D01* -X28375Y117594D01* -X28844D01* -X29156Y117437D01* -X29313Y117281D01* -X30250Y115719D02* -Y117594D01* -Y116656D02* -X30719D01* -X31813Y117594D01* -X30719Y116656D02* -X31813Y115719D01* -X25250Y125719D02* -Y127594D01* -X26031Y126656D01* -X26813Y127594D01* -Y125719D01* -X27750Y126344D02* -Y126969D01* -X27906Y127281D01* -X28063Y127437D01* -X28375Y127594D01* -X28687D01* -X29000Y127437D01* -X29156Y127281D01* -X29313Y126969D01* -Y126344D01* -X29156Y126031D01* -X29000Y125875D01* -X28687Y125719D01* -X28375D01* -X28063Y125875D01* -X27906Y126031D01* -X27750Y126344D01* -X30250Y126187D02* -X30406Y125875D01* -X30719Y125719D01* -X31344D01* -X31656Y125875D01* -X31813Y126187D01* -X31656Y126500D01* -X31344Y126656D01* -X30719D01* -X30406Y126813D01* -X30250Y127125D01* -X30406Y127437D01* -X30719Y127594D01* -X31344D01* -X31656Y127437D01* -X31813Y127125D01* -X33219Y125719D02* -X33844D01* -X33531D02* -Y127594D01* -X33219D02* -X33844D01* -X25250Y135719D02* -Y137594D01* -X26031Y136656D01* -X26813Y137594D01* -Y135719D01* -X28219D02* -X28844D01* -X28531D02* -Y137594D01* -X28219D02* -X28844D01* -X30250Y136187D02* -X30406Y135875D01* -X30719Y135719D01* -X31344D01* -X31656Y135875D01* -X31813Y136187D01* -X31656Y136500D01* -X31344Y136656D01* -X30719D01* -X30406Y136813D01* -X30250Y137125D01* -X30406Y137437D01* -X30719Y137594D01* -X31344D01* -X31656Y137437D01* -X31813Y137125D01* -X32750Y136344D02* -Y136969D01* -X32906Y137281D01* -X33063Y137437D01* -X33375Y137594D01* -X33687D01* -X34000Y137437D01* -X34156Y137281D01* -X34313Y136969D01* -Y136344D01* -X34156Y136031D01* -X34000Y135875D01* -X33687Y135719D01* -X33375D01* -X33063Y135875D01* -X32906Y136031D01* -X32750Y136344D01* -X25719Y145719D02* -X26344D01* -X26031D02* -Y147594D01* -X25719D02* -X26344D01* -X27750Y145719D02* -Y147594D01* -X28844D01* -X29156Y147437D01* -X29313Y147125D01* -X29156Y146813D01* -X28844Y146656D01* -X27750D01* -X28844D02* -X29313Y145719D01* -X30250Y146344D02* -Y146969D01* -X30406Y147281D01* -X30563Y147437D01* -X30875Y147594D01* -X31187D01* -X31500Y147437D01* -X31656Y147281D01* -X31813Y146969D01* -Y146344D01* -X31656Y146031D01* -X31500Y145875D01* -X31187Y145719D01* -X30875D01* -X30563Y145875D01* -X30406Y146031D01* -X30250Y146344D01* -X31344Y146187D02* -X31813Y145719D01* -X26344Y156500D02* -X26813D01* -Y156344D01* -X26656Y156031D01* -X26500Y155875D01* -X26187Y155719D01* -X25875D01* -X25563Y155875D01* -X25406Y156031D01* -X25250Y156344D01* -Y156969D01* -X25406Y157281D01* -X25563Y157437D01* -X25875Y157594D01* -X26187D01* -X26500Y157437D01* -X26656Y157281D01* -X26813Y156969D01* -X27750Y155719D02* -Y157594D01* -X29313Y155719D01* -Y157594D01* -X30250Y155719D02* -Y157594D01* -X31187D01* -X31500Y157437D01* -X31656Y157281D01* -X31813Y156969D01* -Y156344D01* -X31656Y156031D01* -X31500Y155875D01* -X31187Y155719D01* -X30250D01* -X25250Y165719D02* -Y167594D01* -X26344D01* -X26656Y167437D01* -X26813Y167125D01* -X26656Y166813D01* -X26344Y166656D01* -X25250D01* -X26344D02* -X26813Y165719D01* -X27750Y166187D02* -X27906Y165875D01* -X28219Y165719D01* -X28844D01* -X29156Y165875D01* -X29313Y166187D01* -X29156Y166500D01* -X28844Y166656D01* -X28219D01* -X27906Y166813D01* -X27750Y167125D01* -X27906Y167437D01* -X28219Y167594D01* -X28844D01* -X29156Y167437D01* -X29313Y167125D01* -X31031Y165719D02* -Y167594D01* -X30250D02* -X31813D01* -X25406Y175875D02* -X25719Y175719D01* -X26031D01* -X26344Y175875D01* -X26500Y176187D01* -X26344Y176500D01* -X26031Y176656D01* -X25719D01* -X26031D02* -X26344Y176813D01* -X26500Y177125D01* -X26344Y177437D01* -X26031Y177594D01* -X25719D01* -X25406Y177437D01* -X27906Y175719D02* -X28063Y175875D01* -X27906Y176031D01* -X27750Y175875D01* -X27906Y175719D01* -X30406Y175875D02* -X30719Y175719D01* -X31031D01* -X31344Y175875D01* -X31500Y176187D01* -X31344Y176500D01* -X31031Y176656D01* -X30719D01* -X31031D02* -X31344Y176813D01* -X31500Y177125D01* -X31344Y177437D01* -X31031Y177594D01* -X30719D01* -X30406Y177437D01* -X32750Y176969D02* -X33375Y175719D01* -X34000Y176969D01* -X262967Y32945D02* -X263546Y32869D01* -X263517Y32722D01* -X263480Y32587D01* -X263432Y32455D01* -X263378Y32334D01* -X263311Y32220D01* -X263238Y32118D01* -X263154Y32019D01* -X263059Y31931D01* -X262960Y31854D01* -X262854Y31784D01* -X262740Y31726D01* -X262623Y31678D01* -X262498Y31642D01* -X262370Y31616D01* -X262239Y31598D01* -X262096Y31594D01* -X261924Y31601D01* -X261759Y31623D01* -X261601Y31660D01* -X261451Y31711D01* -X261312Y31777D01* -X261184Y31857D01* -X261063Y31953D01* -X260950Y32059D01* -X260847Y32183D01* -X260759Y32319D01* -X260682Y32469D01* -X260624Y32627D01* -X260576Y32802D01* -X260539Y32989D01* -X260521Y33187D01* -X260514Y33400D01* -X260517Y33539D01* -X260525Y33670D01* -X260539Y33802D01* -X260561Y33927D01* -X260587Y34048D01* -X260620Y34165D01* -X260656Y34278D01* -X260700Y34385D01* -X260752Y34487D01* -X260807Y34582D01* -X260869Y34674D01* -X260935Y34754D01* -X261012Y34831D01* -X261092Y34901D01* -X261176Y34963D01* -X261268Y35018D01* -X261367Y35069D01* -X261466Y35109D01* -X261565Y35146D01* -X261667Y35176D01* -X261774Y35201D01* -X261880Y35216D01* -X261989Y35227D01* -X262099Y35230D01* -X262239Y35227D01* -X262370Y35212D01* -X262498Y35190D01* -X262616Y35157D01* -X262729Y35117D01* -X262835Y35069D01* -X262934Y35011D01* -X263030Y34945D01* -X263114Y34868D01* -X263194Y34784D01* -X263264Y34692D01* -X263326Y34597D01* -X263378Y34491D01* -X263425Y34377D01* -X263462Y34256D01* -X263491Y34128D01* -X262916Y34040D01* -X262894Y34124D01* -X262869Y34205D01* -X262835Y34278D01* -X262802Y34348D01* -X262766Y34410D01* -X262722Y34469D01* -X262678Y34524D01* -X262627Y34568D01* -X262572Y34611D01* -X262517Y34648D01* -X262458Y34678D01* -X262396Y34703D01* -X262334Y34721D01* -X262264Y34736D01* -X262194Y34743D01* -X262125Y34747D01* -X262015Y34743D01* -X261913Y34725D01* -X261814Y34703D01* -X261719Y34667D01* -X261631Y34622D01* -X261550Y34568D01* -X261473Y34502D01* -X261400Y34428D01* -X261334Y34341D01* -X261279Y34245D01* -X261231Y34135D01* -X261191Y34015D01* -X261162Y33883D01* -X261140Y33736D01* -X261125Y33583D01* -X261122Y33414D01* -X261125Y33246D01* -X261140Y33088D01* -X261158Y32942D01* -X261187Y32810D01* -X261228Y32689D01* -X261272Y32579D01* -X261327Y32480D01* -X261389Y32396D01* -X261462Y32319D01* -X261535Y32257D01* -X261616Y32202D01* -X261700Y32158D01* -X261792Y32121D01* -X261887Y32096D01* -X261986Y32081D01* -X262092Y32078D01* -X262176Y32081D01* -X262257Y32092D01* -X262337Y32107D01* -X262411Y32129D01* -X262480Y32162D01* -X262550Y32198D01* -X262612Y32239D01* -X262670Y32290D01* -X262729Y32348D01* -X262777Y32411D01* -X262824Y32480D01* -X262861Y32561D01* -X262898Y32645D01* -X262927Y32737D01* -X262949Y32839D01* -X262967Y32945D01* -X266322Y32099D02* -X266241Y32033D01* -X266161Y31971D01* -X266080Y31913D01* -X266000Y31861D01* -X265919Y31817D01* -X265842Y31774D01* -X265765Y31741D01* -X265688Y31707D01* -X265534Y31656D01* -X265377Y31623D01* -X265209Y31601D01* -X265040Y31594D01* -X264901Y31598D01* -X264769Y31612D01* -X264648Y31634D01* -X264531Y31663D01* -X264425Y31704D01* -X264330Y31752D01* -X264238Y31806D01* -X264157Y31872D01* -X264084Y31946D01* -X264022Y32022D01* -X263971Y32107D01* -X263927Y32191D01* -X263894Y32282D01* -X263868Y32381D01* -X263854Y32484D01* -X263850Y32590D01* -X263857Y32715D01* -X263879Y32832D01* -X263916Y32945D01* -X263967Y33055D01* -X264029Y33154D01* -X264099Y33246D01* -X264183Y33326D01* -X264271Y33396D01* -X264370Y33454D01* -X264472Y33506D01* -X264579Y33550D01* -X264696Y33586D01* -X264740Y33597D01* -X264794Y33612D01* -X264850Y33623D01* -X264912Y33634D01* -X264981Y33645D01* -X265055Y33656D01* -X265135Y33667D01* -X265219Y33678D01* -X265392Y33696D01* -X265553Y33722D01* -X265703Y33744D01* -X265838Y33769D01* -X265967Y33795D01* -X266080Y33820D01* -X266179Y33850D01* -X266270Y33879D01* -X266274Y33934D01* -Y33978D01* -Y34011D01* -Y34033D01* -X266270Y34121D01* -X266263Y34202D01* -X266252Y34275D01* -X266234Y34341D01* -X266208Y34403D01* -X266179Y34454D01* -X266146Y34502D01* -X266106Y34542D01* -X266047Y34590D01* -X265981Y34630D01* -X265908Y34667D01* -X265828Y34692D01* -X265739Y34714D01* -X265644Y34732D01* -X265545Y34740D01* -X265435Y34743D01* -X265337Y34740D01* -X265241Y34732D01* -X265157Y34721D01* -X265077Y34707D01* -X265004Y34685D01* -X264937Y34659D01* -X264875Y34630D01* -X264824Y34597D01* -X264776Y34557D01* -X264732Y34509D01* -X264689Y34454D01* -X264652Y34396D01* -X264615Y34326D01* -X264586Y34253D01* -X264557Y34169D01* -X264531Y34081D01* -X263952Y34157D01* -X263974Y34249D01* -X263996Y34333D01* -X264026Y34414D01* -X264055Y34491D01* -X264092Y34564D01* -X264128Y34633D01* -X264169Y34696D01* -X264213Y34754D01* -X264260Y34813D01* -X264311Y34864D01* -X264370Y34912D01* -X264432Y34956D01* -X264498Y35000D01* -X264571Y35040D01* -X264648Y35073D01* -X264732Y35106D01* -X264820Y35135D01* -X264908Y35161D01* -X265004Y35183D01* -X265099Y35198D01* -X265201Y35212D01* -X265304Y35223D01* -X265410Y35227D01* -X265520Y35230D01* -X265630Y35227D01* -X265732Y35223D01* -X265831Y35216D01* -X265926Y35205D01* -X266014Y35190D01* -X266095Y35172D01* -X266172Y35150D01* -X266245Y35124D01* -X266311Y35099D01* -X266377Y35069D01* -X266431Y35040D01* -X266487Y35007D01* -X266534Y34974D01* -X266578Y34937D01* -X266619Y34901D01* -X266655Y34861D01* -X266714Y34776D01* -X266765Y34681D01* -X266805Y34575D01* -X266838Y34458D01* -X266845Y34417D01* -X266849Y34370D01* -X266856Y34311D01* -X266860Y34249D01* -X266864Y34176D01* -X266867Y34095D01* -Y34011D01* -Y33916D01* -Y33128D01* -Y33030D01* -Y32934D01* -Y32843D01* -X266871Y32755D01* -Y32674D01* -Y32597D01* -X266875Y32524D01* -X266878Y32458D01* -Y32396D01* -X266882Y32337D01* -X266886Y32286D01* -X266889Y32235D01* -X266893Y32191D01* -X266897Y32154D01* -X266900Y32118D01* -X266904Y32088D01* -X266930Y31982D01* -X266963Y31876D01* -X267003Y31774D01* -X267054Y31671D01* -X266439D01* -X266399Y31766D01* -X266366Y31869D01* -X266340Y31978D01* -X266322Y32099D01* -X266274Y33418D02* -X266190Y33385D01* -X266095Y33356D01* -X265989Y33326D01* -X265871Y33297D01* -X265747Y33268D01* -X265611Y33242D01* -X265465Y33220D01* -X265311Y33194D01* -X265223Y33180D01* -X265143Y33169D01* -X265066Y33154D01* -X265000Y33139D01* -X264937Y33125D01* -X264883Y33110D01* -X264835Y33092D01* -X264794Y33077D01* -X264725Y33041D01* -X264663Y32996D01* -X264608Y32945D01* -X264560Y32887D01* -X264527Y32821D01* -X264502Y32751D01* -X264483Y32681D01* -X264480Y32605D01* -X264483Y32546D01* -X264491Y32491D01* -X264506Y32440D01* -X264524Y32389D01* -X264549Y32341D01* -X264579Y32297D01* -X264615Y32253D01* -X264659Y32213D01* -X264707Y32176D01* -X264758Y32143D01* -X264817Y32118D01* -X264879Y32096D01* -X264945Y32078D01* -X265018Y32067D01* -X265099Y32059D01* -X265179Y32056D01* -X265263Y32059D01* -X265348Y32063D01* -X265424Y32078D01* -X265502Y32092D01* -X265578Y32114D01* -X265648Y32140D01* -X265718Y32169D01* -X265787Y32206D01* -X265849Y32242D01* -X265912Y32286D01* -X265967Y32330D01* -X266018Y32381D01* -X266062Y32433D01* -X266106Y32491D01* -X266143Y32550D01* -X266175Y32612D01* -X266197Y32663D01* -X266219Y32722D01* -X266234Y32788D01* -X266248Y32857D01* -X266256Y32934D01* -X266263Y33019D01* -X266270Y33106D01* -Y33202D01* -X266274Y33418D01* -X267776Y31671D02* -Y35154D01* -X268307D01* -Y34626D01* -X268358Y34714D01* -X268406Y34794D01* -X268453Y34868D01* -X268501Y34930D01* -X268548Y34989D01* -X268592Y35036D01* -X268636Y35080D01* -X268680Y35113D01* -X268768Y35165D01* -X268863Y35201D01* -X268911Y35212D01* -X268959Y35223D01* -X269010Y35227D01* -X269061Y35230D01* -X269134Y35227D01* -X269207Y35219D01* -X269284Y35205D01* -X269361Y35183D01* -X269435Y35157D01* -X269511Y35124D01* -X269588Y35088D01* -X269665Y35044D01* -X269460Y34494D01* -X269405Y34524D01* -X269350Y34553D01* -X269299Y34571D01* -X269244Y34590D01* -X269189Y34604D01* -X269134Y34615D01* -X269083Y34619D01* -X269028Y34622D01* -X268933Y34615D01* -X268845Y34593D01* -X268761Y34557D01* -X268684Y34506D01* -X268611Y34443D01* -X268552Y34366D01* -X268501Y34282D01* -X268464Y34183D01* -X268420Y34022D01* -X268391Y33854D01* -X268372Y33678D01* -X268365Y33494D01* -Y31671D01* -X267776D01* -X270002D02* -Y36476D01* -X270592D01* -Y31671D01* -X270002D01* -X272049D02* -X271504D01* -Y36476D01* -X272093D01* -Y34762D01* -X272189Y34872D01* -X272294Y34967D01* -X272401Y35047D01* -X272518Y35113D01* -X272643Y35165D01* -X272771Y35201D01* -X272906Y35223D01* -X273045Y35230D01* -X273126Y35227D01* -X273207Y35223D01* -X273283Y35212D01* -X273360Y35198D01* -X273433Y35179D01* -X273511Y35157D01* -X273584Y35131D01* -X273653Y35102D01* -X273793Y35029D01* -X273917Y34945D01* -X274027Y34846D01* -X274126Y34736D01* -X274214Y34615D01* -X274291Y34480D01* -X274360Y34330D01* -X274415Y34172D01* -X274463Y34004D01* -X274496Y33828D01* -X274514Y33648D01* -X274521Y33465D01* -X274514Y33246D01* -X274492Y33044D01* -X274459Y32850D01* -X274411Y32670D01* -X274349Y32506D01* -X274272Y32352D01* -X274181Y32209D01* -X274078Y32081D01* -X274023Y32022D01* -X273965Y31968D01* -X273906Y31916D01* -X273847Y31869D01* -X273785Y31825D01* -X273723Y31784D01* -X273657Y31748D01* -X273591Y31715D01* -X273525Y31685D01* -X273456Y31663D01* -X273386Y31642D01* -X273317Y31623D01* -X273243Y31612D01* -X273170Y31601D01* -X273093Y31594D01* -X273016D01* -X272939Y31598D01* -X272866Y31601D01* -X272796Y31612D01* -X272723Y31627D01* -X272657Y31645D01* -X272591Y31667D01* -X272529Y31693D01* -X272467Y31722D01* -X272408Y31755D01* -X272350Y31795D01* -X272294Y31836D01* -X272240Y31883D01* -X272192Y31931D01* -X272141Y31986D01* -X272093Y32044D01* -X272049Y32107D01* -Y31671D01* -X272042Y33440D02* -X272046Y33286D01* -X272053Y33147D01* -X272068Y33019D01* -X272086Y32898D01* -X272108Y32791D01* -X272137Y32693D01* -X272174Y32608D01* -X272211Y32531D01* -X272284Y32425D01* -X272364Y32334D01* -X272448Y32257D01* -X272540Y32191D01* -X272635Y32140D01* -X272741Y32107D01* -X272848Y32085D01* -X272965Y32078D01* -X273060Y32081D01* -X273152Y32099D01* -X273239Y32125D01* -X273324Y32162D01* -X273408Y32209D01* -X273485Y32268D01* -X273562Y32334D01* -X273631Y32414D01* -X273697Y32502D01* -X273756Y32601D01* -X273804Y32711D01* -X273844Y32832D01* -X273873Y32964D01* -X273895Y33103D01* -X273910Y33253D01* -X273913Y33414D01* -X273910Y33579D01* -X273895Y33733D01* -X273877Y33876D01* -X273847Y34007D01* -X273807Y34128D01* -X273763Y34238D01* -X273708Y34337D01* -X273643Y34421D01* -X273573Y34498D01* -X273503Y34564D01* -X273426Y34619D01* -X273346Y34667D01* -X273261Y34700D01* -X273174Y34725D01* -X273086Y34743D01* -X272991Y34747D01* -X272895Y34743D01* -X272804Y34725D01* -X272716Y34700D01* -X272631Y34663D01* -X272551Y34615D01* -X272470Y34557D01* -X272397Y34491D01* -X272324Y34410D01* -X272258Y34322D01* -X272200Y34223D01* -X272152Y34117D01* -X272111Y34000D01* -X272082Y33872D01* -X272060Y33736D01* -X272046Y33594D01* -X272042Y33440D01* -X275019Y33410D02* -X275023Y33531D01* -X275027Y33645D01* -X275037Y33758D01* -X275052Y33865D01* -X275070Y33967D01* -X275096Y34066D01* -X275122Y34161D01* -X275155Y34253D01* -X275188Y34341D01* -X275228Y34425D01* -X275272Y34506D01* -X275323Y34579D01* -X275374Y34652D01* -X275430Y34718D01* -X275492Y34784D01* -X275557Y34842D01* -X275671Y34934D01* -X275792Y35015D01* -X275920Y35080D01* -X276056Y35135D01* -X276195Y35176D01* -X276341Y35205D01* -X276491Y35223D01* -X276649Y35230D01* -X276741Y35227D01* -X276825Y35223D01* -X276909Y35212D01* -X276993Y35201D01* -X277074Y35183D01* -X277151Y35165D01* -X277228Y35139D01* -X277304Y35113D01* -X277374Y35080D01* -X277444Y35047D01* -X277513Y35007D01* -X277579Y34967D01* -X277645Y34919D01* -X277707Y34872D01* -X277766Y34817D01* -X277824Y34762D01* -X277931Y34637D01* -X278022Y34502D01* -X278099Y34355D01* -X278165Y34202D01* -X278216Y34033D01* -X278249Y33854D01* -X278271Y33663D01* -X278279Y33462D01* -X278275Y33297D01* -X278268Y33143D01* -X278249Y32996D01* -X278227Y32861D01* -X278202Y32733D01* -X278165Y32616D01* -X278125Y32506D01* -X278077Y32403D01* -X278022Y32312D01* -X277964Y32224D01* -X277901Y32140D01* -X277828Y32063D01* -X277755Y31989D01* -X277670Y31924D01* -X277583Y31861D01* -X277491Y31806D01* -X277393Y31755D01* -X277293Y31715D01* -X277191Y31678D01* -X277088Y31645D01* -X276982Y31623D01* -X276872Y31609D01* -X276763Y31598D01* -X276649Y31594D01* -X276473Y31601D01* -X276305Y31623D01* -X276220Y31638D01* -X276144Y31660D01* -X276067Y31682D01* -X275990Y31711D01* -X275917Y31741D01* -X275847Y31777D01* -X275777Y31814D01* -X275711Y31857D01* -X275649Y31902D01* -X275587Y31953D01* -X275528Y32004D01* -X275470Y32063D01* -X275363Y32187D01* -X275272Y32323D01* -X275195Y32473D01* -X275133Y32634D01* -X275081Y32810D01* -X275048Y32996D01* -X275027Y33198D01* -X275019Y33410D01* -X275627D02* -X275631Y33249D01* -X275646Y33099D01* -X275667Y32956D01* -X275700Y32828D01* -X275741Y32707D01* -X275792Y32597D01* -X275850Y32498D01* -X275917Y32411D01* -X275993Y32330D01* -X276074Y32264D01* -X276158Y32206D01* -X276246Y32162D01* -X276341Y32125D01* -X276440Y32099D01* -X276543Y32081D01* -X276649Y32078D01* -X276759Y32081D01* -X276861Y32099D01* -X276960Y32125D01* -X277052Y32162D01* -X277140Y32209D01* -X277224Y32264D01* -X277304Y32334D01* -X277381Y32411D01* -X277447Y32502D01* -X277506Y32601D01* -X277557Y32711D01* -X277597Y32832D01* -X277630Y32967D01* -X277652Y33110D01* -X277667Y33264D01* -X277670Y33432D01* -X277667Y33590D01* -X277652Y33736D01* -X277630Y33872D01* -X277597Y34000D01* -X277557Y34117D01* -X277506Y34223D01* -X277447Y34322D01* -X277378Y34410D01* -X277304Y34487D01* -X277224Y34557D01* -X277140Y34611D01* -X277052Y34659D01* -X276957Y34696D01* -X276857Y34721D01* -X276759Y34740D01* -X276649Y34743D01* -X276543Y34740D01* -X276440Y34721D01* -X276341Y34696D01* -X276246Y34659D01* -X276158Y34615D01* -X276074Y34557D01* -X275993Y34491D01* -X275917Y34410D01* -X275850Y34322D01* -X275792Y34223D01* -X275741Y34117D01* -X275700Y33996D01* -X275667Y33865D01* -X275646Y33725D01* -X275631Y33575D01* -X275627Y33410D01* -X281248Y31671D02* -Y32183D01* -X281197Y32114D01* -X281143Y32048D01* -X281087Y31982D01* -X281029Y31927D01* -X280967Y31872D01* -X280904Y31825D01* -X280838Y31781D01* -X280769Y31741D01* -X280699Y31707D01* -X280626Y31678D01* -X280553Y31653D01* -X280476Y31631D01* -X280395Y31616D01* -X280315Y31601D01* -X280230Y31598D01* -X280146Y31594D01* -X280069D01* -X279993Y31601D01* -X279919Y31609D01* -X279846Y31623D01* -X279776Y31642D01* -X279707Y31660D01* -X279637Y31685D01* -X279571Y31711D01* -X279506Y31741D01* -X279447Y31774D01* -X279388Y31810D01* -X279337Y31843D01* -X279289Y31883D01* -X279245Y31924D01* -X279209Y31964D01* -X279172Y32008D01* -X279113Y32103D01* -X279062Y32206D01* -X279022Y32323D01* -X278993Y32447D01* -X278985Y32491D01* -X278978Y32546D01* -X278971Y32605D01* -X278967Y32670D01* -X278960Y32744D01* -Y32821D01* -X278956Y32905D01* -Y32996D01* -Y35154D01* -X279546D01* -Y33224D01* -Y33114D01* -X279549Y33011D01* -Y32920D01* -X279557Y32835D01* -X279560Y32762D01* -X279568Y32700D01* -X279575Y32645D01* -X279582Y32601D01* -X279597Y32543D01* -X279619Y32491D01* -X279641Y32440D01* -X279670Y32393D01* -X279700Y32348D01* -X279736Y32308D01* -X279773Y32272D01* -X279817Y32235D01* -X279864Y32206D01* -X279912Y32176D01* -X279963Y32154D01* -X280018Y32136D01* -X280077Y32121D01* -X280135Y32110D01* -X280198Y32107D01* -X280263Y32103D01* -X280330Y32107D01* -X280395Y32110D01* -X280457Y32121D01* -X280520Y32136D01* -X280582Y32154D01* -X280641Y32180D01* -X280703Y32206D01* -X280761Y32239D01* -X280817Y32275D01* -X280868Y32312D01* -X280915Y32356D01* -X280959Y32400D01* -X281000Y32447D01* -X281032Y32498D01* -X281062Y32554D01* -X281091Y32608D01* -X281113Y32670D01* -X281131Y32740D01* -X281150Y32813D01* -X281161Y32898D01* -X281172Y32985D01* -X281179Y33081D01* -X281186Y33180D01* -Y33289D01* -Y35154D01* -X281776D01* -Y31671D01* -X281248D01* -X284962D02* -Y32110D01* -X284918Y32048D01* -X284874Y31989D01* -X284826Y31935D01* -X284779Y31883D01* -X284724Y31839D01* -X284669Y31795D01* -X284614Y31759D01* -X284552Y31722D01* -X284489Y31693D01* -X284427Y31667D01* -X284361Y31645D01* -X284292Y31627D01* -X284219Y31612D01* -X284145Y31601D01* -X284069Y31598D01* -X283988Y31594D01* -X283885Y31598D01* -X283783Y31609D01* -X283684Y31627D01* -X283589Y31653D01* -X283493Y31682D01* -X283402Y31722D01* -X283310Y31770D01* -X283222Y31825D01* -X283138Y31883D01* -X283057Y31949D01* -X282984Y32019D01* -X282911Y32099D01* -X282849Y32180D01* -X282787Y32268D01* -X282731Y32363D01* -X282680Y32462D01* -X282637Y32568D01* -X282600Y32678D01* -X282567Y32788D01* -X282537Y32905D01* -X282516Y33026D01* -X282501Y33150D01* -X282494Y33279D01* -X282490Y33410D01* -X282494Y33539D01* -X282501Y33663D01* -X282516Y33784D01* -X282534Y33905D01* -X282559Y34022D01* -X282589Y34135D01* -X282622Y34245D01* -X282662Y34355D01* -X282710Y34458D01* -X282761Y34553D01* -X282820Y34644D01* -X282882Y34729D01* -X282948Y34806D01* -X283021Y34879D01* -X283102Y34945D01* -X283182Y35004D01* -X283270Y35058D01* -X283361Y35102D01* -X283457Y35143D01* -X283552Y35172D01* -X283651Y35198D01* -X283750Y35216D01* -X283852Y35227D01* -X283959Y35230D01* -X284035Y35227D01* -X284112Y35223D01* -X284185Y35212D01* -X284255Y35198D01* -X284325Y35179D01* -X284391Y35157D01* -X284457Y35128D01* -X284519Y35099D01* -X284636Y35025D01* -X284742Y34945D01* -X284834Y34853D01* -X284918Y34754D01* -Y36476D01* -X285507D01* -Y31671D01* -X284962D01* -X283098Y33407D02* -X283102Y33246D01* -X283116Y33095D01* -X283138Y32953D01* -X283167Y32824D01* -X283208Y32704D01* -X283256Y32594D01* -X283314Y32495D01* -X283380Y32407D01* -X283453Y32330D01* -X283526Y32264D01* -X283607Y32206D01* -X283687Y32162D01* -X283772Y32125D01* -X283859Y32099D01* -X283951Y32081D01* -X284046Y32078D01* -X284142Y32081D01* -X284233Y32096D01* -X284317Y32121D01* -X284402Y32158D01* -X284482Y32202D01* -X284559Y32257D01* -X284632Y32319D01* -X284702Y32393D01* -X284768Y32476D01* -X284823Y32572D01* -X284867Y32678D01* -X284907Y32791D01* -X284936Y32920D01* -X284955Y33055D01* -X284969Y33202D01* -X284973Y33359D01* -X284969Y33531D01* -X284955Y33693D01* -X284933Y33843D01* -X284903Y33978D01* -X284867Y34102D01* -X284819Y34216D01* -X284761Y34319D01* -X284698Y34410D01* -X284629Y34487D01* -X284552Y34557D01* -X284475Y34611D01* -X284391Y34659D01* -X284303Y34696D01* -X284211Y34721D01* -X284120Y34740D01* -X284021Y34743D01* -X283922Y34740D01* -X283830Y34721D01* -X283743Y34700D01* -X283658Y34663D01* -X283578Y34619D01* -X283501Y34564D01* -X283431Y34498D01* -X283361Y34421D01* -X283299Y34337D01* -X283248Y34238D01* -X283200Y34128D01* -X283164Y34007D01* -X283135Y33876D01* -X283116Y33733D01* -X283102Y33575D01* -X283098Y33407D01* -X286427Y31671D02* -Y35154D01* -X286958D01* -Y34626D01* -X287009Y34714D01* -X287057Y34794D01* -X287104Y34868D01* -X287152Y34930D01* -X287200Y34989D01* -X287243Y35036D01* -X287287Y35080D01* -X287331Y35113D01* -X287419Y35165D01* -X287515Y35201D01* -X287562Y35212D01* -X287609Y35223D01* -X287661Y35227D01* -X287712Y35230D01* -X287785Y35227D01* -X287859Y35219D01* -X287935Y35205D01* -X288013Y35183D01* -X288086Y35157D01* -X288163Y35124D01* -X288239Y35088D01* -X288317Y35044D01* -X288111Y34494D01* -X288056Y34524D01* -X288002Y34553D01* -X287950Y34571D01* -X287895Y34590D01* -X287840Y34604D01* -X287785Y34615D01* -X287734Y34619D01* -X287679Y34622D01* -X287584Y34615D01* -X287496Y34593D01* -X287412Y34557D01* -X287335Y34506D01* -X287262Y34443D01* -X287203Y34366D01* -X287152Y34282D01* -X287115Y34183D01* -X287071Y34022D01* -X287042Y33854D01* -X287024Y33678D01* -X287017Y33494D01* -Y31671D01* -X286427D01* -X291048Y32795D02* -X291660Y32718D01* -X291620Y32587D01* -X291572Y32466D01* -X291517Y32352D01* -X291455Y32242D01* -X291381Y32143D01* -X291305Y32052D01* -X291217Y31968D01* -X291125Y31887D01* -X291023Y31821D01* -X290917Y31759D01* -X290803Y31707D01* -X290682Y31667D01* -X290554Y31634D01* -X290419Y31612D01* -X290276Y31598D01* -X290129Y31594D01* -X290034D01* -X289943Y31601D01* -X289854Y31609D01* -X289767Y31623D01* -X289682Y31638D01* -X289602Y31660D01* -X289521Y31685D01* -X289444Y31711D01* -X289371Y31744D01* -X289298Y31777D01* -X289228Y31817D01* -X289162Y31857D01* -X289096Y31905D01* -X289034Y31953D01* -X288976Y32008D01* -X288917Y32063D01* -X288815Y32187D01* -X288723Y32323D01* -X288646Y32469D01* -X288584Y32627D01* -X288532Y32799D01* -X288500Y32982D01* -X288478Y33176D01* -X288470Y33381D01* -X288478Y33597D01* -X288500Y33798D01* -X288532Y33985D01* -X288584Y34161D01* -X288646Y34326D01* -X288726Y34480D01* -X288818Y34619D01* -X288924Y34747D01* -X288979Y34806D01* -X289041Y34861D01* -X289100Y34912D01* -X289166Y34956D01* -X289232Y35000D01* -X289298Y35040D01* -X289371Y35077D01* -X289441Y35109D01* -X289518Y35139D01* -X289594Y35161D01* -X289671Y35183D01* -X289752Y35201D01* -X289836Y35212D01* -X289920Y35223D01* -X290008Y35227D01* -X290096Y35230D01* -X290180Y35227D01* -X290265Y35223D01* -X290349Y35212D01* -X290430Y35201D01* -X290506Y35183D01* -X290583Y35165D01* -X290656Y35139D01* -X290730Y35109D01* -X290799Y35080D01* -X290869Y35044D01* -X290935Y35007D01* -X290997Y34963D01* -X291059Y34915D01* -X291122Y34868D01* -X291180Y34813D01* -X291235Y34754D01* -X291341Y34630D01* -X291429Y34494D01* -X291506Y34344D01* -X291569Y34183D01* -X291616Y34011D01* -X291649Y33824D01* -X291671Y33626D01* -X291678Y33418D01* -Y33389D01* -Y33352D01* -Y33308D01* -X291674Y33260D01* -X289078D01* -X289089Y33121D01* -X289111Y32989D01* -X289141Y32869D01* -X289177Y32755D01* -X289221Y32649D01* -X289272Y32550D01* -X289335Y32462D01* -X289404Y32381D01* -X289477Y32312D01* -X289558Y32250D01* -X289642Y32194D01* -X289730Y32154D01* -X289825Y32121D01* -X289920Y32096D01* -X290023Y32081D01* -X290129Y32078D01* -X290210Y32081D01* -X290287Y32088D01* -X290360Y32099D01* -X290433Y32121D01* -X290499Y32143D01* -X290565Y32172D01* -X290627Y32209D01* -X290686Y32250D01* -X290741Y32293D01* -X290796Y32348D01* -X290843Y32407D01* -X290891Y32469D01* -X290935Y32543D01* -X290975Y32619D01* -X291015Y32704D01* -X291048Y32795D01* -X289111Y33744D02* -X291056D01* -X291044Y33850D01* -X291026Y33949D01* -X291004Y34044D01* -X290979Y34128D01* -X290950Y34209D01* -X290917Y34282D01* -X290876Y34348D01* -X290832Y34406D01* -X290759Y34483D01* -X290682Y34553D01* -X290598Y34611D01* -X290510Y34663D01* -X290415Y34700D01* -X290316Y34725D01* -X290210Y34740D01* -X290100Y34747D01* -X290001Y34743D01* -X289906Y34729D01* -X289814Y34707D01* -X289726Y34678D01* -X289642Y34641D01* -X289565Y34593D01* -X289488Y34538D01* -X289419Y34472D01* -X289353Y34403D01* -X289294Y34326D01* -X289246Y34242D01* -X289203Y34154D01* -X289170Y34059D01* -X289141Y33960D01* -X289122Y33854D01* -X289111Y33744D01* -X294670Y32099D02* -X294590Y32033D01* -X294509Y31971D01* -X294428Y31913D01* -X294348Y31861D01* -X294267Y31817D01* -X294191Y31774D01* -X294113Y31741D01* -X294037Y31707D01* -X293883Y31656D01* -X293725Y31623D01* -X293557Y31601D01* -X293389Y31594D01* -X293249Y31598D01* -X293117Y31612D01* -X292996Y31634D01* -X292880Y31663D01* -X292773Y31704D01* -X292678Y31752D01* -X292587Y31806D01* -X292506Y31872D01* -X292433Y31946D01* -X292370Y32022D01* -X292319Y32107D01* -X292275Y32191D01* -X292242Y32282D01* -X292217Y32381D01* -X292202Y32484D01* -X292198Y32590D01* -X292206Y32715D01* -X292228Y32832D01* -X292264Y32945D01* -X292315Y33055D01* -X292378Y33154D01* -X292447Y33246D01* -X292531Y33326D01* -X292619Y33396D01* -X292718Y33454D01* -X292821Y33506D01* -X292927Y33550D01* -X293044Y33586D01* -X293088Y33597D01* -X293143Y33612D01* -X293198Y33623D01* -X293260Y33634D01* -X293330Y33645D01* -X293403Y33656D01* -X293483Y33667D01* -X293568Y33678D01* -X293740Y33696D01* -X293901Y33722D01* -X294051Y33744D01* -X294187Y33769D01* -X294315Y33795D01* -X294428Y33820D01* -X294527Y33850D01* -X294619Y33879D01* -X294622Y33934D01* -Y33978D01* -Y34011D01* -Y34033D01* -X294619Y34121D01* -X294611Y34202D01* -X294600Y34275D01* -X294582Y34341D01* -X294557Y34403D01* -X294527Y34454D01* -X294494Y34502D01* -X294454Y34542D01* -X294396Y34590D01* -X294330Y34630D01* -X294256Y34667D01* -X294176Y34692D01* -X294088Y34714D01* -X293993Y34732D01* -X293894Y34740D01* -X293784Y34743D01* -X293685Y34740D01* -X293590Y34732D01* -X293506Y34721D01* -X293425Y34707D01* -X293352Y34685D01* -X293286Y34659D01* -X293224Y34630D01* -X293172Y34597D01* -X293125Y34557D01* -X293081Y34509D01* -X293037Y34454D01* -X293000Y34396D01* -X292964Y34326D01* -X292934Y34253D01* -X292905Y34169D01* -X292880Y34081D01* -X292301Y34157D01* -X292323Y34249D01* -X292345Y34333D01* -X292374Y34414D01* -X292403Y34491D01* -X292440Y34564D01* -X292476Y34633D01* -X292517Y34696D01* -X292561Y34754D01* -X292608Y34813D01* -X292660Y34864D01* -X292718Y34912D01* -X292781Y34956D01* -X292846Y35000D01* -X292920Y35040D01* -X292996Y35073D01* -X293081Y35106D01* -X293169Y35135D01* -X293257Y35161D01* -X293352Y35183D01* -X293447Y35198D01* -X293550Y35212D01* -X293652Y35223D01* -X293758Y35227D01* -X293868Y35230D01* -X293978Y35227D01* -X294081Y35223D01* -X294180Y35216D01* -X294275Y35205D01* -X294363Y35190D01* -X294443Y35172D01* -X294520Y35150D01* -X294593Y35124D01* -X294659Y35099D01* -X294725Y35069D01* -X294780Y35040D01* -X294835Y35007D01* -X294883Y34974D01* -X294926Y34937D01* -X294967Y34901D01* -X295004Y34861D01* -X295062Y34776D01* -X295113Y34681D01* -X295154Y34575D01* -X295187Y34458D01* -X295194Y34417D01* -X295198Y34370D01* -X295205Y34311D01* -X295209Y34249D01* -X295212Y34176D01* -X295216Y34095D01* -Y34011D01* -Y33916D01* -Y33128D01* -Y33030D01* -Y32934D01* -Y32843D01* -X295219Y32755D01* -Y32674D01* -Y32597D01* -X295223Y32524D01* -X295227Y32458D01* -Y32396D01* -X295230Y32337D01* -X295234Y32286D01* -X295238Y32235D01* -X295241Y32191D01* -X295245Y32154D01* -X295249Y32118D01* -X295252Y32088D01* -X295278Y31982D01* -X295311Y31876D01* -X295351Y31774D01* -X295403Y31671D01* -X294787D01* -X294747Y31766D01* -X294714Y31869D01* -X294689Y31978D01* -X294670Y32099D01* -X294622Y33418D02* -X294538Y33385D01* -X294443Y33356D01* -X294337Y33326D01* -X294220Y33297D01* -X294095Y33268D01* -X293960Y33242D01* -X293813Y33220D01* -X293659Y33194D01* -X293572Y33180D01* -X293491Y33169D01* -X293414Y33154D01* -X293348Y33139D01* -X293286Y33125D01* -X293231Y33110D01* -X293183Y33092D01* -X293143Y33077D01* -X293074Y33041D01* -X293011Y32996D01* -X292956Y32945D01* -X292909Y32887D01* -X292876Y32821D01* -X292850Y32751D01* -X292832Y32681D01* -X292828Y32605D01* -X292832Y32546D01* -X292839Y32491D01* -X292854Y32440D01* -X292872Y32389D01* -X292898Y32341D01* -X292927Y32297D01* -X292964Y32253D01* -X293007Y32213D01* -X293055Y32176D01* -X293106Y32143D01* -X293165Y32118D01* -X293227Y32096D01* -X293293Y32078D01* -X293367Y32067D01* -X293447Y32059D01* -X293528Y32056D01* -X293612Y32059D01* -X293696Y32063D01* -X293773Y32078D01* -X293850Y32092D01* -X293927Y32114D01* -X293996Y32140D01* -X294066Y32169D01* -X294135Y32206D01* -X294198Y32242D01* -X294260Y32286D01* -X294315Y32330D01* -X294366Y32381D01* -X294410Y32433D01* -X294454Y32491D01* -X294491Y32550D01* -X294524Y32612D01* -X294546Y32663D01* -X294568Y32722D01* -X294582Y32788D01* -X294597Y32857D01* -X294604Y32934D01* -X294611Y33019D01* -X294619Y33106D01* -Y33202D01* -X294622Y33418D01* -X298409Y31671D02* -Y32183D01* -X298358Y32114D01* -X298303Y32048D01* -X298248Y31982D01* -X298189Y31927D01* -X298127Y31872D01* -X298065Y31825D01* -X297999Y31781D01* -X297930Y31741D01* -X297860Y31707D01* -X297787Y31678D01* -X297713Y31653D01* -X297637Y31631D01* -X297556Y31616D01* -X297475Y31601D01* -X297391Y31598D01* -X297307Y31594D01* -X297230D01* -X297153Y31601D01* -X297080Y31609D01* -X297007Y31623D01* -X296937Y31642D01* -X296867Y31660D01* -X296798Y31685D01* -X296732Y31711D01* -X296666Y31741D01* -X296607Y31774D01* -X296549Y31810D01* -X296498Y31843D01* -X296450Y31883D01* -X296406Y31924D01* -X296369Y31964D01* -X296333Y32008D01* -X296274Y32103D01* -X296223Y32206D01* -X296183Y32323D01* -X296153Y32447D01* -X296146Y32491D01* -X296139Y32546D01* -X296131Y32605D01* -X296128Y32670D01* -X296120Y32744D01* -Y32821D01* -X296117Y32905D01* -Y32996D01* -Y35154D01* -X296706D01* -Y33224D01* -Y33114D01* -X296710Y33011D01* -Y32920D01* -X296717Y32835D01* -X296721Y32762D01* -X296728Y32700D01* -X296735Y32645D01* -X296743Y32601D01* -X296757Y32543D01* -X296780Y32491D01* -X296802Y32440D01* -X296831Y32393D01* -X296860Y32348D01* -X296897Y32308D01* -X296933Y32272D01* -X296977Y32235D01* -X297025Y32206D01* -X297072Y32176D01* -X297124Y32154D01* -X297179Y32136D01* -X297237Y32121D01* -X297296Y32110D01* -X297358Y32107D01* -X297424Y32103D01* -X297490Y32107D01* -X297556Y32110D01* -X297618Y32121D01* -X297680Y32136D01* -X297743Y32154D01* -X297801Y32180D01* -X297863Y32206D01* -X297922Y32239D01* -X297977Y32275D01* -X298028Y32312D01* -X298076Y32356D01* -X298120Y32400D01* -X298160Y32447D01* -X298193Y32498D01* -X298222Y32554D01* -X298252Y32608D01* -X298274Y32670D01* -X298292Y32740D01* -X298310Y32813D01* -X298321Y32898D01* -X298332Y32985D01* -X298340Y33081D01* -X298347Y33180D01* -Y33289D01* -Y35154D01* -X298937D01* -Y31671D01* -X298409D01* -X299698Y34040D02* -X299702Y34249D01* -X299709Y34447D01* -X299724Y34633D01* -X299742Y34809D01* -X299768Y34974D01* -X299797Y35131D01* -X299834Y35278D01* -X299874Y35413D01* -X299922Y35538D01* -X299973Y35655D01* -X300028Y35769D01* -X300090Y35871D01* -X300160Y35970D01* -X300233Y36058D01* -X300310Y36139D01* -X300394Y36212D01* -X300482Y36278D01* -X300577Y36337D01* -X300680Y36384D01* -X300786Y36424D01* -X300896Y36454D01* -X301013Y36476D01* -X301137Y36490D01* -X301266Y36494D01* -X301361Y36490D01* -X301452Y36483D01* -X301540Y36472D01* -X301628Y36454D01* -X301709Y36431D01* -X301789Y36406D01* -X301870Y36373D01* -X301943Y36337D01* -X302013Y36296D01* -X302082Y36252D01* -X302148Y36201D01* -X302211Y36146D01* -X302269Y36091D01* -X302324Y36029D01* -X302375Y35959D01* -X302423Y35890D01* -X302470Y35813D01* -X302515Y35736D01* -X302555Y35652D01* -X302591Y35564D01* -X302628Y35472D01* -X302661Y35377D01* -X302694Y35278D01* -X302723Y35176D01* -X302745Y35066D01* -X302767Y34945D01* -X302789Y34817D01* -X302804Y34681D01* -X302815Y34535D01* -X302822Y34377D01* -X302830Y34213D01* -Y34040D01* -X302826Y33835D01* -X302819Y33637D01* -X302804Y33451D01* -X302785Y33275D01* -X302763Y33110D01* -X302730Y32956D01* -X302698Y32810D01* -X302657Y32674D01* -X302609Y32550D01* -X302558Y32429D01* -X302500Y32319D01* -X302437Y32213D01* -X302372Y32118D01* -X302298Y32030D01* -X302221Y31946D01* -X302137Y31872D01* -X302046Y31806D01* -X301954Y31748D01* -X301852Y31700D01* -X301745Y31660D01* -X301635Y31631D01* -X301515Y31609D01* -X301394Y31594D01* -X301266Y31590D01* -X301178D01* -X301094Y31598D01* -X301013Y31609D01* -X300936Y31620D01* -X300859Y31638D01* -X300786Y31660D01* -X300713Y31685D01* -X300643Y31715D01* -X300577Y31748D01* -X300511Y31784D01* -X300449Y31825D01* -X300391Y31869D01* -X300332Y31916D01* -X300277Y31971D01* -X300226Y32026D01* -X300174Y32085D01* -X300116Y32165D01* -X300061Y32250D01* -X300013Y32337D01* -X299966Y32433D01* -X299922Y32535D01* -X299885Y32641D01* -X299848Y32755D01* -X299815Y32876D01* -X299790Y33000D01* -X299764Y33132D01* -X299746Y33268D01* -X299728Y33410D01* -X299717Y33561D01* -X299706Y33714D01* -X299702Y33876D01* -X299698Y34040D01* -X300306D02* -Y33894D01* -X300310Y33755D01* -X300317Y33623D01* -X300324Y33498D01* -X300332Y33378D01* -X300346Y33264D01* -X300357Y33154D01* -X300376Y33055D01* -X300394Y32956D01* -X300416Y32869D01* -X300438Y32784D01* -X300460Y32707D01* -X300489Y32638D01* -X300519Y32576D01* -X300548Y32517D01* -X300581Y32466D01* -X300654Y32374D01* -X300727Y32293D01* -X300808Y32228D01* -X300892Y32172D01* -X300976Y32129D01* -X301068Y32099D01* -X301163Y32081D01* -X301266Y32074D01* -X301365Y32081D01* -X301460Y32099D01* -X301551Y32129D01* -X301635Y32172D01* -X301720Y32228D01* -X301800Y32293D01* -X301874Y32374D01* -X301947Y32466D01* -X301980Y32517D01* -X302009Y32576D01* -X302038Y32641D01* -X302068Y32711D01* -X302090Y32788D01* -X302115Y32872D01* -X302133Y32960D01* -X302152Y33055D01* -X302170Y33158D01* -X302181Y33264D01* -X302196Y33378D01* -X302203Y33498D01* -X302211Y33623D01* -X302218Y33758D01* -X302221Y33894D01* -Y34040D01* -Y34187D01* -X302218Y34326D01* -X302211Y34458D01* -X302203Y34582D01* -X302196Y34703D01* -X302181Y34817D01* -X302170Y34926D01* -X302152Y35025D01* -X302133Y35124D01* -X302115Y35212D01* -X302090Y35296D01* -X302068Y35373D01* -X302038Y35443D01* -X302009Y35505D01* -X301980Y35564D01* -X301947Y35615D01* -X301874Y35707D01* -X301800Y35787D01* -X301720Y35853D01* -X301635Y35908D01* -X301548Y35952D01* -X301456Y35981D01* -X301357Y36000D01* -X301258Y36007D01* -X301159Y36000D01* -X301064Y35985D01* -X300976Y35959D01* -X300892Y35919D01* -X300815Y35871D01* -X300742Y35813D01* -X300672Y35743D01* -X300610Y35663D01* -X300574Y35604D01* -X300537Y35542D01* -X300507Y35472D01* -X300478Y35395D01* -X300449Y35315D01* -X300423Y35227D01* -X300401Y35135D01* -X300383Y35036D01* -X300365Y34934D01* -X300350Y34824D01* -X300335Y34707D01* -X300324Y34586D01* -X300317Y34458D01* -X300310Y34326D01* -X300306Y34187D01* -Y34040D01* -X303430D02* -X303433Y34249D01* -X303441Y34447D01* -X303456Y34633D01* -X303474Y34809D01* -X303500Y34974D01* -X303529Y35131D01* -X303565Y35278D01* -X303606Y35413D01* -X303653Y35538D01* -X303705Y35655D01* -X303759Y35769D01* -X303822Y35871D01* -X303891Y35970D01* -X303965Y36058D01* -X304041Y36139D01* -X304126Y36212D01* -X304214Y36278D01* -X304309Y36337D01* -X304411Y36384D01* -X304518Y36424D01* -X304628Y36454D01* -X304744Y36476D01* -X304869Y36490D01* -X304997Y36494D01* -X305093Y36490D01* -X305184Y36483D01* -X305272Y36472D01* -X305360Y36454D01* -X305441Y36431D01* -X305521Y36406D01* -X305602Y36373D01* -X305675Y36337D01* -X305744Y36296D01* -X305814Y36252D01* -X305880Y36201D01* -X305942Y36146D01* -X306001Y36091D01* -X306056Y36029D01* -X306107Y35959D01* -X306155Y35890D01* -X306202Y35813D01* -X306246Y35736D01* -X306286Y35652D01* -X306323Y35564D01* -X306359Y35472D01* -X306393Y35377D01* -X306426Y35278D01* -X306455Y35176D01* -X306477Y35066D01* -X306499Y34945D01* -X306521Y34817D01* -X306535Y34681D01* -X306546Y34535D01* -X306554Y34377D01* -X306561Y34213D01* -Y34040D01* -X306557Y33835D01* -X306550Y33637D01* -X306535Y33451D01* -X306517Y33275D01* -X306495Y33110D01* -X306462Y32956D01* -X306429Y32810D01* -X306389Y32674D01* -X306341Y32550D01* -X306290Y32429D01* -X306231Y32319D01* -X306169Y32213D01* -X306103Y32118D01* -X306030Y32030D01* -X305953Y31946D01* -X305869Y31872D01* -X305777Y31806D01* -X305686Y31748D01* -X305583Y31700D01* -X305477Y31660D01* -X305367Y31631D01* -X305246Y31609D01* -X305126Y31594D01* -X304997Y31590D01* -X304909D01* -X304825Y31598D01* -X304744Y31609D01* -X304668Y31620D01* -X304591Y31638D01* -X304518Y31660D01* -X304444Y31685D01* -X304375Y31715D01* -X304309Y31748D01* -X304243Y31784D01* -X304181Y31825D01* -X304122Y31869D01* -X304063Y31916D01* -X304009Y31971D01* -X303957Y32026D01* -X303906Y32085D01* -X303847Y32165D01* -X303793Y32250D01* -X303745Y32337D01* -X303697Y32433D01* -X303653Y32535D01* -X303617Y32641D01* -X303580Y32755D01* -X303547Y32876D01* -X303522Y33000D01* -X303496Y33132D01* -X303478Y33268D01* -X303459Y33410D01* -X303448Y33561D01* -X303437Y33714D01* -X303433Y33876D01* -X303430Y34040D01* -X304038D02* -Y33894D01* -X304041Y33755D01* -X304049Y33623D01* -X304056Y33498D01* -X304063Y33378D01* -X304078Y33264D01* -X304089Y33154D01* -X304107Y33055D01* -X304126Y32956D01* -X304148Y32869D01* -X304170Y32784D01* -X304192Y32707D01* -X304221Y32638D01* -X304250Y32576D01* -X304280Y32517D01* -X304313Y32466D01* -X304386Y32374D01* -X304459Y32293D01* -X304539Y32228D01* -X304624Y32172D01* -X304708Y32129D01* -X304800Y32099D01* -X304895Y32081D01* -X304997Y32074D01* -X305096Y32081D01* -X305191Y32099D01* -X305283Y32129D01* -X305367Y32172D01* -X305452Y32228D01* -X305532Y32293D01* -X305605Y32374D01* -X305678Y32466D01* -X305711Y32517D01* -X305741Y32576D01* -X305770Y32641D01* -X305799Y32711D01* -X305821Y32788D01* -X305847Y32872D01* -X305865Y32960D01* -X305883Y33055D01* -X305902Y33158D01* -X305913Y33264D01* -X305928Y33378D01* -X305935Y33498D01* -X305942Y33623D01* -X305950Y33758D01* -X305953Y33894D01* -Y34040D01* -Y34187D01* -X305950Y34326D01* -X305942Y34458D01* -X305935Y34582D01* -X305928Y34703D01* -X305913Y34817D01* -X305902Y34926D01* -X305883Y35025D01* -X305865Y35124D01* -X305847Y35212D01* -X305821Y35296D01* -X305799Y35373D01* -X305770Y35443D01* -X305741Y35505D01* -X305711Y35564D01* -X305678Y35615D01* -X305605Y35707D01* -X305532Y35787D01* -X305452Y35853D01* -X305367Y35908D01* -X305279Y35952D01* -X305188Y35981D01* -X305089Y36000D01* -X304990Y36007D01* -X304891Y36000D01* -X304796Y35985D01* -X304708Y35959D01* -X304624Y35919D01* -X304547Y35871D01* -X304474Y35813D01* -X304404Y35743D01* -X304342Y35663D01* -X304305Y35604D01* -X304269Y35542D01* -X304239Y35472D01* -X304210Y35395D01* -X304181Y35315D01* -X304155Y35227D01* -X304133Y35135D01* -X304115Y35036D01* -X304096Y34934D01* -X304082Y34824D01* -X304067Y34707D01* -X304056Y34586D01* -X304049Y34458D01* -X304041Y34326D01* -X304038Y34187D01* -Y34040D01* -X307202Y35846D02* -Y36413D01* -X310311D01* -Y35956D01* -X310198Y35828D01* -X310084Y35688D01* -X309967Y35542D01* -X309853Y35384D01* -X309740Y35219D01* -X309626Y35040D01* -X309517Y34853D01* -X309403Y34656D01* -X309293Y34454D01* -X309191Y34249D01* -X309092Y34044D01* -X309004Y33835D01* -X308919Y33626D01* -X308843Y33414D01* -X308769Y33206D01* -X308707Y32993D01* -X308663Y32839D01* -X308626Y32681D01* -X308590Y32524D01* -X308561Y32359D01* -X308535Y32191D01* -X308513Y32022D01* -X308494Y31847D01* -X308480Y31671D01* -X307872D01* -X307880Y31817D01* -X307891Y31968D01* -X307909Y32129D01* -X307934Y32297D01* -X307964Y32473D01* -X308000Y32652D01* -X308044Y32843D01* -X308095Y33041D01* -X308150Y33238D01* -X308213Y33440D01* -X308282Y33634D01* -X308356Y33828D01* -X308432Y34022D01* -X308520Y34213D01* -X308608Y34403D01* -X308707Y34590D01* -X308806Y34773D01* -X308908Y34945D01* -X309011Y35113D01* -X309117Y35274D01* -X309223Y35428D01* -X309333Y35575D01* -X309443Y35714D01* -X309553Y35846D01* -X307202D01* -X314420Y32206D02* -X314310Y32088D01* -X314193Y31982D01* -X314072Y31891D01* -X313944Y31810D01* -X313878Y31774D01* -X313812Y31744D01* -X313746Y31719D01* -X313680Y31696D01* -X313614Y31682D01* -X313548Y31671D01* -X313482Y31663D01* -X313417Y31660D01* -X313343Y31663D01* -X313270Y31671D01* -X313200Y31682D01* -X313127Y31704D01* -X313057Y31726D01* -X312988Y31755D01* -X312919Y31792D01* -X312849Y31828D01* -X312783Y31876D01* -X312717Y31927D01* -X312658Y31982D01* -X312600Y32044D01* -X312545Y32114D01* -X312494Y32187D01* -X312446Y32268D01* -X312402Y32356D01* -X312362Y32444D01* -X312325Y32535D01* -X312296Y32630D01* -X312274Y32726D01* -X312256Y32824D01* -X312241Y32923D01* -X312233Y33026D01* -X312230Y33132D01* -X312233Y33260D01* -X312248Y33392D01* -X312267Y33524D01* -X312296Y33652D01* -X312336Y33784D01* -X312380Y33916D01* -X312435Y34044D01* -X312497Y34176D01* -X312567Y34300D01* -X312640Y34421D01* -X312717Y34531D01* -X312798Y34633D01* -X312882Y34729D01* -X312970Y34813D01* -X313061Y34890D01* -X313160Y34959D01* -X313259Y35022D01* -X313358Y35077D01* -X313453Y35120D01* -X313552Y35157D01* -X313647Y35187D01* -X313743Y35205D01* -X313838Y35219D01* -X313929Y35223D01* -X313999Y35219D01* -X314072Y35212D01* -X314138Y35201D01* -X314207Y35187D01* -X314277Y35165D01* -X314343Y35139D01* -X314409Y35109D01* -X314475Y35073D01* -X314537Y35033D01* -X314599Y34989D01* -X314658Y34941D01* -X314713Y34886D01* -X314768Y34828D01* -X314819Y34762D01* -X314870Y34692D01* -X314918Y34619D01* -X315031Y35128D01* -X315617D01* -X315145Y32927D01* -X315123Y32817D01* -X315101Y32722D01* -X315087Y32641D01* -X315072Y32568D01* -X315061Y32513D01* -X315054Y32469D01* -X315046Y32436D01* -Y32418D01* -X315050Y32374D01* -X315065Y32337D01* -X315083Y32301D01* -X315112Y32264D01* -X315149Y32239D01* -X315189Y32217D01* -X315229Y32206D01* -X315277Y32202D01* -X315321Y32206D01* -X315369Y32213D01* -X315423Y32231D01* -X315478Y32253D01* -X315537Y32279D01* -X315599Y32315D01* -X315665Y32356D01* -X315731Y32403D01* -X315822Y32469D01* -X315910Y32543D01* -X315991Y32623D01* -X316068Y32707D01* -X316141Y32799D01* -X316207Y32894D01* -X316269Y32996D01* -X316324Y33106D01* -X316376Y33216D01* -X316419Y33326D01* -X316460Y33440D01* -X316489Y33553D01* -X316515Y33667D01* -X316529Y33780D01* -X316540Y33898D01* -X316544Y34015D01* -X316540Y34150D01* -X316526Y34286D01* -X316504Y34414D01* -X316474Y34546D01* -X316434Y34670D01* -X316387Y34794D01* -X316328Y34919D01* -X316262Y35036D01* -X316189Y35154D01* -X316108Y35263D01* -X316013Y35366D01* -X315914Y35465D01* -X315804Y35556D01* -X315687Y35644D01* -X315563Y35725D01* -X315427Y35798D01* -X315288Y35864D01* -X315141Y35922D01* -X314995Y35970D01* -X314841Y36011D01* -X314687Y36043D01* -X314530Y36065D01* -X314365Y36080D01* -X314200Y36084D01* -X314010Y36076D01* -X313823Y36062D01* -X313644Y36032D01* -X313464Y35992D01* -X313292Y35944D01* -X313124Y35882D01* -X312959Y35809D01* -X312798Y35725D01* -X312644Y35630D01* -X312497Y35527D01* -X312362Y35410D01* -X312233Y35289D01* -X312117Y35154D01* -X312007Y35011D01* -X311904Y34857D01* -X311813Y34696D01* -X311732Y34527D01* -X311662Y34355D01* -X311600Y34180D01* -X311552Y34000D01* -X311512Y33820D01* -X311487Y33634D01* -X311472Y33447D01* -X311465Y33257D01* -X311472Y33063D01* -X311487Y32872D01* -X311512Y32685D01* -X311552Y32509D01* -X311600Y32341D01* -X311662Y32180D01* -X311732Y32022D01* -X311813Y31876D01* -X311908Y31733D01* -X312007Y31605D01* -X312120Y31480D01* -X312241Y31370D01* -X312373Y31268D01* -X312512Y31176D01* -X312662Y31092D01* -X312823Y31019D01* -X312992Y30953D01* -X313164Y30894D01* -X313340Y30850D01* -X313519Y30810D01* -X313706Y30781D01* -X313896Y30759D01* -X314090Y30744D01* -X314288Y30741D01* -X314497Y30744D01* -X314698Y30759D01* -X314893Y30781D01* -X315076Y30814D01* -X315251Y30854D01* -X315420Y30902D01* -X315577Y30961D01* -X315727Y31030D01* -X315867Y31103D01* -X315998Y31184D01* -X316119Y31265D01* -X316233Y31349D01* -X316339Y31440D01* -X316434Y31535D01* -X316519Y31631D01* -X316595Y31733D01* -X317189D01* -X317144Y31645D01* -X317090Y31561D01* -X317031Y31473D01* -X316961Y31385D01* -X316885Y31297D01* -X316804Y31209D01* -X316713Y31122D01* -X316613Y31030D01* -X316511Y30942D01* -X316401Y30861D01* -X316287Y30785D01* -X316170Y30711D01* -X316046Y30642D01* -X315918Y30580D01* -X315786Y30521D01* -X315647Y30466D01* -X315504Y30415D01* -X315354Y30374D01* -X315196Y30338D01* -X315031Y30309D01* -X314859Y30287D01* -X314680Y30272D01* -X314493Y30261D01* -X314299Y30257D01* -X314116Y30261D01* -X313940Y30269D01* -X313768Y30283D01* -X313600Y30305D01* -X313431Y30331D01* -X313270Y30363D01* -X313113Y30400D01* -X312955Y30444D01* -X312805Y30495D01* -X312658Y30550D01* -X312519Y30609D01* -X312387Y30678D01* -X312259Y30752D01* -X312135Y30829D01* -X312021Y30917D01* -X311908Y31004D01* -X311805Y31103D01* -X311706Y31202D01* -X311615Y31305D01* -X311531Y31411D01* -X311450Y31521D01* -X311380Y31634D01* -X311315Y31748D01* -X311256Y31869D01* -X311194Y32026D01* -X311135Y32187D01* -X311087Y32348D01* -X311051Y32513D01* -X311022Y32681D01* -X311000Y32854D01* -X310985Y33030D01* -X310981Y33206D01* -X310985Y33407D01* -X311003Y33601D01* -X311029Y33795D01* -X311062Y33989D01* -X311109Y34176D01* -X311164Y34363D01* -X311234Y34549D01* -X311307Y34732D01* -X311413Y34945D01* -X311531Y35150D01* -X311655Y35340D01* -X311794Y35516D01* -X311941Y35677D01* -X312098Y35828D01* -X312267Y35967D01* -X312446Y36091D01* -X312537Y36150D01* -X312633Y36201D01* -X312731Y36252D01* -X312831Y36296D01* -X312933Y36340D01* -X313039Y36380D01* -X313149Y36413D01* -X313259Y36446D01* -X313372Y36472D01* -X313486Y36498D01* -X313603Y36516D01* -X313724Y36534D01* -X313845Y36545D01* -X313973Y36556D01* -X314098Y36560D01* -X314230Y36563D01* -X314431Y36560D01* -X314625Y36541D01* -X314815Y36516D01* -X314998Y36479D01* -X315181Y36431D01* -X315354Y36377D01* -X315526Y36307D01* -X315687Y36230D01* -X315848Y36143D01* -X315994Y36043D01* -X316137Y35933D01* -X316269Y35817D01* -X316390Y35688D01* -X316507Y35549D01* -X316613Y35399D01* -X316709Y35238D01* -X316786Y35095D01* -X316848Y34948D01* -X316903Y34798D01* -X316947Y34648D01* -X316983Y34491D01* -X317009Y34333D01* -X317024Y34172D01* -X317027Y34007D01* -X317024Y33887D01* -X317017Y33773D01* -X317006Y33656D01* -X316987Y33546D01* -X316961Y33432D01* -X316932Y33322D01* -X316899Y33216D01* -X316859Y33110D01* -X316815Y33004D01* -X316767Y32901D01* -X316713Y32799D01* -X316650Y32700D01* -X316584Y32601D01* -X316515Y32506D01* -X316438Y32411D01* -X316357Y32319D01* -X316284Y32239D01* -X316207Y32162D01* -X316130Y32092D01* -X316053Y32030D01* -X315973Y31968D01* -X315896Y31916D01* -X315815Y31865D01* -X315735Y31821D01* -X315650Y31784D01* -X315570Y31748D01* -X315485Y31722D01* -X315401Y31696D01* -X315313Y31678D01* -X315229Y31667D01* -X315141Y31660D01* -X315054Y31656D01* -X314944Y31660D01* -X314848Y31674D01* -X314761Y31693D01* -X314687Y31726D01* -X314621Y31763D01* -X314567Y31810D01* -X314519Y31861D01* -X314482Y31924D01* -X314471Y31946D01* -X314464Y31971D01* -X314453Y32000D01* -X314446Y32033D01* -X314438Y32070D01* -X314431Y32110D01* -X314424Y32154D01* -X314420Y32206D01* -X312838Y33092D02* -X312842Y32982D01* -X312852Y32880D01* -X312867Y32784D01* -X312893Y32693D01* -X312922Y32608D01* -X312959Y32528D01* -X312999Y32458D01* -X313050Y32393D01* -X313105Y32334D01* -X313160Y32282D01* -X313219Y32242D01* -X313277Y32206D01* -X313340Y32176D01* -X313406Y32158D01* -X313471Y32147D01* -X313537Y32143D01* -X313629Y32151D01* -X313724Y32169D01* -X313823Y32206D01* -X313922Y32253D01* -X314024Y32315D01* -X314123Y32389D01* -X314219Y32476D01* -X314310Y32579D01* -X314357Y32634D01* -X314398Y32696D01* -X314442Y32759D01* -X314478Y32824D01* -X314552Y32971D01* -X314614Y33128D01* -X314640Y33213D01* -X314665Y33297D01* -X314683Y33381D01* -X314702Y33462D01* -X314717Y33546D01* -X314724Y33630D01* -X314731Y33714D01* -Y33798D01* -X314728Y33905D01* -X314717Y34007D01* -X314702Y34102D01* -X314676Y34194D01* -X314647Y34278D01* -X314607Y34355D01* -X314563Y34425D01* -X314511Y34491D01* -X314453Y34546D01* -X314394Y34597D01* -X314332Y34641D01* -X314266Y34674D01* -X314196Y34700D01* -X314127Y34721D01* -X314050Y34732D01* -X313973Y34736D01* -X313870Y34729D01* -X313768Y34711D01* -X313673Y34678D01* -X313578Y34630D01* -X313534Y34600D01* -X313486Y34568D01* -X313442Y34531D01* -X313398Y34491D01* -X313350Y34447D01* -X313307Y34396D01* -X313263Y34344D01* -X313219Y34286D01* -X313138Y34161D01* -X313065Y34026D01* -X312999Y33876D01* -X312944Y33711D01* -X312896Y33546D01* -X312863Y33389D01* -X312845Y33235D01* -X312838Y33092D01* -X317763Y31385D02* -X318338Y31301D01* -X318349Y31235D01* -X318364Y31176D01* -X318386Y31122D01* -X318408Y31070D01* -X318433Y31023D01* -X318467Y30982D01* -X318500Y30946D01* -X318540Y30913D01* -X318598Y30872D01* -X318661Y30840D01* -X318726Y30814D01* -X318800Y30788D01* -X318877Y30770D01* -X318961Y30759D01* -X319045Y30752D01* -X319141Y30748D01* -X319239Y30752D01* -X319331Y30759D01* -X319419Y30770D01* -X319503Y30788D01* -X319580Y30810D01* -X319650Y30840D01* -X319712Y30872D01* -X319770Y30913D01* -X319825Y30953D01* -X319873Y31001D01* -X319917Y31052D01* -X319957Y31107D01* -X319994Y31165D01* -X320023Y31231D01* -X320052Y31297D01* -X320074Y31370D01* -X320085Y31422D01* -X320093Y31484D01* -X320100Y31561D01* -X320107Y31649D01* -X320111Y31748D01* -X320115Y31861D01* -Y31986D01* -Y32125D01* -X320016Y32019D01* -X319909Y31927D01* -X319800Y31847D01* -X319682Y31784D01* -X319558Y31733D01* -X319430Y31700D01* -X319294Y31678D01* -X319151Y31671D01* -X319063Y31674D01* -X318979Y31678D01* -X318895Y31689D01* -X318815Y31704D01* -X318734Y31722D01* -X318661Y31744D01* -X318587Y31770D01* -X318514Y31799D01* -X318448Y31836D01* -X318382Y31872D01* -X318320Y31916D01* -X318258Y31960D01* -X318199Y32011D01* -X318144Y32067D01* -X318089Y32125D01* -X318042Y32187D01* -X317950Y32323D01* -X317870Y32462D01* -X317800Y32605D01* -X317745Y32759D01* -X317701Y32916D01* -X317672Y33081D01* -X317654Y33253D01* -X317646Y33432D01* -X317650Y33553D01* -X317657Y33674D01* -X317672Y33795D01* -X317694Y33908D01* -X317719Y34022D01* -X317749Y34135D01* -X317785Y34242D01* -X317830Y34352D01* -X317877Y34454D01* -X317928Y34549D01* -X317987Y34637D01* -X318049Y34721D01* -X318115Y34802D01* -X318188Y34875D01* -X318269Y34941D01* -X318349Y35000D01* -X318437Y35055D01* -X318529Y35102D01* -X318624Y35139D01* -X318723Y35172D01* -X318826Y35198D01* -X318931Y35216D01* -X319041Y35227D01* -X319155Y35230D01* -X319232Y35227D01* -X319305Y35223D01* -X319378Y35212D01* -X319448Y35198D01* -X319518Y35183D01* -X319587Y35161D01* -X319653Y35135D01* -X319715Y35106D01* -X319778Y35073D01* -X319840Y35036D01* -X319898Y34996D01* -X319957Y34948D01* -X320012Y34901D01* -X320067Y34850D01* -X320118Y34791D01* -X320169Y34732D01* -Y35154D01* -X320715D01* -Y32143D01* -Y32044D01* -Y31949D01* -X320711Y31857D01* -X320704Y31770D01* -X320700Y31682D01* -X320693Y31601D01* -X320686Y31524D01* -X320675Y31451D01* -X320664Y31381D01* -X320653Y31316D01* -X320638Y31250D01* -X320624Y31191D01* -X320605Y31136D01* -X320591Y31085D01* -X320572Y31037D01* -X320550Y30993D01* -X320506Y30909D01* -X320455Y30832D01* -X320400Y30759D01* -X320338Y30689D01* -X320269Y30624D01* -X320195Y30565D01* -X320111Y30510D01* -X320027Y30459D01* -X319935Y30411D01* -X319836Y30371D01* -X319733Y30338D01* -X319624Y30309D01* -X319514Y30290D01* -X319393Y30272D01* -X319272Y30265D01* -X319141Y30261D01* -X318990Y30265D01* -X318844Y30279D01* -X318708Y30301D01* -X318580Y30331D01* -X318456Y30371D01* -X318342Y30419D01* -X318236Y30477D01* -X318137Y30539D01* -X318045Y30616D01* -X317969Y30700D01* -X317903Y30792D01* -X317851Y30891D01* -X317811Y31001D01* -X317782Y31122D01* -X317767Y31250D01* -X317763Y31385D01* -X318254Y33473D02* -X318258Y33308D01* -X318272Y33154D01* -X318294Y33011D01* -X318324Y32880D01* -X318360Y32762D01* -X318408Y32652D01* -X318463Y32557D01* -X318525Y32473D01* -X318598Y32400D01* -X318672Y32334D01* -X318748Y32279D01* -X318833Y32235D01* -X318920Y32202D01* -X319012Y32176D01* -X319107Y32162D01* -X319206Y32158D01* -X319305Y32162D01* -X319404Y32176D01* -X319492Y32202D01* -X319580Y32235D01* -X319664Y32279D01* -X319741Y32334D01* -X319818Y32396D01* -X319887Y32469D01* -X319954Y32554D01* -X320008Y32649D01* -X320056Y32755D01* -X320096Y32872D01* -X320126Y33000D01* -X320148Y33143D01* -X320158Y33293D01* -X320162Y33454D01* -X320158Y33608D01* -X320144Y33755D01* -X320122Y33890D01* -X320093Y34015D01* -X320052Y34132D01* -X320005Y34234D01* -X319946Y34333D01* -X319880Y34417D01* -X319807Y34494D01* -X319730Y34560D01* -X319653Y34615D01* -X319569Y34663D01* -X319481Y34696D01* -X319389Y34721D01* -X319294Y34740D01* -X319199Y34743D01* -X319100Y34740D01* -X319009Y34721D01* -X318920Y34700D01* -X318837Y34663D01* -X318752Y34619D01* -X318675Y34564D01* -X318602Y34498D01* -X318529Y34425D01* -X318467Y34337D01* -X318412Y34245D01* -X318364Y34139D01* -X318324Y34026D01* -X318294Y33901D01* -X318272Y33769D01* -X318258Y33626D01* -X318254Y33473D01* -X321605Y31671D02* -Y35154D01* -X322132D01* -Y34663D01* -X322220Y34784D01* -X322323Y34894D01* -X322440Y34989D01* -X322568Y35073D01* -X322638Y35109D01* -X322707Y35143D01* -X322784Y35168D01* -X322857Y35190D01* -X322938Y35209D01* -X323019Y35219D01* -X323103Y35227D01* -X323187Y35230D01* -X323282Y35227D01* -X323374Y35219D01* -X323458Y35209D01* -X323539Y35190D01* -X323615Y35168D01* -X323689Y35139D01* -X323758Y35106D01* -X323820Y35069D01* -X323883Y35025D01* -X323938Y34981D01* -X323989Y34930D01* -X324033Y34875D01* -X324073Y34817D01* -X324110Y34754D01* -X324143Y34689D01* -X324172Y34619D01* -X324223Y34692D01* -X324278Y34762D01* -X324337Y34828D01* -X324396Y34886D01* -X324454Y34941D01* -X324517Y34993D01* -X324582Y35036D01* -X324648Y35077D01* -X324714Y35113D01* -X324787Y35143D01* -X324857Y35172D01* -X324934Y35194D01* -X325007Y35209D01* -X325088Y35219D01* -X325165Y35227D01* -X325249Y35230D01* -X325373Y35227D01* -X325494Y35212D01* -X325604Y35190D01* -X325707Y35157D01* -X325802Y35117D01* -X325890Y35069D01* -X325974Y35011D01* -X326047Y34945D01* -X326113Y34868D01* -X326168Y34780D01* -X326216Y34685D01* -X326256Y34579D01* -X326285Y34465D01* -X326307Y34341D01* -X326322Y34205D01* -X326326Y34059D01* -Y31671D01* -X325736D01* -Y33861D01* -Y33949D01* -X325732Y34026D01* -X325728Y34099D01* -X325721Y34165D01* -X325714Y34227D01* -X325703Y34282D01* -X325692Y34330D01* -X325677Y34374D01* -X325644Y34447D01* -X325597Y34513D01* -X325538Y34571D01* -X325469Y34622D01* -X325392Y34663D01* -X325307Y34692D01* -X325212Y34711D01* -X325117Y34718D01* -X325025Y34714D01* -X324941Y34703D01* -X324857Y34685D01* -X324780Y34656D01* -X324707Y34622D01* -X324633Y34579D01* -X324568Y34531D01* -X324506Y34472D01* -X324450Y34406D01* -X324399Y34333D01* -X324359Y34249D01* -X324322Y34157D01* -X324296Y34055D01* -X324278Y33941D01* -X324267Y33820D01* -X324264Y33693D01* -Y31671D01* -X323674D01* -Y33930D01* -X323670Y34026D01* -X323663Y34117D01* -X323652Y34198D01* -X323637Y34275D01* -X323615Y34344D01* -X323594Y34410D01* -X323564Y34469D01* -X323528Y34520D01* -X323491Y34568D01* -X323447Y34608D01* -X323396Y34641D01* -X323341Y34667D01* -X323279Y34689D01* -X323209Y34707D01* -X323136Y34714D01* -X323055Y34718D01* -X322996Y34714D01* -X322934Y34711D01* -X322876Y34700D01* -X322817Y34685D01* -X322759Y34667D01* -X322704Y34644D01* -X322649Y34619D01* -X322597Y34586D01* -X322546Y34553D01* -X322498Y34513D01* -X322455Y34472D01* -X322414Y34425D01* -X322378Y34374D01* -X322345Y34322D01* -X322315Y34264D01* -X322290Y34202D01* -X322268Y34135D01* -X322246Y34062D01* -X322231Y33981D01* -X322217Y33894D01* -X322209Y33802D01* -X322198Y33700D01* -X322194Y33590D01* -Y33476D01* -Y31671D01* -X321605D01* -X329468Y32099D02* -X329387Y32033D01* -X329306Y31971D01* -X329226Y31913D01* -X329145Y31861D01* -X329065Y31817D01* -X328988Y31774D01* -X328911Y31741D01* -X328834Y31707D01* -X328680Y31656D01* -X328523Y31623D01* -X328354Y31601D01* -X328186Y31594D01* -X328046Y31598D01* -X327915Y31612D01* -X327794Y31634D01* -X327677Y31663D01* -X327570Y31704D01* -X327475Y31752D01* -X327384Y31806D01* -X327303Y31872D01* -X327230Y31946D01* -X327168Y32022D01* -X327117Y32107D01* -X327072Y32191D01* -X327039Y32282D01* -X327014Y32381D01* -X326999Y32484D01* -X326996Y32590D01* -X327003Y32715D01* -X327025Y32832D01* -X327061Y32945D01* -X327113Y33055D01* -X327175Y33154D01* -X327244Y33246D01* -X327329Y33326D01* -X327417Y33396D01* -X327516Y33454D01* -X327618Y33506D01* -X327724Y33550D01* -X327842Y33586D01* -X327885Y33597D01* -X327941Y33612D01* -X327995Y33623D01* -X328057Y33634D01* -X328127Y33645D01* -X328200Y33656D01* -X328281Y33667D01* -X328365Y33678D01* -X328537Y33696D01* -X328698Y33722D01* -X328849Y33744D01* -X328984Y33769D01* -X329112Y33795D01* -X329226Y33820D01* -X329325Y33850D01* -X329416Y33879D01* -X329420Y33934D01* -Y33978D01* -Y34011D01* -Y34033D01* -X329416Y34121D01* -X329409Y34202D01* -X329398Y34275D01* -X329380Y34341D01* -X329354Y34403D01* -X329325Y34454D01* -X329292Y34502D01* -X329252Y34542D01* -X329193Y34590D01* -X329127Y34630D01* -X329054Y34667D01* -X328973Y34692D01* -X328885Y34714D01* -X328790Y34732D01* -X328691Y34740D01* -X328581Y34743D01* -X328482Y34740D01* -X328387Y34732D01* -X328303Y34721D01* -X328222Y34707D01* -X328149Y34685D01* -X328083Y34659D01* -X328021Y34630D01* -X327970Y34597D01* -X327922Y34557D01* -X327878Y34509D01* -X327834Y34454D01* -X327798Y34396D01* -X327761Y34326D01* -X327731Y34253D01* -X327702Y34169D01* -X327677Y34081D01* -X327098Y34157D01* -X327120Y34249D01* -X327142Y34333D01* -X327171Y34414D01* -X327201Y34491D01* -X327237Y34564D01* -X327274Y34633D01* -X327314Y34696D01* -X327358Y34754D01* -X327406Y34813D01* -X327457Y34864D01* -X327516Y34912D01* -X327578Y34956D01* -X327644Y35000D01* -X327717Y35040D01* -X327794Y35073D01* -X327878Y35106D01* -X327966Y35135D01* -X328054Y35161D01* -X328149Y35183D01* -X328244Y35198D01* -X328347Y35212D01* -X328450Y35223D01* -X328556Y35227D01* -X328665Y35230D01* -X328775Y35227D01* -X328878Y35223D01* -X328977Y35216D01* -X329072Y35205D01* -X329160Y35190D01* -X329241Y35172D01* -X329317Y35150D01* -X329391Y35124D01* -X329457Y35099D01* -X329522Y35069D01* -X329578Y35040D01* -X329632Y35007D01* -X329680Y34974D01* -X329724Y34937D01* -X329764Y34901D01* -X329801Y34861D01* -X329859Y34776D01* -X329911Y34681D01* -X329951Y34575D01* -X329984Y34458D01* -X329991Y34417D01* -X329995Y34370D01* -X330002Y34311D01* -X330006Y34249D01* -X330009Y34176D01* -X330013Y34095D01* -Y34011D01* -Y33916D01* -Y33128D01* -Y33030D01* -Y32934D01* -Y32843D01* -X330017Y32755D01* -Y32674D01* -Y32597D01* -X330020Y32524D01* -X330024Y32458D01* -Y32396D01* -X330028Y32337D01* -X330031Y32286D01* -X330035Y32235D01* -X330039Y32191D01* -X330043Y32154D01* -X330046Y32118D01* -X330050Y32088D01* -X330076Y31982D01* -X330108Y31876D01* -X330149Y31774D01* -X330200Y31671D01* -X329585D01* -X329544Y31766D01* -X329511Y31869D01* -X329486Y31978D01* -X329468Y32099D01* -X329420Y33418D02* -X329336Y33385D01* -X329241Y33356D01* -X329134Y33326D01* -X329017Y33297D01* -X328893Y33268D01* -X328757Y33242D01* -X328611Y33220D01* -X328457Y33194D01* -X328369Y33180D01* -X328288Y33169D01* -X328211Y33154D01* -X328146Y33139D01* -X328083Y33125D01* -X328028Y33110D01* -X327981Y33092D01* -X327941Y33077D01* -X327871Y33041D01* -X327809Y32996D01* -X327754Y32945D01* -X327706Y32887D01* -X327673Y32821D01* -X327648Y32751D01* -X327629Y32681D01* -X327626Y32605D01* -X327629Y32546D01* -X327637Y32491D01* -X327651Y32440D01* -X327669Y32389D01* -X327695Y32341D01* -X327724Y32297D01* -X327761Y32253D01* -X327805Y32213D01* -X327852Y32176D01* -X327904Y32143D01* -X327963Y32118D01* -X328025Y32096D01* -X328091Y32078D01* -X328164Y32067D01* -X328244Y32059D01* -X328325Y32056D01* -X328409Y32059D01* -X328493Y32063D01* -X328570Y32078D01* -X328647Y32092D01* -X328724Y32114D01* -X328794Y32140D01* -X328863Y32169D01* -X328933Y32206D01* -X328995Y32242D01* -X329057Y32286D01* -X329112Y32330D01* -X329163Y32381D01* -X329207Y32433D01* -X329252Y32491D01* -X329288Y32550D01* -X329321Y32612D01* -X329343Y32663D01* -X329365Y32722D01* -X329380Y32788D01* -X329394Y32857D01* -X329402Y32934D01* -X329409Y33019D01* -X329416Y33106D01* -Y33202D01* -X329420Y33418D01* -X330932Y35798D02* -Y36476D01* -X331522D01* -Y35798D01* -X330932D01* -Y31671D02* -Y35154D01* -X331522D01* -Y31671D01* -X330932D01* -X332405D02* -Y36476D01* -X332994D01* -Y31671D01* -X332405D01* -X334074D02* -Y32341D01* -X334744D01* -Y31671D01* -X334074D01* -X338048Y32945D02* -X338626Y32869D01* -X338597Y32722D01* -X338561Y32587D01* -X338513Y32455D01* -X338458Y32334D01* -X338392Y32220D01* -X338319Y32118D01* -X338235Y32019D01* -X338139Y31931D01* -X338041Y31854D01* -X337934Y31784D01* -X337821Y31726D01* -X337704Y31678D01* -X337579Y31642D01* -X337451Y31616D01* -X337319Y31598D01* -X337176Y31594D01* -X337004Y31601D01* -X336839Y31623D01* -X336682Y31660D01* -X336532Y31711D01* -X336393Y31777D01* -X336265Y31857D01* -X336144Y31953D01* -X336030Y32059D01* -X335928Y32183D01* -X335840Y32319D01* -X335763Y32469D01* -X335704Y32627D01* -X335656Y32802D01* -X335620Y32989D01* -X335602Y33187D01* -X335594Y33400D01* -X335598Y33539D01* -X335605Y33670D01* -X335620Y33802D01* -X335642Y33927D01* -X335667Y34048D01* -X335700Y34165D01* -X335737Y34278D01* -X335781Y34385D01* -X335832Y34487D01* -X335887Y34582D01* -X335950Y34674D01* -X336015Y34754D01* -X336092Y34831D01* -X336173Y34901D01* -X336257Y34963D01* -X336349Y35018D01* -X336448Y35069D01* -X336546Y35109D01* -X336645Y35146D01* -X336748Y35176D01* -X336854Y35201D01* -X336960Y35216D01* -X337070Y35227D01* -X337180Y35230D01* -X337319Y35227D01* -X337451Y35212D01* -X337579Y35190D01* -X337696Y35157D01* -X337810Y35117D01* -X337916Y35069D01* -X338015Y35011D01* -X338110Y34945D01* -X338194Y34868D01* -X338275Y34784D01* -X338344Y34692D01* -X338407Y34597D01* -X338458Y34491D01* -X338506Y34377D01* -X338542Y34256D01* -X338572Y34128D01* -X337996Y34040D01* -X337975Y34124D01* -X337949Y34205D01* -X337916Y34278D01* -X337883Y34348D01* -X337846Y34410D01* -X337802Y34469D01* -X337759Y34524D01* -X337707Y34568D01* -X337652Y34611D01* -X337597Y34648D01* -X337539Y34678D01* -X337476Y34703D01* -X337414Y34721D01* -X337345Y34736D01* -X337275Y34743D01* -X337206Y34747D01* -X337096Y34743D01* -X336993Y34725D01* -X336894Y34703D01* -X336799Y34667D01* -X336711Y34622D01* -X336631Y34568D01* -X336554Y34502D01* -X336480Y34428D01* -X336415Y34341D01* -X336359Y34245D01* -X336312Y34135D01* -X336272Y34015D01* -X336243Y33883D01* -X336220Y33736D01* -X336206Y33583D01* -X336202Y33414D01* -X336206Y33246D01* -X336220Y33088D01* -X336239Y32942D01* -X336268Y32810D01* -X336308Y32689D01* -X336352Y32579D01* -X336407Y32480D01* -X336469Y32396D01* -X336543Y32319D01* -X336616Y32257D01* -X336696Y32202D01* -X336781Y32158D01* -X336872Y32121D01* -X336968Y32096D01* -X337067Y32081D01* -X337172Y32078D01* -X337257Y32081D01* -X337337Y32092D01* -X337418Y32107D01* -X337491Y32129D01* -X337561Y32162D01* -X337630Y32198D01* -X337693Y32239D01* -X337751Y32290D01* -X337810Y32348D01* -X337857Y32411D01* -X337905Y32480D01* -X337942Y32561D01* -X337978Y32645D01* -X338007Y32737D01* -X338030Y32839D01* -X338048Y32945D01* -X338912Y33410D02* -X338916Y33531D01* -X338919Y33645D01* -X338930Y33758D01* -X338945Y33865D01* -X338963Y33967D01* -X338989Y34066D01* -X339015Y34161D01* -X339048Y34253D01* -X339081Y34341D01* -X339121Y34425D01* -X339165Y34506D01* -X339216Y34579D01* -X339267Y34652D01* -X339322Y34718D01* -X339385Y34784D01* -X339450Y34842D01* -X339564Y34934D01* -X339685Y35015D01* -X339813Y35080D01* -X339948Y35135D01* -X340088Y35176D01* -X340234Y35205D01* -X340384Y35223D01* -X340542Y35230D01* -X340633Y35227D01* -X340718Y35223D01* -X340802Y35212D01* -X340886Y35201D01* -X340967Y35183D01* -X341043Y35165D01* -X341120Y35139D01* -X341197Y35113D01* -X341267Y35080D01* -X341337Y35047D01* -X341406Y35007D01* -X341472Y34967D01* -X341538Y34919D01* -X341600Y34872D01* -X341659Y34817D01* -X341717Y34762D01* -X341824Y34637D01* -X341915Y34502D01* -X341992Y34355D01* -X342058Y34202D01* -X342109Y34033D01* -X342142Y33854D01* -X342164Y33663D01* -X342171Y33462D01* -X342168Y33297D01* -X342160Y33143D01* -X342142Y32996D01* -X342120Y32861D01* -X342094Y32733D01* -X342058Y32616D01* -X342018Y32506D01* -X341970Y32403D01* -X341915Y32312D01* -X341856Y32224D01* -X341794Y32140D01* -X341721Y32063D01* -X341648Y31989D01* -X341563Y31924D01* -X341476Y31861D01* -X341384Y31806D01* -X341285Y31755D01* -X341186Y31715D01* -X341084Y31678D01* -X340981Y31645D01* -X340875Y31623D01* -X340765Y31609D01* -X340655Y31598D01* -X340542Y31594D01* -X340366Y31601D01* -X340198Y31623D01* -X340113Y31638D01* -X340036Y31660D01* -X339959Y31682D01* -X339883Y31711D01* -X339809Y31741D01* -X339740Y31777D01* -X339670Y31814D01* -X339604Y31857D01* -X339542Y31902D01* -X339480Y31953D01* -X339421Y32004D01* -X339363Y32063D01* -X339256Y32187D01* -X339165Y32323D01* -X339088Y32473D01* -X339026Y32634D01* -X338974Y32810D01* -X338941Y32996D01* -X338919Y33198D01* -X338912Y33410D01* -X339520D02* -X339524Y33249D01* -X339538Y33099D01* -X339560Y32956D01* -X339593Y32828D01* -X339633Y32707D01* -X339685Y32597D01* -X339743Y32498D01* -X339809Y32411D01* -X339886Y32330D01* -X339967Y32264D01* -X340051Y32206D01* -X340139Y32162D01* -X340234Y32125D01* -X340333Y32099D01* -X340435Y32081D01* -X340542Y32078D01* -X340652Y32081D01* -X340754Y32099D01* -X340853Y32125D01* -X340944Y32162D01* -X341032Y32209D01* -X341117Y32264D01* -X341197Y32334D01* -X341274Y32411D01* -X341340Y32502D01* -X341399Y32601D01* -X341450Y32711D01* -X341490Y32832D01* -X341523Y32967D01* -X341545Y33110D01* -X341560Y33264D01* -X341563Y33432D01* -X341560Y33590D01* -X341545Y33736D01* -X341523Y33872D01* -X341490Y34000D01* -X341450Y34117D01* -X341399Y34223D01* -X341340Y34322D01* -X341270Y34410D01* -X341197Y34487D01* -X341117Y34557D01* -X341032Y34611D01* -X340944Y34659D01* -X340849Y34696D01* -X340750Y34721D01* -X340652Y34740D01* -X340542Y34743D01* -X340435Y34740D01* -X340333Y34721D01* -X340234Y34696D01* -X340139Y34659D01* -X340051Y34615D01* -X339967Y34557D01* -X339886Y34491D01* -X339809Y34410D01* -X339743Y34322D01* -X339685Y34223D01* -X339633Y34117D01* -X339593Y33996D01* -X339560Y33865D01* -X339538Y33725D01* -X339524Y33575D01* -X339520Y33410D01* -X342863Y31671D02* -Y35154D01* -X343391D01* -Y34663D01* -X343479Y34784D01* -X343581Y34894D01* -X343698Y34989D01* -X343827Y35073D01* -X343896Y35109D01* -X343966Y35143D01* -X344043Y35168D01* -X344116Y35190D01* -X344196Y35209D01* -X344277Y35219D01* -X344361Y35227D01* -X344446Y35230D01* -X344541Y35227D01* -X344632Y35219D01* -X344717Y35209D01* -X344797Y35190D01* -X344874Y35168D01* -X344947Y35139D01* -X345017Y35106D01* -X345079Y35069D01* -X345141Y35025D01* -X345196Y34981D01* -X345248Y34930D01* -X345291Y34875D01* -X345332Y34817D01* -X345369Y34754D01* -X345401Y34689D01* -X345431Y34619D01* -X345482Y34692D01* -X345537Y34762D01* -X345595Y34828D01* -X345654Y34886D01* -X345713Y34941D01* -X345775Y34993D01* -X345841Y35036D01* -X345907Y35077D01* -X345973Y35113D01* -X346046Y35143D01* -X346115Y35172D01* -X346193Y35194D01* -X346266Y35209D01* -X346346Y35219D01* -X346423Y35227D01* -X346507Y35230D01* -X346632Y35227D01* -X346753Y35212D01* -X346863Y35190D01* -X346965Y35157D01* -X347060Y35117D01* -X347148Y35069D01* -X347232Y35011D01* -X347306Y34945D01* -X347372Y34868D01* -X347426Y34780D01* -X347474Y34685D01* -X347515Y34579D01* -X347544Y34465D01* -X347566Y34341D01* -X347580Y34205D01* -X347584Y34059D01* -Y31671D01* -X346994D01* -Y33861D01* -Y33949D01* -X346991Y34026D01* -X346987Y34099D01* -X346980Y34165D01* -X346972Y34227D01* -X346961Y34282D01* -X346950Y34330D01* -X346936Y34374D01* -X346903Y34447D01* -X346855Y34513D01* -X346796Y34571D01* -X346727Y34622D01* -X346650Y34663D01* -X346566Y34692D01* -X346471Y34711D01* -X346376Y34718D01* -X346284Y34714D01* -X346200Y34703D01* -X346115Y34685D01* -X346039Y34656D01* -X345965Y34622D01* -X345892Y34579D01* -X345826Y34531D01* -X345764Y34472D01* -X345709Y34406D01* -X345658Y34333D01* -X345617Y34249D01* -X345581Y34157D01* -X345555Y34055D01* -X345537Y33941D01* -X345526Y33820D01* -X345522Y33693D01* -Y31671D01* -X344933D01* -Y33930D01* -X344929Y34026D01* -X344922Y34117D01* -X344911Y34198D01* -X344896Y34275D01* -X344874Y34344D01* -X344852Y34410D01* -X344823Y34469D01* -X344786Y34520D01* -X344750Y34568D01* -X344706Y34608D01* -X344654Y34641D01* -X344599Y34667D01* -X344537Y34689D01* -X344468Y34707D01* -X344394Y34714D01* -X344314Y34718D01* -X344255Y34714D01* -X344193Y34711D01* -X344134Y34700D01* -X344076Y34685D01* -X344017Y34667D01* -X343962Y34644D01* -X343907Y34619D01* -X343856Y34586D01* -X343805Y34553D01* -X343757Y34513D01* -X343713Y34472D01* -X343673Y34425D01* -X343636Y34374D01* -X343603Y34322D01* -X343574Y34264D01* -X343548Y34202D01* -X343526Y34135D01* -X343504Y34062D01* -X343490Y33981D01* -X343475Y33894D01* -X343468Y33802D01* -X343457Y33700D01* -X343453Y33590D01* -Y33476D01* -Y31671D01* -X342863D01* -X313367Y30344D02* -X315222D01* -X318540D02* -X319752D01* -X312979Y30437D02* -X315567D01* -X318308D02* -X319986D01* -X312710Y30531D02* -X315809D01* -X318150D02* -X320143D01* -X312489Y30625D02* -X316011D01* -X318037D02* -X320269D01* -X312317Y30719D02* -X316182D01* -X317956D02* -X320364D01* -X312161Y30812D02* -X313510D01* -X315069D02* -X316328D01* -X317892D02* -X318726D01* -X319585D02* -X320440D01* -X312035Y30906D02* -X313130D01* -X315430D02* -X316462D01* -X317846D02* -X318550D01* -X319760D02* -X320504D01* -X311914Y31000D02* -X312873D01* -X315661D02* -X316578D01* -X317811D02* -X318452D01* -X319872D02* -X320554D01* -X311815Y31093D02* -X312662D01* -X315848D02* -X316682D01* -X317789D02* -X318398D01* -X319947D02* -X320593D01* -X311721Y31187D02* -X312496D01* -X316003D02* -X316781D01* -X317774D02* -X318361D01* -X320003D02* -X320622D01* -X311636Y31281D02* -X312357D01* -X316141D02* -X316869D01* -X317766D02* -X318342D01* -X320045D02* -X320645D01* -X311559Y31374D02* -X312237D01* -X316263D02* -X316952D01* -X317764D02* -X317839D01* -X320075D02* -X320663D01* -X311489Y31468D02* -X312133D01* -X316367D02* -X317027D01* -X320091D02* -X320677D01* -X311425Y31562D02* -X312046D01* -X316457D02* -X317090D01* -X320100D02* -X320689D01* -X261620Y31656D02* -X262545D01* -X264563D02* -X265534D01* -X272626D02* -X273430D01* -X276159D02* -X277120D01* -X279723D02* -X280561D01* -X283580D02* -X284392D01* -X289618D02* -X290637D01* -X292911D02* -X293883D01* -X296884D02* -X297721D01* -X300800D02* -X301729D01* -X304532D02* -X305461D01* -X311368D02* -X311968D01* -X315054D02* -X315078D01* -X316537D02* -X317150D01* -X320107D02* -X320698D01* -X327709D02* -X328680D01* -X336700D02* -X337626D01* -X340051D02* -X341013D01* -X261371Y31749D02* -X262785D01* -X264334D02* -X265785D01* -X266406D02* -X267015D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272049D01* -X272419D02* -X273657D01* -X275900D02* -X277378D01* -X279490D02* -X280784D01* -X281248D02* -X281776D01* -X283350D02* -X284598D01* -X284962D02* -X285507D01* -X286427D02* -X287017D01* -X289360D02* -X290896D01* -X292683D02* -X294133D01* -X294754D02* -X295363D01* -X296651D02* -X297944D01* -X298409D02* -X298937D01* -X300574D02* -X301954D01* -X304306D02* -X305686D01* -X307876D02* -X308486D01* -X311314D02* -X311897D01* -X313002D02* -X313824D01* -X314645D02* -X315570D01* -X318646D02* -X319597D01* -X320111D02* -X320703D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327480D02* -X328931D01* -X329552D02* -X330161D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X336452D02* -X337866D01* -X339793D02* -X341270D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X261207Y31843D02* -X262943D01* -X264194D02* -X265966D01* -X266374D02* -X266976D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272049D01* -X272286D02* -X273811D01* -X275733D02* -X277552D01* -X279337D02* -X280928D01* -X281248D02* -X281776D01* -X283196D02* -X284728D01* -X284962D02* -X285507D01* -X286427D02* -X287017D01* -X289186D02* -X291057D01* -X292542D02* -X294314D01* -X294722D02* -X295324D01* -X296498D02* -X298089D01* -X298409D02* -X298937D01* -X300425D02* -X302096D01* -X304156D02* -X305828D01* -X307881D02* -X308494D01* -X311269D02* -X311835D01* -X312829D02* -X313996D01* -X314536D02* -X315775D01* -X318435D02* -X319792D01* -X320114D02* -X320710D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327339D02* -X329111D01* -X329520D02* -X330121D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X336288D02* -X338024D01* -X339626D02* -X341445D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X261083Y31937D02* -X263065D01* -X264093D02* -X266113D01* -X266350D02* -X266944D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272049D01* -X272187D02* -X273929D01* -X275607D02* -X277687D01* -X279233D02* -X281039D01* -X281248D02* -X281776D01* -X283073D02* -X284828D01* -X284962D02* -X285507D01* -X286427D02* -X287017D01* -X289056D02* -X291181D01* -X292442D02* -X294461D01* -X294698D02* -X295292D01* -X296394D02* -X298200D01* -X298409D02* -X298937D01* -X300311D02* -X302211D01* -X304043D02* -X305943D01* -X307888D02* -X308504D01* -X311229D02* -X311779D01* -X312707D02* -X314133D01* -X314476D02* -X315926D01* -X318291D02* -X319920D01* -X320115D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327239D02* -X329259D01* -X329496D02* -X330090D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X336164D02* -X338145D01* -X339500D02* -X341580D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260980Y32030D02* -X263164D01* -X264017D02* -X266237D01* -X266332D02* -X266918D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272049D01* -X272105D02* -X274031D01* -X275502D02* -X277796D01* -X279158D02* -X281128D01* -X281248D02* -X281776D01* -X282974D02* -X284905D01* -X284962D02* -X285507D01* -X286427D02* -X287017D01* -X288952D02* -X291282D01* -X292366D02* -X294586D01* -X294681D02* -X295267D01* -X296319D02* -X298288D01* -X298409D02* -X298937D01* -X300222D02* -X302298D01* -X303953D02* -X306030D01* -X307898D02* -X308514D01* -X311192D02* -X311728D01* -X312613D02* -X314246D01* -X314446D02* -X316053D01* -X318180D02* -X320026D01* -X320115D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327163D02* -X329383D01* -X329478D02* -X330064D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X336061D02* -X338244D01* -X339395D02* -X341689D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260896Y32124D02* -X261785D01* -X262395D02* -X263243D01* -X263962D02* -X264802D01* -X265605D02* -X266900D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272686D01* -X273237D02* -X274113D01* -X275417D02* -X276341D01* -X276958D02* -X277886D01* -X279103D02* -X280066D01* -X280469D02* -X281204D01* -X281248D02* -X281776D01* -X282892D02* -X283772D01* -X284324D02* -X285507D01* -X286427D02* -X287017D01* -X288867D02* -X289817D01* -X290441D02* -X291365D01* -X292310D02* -X293150D01* -X293954D02* -X295248D01* -X296263D02* -X297226D01* -X297630D02* -X298365D01* -X298409D02* -X298937D01* -X300146D02* -X300991D01* -X301537D02* -X302376D01* -X303877D02* -X304722D01* -X305269D02* -X306107D01* -X307908D02* -X308526D01* -X311158D02* -X311687D01* -X312538D02* -X314344D01* -X314429D02* -X316165D01* -X318090D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327107D02* -X327948D01* -X328751D02* -X330045D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X335976D02* -X336865D01* -X337476D02* -X338323D01* -X339310D02* -X340234D01* -X340851D02* -X341779D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260825Y32218D02* -X261593D01* -X262580D02* -X263310D01* -X263917D02* -X264654D01* -X265808D02* -X266891D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272503D01* -X273419D02* -X274186D01* -X275343D02* -X276141D01* -X277153D02* -X277959D01* -X279058D02* -X279844D01* -X280724D02* -X281776D01* -X282822D02* -X283590D01* -X284504D02* -X285507D01* -X286427D02* -X287017D01* -X288794D02* -X289607D01* -X290640D02* -X291437D01* -X292265D02* -X293002D01* -X294156D02* -X295239D01* -X296219D02* -X297005D01* -X297885D02* -X298937D01* -X300081D02* -X300823D01* -X301705D02* -X302440D01* -X303813D02* -X304554D01* -X305437D02* -X306172D01* -X307922D02* -X308539D01* -X311126D02* -X311648D01* -X312476D02* -X313258D01* -X313848D02* -X315189D01* -X315383D02* -X316263D01* -X318021D02* -X318879D01* -X319534D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327063D02* -X327800D01* -X328954D02* -X330037D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X335906D02* -X336673D01* -X337660D02* -X338391D01* -X339236D02* -X340033D01* -X341046D02* -X341852D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260764Y32311D02* -X261471D01* -X262692D02* -X263365D01* -X263886D02* -X264569D01* -X265943D02* -X266884D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272389D01* -X273536D02* -X274246D01* -X275280D02* -X276016D01* -X277278D02* -X278022D01* -X279026D02* -X279733D01* -X280867D02* -X281776D01* -X282761D02* -X283474D01* -X284624D02* -X285507D01* -X286427D02* -X287017D01* -X288731D02* -X289477D01* -X290759D02* -X291494D01* -X292235D02* -X292918D01* -X294292D02* -X295232D01* -X296187D02* -X296894D01* -X298028D02* -X298937D01* -X300027D02* -X300711D01* -X301817D02* -X302495D01* -X303759D02* -X304443D01* -X305548D02* -X306227D01* -X307937D02* -X308553D01* -X311098D02* -X311611D01* -X312424D02* -X313129D01* -X314018D02* -X315078D01* -X315593D02* -X316350D01* -X317958D02* -X318703D01* -X319710D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327032D02* -X327715D01* -X329089D02* -X330030D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X334074D02* -X334744D01* -X335844D02* -X336552D01* -X337773D02* -X338445D01* -X339173D02* -X339909D01* -X341171D02* -X341915D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260715Y32405D02* -X261382D01* -X262772D02* -X263410D01* -X263865D02* -X264518D01* -X266038D02* -X266878D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272302D01* -X273624D02* -X274299D01* -X275230D02* -X275922D01* -X277376D02* -X278078D01* -X279002D02* -X279662D01* -X280964D02* -X281776D01* -X282710D02* -X283382D01* -X284712D02* -X285507D01* -X286427D02* -X287017D01* -X288680D02* -X289383D01* -X290842D02* -X291543D01* -X292213D02* -X292866D01* -X294387D02* -X295227D01* -X296163D02* -X296823D01* -X298124D02* -X298937D01* -X299980D02* -X300629D01* -X301898D02* -X302546D01* -X303711D02* -X304361D01* -X305630D02* -X306278D01* -X307952D02* -X308569D01* -X311075D02* -X311582D01* -X312380D02* -X313041D01* -X314141D02* -X315047D01* -X315734D02* -X316433D01* -X317902D02* -X318593D01* -X319826D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327010D02* -X327663D01* -X329184D02* -X330024D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335796D02* -X336463D01* -X337853D02* -X338491D01* -X339122D02* -X339815D01* -X341269D02* -X341971D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260671Y32499D02* -X261317D01* -X262833D02* -X263448D01* -X263853D02* -X264490D01* -X266111D02* -X266876D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272233D01* -X273694D02* -X274346D01* -X275185D02* -X275850D01* -X277445D02* -X278122D01* -X278984D02* -X279616D01* -X281033D02* -X281776D01* -X282665D02* -X283311D01* -X284781D02* -X285507D01* -X286427D02* -X287017D01* -X288634D02* -X289308D01* -X290909D02* -X291585D01* -X292202D02* -X292838D01* -X294459D02* -X295224D01* -X296145D02* -X296776D01* -X298194D02* -X298937D01* -X299937D02* -X300559D01* -X301968D02* -X302588D01* -X303669D02* -X304291D01* -X305700D02* -X306320D01* -X307969D02* -X308585D01* -X311054D02* -X311556D01* -X312340D02* -X312976D01* -X314239D02* -X315058D01* -X315858D02* -X316509D01* -X317852D02* -X318506D01* -X319911D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X326999D02* -X327635D01* -X329256D02* -X330022D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335752D02* -X336397D01* -X337913D02* -X338529D01* -X339078D02* -X339743D01* -X341338D02* -X342015D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260636Y32593D02* -X261266D01* -X262875D02* -X263481D01* -X263850D02* -X264481D01* -X266165D02* -X266872D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272181D01* -X273751D02* -X274382D01* -X275149D02* -X275795D01* -X277501D02* -X278156D01* -X278972D02* -X279584D01* -X281083D02* -X281776D01* -X282628D02* -X283256D01* -X284831D02* -X285507D01* -X286427D02* -X287017D01* -X288597D02* -X289250D01* -X290961D02* -X291622D01* -X292198D02* -X292829D01* -X294513D02* -X295220D01* -X296133D02* -X296745D01* -X298243D02* -X298937D01* -X299902D02* -X300511D01* -X302017D02* -X302626D01* -X303633D02* -X304243D01* -X305748D02* -X306357D01* -X307988D02* -X308606D01* -X311037D02* -X311533D01* -X312307D02* -X312929D01* -X314322D02* -X315077D01* -X315960D02* -X316578D01* -X317806D02* -X318443D01* -X319976D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X326996D02* -X327626D01* -X329311D02* -X330017D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335717D02* -X336347D01* -X337956D02* -X338562D01* -X339042D02* -X339687D01* -X341394D02* -X342049D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260607Y32686D02* -X261229D01* -X262911D02* -X263507D01* -X263856D02* -X264485D01* -X266206D02* -X266871D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272140D01* -X273793D02* -X274416D01* -X275117D02* -X275750D01* -X277546D02* -X278187D01* -X278965D02* -X279570D01* -X281117D02* -X281776D01* -X282598D02* -X283215D01* -X284870D02* -X285507D01* -X286427D02* -X287017D01* -X288566D02* -X289206D01* -X291007D02* -X291650D01* -X292204D02* -X292833D01* -X294554D02* -X295219D01* -X296126D02* -X296730D01* -X298278D02* -X298937D01* -X299870D02* -X300469D01* -X302057D02* -X302661D01* -X303602D02* -X304200D01* -X305789D02* -X306393D01* -X308008D02* -X308628D01* -X311021D02* -X311512D01* -X312283D02* -X312895D01* -X314391D02* -X315095D01* -X316048D02* -X316641D01* -X317771D02* -X318393D01* -X320025D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327001D02* -X327630D01* -X329352D02* -X330017D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335688D02* -X336309D01* -X337991D02* -X338587D01* -X339010D02* -X339643D01* -X341439D02* -X342080D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260582Y32780D02* -X261197D01* -X262936D02* -X263528D01* -X263869D02* -X264512D01* -X266232D02* -X266870D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272111D01* -X273826D02* -X274441D01* -X275090D02* -X275717D01* -X277580D02* -X278211D01* -X278960D02* -X279559D01* -X281141D02* -X281776D01* -X282569D02* -X283182D01* -X284903D02* -X285507D01* -X286427D02* -X287017D01* -X288538D02* -X289169D01* -X291043D02* -X291170D01* -X292218D02* -X292861D01* -X294581D02* -X295218D01* -X296120D02* -X296720D01* -X298302D02* -X298937D01* -X299841D02* -X300439D01* -X302087D02* -X302689D01* -X303573D02* -X304171D01* -X305819D02* -X306420D01* -X308030D02* -X308649D01* -X311009D02* -X311499D01* -X312264D02* -X312869D01* -X314454D02* -X315115D01* -X316126D02* -X316701D01* -X317739D02* -X318355D01* -X320065D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327015D02* -X327658D01* -X329378D02* -X330016D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335662D02* -X336278D01* -X338017D02* -X338609D01* -X338983D02* -X339609D01* -X341473D02* -X342104D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260562Y32874D02* -X261173D01* -X262955D02* -X263507D01* -X263893D02* -X264554D01* -X266250D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272091D01* -X273853D02* -X274463D01* -X275070D02* -X275689D01* -X277607D02* -X278229D01* -X278957D02* -X279553D01* -X281157D02* -X281776D01* -X282545D02* -X283156D01* -X284926D02* -X285507D01* -X286427D02* -X287017D01* -X288519D02* -X289139D01* -X292241D02* -X292902D01* -X294598D02* -X295216D01* -X296118D02* -X296714D01* -X298318D02* -X298937D01* -X299816D02* -X300415D01* -X302116D02* -X302712D01* -X303548D02* -X304146D01* -X305847D02* -X306444D01* -X308052D02* -X308673D01* -X310998D02* -X311487D01* -X312248D02* -X312853D01* -X314503D02* -X315134D01* -X316193D02* -X316753D01* -X317713D02* -X318326D01* -X320096D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327038D02* -X327700D01* -X329396D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335643D02* -X336254D01* -X338035D02* -X338588D01* -X338963D02* -X339581D01* -X341500D02* -X342122D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260544Y32967D02* -X261155D01* -X263926D02* -X264631D01* -X266259D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272075D01* -X273874D02* -X274479D01* -X275054D02* -X275666D01* -X277630D02* -X278244D01* -X278956D02* -X279549D01* -X281169D02* -X281776D01* -X282526D02* -X283136D01* -X284943D02* -X285507D01* -X286427D02* -X287017D01* -X288502D02* -X289117D01* -X292274D02* -X292980D01* -X294607D02* -X295216D01* -X296117D02* -X296710D01* -X298330D02* -X298937D01* -X299796D02* -X300392D01* -X302135D02* -X302733D01* -X303528D02* -X304124D01* -X305867D02* -X306465D01* -X308076D02* -X308700D01* -X310990D02* -X311480D01* -X312238D02* -X312843D01* -X314550D02* -X315154D01* -X316252D02* -X316798D01* -X317692D02* -X318304D01* -X320118D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327072D02* -X327777D01* -X329404D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335624D02* -X336235D01* -X338946D02* -X339559D01* -X341523D02* -X342137D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260533Y33061D02* -X261143D01* -X263970D02* -X264764D01* -X266267D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272063D01* -X273888D02* -X274494D01* -X275041D02* -X275652D01* -X277645D02* -X278257D01* -X278956D02* -X279548D01* -X281178D02* -X281776D01* -X282511D02* -X283121D01* -X284955D02* -X285507D01* -X286427D02* -X287017D01* -X288491D02* -X289099D01* -X292319D02* -X293112D01* -X294615D02* -X295216D01* -X296117D02* -X296708D01* -X298338D02* -X298937D01* -X299778D02* -X300374D01* -X302153D02* -X302753D01* -X303510D02* -X304106D01* -X305885D02* -X306485D01* -X308101D02* -X308727D01* -X310984D02* -X311472D01* -X312232D02* -X312839D01* -X314587D02* -X315174D01* -X316302D02* -X316839D01* -X317676D02* -X318287D01* -X320135D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327117D02* -X327910D01* -X329413D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335613D02* -X336224D01* -X338934D02* -X339544D01* -X341538D02* -X342150D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260524Y33155D02* -X261133D01* -X264030D02* -X265066D01* -X266270D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272053D01* -X273900D02* -X274504D01* -X275031D02* -X275640D01* -X277657D02* -X278268D01* -X278956D02* -X279546D01* -X281184D02* -X281776D01* -X282500D02* -X283110D01* -X284965D02* -X285507D01* -X286427D02* -X287017D01* -X288480D02* -X289086D01* -X292378D02* -X293414D01* -X294619D02* -X295216D01* -X296117D02* -X296706D01* -X298345D02* -X298937D01* -X299761D02* -X300357D01* -X302170D02* -X302769D01* -X303493D02* -X304089D01* -X305902D02* -X306501D01* -X308127D02* -X308754D01* -X310982D02* -X311469D01* -X312231D02* -X312841D01* -X314622D02* -X315194D01* -X316347D02* -X316876D01* -X317664D02* -X318272D01* -X320148D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327176D02* -X328211D01* -X329416D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335605D02* -X336214D01* -X338924D02* -X339533D01* -X341550D02* -X342161D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260519Y33248D02* -X261125D01* -X264102D02* -X265645D01* -X266271D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272048D01* -X273909D02* -X274514D01* -X275025D02* -X275631D01* -X277665D02* -X278272D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282495D02* -X283102D01* -X284970D02* -X285507D01* -X286427D02* -X287017D01* -X288475D02* -X289079D01* -X292450D02* -X293993D01* -X294620D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299748D02* -X300348D01* -X302180D02* -X302782D01* -X303480D02* -X304080D01* -X305911D02* -X306513D01* -X308154D02* -X308784D01* -X310982D02* -X311465D01* -X312233D02* -X312847D01* -X314651D02* -X315214D01* -X316389D02* -X316909D01* -X317654D02* -X318263D01* -X320155D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327247D02* -X328791D01* -X329417D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335600D02* -X336206D01* -X338918D02* -X339524D01* -X341558D02* -X342165D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260516Y33342D02* -X261123D01* -X264204D02* -X266047D01* -X266273D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272044D01* -X273912D02* -X274517D01* -X275022D02* -X275629D01* -X277669D02* -X278276D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282492D02* -X283100D01* -X284972D02* -X285507D01* -X286427D02* -X287017D01* -X288472D02* -X291678D01* -X292552D02* -X294395D01* -X294621D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299736D02* -X300337D01* -X302191D02* -X302793D01* -X303468D02* -X304068D01* -X305923D02* -X306524D01* -X308182D02* -X308817D01* -X310984D02* -X311468D01* -X312243D02* -X312858D01* -X314675D02* -X315234D01* -X316425D02* -X316937D01* -X317650D02* -X318257D01* -X320159D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327349D02* -X329193D01* -X329419D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335596D02* -X336204D01* -X338915D02* -X339522D01* -X341561D02* -X342169D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260515Y33436D02* -X261122D01* -X264339D02* -X266867D01* -X267776D02* -X268365D01* -X270002D02* -X270592D01* -X271504D02* -X272042D01* -X273913D02* -X274520D01* -X275020D02* -X275628D01* -X277670D02* -X278278D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282491D02* -X283099D01* -X284971D02* -X285507D01* -X286427D02* -X287017D01* -X288472D02* -X291678D01* -X292687D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299726D02* -X300328D01* -X302199D02* -X302802D01* -X303457D02* -X304060D01* -X305931D02* -X306534D01* -X308211D02* -X308850D01* -X310988D02* -X311472D01* -X312254D02* -X312873D01* -X314696D02* -X315254D01* -X316458D02* -X316962D01* -X317646D02* -X318255D01* -X320162D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327485D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335595D02* -X336202D01* -X338913D02* -X339520D01* -X341563D02* -X342171D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260517Y33530D02* -X261124D01* -X264530D02* -X266867D01* -X267776D02* -X268367D01* -X270002D02* -X270592D01* -X271504D02* -X272044D01* -X273911D02* -X274519D01* -X275023D02* -X275630D01* -X277668D02* -X278276D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282493D02* -X283101D01* -X284969D02* -X285507D01* -X286427D02* -X287018D01* -X288475D02* -X291674D01* -X292879D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299719D02* -X300323D01* -X302205D02* -X302810D01* -X303451D02* -X304054D01* -X305937D02* -X306542D01* -X308245D02* -X308884D01* -X310996D02* -X311478D01* -X312268D02* -X312893D01* -X314714D02* -X315274D01* -X316483D02* -X316983D01* -X317649D02* -X318256D01* -X320160D02* -X320715D01* -X321605D02* -X322194D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327676D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335598D02* -X336205D01* -X338916D02* -X339523D01* -X341561D02* -X342169D01* -X342863D02* -X343453D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260522Y33623D02* -X261129D01* -X264852D02* -X266867D01* -X267776D02* -X268370D01* -X270002D02* -X270592D01* -X271504D02* -X272049D01* -X273906D02* -X274515D01* -X275026D02* -X275635D01* -X277664D02* -X278273D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282498D02* -X283106D01* -X284961D02* -X285507D01* -X286427D02* -X287022D01* -X288480D02* -X291671D01* -X293200D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299712D02* -X300317D01* -X302211D02* -X302817D01* -X303444D02* -X304049D01* -X305942D02* -X306549D01* -X308278D02* -X308918D01* -X311006D02* -X311486D01* -X312289D02* -X312919D01* -X314723D02* -X315294D01* -X316505D02* -X317000D01* -X317654D02* -X318258D01* -X320157D02* -X320715D01* -X321605D02* -X322196D01* -X323674D02* -X324264D01* -X325736D02* -X326326D01* -X327998D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335603D02* -X336210D01* -X338919D02* -X339528D01* -X341557D02* -X342166D01* -X342863D02* -X343454D01* -X344933D02* -X345522D01* -X346994D02* -X347584D01* -X260530Y33717D02* -X261138D01* -X265523D02* -X266867D01* -X267776D02* -X268377D01* -X270002D02* -X270592D01* -X271504D02* -X272058D01* -X273896D02* -X274507D01* -X275033D02* -X275645D01* -X277654D02* -X278265D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282507D02* -X283115D01* -X284951D02* -X285507D01* -X286427D02* -X287028D01* -X288491D02* -X291661D01* -X293871D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299706D02* -X300312D01* -X302216D02* -X302821D01* -X303437D02* -X304043D01* -X305947D02* -X306553D01* -X308314D02* -X308956D01* -X311019D02* -X311498D01* -X312316D02* -X312946D01* -X314731D02* -X315315D01* -X316521D02* -X317011D01* -X317662D02* -X318267D01* -X320148D02* -X320715D01* -X321605D02* -X322200D01* -X323674D02* -X324265D01* -X325736D02* -X326326D01* -X328669D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335610D02* -X336219D01* -X338926D02* -X339537D01* -X341547D02* -X342158D01* -X342863D02* -X343459D01* -X344933D02* -X345523D01* -X346994D02* -X347584D01* -X260541Y33811D02* -X261151D01* -X266036D02* -X266867D01* -X267776D02* -X268387D01* -X270002D02* -X270592D01* -X271504D02* -X272072D01* -X273885D02* -X274497D01* -X275045D02* -X275659D01* -X277640D02* -X278254D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282520D02* -X283126D01* -X284937D02* -X285507D01* -X286427D02* -X287038D01* -X288502D02* -X289118D01* -X291048D02* -X291650D01* -X294385D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299704D02* -X300308D01* -X302219D02* -X302825D01* -X303435D02* -X304040D01* -X305951D02* -X306557D01* -X308349D02* -X308994D01* -X311031D02* -X311511D01* -X312345D02* -X312978D01* -X314731D02* -X315335D01* -X316532D02* -X317019D01* -X317675D02* -X318280D01* -X320135D02* -X320715D01* -X321605D02* -X322210D01* -X323674D02* -X324267D01* -X325736D02* -X326326D01* -X329182D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335621D02* -X336231D01* -X338937D02* -X339552D01* -X341533D02* -X342147D01* -X342863D02* -X343469D01* -X344933D02* -X345526D01* -X346994D02* -X347584D01* -X260557Y33904D02* -X261167D01* -X266272D02* -X266867D01* -X267776D02* -X268400D01* -X270002D02* -X270592D01* -X271504D02* -X272090D01* -X273870D02* -X274481D01* -X275059D02* -X275677D01* -X277622D02* -X278240D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282534D02* -X283141D01* -X284919D02* -X285507D01* -X286427D02* -X287051D01* -X288518D02* -X289131D01* -X291035D02* -X291635D01* -X294620D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299701D02* -X300306D01* -X302221D02* -X302827D01* -X303433D02* -X304038D01* -X305953D02* -X306559D01* -X308386D02* -X309033D01* -X311047D02* -X311531D01* -X312376D02* -X313012D01* -X314728D02* -X315355D01* -X316541D02* -X317024D01* -X317693D02* -X318295D01* -X320119D02* -X320715D01* -X321605D02* -X322218D01* -X323674D02* -X324275D01* -X325736D02* -X326326D01* -X329418D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335638D02* -X336247D01* -X338952D02* -X339570D01* -X341515D02* -X342133D01* -X342863D02* -X343477D01* -X344933D02* -X345533D01* -X346994D02* -X347584D01* -X260576Y33998D02* -X261188D01* -X266274D02* -X266867D01* -X267776D02* -X268416D01* -X270002D02* -X270592D01* -X271504D02* -X272111D01* -X273849D02* -X274464D01* -X275078D02* -X275700D01* -X277598D02* -X278222D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282554D02* -X283162D01* -X284897D02* -X285507D01* -X286427D02* -X287067D01* -X288536D02* -X289152D01* -X291015D02* -X291619D01* -X294622D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299699D02* -X300306D01* -X302221D02* -X302829D01* -X303431D02* -X304038D01* -X305953D02* -X306560D01* -X308423D02* -X309072D01* -X311064D02* -X311552D01* -X312415D02* -X313053D01* -X314718D02* -X315375D01* -X316544D02* -X317027D01* -X317714D02* -X318317D01* -X320096D02* -X320715D01* -X321605D02* -X322234D01* -X323672D02* -X324287D01* -X325733D02* -X326326D01* -X329420D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335657D02* -X336268D01* -X338971D02* -X339593D01* -X341491D02* -X342115D01* -X342863D02* -X343493D01* -X344930D02* -X345546D01* -X346992D02* -X347584D01* -X260599Y34092D02* -X261217D01* -X262903D02* -X263252D01* -X264448D02* -X264534D01* -X266272D02* -X266867D01* -X267776D02* -X268439D01* -X270002D02* -X270592D01* -X271504D02* -X272143D01* -X273819D02* -X274438D01* -X275103D02* -X275732D01* -X277566D02* -X278198D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282578D02* -X283189D01* -X284870D02* -X285507D01* -X286427D02* -X287090D01* -X288563D02* -X289181D01* -X290990D02* -X291594D01* -X292796D02* -X292883D01* -X294620D02* -X295216D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299699D02* -X300306D01* -X302221D02* -X302830D01* -X303431D02* -X304038D01* -X305953D02* -X306561D01* -X308465D02* -X309115D01* -X311088D02* -X311577D01* -X312457D02* -X313101D01* -X314704D02* -X315395D01* -X316542D02* -X317025D01* -X317737D02* -X318347D01* -X320066D02* -X320715D01* -X321605D02* -X322255D01* -X323665D02* -X324306D01* -X325729D02* -X326325D01* -X327594D02* -X327680D01* -X329417D02* -X330013D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335680D02* -X336298D01* -X337983D02* -X338333D01* -X338996D02* -X339625D01* -X341459D02* -X342091D01* -X342863D02* -X343513D01* -X344924D02* -X345564D01* -X346987D02* -X347583D01* -X260626Y34185D02* -X261253D01* -X262875D02* -X263478D01* -X263959D02* -X264563D01* -X266265D02* -X266863D01* -X267776D02* -X268465D01* -X270002D02* -X270592D01* -X271504D02* -X272183D01* -X273784D02* -X274410D01* -X275130D02* -X275774D01* -X277524D02* -X278170D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282604D02* -X283225D01* -X284832D02* -X285507D01* -X286427D02* -X287116D01* -X288593D02* -X289219D01* -X290958D02* -X291568D01* -X292307D02* -X292911D01* -X294613D02* -X295212D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299701D02* -X300306D01* -X302221D02* -X302830D01* -X303432D02* -X304038D01* -X305953D02* -X306561D01* -X308507D02* -X309160D01* -X311112D02* -X311602D01* -X312503D02* -X313154D01* -X314679D02* -X315415D01* -X316536D02* -X317022D01* -X317766D02* -X318385D01* -X320028D02* -X320715D01* -X321605D02* -X322284D01* -X323654D02* -X324333D01* -X325719D02* -X326322D01* -X327105D02* -X327708D01* -X329411D02* -X330009D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335707D02* -X336334D01* -X337955D02* -X338559D01* -X339023D02* -X339667D01* -X341417D02* -X342063D01* -X342863D02* -X343543D01* -X344912D02* -X345592D01* -X346978D02* -X347581D01* -X260657Y34279D02* -X261298D01* -X262835D02* -X263455D01* -X263982D02* -X264596D01* -X266251D02* -X266858D01* -X267776D02* -X268500D01* -X270002D02* -X270592D01* -X271504D02* -X272232D01* -X273740D02* -X274378D01* -X275165D02* -X275825D01* -X277473D02* -X278132D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282634D02* -X283269D01* -X284783D02* -X285507D01* -X286427D02* -X287151D01* -X288628D02* -X289268D01* -X290918D02* -X291531D01* -X292331D02* -X292945D01* -X294599D02* -X295207D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299703D02* -X300309D01* -X302219D02* -X302826D01* -X303435D02* -X304040D01* -X305951D02* -X306558D01* -X308551D02* -X309206D01* -X311140D02* -X311635D01* -X312555D02* -X313215D01* -X314646D02* -X315435D01* -X316526D02* -X317014D01* -X317800D02* -X318432D01* -X319978D02* -X320715D01* -X321605D02* -X322323D01* -X323636D02* -X324373D01* -X325703D02* -X326314D01* -X327128D02* -X327742D01* -X329397D02* -X330004D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335737D02* -X336379D01* -X337916D02* -X338535D01* -X339057D02* -X339718D01* -X341366D02* -X342025D01* -X342863D02* -X343581D01* -X344894D02* -X345632D01* -X346962D02* -X347572D01* -X260696Y34373D02* -X261358D01* -X262788D02* -X263426D01* -X264011D02* -X264640D01* -X266220D02* -X266849D01* -X267776D02* -X268557D01* -X270002D02* -X270592D01* -X271504D02* -X272296D01* -X273680D02* -X274340D01* -X275203D02* -X275888D01* -X277407D02* -X278090D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282670D02* -X283326D01* -X284724D02* -X285507D01* -X286427D02* -X287208D01* -X288670D02* -X289330D01* -X290857D02* -X291492D01* -X292359D02* -X292989D01* -X294569D02* -X295197D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299706D02* -X300313D01* -X302215D02* -X302822D01* -X303438D02* -X304044D01* -X305947D02* -X306554D01* -X308594D02* -X309252D01* -X311168D02* -X311669D01* -X312611D02* -X313287D01* -X314596D02* -X315455D01* -X316511D02* -X317003D01* -X317839D02* -X318492D01* -X319915D02* -X320715D01* -X321605D02* -X322378D01* -X323606D02* -X324427D01* -X325678D02* -X326301D01* -X327156D02* -X327786D01* -X329366D02* -X329994D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335776D02* -X336439D01* -X337869D02* -X338507D01* -X339096D02* -X339781D01* -X341300D02* -X341983D01* -X342863D02* -X343636D01* -X344865D02* -X345686D01* -X346936D02* -X347560D01* -X260741Y34467D02* -X261438D01* -X262724D02* -X263388D01* -X264046D02* -X264698D01* -X266170D02* -X266836D01* -X267776D02* -X268638D01* -X270002D02* -X270592D01* -X271504D02* -X272375D01* -X273602D02* -X274297D01* -X275251D02* -X275970D01* -X277324D02* -X278041D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282715D02* -X283402D01* -X284647D02* -X285507D01* -X286427D02* -X287289D01* -X288719D02* -X289413D01* -X290775D02* -X291443D01* -X292394D02* -X293047D01* -X294519D02* -X295184D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299711D02* -X300318D01* -X302210D02* -X302818D01* -X303443D02* -X304049D01* -X305942D02* -X306550D01* -X308642D02* -X309300D01* -X311203D02* -X311707D01* -X312672D02* -X313372D01* -X314530D02* -X315475D01* -X316492D02* -X316987D01* -X317883D02* -X318570D01* -X319833D02* -X320715D01* -X321605D02* -X322450D01* -X323565D02* -X324500D01* -X325630D02* -X326285D01* -X327192D02* -X327844D01* -X329316D02* -X329981D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335822D02* -X336519D01* -X337804D02* -X338468D01* -X339144D02* -X339863D01* -X341217D02* -X341933D01* -X342863D02* -X343708D01* -X344824D02* -X345759D01* -X346889D02* -X347544D01* -X260794Y34560D02* -X261541D01* -X262635D02* -X263344D01* -X264090D02* -X264781D01* -X266083D02* -X266809D01* -X267776D02* -X268769D01* -X269330D02* -X269485D01* -X270002D02* -X270592D01* -X271504D02* -X272475D01* -X273507D02* -X274245D01* -X275310D02* -X276079D01* -X277219D02* -X277983D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282766D02* -X283497D01* -X284546D02* -X285507D01* -X286427D02* -X287420D01* -X287981D02* -X288136D01* -X288780D02* -X289519D01* -X290672D02* -X291387D01* -X292438D02* -X293129D01* -X294432D02* -X295157D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299718D02* -X300323D01* -X302204D02* -X302813D01* -X303450D02* -X304055D01* -X305936D02* -X306544D01* -X308691D02* -X309351D01* -X311238D02* -X311748D01* -X312740D02* -X313477D01* -X314436D02* -X315495D01* -X316470D02* -X316967D01* -X317936D02* -X318671D01* -X319730D02* -X320715D01* -X321605D02* -X322557D01* -X323497D02* -X324608D01* -X325549D02* -X326261D01* -X327236D02* -X327926D01* -X329229D02* -X329955D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335875D02* -X336622D01* -X337716D02* -X338424D01* -X339203D02* -X339972D01* -X341111D02* -X341876D01* -X342863D02* -X343816D01* -X344756D02* -X345867D01* -X346807D02* -X347519D01* -X260855Y34654D02* -X261693D01* -X262505D02* -X263289D01* -X264142D02* -X264926D01* -X265933D02* -X266775D01* -X267776D02* -X268307D01* -X268323D02* -X269520D01* -X270002D02* -X270592D01* -X271504D02* -X272616D01* -X273367D02* -X274185D01* -X275376D02* -X276236D01* -X277061D02* -X277917D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282827D02* -X283642D01* -X284400D02* -X285507D01* -X286427D02* -X286958D01* -X286974D02* -X288171D01* -X288847D02* -X289672D01* -X290525D02* -X291321D01* -X292490D02* -X293275D01* -X294281D02* -X295124D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299726D02* -X300331D01* -X302199D02* -X302806D01* -X303457D02* -X304063D01* -X305930D02* -X306537D01* -X308742D02* -X309403D01* -X311276D02* -X311793D01* -X312816D02* -X313626D01* -X314306D02* -X314895D01* -X314926D02* -X315516D01* -X316439D02* -X316945D01* -X317999D02* -X318819D01* -X319585D02* -X320715D01* -X321605D02* -X322727D01* -X323368D02* -X324157D01* -X324196D02* -X324780D01* -X325409D02* -X326228D01* -X327287D02* -X328072D01* -X329079D02* -X329921D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X335936D02* -X336774D01* -X337585D02* -X338369D01* -X339269D02* -X340129D01* -X340954D02* -X341809D01* -X342863D02* -X343986D01* -X344626D02* -X345416D01* -X345455D02* -X346039D01* -X346667D02* -X347486D01* -X260929Y34748D02* -X263222D01* -X264207D02* -X266729D01* -X267776D02* -X268307D01* -X268378D02* -X269555D01* -X270002D02* -X270592D01* -X271504D02* -X274115D01* -X275457D02* -X277837D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282898D02* -X285507D01* -X286427D02* -X286958D01* -X287029D02* -X288206D01* -X288925D02* -X291241D01* -X292556D02* -X295078D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299736D02* -X300341D01* -X302190D02* -X302796D01* -X303467D02* -X304072D01* -X305922D02* -X306528D01* -X308792D02* -X309456D01* -X311315D02* -X311842D01* -X312902D02* -X314830D01* -X314947D02* -X315536D01* -X316405D02* -X316918D01* -X318071D02* -X320156D01* -X320169D02* -X320715D01* -X321605D02* -X322132D01* -X322194D02* -X324113D01* -X324267D02* -X326184D01* -X327353D02* -X329875D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X336010D02* -X338302D01* -X339350D02* -X341730D01* -X342863D02* -X343391D01* -X343452D02* -X345372D01* -X345526D02* -X347443D01* -X261024Y34841D02* -X263139D01* -X264289D02* -X266669D01* -X267776D02* -X268307D01* -X268436D02* -X269590D01* -X270002D02* -X270592D01* -X271504D02* -X272093D01* -X272162D02* -X274031D01* -X275557D02* -X277739D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X282983D02* -X284844D01* -X284918D02* -X285507D01* -X286427D02* -X286958D01* -X287087D02* -X288241D01* -X289020D02* -X291150D01* -X292637D02* -X295017D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299747D02* -X300352D01* -X302179D02* -X302785D01* -X303479D02* -X304084D01* -X305911D02* -X306517D01* -X308847D02* -X309510D01* -X311362D02* -X311895D01* -X313004D02* -X314755D01* -X314968D02* -X315556D01* -X316365D02* -X316887D01* -X318154D02* -X320074D01* -X320169D02* -X320715D01* -X321605D02* -X322132D01* -X322274D02* -X324056D01* -X324351D02* -X326130D01* -X327434D02* -X329814D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X336104D02* -X338220D01* -X339450D02* -X341632D01* -X342863D02* -X343391D01* -X343532D02* -X345315D01* -X345609D02* -X347388D01* -X261139Y34935D02* -X263040D01* -X264403D02* -X266581D01* -X267776D02* -X268307D01* -X268505D02* -X269625D01* -X270002D02* -X270592D01* -X271504D02* -X272093D01* -X272259D02* -X273928D01* -X275673D02* -X277623D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X283089D02* -X284752D01* -X284918D02* -X285507D01* -X286427D02* -X286958D01* -X287156D02* -X288276D01* -X289135D02* -X291034D01* -X292751D02* -X294929D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299762D02* -X300365D01* -X302169D02* -X302769D01* -X303494D02* -X304096D01* -X305900D02* -X306500D01* -X308902D02* -X309565D01* -X311409D02* -X311956D01* -X313126D02* -X314664D01* -X314989D02* -X315576D01* -X316319D02* -X316853D01* -X318261D02* -X319972D01* -X320169D02* -X320715D01* -X321605D02* -X322132D01* -X322374D02* -X323984D01* -X324447D02* -X326056D01* -X327548D02* -X329727D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X336219D02* -X338121D01* -X339565D02* -X341516D01* -X342863D02* -X343391D01* -X343632D02* -X345243D01* -X345706D02* -X347314D01* -X261289Y35029D02* -X262904D01* -X264551D02* -X266450D01* -X267776D02* -X268307D01* -X268585D02* -X269660D01* -X270002D02* -X270592D01* -X271504D02* -X272093D01* -X272376D02* -X273793D01* -X275820D02* -X277476D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X283223D02* -X284630D01* -X284918D02* -X285507D01* -X286427D02* -X286958D01* -X287237D02* -X288311D01* -X289280D02* -X290896D01* -X292899D02* -X294799D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299778D02* -X300382D01* -X302151D02* -X302752D01* -X303510D02* -X304113D01* -X305883D02* -X306483D01* -X308959D02* -X309620D01* -X311461D02* -X312020D01* -X313272D02* -X314543D01* -X315009D02* -X315596D01* -X316266D02* -X316814D01* -X318396D02* -X319851D01* -X320169D02* -X320715D01* -X321605D02* -X322132D01* -X322501D02* -X323878D01* -X324571D02* -X325948D01* -X327696D02* -X329596D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X336369D02* -X337985D01* -X339712D02* -X341369D01* -X342863D02* -X343391D01* -X343759D02* -X345136D01* -X345830D02* -X347206D01* -X261501Y35122D02* -X262713D01* -X264781D02* -X266250D01* -X267776D02* -X268307D01* -X268696D02* -X269515D01* -X270002D02* -X270592D01* -X271504D02* -X272093D01* -X272540D02* -X273606D01* -X276024D02* -X277277D01* -X278956D02* -X279546D01* -X281186D02* -X281776D01* -X283409D02* -X284469D01* -X284918D02* -X285507D01* -X286427D02* -X286958D01* -X287347D02* -X288167D01* -X289474D02* -X290698D01* -X293130D02* -X294598D01* -X296117D02* -X296706D01* -X298347D02* -X298937D01* -X299796D02* -X300399D01* -X302134D02* -X302734D01* -X303527D02* -X304131D01* -X305866D02* -X306465D01* -X309017D02* -X309678D01* -X311515D02* -X312093D01* -X313458D02* -X314380D01* -X315030D02* -X315616D01* -X316208D02* -X316771D01* -X318581D02* -X319681D01* -X320169D02* -X320715D01* -X321605D02* -X322132D01* -X322665D02* -X323724D01* -X324737D02* -X325789D01* -X327928D02* -X329396D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X336581D02* -X337794D01* -X339917D02* -X341170D01* -X342863D02* -X343391D01* -X343924D02* -X344982D01* -X345996D02* -X347047D01* -X261883Y35216D02* -X262335D01* -X265238D02* -X265831D01* -X268928D02* -X269224D01* -X270002D02* -X270592D01* -X271504D02* -X272093D01* -X272863D02* -X273256D01* -X276434D02* -X276879D01* -X283753D02* -X284159D01* -X284918D02* -X285507D01* -X287579D02* -X287875D01* -X289866D02* -X290319D01* -X293586D02* -X294180D01* -X299819D02* -X300420D01* -X302114D02* -X302711D01* -X303550D02* -X304152D01* -X305846D02* -X306443D01* -X309079D02* -X309738D01* -X311574D02* -X312170D01* -X313817D02* -X314031D01* -X316143D02* -X316720D01* -X318935D02* -X319352D01* -X322994D02* -X323398D01* -X325064D02* -X325461D01* -X328383D02* -X328977D01* -X332405D02* -X332994D01* -X336964D02* -X337415D01* -X340327D02* -X340772D01* -X344253D02* -X344657D01* -X346322D02* -X346720D01* -X270002Y35310D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X299843D02* -X300448D01* -X302086D02* -X302683D01* -X303575D02* -X304180D01* -X305817D02* -X306415D01* -X309142D02* -X309802D01* -X311635D02* -X312256D01* -X316065D02* -X316666D01* -X332405D02* -X332994D01* -X270002Y35404D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X299871D02* -X300481D01* -X302055D02* -X302652D01* -X303603D02* -X304213D01* -X305787D02* -X306383D01* -X309206D02* -X309867D01* -X311705D02* -X312355D01* -X315976D02* -X316610D01* -X332405D02* -X332994D01* -X270002Y35497D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X299906D02* -X300518D01* -X302013D02* -X302618D01* -X303638D02* -X304250D01* -X305744D02* -X306349D01* -X309275D02* -X309935D01* -X311779D02* -X312463D01* -X315875D02* -X316544D01* -X332405D02* -X332994D01* -X270002Y35591D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X299945D02* -X300566D01* -X301962D02* -X302580D01* -X303676D02* -X304298D01* -X305694D02* -X306311D01* -X309346D02* -X310006D01* -X311862D02* -X312589D01* -X315758D02* -X316472D01* -X332405D02* -X332994D01* -X270002Y35685D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X299987D02* -X300627D01* -X301891D02* -X302539D01* -X303719D02* -X304359D01* -X305623D02* -X306270D01* -X309420D02* -X310081D01* -X311948D02* -X312733D01* -X315624D02* -X316393D01* -X332405D02* -X332994D01* -X270002Y35778D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300034D02* -X300708D01* -X301808D02* -X302490D01* -X303765D02* -X304439D01* -X305540D02* -X306222D01* -X309497D02* -X310157D01* -X312046D02* -X312900D01* -X315463D02* -X316305D01* -X332405D02* -X332994D01* -X270002Y35872D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300091D02* -X300815D01* -X301691D02* -X302434D01* -X303822D02* -X304547D01* -X305422D02* -X306166D01* -X307202D02* -X310237D01* -X312152D02* -X313100D01* -X315268D02* -X316207D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y35966D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300157D02* -X300999D01* -X301504D02* -X302370D01* -X303888D02* -X304731D01* -X305236D02* -X306102D01* -X307202D02* -X310311D01* -X312265D02* -X313369D01* -X315008D02* -X316095D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y36059D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300234D02* -X302297D01* -X303966D02* -X306028D01* -X307202D02* -X310311D01* -X312401D02* -X313809D01* -X314572D02* -X315970D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y36153D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300327D02* -X302202D01* -X304058D02* -X305934D01* -X307202D02* -X310311D01* -X312544D02* -X315828D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y36247D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300441D02* -X302089D01* -X304172D02* -X305821D01* -X307202D02* -X310311D01* -X312721D02* -X315652D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y36341D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300586D02* -X301935D01* -X304317D02* -X305667D01* -X307202D02* -X310311D01* -X312934D02* -X315443D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X270002Y36434D02* -X270592D01* -X271504D02* -X272093D01* -X284918D02* -X285507D01* -X300823D02* -X301699D01* -X304555D02* -X305430D01* -X313219D02* -X315171D01* -X330932D02* -X331522D01* -X332405D02* -X332994D01* -X313683Y36528D02* -X314725D01* -X261926Y46766D02* -Y51024D01* -X260406D01* -Y51891D01* -X264476D01* -Y51024D01* -X262961D01* -Y46766D01* -X261926D01* -X267289Y47949D02* -X268270Y47785D01* -X268219Y47652D01* -X268160Y47531D01* -X268098Y47418D01* -X268027Y47309D01* -X267949Y47211D01* -X267863Y47121D01* -X267774Y47039D01* -X267672Y46965D01* -X267567Y46898D01* -X267457Y46840D01* -X267340Y46793D01* -X267215Y46754D01* -X267082Y46723D01* -X266945Y46699D01* -X266805Y46687D01* -X266652Y46683D01* -X266535Y46687D01* -X266418Y46691D01* -X266309Y46707D01* -X266199Y46723D01* -X266098Y46746D01* -X265996Y46774D01* -X265902Y46805D01* -X265809Y46840D01* -X265723Y46883D01* -X265641Y46930D01* -X265559Y46980D01* -X265484Y47039D01* -X265410Y47102D01* -X265344Y47168D01* -X265277Y47238D01* -X265219Y47317D01* -X265133Y47445D01* -X265059Y47586D01* -X264996Y47734D01* -X264945Y47891D01* -X264902Y48055D01* -X264875Y48226D01* -X264859Y48406D01* -X264852Y48594D01* -X264859Y48820D01* -X264883Y49031D01* -X264918Y49230D01* -X264973Y49418D01* -X265039Y49590D01* -X265125Y49754D01* -X265223Y49902D01* -X265336Y50039D01* -X265394Y50102D01* -X265461Y50160D01* -X265524Y50219D01* -X265590Y50270D01* -X265660Y50317D01* -X265730Y50359D01* -X265805Y50398D01* -X265879Y50430D01* -X265957Y50461D01* -X266039Y50488D01* -X266117Y50512D01* -X266203Y50531D01* -X266285Y50543D01* -X266375Y50555D01* -X266465Y50559D01* -X266555Y50563D01* -X266656Y50559D01* -X266758Y50555D01* -X266852Y50543D01* -X266945Y50527D01* -X267039Y50508D01* -X267129Y50484D01* -X267211Y50457D01* -X267297Y50426D01* -X267375Y50391D01* -X267453Y50348D01* -X267527Y50305D01* -X267602Y50254D01* -X267672Y50199D01* -X267738Y50144D01* -X267801Y50082D01* -X267863Y50016D01* -X267922Y49945D01* -X267973Y49871D01* -X268024Y49789D01* -X268070Y49707D01* -X268113Y49617D01* -X268152Y49524D01* -X268187Y49426D01* -X268215Y49324D01* -X268242Y49215D01* -X268266Y49106D01* -X268285Y48988D01* -X268301Y48867D01* -X268313Y48742D01* -X268317Y48613D01* -X268320Y48476D01* -Y48340D01* -X265859D01* -X265867Y48234D01* -X265879Y48133D01* -X265898Y48039D01* -X265926Y47953D01* -X265957Y47871D01* -X265996Y47793D01* -X266043Y47723D01* -X266098Y47660D01* -X266156Y47602D01* -X266219Y47555D01* -X266285Y47512D01* -X266352Y47476D01* -X266426Y47453D01* -X266500Y47433D01* -X266582Y47422D01* -X266664Y47418D01* -X266719D01* -X266774Y47426D01* -X266828Y47433D01* -X266875Y47449D01* -X266922Y47465D01* -X266969Y47488D01* -X267012Y47516D01* -X267051Y47543D01* -X267090Y47578D01* -X267125Y47617D01* -X267160Y47660D01* -X267191Y47707D01* -X267219Y47762D01* -X267242Y47820D01* -X267270Y47883D01* -X267289Y47949D01* -X267344Y48941D02* -X267340Y49043D01* -X267328Y49141D01* -X267309Y49230D01* -X267285Y49317D01* -X267254Y49394D01* -X267215Y49465D01* -X267172Y49531D01* -X267125Y49590D01* -X267070Y49641D01* -X267012Y49687D01* -X266953Y49726D01* -X266891Y49758D01* -X266828Y49781D01* -X266758Y49797D01* -X266687Y49809D01* -X266613Y49813D01* -X266535Y49809D01* -X266461Y49797D01* -X266391Y49777D01* -X266320Y49754D01* -X266258Y49719D01* -X266195Y49680D01* -X266137Y49633D01* -X266082Y49578D01* -X266035Y49516D01* -X265992Y49449D01* -X265957Y49379D01* -X265926Y49301D01* -X265902Y49219D01* -X265887Y49133D01* -X265879Y49039D01* -X265875Y48941D01* -X267344D01* -X272352Y49383D02* -X271383Y49207D01* -X271367Y49277D01* -X271352Y49344D01* -X271328Y49402D01* -X271305Y49461D01* -X271274Y49512D01* -X271238Y49559D01* -X271203Y49602D01* -X271160Y49641D01* -X271117Y49676D01* -X271070Y49707D01* -X271016Y49730D01* -X270961Y49754D01* -X270906Y49770D01* -X270844Y49781D01* -X270781Y49785D01* -X270711Y49789D01* -X270625Y49785D01* -X270539Y49774D01* -X270457Y49754D01* -X270383Y49726D01* -X270313Y49691D01* -X270246Y49644D01* -X270183Y49594D01* -X270129Y49535D01* -X270078Y49469D01* -X270031Y49387D01* -X269996Y49297D01* -X269965Y49195D01* -X269941Y49086D01* -X269926Y48965D01* -X269914Y48832D01* -X269910Y48687D01* -X269914Y48531D01* -X269926Y48383D01* -X269941Y48250D01* -X269965Y48125D01* -X269996Y48016D01* -X270035Y47918D01* -X270082Y47832D01* -X270133Y47758D01* -X270191Y47691D01* -X270254Y47637D01* -X270320Y47590D01* -X270391Y47551D01* -X270469Y47524D01* -X270551Y47500D01* -X270637Y47488D01* -X270726Y47484D01* -X270797Y47488D01* -X270863Y47492D01* -X270922Y47508D01* -X270984Y47524D01* -X271039Y47547D01* -X271090Y47574D01* -X271141Y47606D01* -X271187Y47644D01* -X271230Y47687D01* -X271270Y47738D01* -X271305Y47793D01* -X271340Y47859D01* -X271367Y47933D01* -X271394Y48012D01* -X271418Y48098D01* -X271437Y48191D01* -X272402Y48027D01* -X272359Y47867D01* -X272309Y47715D01* -X272250Y47574D01* -X272183Y47441D01* -X272106Y47324D01* -X272024Y47211D01* -X271930Y47113D01* -X271824Y47024D01* -X271715Y46941D01* -X271594Y46875D01* -X271465Y46817D01* -X271328Y46770D01* -X271180Y46730D01* -X271024Y46703D01* -X270859Y46687D01* -X270683Y46683D01* -X270582D01* -X270484Y46691D01* -X270391Y46703D01* -X270297Y46715D01* -X270207Y46734D01* -X270121Y46754D01* -X270035Y46781D01* -X269953Y46813D01* -X269871Y46848D01* -X269797Y46883D01* -X269723Y46926D01* -X269648Y46973D01* -X269578Y47024D01* -X269512Y47078D01* -X269449Y47133D01* -X269387Y47195D01* -X269274Y47332D01* -X269176Y47476D01* -X269090Y47637D01* -X269024Y47809D01* -X268969Y47992D01* -X268933Y48191D01* -X268910Y48398D01* -X268902Y48621D01* -X268910Y48844D01* -X268933Y49055D01* -X268973Y49250D01* -X269024Y49437D01* -X269094Y49609D01* -X269176Y49770D01* -X269274Y49914D01* -X269387Y50051D01* -X269449Y50113D01* -X269516Y50172D01* -X269582Y50223D01* -X269652Y50274D01* -X269723Y50320D01* -X269801Y50363D01* -X269879Y50398D01* -X269957Y50433D01* -X270043Y50465D01* -X270129Y50488D01* -X270215Y50512D01* -X270309Y50531D01* -X270402Y50543D01* -X270500Y50555D01* -X270598Y50559D01* -X270699Y50563D01* -X270867Y50559D01* -X271024Y50543D01* -X271168Y50520D01* -X271309Y50488D01* -X271437Y50449D01* -X271559Y50398D01* -X271672Y50340D01* -X271777Y50270D01* -X271875Y50191D01* -X271965Y50106D01* -X272047Y50008D01* -X272121Y49902D01* -X272187Y49785D01* -X272250Y49660D01* -X272305Y49527D01* -X272352Y49383D01* -X274082Y51891D02* -Y50012D01* -X274141Y50078D01* -X274203Y50141D01* -X274266Y50199D01* -X274332Y50254D01* -X274398Y50301D01* -X274465Y50348D01* -X274531Y50387D01* -X274602Y50426D01* -X274676Y50457D01* -X274746Y50484D01* -X274820Y50508D01* -X274898Y50527D01* -X274976Y50543D01* -X275055Y50555D01* -X275133Y50559D01* -X275215Y50563D01* -X275301Y50559D01* -X275383Y50555D01* -X275461Y50543D01* -X275539Y50531D01* -X275613Y50512D01* -X275687Y50492D01* -X275758Y50465D01* -X275828Y50437D01* -X275894Y50402D01* -X275957Y50367D01* -X276012Y50332D01* -X276067Y50293D01* -X276117Y50250D01* -X276160Y50207D01* -X276199Y50164D01* -X276238Y50113D01* -X276301Y50016D01* -X276356Y49910D01* -X276394Y49797D01* -X276426Y49680D01* -X276437Y49617D01* -X276449Y49547D01* -X276457Y49465D01* -X276465Y49379D01* -X276469Y49281D01* -X276473Y49176D01* -X276476Y49063D01* -Y48945D01* -Y46766D01* -X275492D01* -Y48726D01* -Y48867D01* -X275488Y48992D01* -X275484Y49106D01* -X275476Y49207D01* -X275469Y49293D01* -X275461Y49363D01* -X275449Y49422D01* -X275437Y49469D01* -X275402Y49543D01* -X275359Y49609D01* -X275305Y49668D01* -X275238Y49719D01* -X275164Y49762D01* -X275082Y49789D01* -X274988Y49805D01* -X274887Y49813D01* -X274770Y49805D01* -X274656Y49781D01* -X274551Y49746D01* -X274453Y49691D01* -X274363Y49625D01* -X274285Y49543D01* -X274223Y49445D01* -X274172Y49336D01* -X274148Y49270D01* -X274133Y49199D01* -X274117Y49121D01* -X274106Y49039D01* -X274094Y48945D01* -X274086Y48848D01* -X274082Y48738D01* -Y48625D01* -Y46766D01* -X273098D01* -Y51891D01* -X274082D01* -X280852Y46766D02* -X279867D01* -Y48660D01* -Y48805D01* -X279863Y48937D01* -X279859Y49055D01* -X279852Y49156D01* -X279844Y49246D01* -X279832Y49324D01* -X279820Y49391D01* -X279805Y49441D01* -X279770Y49524D01* -X279723Y49598D01* -X279664Y49660D01* -X279602Y49715D01* -X279527Y49758D01* -X279445Y49789D01* -X279356Y49805D01* -X279258Y49813D01* -X279195Y49809D01* -X279137Y49805D01* -X279074Y49793D01* -X279020Y49777D01* -X278961Y49758D01* -X278906Y49734D01* -X278856Y49703D01* -X278801Y49672D01* -X278754Y49637D01* -X278707Y49598D01* -X278668Y49555D01* -X278633Y49508D01* -X278598Y49461D01* -X278570Y49410D01* -X278547Y49359D01* -X278524Y49301D01* -X278508Y49238D01* -X278492Y49160D01* -X278480Y49074D01* -X278469Y48973D01* -X278461Y48859D01* -X278453Y48734D01* -X278449Y48598D01* -Y48449D01* -Y46766D01* -X277465D01* -Y50480D01* -X278379D01* -Y49933D01* -X278441Y50012D01* -X278504Y50082D01* -X278570Y50148D01* -X278637Y50211D01* -X278707Y50266D01* -X278777Y50317D01* -X278852Y50363D01* -X278930Y50406D01* -X279004Y50441D01* -X279086Y50473D01* -X279168Y50500D01* -X279250Y50524D01* -X279336Y50539D01* -X279422Y50551D01* -X279512Y50559D01* -X279602Y50563D01* -X279762Y50555D01* -X279914Y50531D01* -X280059Y50496D01* -X280199Y50445D01* -X280262Y50414D01* -X280324Y50383D01* -X280383Y50348D01* -X280433Y50313D01* -X280484Y50274D01* -X280527Y50234D01* -X280570Y50191D01* -X280606Y50144D01* -X280668Y50051D01* -X280723Y49953D01* -X280766Y49848D01* -X280797Y49734D01* -X280809Y49672D01* -X280820Y49606D01* -X280832Y49531D01* -X280840Y49453D01* -X280844Y49367D01* -X280848Y49274D01* -X280852Y49176D01* -Y49074D01* -Y46766D01* -X281621Y48676D02* -X281625Y48797D01* -X281637Y48918D01* -X281656Y49039D01* -X281680Y49156D01* -X281715Y49274D01* -X281758Y49391D01* -X281805Y49508D01* -X281863Y49621D01* -X281926Y49734D01* -X281996Y49836D01* -X282070Y49933D01* -X282156Y50027D01* -X282242Y50109D01* -X282340Y50187D01* -X282441Y50258D01* -X282547Y50320D01* -X282660Y50379D01* -X282774Y50426D01* -X282894Y50469D01* -X283016Y50500D01* -X283141Y50527D01* -X283270Y50547D01* -X283402Y50559D01* -X283535Y50563D01* -X283641Y50559D01* -X283742Y50555D01* -X283840Y50543D01* -X283937Y50527D01* -X284031Y50508D01* -X284125Y50484D01* -X284215Y50457D01* -X284305Y50426D01* -X284387Y50391D01* -X284473Y50348D01* -X284551Y50305D01* -X284629Y50254D01* -X284707Y50199D01* -X284777Y50144D01* -X284848Y50082D01* -X284918Y50016D01* -X284984Y49945D01* -X285043Y49875D01* -X285102Y49801D01* -X285152Y49723D01* -X285203Y49644D01* -X285246Y49567D01* -X285285Y49480D01* -X285324Y49394D01* -X285356Y49309D01* -X285383Y49219D01* -X285406Y49129D01* -X285422Y49031D01* -X285437Y48937D01* -X285449Y48836D01* -X285453Y48738D01* -X285457Y48633D01* -X285453Y48527D01* -X285449Y48426D01* -X285437Y48328D01* -X285422Y48230D01* -X285402Y48137D01* -X285379Y48043D01* -X285352Y47953D01* -X285320Y47863D01* -X285285Y47777D01* -X285246Y47691D01* -X285199Y47613D01* -X285152Y47531D01* -X285098Y47453D01* -X285039Y47379D01* -X284980Y47309D01* -X284914Y47238D01* -X284844Y47172D01* -X284774Y47106D01* -X284699Y47051D01* -X284625Y46996D01* -X284547Y46945D01* -X284465Y46898D01* -X284383Y46859D01* -X284297Y46820D01* -X284211Y46789D01* -X284121Y46762D01* -X284031Y46738D01* -X283937Y46719D01* -X283844Y46703D01* -X283746Y46691D01* -X283644Y46687D01* -X283543Y46683D01* -X283414Y46687D01* -X283289Y46699D01* -X283168Y46715D01* -X283043Y46742D01* -X282922Y46774D01* -X282805Y46813D01* -X282683Y46859D01* -X282567Y46914D01* -X282457Y46976D01* -X282352Y47043D01* -X282250Y47117D01* -X282160Y47199D01* -X282074Y47285D01* -X281996Y47379D01* -X281926Y47480D01* -X281863Y47590D01* -X281805Y47703D01* -X281758Y47824D01* -X281715Y47953D01* -X281680Y48082D01* -X281656Y48223D01* -X281637Y48367D01* -X281625Y48520D01* -X281621Y48676D01* -X282629Y48621D02* -X282633Y48488D01* -X282644Y48363D01* -X282664Y48246D01* -X282695Y48137D01* -X282730Y48035D01* -X282777Y47941D01* -X282828Y47856D01* -X282891Y47777D01* -X282961Y47707D01* -X283031Y47648D01* -X283106Y47598D01* -X283183Y47559D01* -X283266Y47524D01* -X283356Y47504D01* -X283445Y47488D01* -X283539Y47484D01* -X283633Y47488D01* -X283723Y47504D01* -X283809Y47524D01* -X283894Y47559D01* -X283973Y47598D01* -X284047Y47648D01* -X284117Y47707D01* -X284183Y47777D01* -X284246Y47856D01* -X284297Y47941D01* -X284344Y48035D01* -X284379Y48137D01* -X284410Y48246D01* -X284430Y48367D01* -X284441Y48492D01* -X284445Y48629D01* -X284441Y48762D01* -X284430Y48887D01* -X284410Y49004D01* -X284379Y49113D01* -X284344Y49211D01* -X284297Y49305D01* -X284246Y49391D01* -X284183Y49469D01* -X284117Y49535D01* -X284047Y49598D01* -X283973Y49648D01* -X283894Y49687D01* -X283809Y49719D01* -X283723Y49742D01* -X283633Y49758D01* -X283539Y49762D01* -X283445Y49758D01* -X283356Y49742D01* -X283266Y49719D01* -X283183Y49687D01* -X283106Y49648D01* -X283031Y49598D01* -X282961Y49535D01* -X282891Y49469D01* -X282828Y49391D01* -X282777Y49305D01* -X282730Y49211D01* -X282695Y49109D01* -X282664Y49000D01* -X282644Y48883D01* -X282633Y48758D01* -X282629Y48621D01* -X286226Y46766D02* -Y51891D01* -X287211D01* -Y46766D01* -X286226D01* -X287984Y48676D02* -X287988Y48797D01* -X288000Y48918D01* -X288020Y49039D01* -X288043Y49156D01* -X288078Y49274D01* -X288121Y49391D01* -X288168Y49508D01* -X288226Y49621D01* -X288289Y49734D01* -X288359Y49836D01* -X288433Y49933D01* -X288520Y50027D01* -X288606Y50109D01* -X288703Y50187D01* -X288805Y50258D01* -X288910Y50320D01* -X289024Y50379D01* -X289137Y50426D01* -X289258Y50469D01* -X289379Y50500D01* -X289504Y50527D01* -X289633Y50547D01* -X289766Y50559D01* -X289898Y50563D01* -X290004Y50559D01* -X290106Y50555D01* -X290203Y50543D01* -X290301Y50527D01* -X290394Y50508D01* -X290488Y50484D01* -X290578Y50457D01* -X290668Y50426D01* -X290750Y50391D01* -X290836Y50348D01* -X290914Y50305D01* -X290992Y50254D01* -X291070Y50199D01* -X291141Y50144D01* -X291211Y50082D01* -X291281Y50016D01* -X291348Y49945D01* -X291406Y49875D01* -X291465Y49801D01* -X291516Y49723D01* -X291567Y49644D01* -X291609Y49567D01* -X291648Y49480D01* -X291687Y49394D01* -X291719Y49309D01* -X291746Y49219D01* -X291770Y49129D01* -X291785Y49031D01* -X291801Y48937D01* -X291813Y48836D01* -X291817Y48738D01* -X291820Y48633D01* -X291817Y48527D01* -X291813Y48426D01* -X291801Y48328D01* -X291785Y48230D01* -X291766Y48137D01* -X291742Y48043D01* -X291715Y47953D01* -X291683Y47863D01* -X291648Y47777D01* -X291609Y47691D01* -X291563Y47613D01* -X291516Y47531D01* -X291461Y47453D01* -X291402Y47379D01* -X291344Y47309D01* -X291277Y47238D01* -X291207Y47172D01* -X291137Y47106D01* -X291063Y47051D01* -X290988Y46996D01* -X290910Y46945D01* -X290828Y46898D01* -X290746Y46859D01* -X290660Y46820D01* -X290574Y46789D01* -X290484Y46762D01* -X290394Y46738D01* -X290301Y46719D01* -X290207Y46703D01* -X290109Y46691D01* -X290008Y46687D01* -X289906Y46683D01* -X289777Y46687D01* -X289652Y46699D01* -X289531Y46715D01* -X289406Y46742D01* -X289285Y46774D01* -X289168Y46813D01* -X289047Y46859D01* -X288930Y46914D01* -X288820Y46976D01* -X288715Y47043D01* -X288613Y47117D01* -X288524Y47199D01* -X288437Y47285D01* -X288359Y47379D01* -X288289Y47480D01* -X288226Y47590D01* -X288168Y47703D01* -X288121Y47824D01* -X288078Y47953D01* -X288043Y48082D01* -X288020Y48223D01* -X288000Y48367D01* -X287988Y48520D01* -X287984Y48676D01* -X288992Y48621D02* -X288996Y48488D01* -X289008Y48363D01* -X289027Y48246D01* -X289059Y48137D01* -X289094Y48035D01* -X289141Y47941D01* -X289191Y47856D01* -X289254Y47777D01* -X289324Y47707D01* -X289394Y47648D01* -X289469Y47598D01* -X289547Y47559D01* -X289629Y47524D01* -X289719Y47504D01* -X289809Y47488D01* -X289902Y47484D01* -X289996Y47488D01* -X290086Y47504D01* -X290172Y47524D01* -X290258Y47559D01* -X290336Y47598D01* -X290410Y47648D01* -X290480Y47707D01* -X290547Y47777D01* -X290609Y47856D01* -X290660Y47941D01* -X290707Y48035D01* -X290742Y48137D01* -X290774Y48246D01* -X290793Y48367D01* -X290805Y48492D01* -X290809Y48629D01* -X290805Y48762D01* -X290793Y48887D01* -X290774Y49004D01* -X290742Y49113D01* -X290707Y49211D01* -X290660Y49305D01* -X290609Y49391D01* -X290547Y49469D01* -X290480Y49535D01* -X290410Y49598D01* -X290336Y49648D01* -X290258Y49687D01* -X290172Y49719D01* -X290086Y49742D01* -X289996Y49758D01* -X289902Y49762D01* -X289809Y49758D01* -X289719Y49742D01* -X289629Y49719D01* -X289547Y49687D01* -X289469Y49648D01* -X289394Y49598D01* -X289324Y49535D01* -X289254Y49469D01* -X289191Y49391D01* -X289141Y49305D01* -X289094Y49211D01* -X289059Y49109D01* -X289027Y49000D01* -X289008Y48883D01* -X288996Y48758D01* -X288992Y48621D01* -X292492Y46524D02* -X293613Y46387D01* -X293633Y46297D01* -X293660Y46219D01* -X293695Y46160D01* -X293719Y46133D01* -X293742Y46113D01* -X293781Y46090D01* -X293824Y46067D01* -X293871Y46051D01* -X293926Y46035D01* -X293980Y46024D01* -X294047Y46016D01* -X294113Y46008D01* -X294187D01* -X294281D01* -X294367Y46016D01* -X294449Y46024D01* -X294524Y46035D01* -X294594Y46055D01* -X294656Y46074D01* -X294715Y46098D01* -X294766Y46125D01* -X294828Y46168D01* -X294879Y46223D01* -X294926Y46293D01* -X294961Y46371D01* -X294973Y46406D01* -X294980Y46445D01* -X294988Y46492D01* -X294996Y46547D01* -X295000Y46606D01* -X295004Y46672D01* -X295008Y46746D01* -Y46824D01* -X295012Y47367D01* -X294957Y47297D01* -X294898Y47226D01* -X294840Y47164D01* -X294777Y47106D01* -X294715Y47051D01* -X294648Y47000D01* -X294582Y46957D01* -X294512Y46918D01* -X294441Y46879D01* -X294371Y46852D01* -X294297Y46824D01* -X294219Y46805D01* -X294141Y46785D01* -X294063Y46774D01* -X293980Y46770D01* -X293898Y46766D01* -X293805Y46770D01* -X293715Y46774D01* -X293629Y46789D01* -X293543Y46805D01* -X293461Y46828D01* -X293379Y46856D01* -X293301Y46887D01* -X293226Y46922D01* -X293152Y46965D01* -X293082Y47012D01* -X293016Y47067D01* -X292949Y47121D01* -X292887Y47183D01* -X292824Y47250D01* -X292766Y47320D01* -X292711Y47398D01* -X292629Y47527D01* -X292559Y47664D01* -X292500Y47809D01* -X292453Y47961D01* -X292414Y48117D01* -X292391Y48285D01* -X292371Y48461D01* -X292367Y48644D01* -X292375Y48871D01* -X292394Y49082D01* -X292430Y49281D01* -X292480Y49465D01* -X292543Y49637D01* -X292621Y49797D01* -X292711Y49937D01* -X292817Y50070D01* -X292933Y50183D01* -X293055Y50285D01* -X293183Y50371D01* -X293320Y50437D01* -X293465Y50492D01* -X293617Y50531D01* -X293774Y50555D01* -X293937Y50563D01* -X294020Y50559D01* -X294106Y50555D01* -X294187Y50543D01* -X294266Y50524D01* -X294344Y50504D01* -X294418Y50476D01* -X294492Y50445D01* -X294567Y50410D01* -X294637Y50371D01* -X294703Y50328D01* -X294770Y50277D01* -X294836Y50223D01* -X294898Y50164D01* -X294957Y50102D01* -X295016Y50031D01* -X295074Y49957D01* -Y50480D01* -X295992D01* -Y47148D01* -Y46988D01* -X295984Y46840D01* -X295976Y46699D01* -X295965Y46570D01* -X295949Y46453D01* -X295930Y46348D01* -X295910Y46250D01* -X295883Y46164D01* -X295856Y46086D01* -X295824Y46008D01* -X295789Y45937D01* -X295754Y45875D01* -X295715Y45813D01* -X295672Y45754D01* -X295625Y45703D01* -X295578Y45652D01* -X295527Y45609D01* -X295473Y45567D01* -X295414Y45524D01* -X295352Y45488D01* -X295281Y45453D01* -X295211Y45418D01* -X295137Y45391D01* -X295055Y45363D01* -X294969Y45336D01* -X294879Y45317D01* -X294785Y45297D01* -X294683Y45285D01* -X294578Y45274D01* -X294465Y45266D01* -X294348Y45258D01* -X294226D01* -X294109D01* -X294000Y45262D01* -X293891Y45270D01* -X293789Y45277D01* -X293687Y45289D01* -X293594Y45305D01* -X293504Y45320D01* -X293418Y45340D01* -X293336Y45359D01* -X293258Y45383D01* -X293187Y45410D01* -X293117Y45441D01* -X293051Y45473D01* -X292992Y45508D01* -X292937Y45543D01* -X292883Y45582D01* -X292793Y45664D01* -X292711Y45754D01* -X292644Y45848D01* -X292586Y45949D01* -X292543Y46055D01* -X292512Y46164D01* -X292496Y46281D01* -X292488Y46402D01* -Y46457D01* -X292492Y46524D01* -X293375Y48699D02* -X293379Y48555D01* -X293391Y48422D01* -X293406Y48301D01* -X293433Y48187D01* -X293465Y48082D01* -X293504Y47988D01* -X293551Y47906D01* -X293606Y47832D01* -X293664Y47770D01* -X293726Y47711D01* -X293789Y47664D01* -X293859Y47625D01* -X293930Y47598D01* -X294008Y47574D01* -X294086Y47563D01* -X294168Y47559D01* -X294258Y47563D01* -X294340Y47574D01* -X294422Y47598D01* -X294500Y47629D01* -X294574Y47668D01* -X294644Y47715D01* -X294711Y47774D01* -X294777Y47840D01* -X294832Y47914D01* -X294883Y47996D01* -X294926Y48090D01* -X294961Y48191D01* -X294988Y48297D01* -X295008Y48414D01* -X295020Y48539D01* -X295024Y48676D01* -X295020Y48817D01* -X295008Y48945D01* -X294988Y49067D01* -X294965Y49180D01* -X294930Y49281D01* -X294891Y49375D01* -X294840Y49457D01* -X294785Y49531D01* -X294726Y49598D01* -X294660Y49656D01* -X294590Y49703D01* -X294516Y49742D01* -X294441Y49774D01* -X294359Y49793D01* -X294274Y49809D01* -X294183Y49813D01* -X294098Y49809D01* -X294016Y49797D01* -X293937Y49774D01* -X293863Y49742D01* -X293793Y49703D01* -X293726Y49656D01* -X293664Y49602D01* -X293606Y49539D01* -X293551Y49465D01* -X293504Y49383D01* -X293465Y49289D01* -X293433Y49191D01* -X293406Y49082D01* -X293391Y48965D01* -X293379Y48836D01* -X293375Y48699D01* -X296500Y50480D02* -X297547D01* -X298437Y47844D01* -X299301Y50480D01* -X300317D01* -X299012Y46902D01* -X298774Y46258D01* -X298742Y46176D01* -X298711Y46102D01* -X298680Y46035D01* -X298648Y45969D01* -X298617Y45910D01* -X298586Y45856D01* -X298559Y45805D01* -X298527Y45762D01* -X298465Y45680D01* -X298402Y45606D01* -X298332Y45539D01* -X298258Y45484D01* -X298176Y45433D01* -X298090Y45387D01* -X297988Y45352D01* -X297883Y45317D01* -X297770Y45293D01* -X297648Y45274D01* -X297516Y45262D01* -X297379Y45258D01* -X297238Y45262D01* -X297102Y45274D01* -X296961Y45289D01* -X296824Y45317D01* -X296738Y46086D01* -X296852Y46067D01* -X296957Y46051D01* -X297059Y46043D01* -X297156Y46039D01* -X297238Y46043D01* -X297317Y46051D01* -X297387Y46067D01* -X297453Y46090D01* -X297516Y46117D01* -X297570Y46152D01* -X297617Y46191D01* -X297664Y46242D01* -X297738Y46348D01* -X297809Y46469D01* -X297867Y46606D01* -X297914Y46754D01* -X296500Y50480D01* -X306219Y48652D02* -X307223Y48336D01* -X307160Y48133D01* -X307090Y47941D01* -X307008Y47766D01* -X306914Y47602D01* -X306817Y47453D01* -X306703Y47317D01* -X306586Y47195D01* -X306457Y47086D01* -X306317Y46992D01* -X306168Y46910D01* -X306012Y46840D01* -X305848Y46781D01* -X305672Y46738D01* -X305488Y46703D01* -X305297Y46687D01* -X305094Y46680D01* -X304969Y46683D01* -X304844Y46691D01* -X304723Y46703D01* -X304606Y46723D01* -X304492Y46746D01* -X304379Y46777D01* -X304270Y46813D01* -X304164Y46856D01* -X304059Y46898D01* -X303961Y46953D01* -X303863Y47008D01* -X303766Y47070D01* -X303676Y47141D01* -X303586Y47215D01* -X303500Y47293D01* -X303414Y47375D01* -X303336Y47465D01* -X303262Y47559D01* -X303191Y47656D01* -X303129Y47758D01* -X303070Y47863D01* -X303016Y47973D01* -X302965Y48086D01* -X302922Y48203D01* -X302883Y48324D01* -X302852Y48449D01* -X302820Y48578D01* -X302801Y48711D01* -X302781Y48848D01* -X302770Y48988D01* -X302762Y49133D01* -X302758Y49281D01* -X302762Y49441D01* -X302770Y49594D01* -X302781Y49742D01* -X302801Y49887D01* -X302824Y50027D01* -X302852Y50160D01* -X302883Y50293D01* -X302922Y50418D01* -X302969Y50539D01* -X303016Y50656D01* -X303070Y50770D01* -X303129Y50879D01* -X303195Y50984D01* -X303266Y51082D01* -X303340Y51180D01* -X303418Y51270D01* -X303504Y51356D01* -X303590Y51433D01* -X303680Y51508D01* -X303774Y51578D01* -X303871Y51641D01* -X303973Y51699D01* -X304074Y51754D01* -X304183Y51801D01* -X304293Y51840D01* -X304406Y51875D01* -X304524Y51906D01* -X304644Y51933D01* -X304766Y51953D01* -X304894Y51965D01* -X305024Y51973D01* -X305156Y51976D01* -X305274Y51973D01* -X305387Y51969D01* -X305496Y51957D01* -X305602Y51941D01* -X305707Y51922D01* -X305813Y51898D01* -X305910Y51871D01* -X306008Y51836D01* -X306102Y51801D01* -X306191Y51758D01* -X306281Y51715D01* -X306367Y51664D01* -X306449Y51609D01* -X306531Y51551D01* -X306609Y51488D01* -X306683Y51422D01* -X306766Y51336D01* -X306848Y51238D01* -X306922Y51137D01* -X306988Y51024D01* -X307051Y50898D01* -X307109Y50770D01* -X307160Y50629D01* -X307207Y50480D01* -X306183Y50234D01* -X306156Y50332D01* -X306125Y50422D01* -X306086Y50508D01* -X306043Y50590D01* -X305992Y50668D01* -X305937Y50738D01* -X305875Y50801D01* -X305805Y50863D01* -X305730Y50918D01* -X305652Y50965D01* -X305570Y51004D01* -X305484Y51035D01* -X305394Y51063D01* -X305301Y51078D01* -X305203Y51090D01* -X305106Y51094D01* -X304965Y51086D01* -X304832Y51067D01* -X304707Y51035D01* -X304586Y50992D01* -X304476Y50933D01* -X304371Y50863D01* -X304270Y50781D01* -X304180Y50683D01* -X304137Y50633D01* -X304098Y50574D01* -X304059Y50512D01* -X304024Y50449D01* -X303992Y50379D01* -X303965Y50305D01* -X303937Y50230D01* -X303914Y50148D01* -X303891Y50063D01* -X303875Y49976D01* -X303859Y49883D01* -X303848Y49785D01* -X303836Y49683D01* -X303828Y49582D01* -X303824Y49473D01* -Y49359D01* -Y49238D01* -X303828Y49125D01* -X303836Y49016D01* -X303848Y48910D01* -X303859Y48805D01* -X303875Y48707D01* -X303891Y48617D01* -X303910Y48527D01* -X303933Y48441D01* -X303961Y48363D01* -X303988Y48289D01* -X304020Y48215D01* -X304055Y48148D01* -X304094Y48086D01* -X304133Y48027D01* -X304176Y47976D01* -X304266Y47879D01* -X304363Y47793D01* -X304465Y47723D01* -X304574Y47664D01* -X304691Y47621D01* -X304817Y47590D01* -X304945Y47570D01* -X305082Y47563D01* -X305183Y47567D01* -X305281Y47578D01* -X305375Y47598D01* -X305465Y47629D01* -X305555Y47664D01* -X305637Y47711D01* -X305715Y47762D01* -X305793Y47824D01* -X305863Y47894D01* -X305930Y47976D01* -X305992Y48063D01* -X306047Y48164D01* -X306098Y48270D01* -X306144Y48391D01* -X306183Y48516D01* -X306219Y48652D01* -X308106Y46766D02* -Y51891D01* -X309090D01* -Y46766D01* -X308106D01* -X312535D02* -Y47320D01* -X312484Y47250D01* -X312426Y47180D01* -X312363Y47117D01* -X312301Y47055D01* -X312230Y47000D01* -X312160Y46945D01* -X312082Y46898D01* -X312004Y46856D01* -X311918Y46813D01* -X311836Y46777D01* -X311750Y46750D01* -X311664Y46726D01* -X311574Y46707D01* -X311484Y46695D01* -X311394Y46687D01* -X311305Y46683D01* -X311211Y46687D01* -X311121Y46695D01* -X311035Y46707D01* -X310949Y46723D01* -X310867Y46746D01* -X310785Y46777D01* -X310707Y46809D01* -X310633Y46848D01* -X310563Y46891D01* -X310496Y46937D01* -X310433Y46988D01* -X310379Y47043D01* -X310324Y47106D01* -X310281Y47168D01* -X310238Y47238D01* -X310203Y47309D01* -X310172Y47387D01* -X310144Y47473D01* -X310121Y47563D01* -X310106Y47664D01* -X310090Y47770D01* -X310078Y47883D01* -X310074Y48004D01* -X310070Y48129D01* -Y50480D01* -X311055D01* -Y48774D01* -Y48680D01* -Y48590D01* -X311059Y48504D01* -Y48422D01* -Y48344D01* -X311063Y48274D01* -X311067Y48207D01* -X311070Y48144D01* -Y48086D01* -X311074Y48035D01* -X311082Y47984D01* -X311086Y47941D01* -X311090Y47902D01* -X311098Y47871D01* -X311102Y47840D01* -X311109Y47817D01* -X311141Y47730D01* -X311183Y47656D01* -X311238Y47594D01* -X311305Y47535D01* -X311383Y47492D01* -X311469Y47457D01* -X311563Y47441D01* -X311668Y47433D01* -X311730D01* -X311793Y47441D01* -X311852Y47453D01* -X311906Y47469D01* -X311961Y47488D01* -X312016Y47512D01* -X312070Y47539D01* -X312121Y47570D01* -X312168Y47606D01* -X312211Y47644D01* -X312250Y47683D01* -X312285Y47726D01* -X312320Y47770D01* -X312348Y47817D01* -X312371Y47863D01* -X312391Y47914D01* -X312402Y47941D01* -X312410Y47973D01* -X312418Y48012D01* -X312422Y48055D01* -X312430Y48098D01* -X312437Y48148D01* -X312441Y48207D01* -X312445Y48266D01* -X312449Y48332D01* -X312453Y48402D01* -X312457Y48476D01* -X312461Y48555D01* -Y48637D01* -X312465Y48726D01* -Y48817D01* -Y48914D01* -Y50480D01* -X313449D01* -Y46766D01* -X312535D01* -X314426D02* -Y51891D01* -X315410D01* -Y50043D01* -X315469Y50106D01* -X315527Y50164D01* -X315586Y50219D01* -X315648Y50270D01* -X315711Y50317D01* -X315774Y50359D01* -X315840Y50398D01* -X315906Y50433D01* -X315973Y50465D01* -X316043Y50488D01* -X316113Y50512D01* -X316187Y50531D01* -X316258Y50543D01* -X316332Y50555D01* -X316410Y50559D01* -X316484Y50563D01* -X316652Y50555D01* -X316809Y50531D01* -X316961Y50492D01* -X317106Y50437D01* -X317242Y50371D01* -X317371Y50285D01* -X317492Y50187D01* -X317606Y50070D01* -X317711Y49941D01* -X317801Y49801D01* -X317879Y49644D01* -X317941Y49473D01* -X317988Y49289D01* -X318024Y49094D01* -X318043Y48883D01* -X318051Y48660D01* -X318043Y48430D01* -X318024Y48215D01* -X317988Y48008D01* -X317937Y47820D01* -X317875Y47644D01* -X317797Y47480D01* -X317703Y47332D01* -X317598Y47195D01* -X317543Y47133D01* -X317480Y47078D01* -X317422Y47024D01* -X317359Y46973D01* -X317297Y46926D01* -X317230Y46883D01* -X317164Y46848D01* -X317098Y46813D01* -X317027Y46781D01* -X316957Y46754D01* -X316887Y46734D01* -X316813Y46715D01* -X316734Y46703D01* -X316660Y46691D01* -X316578Y46683D01* -X316500D01* -X316422Y46687D01* -X316340Y46691D01* -X316262Y46707D01* -X316183Y46723D01* -X316106Y46746D01* -X316027Y46774D01* -X315949Y46805D01* -X315871Y46840D01* -X315797Y46883D01* -X315723Y46930D01* -X315652Y46980D01* -X315586Y47039D01* -X315520Y47098D01* -X315457Y47164D01* -X315398Y47234D01* -X315340Y47313D01* -Y46766D01* -X314426D01* -X315402Y48703D02* -X315406Y48567D01* -X315414Y48433D01* -X315430Y48313D01* -X315449Y48203D01* -X315473Y48102D01* -X315504Y48008D01* -X315543Y47926D01* -X315582Y47852D01* -X315648Y47762D01* -X315723Y47680D01* -X315797Y47613D01* -X315879Y47559D01* -X315969Y47516D01* -X316059Y47484D01* -X316156Y47469D01* -X316262Y47461D01* -X316340Y47465D01* -X316418Y47476D01* -X316492Y47500D01* -X316563Y47531D01* -X316629Y47570D01* -X316695Y47617D01* -X316758Y47672D01* -X316817Y47738D01* -X316867Y47813D01* -X316914Y47898D01* -X316953Y47992D01* -X316984Y48098D01* -X317012Y48211D01* -X317027Y48336D01* -X317039Y48469D01* -X317043Y48613D01* -X317039Y48766D01* -X317027Y48910D01* -X317012Y49039D01* -X316984Y49160D01* -X316953Y49270D01* -X316914Y49367D01* -X316867Y49453D01* -X316813Y49531D01* -X316754Y49598D01* -X316687Y49652D01* -X316621Y49703D01* -X316551Y49742D01* -X316473Y49774D01* -X316394Y49793D01* -X316313Y49809D01* -X316223Y49813D01* -X316137Y49809D01* -X316055Y49797D01* -X315976Y49774D01* -X315898Y49742D01* -X315828Y49703D01* -X315762Y49656D01* -X315695Y49602D01* -X315637Y49539D01* -X315582Y49465D01* -X315535Y49383D01* -X315492Y49293D01* -X315461Y49191D01* -X315433Y49082D01* -X315418Y48965D01* -X315406Y48840D01* -X315402Y48703D01* -X293402Y45344D02* -X294993D01* -X296821D02* -X297965D01* -X293126Y45437D02* -X295250D01* -X296811D02* -X298182D01* -X292956Y45531D02* -X295424D01* -X296800D02* -X298321D01* -X292836Y45625D02* -X295545D01* -X296790D02* -X298419D01* -X292743Y45719D02* -X295639D01* -X296780D02* -X298494D01* -X292670Y45812D02* -X295715D01* -X296769D02* -X298563D01* -X292611Y45906D02* -X295771D01* -X296758D02* -X298615D01* -X292565Y46000D02* -X295820D01* -X296748D02* -X298663D01* -X292532Y46093D02* -X293775D01* -X294704D02* -X295858D01* -X297461D02* -X298707D01* -X292509Y46187D02* -X293679D01* -X294846D02* -X295890D01* -X297612D02* -X298746D01* -X292496Y46281D02* -X293638D01* -X294917D02* -X295916D01* -X297691D02* -X298782D01* -X292490Y46374D02* -X293616D01* -X294962D02* -X295935D01* -X297754D02* -X298817D01* -X292489Y46468D02* -X292946D01* -X294984D02* -X295951D01* -X297808D02* -X298851D01* -X294997Y46562D02* -X295964D01* -X297848D02* -X298886D01* -X295003Y46656D02* -X295972D01* -X297883D02* -X298920D01* -X266086Y46749D02* -X267195D01* -X270142D02* -X271251D01* -X283016D02* -X284073D01* -X289379D02* -X290436D01* -X295008D02* -X295979D01* -X297913D02* -X298955D01* -X304481D02* -X305717D01* -X310859D02* -X311750D01* -X316096D02* -X316940D01* -X261926Y46843D02* -X262961D01* -X265802D02* -X267463D01* -X269882D02* -X271523D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282726D02* -X284346D01* -X286226D02* -X287211D01* -X289090D02* -X290710D01* -X293417D02* -X294348D01* -X295008D02* -X295984D01* -X297880D02* -X298990D01* -X304195D02* -X306019D01* -X308106D02* -X309090D01* -X310642D02* -X311979D01* -X312535D02* -X313449D01* -X314426D02* -X315340D01* -X315866D02* -X317155D01* -X261926Y46937D02* -X262961D01* -X265629D02* -X267627D01* -X269706D02* -X271706D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282527D02* -X284532D01* -X286226D02* -X287211D01* -X288890D02* -X290895D01* -X293201D02* -X294545D01* -X295009D02* -X295989D01* -X297845D02* -X299024D01* -X303991D02* -X306216D01* -X308106D02* -X309090D01* -X310497D02* -X312146D01* -X312535D02* -X313449D01* -X314426D02* -X315340D01* -X315713D02* -X317311D01* -X261926Y47030D02* -X262961D01* -X265495D02* -X267762D01* -X269570D02* -X271832D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282372D02* -X284672D01* -X286226D02* -X287211D01* -X288735D02* -X291035D01* -X293059D02* -X294688D01* -X295009D02* -X295992D01* -X297809D02* -X299059D01* -X303828D02* -X306374D01* -X308106D02* -X309090D01* -X310391D02* -X312269D01* -X312535D02* -X313449D01* -X314426D02* -X315340D01* -X315596D02* -X317429D01* -X261926Y47124D02* -X262961D01* -X265388D02* -X267866D01* -X269459D02* -X271940D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282243D02* -X284793D01* -X286226D02* -X287211D01* -X288606D02* -X291156D01* -X292946D02* -X294797D01* -X295010D02* -X295992D01* -X297774D02* -X299093D01* -X303697D02* -X306502D01* -X308106D02* -X309090D01* -X310311D02* -X312370D01* -X312535D02* -X313449D01* -X314426D02* -X315340D01* -X315495D02* -X317533D01* -X261926Y47218D02* -X262961D01* -X265296D02* -X267955D01* -X269368D02* -X272028D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282142D02* -X284893D01* -X286226D02* -X287211D01* -X288505D02* -X291256D01* -X292855D02* -X294890D01* -X295011D02* -X295992D01* -X297738D02* -X299127D01* -X303583D02* -X306607D01* -X308106D02* -X309090D01* -X310251D02* -X312457D01* -X312535D02* -X313449D01* -X314426D02* -X315340D01* -X315412D02* -X317615D01* -X261926Y47311D02* -X262961D01* -X265223D02* -X268029D01* -X269291D02* -X272096D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X282052D02* -X284983D01* -X286226D02* -X287211D01* -X288415D02* -X291346D01* -X292773D02* -X294969D01* -X295011D02* -X295992D01* -X297703D02* -X299161D01* -X303481D02* -X306698D01* -X308106D02* -X309090D01* -X310202D02* -X312528D01* -X312535D02* -X313449D01* -X314426D02* -X317687D01* -X261926Y47405D02* -X262961D01* -X265159D02* -X268089D01* -X269224D02* -X272159D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281978D02* -X285060D01* -X286226D02* -X287211D01* -X288341D02* -X291423D01* -X292707D02* -X295992D01* -X297667D02* -X299195D01* -X303388D02* -X306777D01* -X308106D02* -X309090D01* -X310166D02* -X313449D01* -X314426D02* -X317749D01* -X261926Y47499D02* -X262961D01* -X265104D02* -X266309D01* -X266985D02* -X268143D01* -X269163D02* -X270551D01* -X270888D02* -X272212D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281915D02* -X283385D01* -X283694D02* -X285130D01* -X286226D02* -X287211D01* -X288278D02* -X289748D01* -X290057D02* -X291493D01* -X292647D02* -X295992D01* -X297631D02* -X299229D01* -X303309D02* -X306846D01* -X308106D02* -X309090D01* -X310138D02* -X311370D01* -X311986D02* -X313449D01* -X314426D02* -X316017D01* -X316489D02* -X317806D01* -X261926Y47593D02* -X262961D01* -X265056D02* -X266169D01* -X267103D02* -X268190D01* -X269113D02* -X270317D01* -X271119D02* -X272257D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281862D02* -X283116D01* -X283963D02* -X285187D01* -X286226D02* -X287211D01* -X288225D02* -X289479D01* -X290326D02* -X291551D01* -X292595D02* -X293947D01* -X294404D02* -X295992D01* -X297596D02* -X299263D01* -X303237D02* -X304806D01* -X305351D02* -X306908D01* -X308106D02* -X309090D01* -X310117D02* -X311238D01* -X312151D02* -X313449D01* -X314426D02* -X315828D01* -X316660D02* -X317850D01* -X261926Y47686D02* -X262961D01* -X265016D02* -X266075D01* -X267178D02* -X268232D01* -X269071D02* -X270197D01* -X271230D02* -X272297D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281813D02* -X282986D01* -X284092D02* -X285243D01* -X286226D02* -X287211D01* -X288177D02* -X289349D01* -X290456D02* -X291606D01* -X292550D02* -X293759D01* -X294602D02* -X295992D01* -X297560D02* -X299298D01* -X303173D02* -X304533D01* -X305593D02* -X306963D01* -X308106D02* -X309090D01* -X310102D02* -X311166D01* -X312252D02* -X313449D01* -X314426D02* -X315717D01* -X316770D02* -X317890D01* -X261926Y47780D02* -X262961D01* -X264981D02* -X266005D01* -X267226D02* -X268268D01* -X269035D02* -X270118D01* -X271296D02* -X272330D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281775D02* -X282888D01* -X284186D02* -X285286D01* -X286226D02* -X287211D01* -X288139D02* -X289252D01* -X290549D02* -X291650D01* -X292512D02* -X293654D01* -X294717D02* -X295992D01* -X297525D02* -X299332D01* -X303117D02* -X304382D01* -X305737D02* -X307015D01* -X308106D02* -X309090D01* -X310089D02* -X311123D01* -X312326D02* -X313449D01* -X314426D02* -X315635D01* -X316845D02* -X317923D01* -X261926Y47874D02* -X262961D01* -X264951D02* -X265956D01* -X267266D02* -X267741D01* -X269004D02* -X270059D01* -X271345D02* -X272361D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281741D02* -X282817D01* -X284257D02* -X285324D01* -X286226D02* -X287211D01* -X288105D02* -X289181D01* -X290620D02* -X291687D01* -X292480D02* -X293575D01* -X294802D02* -X295992D01* -X297489D02* -X298427D01* -X298447D02* -X299366D01* -X303065D02* -X304272D01* -X305843D02* -X307058D01* -X308106D02* -X309090D01* -X310079D02* -X311097D01* -X312375D02* -X313449D01* -X314426D02* -X315570D01* -X316901D02* -X317952D01* -X261926Y47967D02* -X262961D01* -X264925D02* -X265921D01* -X268976D02* -X270015D01* -X271379D02* -X272386D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281711D02* -X282764D01* -X284310D02* -X285356D01* -X286226D02* -X287211D01* -X288074D02* -X289128D01* -X290673D02* -X291719D01* -X292452D02* -X293516D01* -X294865D02* -X295992D01* -X297454D02* -X298396D01* -X298478D02* -X299400D01* -X303019D02* -X304184D01* -X305922D02* -X307099D01* -X308106D02* -X309090D01* -X310076D02* -X311083D01* -X312409D02* -X313449D01* -X314426D02* -X315523D01* -X316943D02* -X317977D01* -X261926Y48061D02* -X262961D01* -X264901D02* -X265894D01* -X268957D02* -X269983D01* -X271408D02* -X272204D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281685D02* -X282721D01* -X284353D02* -X285383D01* -X286226D02* -X287211D01* -X288048D02* -X289085D01* -X290716D02* -X291747D01* -X292428D02* -X293474D01* -X294913D02* -X295992D01* -X297418D02* -X298364D01* -X298509D02* -X299434D01* -X302976D02* -X304110D01* -X305991D02* -X307134D01* -X308106D02* -X309090D01* -X310072D02* -X311072D01* -X312423D02* -X313449D01* -X314426D02* -X315486D01* -X316974D02* -X317997D01* -X261926Y48155D02* -X262961D01* -X264887D02* -X265876D01* -X268940D02* -X269959D01* -X271430D02* -X271653D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281668D02* -X282690D01* -X284384D02* -X285406D01* -X286226D02* -X287211D01* -X288031D02* -X289054D01* -X290747D02* -X291769D01* -X292409D02* -X293443D01* -X294948D02* -X295992D01* -X297383D02* -X298332D01* -X298539D02* -X299469D01* -X302940D02* -X304052D01* -X306042D02* -X307167D01* -X308106D02* -X309090D01* -X310070D02* -X311070D01* -X312438D02* -X313449D01* -X314426D02* -X315461D01* -X316998D02* -X318013D01* -X261926Y48248D02* -X262961D01* -X264873D02* -X265866D01* -X268927D02* -X269941D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281653D02* -X282664D01* -X284411D02* -X285425D01* -X286226D02* -X287211D01* -X288016D02* -X289027D01* -X290774D02* -X291788D01* -X292396D02* -X293419D01* -X294976D02* -X295992D01* -X297347D02* -X298301D01* -X298570D02* -X299503D01* -X302907D02* -X304006D01* -X306087D02* -X307196D01* -X308106D02* -X309090D01* -X310070D02* -X311064D01* -X312444D02* -X313449D01* -X314426D02* -X315441D01* -X317017D02* -X318027D01* -X261926Y48342D02* -X262961D01* -X264865D02* -X268320D01* -X268917D02* -X269930D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281640D02* -X282648D01* -X284426D02* -X285439D01* -X286226D02* -X287211D01* -X288004D02* -X289011D01* -X290789D02* -X291802D01* -X292384D02* -X293401D01* -X294996D02* -X295992D01* -X297311D02* -X298269D01* -X298601D02* -X299537D01* -X302878D02* -X303969D01* -X306126D02* -X307203D01* -X308106D02* -X309090D01* -X310070D02* -X311059D01* -X312450D02* -X313449D01* -X314426D02* -X315426D01* -X317028D02* -X318035D01* -X261926Y48436D02* -X262961D01* -X264858D02* -X268320D01* -X268909D02* -X269922D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281631D02* -X282638D01* -X284436D02* -X285450D01* -X286226D02* -X287211D01* -X287995D02* -X289001D01* -X290799D02* -X291813D01* -X292374D02* -X293389D01* -X295010D02* -X295992D01* -X297276D02* -X298237D01* -X298631D02* -X299571D01* -X302855D02* -X303935D01* -X306159D02* -X306906D01* -X308106D02* -X309090D01* -X310070D02* -X311059D01* -X312455D02* -X313449D01* -X314426D02* -X315414D01* -X317036D02* -X318043D01* -X261926Y48530D02* -X262961D01* -X264854D02* -X268319D01* -X268906D02* -X269914D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278449D01* -X279867D02* -X280852D01* -X281625D02* -X282631D01* -X284443D02* -X285453D01* -X286226D02* -X287211D01* -X287988D02* -X288995D01* -X290806D02* -X291817D01* -X292370D02* -X293381D01* -X295019D02* -X295992D01* -X297240D02* -X298206D01* -X298662D02* -X299605D01* -X302832D02* -X303910D01* -X306187D02* -X306609D01* -X308106D02* -X309090D01* -X310070D02* -X311057D01* -X312460D02* -X313449D01* -X314426D02* -X315409D01* -X317041D02* -X318046D01* -X261926Y48623D02* -X262961D01* -X264853D02* -X268316D01* -X268902D02* -X269912D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278450D01* -X279867D02* -X280852D01* -X281622D02* -X282629D01* -X284445D02* -X285457D01* -X286226D02* -X287211D01* -X287985D02* -X288992D01* -X290809D02* -X291820D01* -X292368D02* -X293377D01* -X295022D02* -X295992D01* -X297205D02* -X298174D01* -X298693D02* -X299639D01* -X302814D02* -X303889D01* -X306211D02* -X306311D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312461D02* -X313449D01* -X314426D02* -X315405D01* -X317043D02* -X318050D01* -X261926Y48717D02* -X262961D01* -X264856D02* -X268313D01* -X268906D02* -X269911D01* -X273098D02* -X274082D01* -X275492D02* -X276476D01* -X277465D02* -X278453D01* -X279867D02* -X280852D01* -X281622D02* -X282631D01* -X284443D02* -X285454D01* -X286226D02* -X287211D01* -X287985D02* -X288995D01* -X290806D02* -X291817D01* -X292370D02* -X293376D01* -X295022D02* -X295992D01* -X297169D02* -X298143D01* -X298723D02* -X299674D01* -X302800D02* -X303874D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315403D01* -X317040D02* -X318049D01* -X261926Y48811D02* -X262961D01* -X264859D02* -X268306D01* -X268909D02* -X269914D01* -X273098D02* -X274085D01* -X275492D02* -X276476D01* -X277465D02* -X278458D01* -X279867D02* -X280852D01* -X281626D02* -X282638D01* -X284437D02* -X285450D01* -X286226D02* -X287211D01* -X287989D02* -X289001D01* -X290800D02* -X291814D01* -X292373D02* -X293378D01* -X295020D02* -X295992D01* -X297133D02* -X298111D01* -X298754D02* -X299707D01* -X302787D02* -X303859D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315406D01* -X317035D02* -X318045D01* -X261926Y48904D02* -X262961D01* -X264869D02* -X268296D01* -X268917D02* -X269920D01* -X273098D02* -X274091D01* -X275491D02* -X276476D01* -X277465D02* -X278464D01* -X279864D02* -X280852D01* -X281635D02* -X282648D01* -X284427D02* -X285441D01* -X286226D02* -X287211D01* -X287999D02* -X289011D01* -X290790D02* -X291805D01* -X292378D02* -X293385D01* -X295012D02* -X295992D01* -X297098D02* -X298079D01* -X298785D02* -X299742D01* -X302776D02* -X303848D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315412D01* -X317028D02* -X318041D01* -X261926Y48998D02* -X262961D01* -X264879D02* -X265877D01* -X267341D02* -X268283D01* -X268927D02* -X269930D01* -X273098D02* -X274100D01* -X275488D02* -X276476D01* -X277465D02* -X278472D01* -X279861D02* -X280852D01* -X281650D02* -X282664D01* -X284411D02* -X285428D01* -X286226D02* -X287211D01* -X288013D02* -X289027D01* -X290774D02* -X291791D01* -X292387D02* -X293395D01* -X294999D02* -X295992D01* -X297063D02* -X298048D01* -X298815D02* -X299776D01* -X302769D02* -X303838D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315422D01* -X317017D02* -X318032D01* -X261926Y49092D02* -X262961D01* -X264893D02* -X265883D01* -X267334D02* -X268268D01* -X268941D02* -X269943D01* -X273098D02* -X274113D01* -X275485D02* -X276476D01* -X277465D02* -X278483D01* -X279857D02* -X280852D01* -X281667D02* -X282690D01* -X284385D02* -X285412D01* -X286226D02* -X287211D01* -X288030D02* -X289054D01* -X290748D02* -X291776D01* -X292396D02* -X293409D01* -X294983D02* -X295992D01* -X297027D02* -X298016D01* -X298846D02* -X299810D01* -X302764D02* -X303830D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315436D01* -X317000D02* -X318024D01* -X261926Y49185D02* -X262961D01* -X264910D02* -X265896D01* -X267318D02* -X268248D01* -X268960D02* -X269963D01* -X273098D02* -X274130D01* -X275478D02* -X276472D01* -X277465D02* -X278497D01* -X279849D02* -X280851D01* -X281688D02* -X282722D01* -X284353D02* -X285391D01* -X286226D02* -X287211D01* -X288052D02* -X289085D01* -X290716D02* -X291755D01* -X292413D02* -X293432D01* -X294963D02* -X295992D01* -X296991D02* -X297984D01* -X298877D02* -X299844D01* -X302760D02* -X303826D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315459D01* -X316977D02* -X318007D01* -X261926Y49279D02* -X262961D01* -X264932D02* -X265919D01* -X267295D02* -X268226D01* -X268981D02* -X269991D01* -X271367D02* -X271780D01* -X273098D02* -X274152D01* -X275470D02* -X276469D01* -X277465D02* -X278518D01* -X279839D02* -X280847D01* -X281717D02* -X282764D01* -X284309D02* -X285365D01* -X286226D02* -X287211D01* -X288080D02* -X289128D01* -X290673D02* -X291728D01* -X292429D02* -X293462D01* -X294930D02* -X295992D01* -X296956D02* -X297953D01* -X298907D02* -X299878D01* -X302758D02* -X303824D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315488D01* -X316949D02* -X317990D01* -X261926Y49373D02* -X262961D01* -X264959D02* -X265955D01* -X267263D02* -X268202D01* -X269006D02* -X270026D01* -X271340D02* -X272297D01* -X273098D02* -X274189D01* -X275459D02* -X276465D01* -X277465D02* -X278553D01* -X279824D02* -X280843D01* -X281751D02* -X282817D01* -X284257D02* -X285332D01* -X286226D02* -X287211D01* -X288115D02* -X289181D01* -X290620D02* -X291695D01* -X292455D02* -X293500D01* -X294891D02* -X295992D01* -X296920D02* -X297921D01* -X298938D02* -X299913D01* -X302760D02* -X303824D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315530D01* -X316911D02* -X317967D01* -X261926Y49467D02* -X262961D01* -X264991D02* -X266003D01* -X267214D02* -X268173D01* -X269035D02* -X270077D01* -X271301D02* -X272324D01* -X273098D02* -X274236D01* -X275438D02* -X276457D01* -X277465D02* -X278602D01* -X279794D02* -X280839D01* -X281788D02* -X282889D01* -X284185D02* -X285291D01* -X286226D02* -X287211D01* -X288152D02* -X289252D01* -X290549D02* -X291655D01* -X292481D02* -X293551D01* -X294833D02* -X295992D01* -X296885D02* -X297889D01* -X298969D02* -X299947D01* -X302763D02* -X303824D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315582D01* -X316858D02* -X317943D01* -X261926Y49560D02* -X262961D01* -X265028D02* -X266069D01* -X267149D02* -X268137D01* -X269074D02* -X270152D01* -X271237D02* -X272291D01* -X273098D02* -X274302D01* -X275391D02* -X276447D01* -X277465D02* -X278673D01* -X279746D02* -X280828D01* -X281832D02* -X282989D01* -X284089D02* -X285249D01* -X286226D02* -X287211D01* -X288195D02* -X289353D01* -X290452D02* -X291612D01* -X292515D02* -X293626D01* -X294759D02* -X295992D01* -X296849D02* -X297857D01* -X299000D02* -X299981D01* -X302768D02* -X303827D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315657D01* -X316787D02* -X317909D01* -X261926Y49654D02* -X262961D01* -X265073D02* -X266163D01* -X267054D02* -X268096D01* -X269117D02* -X270259D01* -X271144D02* -X272253D01* -X273098D02* -X274403D01* -X275318D02* -X276430D01* -X277465D02* -X278777D01* -X279670D02* -X280812D01* -X281881D02* -X283117D01* -X283962D02* -X285197D01* -X286226D02* -X287211D01* -X288244D02* -X289480D01* -X290325D02* -X291560D01* -X292552D02* -X293724D01* -X294663D02* -X295992D01* -X296814D02* -X297826D01* -X299030D02* -X300015D01* -X302774D02* -X303833D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315759D01* -X316685D02* -X317874D01* -X261926Y49748D02* -X262961D01* -X265122D02* -X266309D01* -X266911D02* -X268047D01* -X269164D02* -X270440D01* -X270976D02* -X272206D01* -X273098D02* -X274551D01* -X275189D02* -X276407D01* -X277465D02* -X278937D01* -X279545D02* -X280793D01* -X281935D02* -X283387D01* -X283691D02* -X285136D01* -X286226D02* -X287211D01* -X288298D02* -X289750D01* -X290054D02* -X291500D01* -X292597D02* -X293876D01* -X294503D02* -X295992D01* -X296778D02* -X297794D01* -X299061D02* -X300049D01* -X302782D02* -X303843D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315912D01* -X316537D02* -X317827D01* -X261926Y49841D02* -X262961D01* -X265183D02* -X267991D01* -X269224D02* -X272156D01* -X273098D02* -X276379D01* -X277465D02* -X280767D01* -X282000D02* -X285069D01* -X286226D02* -X287211D01* -X288364D02* -X291433D01* -X292650D02* -X295992D01* -X296743D02* -X297763D01* -X299092D02* -X300083D01* -X302794D02* -X303854D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X317775D01* -X261926Y49935D02* -X262961D01* -X265250D02* -X267929D01* -X269291D02* -X272098D01* -X273098D02* -X276343D01* -X277465D02* -X278379D01* -X278380D02* -X280730D01* -X282072D02* -X284993D01* -X286226D02* -X287211D01* -X288435D02* -X291356D01* -X292709D02* -X295992D01* -X296707D02* -X297731D01* -X299122D02* -X300118D01* -X302809D02* -X303868D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X317715D01* -X261926Y50029D02* -X262961D01* -X265327D02* -X267851D01* -X269369D02* -X272030D01* -X273098D02* -X274082D01* -X274097D02* -X276293D01* -X277465D02* -X278379D01* -X278456D02* -X280680D01* -X282158D02* -X284904D01* -X286226D02* -X287211D01* -X288521D02* -X291267D01* -X292783D02* -X295018D01* -X295074D02* -X295992D01* -X296671D02* -X297699D01* -X299153D02* -X300152D01* -X302825D02* -X303885D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X317640D01* -X261926Y50122D02* -X262961D01* -X265418D02* -X267760D01* -X269459D02* -X271947D01* -X273098D02* -X274082D01* -X274185D02* -X276231D01* -X277465D02* -X278379D01* -X278544D02* -X280620D01* -X282258D02* -X284802D01* -X286226D02* -X287211D01* -X288622D02* -X291165D01* -X292870D02* -X294937D01* -X295074D02* -X295992D01* -X296636D02* -X297668D01* -X299183D02* -X300186D01* -X302844D02* -X303907D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315410D01* -X315486D02* -X317555D01* -X261926Y50216D02* -X262961D01* -X265521D02* -X267650D01* -X269573D02* -X271844D01* -X273098D02* -X274082D01* -X274286D02* -X276151D01* -X277465D02* -X278379D01* -X278643D02* -X280545D01* -X282381D02* -X284683D01* -X286226D02* -X287211D01* -X288744D02* -X291046D01* -X292972D02* -X294843D01* -X295074D02* -X295992D01* -X296600D02* -X297636D01* -X299214D02* -X300220D01* -X302865D02* -X303933D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315410D01* -X315583D02* -X317457D01* -X261926Y50310D02* -X262961D01* -X265650D02* -X267519D01* -X269707D02* -X271717D01* -X273098D02* -X274082D01* -X274411D02* -X276043D01* -X277465D02* -X278379D01* -X278768D02* -X280437D01* -X282529D02* -X284541D01* -X286226D02* -X287211D01* -X288892D02* -X290905D01* -X293092D02* -X294727D01* -X295074D02* -X295992D01* -X296565D02* -X297604D01* -X299245D02* -X300254D01* -X302888D02* -X303967D01* -X306163D02* -X306498D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315410D01* -X315702D02* -X317334D01* -X261926Y50404D02* -X262961D01* -X265817D02* -X267346D01* -X269890D02* -X271546D01* -X273098D02* -X274082D01* -X274562D02* -X275894D01* -X277465D02* -X278379D01* -X278924D02* -X280283D01* -X282720D02* -X284356D01* -X286226D02* -X287211D01* -X289083D02* -X290720D01* -X293250D02* -X294579D01* -X295074D02* -X295992D01* -X296529D02* -X297573D01* -X299276D02* -X300289D01* -X302917D02* -X304003D01* -X306131D02* -X306888D01* -X308106D02* -X309090D01* -X310070D02* -X311055D01* -X312465D02* -X313449D01* -X314426D02* -X315410D01* -X315850D02* -X317176D01* -X261926Y50497D02* -X262961D01* -X266069D02* -X267080D01* -X270162D02* -X271268D01* -X273098D02* -X274082D01* -X274787D02* -X275668D01* -X279160D02* -X280059D01* -X283005D02* -X284074D01* -X286226D02* -X287211D01* -X289368D02* -X290437D01* -X293485D02* -X294362D01* -X302953D02* -X304050D01* -X306091D02* -X307202D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X316070D02* -X316941D01* -X261926Y50591D02* -X262961D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X302990D02* -X304109D01* -X306042D02* -X307172D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X261926Y50685D02* -X262961D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303030D02* -X304180D01* -X305979D02* -X307140D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X261926Y50778D02* -X262961D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303075D02* -X304267D01* -X305898D02* -X307106D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X261926Y50872D02* -X262961D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303125D02* -X304384D01* -X305793D02* -X307063D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X261926Y50966D02* -X262961D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303183D02* -X304537D01* -X305651D02* -X307017D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51059D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303250D02* -X304804D01* -X305405D02* -X306967D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51153D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303320D02* -X306910D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51247D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303398D02* -X306841D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51341D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303489D02* -X306761D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51434D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303591D02* -X306670D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51528D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303706D02* -X306560D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51622D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X303842D02* -X306431D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51715D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X304003D02* -X306281D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X260406Y51809D02* -X264476D01* -X273098D02* -X274082D01* -X286226D02* -X287211D01* -X304207D02* -X306080D01* -X308106D02* -X309090D01* -X314426D02* -X315410D01* -X304510Y51903D02* -X305793D01* -X260563Y64297D02* -X260567Y64488D01* -X260578Y64672D01* -X260594Y64848D01* -X260621Y65016D01* -X260652Y65176D01* -X260695Y65328D01* -X260742Y65473D01* -X260797Y65609D01* -X260844Y65707D01* -X260891Y65801D01* -X260945Y65891D01* -X261004Y65980D01* -X261067Y66067D01* -X261129Y66152D01* -X261199Y66234D01* -X261274Y66313D01* -X261352Y66387D01* -X261430Y66457D01* -X261508Y66524D01* -X261590Y66582D01* -X261676Y66637D01* -X261762Y66687D01* -X261848Y66734D01* -X261937Y66774D01* -X262059Y66820D01* -X262187Y66863D01* -X262317Y66898D01* -X262453Y66926D01* -X262594Y66949D01* -X262738Y66965D01* -X262887Y66973D01* -X263043Y66976D01* -X263183Y66973D01* -X263317Y66965D01* -X263449Y66953D01* -X263582Y66933D01* -X263707Y66906D01* -X263828Y66879D01* -X263945Y66844D01* -X264063Y66801D01* -X264172Y66754D01* -X264281Y66703D01* -X264387Y66644D01* -X264488Y66582D01* -X264586Y66512D01* -X264680Y66437D01* -X264770Y66359D01* -X264856Y66274D01* -X264937Y66183D01* -X265016Y66090D01* -X265086Y65992D01* -X265152Y65887D01* -X265215Y65781D01* -X265270Y65668D01* -X265320Y65555D01* -X265367Y65433D01* -X265406Y65309D01* -X265441Y65183D01* -X265469Y65051D01* -X265492Y64910D01* -X265512Y64770D01* -X265524Y64625D01* -X265531Y64476D01* -X265535Y64320D01* -X265531Y64168D01* -X265524Y64020D01* -X265512Y63875D01* -X265492Y63734D01* -X265469Y63598D01* -X265441Y63465D01* -X265406Y63340D01* -X265367Y63215D01* -X265320Y63098D01* -X265274Y62980D01* -X265215Y62871D01* -X265156Y62766D01* -X265090Y62660D01* -X265020Y62563D01* -X264941Y62469D01* -X264859Y62379D01* -X264774Y62297D01* -X264683Y62215D01* -X264590Y62141D01* -X264496Y62074D01* -X264394Y62012D01* -X264289Y61953D01* -X264183Y61902D01* -X264070Y61856D01* -X263957Y61813D01* -X263840Y61777D01* -X263719Y61746D01* -X263594Y61723D01* -X263465Y61703D01* -X263332Y61691D01* -X263195Y61683D01* -X263055Y61680D01* -X262914Y61683D01* -X262777Y61691D01* -X262644Y61703D01* -X262512Y61723D01* -X262387Y61746D01* -X262266Y61777D01* -X262144Y61813D01* -X262031Y61856D01* -X261918Y61898D01* -X261809Y61953D01* -X261703Y62008D01* -X261606Y62070D01* -X261508Y62141D01* -X261414Y62215D01* -X261324Y62293D01* -X261238Y62375D01* -X261156Y62465D01* -X261078Y62559D01* -X261008Y62656D01* -X260941Y62758D01* -X260883Y62863D01* -X260828Y62973D01* -X260777Y63086D01* -X260730Y63203D01* -X260691Y63328D01* -X260656Y63453D01* -X260629Y63582D01* -X260606Y63719D01* -X260586Y63856D01* -X260574Y64000D01* -X260567Y64144D01* -X260563Y64297D01* -X261629Y64332D02* -X261637Y64121D01* -X261652Y63922D01* -X261687Y63738D01* -X261730Y63567D01* -X261785Y63406D01* -X261856Y63262D01* -X261937Y63129D01* -X262031Y63012D01* -X262137Y62906D01* -X262246Y62817D01* -X262363Y62738D01* -X262488Y62676D01* -X262621Y62625D01* -X262758Y62590D01* -X262902Y62570D01* -X263055Y62563D01* -X263207Y62570D01* -X263352Y62590D01* -X263488Y62625D01* -X263617Y62672D01* -X263742Y62734D01* -X263859Y62813D01* -X263969Y62902D01* -X264070Y63008D01* -X264164Y63125D01* -X264246Y63258D01* -X264313Y63406D01* -X264371Y63567D01* -X264414Y63738D01* -X264445Y63926D01* -X264461Y64129D01* -X264469Y64344D01* -X264461Y64559D01* -X264445Y64758D01* -X264414Y64941D01* -X264371Y65113D01* -X264317Y65274D01* -X264250Y65414D01* -X264172Y65543D01* -X264082Y65660D01* -X263980Y65762D01* -X263871Y65848D01* -X263758Y65926D01* -X263633Y65984D01* -X263500Y66031D01* -X263359Y66067D01* -X263211Y66086D01* -X263055Y66094D01* -X262898Y66086D01* -X262750Y66067D01* -X262609Y66031D01* -X262476Y65984D01* -X262352Y65922D01* -X262234Y65848D01* -X262125Y65758D01* -X262020Y65656D01* -X261930Y65539D01* -X261852Y65406D01* -X261781Y65262D01* -X261726Y65106D01* -X261683Y64933D01* -X261652Y64746D01* -X261637Y64547D01* -X261629Y64332D01* -X266238Y61524D02* -X267359Y61387D01* -X267379Y61297D01* -X267406Y61219D01* -X267441Y61160D01* -X267465Y61133D01* -X267488Y61113D01* -X267527Y61090D01* -X267570Y61067D01* -X267617Y61051D01* -X267672Y61035D01* -X267726Y61024D01* -X267793Y61016D01* -X267859Y61008D01* -X267933D01* -X268027D01* -X268113Y61016D01* -X268195Y61024D01* -X268270Y61035D01* -X268340Y61055D01* -X268402Y61074D01* -X268461Y61098D01* -X268512Y61125D01* -X268574Y61168D01* -X268625Y61223D01* -X268672Y61293D01* -X268707Y61371D01* -X268719Y61406D01* -X268726Y61445D01* -X268734Y61492D01* -X268742Y61547D01* -X268746Y61606D01* -X268750Y61672D01* -X268754Y61746D01* -Y61824D01* -X268758Y62367D01* -X268703Y62297D01* -X268644Y62226D01* -X268586Y62164D01* -X268524Y62106D01* -X268461Y62051D01* -X268394Y62000D01* -X268328Y61957D01* -X268258Y61918D01* -X268187Y61879D01* -X268117Y61852D01* -X268043Y61824D01* -X267965Y61805D01* -X267887Y61785D01* -X267809Y61774D01* -X267726Y61770D01* -X267644Y61766D01* -X267551Y61770D01* -X267461Y61774D01* -X267375Y61789D01* -X267289Y61805D01* -X267207Y61828D01* -X267125Y61856D01* -X267047Y61887D01* -X266973Y61922D01* -X266898Y61965D01* -X266828Y62012D01* -X266762Y62067D01* -X266695Y62121D01* -X266633Y62183D01* -X266570Y62250D01* -X266512Y62320D01* -X266457Y62398D01* -X266375Y62527D01* -X266305Y62664D01* -X266246Y62809D01* -X266199Y62961D01* -X266160Y63117D01* -X266137Y63285D01* -X266117Y63461D01* -X266113Y63644D01* -X266121Y63871D01* -X266141Y64082D01* -X266176Y64281D01* -X266226Y64465D01* -X266289Y64637D01* -X266367Y64797D01* -X266457Y64937D01* -X266563Y65070D01* -X266680Y65183D01* -X266801Y65285D01* -X266930Y65371D01* -X267067Y65437D01* -X267211Y65492D01* -X267363Y65531D01* -X267520Y65555D01* -X267683Y65563D01* -X267766Y65559D01* -X267852Y65555D01* -X267933Y65543D01* -X268012Y65524D01* -X268090Y65504D01* -X268164Y65476D01* -X268238Y65445D01* -X268313Y65410D01* -X268383Y65371D01* -X268449Y65328D01* -X268516Y65277D01* -X268582Y65223D01* -X268644Y65164D01* -X268703Y65102D01* -X268762Y65031D01* -X268820Y64957D01* -Y65480D01* -X269738D01* -Y62148D01* -Y61988D01* -X269730Y61840D01* -X269723Y61699D01* -X269711Y61570D01* -X269695Y61453D01* -X269676Y61348D01* -X269656Y61250D01* -X269629Y61164D01* -X269602Y61086D01* -X269570Y61008D01* -X269535Y60937D01* -X269500Y60875D01* -X269461Y60813D01* -X269418Y60754D01* -X269371Y60703D01* -X269324Y60652D01* -X269274Y60609D01* -X269219Y60567D01* -X269160Y60524D01* -X269098Y60488D01* -X269027Y60453D01* -X268957Y60418D01* -X268883Y60391D01* -X268801Y60363D01* -X268715Y60336D01* -X268625Y60317D01* -X268531Y60297D01* -X268430Y60285D01* -X268324Y60274D01* -X268211Y60266D01* -X268094Y60258D01* -X267973D01* -X267856D01* -X267746Y60262D01* -X267637Y60270D01* -X267535Y60277D01* -X267433Y60289D01* -X267340Y60305D01* -X267250Y60320D01* -X267164Y60340D01* -X267082Y60359D01* -X267004Y60383D01* -X266933Y60410D01* -X266863Y60441D01* -X266797Y60473D01* -X266738Y60508D01* -X266683Y60543D01* -X266629Y60582D01* -X266539Y60664D01* -X266457Y60754D01* -X266391Y60848D01* -X266332Y60949D01* -X266289Y61055D01* -X266258Y61164D01* -X266242Y61281D01* -X266234Y61402D01* -Y61457D01* -X266238Y61524D01* -X267121Y63699D02* -X267125Y63555D01* -X267137Y63422D01* -X267152Y63301D01* -X267180Y63187D01* -X267211Y63082D01* -X267250Y62988D01* -X267297Y62906D01* -X267352Y62832D01* -X267410Y62770D01* -X267473Y62711D01* -X267535Y62664D01* -X267606Y62625D01* -X267676Y62598D01* -X267754Y62574D01* -X267832Y62563D01* -X267914Y62559D01* -X268004Y62563D01* -X268086Y62574D01* -X268168Y62598D01* -X268246Y62629D01* -X268320Y62668D01* -X268391Y62715D01* -X268457Y62774D01* -X268524Y62840D01* -X268578Y62914D01* -X268629Y62996D01* -X268672Y63090D01* -X268707Y63191D01* -X268734Y63297D01* -X268754Y63414D01* -X268766Y63539D01* -X268770Y63676D01* -X268766Y63817D01* -X268754Y63945D01* -X268734Y64067D01* -X268711Y64180D01* -X268676Y64281D01* -X268637Y64375D01* -X268586Y64457D01* -X268531Y64531D01* -X268473Y64598D01* -X268406Y64656D01* -X268336Y64703D01* -X268262Y64742D01* -X268187Y64774D01* -X268106Y64793D01* -X268020Y64809D01* -X267930Y64813D01* -X267844Y64809D01* -X267762Y64797D01* -X267683Y64774D01* -X267609Y64742D01* -X267539Y64703D01* -X267473Y64656D01* -X267410Y64602D01* -X267352Y64539D01* -X267297Y64465D01* -X267250Y64383D01* -X267211Y64289D01* -X267180Y64191D01* -X267152Y64082D01* -X267137Y63965D01* -X267125Y63836D01* -X267121Y63699D01* -X270711Y65980D02* -Y66891D01* -X271695D01* -Y65980D01* -X270711D01* -Y61766D02* -Y65480D01* -X271695D01* -Y61766D01* -X270711D01* -X272699D02* -Y66891D01* -X273683D01* -Y61766D01* -X272699D01* -X275707D02* -X274215Y65480D01* -X275246D01* -X275945Y63586D01* -X276148Y62953D01* -X276164Y63008D01* -X276183Y63063D01* -X276199Y63109D01* -X276211Y63152D01* -X276223Y63187D01* -X276234Y63219D01* -X276242Y63246D01* -X276246Y63270D01* -X276352Y63586D01* -X277059Y65480D01* -X278070D01* -X276594Y61766D01* -X275707D01* -X278668Y65980D02* -Y66891D01* -X279652D01* -Y65980D01* -X278668D01* -Y61766D02* -Y65480D01* -X279652D01* -Y61766D01* -X278668D01* -X282805Y62949D02* -X283785Y62785D01* -X283734Y62652D01* -X283676Y62531D01* -X283613Y62418D01* -X283543Y62309D01* -X283465Y62211D01* -X283379Y62121D01* -X283289Y62039D01* -X283187Y61965D01* -X283082Y61898D01* -X282973Y61840D01* -X282856Y61793D01* -X282730Y61754D01* -X282598Y61723D01* -X282461Y61699D01* -X282320Y61687D01* -X282168Y61683D01* -X282051Y61687D01* -X281933Y61691D01* -X281824Y61707D01* -X281715Y61723D01* -X281613Y61746D01* -X281512Y61774D01* -X281418Y61805D01* -X281324Y61840D01* -X281238Y61883D01* -X281156Y61930D01* -X281074Y61980D01* -X281000Y62039D01* -X280926Y62102D01* -X280859Y62168D01* -X280793Y62238D01* -X280734Y62317D01* -X280648Y62445D01* -X280574Y62586D01* -X280512Y62734D01* -X280461Y62891D01* -X280418Y63055D01* -X280391Y63226D01* -X280375Y63406D01* -X280367Y63594D01* -X280375Y63820D01* -X280398Y64031D01* -X280433Y64230D01* -X280488Y64418D01* -X280555Y64590D01* -X280641Y64754D01* -X280738Y64902D01* -X280852Y65039D01* -X280910Y65102D01* -X280976Y65160D01* -X281039Y65219D01* -X281106Y65270D01* -X281176Y65317D01* -X281246Y65359D01* -X281320Y65398D01* -X281394Y65430D01* -X281473Y65461D01* -X281555Y65488D01* -X281633Y65512D01* -X281719Y65531D01* -X281801Y65543D01* -X281891Y65555D01* -X281980Y65559D01* -X282070Y65563D01* -X282172Y65559D01* -X282274Y65555D01* -X282367Y65543D01* -X282461Y65527D01* -X282555Y65508D01* -X282644Y65484D01* -X282726Y65457D01* -X282813Y65426D01* -X282891Y65391D01* -X282969Y65348D01* -X283043Y65305D01* -X283117Y65254D01* -X283187Y65199D01* -X283254Y65144D01* -X283317Y65082D01* -X283379Y65016D01* -X283437Y64945D01* -X283488Y64871D01* -X283539Y64789D01* -X283586Y64707D01* -X283629Y64617D01* -X283668Y64524D01* -X283703Y64426D01* -X283730Y64324D01* -X283758Y64215D01* -X283781Y64106D01* -X283801Y63988D01* -X283817Y63867D01* -X283828Y63742D01* -X283832Y63613D01* -X283836Y63476D01* -Y63340D01* -X281375D01* -X281383Y63234D01* -X281394Y63133D01* -X281414Y63039D01* -X281441Y62953D01* -X281473Y62871D01* -X281512Y62793D01* -X281559Y62723D01* -X281613Y62660D01* -X281672Y62602D01* -X281734Y62555D01* -X281801Y62512D01* -X281867Y62476D01* -X281941Y62453D01* -X282016Y62433D01* -X282098Y62422D01* -X282180Y62418D01* -X282234D01* -X282289Y62426D01* -X282344Y62433D01* -X282391Y62449D01* -X282437Y62465D01* -X282484Y62488D01* -X282527Y62516D01* -X282567Y62543D01* -X282606Y62578D01* -X282641Y62617D01* -X282676Y62660D01* -X282707Y62707D01* -X282734Y62762D01* -X282758Y62820D01* -X282785Y62883D01* -X282805Y62949D01* -X282859Y63941D02* -X282856Y64043D01* -X282844Y64141D01* -X282824Y64230D01* -X282801Y64317D01* -X282770Y64394D01* -X282730Y64465D01* -X282687Y64531D01* -X282641Y64590D01* -X282586Y64641D01* -X282527Y64687D01* -X282469Y64726D01* -X282406Y64758D01* -X282344Y64781D01* -X282274Y64797D01* -X282203Y64809D01* -X282129Y64813D01* -X282051Y64809D01* -X281976Y64797D01* -X281906Y64777D01* -X281836Y64754D01* -X281774Y64719D01* -X281711Y64680D01* -X281652Y64633D01* -X281598Y64578D01* -X281551Y64516D01* -X281508Y64449D01* -X281473Y64379D01* -X281441Y64301D01* -X281418Y64219D01* -X281402Y64133D01* -X281394Y64039D01* -X281391Y63941D01* -X282859D01* -X286367Y63437D02* -X287375Y63535D01* -X287402Y63414D01* -X287433Y63297D01* -X287469Y63191D01* -X287512Y63094D01* -X287563Y63004D01* -X287617Y62926D01* -X287676Y62852D01* -X287742Y62789D01* -X287817Y62734D01* -X287894Y62683D01* -X287980Y62644D01* -X288070Y62609D01* -X288168Y62582D01* -X288270Y62567D01* -X288379Y62555D01* -X288492Y62551D01* -X288613Y62555D01* -X288726Y62563D01* -X288832Y62582D01* -X288933Y62602D01* -X289024Y62633D01* -X289106Y62668D01* -X289180Y62711D01* -X289246Y62762D01* -X289305Y62817D01* -X289359Y62871D01* -X289402Y62930D01* -X289437Y62992D01* -X289465Y63055D01* -X289484Y63121D01* -X289496Y63187D01* -X289500Y63258D01* -X289492Y63344D01* -X289473Y63426D01* -X289441Y63500D01* -X289394Y63567D01* -X289363Y63598D01* -X289332Y63629D01* -X289293Y63656D01* -X289246Y63687D01* -X289199Y63715D01* -X289144Y63738D01* -X289086Y63766D01* -X289020Y63789D01* -X288969Y63805D01* -X288902Y63828D01* -X288820Y63852D01* -X288723Y63875D01* -X288613Y63906D01* -X288484Y63937D01* -X288348Y63973D01* -X288191Y64012D01* -X287992Y64067D01* -X287805Y64121D01* -X287637Y64180D01* -X287484Y64242D01* -X287344Y64305D01* -X287223Y64375D01* -X287113Y64445D01* -X287024Y64520D01* -X286914Y64625D01* -X286817Y64742D01* -X286734Y64859D01* -X286668Y64988D01* -X286617Y65117D01* -X286582Y65258D01* -X286559Y65398D01* -X286551Y65547D01* -X286555Y65644D01* -X286567Y65742D01* -X286582Y65836D01* -X286606Y65926D01* -X286637Y66016D01* -X286676Y66106D01* -X286723Y66195D01* -X286774Y66281D01* -X286832Y66363D01* -X286894Y66441D01* -X286969Y66512D01* -X287043Y66578D01* -X287129Y66641D01* -X287215Y66699D01* -X287313Y66750D01* -X287414Y66797D01* -X287520Y66840D01* -X287633Y66875D01* -X287750Y66906D01* -X287875Y66933D01* -X288004Y66953D01* -X288137Y66965D01* -X288277Y66973D01* -X288422Y66976D01* -X288656Y66969D01* -X288875Y66949D01* -X289078Y66918D01* -X289266Y66871D01* -X289441Y66813D01* -X289602Y66738D01* -X289746Y66652D01* -X289875Y66555D01* -X289988Y66445D01* -X290090Y66324D01* -X290176Y66195D01* -X290246Y66059D01* -X290305Y65914D01* -X290344Y65762D01* -X290375Y65598D01* -X290387Y65426D01* -X289352Y65379D01* -X289332Y65473D01* -X289309Y65563D01* -X289281Y65644D01* -X289246Y65719D01* -X289211Y65785D01* -X289168Y65848D01* -X289117Y65902D01* -X289067Y65949D01* -X289008Y65988D01* -X288945Y66024D01* -X288871Y66055D01* -X288793Y66078D01* -X288707Y66098D01* -X288617Y66109D01* -X288516Y66117D01* -X288410Y66121D01* -X288301Y66117D01* -X288195Y66109D01* -X288098Y66094D01* -X288008Y66074D01* -X287922Y66047D01* -X287844Y66016D01* -X287770Y65980D01* -X287703Y65933D01* -X287664Y65906D01* -X287633Y65871D01* -X287602Y65836D01* -X287582Y65797D01* -X287563Y65754D01* -X287551Y65711D01* -X287543Y65664D01* -X287539Y65617D01* -X287543Y65574D01* -X287547Y65531D01* -X287563Y65488D01* -X287578Y65449D01* -X287598Y65410D01* -X287625Y65375D01* -X287656Y65340D01* -X287691Y65305D01* -X287719Y65285D01* -X287750Y65266D01* -X287785Y65242D01* -X287824Y65223D01* -X287871Y65203D01* -X287918Y65180D01* -X287973Y65160D01* -X288027Y65137D01* -X288090Y65117D01* -X288156Y65094D01* -X288226Y65074D01* -X288301Y65051D01* -X288383Y65031D01* -X288465Y65008D01* -X288555Y64984D01* -X288644Y64965D01* -X288828Y64918D01* -X289000Y64875D01* -X289156Y64828D01* -X289305Y64781D01* -X289437Y64738D01* -X289559Y64691D01* -X289668Y64644D01* -X289762Y64594D01* -X289852Y64547D01* -X289933Y64492D01* -X290012Y64433D01* -X290086Y64371D01* -X290156Y64301D01* -X290219Y64230D01* -X290277Y64156D01* -X290332Y64074D01* -X290379Y63988D01* -X290422Y63898D01* -X290457Y63805D01* -X290484Y63707D01* -X290508Y63602D01* -X290524Y63492D01* -X290531Y63379D01* -X290535Y63258D01* -X290531Y63148D01* -X290520Y63043D01* -X290500Y62937D01* -X290473Y62832D01* -X290441Y62730D01* -X290398Y62629D01* -X290348Y62531D01* -X290289Y62433D01* -X290226Y62340D01* -X290156Y62254D01* -X290078Y62172D01* -X289996Y62098D01* -X289906Y62031D01* -X289809Y61969D01* -X289707Y61914D01* -X289598Y61863D01* -X289484Y61820D01* -X289359Y61781D01* -X289230Y61750D01* -X289094Y61723D01* -X288953Y61703D01* -X288805Y61687D01* -X288644Y61680D01* -X288484Y61676D01* -X288246Y61683D01* -X288024Y61703D01* -X287817Y61738D01* -X287625Y61789D01* -X287445Y61852D01* -X287277Y61930D01* -X287125Y62020D01* -X286988Y62125D01* -X286867Y62246D01* -X286754Y62375D01* -X286656Y62520D01* -X286574Y62680D01* -X286504Y62848D01* -X286445Y63031D01* -X286398Y63226D01* -X286367Y63437D01* -X294633Y64383D02* -X293664Y64207D01* -X293648Y64277D01* -X293633Y64344D01* -X293609Y64402D01* -X293586Y64461D01* -X293555Y64512D01* -X293520Y64559D01* -X293484Y64602D01* -X293441Y64641D01* -X293398Y64676D01* -X293352Y64707D01* -X293297Y64730D01* -X293242Y64754D01* -X293187Y64770D01* -X293125Y64781D01* -X293063Y64785D01* -X292992Y64789D01* -X292906Y64785D01* -X292820Y64774D01* -X292738Y64754D01* -X292664Y64726D01* -X292594Y64691D01* -X292527Y64644D01* -X292465Y64594D01* -X292410Y64535D01* -X292359Y64469D01* -X292313Y64387D01* -X292277Y64297D01* -X292246Y64195D01* -X292223Y64086D01* -X292207Y63965D01* -X292195Y63832D01* -X292191Y63687D01* -X292195Y63531D01* -X292207Y63383D01* -X292223Y63250D01* -X292246Y63125D01* -X292277Y63016D01* -X292317Y62918D01* -X292363Y62832D01* -X292414Y62758D01* -X292473Y62691D01* -X292535Y62637D01* -X292602Y62590D01* -X292672Y62551D01* -X292750Y62524D01* -X292832Y62500D01* -X292918Y62488D01* -X293008Y62484D01* -X293078Y62488D01* -X293144Y62492D01* -X293203Y62508D01* -X293266Y62524D01* -X293320Y62547D01* -X293371Y62574D01* -X293422Y62606D01* -X293469Y62644D01* -X293512Y62687D01* -X293551Y62738D01* -X293586Y62793D01* -X293621Y62859D01* -X293648Y62933D01* -X293676Y63012D01* -X293699Y63098D01* -X293719Y63191D01* -X294683Y63027D01* -X294641Y62867D01* -X294590Y62715D01* -X294531Y62574D01* -X294465Y62441D01* -X294387Y62324D01* -X294305Y62211D01* -X294211Y62113D01* -X294106Y62024D01* -X293996Y61941D01* -X293875Y61875D01* -X293746Y61817D01* -X293609Y61770D01* -X293461Y61730D01* -X293305Y61703D01* -X293141Y61687D01* -X292965Y61683D01* -X292863D01* -X292766Y61691D01* -X292672Y61703D01* -X292578Y61715D01* -X292488Y61734D01* -X292402Y61754D01* -X292317Y61781D01* -X292234Y61813D01* -X292152Y61848D01* -X292078Y61883D01* -X292004Y61926D01* -X291930Y61973D01* -X291859Y62024D01* -X291793Y62078D01* -X291730Y62133D01* -X291668Y62195D01* -X291555Y62332D01* -X291457Y62476D01* -X291371Y62637D01* -X291305Y62809D01* -X291250Y62992D01* -X291215Y63191D01* -X291191Y63398D01* -X291183Y63621D01* -X291191Y63844D01* -X291215Y64055D01* -X291254Y64250D01* -X291305Y64437D01* -X291375Y64609D01* -X291457Y64770D01* -X291555Y64914D01* -X291668Y65051D01* -X291730Y65113D01* -X291797Y65172D01* -X291863Y65223D01* -X291933Y65274D01* -X292004Y65320D01* -X292082Y65363D01* -X292160Y65398D01* -X292238Y65433D01* -X292324Y65465D01* -X292410Y65488D01* -X292496Y65512D01* -X292590Y65531D01* -X292683Y65543D01* -X292781Y65555D01* -X292879Y65559D01* -X292980Y65563D01* -X293148Y65559D01* -X293305Y65543D01* -X293449Y65520D01* -X293590Y65488D01* -X293719Y65449D01* -X293840Y65398D01* -X293953Y65340D01* -X294059Y65270D01* -X294156Y65191D01* -X294246Y65106D01* -X294328Y65008D01* -X294402Y64902D01* -X294469Y64785D01* -X294531Y64660D01* -X294586Y64527D01* -X294633Y64383D01* -X296363Y66891D02* -Y65012D01* -X296422Y65078D01* -X296484Y65141D01* -X296547Y65199D01* -X296613Y65254D01* -X296680Y65301D01* -X296746Y65348D01* -X296813Y65387D01* -X296883Y65426D01* -X296957Y65457D01* -X297027Y65484D01* -X297102Y65508D01* -X297180Y65527D01* -X297258Y65543D01* -X297336Y65555D01* -X297414Y65559D01* -X297496Y65563D01* -X297582Y65559D01* -X297664Y65555D01* -X297742Y65543D01* -X297820Y65531D01* -X297894Y65512D01* -X297969Y65492D01* -X298039Y65465D01* -X298109Y65437D01* -X298176Y65402D01* -X298238Y65367D01* -X298293Y65332D01* -X298348Y65293D01* -X298398Y65250D01* -X298441Y65207D01* -X298480Y65164D01* -X298520Y65113D01* -X298582Y65016D01* -X298637Y64910D01* -X298676Y64797D01* -X298707Y64680D01* -X298719Y64617D01* -X298730Y64547D01* -X298738Y64465D01* -X298746Y64379D01* -X298750Y64281D01* -X298754Y64176D01* -X298758Y64063D01* -Y63945D01* -Y61766D01* -X297774D01* -Y63726D01* -Y63867D01* -X297770Y63992D01* -X297766Y64106D01* -X297758Y64207D01* -X297750Y64293D01* -X297742Y64363D01* -X297730Y64422D01* -X297719Y64469D01* -X297683Y64543D01* -X297641Y64609D01* -X297586Y64668D01* -X297520Y64719D01* -X297445Y64762D01* -X297363Y64789D01* -X297270Y64805D01* -X297168Y64813D01* -X297051Y64805D01* -X296937Y64781D01* -X296832Y64746D01* -X296734Y64691D01* -X296644Y64625D01* -X296567Y64543D01* -X296504Y64445D01* -X296453Y64336D01* -X296430Y64270D01* -X296414Y64199D01* -X296398Y64121D01* -X296387Y64039D01* -X296375Y63945D01* -X296367Y63848D01* -X296363Y63738D01* -Y63625D01* -Y61766D01* -X295379D01* -Y66891D01* -X296363D01* -X299527Y63676D02* -X299531Y63797D01* -X299543Y63918D01* -X299563Y64039D01* -X299586Y64156D01* -X299621Y64274D01* -X299664Y64391D01* -X299711Y64508D01* -X299770Y64621D01* -X299832Y64734D01* -X299902Y64836D01* -X299976Y64933D01* -X300063Y65027D01* -X300148Y65109D01* -X300246Y65187D01* -X300348Y65258D01* -X300453Y65320D01* -X300567Y65379D01* -X300680Y65426D01* -X300801Y65469D01* -X300922Y65500D01* -X301047Y65527D01* -X301176Y65547D01* -X301309Y65559D01* -X301441Y65563D01* -X301547Y65559D01* -X301648Y65555D01* -X301746Y65543D01* -X301844Y65527D01* -X301937Y65508D01* -X302031Y65484D01* -X302121Y65457D01* -X302211Y65426D01* -X302293Y65391D01* -X302379Y65348D01* -X302457Y65305D01* -X302535Y65254D01* -X302613Y65199D01* -X302683Y65144D01* -X302754Y65082D01* -X302824Y65016D01* -X302891Y64945D01* -X302949Y64875D01* -X303008Y64801D01* -X303059Y64723D01* -X303109Y64644D01* -X303152Y64567D01* -X303191Y64480D01* -X303230Y64394D01* -X303262Y64309D01* -X303289Y64219D01* -X303313Y64129D01* -X303328Y64031D01* -X303344Y63937D01* -X303356Y63836D01* -X303359Y63738D01* -X303363Y63633D01* -X303359Y63527D01* -X303356Y63426D01* -X303344Y63328D01* -X303328Y63230D01* -X303309Y63137D01* -X303285Y63043D01* -X303258Y62953D01* -X303226Y62863D01* -X303191Y62777D01* -X303152Y62691D01* -X303106Y62613D01* -X303059Y62531D01* -X303004Y62453D01* -X302945Y62379D01* -X302887Y62309D01* -X302820Y62238D01* -X302750Y62172D01* -X302680Y62106D01* -X302606Y62051D01* -X302531Y61996D01* -X302453Y61945D01* -X302371Y61898D01* -X302289Y61859D01* -X302203Y61820D01* -X302117Y61789D01* -X302027Y61762D01* -X301937Y61738D01* -X301844Y61719D01* -X301750Y61703D01* -X301652Y61691D01* -X301551Y61687D01* -X301449Y61683D01* -X301320Y61687D01* -X301195Y61699D01* -X301074Y61715D01* -X300949Y61742D01* -X300828Y61774D01* -X300711Y61813D01* -X300590Y61859D01* -X300473Y61914D01* -X300363Y61976D01* -X300258Y62043D01* -X300156Y62117D01* -X300067Y62199D01* -X299980Y62285D01* -X299902Y62379D01* -X299832Y62480D01* -X299770Y62590D01* -X299711Y62703D01* -X299664Y62824D01* -X299621Y62953D01* -X299586Y63082D01* -X299563Y63223D01* -X299543Y63367D01* -X299531Y63520D01* -X299527Y63676D01* -X300535Y63621D02* -X300539Y63488D01* -X300551Y63363D01* -X300570Y63246D01* -X300602Y63137D01* -X300637Y63035D01* -X300683Y62941D01* -X300734Y62856D01* -X300797Y62777D01* -X300867Y62707D01* -X300937Y62648D01* -X301012Y62598D01* -X301090Y62559D01* -X301172Y62524D01* -X301262Y62504D01* -X301352Y62488D01* -X301445Y62484D01* -X301539Y62488D01* -X301629Y62504D01* -X301715Y62524D01* -X301801Y62559D01* -X301879Y62598D01* -X301953Y62648D01* -X302024Y62707D01* -X302090Y62777D01* -X302152Y62856D01* -X302203Y62941D01* -X302250Y63035D01* -X302285Y63137D01* -X302317Y63246D01* -X302336Y63367D01* -X302348Y63492D01* -X302352Y63629D01* -X302348Y63762D01* -X302336Y63887D01* -X302317Y64004D01* -X302285Y64113D01* -X302250Y64211D01* -X302203Y64305D01* -X302152Y64391D01* -X302090Y64469D01* -X302024Y64535D01* -X301953Y64598D01* -X301879Y64648D01* -X301801Y64687D01* -X301715Y64719D01* -X301629Y64742D01* -X301539Y64758D01* -X301445Y64762D01* -X301352Y64758D01* -X301262Y64742D01* -X301172Y64719D01* -X301090Y64687D01* -X301012Y64648D01* -X300937Y64598D01* -X300867Y64535D01* -X300797Y64469D01* -X300734Y64391D01* -X300683Y64305D01* -X300637Y64211D01* -X300602Y64109D01* -X300570Y64000D01* -X300551Y63883D01* -X300539Y63758D01* -X300535Y63621D01* -X303902Y63676D02* -X303906Y63797D01* -X303918Y63918D01* -X303937Y64039D01* -X303961Y64156D01* -X303996Y64274D01* -X304039Y64391D01* -X304086Y64508D01* -X304144Y64621D01* -X304207Y64734D01* -X304277Y64836D01* -X304352Y64933D01* -X304437Y65027D01* -X304524Y65109D01* -X304621Y65187D01* -X304723Y65258D01* -X304828Y65320D01* -X304941Y65379D01* -X305055Y65426D01* -X305176Y65469D01* -X305297Y65500D01* -X305422Y65527D01* -X305551Y65547D01* -X305683Y65559D01* -X305817Y65563D01* -X305922Y65559D01* -X306024Y65555D01* -X306121Y65543D01* -X306219Y65527D01* -X306313Y65508D01* -X306406Y65484D01* -X306496Y65457D01* -X306586Y65426D01* -X306668Y65391D01* -X306754Y65348D01* -X306832Y65305D01* -X306910Y65254D01* -X306988Y65199D01* -X307059Y65144D01* -X307129Y65082D01* -X307199Y65016D01* -X307266Y64945D01* -X307324Y64875D01* -X307383Y64801D01* -X307433Y64723D01* -X307484Y64644D01* -X307527Y64567D01* -X307567Y64480D01* -X307606Y64394D01* -X307637Y64309D01* -X307664Y64219D01* -X307687Y64129D01* -X307703Y64031D01* -X307719Y63937D01* -X307730Y63836D01* -X307734Y63738D01* -X307738Y63633D01* -X307734Y63527D01* -X307730Y63426D01* -X307719Y63328D01* -X307703Y63230D01* -X307683Y63137D01* -X307660Y63043D01* -X307633Y62953D01* -X307602Y62863D01* -X307567Y62777D01* -X307527Y62691D01* -X307480Y62613D01* -X307433Y62531D01* -X307379Y62453D01* -X307320Y62379D01* -X307262Y62309D01* -X307195Y62238D01* -X307125Y62172D01* -X307055Y62106D01* -X306980Y62051D01* -X306906Y61996D01* -X306828Y61945D01* -X306746Y61898D01* -X306664Y61859D01* -X306578Y61820D01* -X306492Y61789D01* -X306402Y61762D01* -X306313Y61738D01* -X306219Y61719D01* -X306125Y61703D01* -X306027Y61691D01* -X305926Y61687D01* -X305824Y61683D01* -X305695Y61687D01* -X305570Y61699D01* -X305449Y61715D01* -X305324Y61742D01* -X305203Y61774D01* -X305086Y61813D01* -X304965Y61859D01* -X304848Y61914D01* -X304738Y61976D01* -X304633Y62043D01* -X304531Y62117D01* -X304441Y62199D01* -X304356Y62285D01* -X304277Y62379D01* -X304207Y62480D01* -X304144Y62590D01* -X304086Y62703D01* -X304039Y62824D01* -X303996Y62953D01* -X303961Y63082D01* -X303937Y63223D01* -X303918Y63367D01* -X303906Y63520D01* -X303902Y63676D01* -X304910Y63621D02* -X304914Y63488D01* -X304926Y63363D01* -X304945Y63246D01* -X304976Y63137D01* -X305012Y63035D01* -X305059Y62941D01* -X305109Y62856D01* -X305172Y62777D01* -X305242Y62707D01* -X305313Y62648D01* -X305387Y62598D01* -X305465Y62559D01* -X305547Y62524D01* -X305637Y62504D01* -X305726Y62488D01* -X305820Y62484D01* -X305914Y62488D01* -X306004Y62504D01* -X306090Y62524D01* -X306176Y62559D01* -X306254Y62598D01* -X306328Y62648D01* -X306398Y62707D01* -X306465Y62777D01* -X306527Y62856D01* -X306578Y62941D01* -X306625Y63035D01* -X306660Y63137D01* -X306691Y63246D01* -X306711Y63367D01* -X306723Y63492D01* -X306726Y63629D01* -X306723Y63762D01* -X306711Y63887D01* -X306691Y64004D01* -X306660Y64113D01* -X306625Y64211D01* -X306578Y64305D01* -X306527Y64391D01* -X306465Y64469D01* -X306398Y64535D01* -X306328Y64598D01* -X306254Y64648D01* -X306176Y64687D01* -X306090Y64719D01* -X306004Y64742D01* -X305914Y64758D01* -X305820Y64762D01* -X305726Y64758D01* -X305637Y64742D01* -X305547Y64719D01* -X305465Y64687D01* -X305387Y64648D01* -X305313Y64598D01* -X305242Y64535D01* -X305172Y64469D01* -X305109Y64391D01* -X305059Y64305D01* -X305012Y64211D01* -X304976Y64109D01* -X304945Y64000D01* -X304926Y63883D01* -X304914Y63758D01* -X304910Y63621D01* -X308508Y61766D02* -Y66891D01* -X309492D01* -Y61766D01* -X308508D01* -X267148Y60344D02* -X268739D01* -X266872Y60437D02* -X268996D01* -X266702Y60531D02* -X269170D01* -X266582Y60625D02* -X269292D01* -X266489Y60719D02* -X269385D01* -X266416Y60812D02* -X269461D01* -X266357Y60906D02* -X269517D01* -X266311Y61000D02* -X269566D01* -X266278Y61093D02* -X267521D01* -X268450D02* -X269604D01* -X266255Y61187D02* -X267425D01* -X268592D02* -X269636D01* -X266242Y61281D02* -X267384D01* -X268664D02* -X269662D01* -X266236Y61374D02* -X267362D01* -X268708D02* -X269681D01* -X266235Y61468D02* -X266693D01* -X268730D02* -X269697D01* -X268743Y61562D02* -X269710D01* -X268749Y61656D02* -X269719D01* -X262374Y61749D02* -X263731D01* -X268754D02* -X269726D01* -X281602D02* -X282710D01* -X287775D02* -X289230D01* -X292423D02* -X293532D01* -X300922D02* -X301979D01* -X305297D02* -X306354D01* -X262065Y61843D02* -X264037D01* -X267163D02* -X268094D01* -X268754D02* -X269730D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275676D02* -X276624D01* -X278668D02* -X279652D01* -X281318D02* -X282979D01* -X287470D02* -X289544D01* -X292163D02* -X293804D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X300633D02* -X302253D01* -X305007D02* -X306628D01* -X308508D02* -X309492D01* -X261842Y61937D02* -X264255D01* -X266948D02* -X268291D01* -X268755D02* -X269735D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275639D02* -X276662D01* -X278668D02* -X279652D01* -X281145D02* -X283143D01* -X287265D02* -X289749D01* -X291987D02* -X293987D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X300433D02* -X302438D01* -X304808D02* -X306813D01* -X308508D02* -X309492D01* -X261668Y62030D02* -X264424D01* -X266806D02* -X268434D01* -X268756D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275601D02* -X276699D01* -X278668D02* -X279652D01* -X281011D02* -X283277D01* -X287111D02* -X289906D01* -X291851D02* -X294113D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X300278D02* -X302578D01* -X304653D02* -X306953D01* -X308508D02* -X309492D01* -X261531Y62124D02* -X264566D01* -X266693D02* -X268543D01* -X268756D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275563D02* -X276736D01* -X278668D02* -X279652D01* -X280903D02* -X283381D01* -X286989D02* -X290025D01* -X291740D02* -X294221D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X300149D02* -X302699D01* -X304524D02* -X307074D01* -X308508D02* -X309492D01* -X261411Y62218D02* -X264687D01* -X266601D02* -X268636D01* -X268757D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275526D02* -X276773D01* -X278668D02* -X279652D01* -X280812D02* -X283470D01* -X286896D02* -X290122D01* -X291650D02* -X294309D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X300048D02* -X302799D01* -X304423D02* -X307174D01* -X308508D02* -X309492D01* -X261305Y62311D02* -X264789D01* -X266519D02* -X268715D01* -X268757D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275488D02* -X276811D01* -X278668D02* -X279652D01* -X280738D02* -X283545D01* -X286810D02* -X290203D01* -X291572D02* -X294377D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299958D02* -X302889D01* -X304333D02* -X307264D01* -X308508D02* -X309492D01* -X261211Y62405D02* -X264883D01* -X266453D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275450D02* -X276848D01* -X278668D02* -X279652D01* -X280675D02* -X283605D01* -X286733D02* -X290270D01* -X291505D02* -X294441D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299884D02* -X302966D01* -X304259D02* -X307341D01* -X308508D02* -X309492D01* -X261128Y62499D02* -X264967D01* -X266393D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275413D02* -X276885D01* -X278668D02* -X279652D01* -X280620D02* -X281825D01* -X282501D02* -X283658D01* -X286670D02* -X290328D01* -X291445D02* -X292832D01* -X293169D02* -X294494D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299821D02* -X301291D01* -X301600D02* -X303036D01* -X304196D02* -X305666D01* -X305975D02* -X307411D01* -X308508D02* -X309492D01* -X261054Y62593D02* -X262747D01* -X263362D02* -X265041D01* -X266342D02* -X267693D01* -X268150D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275375D02* -X276922D01* -X278668D02* -X279652D01* -X280572D02* -X281684D01* -X282619D02* -X283705D01* -X286619D02* -X288130D01* -X288887D02* -X290380D01* -X291395D02* -X292598D01* -X293401D02* -X294539D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299768D02* -X301022D01* -X301869D02* -X303094D01* -X304143D02* -X305397D01* -X306244D02* -X307469D01* -X308508D02* -X309492D01* -X260988Y62686D02* -X262467D01* -X263646D02* -X265106D01* -X266296D02* -X267506D01* -X268348D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275337D02* -X276960D01* -X278668D02* -X279652D01* -X280532D02* -X281591D01* -X282693D02* -X283747D01* -X286572D02* -X287890D01* -X289137D02* -X290423D01* -X291352D02* -X292479D01* -X293511D02* -X294578D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299720D02* -X300892D01* -X301998D02* -X303149D01* -X304094D02* -X305267D01* -X306373D02* -X307524D01* -X308508D02* -X309492D01* -X260929Y62780D02* -X262301D01* -X263811D02* -X265164D01* -X266258D02* -X267400D01* -X268463D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275300D02* -X276997D01* -X278668D02* -X279652D01* -X280497D02* -X281520D01* -X282742D02* -X283783D01* -X286532D02* -X287754D01* -X289265D02* -X290457D01* -X291316D02* -X292399D01* -X293578D02* -X294611D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299681D02* -X300794D01* -X302092D02* -X303193D01* -X304056D02* -X305170D01* -X306467D02* -X307568D01* -X308508D02* -X309492D01* -X260878Y62874D02* -X262176D01* -X263934D02* -X265216D01* -X266226D02* -X267321D01* -X268548D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275262D02* -X277034D01* -X278668D02* -X279652D01* -X280467D02* -X281472D01* -X282781D02* -X283256D01* -X286496D02* -X287658D01* -X289361D02* -X290483D01* -X291285D02* -X292341D01* -X293626D02* -X294642D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299648D02* -X300724D01* -X302163D02* -X303230D01* -X304022D02* -X305099D01* -X306538D02* -X307605D01* -X308508D02* -X309492D01* -X260831Y62967D02* -X262076D01* -X264031D02* -X265267D01* -X266198D02* -X267262D01* -X268611D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275224D02* -X276144D01* -X276152D02* -X277071D01* -X278668D02* -X279652D01* -X280441D02* -X281437D01* -X286466D02* -X287588D01* -X289424D02* -X290506D01* -X291257D02* -X292297D01* -X293660D02* -X294667D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299617D02* -X300670D01* -X302216D02* -X303262D01* -X303992D02* -X305046D01* -X306591D02* -X307637D01* -X308508D02* -X309492D01* -X260788Y63061D02* -X261992D01* -X264113D02* -X265306D01* -X266174D02* -X267220D01* -X268659D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275187D02* -X276114D01* -X276183D02* -X277109D01* -X278668D02* -X279652D01* -X280417D02* -X281409D01* -X286438D02* -X287530D01* -X289467D02* -X290522D01* -X291238D02* -X292264D01* -X293689D02* -X294485D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299592D02* -X300628D01* -X302259D02* -X303290D01* -X303967D02* -X305003D01* -X306634D02* -X307665D01* -X308508D02* -X309492D01* -X260750Y63155D02* -X261921D01* -X264183D02* -X265343D01* -X266155D02* -X267189D01* -X268694D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275149D02* -X276084D01* -X276212D02* -X277146D01* -X278668D02* -X279652D01* -X280402D02* -X281392D01* -X286416D02* -X287485D01* -X289490D02* -X290531D01* -X291221D02* -X292241D01* -X293711D02* -X293934D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299574D02* -X300596D01* -X302290D02* -X303312D01* -X303949D02* -X304971D01* -X306665D02* -X307687D01* -X308508D02* -X309492D01* -X260716Y63248D02* -X261864D01* -X264240D02* -X265378D01* -X266142D02* -X267165D01* -X268722D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275111D02* -X276054D01* -X276243D02* -X277183D01* -X278668D02* -X279652D01* -X280389D02* -X281381D01* -X286395D02* -X287450D01* -X289500D02* -X290535D01* -X291208D02* -X292223D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299559D02* -X300570D01* -X302317D02* -X303331D01* -X303934D02* -X304945D01* -X306692D02* -X307706D01* -X308508D02* -X309492D01* -X260687Y63342D02* -X261817D01* -X264284D02* -X265407D01* -X266130D02* -X267147D01* -X268742D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275074D02* -X276024D01* -X276270D02* -X277220D01* -X278668D02* -X279652D01* -X280381D02* -X283836D01* -X286381D02* -X287422D01* -X289493D02* -X290532D01* -X291198D02* -X292212D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299546D02* -X300554D01* -X302332D02* -X303345D01* -X303922D02* -X304929D01* -X306707D02* -X307720D01* -X308508D02* -X309492D01* -X260661Y63436D02* -X261775D01* -X264323D02* -X265433D01* -X266120D02* -X267135D01* -X268756D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X275036D02* -X275993D01* -X276302D02* -X277257D01* -X278668D02* -X279652D01* -X280374D02* -X283836D01* -X286351D02* -X287398D01* -X289469D02* -X290527D01* -X291190D02* -X292203D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299538D02* -X300544D01* -X302342D02* -X303356D01* -X303913D02* -X304919D01* -X306717D02* -X307731D01* -X308508D02* -X309492D01* -X260640Y63530D02* -X261743D01* -X264358D02* -X265455D01* -X266116D02* -X267128D01* -X268765D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274998D02* -X275963D01* -X276333D02* -X277295D01* -X278668D02* -X279652D01* -X280370D02* -X283834D01* -X287318D02* -X287376D01* -X289420D02* -X290518D01* -X291187D02* -X292195D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299531D02* -X300538D01* -X302349D02* -X303359D01* -X303906D02* -X304913D01* -X306724D02* -X307734D01* -X308508D02* -X309492D01* -X260622Y63623D02* -X261716D01* -X264385D02* -X265473D01* -X266114D02* -X267123D01* -X268768D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274961D02* -X275931D01* -X276365D02* -X277332D01* -X278668D02* -X279652D01* -X280369D02* -X283831D01* -X289337D02* -X290503D01* -X291183D02* -X292193D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299528D02* -X300535D01* -X302352D02* -X303363D01* -X303904D02* -X304910D01* -X306726D02* -X307738D01* -X308508D02* -X309492D01* -X260606Y63717D02* -X261693D01* -X264409D02* -X265489D01* -X266116D02* -X267122D01* -X268769D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274923D02* -X275897D01* -X276400D02* -X277369D01* -X278668D02* -X279652D01* -X280372D02* -X283829D01* -X289194D02* -X290481D01* -X291187D02* -X292192D01* -X295379D02* -X296363D01* -X297774D02* -X298758D01* -X299528D02* -X300538D01* -X302349D02* -X303360D01* -X303904D02* -X304913D01* -X306724D02* -X307735D01* -X308508D02* -X309492D01* -X260592Y63811D02* -X261674D01* -X264426D02* -X265503D01* -X266119D02* -X267124D01* -X268766D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274886D02* -X275862D01* -X276435D02* -X277407D01* -X278668D02* -X279652D01* -X280375D02* -X283822D01* -X288952D02* -X290455D01* -X291190D02* -X292195D01* -X295379D02* -X296366D01* -X297774D02* -X298758D01* -X299532D02* -X300544D01* -X302343D02* -X303357D01* -X303907D02* -X304919D01* -X306718D02* -X307731D01* -X308508D02* -X309492D01* -X260582Y63904D02* -X261656D01* -X264442D02* -X265514D01* -X266124D02* -X267131D01* -X268758D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274848D02* -X275828D01* -X276470D02* -X277444D01* -X278668D02* -X279652D01* -X280384D02* -X283812D01* -X288620D02* -X290419D01* -X291198D02* -X292202D01* -X295379D02* -X296372D01* -X297772D02* -X298758D01* -X299542D02* -X300554D01* -X302333D02* -X303348D01* -X303917D02* -X304929D01* -X306708D02* -X307722D01* -X308508D02* -X309492D01* -X260574Y63998D02* -X261646D01* -X264451D02* -X265522D01* -X266133D02* -X267141D01* -X268745D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274810D02* -X275793D01* -X276506D02* -X277481D01* -X278668D02* -X279652D01* -X280395D02* -X281393D01* -X282857D02* -X283799D01* -X288246D02* -X290373D01* -X291209D02* -X292211D01* -X295379D02* -X296381D01* -X297769D02* -X298758D01* -X299556D02* -X300570D01* -X302317D02* -X303333D01* -X303931D02* -X304945D01* -X306693D02* -X307709D01* -X308508D02* -X309492D01* -X260569Y64092D02* -X261639D01* -X264458D02* -X265527D01* -X266142D02* -X267155D01* -X268729D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274773D02* -X275759D01* -X276541D02* -X277519D01* -X278668D02* -X279652D01* -X280409D02* -X281399D01* -X282850D02* -X283783D01* -X287906D02* -X290320D01* -X291222D02* -X292224D01* -X295379D02* -X296394D01* -X297766D02* -X298757D01* -X299573D02* -X300596D01* -X302291D02* -X303319D01* -X303948D02* -X304971D01* -X306667D02* -X307693D01* -X308508D02* -X309492D01* -X260565Y64185D02* -X261634D01* -X264463D02* -X265531D01* -X266159D02* -X267178D01* -X268709D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274735D02* -X275724D01* -X276575D02* -X277556D01* -X278668D02* -X279652D01* -X280426D02* -X281412D01* -X282834D02* -X283764D01* -X287622D02* -X290254D01* -X291241D02* -X292244D01* -X295379D02* -X296411D01* -X297759D02* -X298754D01* -X299594D02* -X300628D01* -X302259D02* -X303298D01* -X303970D02* -X305003D01* -X306634D02* -X307673D01* -X308508D02* -X309492D01* -X260563Y64279D02* -X261631D01* -X264467D02* -X265534D01* -X266175D02* -X267208D01* -X268676D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274698D02* -X275689D01* -X276610D02* -X277593D01* -X278668D02* -X279652D01* -X280448D02* -X281435D01* -X282811D02* -X283742D01* -X287401D02* -X290176D01* -X291262D02* -X292272D01* -X293648D02* -X294061D01* -X295379D02* -X296433D01* -X297751D02* -X298750D01* -X299623D02* -X300670D01* -X302216D02* -X303271D01* -X303998D02* -X305046D01* -X306591D02* -X307646D01* -X308508D02* -X309492D01* -X260564Y64373D02* -X261630D01* -X264468D02* -X265534D01* -X266201D02* -X267246D01* -X268637D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274660D02* -X275655D01* -X276645D02* -X277630D01* -X278668D02* -X279652D01* -X280475D02* -X281470D01* -X282778D02* -X283717D01* -X287226D02* -X290086D01* -X291287D02* -X292307D01* -X293621D02* -X294578D01* -X295379D02* -X296470D01* -X297740D02* -X298746D01* -X299657D02* -X300724D01* -X302163D02* -X303238D01* -X304032D02* -X305099D01* -X306538D02* -X307613D01* -X308508D02* -X309492D01* -X260566Y64467D02* -X261634D01* -X264465D02* -X265531D01* -X266227D02* -X267297D01* -X268579D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274622D02* -X275620D01* -X276680D02* -X277667D01* -X278668D02* -X279652D01* -X280507D02* -X281519D01* -X282729D02* -X283689D01* -X287088D02* -X289968D01* -X291317D02* -X292358D01* -X293582D02* -X294606D01* -X295379D02* -X296518D01* -X297719D02* -X298738D01* -X299694D02* -X300795D01* -X302092D02* -X303198D01* -X304069D02* -X305170D01* -X306467D02* -X307573D01* -X308508D02* -X309492D01* -X260571Y64560D02* -X261638D01* -X264461D02* -X265527D01* -X266261D02* -X267372D01* -X268506D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274585D02* -X275586D01* -X276715D02* -X277705D01* -X278668D02* -X279652D01* -X280543D02* -X281584D01* -X282664D02* -X283653D01* -X286981D02* -X289826D01* -X291355D02* -X292434D01* -X293519D02* -X294572D01* -X295379D02* -X296583D01* -X297672D02* -X298728D01* -X299738D02* -X300896D01* -X301995D02* -X303155D01* -X304113D02* -X305270D01* -X306370D02* -X307530D01* -X308508D02* -X309492D01* -X260577Y64654D02* -X261645D01* -X264454D02* -X265521D01* -X266298D02* -X267470D01* -X268409D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274547D02* -X275551D01* -X276750D02* -X277742D01* -X278668D02* -X279652D01* -X280588D02* -X281679D01* -X282569D02* -X283611D01* -X286890D02* -X289646D01* -X291398D02* -X292541D01* -X293425D02* -X294534D01* -X295379D02* -X296684D01* -X297599D02* -X298712D01* -X299788D02* -X301023D01* -X301868D02* -X303103D01* -X304163D02* -X305398D01* -X306243D02* -X307478D01* -X308508D02* -X309492D01* -X260585Y64748D02* -X261652D01* -X264446D02* -X265514D01* -X266343D02* -X267622D01* -X268249D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274509D02* -X275517D01* -X276785D02* -X277779D01* -X278668D02* -X279652D01* -X280637D02* -X281825D01* -X282427D02* -X283563D01* -X286813D02* -X289408D01* -X291446D02* -X292721D01* -X293257D02* -X294487D01* -X295379D02* -X296832D01* -X297470D02* -X298689D01* -X299841D02* -X301293D01* -X301597D02* -X303043D01* -X304216D02* -X305668D01* -X305972D02* -X307417D01* -X308508D02* -X309492D01* -X260593Y64841D02* -X261668D01* -X264431D02* -X265502D01* -X266396D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274472D02* -X275482D01* -X276820D02* -X277817D01* -X278668D02* -X279652D01* -X280698D02* -X283507D01* -X286747D02* -X289112D01* -X291506D02* -X294437D01* -X295379D02* -X298660D01* -X299907D02* -X302976D01* -X304281D02* -X307351D01* -X308508D02* -X309492D01* -X260608Y64935D02* -X261683D01* -X264415D02* -X265488D01* -X266456D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274434D02* -X275447D01* -X276855D02* -X277854D01* -X278668D02* -X279652D01* -X280765D02* -X283444D01* -X286695D02* -X288762D01* -X291572D02* -X294379D01* -X295379D02* -X298624D01* -X299978D02* -X302899D01* -X304353D02* -X307274D01* -X308508D02* -X309492D01* -X260624Y65029D02* -X261707D01* -X264393D02* -X265472D01* -X266530D02* -X268764D01* -X268820D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274396D02* -X275413D01* -X276890D02* -X277891D01* -X278668D02* -X279652D01* -X280843D02* -X283367D01* -X286652D02* -X288391D01* -X291650D02* -X294311D01* -X295379D02* -X296363D01* -X296378D02* -X298574D01* -X300064D02* -X302811D01* -X304439D02* -X307185D01* -X308508D02* -X309492D01* -X260642Y65122D02* -X261732D01* -X264368D02* -X265454D01* -X266617D02* -X268683D01* -X268820D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274359D02* -X275378D01* -X276925D02* -X277928D01* -X278668D02* -X279652D01* -X280934D02* -X283276D01* -X286616D02* -X288073D01* -X291741D02* -X294228D01* -X295379D02* -X296363D01* -X296466D02* -X298513D01* -X300165D02* -X302708D01* -X304540D02* -X307083D01* -X308508D02* -X309492D01* -X260664Y65216D02* -X261765D01* -X264336D02* -X265432D01* -X266719D02* -X268589D01* -X268820D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274321D02* -X275344D01* -X276960D02* -X277965D01* -X278668D02* -X279652D01* -X281036D02* -X283166D01* -X286593D02* -X287840D01* -X291855D02* -X294125D01* -X295379D02* -X296363D01* -X296567D02* -X298432D01* -X300287D02* -X302589D01* -X304663D02* -X306964D01* -X308508D02* -X309492D01* -X260690Y65310D02* -X261805D01* -X264299D02* -X265406D01* -X266838D02* -X268473D01* -X268820D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274283D02* -X275309D01* -X276995D02* -X278003D01* -X278668D02* -X279652D01* -X281166D02* -X283034D01* -X286573D02* -X287686D01* -X291988D02* -X293998D01* -X295379D02* -X296363D01* -X296693D02* -X298324D01* -X300435D02* -X302448D01* -X304810D02* -X306822D01* -X308508D02* -X309492D01* -X260720Y65404D02* -X261850D01* -X264255D02* -X265377D01* -X266996D02* -X268325D01* -X268820D02* -X269738D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X274246D02* -X275274D01* -X277030D02* -X278040D01* -X278668D02* -X279652D01* -X281333D02* -X282862D01* -X286558D02* -X287603D01* -X289346D02* -X289900D01* -X292172D02* -X293828D01* -X295379D02* -X296363D01* -X296843D02* -X298176D01* -X300626D02* -X302263D01* -X305001D02* -X306638D01* -X308508D02* -X309492D01* -X260752Y65497D02* -X261905D01* -X264200D02* -X265343D01* -X267231D02* -X268108D01* -X272699D02* -X273683D01* -X281585D02* -X282595D01* -X286554D02* -X287559D01* -X289326D02* -X290382D01* -X292443D02* -X293549D01* -X295379D02* -X296363D01* -X297068D02* -X297950D01* -X300911D02* -X301980D01* -X305286D02* -X306355D01* -X308508D02* -X309492D01* -X260789Y65591D02* -X261969D01* -X264135D02* -X265304D01* -X272699D02* -X273683D01* -X286553D02* -X287541D01* -X289299D02* -X290376D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X260833Y65685D02* -X262049D01* -X264057D02* -X265262D01* -X272699D02* -X273683D01* -X286559D02* -X287546D01* -X289262D02* -X290359D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X260880Y65778D02* -X262150D01* -X263959D02* -X265216D01* -X272699D02* -X273683D01* -X286572D02* -X287574D01* -X289215D02* -X290339D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X260934Y65872D02* -X262273D01* -X263836D02* -X265161D01* -X272699D02* -X273683D01* -X286591D02* -X287633D01* -X289145D02* -X290315D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X260994Y65966D02* -X262439D01* -X263672D02* -X265102D01* -X272699D02* -X273683D01* -X286619D02* -X287749D01* -X289042D02* -X290284D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261061Y66059D02* -X262722D01* -X263387D02* -X265037D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286656D02* -X287961D01* -X288856D02* -X290246D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261130Y66153D02* -X264963D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286701D02* -X290197D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261211Y66247D02* -X264880D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286754D02* -X290141D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261303Y66341D02* -X264789D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286816D02* -X290076D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261404Y66434D02* -X264683D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286889D02* -X289998D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261514Y66528D02* -X264563D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X286987D02* -X289903D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261652Y66622D02* -X264424D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X287103D02* -X289787D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X261813Y66715D02* -X264255D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X287246D02* -X289640D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X262029Y66809D02* -X264040D01* -X270711D02* -X271695D01* -X272699D02* -X273683D01* -X278668D02* -X279652D01* -X287444D02* -X289449D01* -X295379D02* -X296363D01* -X308508D02* -X309492D01* -X262338Y66903D02* -X263722D01* -X287737D02* -X289139D01* -X0Y0D02* -M02* diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.mop b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.mop deleted file mode 100644 index af32a27f5..000000000 --- a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.mop +++ /dev/null @@ -1,454 +0,0 @@ -MOPFILE 2 -DESIGN_TYPE PCB_DESIGN -DESCRIPTION "" -# ============ -PLOT "Top Silkscreen" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_TOP LAYERTYPE NONELEC NAME "Top Silkscreen" LAYERTYPENAME "Silk Screen" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Top Copper" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_TOP LAYERTYPE ELECTRICAL NAME "Top Copper" LAYERTYPENAME "Electrical" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Top Copper (Resist)" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_TOP LAYERTYPE ELECTRICAL NAME "Top Copper" LAYERTYPENAME "Electrical" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -PADS_ONLY OVERSIZE_ABSOLUTE 1 OVERSIZE 1270 OVERSIZE_PERCENT 10 LARGER TESTLAND_VIAS DRILLED_PADS UNDRILLED_PADS -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Top Paste" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED N -VARIANTNAME "" -LAYER SIDE SIDE_TOP LAYERTYPE NONELEC NAME "Top Paste" LAYERTYPENAME "Paste Mask" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED Y -BOARDUNPLATED Y -PINS Y -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS Y -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2285365 2921635 3023235 2285365 -ENDPLOT -# ============ -PLOT "Top Assembly" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_TOP LAYERTYPE NONELEC NAME "Top Assembly" LAYERTYPENAME "Assembly" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Bottom Copper" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_BOTTOM LAYERTYPE ELECTRICAL NAME "Bottom Copper" LAYERTYPENAME "Electrical" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Bottom Paste" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED N -VARIANTNAME "" -LAYER SIDE SIDE_BOTTOM LAYERTYPE NONELEC NAME "Bottom Paste" LAYERTYPENAME "Paste Mask" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Bottom Resist" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER SIDE SIDE_BOTTOM LAYERTYPE NONELEC NAME "Bottom Resist" LAYERTYPENAME "Solder Mask" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Gerber Drill Data - [Through Hole]" -DEVICETYPE 1 -PLOT_TYPE OUTPUT_TO -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER LAYERTYPE SPAN NAME "[Through Hole]" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -DRILLPLATEDBOARD N -DRILLUNPLATEDBOARD N -DRILLPLATEDHOLES Y -DRILLUNPLATEDHOLES Y -DRILLROUNDHOLES Y -DRILLSLOTS Y -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "NC Drill Data - [Through Hole]" -DEVICETYPE 4 -PLOT_TYPE OUTPUT_TO -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER LAYERTYPE SPAN NAME "[Through Hole]" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -DRILLPLATEDBOARD N -DRILLUNPLATEDBOARD N -DRILLPLATEDHOLES Y -DRILLUNPLATEDHOLES Y -DRILLROUNDHOLES Y -DRILLSLOTS Y -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Drill Ident Drawing - [Through Hole]" -DEVICETYPE 1 -PLOT_TYPE DRILLIDENT -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER LAYERTYPE SPAN NAME "[Through Hole]" -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD N -BOARDPLATED N -BOARDUNPLATED N -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -DRILLPLATEDBOARD Y -DRILLUNPLATEDBOARD Y -DRILLPLATEDHOLES Y -DRILLUNPLATEDHOLES Y -DRILLROUNDHOLES Y -DRILLSLOTS Y -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT -# ============ -PLOT "Board Outline" -DEVICETYPE 1 -PLOT_TYPE ARTWORK -OUTPUT_TO FILE -PLOTENABLED Y -VARIANTNAME "" -LAYER BOARDUNPLATED Y -ALL_COLOURS_BLACK Y -FILL_DRILL_HOLES Y -FILL_UNPLATED_DRILL_HOLES Y -INCLUDE_DRILLED_OUT Y -EXCLUDE_TENTED N -BOARD Y -BOARDPLATED N -BOARDUNPLATED Y -PINS N -PIN_NAME N -COMBINE_PLOTS Y -BOOKMARKS Y -COMPONENT_DETAILS Y -SYMBOL_DETAILS Y -LINK_NET_NAMES Y -BLOCK_DETAILS Y -PUSH_INTO_BLOCK Y -VIEW_PDF Y -PDF_ALL_COLOURS_BLACK N -PANELOUTLINES N -PANELPCBCONTENTS N -MIRROR N -ROTATE N -SCALE 1.000000 -OFFSET 0 0 -PLOT_BOUNDS_TYPE FIT_DESIGN -PLOT_BOUNDS 2209165 2921635 3124835 2285365 -ENDPLOT diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.pcb b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.pcb deleted file mode 100644 index 70574c8ea..000000000 Binary files a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.pcb and /dev/null differ diff --git a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.zip b/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.zip deleted file mode 100644 index c5b147b29..000000000 Binary files a/src/kits/farm-animal-tracker/PICO_FarmAnimalManager_v5.zip and /dev/null differ diff --git a/src/kits/farm-animal-tracker/WireDiagram.psd b/src/kits/farm-animal-tracker/WireDiagram.psd deleted file mode 100644 index 784576588..000000000 Binary files a/src/kits/farm-animal-tracker/WireDiagram.psd and /dev/null differ diff --git a/src/kits/farm-animal-tracker/main.py b/src/kits/farm-animal-tracker/main.py deleted file mode 100644 index 9a6b726e7..000000000 --- a/src/kits/farm-animal-tracker/main.py +++ /dev/null @@ -1,50 +0,0 @@ -# farm animal manager - -from mfrc522 import MFRC522 -import utime -import machine -from time import sleep -from ssd1306 import SSD1306_I2C - -reader = MFRC522(spi_id=0,sck=6,miso=4,mosi=7,cs=5,rst=22) - -i2c = machine.I2C(0, sda=machine.Pin(16), scl=machine.Pin(17)) -# setup the display driver using the i2c interface -oled = SSD1306_I2C(128, 64, i2c) - -def my_function(myCard): - if myCard == "980505127": - return "Animal-1" - elif myCard == "1535192762": - return "Animal-2" - elif myCard == "2760850942": - return "Animal-3" - else: - return "Unknown!" - -while True: - reader.init() - (stat, tag_type) = reader.request(reader.REQIDL) - if stat == reader.OK: - (stat, uid) = reader.SelectTagSN() - if stat == reader.OK: - card = int.from_bytes(bytes(uid),"little",False) - - oled.fill(0) - oled.show() - oled.text(str(card), 0, 0) - oled.text(my_function(str(card)), 0, 15) - oled.show() - - print("ID: "+str(card)) - print(my_function(str(card))) - - else: - print("Waiting for animal.") - oled.fill(0) - oled.show() - oled.text("Waiting for", 0, 0) - oled.text("animal.", 0, 15) - oled.show() - -utime.sleep_ms(500) diff --git a/src/kits/farm-animal-tracker/mfrc522.py b/src/kits/farm-animal-tracker/mfrc522.py deleted file mode 100644 index 794326923..000000000 --- a/src/kits/farm-animal-tracker/mfrc522.py +++ /dev/null @@ -1,382 +0,0 @@ -#mfrc522.py - -from machine import Pin, SPI -from os import uname - - -class MFRC522: - - DEBUG = False - OK = 0 - NOTAGERR = 1 - ERR = 2 - - REQIDL = 0x26 - REQALL = 0x52 - AUTHENT1A = 0x60 - AUTHENT1B = 0x61 - - PICC_ANTICOLL1 = 0x93 - PICC_ANTICOLL2 = 0x95 - PICC_ANTICOLL3 = 0x97 - - - def __init__(self, sck, mosi, miso, rst, cs,baudrate=1000000,spi_id=0): - - self.sck = Pin(sck, Pin.OUT) - self.mosi = Pin(mosi, Pin.OUT) - self.miso = Pin(miso) - self.rst = Pin(rst, Pin.OUT) - self.cs = Pin(cs, Pin.OUT) - - self.rst.value(0) - self.cs.value(1) - - board = uname()[0] - - if board == 'WiPy' or board == 'LoPy' or board == 'FiPy': - self.spi = SPI(0) - self.spi.init(SPI.MASTER, baudrate=1000000, pins=(self.sck, self.mosi, self.miso)) - elif (board == 'esp8266') or (board == 'esp32'): - self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso) - self.spi.init() - elif board == 'rp2': - self.spi = SPI(spi_id,baudrate=baudrate,sck=self.sck, mosi= self.mosi, miso= self.miso) - else: - raise RuntimeError("Unsupported platform") - - self.rst.value(1) - self.init() - - def _wreg(self, reg, val): - - self.cs.value(0) - self.spi.write(b'%c' % int(0xff & ((reg << 1) & 0x7e))) - self.spi.write(b'%c' % int(0xff & val)) - self.cs.value(1) - - def _rreg(self, reg): - - self.cs.value(0) - self.spi.write(b'%c' % int(0xff & (((reg << 1) & 0x7e) | 0x80))) - val = self.spi.read(1) - self.cs.value(1) - - return val[0] - - def _sflags(self, reg, mask): - self._wreg(reg, self._rreg(reg) | mask) - - def _cflags(self, reg, mask): - self._wreg(reg, self._rreg(reg) & (~mask)) - - def _tocard(self, cmd, send): - - recv = [] - bits = irq_en = wait_irq = n = 0 - stat = self.ERR - - if cmd == 0x0E: - irq_en = 0x12 - wait_irq = 0x10 - elif cmd == 0x0C: - irq_en = 0x77 - wait_irq = 0x30 - - self._wreg(0x02, irq_en | 0x80) - self._cflags(0x04, 0x80) - self._sflags(0x0A, 0x80) - self._wreg(0x01, 0x00) - - for c in send: - self._wreg(0x09, c) - self._wreg(0x01, cmd) - - if cmd == 0x0C: - self._sflags(0x0D, 0x80) - - i = 2000 - while True: - n = self._rreg(0x04) - i -= 1 - if ~((i != 0) and ~(n & 0x01) and ~(n & wait_irq)): - break - - self._cflags(0x0D, 0x80) - - if i: - if (self._rreg(0x06) & 0x1B) == 0x00: - stat = self.OK - - if n & irq_en & 0x01: - stat = self.NOTAGERR - elif cmd == 0x0C: - n = self._rreg(0x0A) - lbits = self._rreg(0x0C) & 0x07 - if lbits != 0: - bits = (n - 1) * 8 + lbits - else: - bits = n * 8 - - if n == 0: - n = 1 - elif n > 16: - n = 16 - - for _ in range(n): - recv.append(self._rreg(0x09)) - else: - stat = self.ERR - - return stat, recv, bits - - def _crc(self, data): - - self._cflags(0x05, 0x04) - self._sflags(0x0A, 0x80) - - for c in data: - self._wreg(0x09, c) - - self._wreg(0x01, 0x03) - - i = 0xFF - while True: - n = self._rreg(0x05) - i -= 1 - if not ((i != 0) and not (n & 0x04)): - break - - return [self._rreg(0x22), self._rreg(0x21)] - - def init(self): - - self.reset() - self._wreg(0x2A, 0x8D) - self._wreg(0x2B, 0x3E) - self._wreg(0x2D, 30) - self._wreg(0x2C, 0) - self._wreg(0x15, 0x40) - self._wreg(0x11, 0x3D) - self.antenna_on() - - def reset(self): - self._wreg(0x01, 0x0F) - - def antenna_on(self, on=True): - - if on and ~(self._rreg(0x14) & 0x03): - self._sflags(0x14, 0x03) - else: - self._cflags(0x14, 0x03) - - def request(self, mode): - - self._wreg(0x0D, 0x07) - (stat, recv, bits) = self._tocard(0x0C, [mode]) - - if (stat != self.OK) | (bits != 0x10): - stat = self.ERR - - return stat, bits - - def anticoll(self,anticolN): - - ser_chk = 0 - ser = [anticolN, 0x20] - - self._wreg(0x0D, 0x00) - (stat, recv, bits) = self._tocard(0x0C, ser) - - if stat == self.OK: - if len(recv) == 5: - for i in range(4): - ser_chk = ser_chk ^ recv[i] - if ser_chk != recv[4]: - stat = self.ERR - else: - stat = self.ERR - - return stat, recv - - - def PcdSelect(self, serNum,anticolN): - backData = [] - buf = [] - buf.append(anticolN) - buf.append(0x70) - #i = 0 - ###xorsum=0; - for i in serNum: - buf.append(i) - #while i<5: - # buf.append(serNum[i]) - # i = i + 1 - pOut = self._crc(buf) - buf.append(pOut[0]) - buf.append(pOut[1]) - (status, backData, backLen) = self._tocard( 0x0C, buf) - if (status == self.OK) and (backLen == 0x18): - return 1 - else: - return 0 - - - def SelectTag(self, uid): - byte5 = 0 - - #(status,puid)= self.anticoll(self.PICC_ANTICOLL1) - #print("uid",uid,"puid",puid) - for i in uid: - byte5 = byte5 ^ i - puid = uid + [byte5] - - if self.PcdSelect(puid,self.PICC_ANTICOLL1) == 0: - return (self.ERR,[]) - return (self.OK , uid) - - def tohexstring(self,v): - s="[" - for i in v: - if i != v[0]: - s = s+ ", " - s=s+ "0x{:02X}".format(i) - s= s+ "]" - return s - - - - - def SelectTagSN(self): - valid_uid=[] - (status,uid)= self.anticoll(self.PICC_ANTICOLL1) - #print("Select Tag 1:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - - if self.DEBUG: print("anticol(1) {}".format(uid)) - if self.PcdSelect(uid,self.PICC_ANTICOLL1) == 0: - return (self.ERR,[]) - if self.DEBUG: print("pcdSelect(1) {}".format(uid)) - - #check if first byte is 0x88 - if uid[0] == 0x88 : - #ok we have another type of card - valid_uid.extend(uid[1:4]) - (status,uid)=self.anticoll(self.PICC_ANTICOLL2) - #print("Select Tag 2:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - if self.DEBUG: print("Anticol(2) {}".format(uid)) - rtn = self.PcdSelect(uid,self.PICC_ANTICOLL2) - if self.DEBUG: print("pcdSelect(2) return={} uid={}".format(rtn,uid)) - if rtn == 0: - return (self.ERR,[]) - if self.DEBUG: print("PcdSelect2() {}".format(uid)) - #now check again if uid[0] is 0x88 - if uid[0] == 0x88 : - valid_uid.extend(uid[1:4]) - (status , uid) = self.anticoll(self.PICC_ANTICOLL3) - #print("Select Tag 3:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - if self.DEBUG: print("Anticol(3) {}".format(uid)) - if self.MFRC522_PcdSelect(uid,self.PICC_ANTICOLL3) == 0: - return (self.ERR,[]) - if self.DEBUG: print("PcdSelect(3) {}".format(uid)) - valid_uid.extend(uid[0:5]) - # if we are here than the uid is ok - # let's remove the last BYTE whic is the XOR sum - - return (self.OK , valid_uid[:len(valid_uid)-1]) - #return (self.OK , valid_uid) - - - - - - - def auth(self, mode, addr, sect, ser): - return self._tocard(0x0E, [mode, addr] + sect + ser[:4])[0] - - def authKeys(self,uid,addr,keyA=None, keyB=None): - status = self.ERR - if keyA is not None: - status = self.auth(self.AUTHENT1A, addr, keyA, uid) - elif keyB is not None: - status = self.auth(self.AUTHENT1B, addr, keyB, uid) - return status - - - def stop_crypto1(self): - self._cflags(0x08, 0x08) - - def read(self, addr): - - data = [0x30, addr] - data += self._crc(data) - (stat, recv, _) = self._tocard(0x0C, data) - return stat, recv - - def write(self, addr, data): - - buf = [0xA0, addr] - buf += self._crc(buf) - (stat, recv, bits) = self._tocard(0x0C, buf) - - if not (stat == self.OK) or not (bits == 4) or not ((recv[0] & 0x0F) == 0x0A): - stat = self.ERR - else: - buf = [] - for i in range(16): - buf.append(data[i]) - buf += self._crc(buf) - (stat, recv, bits) = self._tocard(0x0C, buf) - if not (stat == self.OK) or not (bits == 4) or not ((recv[0] & 0x0F) == 0x0A): - stat = self.ERR - return stat - - - def writeSectorBlock(self,uid, sector, block, data, keyA=None, keyB = None): - absoluteBlock = sector * 4 + (block % 4) - if absoluteBlock > 63 : - return self.ERR - if len(data) != 16: - return self.ERR - if self.authKeys(uid,absoluteBlock,keyA,keyB) != self.ERR : - return self.write(absoluteBlock, data) - return self.ERR - - def readSectorBlock(self,uid ,sector, block, keyA=None, keyB = None): - absoluteBlock = sector * 4 + (block % 4) - if absoluteBlock > 63 : - return self.ERR, None - if self.authKeys(uid,absoluteBlock,keyA,keyB) != self.ERR : - return self.read(absoluteBlock) - return self.ERR, None - - def MFRC522_DumpClassic1K(self,uid, Start=0, End=64, keyA=None, keyB=None): - for absoluteBlock in range(Start,End): - status = self.authKeys(uid,absoluteBlock,keyA,keyB) - # Check if authenticated - print("{:02d} S{:02d} B{:1d}: ".format(absoluteBlock, absoluteBlock//4 , absoluteBlock % 4),end="") - if status == self.OK: - status, block = self.read(absoluteBlock) - if status == self.ERR: - break - else: - for value in block: - print("{:02X} ".format(value),end="") - print(" ",end="") - for value in block: - if (value > 0x20) and (value < 0x7f): - print(chr(value),end="") - else: - print('.',end="") - print("") - else: - break - if status == self.ERR: - print("Authentication error") - return self.ERR - return self.OK \ No newline at end of file diff --git a/src/kits/farm-animal-tracker/ssd1306.py b/src/kits/farm-animal-tracker/ssd1306.py deleted file mode 100644 index e94913705..000000000 --- a/src/kits/farm-animal-tracker/ssd1306.py +++ /dev/null @@ -1,168 +0,0 @@ -# MicroPython SSD1306 OLED driver, I2C and SPI interfaces - -import time -import framebuf - - -# register definitions -SET_CONTRAST = const(0x81) -SET_ENTIRE_ON = const(0xa4) -SET_NORM_INV = const(0xa6) -SET_DISP = const(0xae) -SET_MEM_ADDR = const(0x20) -SET_COL_ADDR = const(0x21) -SET_PAGE_ADDR = const(0x22) -SET_DISP_START_LINE = const(0x40) -SET_SEG_REMAP = const(0xa0) -SET_MUX_RATIO = const(0xa8) -SET_COM_OUT_DIR = const(0xc0) -SET_DISP_OFFSET = const(0xd3) -SET_COM_PIN_CFG = const(0xda) -SET_DISP_CLK_DIV = const(0xd5) -SET_PRECHARGE = const(0xd9) -SET_VCOM_DESEL = const(0xdb) -SET_CHARGE_PUMP = const(0x8d) - - -class SSD1306: - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - # Note the subclass must initialize self.framebuf to a framebuffer. - # This is necessary because the underlying data buffer is different - # between I2C and SPI implementations (I2C needs an extra byte). - self.poweron() - self.init_display() - - def init_display(self): - for cmd in ( - SET_DISP | 0x00, # off - # address setting - SET_MEM_ADDR, 0x00, # horizontal - # resolution and layout - SET_DISP_START_LINE | 0x00, - SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 - SET_MUX_RATIO, self.height - 1, - SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0 - SET_DISP_OFFSET, 0x00, - SET_COM_PIN_CFG, 0x02 if self.height == 32 else 0x12, - # timing and driving scheme - SET_DISP_CLK_DIV, 0x80, - SET_PRECHARGE, 0x22 if self.external_vcc else 0xf1, - SET_VCOM_DESEL, 0x30, # 0.83*Vcc - # display - SET_CONTRAST, 0xff, # maximum - SET_ENTIRE_ON, # output follows RAM contents - SET_NORM_INV, # not inverted - # charge pump - SET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14, - SET_DISP | 0x01): # on - self.write_cmd(cmd) - self.fill(0) - self.show() - - def poweroff(self): - self.write_cmd(SET_DISP | 0x00) - - def contrast(self, contrast): - self.write_cmd(SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(SET_NORM_INV | (invert & 1)) - - def show(self): - x0 = 0 - x1 = self.width - 1 - if self.width == 64: - # displays with width of 64 pixels are shifted by 32 - x0 += 32 - x1 += 32 - self.write_cmd(SET_COL_ADDR) - self.write_cmd(x0) - self.write_cmd(x1) - self.write_cmd(SET_PAGE_ADDR) - self.write_cmd(0) - self.write_cmd(self.pages - 1) - self.write_framebuf() - - def fill(self, col): - self.framebuf.fill(col) - - def pixel(self, x, y, col): - self.framebuf.pixel(x, y, col) - - def scroll(self, dx, dy): - self.framebuf.scroll(dx, dy) - - def text(self, string, x, y, col=1): - self.framebuf.text(string, x, y, col) - - -class SSD1306_I2C(SSD1306): - def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.temp = bytearray(2) - # Add an extra byte to the data buffer to hold an I2C data/command byte - # to use hardware-compatible I2C transactions. A memoryview of the - # buffer is used to mask this byte from the framebuffer operations - # (without a major memory hit as memoryview doesn't copy to a separate - # buffer). - self.buffer = bytearray(((height // 8) * width) + 1) - self.buffer[0] = 0x40 # Set first byte of data buffer to Co=0, D/C=1 - self.framebuf = framebuf.FrameBuffer1(memoryview(self.buffer)[1:], width, height) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_framebuf(self): - # Blast out the frame buffer using a single I2C transaction to support - # hardware I2C interfaces. - self.i2c.writeto(self.addr, self.buffer) - - def poweron(self): - pass - - -class SSD1306_SPI(SSD1306): - def __init__(self, width, height, spi, dc, res, cs, external_vcc=False): - self.rate = 10 * 1024 * 1024 - dc.init(dc.OUT, value=0) - res.init(res.OUT, value=0) - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - self.buffer = bytearray((height // 8) * width) - self.framebuf = framebuf.FrameBuffer1(self.buffer, width, height) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs.high() - self.dc.low() - self.cs.low() - self.spi.write(bytearray([cmd])) - self.cs.high() - - def write_framebuf(self): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs.high() - self.dc.high() - self.cs.low() - self.spi.write(self.buffer) - self.cs.high() - - def poweron(self): - self.res.high() - time.sleep_ms(1) - self.res.low() - time.sleep_ms(10) - self.res.high() diff --git a/src/kits/farm-animal-tracker/video1557917208.mp4 b/src/kits/farm-animal-tracker/video1557917208.mp4 deleted file mode 100644 index 5cdd57b33..000000000 Binary files a/src/kits/farm-animal-tracker/video1557917208.mp4 and /dev/null differ diff --git a/src/kits/h-bridge/03-move-pixel.py b/src/kits/h-bridge/03-move-pixel.py deleted file mode 100644 index 6152fb7f1..000000000 --- a/src/kits/h-bridge/03-move-pixel.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin -from time import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - strip[i] = (255,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(.1) # keep on 1/10 of a second - strip[i] = (0,0,0) # change the RAM back but don't resend the data \ No newline at end of file diff --git a/src/kits/h-bridge/05-rainbow-cycle.py b/src/kits/h-bridge/05-rainbow-cycle.py deleted file mode 100644 index a3e698e32..000000000 --- a/src/kits/h-bridge/05-rainbow-cycle.py +++ /dev/null @@ -1,37 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 12 -NUMBER_PIXELS = 28 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(wait): - global NUMBER_PIXELS, strip - for j in range(255): - for i in range(NUMBER_PIXELS): - rc_index = (i * 256 // NUMBER_PIXELS) + j - # print(rc_index) - strip[i] = wheel(rc_index & 255) - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(.05) - counter += 1 \ No newline at end of file diff --git a/src/kits/h-bridge/07-show-segments.py b/src/kits/h-bridge/07-show-segments.py deleted file mode 100644 index 17be50cd1..000000000 --- a/src/kits/h-bridge/07-show-segments.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -off = (0,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -for i in range(0, num_segments): - seg_length = segments[i][1] - segments[i][0] + 1 - print(i, seg_length) - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = colors[i] - strip.write() - diff --git a/src/kits/h-bridge/08-animate-segments.py b/src/kits/h-bridge/08-animate-segments.py deleted file mode 100644 index 501090bec..000000000 --- a/src/kits/h-bridge/08-animate-segments.py +++ /dev/null @@ -1,36 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -delay = 0.5 -while True: - for i in range(0, num_segments): - seg_length = segments[i][1] - segments[i][0] + 1 - print(i, seg_length) - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - diff --git a/src/kits/h-bridge/09-animate-forward.py b/src/kits/h-bridge/09-animate-forward.py deleted file mode 100644 index 10d9f5125..000000000 --- a/src/kits/h-bridge/09-animate-forward.py +++ /dev/null @@ -1,53 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -delay = 0.1 -while True: - seg_counter = 0 - for i in foward_segments: - seg_length = segments[i][1] - segments[i][0] + 1 - print("seg:", i, - " len:", seg_length, - " start:", segments[i][0], - " end:", segments[i][1], - " dir:", forward_directions[seg_counter]) - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - else: - print("range:", segments[i][1], "to:", segments[i][0]) - for j in range(segments[i][1], segments[i][0]-1, -1): - # print(j) - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - seg_counter += 1 - diff --git a/src/kits/h-bridge/10-fwd-rev.py b/src/kits/h-bridge/10-fwd-rev.py deleted file mode 100644 index d0aeabcab..000000000 --- a/src/kits/h-bridge/10-fwd-rev.py +++ /dev/null @@ -1,80 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -delay = 0.1 -while True: - seg_counter = 0 - for i in foward_segments: - seg_length = segments[i][1] - segments[i][0] + 1 - print("fwd seg:", i, - " len:", seg_length, - " start:", segments[i][0], - " end:", segments[i][1], - " dir:", forward_directions[seg_counter]) - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - else: - # print("range:", segments[i][1], "to:", segments[i][0]) - for j in range(segments[i][1], segments[i][0]-1, -1): - # print(j) - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - seg_counter += 1 - - # reverse animation - seg_counter = 0 - for i in reverse_segments: - seg_length = segments[i][1] - segments[i][0] + 1 - print("rev seg:", i, - " len:", seg_length, - " start:", segments[i][0], - " end:", segments[i][1], - " dir:", reverse_directions[seg_counter]) - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - else: - # print("range:", segments[i][1], "to:", segments[i][0]) - for j in range(segments[i][1], segments[i][0]-1, -1): - # print(j) - strip[j] = colors[i] - strip.write() - sleep(delay) - strip[j] = off - seg_counter += 1 - diff --git a/src/kits/h-bridge/12-fwd-rev-colors.py b/src/kits/h-bridge/12-fwd-rev-colors.py deleted file mode 100644 index a5c2208fe..000000000 --- a/src/kits/h-bridge/12-fwd-rev-colors.py +++ /dev/null @@ -1,83 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -delay = 0.1 -while True: - seg_counter = 0 - for i in foward_segments: - seg_length = segments[i][1] - segments[i][0] + 1 - print("fwd seg:", i, - " len:", seg_length, - " start:", segments[i][0], - " end:", segments[i][1], - " dir:", forward_directions[seg_counter]) - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = lightblue - strip.write() - sleep(delay) - strip[j] = off - else: - # print("range:", segments[i][1], "to:", segments[i][0]) - for j in range(segments[i][1], segments[i][0]-1, -1): - # print(j) - strip[j] = lightblue - strip.write() - sleep(delay) - strip[j] = off - seg_counter += 1 - - # reverse animation - seg_counter = 0 - for i in reverse_segments: - seg_length = segments[i][1] - segments[i][0] + 1 - print("rev seg:", i, - " len:", seg_length, - " start:", segments[i][0], - " end:", segments[i][1], - " dir:", reverse_directions[seg_counter]) - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - strip[j] = lightgreen - strip.write() - sleep(delay) - strip[j] = off - else: - # print("range:", segments[i][1], "to:", segments[i][0]) - for j in range(segments[i][1], segments[i][0]-1, -1): - # print(j) - strip[j] = lightgreen - strip.write() - sleep(delay) - strip[j] = off - seg_counter += 1 - diff --git a/src/kits/h-bridge/12-fwd-rev-functions.py b/src/kits/h-bridge/12-fwd-rev-functions.py deleted file mode 100644 index a363153c6..000000000 --- a/src/kits/h-bridge/12-fwd-rev-functions.py +++ /dev/null @@ -1,86 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -# lower right, upper right, upper left, lower left, middle right, middle left -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -# upper left, middle left, middle right, lower right -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -forward_list = [] -# upper right, middle right, middle left, lower left -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] -reverse_list = [] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -def make_forward_list(): - seg_counter = 0 - for i in foward_segments: - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - forward_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - forward_list.append(j) - seg_counter += 1 - -def make_reverse_list(): - seg_counter = 0 - for i in reverse_segments: - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - reverse_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - reverse_list.append(j) - seg_counter += 1 - -def forward(): - for i in forward_list: - strip[i] = lightblue - strip.write() - sleep(delay) - strip[i] = off - -def reverse(): - for i in reverse_list: - strip[i] = lightgreen - strip.write() - sleep(delay) - strip[i] = off - -delay = 0.2 - -make_forward_list() -print(forward_list) -make_reverse_list() -print(reverse_list) - -while True: - forward() - reverse() - - - diff --git a/src/kits/h-bridge/13-wire-animate.py b/src/kits/h-bridge/13-wire-animate.py deleted file mode 100644 index 8c1808591..000000000 --- a/src/kits/h-bridge/13-wire-animate.py +++ /dev/null @@ -1,109 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -# lower right, upper right, upper left, lower left, middle right, middle left -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -# upper left, middle left, middle right, lower right -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -forward_list = [] -# upper right, middle right, middle left, lower left -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] -reverse_list = [] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -def make_forward_list(): - seg_counter = 0 - for i in foward_segments: - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - forward_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - forward_list.append(j) - seg_counter += 1 - -def make_reverse_list(): - seg_counter = 0 - for i in reverse_segments: - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - reverse_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - reverse_list.append(j) - seg_counter += 1 - -# draw every third pixel on -def forward(start, delay): - #print("fwd:", start) - length = len(forward_list) - for i in range(0, length): - # print(start, i, forward_list[i+start], not((i) % 3)) - if (i+start) < (length-1) and not((i+start) % 3): - strip[forward_list[i]] = lightblue - # print("on: ", forward_list[i]) - else: - if (i+start) < length-1: - strip[forward_list[i]] = off - strip.write() - sleep(delay) - -def reverse(start, delay): - #print("rev:", start) - length = len(reverse_list) - for i in range(0, length): - #print(i+start) - if not((i+start) % 3) and (i+start) < (length-1): - strip[reverse_list[i]] = lightgreen - else: - if (i+start) < length-1: - strip[reverse_list[i]] = off - strip.write() - sleep(delay) - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = off - strip.write() - -delay = .2 - -make_forward_list() -print(forward_list) -make_reverse_list() -print(reverse_list) - -while True: - for i in range(0, 40): - forward(i%3, delay) - clear() - for i in range(0, 40): - reverse(i%3, delay) - clear() - - - diff --git a/src/kits/h-bridge/20-motor-test.py b/src/kits/h-bridge/20-motor-test.py deleted file mode 100644 index a311f6dcb..000000000 --- a/src/kits/h-bridge/20-motor-test.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -MAX_POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - - -forward = PWM(Pin(RIGHT_FORWARD_PIN)) -reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -# set the frequencey to be 50 Khz -forward.freq(50) -reverse.freq(50) - -while True: - print('forward') - forward.duty_u16(MAX_POWER_LEVEL) - reverse.duty_u16(0) - sleep(2) - - print('reverse') - reverse.duty_u16(MAX_POWER_LEVEL) - forward.duty_u16(0) - sleep(2) - - print('stop') - reverse.duty_u16(0) - forward.duty_u16(0) - sleep(3) \ No newline at end of file diff --git a/src/kits/h-bridge/21-stop-motors.py b/src/kits/h-bridge/21-stop-motors.py deleted file mode 100644 index 87f6251be..000000000 --- a/src/kits/h-bridge/21-stop-motors.py +++ /dev/null @@ -1,18 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -MAX_POWER_LEVEL = 65025 -# lower right pins with USB on top -FORWARD_PIN = 8 -REVERSE_PIN = 9 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -# set the frequencey to be 50 Khz -forward.freq(50) -reverse.freq(50) - -# turn off the PWM -reverse.duty_u16(0) -forward.duty_u16(0) diff --git a/src/kits/h-bridge/23-switch-test.py b/src/kits/h-bridge/23-switch-test.py deleted file mode 100644 index b0234cb9d..000000000 --- a/src/kits/h-bridge/23-switch-test.py +++ /dev/null @@ -1,61 +0,0 @@ -# swith status with no debounce logic -from machine import Pin - -builtin_led = Pin(25) -# Upper left swith -UL_PIN = 2 -LL_PIN = 3 -UR_PIN = 14 -LR_PIN = 15 - -ul_switch = Pin(UL_PIN, Pin.IN, Pin.PULL_UP) -ll_switch = Pin(LL_PIN, Pin.IN, Pin.PULL_UP) -ur_switch = Pin(UR_PIN, Pin.IN, Pin.PULL_UP) -lr_switch = Pin(LR_PIN, Pin.IN, Pin.PULL_UP) - -# old values -ul_val = 0 -ll_val = 0 -ur_val = 0 -lr_val = 0 - -counter = 0 -while True: - # only print on change in the button_presses value - - new_ul_switch = ul_switch.value() - if ul_val != new_ul_switch: - if new_ul_switch == 0: - print("Upper Right = On") - else: print("Upper Right = Off") - builtin_led.toggle() - ul_val = new_ul_switch - counter += 1 - - new_ll_switch = ll_switch.value() - if ll_val != new_ll_switch: - if new_ll_switch == 0: - print("Lower Left = On") - else: print("Lower Left = Off") - builtin_led.toggle() - ll_val = new_ll_switch - counter += 1 - - - new_ur_switch = ur_switch.value() - if ur_val != new_ur_switch: - if new_ur_switch == 0: - print("Upper Right = On") - else: print("Upper Right = Off") - builtin_led.toggle() - ur_val = new_ur_switch - counter += 1 - - new_lr_switch = lr_switch.value() - if lr_val != new_lr_switch: - if new_lr_switch == 0: - print("Lower Right = On") - else: print("Lower Right = Off") - builtin_led.toggle() - lr_val = new_lr_switch - counter += 1 \ No newline at end of file diff --git a/src/kits/h-bridge/24-switch-debounce.py b/src/kits/h-bridge/24-switch-debounce.py deleted file mode 100644 index 455a9946b..000000000 --- a/src/kits/h-bridge/24-switch-debounce.py +++ /dev/null @@ -1,101 +0,0 @@ -# swith status with no debounce logic -from machine import Pin -from utime import sleep, ticks_ms - -builtin_led = Pin(25) -# Upper left swith -UL_PIN = 2 -LL_PIN = 3 -UR_PIN = 14 -LR_PIN = 13 - -ul_switch = Pin(UL_PIN, Pin.IN, Pin.PULL_UP) -ll_switch = Pin(LL_PIN, Pin.IN, Pin.PULL_UP) -ur_switch = Pin(UR_PIN, Pin.IN, Pin.PULL_UP) -lr_switch = Pin(LR_PIN, Pin.IN, Pin.PULL_UP) - -# get current values as global variables -ul = ul_switch.value() -ll = ll_switch.value() -ur = ur_switch.value() -lr = lr_switch.value() - -# old values -ul_old = 0 -ll_old = 0 -ur_old = 0 -lr_old = 0 - -last_time = 0 -switch_counter = 0 -# this function gets called every time the button is pressed -def switch_changed_handler(pin): - global last_time, switch_counter, ul, ll, ur, lr - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if 'GPIO2' in str(pin): - if ul == 0: - ul = 1 - else: ul = 0 - if 'GPIO3' in str(pin): - if ll == 0: - ll = 1 - else: ll = 0 - if 'GPIO14' in str(pin): - if ur == 0: - ur = 1 - else: ur = 0 - if 'GPIO13' in str(pin): - if lr == 0: - lr = 1 - else: lr = 0 - switch_counter +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -# https://docs.micropython.org/en/latest/library/machine.Pin.html -ul_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ll_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ur_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -lr_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) - -old_switch_counter = 0 -counter = 0 -print('Startup:', ul, ll, ur, lr) -while True: - # only print on change in the button_presses value - if old_switch_counter != switch_counter: - # print('Switch counter: ', switch_counter) - old_switch_counter = switch_counter - - if ul != ul_old: - if ul == 0: - print("Upper Left = On") - else: print("Upper Left = Off") - builtin_led.toggle() - ul_old = ul - counter += 1 - - if ll != ll_old: - if ll == 0: - print("Lower Left = On") - else: print("Lower Left = Off") - builtin_led.toggle() - ll_old = ll - counter += 1 - - if ur != ur_old: - if ur == 0: - print("Upper Right = On") - else: print("Upper Right = Off") - builtin_led.toggle() - ur_old = ur - counter += 1 - - if lr != lr_old: - if lr == 0: - print("Lower Right = On") - else: print("Lower Right = Off") - builtin_led.toggle() - lr_old = lr diff --git a/src/kits/h-bridge/25-switch-leds.py b/src/kits/h-bridge/25-switch-leds.py deleted file mode 100644 index a8e8ffbff..000000000 --- a/src/kits/h-bridge/25-switch-leds.py +++ /dev/null @@ -1,241 +0,0 @@ -# swith status with no debounce logic -from machine import Pin -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -# lower right, upper right, upper left, lower left, middle right, middle left -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -# upper left, middle left, middle right, lower right -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -forward_list = [] -# upper right, middle right, middle left, lower left -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] -reverse_list = [] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -def make_forward_list(): - seg_counter = 0 - for i in foward_segments: - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - forward_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - forward_list.append(j) - seg_counter += 1 - -def make_reverse_list(): - seg_counter = 0 - for i in reverse_segments: - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - reverse_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - reverse_list.append(j) - seg_counter += 1 - -make_forward_list() -make_reverse_list() - -# draw every third pixel on -state = 2 # 0, 1 or 2 -def draw_forward(delay): - global state - #print("fwd:", start) - length = len(forward_list) + 2 - for i in range(0, length): - # print(start, i, forward_list[i+start], not((i) % 3)) - if (i+state) < (length-1) and not((i+state) % 3): - if i < length-2: - # for a dark room use lightblue - strip[forward_list[i]] = blue - # print("on: ", forward_list[i]) - else: - if (i+state) < length-1: - strip[forward_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -state = 2 -def draw_reverse(delay): - global state - #print("rev:", start) - length = len(reverse_list)+2 - for i in range(0, length): - #print(i+state) - if not((i+state) % 3) and (i+state) < (length-1): - if i < length-2: - strip[reverse_list[i]] = green - else: - if (i+state) < length-1: - strip[reverse_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = off - strip.write() - -# Upper left, lower left, upper right, lower right -UL_PIN = 2 -LL_PIN = 3 -UR_PIN = 14 -LR_PIN = 13 - -ul_switch = Pin(UL_PIN, Pin.IN, Pin.PULL_UP) -ll_switch = Pin(LL_PIN, Pin.IN, Pin.PULL_UP) -ur_switch = Pin(UR_PIN, Pin.IN, Pin.PULL_UP) -lr_switch = Pin(LR_PIN, Pin.IN, Pin.PULL_UP) - -# get current values as global variables -ul = ul_switch.value() -ll = ll_switch.value() -ur = ur_switch.value() -lr = lr_switch.value() - -# old values -ul_old = 0 -ll_old = 0 -ur_old = 0 -lr_old = 0 - -last_time = 0 -switch_counter = 0 -# this function gets called every time the button is pressed -def switch_changed_handler(pin): - global last_time, switch_counter, ul, ll, ur, lr - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if 'GPIO2' in str(pin): - if ul == 0: - ul = 1 - else: ul = 0 - if 'GPIO3' in str(pin): - if ll == 0: - ll = 1 - else: ll = 0 - if 'GPIO14' in str(pin): - if ur == 0: - ur = 1 - else: ur = 0 - if 'GPIO13' in str(pin): - if lr == 0: - lr = 1 - else: lr = 0 - switch_counter +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -# https://docs.micropython.org/en/latest/library/machine.Pin.html -ul_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ll_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ur_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -lr_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) - -delay = .2 -old_switch_counter = 0 -counter = 0 -print('Startup:', ul, ll, ur, lr) -while True: - - if (not(ul) and not(lr) and not(ll) and not(ur) ): - for i in range(0, 20): - strip[i] = red - strip.write() - print('Double Short Circuit') - - elif (not(ul) and not(lr) and ll and ur ): - print('Startup:', ul, ll, ur, lr) - print('forward') - draw_forward(delay) - - elif (not(ll) and not(ur) and ul and lr): - print('reverse') - draw_reverse(delay) - - # short circuit left - elif not(ul) and not(ll): - print('short circuit left') - print('Startup:', ul, ll, ur, lr) - for i in range(10, 20): - strip[i] = red - strip.write() - - # short circuitright - elif not(ur)and not(lr): - print('short circuit right') - print('Startup:', ul, ll, ur, lr) - for i in range(0, 10): - strip[i] = red - strip.write() - - # only print on change in the button_presses value - if old_switch_counter != switch_counter: - # print('Switch counter: ', switch_counter) - old_switch_counter = switch_counter - - if ul != ul_old: - if ul == 0: - print("Upper Left = On") - else: - print("Upper Left = Off") - clear() - ul_old = ul - counter += 1 - - if ll != ll_old: - if ll == 0: - print("Lower Left = On") - else: - print("Lower Left = Off") - clear() - ll_old = ll - counter += 1 - - if ur != ur_old: - if ur == 0: - print("Upper Right = On") - else: - print("Upper Right = Off") - clear() - ur_old = ur - counter += 1 - - if lr != lr_old: - if lr == 0: - print("Lower Right = On") - else: - print("Lower Right = Off") - clear() - lr_old = lr diff --git a/src/kits/h-bridge/30-full-demo-with-motors.py b/src/kits/h-bridge/30-full-demo-with-motors.py deleted file mode 100644 index fe97bda6c..000000000 --- a/src/kits/h-bridge/30-full-demo-with-motors.py +++ /dev/null @@ -1,269 +0,0 @@ -# swith status with no debounce logic -from machine import Pin, PWM -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -# lower right, upper right, upper left, lower left, middle right, middle left -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -# upper left, middle left, middle right, lower right -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -forward_list = [] -# upper right, middle right, middle left, lower left -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] -reverse_list = [] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -def make_forward_list(): - seg_counter = 0 - for i in foward_segments: - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - forward_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - forward_list.append(j) - seg_counter += 1 - -def make_reverse_list(): - seg_counter = 0 - for i in reverse_segments: - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - reverse_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - reverse_list.append(j) - seg_counter += 1 - -make_forward_list() -make_reverse_list() - -# draw every third pixel on -state = 2 # 0, 1 or 2 -def draw_forward(delay): - global state - #print("fwd:", start) - length = len(forward_list) + 2 - for i in range(0, length): - # print(start, i, forward_list[i+start], not((i) % 3)) - if (i+state) < (length-1) and not((i+state) % 3): - if i < length-2: - # for a dark room use lightblue - strip[forward_list[i]] = blue - # print("on: ", forward_list[i]) - else: - if (i+state) < length-1: - strip[forward_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -state = 2 -def draw_reverse(delay): - global state - #print("rev:", start) - length = len(reverse_list)+2 - for i in range(0, length): - #print(i+state) - if not((i+state) % 3) and (i+state) < (length-1): - if i < length-2: - strip[reverse_list[i]] = green - else: - if (i+state) < length-1: - strip[reverse_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = off - strip.write() - -# Upper left, lower left, upper right, lower right -UL_PIN = 2 -LL_PIN = 3 -UR_PIN = 14 -LR_PIN = 13 - -ul_switch = Pin(UL_PIN, Pin.IN, Pin.PULL_UP) -ll_switch = Pin(LL_PIN, Pin.IN, Pin.PULL_UP) -ur_switch = Pin(UR_PIN, Pin.IN, Pin.PULL_UP) -lr_switch = Pin(LR_PIN, Pin.IN, Pin.PULL_UP) - -# get current values as global variables -ul = ul_switch.value() -ll = ll_switch.value() -ur = ur_switch.value() -lr = lr_switch.value() - -# old values -ul_old = 0 -ll_old = 0 -ur_old = 0 -lr_old = 0 - -last_time = 0 -switch_counter = 0 -# this function gets called every time the button is pressed -def switch_changed_handler(pin): - global last_time, switch_counter, ul, ll, ur, lr - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if 'GPIO2' in str(pin): - if ul == 0: - ul = 1 - else: ul = 0 - if 'GPIO3' in str(pin): - if ll == 0: - ll = 1 - else: ll = 0 - if 'GPIO14' in str(pin): - if ur == 0: - ur = 1 - else: ur = 0 - if 'GPIO13' in str(pin): - if lr == 0: - lr = 1 - else: lr = 0 - switch_counter +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -# https://docs.micropython.org/en/latest/library/machine.Pin.html -ul_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ll_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -ur_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) -lr_switch.irq(trigger=(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler = switch_changed_handler) - -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -MAX_POWER_LEVEL = 65025 -POWER_LEVEL = 30000 -forward = PWM(Pin(RIGHT_FORWARD_PIN)) -reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -# set the frequencey to be 50 Khz -forward.freq(50) -reverse.freq(50) - -def stop(): - reverse.duty_u16(0) - forward.duty_u16(0) - -delay = .2 -old_switch_counter = 0 -counter = 0 -print('Startup:', ul, ll, ur, lr) -while True: - - if (not(ul) and not(lr) and not(ll) and not(ur) ): - for i in range(0, 20): - strip[i] = red - strip.write() - stop() - print('Double Short Circuit') - - # short circuit left - elif not(ul) and not(ll): - print('short circuit left') - print('Startup:', ul, ll, ur, lr) - for i in range(10, 20): - strip[i] = red - strip.write() - stop() - - # short circuitright - elif not(ur) and not(lr): - print('short circuit right') - print('Startup:', ul, ll, ur, lr) - for i in range(0, 10): - strip[i] = red - strip.write() - stop() - - elif (not(ul) and not(lr) and ll and ur ): - print('Startup:', ul, ll, ur, lr) - print('forward') - draw_forward(delay) - forward.duty_u16(POWER_LEVEL) - reverse.duty_u16(0) - - elif (not(ll) and not(ur) and ul and lr): - print('reverse') - draw_reverse(delay) - forward.duty_u16(0) - reverse.duty_u16(POWER_LEVEL) - - - # only print on change in the button_presses value - if old_switch_counter != switch_counter: - # print('Switch counter: ', switch_counter) - old_switch_counter = switch_counter - - if ul != ul_old: - if ul == 0: - print("Upper Left = On") - else: - print("Upper Left = Off") - clear() - stop() - ul_old = ul - counter += 1 - - if ll != ll_old: - if ll == 0: - print("Lower Left = On") - else: - print("Lower Left = Off") - clear() - stop() - ll_old = ll - counter += 1 - - if ur != ur_old: - if ur == 0: - print("Upper Right = On") - else: - print("Upper Right = Off") - clear() - stop() - ur_old = ur - counter += 1 - - if lr != lr_old: - if lr == 0: - print("Lower Right = On") - else: - print("Lower Right = Off") - clear() - stop() - lr_old = lr diff --git a/src/kits/holiday-hats/fourth-of-july.py b/src/kits/holiday-hats/fourth-of-july.py deleted file mode 100644 index 1f887e437..000000000 --- a/src/kits/holiday-hats/fourth-of-july.py +++ /dev/null @@ -1,331 +0,0 @@ -# St. Patrick's Day Hat -# 36 pixels in a circule in a hat -# The pattern are green, orange and white colors -# The pattern changes every five seconds -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -# This is the best number of pixels for most hats -# if you use 160 pixels/meter strips -NUMBER_PIXELS = 36 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -builtin_led = machine.Pin(25, Pin.OUT) - -red = (255,0,0) -green = (0, 255, 0) -green_med = (0,32, 0) -green_light = (0, 8, 0) -blue = (0,0,255) -off = (0, 0, 0) -orange = (140, 60, 0) -white = (255, 255, 255) -colors = (red, white, blue) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', - 'solid red', 'solid white', 'solid blue', - 'red commet', 'white commet', 'blue commet' - 'running lights red', 'running lights red', 'running lights blue', - '3-bands 3', '3-bands 4', '3-bands 5', - 'move dot red', 'move dot green', 'move dot blue', - 'rainbow cycle'] - -mode_count = len(mode_list) -print('mode_count:', mode_count) - - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def move_dot_rev(counter, color, delay): - strip[NUMBER_PIXELS - counter - 1] = color - strip.write() - sleep(delay) - strip[NUMBER_PIXELS - counter - 1] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def comet_tail_rev(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = NUMBER_PIXELS - (((level_count - i - 1) + counter) % NUMBER_PIXELS) - 1 - # number to scale by - scale = (levels[i] / 255) - # write up to the color_count - if target > color_count: - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - if counter < NUMBER_PIXELS-1: - strip[NUMBER_PIXELS - counter - 1] = (0,0,0) - strip.write() - sleep(delay) - - -def solid_color(color, delay): - for i in range(0, NUMBER_PIXELS-1): - strip[i] = color; - strip.write() - sleep(delay) - - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle_rnd(): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - -def candle(delay): - for i in range(0, 5): - candle_rnd() - sleep(delay) - -def random_color_pixel(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_green_brightness = randint(0, 255) - strip[random_offset] = (0, random_green_brightness, 0) - strip.write() - - -def random_color(delay): - for i in range(0, 5): - random_color_pixel() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def running_lights_rev(counter, color, spacing, delay): - for i in range(NUMBER_PIXELS-1, 0, -1): - if (counter-i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -# Three bands of color rotating down the strip -# This has some bugs but they are not too visible -def three_bands(c, spacing, c1, c2, c3, delay): - band_length = spacing * 3 - bands = int((NUMBER_PIXELS/ (spacing*3))) - # print('bands=', bands) - for i in range(bands): - for j in range(spacing): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('red', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c1 - for j in range(spacing, spacing*2): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('green', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c2 - for j in range(spacing*2, spacing*3): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('blue', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c3 - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = green_light - strip[counter+1] = green_med - strip[counter+2] = green - strip[counter+3] = green_med - strip[counter+4] = green_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = green_light - strip[i+1] = green_med - strip[i+2] = green - strip[i+3] = green_med - strip[i+4] = green_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) - -# Global variables -# where in the mode loop we get started -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - # 'green fade-in-and-out', 'moving green dot', 'green theater chase', 'green theater chase backwards', - # 'green commet', 'random green and orange', 'random greens', 'green bounce', - # 'rainbow cycle', 'green cylon scanner' - if mode == 0: - moving_rainbow(counter, .04) - elif mode == 1: - solid_color(red, .05) - elif mode == 2: - solid_color(white, .05) - elif mode == 2: - solid_color(blue, .05) - - elif mode == 3: - comet_tail(counter, red, .05) - elif mode == 4: - comet_tail(counter, white, .05) - elif mode == 5: - comet_tail(counter, blue, .05) - - elif mode == 6: - running_lights(counter, red, 4, .1) - elif mode == 7: - running_lights(counter, white, 4, .1) - elif mode == 8: - running_lights_rev(counter, blue, 4, .1) - - elif mode == 9: - three_bands(counter, 3, red, white, blue, 0.04) - elif mode == 10: - three_bands(counter, 4, red, white, blue, 0.04) - elif mode == 11: - three_bands(counter, 5, red, white, blue, 0.04) - - elif mode == 12: - move_dot(counter, red, 0.03) - elif mode == 13: - move_dot(counter, white, 0.03) - elif mode == 14: - move_dot(counter, blue, 0.03) - - elif mode == 15: - rainbow_cycle(counter, .03) - - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter > NUMBER_PIXELS -1 : - counter = 0 - mode += 1 - if mode > mode_count - 1: - mode = 0 diff --git a/src/kits/holiday-hats/st-patricks-day-hat.py b/src/kits/holiday-hats/st-patricks-day-hat.py deleted file mode 100644 index 827bfb20d..000000000 --- a/src/kits/holiday-hats/st-patricks-day-hat.py +++ /dev/null @@ -1,279 +0,0 @@ -# St. Patrick's Day Hat -# 36 pixels in a circule in a hat -# The pattern are green, orange and white colors -# The pattern changes every five seconds -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -# This is the best number of pixels for most hats -# if you use 160 pixels/meter strips -NUMBER_PIXELS = 36 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -builtin_led = machine.Pin(25, Pin.OUT) - - -green = (0, 255, 0) -green_med = (0,32, 0) -green_light = (0, 8, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -white = (128, 128, 128) -colors = (green, orange, white, green_med, green_light) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving green dot fwd', 'moving green dot rev', 'green commet fwd', 'green commet rev', - 'random green brightness', 'green bounce', - 'green theater chase', 'green theater chase backwards', - 'green cylon scanner', 'rainbow cycle'] - -mode_count = len(mode_list) -print('mode_count:', mode_count) - - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def move_dot_rev(counter, color, delay): - strip[NUMBER_PIXELS - counter - 1] = color - strip.write() - sleep(delay) - strip[NUMBER_PIXELS - counter - 1] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def comet_tail_rev(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = NUMBER_PIXELS - (((level_count - i - 1) + counter) % NUMBER_PIXELS) - 1 - # number to scale by - scale = (levels[i] / 255) - # write up to the color_count - if target > color_count: - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - if counter < NUMBER_PIXELS-1: - strip[NUMBER_PIXELS - counter - 1] = (0,0,0) - strip.write() - sleep(delay) - - - - - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle_rnd(): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - -def candle(delay): - for i in range(0, 5): - candle_rnd() - sleep(delay) - -def random_color_pixel(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_green_brightness = randint(0, 255) - strip[random_offset] = (0, random_green_brightness, 0) - strip.write() - - -def random_color(delay): - for i in range(0, 5): - random_color_pixel() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def running_lights_rev(counter, color, spacing, delay): - for i in range(NUMBER_PIXELS-1, 0, -1): - if (counter-i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = green_light - strip[counter+1] = green_med - strip[counter+2] = green - strip[counter+3] = green_med - strip[counter+4] = green_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = green_light - strip[i+1] = green_med - strip[i+2] = green - strip[i+3] = green_med - strip[i+4] = green_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) - -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - # 'green fade-in-and-out', 'moving green dot', 'green theater chase', 'green theater chase backwards', - # 'green commet', 'random green and orange', 'random greens', 'green bounce', - # 'rainbow cycle', 'green cylon scanner' - if mode == 0: - moving_rainbow(counter, .04) - elif mode == 1: - move_dot(counter, green, .04) - elif mode == 2: - move_dot_rev(counter, green, .04) - elif mode == 3: - comet_tail(counter, green, .1) - elif mode == 4: - comet_tail_rev(counter, green, .1) - elif mode == 5: - random_color(.01) - elif mode == 6: - bounce(counter, green, .1) - elif mode == 7: - running_lights(counter, green, 4, .2) - elif mode == 8: - running_lights_rev(counter, green, 4, .2) - elif mode == 9: - rainbow_cycle(counter, .03) - elif mode == 10: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter > NUMBER_PIXELS -1 : - counter = 0 - mode += 1 - if mode > mode_count - 2: - mode = 0 diff --git a/src/kits/holiday-hats/test-bands.py b/src/kits/holiday-hats/test-bands.py deleted file mode 100644 index 5f69d8f5a..000000000 --- a/src/kits/holiday-hats/test-bands.py +++ /dev/null @@ -1,55 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -# This is the best number of pixels for most hats -# if you use 160 pixels/meter strips -NUMBER_PIXELS = 36 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255,0,0) -orange = (255,70,0) -yellow = (255,255,0) -green = (0, 255, 0) -green_med = (0,32, 0) -green_light = (0, 8, 0) -blue = (0,0,255) -off = (0, 0, 0) -orange = (140, 60, 0) -white = (255, 255, 255) -colors = (red, orange, yellow, green, blue) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -def three_bands(c, spacing, c1, c2, c3, delay): - band_length = spacing * 3 - bands = int((NUMBER_PIXELS/ (spacing*3))) - # print('bands=', bands) - for i in range(bands): - for j in range(spacing): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('red', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c1 - for j in range(spacing, spacing*2): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('green', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c2 - for j in range(spacing*2, spacing*3): - index = (i*band_length + j + c) % NUMBER_PIXELS - #print('blue', i,j,c, index) - if (index) < NUMBER_PIXELS: - strip[index] = c3 - strip.write() - sleep(delay) - -counter = 0 -while True: - three_bands(counter, 3, red, white, blue, 0.04) - counter += 1 - if counter > NUMBER_PIXELS: - counter = 0 - diff --git a/src/kits/holiday-hats/two-button-demo.py b/src/kits/holiday-hats/two-button-demo.py deleted file mode 100644 index dd325ba6c..000000000 --- a/src/kits/holiday-hats/two-button-demo.py +++ /dev/null @@ -1,276 +0,0 @@ -# moving rainbow main -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle_rnd(): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - -def candle(delay): - for i in range(0, 5): - candle_rnd() - sleep(delay) - -def random_color_pixel(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - - -def random_color(delay): - for i in range(0, 5): - random_color_pixel() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) - -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .03) - elif mode == 2: - move_dot(counter, green, .03) - elif mode == 3: - move_dot(counter, blue, .03) - elif mode == 4: - comet_tail(counter, red, .003) - elif mode == 5: - comet_tail(counter, green, .003) - elif mode == 6: - comet_tail(counter, blue, .003) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .1) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .03) - elif mode == 12: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter > NUMBER_PIXELS -1 : - counter = 0 - mode += 1 - if mode > mode_count - 2: - mode = 0 diff --git a/src/kits/infrared-dist-sensor/01-read-pin-0.py b/src/kits/infrared-dist-sensor/01-read-pin-0.py deleted file mode 100644 index 0c0f3b6fd..000000000 --- a/src/kits/infrared-dist-sensor/01-read-pin-0.py +++ /dev/null @@ -1,12 +0,0 @@ -from machine import Pin -from utime import sleep - -SENSOR_PIN = 0 -sensor = machine.Pin(SENSOR_PIN, Pin.IN, Pin.PULL_DOWN) - -led = Pin(25, Pin.OUT) - -while True: - led.toggle() - print(sensor.value()) - sleep(.1) \ No newline at end of file diff --git a/src/kits/infrared-dist-sensor/main.py b/src/kits/infrared-dist-sensor/main.py deleted file mode 100644 index f4c2bad96..000000000 --- a/src/kits/infrared-dist-sensor/main.py +++ /dev/null @@ -1,70 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -SENSOR_PIN = 0 -sensor = machine.Pin(SENSOR_PIN, Pin.IN, Pin.PULL_DOWN) - -led = Pin(25, Pin.OUT) -external_led = Pin(15, Pin.OUT) - -# corner of the lower right -SPEAKER_PIN = 16 -speaker = PWM(Pin(SPEAKER_PIN)) - -counter = 0 - -def play_sound1(): - # create a Pulse Width Modulation Object on this pin - speaker.duty_u16(1000) - speaker.freq(300) # 1 Kilohertz - sleep(.1) # wait a 1/4 second - speaker.duty_u16(0) - - -def play_sound2(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.1) - speaker.duty_u16(0) - -external_led_state = 0 -def toggle_light(): - global external_led_state - external_led.toggle() - if external_led_state == 0: - external_led_state = 1 - external_led.on() - else: - external_led_state = 0 - external_led.off() - -# turn off the PWM -speaker.duty_u16(0) - -counter = 0 - -prior_value = 0 -def main(): - global counter, prior_value - while True: - # toggle the on-board LED every 20th time - if not counter % 10: - led.toggle() - myVal = sensor.value() - print(myVal) - if myVal != prior_value: - if myVal == 1: - play_sound1() - toggle_light() - else: - play_sound2() - prior_value = myVal - sleep(.05) - # increment counter - counter += 1 - -try: - main() -except KeyboardInterrupt: - speaker.duty_u16(0) - print("Sound terminated") \ No newline at end of file diff --git a/src/kits/infrared-dist-sensor/monitor-pin-0.py b/src/kits/infrared-dist-sensor/monitor-pin-0.py deleted file mode 100644 index 72c0effd3..000000000 --- a/src/kits/infrared-dist-sensor/monitor-pin-0.py +++ /dev/null @@ -1,55 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -SENSOR_PIN = 0 -sensor = machine.Pin(SENSOR_PIN, Pin.IN, Pin.PULL_DOWN) - -led = Pin(25, Pin.OUT) - -# corner of the lower right -SPEAKER_PIN = 16 -speaker = PWM(Pin(SPEAKER_PIN)) - -counter = 0 - -def play_sound1(): - # create a Pulse Width Modulation Object on this pin - speaker.duty_u16(1000) - speaker.freq(300) # 1 Kilohertz - sleep(.1) # wait a 1/4 second - speaker.duty_u16(0) - - -def play_sound2(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.1) - speaker.duty_u16(0) - - -# turn off the PWM -speaker.duty_u16(0) - -counter = 0 -def main(): - global counter - while True: - # toggle the on-board LED every 20th time - if not counter % 10: - led.toggle() - myVal = sensor.value() - print(myVal) - if myVal: - play_sound1() - else: - # play_sound2() - sleep(0) - sleep(.05) - # increment counter - counter += 1 - -try: - main() -except KeyboardInterrupt: - speaker.duty_u16(0) - print("Sound terminated") \ No newline at end of file diff --git a/src/kits/infrared-dist-sensor/stop-pwm.py b/src/kits/infrared-dist-sensor/stop-pwm.py deleted file mode 100644 index 38a8c2917..000000000 --- a/src/kits/infrared-dist-sensor/stop-pwm.py +++ /dev/null @@ -1,12 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -SENSOR_PIN = 0 -sensor = machine.Pin(SENSOR_PIN, Pin.IN, Pin.PULL_DOWN) - -led = Pin(25, Pin.OUT) - -# corner of the lower right -SPEAKER_PIN = 16 -speaker = PWM(Pin(SPEAKER_PIN)) -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/kits/luminary/01-blink.py b/src/kits/luminary/01-blink.py deleted file mode 100644 index 06593167a..000000000 --- a/src/kits/luminary/01-blink.py +++ /dev/null @@ -1,18 +0,0 @@ -# Setup - run once -from machine import Pin # Get the Pin function from the machine module. -from time import sleep # Get the sleep library from the time module. - -# This is the built-in green LED on the Pico. -BUILT_IN_LED_PIN = 25 -# change this to the following named pin on the "W" -# BUILT_IN_LED_PIN = Pin("LED", Pin.OUT) - -# The line below indicates we are configuring this as an output (not input) -led = machine.Pin(BUILT_IN_LED_PIN, machine.Pin.OUT) - -# Main loop: Repeat the forever... -while True: - led.high() # turn on the LED - sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second diff --git a/src/kits/luminary/02-blink-neopixel.py b/src/kits/luminary/02-blink-neopixel.py deleted file mode 100644 index de16c2ba5..000000000 --- a/src/kits/luminary/02-blink-neopixel.py +++ /dev/null @@ -1,16 +0,0 @@ -from machine import Pin -from time import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -while True: - strip[0] = (255,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(.5) # keep on 1/10 of a second - strip[0] = (0,0,0) # change the RAM back but don't resend the data - strip.write() - sleep(.5) diff --git a/src/kits/luminary/03-move.py b/src/kits/luminary/03-move.py deleted file mode 100644 index a31e3ec8b..000000000 --- a/src/kits/luminary/03-move.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin -from time import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - strip[i] = (255,0,0) # red=255, green and blue are 0 - strip.write() # send the data from RAM down the wire - sleep(.1) # keep on 1/10 of a second - strip[i] = (0,0,0) # change the RAM back but don't resend the data diff --git a/src/kits/luminary/04-pot-test.py b/src/kits/luminary/04-pot-test.py deleted file mode 100644 index c7a9eb588..000000000 --- a/src/kits/luminary/04-pot-test.py +++ /dev/null @@ -1,21 +0,0 @@ -# use the pot to change the brightness of the built-in LED -from machine import ADC, Pin, PWM -from utime import sleep - -# Pins Used -BUILT_IN_LED_PIN = 25 -POT_PIN = 26 - -pot = ADC(POT_PIN) - -builtin_pwm = PWM(Pin(BUILT_IN_LED_PIN)) -builtin_pwm.freq(1000) # 1K Hz - -POLL_DELAY = .1 # poll the pot after this delay in seconds - -# repeat forever -while True: - pot_value = pot.read_u16() # read the value from the pot - print("pot value:", pot_value) - builtin_pwm.duty_u16(pot_value) - sleep(POLL_DELAY) diff --git a/src/kits/luminary/06-pot-neopixel-brightness-v2.py b/src/kits/luminary/06-pot-neopixel-brightness-v2.py deleted file mode 100644 index 97b06d853..000000000 --- a/src/kits/luminary/06-pot-neopixel-brightness-v2.py +++ /dev/null @@ -1,26 +0,0 @@ -from machine import ADC, Pin, PWM -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# Pins Used -BUILT_IN_LED_PIN = 25 -POT_PIN = 26 - -pot = ADC(POT_PIN) - -POLL_DELAY = .01 # poll the pot after this delay in seconds - -# repeat forever -while True: - pot_value = (pot.read_u16() >> 8) - 6 # read 9 msb and subtract 6 - if pot_value < 0: - pot_value = 0 - print("pot value:", pot_value) - strip[0] = (pot_value,0,0) - strip.write() - sleep(POLL_DELAY) diff --git a/src/kits/luminary/06-pot-neopixel-brightness.py b/src/kits/luminary/06-pot-neopixel-brightness.py deleted file mode 100644 index b889d45d2..000000000 --- a/src/kits/luminary/06-pot-neopixel-brightness.py +++ /dev/null @@ -1,24 +0,0 @@ -from machine import ADC, Pin, PWM -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# Pins Used -BUILT_IN_LED_PIN = 25 -POT_PIN = 26 - -pot = ADC(POT_PIN) - -POLL_DELAY = .01 # poll the pot after this delay in seconds - -# repeat forever -while True: - pot_value = pot.read_u16() >> 8 # read the value from the pot - print("pot value:", pot_value) - strip[0] = (pot_value,0,0) - strip.write() - sleep(POLL_DELAY) diff --git a/src/kits/luminary/06-yellow-dimmer.py b/src/kits/luminary/06-yellow-dimmer.py deleted file mode 100644 index 75fd94dd8..000000000 --- a/src/kits/luminary/06-yellow-dimmer.py +++ /dev/null @@ -1,27 +0,0 @@ -from machine import ADC, Pin, PWM -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# Pins Used -BUILT_IN_LED_PIN = 25 -POT_PIN = 26 - -pot = ADC(POT_PIN) - -POLL_DELAY = .01 # poll the pot after this delay in seconds - -# repeat forever -while True: - pot_value = (pot.read_u16() >> 8) - 6 # read 9 msb and subtract 6 - if pot_value < 0: - pot_value = 0 - print("pot value:", pot_value) - for i in range(0, NUMBER_PIXELS): - strip[i] = (pot_value, pot_value, 0) - strip.write() - sleep(POLL_DELAY) diff --git a/src/kits/luminary/10-button-press.py b/src/kits/luminary/10-button-press.py deleted file mode 100644 index a34e3547e..000000000 --- a/src/kits/luminary/10-button-press.py +++ /dev/null @@ -1,33 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper -# left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 300: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses diff --git a/src/kits/luminary/11-button-color-mode.py b/src/kits/luminary/11-button-color-mode.py deleted file mode 100644 index a057ec2b2..000000000 --- a/src/kits/luminary/11-button-color-mode.py +++ /dev/null @@ -1,61 +0,0 @@ -from machine import ADC, Pin -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -mode = 0 # the count of times the button has been pressed -colors = 15 # the number of colors we will show -color_step = 255 // colors # step around the color wheel -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper -# left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 300: - mode +=1 - last_time = new_time - if mode >= colors: - mode = 0 - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) -# This is for only printing when a new button press count value happens - -old_mode = 0 -while True: - # only print on change in the button_presses value - current_color = wheel(int(mode * color_step)) - if mode != old_mode: - print(mode, current_color) - builtin_led.toggle() - old_mode = mode - for i in range(0, NUMBER_PIXELS): - strip[i] = (current_color[0], current_color[1], current_color[2]) - strip.write() - sleep(.05) - diff --git a/src/kits/luminary/12-color-mode-brightness.py b/src/kits/luminary/12-color-mode-brightness.py deleted file mode 100644 index 142a35f51..000000000 --- a/src/kits/luminary/12-color-mode-brightness.py +++ /dev/null @@ -1,66 +0,0 @@ -from machine import ADC, Pin -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NUMBER_PIXELS = 60 -LED_PIN = 0 -POT_PIN = 26 -pot = ADC(POT_PIN) - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -mode = 0 # the count of times the button has been pressed -colors = 15 # the number of colors we will show -color_step = 255 // colors # step around the color wheel -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper -# left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 300: - mode +=1 - last_time = new_time - if mode >= colors: - mode = 0 - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) -# This is for only printing when a new button press count value happens - -old_mode = 0 -while True: - # only print on change in the button_presses value - current_color = wheel(int(mode * color_step)) - if mode != old_mode: - print(mode, current_color) - builtin_led.toggle() - old_mode = mode - pot_value = pot.read_u16() >> 10 # 0 to 64 - percent = pot_value / 64 - # print(pot_value, percent) - for i in range(0, NUMBER_PIXELS): - strip[i] = (int(current_color[0]*percent), int(current_color[1]*percent), int(current_color[2]*percent)) - strip.write() - sleep(.05) - diff --git a/src/kits/maker-nano-rp2040/01-blink.py b/src/kits/maker-nano-rp2040/01-blink.py deleted file mode 100644 index 470116929..000000000 --- a/src/kits/maker-nano-rp2040/01-blink.py +++ /dev/null @@ -1,11 +0,0 @@ -from machine import Pin # get the Pin function from the machine module -from time import sleep # get the sleep library from the time module -# this is the built-in green LED on the Pico -led = machine.Pin(0, machine.Pin.OUT) - -# repeat forever -while True: - led.high() # turn on the LED - sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second \ No newline at end of file diff --git a/src/kits/maker-nano-rp2040/02-blue-led-up-down.py b/src/kits/maker-nano-rp2040/02-blue-led-up-down.py deleted file mode 100644 index df7764bd4..000000000 --- a/src/kits/maker-nano-rp2040/02-blue-led-up-down.py +++ /dev/null @@ -1,21 +0,0 @@ -from machine import Pin # get the Pin function from the machine module -from time import sleep # get the sleep library from the time module - -leds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 19, 16] -pins = [] -delay = .05 - -for i in range(0, len(leds)): - print(i, leds[i]) - pins.append(machine.Pin(leds[i], machine.Pin.OUT)) - -while True: - for i in range(0, len(leds)): - pins[i].high() - sleep(delay) - pins[i].low() - - for i in range(len(leds)-1, 0, -1): - pins[i].high() - sleep(delay) - pins[i].low() \ No newline at end of file diff --git a/src/kits/maker-nano-rp2040/03-neopixel-rgb-blink.py b/src/kits/maker-nano-rp2040/03-neopixel-rgb-blink.py deleted file mode 100644 index 4db41dfdf..000000000 --- a/src/kits/maker-nano-rp2040/03-neopixel-rgb-blink.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from time import sleep - -NUMBER_PIXELS = 2 -NEOPIXEL_PIN = 18 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - - -while True: - - # blink red - for i in range(0, NUMBER_PIXELS): - strip[i] = (255,0,0) - strip.write() - sleep(.5) - - # blink green - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,255,0) - strip.write() - sleep(.5) - - # blink blue - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,255) - strip.write() - sleep(.5) - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - sleep(.5) \ No newline at end of file diff --git a/src/kits/maker-nano-rp2040/30-pixel-strip-2-buttons.py b/src/kits/maker-nano-rp2040/30-pixel-strip-2-buttons.py deleted file mode 100644 index 291aacbae..000000000 --- a/src/kits/maker-nano-rp2040/30-pixel-strip-2-buttons.py +++ /dev/null @@ -1,262 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 20 -BUTTON_PIN_2 = 21 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle(delay): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -def random_color(delay): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .05) - elif mode == 2: - move_dot(counter, green, .05) - elif mode == 3: - move_dot(counter, blue, .05) - elif mode == 4: - comet_tail(counter, red, .01) - elif mode == 5: - comet_tail(counter, green, .01) - elif mode == 6: - comet_tail(counter, blue, .01) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .15) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .05) - elif mode == 12: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS diff --git a/src/kits/maker-nano-rp2040/test-blue-leds.py b/src/kits/maker-nano-rp2040/test-blue-leds.py deleted file mode 100644 index d6f44306d..000000000 --- a/src/kits/maker-nano-rp2040/test-blue-leds.py +++ /dev/null @@ -1,13 +0,0 @@ -from machine import Pin # get the Pin function from the machine module -from time import sleep # get the sleep library from the time module -# this is the built-in green LED on the Pico -led = machine.Pin(0, machine.Pin.OUT) - -leds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 19, 16] - -# repeat forever -while True: - led.high() # turn on the LED - sleep(0.5) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(0.5) # leave it off for 1/2 second \ No newline at end of file diff --git a/src/kits/maker-pi-pico/01-intro.md b/src/kits/maker-pi-pico/01-intro.md deleted file mode 100644 index 99d55be20..000000000 --- a/src/kits/maker-pi-pico/01-intro.md +++ /dev/null @@ -1,8 +0,0 @@ -# Cytron Maker Pi RP2040 Kits - -There are to types of kits that we provide to your coding clubs. The base kits have just the main Cytron Maker Pi PR2040 board and some sensors. These base kits are ideal for clubs that don't allow students to solder in their buildings. Other kits include the SmartCar Robot chassis, motors and a battery pack for building a collision avoidance robot. These kits require some light soldering: two wires for each motor and two wires for the power switch. - -Because of the way we deliver these kit, our Maker Pi RP2040 materials are divided into two sections: - -1. Section 1 (this part) assumes you just have the main Cytron Maker Pi RP2040 board and a Micro USB cable. This section includes labs on using the LEDs, NeoPixels, buttons and sound. -2. [Section 2](../MAKER-PI-RP2040-robot/02-assembly) assumes you also have the SmartCar Chassis and a distance sensor. This section includes labs on using motors, servos and using a distance sensor to create a collision avoidance robot. There are also advanced labs that integrate a OLED display to allow you to change the parameters of the robot using the buttons. \ No newline at end of file diff --git a/src/kits/maker-pi-pico/bounce-ball-test.py b/src/kits/maker-pi-pico/bounce-ball-test.py deleted file mode 100644 index 111478dea..000000000 --- a/src/kits/maker-pi-pico/bounce-ball-test.py +++ /dev/null @@ -1,16 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) - -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.fill(0) -oled.rect(0, 0, width-1, height-1,1) -oled.show() \ No newline at end of file diff --git a/src/kits/maker-pi-pico/button-press-test.py b/src/kits/maker-pi-pico/button-press-test.py deleted file mode 100644 index 9e6dbcacb..000000000 --- a/src/kits/maker-pi-pico/button-press-test.py +++ /dev/null @@ -1,62 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -prog_mode = 0 -mode_value = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led_1 = machine.Pin(16, Pin.OUT) -builtin_led_2 = machine.Pin(17, Pin.OUT) - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -up_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) -down_pin = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode_value, prog_mode, last_time - new_time = utime.ticks_ms() - pin_string = str(pin) - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in pin_string: - prog_mode += 1 - if prog_mode > 5: - prog_mode = 0 - elif '22' in pin_string: - mode_value +=1 - if mode_value > 5: - mode_value = 5 - elif '21' in pin_string: - mode_value -= 1 - if mode_value < 0: - mode_value = 0 - else: - print('ERROR: unknown pin') - last_time = new_time - - -# now we register the handler function when the button is pressed -mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -up_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -down_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_mode = 0 -old_presses = 0 - -print('Progam Mode:', prog_mode, 'Value:', mode_value) -while True: - # only print on change in the mode_value value - if mode_value != old_presses: - print('val:', mode_value) - builtin_led_1.toggle() - old_presses = mode_value - if prog_mode != old_mode: - print('prog mode:', prog_mode) - builtin_led_2.toggle() - old_mode = prog_mode \ No newline at end of file diff --git a/src/kits/maker-pi-pico/draw-yellow-blue-borders.py b/src/kits/maker-pi-pico/draw-yellow-blue-borders.py deleted file mode 100644 index 93b859859..000000000 --- a/src/kits/maker-pi-pico/draw-yellow-blue-borders.py +++ /dev/null @@ -1,19 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) - -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.fill(0) -# draw yellow border in top 17 lines -oled.rect(0, 0, width-1, 16, 1) -# draw blue border from 18 to 64 -oled.rect(0, 17, width-1, height-17, 1) -oled.show() \ No newline at end of file diff --git a/src/kits/maker-pi-pico/draw-yellow-blue-menus.py b/src/kits/maker-pi-pico/draw-yellow-blue-menus.py deleted file mode 100644 index bbadecdd3..000000000 --- a/src/kits/maker-pi-pico/draw-yellow-blue-menus.py +++ /dev/null @@ -1,90 +0,0 @@ -import machine -from machine import Pin -from utime import sleep, ticks_ms -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) - -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -prog_mode = 0 -mode_value = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led_1 = machine.Pin(16, Pin.OUT) -builtin_led_2 = machine.Pin(17, Pin.OUT) - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -mode_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -up_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) -down_pin = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode_value, prog_mode, last_time - new_time = ticks_ms() - pin_string = str(pin) - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in pin_string: - prog_mode += 1 - if prog_mode > 4: - prog_mode = 0 - elif '22' in pin_string: - mode_value +=1 - if mode_value > 5: - mode_value = 5 - elif '21' in pin_string: - mode_value -= 1 - if mode_value < 0: - mode_value = 0 - else: - print('ERROR: unknown pin') - last_time = new_time - - -# now we register the handler function when the button is pressed -mode_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -up_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -down_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_mode = 0 -old_presses = 0 - -def update_display(): - oled.fill(0) - # draw yellow border in top 17 lines - oled.rect(0, 0, width-1, 16, 1) - # draw blue border from 18 to 64 - oled.rect(0, 17, width-1, height-17, 1) - draw_mode() - oled.show() - -def draw_mode(): - global prog_mode - bar_width = int(width/5) - start = prog_mode * bar_width - oled.fill_rect(start, 1, bar_width, 16, 1) - oled.text(str(prog_mode), start, 1, 0) - oled.text('Value', 1, 18, 1) - oled.text(str(mode_value), 1, 30, 1) - -print('Progam Mode:', prog_mode, 'Value:', mode_value) -while True: - # only print on change in the mode_value value - if mode_value != old_presses: - print('val:', mode_value) - builtin_led_1.toggle() - old_presses = mode_value - if prog_mode != old_mode: - print('prog mode:', prog_mode) - builtin_led_2.toggle() - old_mode = prog_mode - update_display() diff --git a/src/kits/maker-pi-pico/oled-scanner-test.py b/src/kits/maker-pi-pico/oled-scanner-test.py deleted file mode 100644 index 1fab82345..000000000 --- a/src/kits/maker-pi-pico/oled-scanner-test.py +++ /dev/null @@ -1,16 +0,0 @@ -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -devices = i2c.scan() -print("Device found at decimal", devices) - -first_device = devices[0] -if first_device == 60: - print("TEST PASS") -else: - print("No OLED device found at decimal 60. Check connections.") - print("TEST FAIL") diff --git a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/display-pots-and-tof-test.py b/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/display-pots-and-tof-test.py deleted file mode 100644 index 936e693e1..000000000 --- a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/display-pots-and-tof-test.py +++ /dev/null @@ -1,43 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C -import VL53L0X - -POT_PIN_1 = 26 -POT_PIN_2 = 27 -POT_PIN_3 = 28 - -adc_1 = machine.ADC(POT_PIN_1) -adc_2 = machine.ADC(POT_PIN_2) -adc_3 = machine.ADC(POT_PIN_3) - -I2C0_SDA_PIN = 0 -I2C0_SCL_PIN = 1 -I2C1_SDA_PIN = 2 -I2C1_SCL_PIN = 3 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN)) -i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000) - -oled = SSD1306_I2C(128, 64, i2c0) -tof = VL53L0X.VL53L0X(i2c1) -tof.start() - -def read_pot(adc): - return int(adc.read_u16()) >> 8 - -oled_blue_area = 16 -col_2_start = 90 -while True: - oled.fill(0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("Frwd Power:", 0, oled_blue_area) - oled.text(str(read_pot(adc_1)), col_2_start, oled_blue_area) - oled.text("Turn Dist:", 0, oled_blue_area + 12) - oled.text(str(read_pot(adc_2)), col_2_start, oled_blue_area + 12) - oled.text("Turn Time:", 0, oled_blue_area + 24) - oled.text(str(read_pot(adc_3)), col_2_start, oled_blue_area + 24) - oled.text("Dist:", 0, oled_blue_area + 36) - oled.text(str(tof.read()), col_2_start, oled_blue_area + 36) - oled.show() - sleep(.1) - diff --git a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/motor-connection-test.py b/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/motor-connection-test.py deleted file mode 100644 index 5d74f38d1..000000000 --- a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/motor-connection-test.py +++ /dev/null @@ -1,52 +0,0 @@ -# Motor connection test. Use CONTROL-C to shutdown all motors. -from machine import Pin, PWM -import time - -POWER_LEVEL = 30000 # MAX is 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -# turn off all motor PWMs -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/oled-i2c-test.py b/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/oled-i2c-test.py deleted file mode 100644 index 9edd78191..000000000 --- a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/oled-i2c-test.py +++ /dev/null @@ -1,11 +0,0 @@ -import machine -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -print('Done') \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/time-of-flight-test.py b/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/time-of-flight-test.py deleted file mode 100644 index 1ab3d706e..000000000 --- a/src/kits/maker-pi-rp2040-robots/adjusta-bot-pots/time-of-flight-test.py +++ /dev/null @@ -1,19 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(2) # lower right pin -scl=machine.Pin(3) # one up from lower right pin -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -while True: - tof.start() - tof.read() - print(tof.read()) - tof.stop() - time.sleep(0.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/display-all-inputs.py b/src/kits/maker-pi-rp2040-robots/display-all-inputs.py deleted file mode 100644 index 936e693e1..000000000 --- a/src/kits/maker-pi-rp2040-robots/display-all-inputs.py +++ /dev/null @@ -1,43 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C -import VL53L0X - -POT_PIN_1 = 26 -POT_PIN_2 = 27 -POT_PIN_3 = 28 - -adc_1 = machine.ADC(POT_PIN_1) -adc_2 = machine.ADC(POT_PIN_2) -adc_3 = machine.ADC(POT_PIN_3) - -I2C0_SDA_PIN = 0 -I2C0_SCL_PIN = 1 -I2C1_SDA_PIN = 2 -I2C1_SCL_PIN = 3 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN)) -i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000) - -oled = SSD1306_I2C(128, 64, i2c0) -tof = VL53L0X.VL53L0X(i2c1) -tof.start() - -def read_pot(adc): - return int(adc.read_u16()) >> 8 - -oled_blue_area = 16 -col_2_start = 90 -while True: - oled.fill(0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("Frwd Power:", 0, oled_blue_area) - oled.text(str(read_pot(adc_1)), col_2_start, oled_blue_area) - oled.text("Turn Dist:", 0, oled_blue_area + 12) - oled.text(str(read_pot(adc_2)), col_2_start, oled_blue_area + 12) - oled.text("Turn Time:", 0, oled_blue_area + 24) - oled.text(str(read_pot(adc_3)), col_2_start, oled_blue_area + 24) - oled.text("Dist:", 0, oled_blue_area + 36) - oled.text(str(tof.read()), col_2_start, oled_blue_area + 36) - oled.show() - sleep(.1) - diff --git a/src/kits/maker-pi-rp2040-robots/display-three-pots-on-oled.py b/src/kits/maker-pi-rp2040-robots/display-three-pots-on-oled.py deleted file mode 100644 index b9ff0a892..000000000 --- a/src/kits/maker-pi-rp2040-robots/display-three-pots-on-oled.py +++ /dev/null @@ -1,32 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C - -POT_PIN_1 = 26 -POT_PIN_2 = 27 -POT_PIN_3 = 28 - -adc_1 = machine.ADC(POT_PIN_1) -adc_2 = machine.ADC(POT_PIN_2) -adc_3 = machine.ADC(POT_PIN_3) - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) - -def read_pot(adc): - return int(adc.read_u16()) >> 8 - -while True: - oled.fill(0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("P1:", 0, 20) - oled.text(str(read_pot(adc_1)), 40, 20) - oled.text("P2:", 0, 35) - oled.text(str(read_pot(adc_2)), 40, 35) - oled.text("P3:", 0, 50) - oled.text(str(read_pot(adc_3)), 40, 50) - oled.show() - sleep(.1) - diff --git a/src/kits/maker-pi-rp2040-robots/i2c-scanner.py b/src/kits/maker-pi-rp2040-robots/i2c-scanner.py deleted file mode 100644 index 4f188ca0a..000000000 --- a/src/kits/maker-pi-rp2040-robots/i2c-scanner.py +++ /dev/null @@ -1,34 +0,0 @@ -import machine - -I2C0_SDA_PIN = 0 -I2C0_SCL_PIN = 1 -I2C1_SDA_PIN = 2 -I2C1_SCL_PIN = 3 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000) -i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000) - -print('Scanning I2C bus 0.') -devices = i2c0.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found on bus 0.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) - -print('Scanning I2C bus 1.') -devices = i2c1.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found on bus 1.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/drive-test.py b/src/kits/maker-pi-rp2040-robots/line-follower/drive-test.py deleted file mode 100644 index 93f20def9..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/drive-test.py +++ /dev/null @@ -1,55 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN =10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -MAX_POWER_LEVEL = 65025 -QUARTER_POWER = 65025 >> 2 -SLOW_DRIVE_POWER = 26000 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(SLOW_DRIVE_POWER) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/follow-line.py b/src/kits/maker-pi-rp2040-robots/line-follower/follow-line.py deleted file mode 100644 index c5fa8ae20..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/follow-line.py +++ /dev/null @@ -1,81 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# sensor setup -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN =10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -MAX_POWER_LEVEL = 65025 -QUARTER_POWER = 65025 >> 2 -SLOW_DRIVE_POWER = 26000 -BOOST_LEVEL = 5000 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(SLOW_DRIVE_POWER) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def forward(): - right_forward.duty_u16(SLOW_DRIVE_POWER) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER) - left_reverse.duty_u16(0) - -def right(): - right_forward.duty_u16(SLOW_DRIVE_POWER) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER+BOOST_LEVEL) - left_reverse.duty_u16(0) - -def left(): - right_forward.duty_u16(SLOW_DRIVE_POWER+BOOST_LEVEL) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER) - left_reverse.duty_u16(0) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - r = right_sensor.value() - l = left_sensor.value() - if r == 0 and l == 1: - print("right over white - turning left") - left() - if l == 0: - print("left over white") - right() - else: - forward() - -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/main.py b/src/kits/maker-pi-rp2040-robots/line-follower/main.py deleted file mode 100644 index 870e5d129..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/main.py +++ /dev/null @@ -1,94 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# sensor setup -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -# speaker pin on the Cytron Maker Pi RP2040 -SPEAKER_PIN = 22 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle -speaker.duty_u16(1000) - -# Motor setup -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN =10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -MAX_POWER_LEVEL = 65025 -QUARTER_POWER = 65025 >> 2 -SLOW_DRIVE_POWER = 16000 -BOOST_LEVEL = 15000 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(SLOW_DRIVE_POWER) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def forward(): - right_forward.duty_u16(SLOW_DRIVE_POWER) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER) - left_reverse.duty_u16(0) - speaker.duty_u16(0) - -def right(): - right_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL) - left_reverse.duty_u16(0) - speaker.duty_u16(1000) - speaker.freq(800) - -def left(): - right_forward.duty_u16(SLOW_DRIVE_POWER + BOOST_LEVEL) - right_reverse.duty_u16(0) - left_forward.duty_u16(SLOW_DRIVE_POWER - BOOST_LEVEL) - left_reverse.duty_u16(0) - speaker.duty_u16(1000) - speaker.freq(1000) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - speaker.duty_u16(0) - -def main(): - while True: - r = right_sensor.value() - l = left_sensor.value() - if r == 0 and l == 1: - print("right over white - turning left") - right() - if l == 0: - print("left over white") - left() - else: - forward() - -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/motor-drive-test.py b/src/kits/maker-pi-rp2040-robots/line-follower/motor-drive-test.py deleted file mode 100644 index 2e749679a..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/motor-drive-test.py +++ /dev/null @@ -1,53 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN =10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -MAX_POWER_LEVEL = 65025 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(MAX_POWER_LEVEL) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/play-tone.py b/src/kits/maker-pi-rp2040-robots/line-follower/play-tone.py deleted file mode 100644 index b4a1d94f6..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/play-tone.py +++ /dev/null @@ -1,14 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# speaker pin on the Cytron Maker Pi RP2040 -SPEAKER_PIN = 22 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle -speaker.duty_u16(1000) -speaker.freq(1000) # 1 Kilohertz -sleep(1) # wait a second -# turn off the PWM -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-print.py b/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-print.py deleted file mode 100644 index db534c620..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-print.py +++ /dev/null @@ -1,19 +0,0 @@ -from machine import Pin -from utime import sleep - -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -while True: - r = right_sensor.value() - l = left_sensor.value() - print("r", r, "l=", l) - if r == 0: - print("right over white") - if l == 0: - print("left over white") - sleep(.2) - diff --git a/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-sound.py b/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-sound.py deleted file mode 100644 index 968feb0a4..000000000 --- a/src/kits/maker-pi-rp2040-robots/line-follower/read-sensors-sound.py +++ /dev/null @@ -1,34 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -RIGHT_SENSOR_PIN = 2 -LEFT_SENSOR_PIN = 4 - -right_sensor = Pin(RIGHT_SENSOR_PIN) -left_sensor = Pin(LEFT_SENSOR_PIN) - -# speaker pin on the Cytron Maker Pi RP2040 -SPEAKER_PIN = 22 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle -speaker.duty_u16(1000) - -while True: - r = right_sensor.value() - l = left_sensor.value() - print("r", r, "l=", l, end='') - if r == 0 and l == 1: - print("right over white") - speaker.duty_u16(1000) - speaker.freq(400) - elif l == 0 and r == 1: - print("left over white") - speaker.duty_u16(1000) - speaker.freq(500) - else: - # turn the speaker off - speaker.duty_u16(0) - print(' f') - sleep(.3) - diff --git a/src/kits/maker-pi-rp2040-robots/motor-connections-test.py b/src/kits/maker-pi-rp2040-robots/motor-connections-test.py deleted file mode 100644 index e664d9adc..000000000 --- a/src/kits/maker-pi-rp2040-robots/motor-connections-test.py +++ /dev/null @@ -1,49 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 35000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(1) - pwm.duty_u16(0) - time.sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/motor-labs/01-motor-direction-simple.py b/src/kits/maker-pi-rp2040-robots/motor-labs/01-motor-direction-simple.py deleted file mode 100644 index 6286279e9..000000000 --- a/src/kits/maker-pi-rp2040-robots/motor-labs/01-motor-direction-simple.py +++ /dev/null @@ -1,40 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# power is 0 to 65025 -# 3700 just barely moves a DC motor sometimes -POWER_LEVEL = 30000 -# lower right pins with USB on top -FORWARD_PIN = 8 -REVERSE_PIN = 9 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -delay_time = 1 # 1 second -def main(): - while True: - - forward.duty_u16(POWER_LEVEL) - reverse.duty_u16(0) - sleep(delay_time) - - forward.duty_u16(0) - sleep(delay_time) - - reverse.duty_u16(POWER_LEVEL) - sleep(delay_time) - - reverse.duty_u16(0) - sleep(delay_time) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/motor-labs/motor-connections-test.py b/src/kits/maker-pi-rp2040-robots/motor-labs/motor-connections-test.py deleted file mode 100644 index e664d9adc..000000000 --- a/src/kits/maker-pi-rp2040-robots/motor-labs/motor-connections-test.py +++ /dev/null @@ -1,49 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 35000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(1) - pwm.duty_u16(0) - time.sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/motor-labs/pot-change-speed.py b/src/kits/maker-pi-rp2040-robots/motor-labs/pot-change-speed.py deleted file mode 100644 index 9b8b2042b..000000000 --- a/src/kits/maker-pi-rp2040-robots/motor-labs/pot-change-speed.py +++ /dev/null @@ -1,37 +0,0 @@ -from utime import sleep -from machine import Pin, PWM -from time import sleep - -# power is 0 to 65025 -# 3700 just barely moves a DC motor sometimes -MAX_POWER_LEVEL = 30000 -# lower right pins with USB on top -FORWARD_PIN = 8 -REVERSE_PIN = 9 -POT_PIN_1 = 26 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -adc = machine.ADC(POT_PIN_1) - -def main(): - while True: - pot_value = adc.read_u16() - # shift two bits right (divide by 4) - power = pot_value >> 2 - print(pot_value, power) - forward.duty_u16(power) - reverse.duty_u16(0) - sleep(.05) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/motor-labs/pot-reverse-forward.py b/src/kits/maker-pi-rp2040-robots/motor-labs/pot-reverse-forward.py deleted file mode 100644 index 24945c579..000000000 --- a/src/kits/maker-pi-rp2040-robots/motor-labs/pot-reverse-forward.py +++ /dev/null @@ -1,44 +0,0 @@ -from utime import sleep -from machine import Pin, PWM -from time import sleep - -FORWARD_PIN = 9 -REVERSE_PIN = 8 -POT_PIN_1 = 26 - -# Power is an integer 0 to 65025 -# We only need 1/4 of power for the demos -MAX_POWER_LEVEL = 16384 -HALF_POT = 32768 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -adc = machine.ADC(POT_PIN_1) - -def main(): - while True: - pot_value = adc.read_u16() - if pot_value > HALF_POT: - # forward - reverse.duty_u16(0) - power = pot_value - HALF_POT - print('forward:', power) - forward.duty_u16(power) - else: - forward.duty_u16(0) - power = HALF_POT - pot_value - reverse.duty_u16(power) - print('reverse:', power) - sleep(.05) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/collision-avoidance-ping-display-chart.py b/src/kits/maker-pi-rp2040-robots/ping-bot/collision-avoidance-ping-display-chart.py deleted file mode 100644 index e2afdf7ff..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/collision-avoidance-ping-display-chart.py +++ /dev/null @@ -1,198 +0,0 @@ -# Collision Avoidance Demo for Maker Pi RP2040 board -# Version 2.0 with random turn direction and different sounds for left and right turns - -from machine import Pin,PWM -from utime import sleep -import random -import hcsr04 -from array import array -import framebuf -import ssd1306 - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -TRIGGER_PIN = 14 # Connect the white Grove connector wire next to the 5volt on the ping sensor -ECHO_PIN = 15 # Connect the yellow Grove connector wire next to the GND on the ping sensor -MAX_VALID = 64 -ping_sensor = hcsr04.HCSR04(TRIGGER_PIN, ECHO_PIN) - -# max = 65025, min = 20000 -POWER_LEVEL = 20000 -BACKUP_TIME = 0.5 # time to backup get near an obsticle -TURN_TIME = 0.75 # time to turn if we get near an obsticle - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 9 -RIGHT_REVERSE_PIN = 8 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# Time of flight sensor is on the I2C bus on Grove connector 0 -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# get the normalized time-of-flight distance -def avg_dist(num): - total_val = 0 - for i in range(0,num): - total_val += ping_sensor.distance_cm() - sleep(.01) - return round(total_val/num, 3) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - sleep(0.1) - bequiet() - -def play_turn_right(): - playtone(500) - sleep(0.1) - bequiet() - -def play_turn_left(): - playtone(700) - sleep(0.1) - bequiet() - -x = 0 -def update_display(distance): - global x - print('updating display:', x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - oled.show() - -# start our time-of-flight sensor -valid_distance = 1 - -# loop forever -def main(): - global valid_distance - while True: - distance = avg_dist(10) - update_display(distance) - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < 30: - - # back up for a bit - reverse() - sleep(BACKUP_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - play_turn_right() - turn_right() - else: - print('turning left') - play_turn_left() - turn_left() - sleep(TURN_TIME) - else: - print('forward') - forward() - valid_distance = 1 - update_display(distance) - sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence version 1.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - stop() diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/config.py b/src/kits/maker-pi-rp2040-robots/ping-bot/config.py deleted file mode 100644 index 9097c03e4..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/config.py +++ /dev/null @@ -1,21 +0,0 @@ -# VCC, GND Clock and Data are on Grove Port 2 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) - -# servo signal pins -CS = machine.Pin(13) # can also be wired to + -DC = machine.Pin(14) -RES = machine.Pin(15) -oled = SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# pins used on the Grove 4 connector -Trig = Pin(17, Pin.OUT) -Echo = Pin(16, Pin.IN, Pin.PULL_DOWN) - -NEOPIXEL_PIN = 18 -SPEAKER_PIN = 22 - -MOTOR_RIGHT_FORWARD = 11 -MOTOR_RIGHT_BACKWARD = 10 -MOTOR_LEFT_FORWARD = 8 -MOTOR_LEFT_REVERSE = 9 \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/display-ping-sensor-graph.py b/src/kits/maker-pi-rp2040-robots/ping-bot/display-ping-sensor-graph.py deleted file mode 100644 index f735b83de..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/display-ping-sensor-graph.py +++ /dev/null @@ -1,70 +0,0 @@ -from machine import Pin, PWM -from utime import sleep, sleep_us, ticks_us - -from ssd1306 import SSD1306_SPI - -# VCC, GND Clock and Data are on Grove Port 2 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) - -spi=machine.SPI(0, sck=spi_sck, mosi=spi_tx) -# servo signal pins -CS = machine.Pin(13) # can also be wired to + -DC = machine.Pin(14) -RES = machine.Pin(15) -oled = SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# pins used on the Grove 4 connector -Trig = Pin(17, Pin.OUT) -Echo = Pin(16, Pin.IN, Pin.PULL_DOWN) - -def CheckDistance(): - SpeedOfSoundInCM = 0.034 - Trig.low() - sleep_us(2) - Trig.high() - sleep_us(10) - Trig.low() - exitLoop = False - loopcount = 0 - while Echo.value() == 0 and exitLoop == False: - loopcount = loopcount + 1 - delay_time = ticks_us() - if loopcount > 3000: - exitLoop == True - while Echo.value() == 1 and exitLoop == False: - loopcount = loopcount + 1 - receive_time = ticks_us() - if loopcount > 3000: - exitLoop == True - if exitLoop == True: - return (0) - else: - return int(( (receive_time - delay_time) * SpeedOfSoundInCM) / 2) - -oled.fill(0) -MAX_VALID_DISTANCE = 63 -max_dist = 0 -min_dist = 63 -x = 0 -while True: - distance = CheckDistance() - - if distance > MAX_VALID_DISTANCE: - distance = MAX_VALID_DISTANCE - if distance > max_dist: - max_dist = distance - if distance < min_dist: - min_dist = distance - # oled.fill(0) - range = max_dist - min_dist - oled.pixel(x, distance, 1) - if x < 126: - x += 1 - if x > 125: - oled.scroll(-1,0) - - # oled.text(str(distance), x*10, 0, 1) - oled.show() - print(distance, min_dist, max_dist, range, x) - sleep(.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/main.py b/src/kits/maker-pi-rp2040-robots/ping-bot/main.py deleted file mode 100644 index c543d4a8e..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/main.py +++ /dev/null @@ -1,270 +0,0 @@ -# Demo for Maker Pi RP2040 board using Ping sensor -from machine import Pin, PWM, Timer -from utime import sleep, ticks_ms, sleep_us, ticks_us -import urandom -from neopixel import Neopixel - -# Adjust these parameters to tune the collision avoidance behavior - -POWER_LEVEL = 30000 # Max is 64024 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .7 # how long we backup -TURN_TIME = .6 # how long we turn -MAX_VALID_DISTANCE = 100 # any distance above this is NO_SIGNAL or invalid distance - -# startup mode is 0 - motors off and LEDs flashing -# mode 1 is slow -# mode 2 is medium -# mode 3 is fast -mode = 0 - -# Use the Grove 4 Connector and put trigger on white and echo on yellow -TRIGGER_PIN = 0 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 1 # One up from bottom left corner - -# Init HC-SR04P pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -last_time = 0 # the last time we pressed the button - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - mode +=1 - else: - mode -=1 - # deal with ends - if mode > 4: mode = 2 - if mode < 0: mode = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -MAX_POWER_LEVEL = 65025 - -MAX_DISTANCE = 100 # ignore anything above this - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# returns distance in cm -def ping(): - # print('in ping') - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - # print('echo is 1') - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - # print(distance) - return int(distance) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 16 and 17 since the are used for the ping sensor -blue_led_pins = [2, 3, 4, 5, 6, 7, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -number_leds = len(blue_led_pins) -led_ports = [] -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def play_no_signal(): - playnote(100, 0.1) - sound_off() - -def play_turn(): - playnote(500, .1) - sound_off() - -def setfreq(frequency): - buzzer.freq(frequency) - -def playnote(frequency, time): - buzzer.duty_u16(1000) - setfreq(frequency) - sleep(time) - -def sound_off(): - buzzer.duty_u16(0) - -def rest(time): - buzzer.duty_u16(0) - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(.1) - playnote(800, 0.4) - sound_off() - -# loop forever -def main(): - global mode - print("running main()") - # play_startup() - while True: - distance = ping() - print('Distance:', distance) - - # standby mode - if mode == 0: - stop() - # signal to start driving - if distance < TURN_DISTANCE: - mode = 1 - forward() - sleep(1) - # drive mode - else: - if distance < TURN_DISTANCE: - play_turn() - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - else: - turn_left() - sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - led_show_dist(distance) - #sleep(0.05) - -# clean up - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('shutting motors down') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/motor-connection-test.py b/src/kits/maker-pi-rp2040-robots/ping-bot/motor-connection-test.py deleted file mode 100644 index 915309384..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/motor-connection-test.py +++ /dev/null @@ -1,49 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 35000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(1) - pwm.duty_u16(0) - time.sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/neopixel-test.py b/src/kits/maker-pi-rp2040-robots/ping-bot/neopixel-test.py deleted file mode 100644 index dcd1fb362..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/neopixel-test.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import Pin -import time -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import NeoPixel -NUMBER_PIXELS = 2 -LED_PIN = 18 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -# Color RGB values -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - - -color_index = 0 -while True: - for color in colors: - for i in range(NUMBER_PIXELS): - print(i, color_names[color_index]) - strip[i] = color - strip.write() - time.sleep(1) - color_index += 1 - if color_index >= num_colors: color_index = 0 diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/ping-sensor-demo.py b/src/kits/maker-pi-rp2040-robots/ping-bot/ping-sensor-demo.py deleted file mode 100644 index 0023db4c1..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/ping-sensor-demo.py +++ /dev/null @@ -1,62 +0,0 @@ -# Sample MicroPython program to test a ultrasonic ping sensor using the Maker Pi RP2040 -# This is a polling (non interrupt) version of testing a Ultrasonic Ping sensor -# It is deliberately designed for beginning students to be able to understand -# See https://gist.githubusercontent.com/suadanwar/81ca2b83383310fa170a76bdf56771fb/raw/3ff9ae1cc226734c4d6db8756534fbe5df829c4a/UltrasonicPico.py - -from machine import Pin, PWM -import utime - -# We will pull the trigger down low for 2 microsends and then high for 10 microseconds -# then low to start measurement -Trig = Pin(17, Pin.OUT) -# we will look for a -Echo = Pin(16, Pin.IN, Pin.PULL_DOWN) - -Buzzer = PWM(Pin(22)) - -# returns the distance to a obstacle in cm -def CheckDistance(): - SpeedOfSoundInCM = 0.034 - - # begin the LOW/HIGH/LOW trigger output sequence - Trig.low() - utime.sleep_us(2) - Trig.high() - utime.sleep_us(10) - Trig.low() - exitLoop = False - loopcount = 0 #used as a failsafe if the signal doesn't return - # now we wait for the Echo pin to go high - while Echo.value() == 0 and exitLoop == False: - loopcount = loopcount + 1 - delay_time = utime.ticks_us() - # give up after 3,000 tries - if loopcount > 3000 : exitLoop == True - - # we now a high if we did not timeout - while Echo.value() == 1 and exitLoop == False: - loopcount = loopcount + 1 - receive_time = utime.ticks_us() - # give up after 3,000 tries - if loopcount > 3000 : exitLoop == True - - if exitLoop == True: #We failed somewhere - return 0 - else: - dela_time = receive_time - delay_time - distance = dela_time * SpeedOfSoundInCM - distance = int(distance / 2) - return distance - -while True: - # why do they call CheckDistance() 3 times and not reference the distance variable? - distance = CheckDistance() - print(distance) - # biz if we find something closer than 10 cm away - if distance < 10: - Buzzer.duty_u16(3000) - Buzzer.freq(1700) - utime.sleep(0.05) - Buzzer.duty_u16(0) - # sleep longer the further away the object is - utime.sleep(distance/1000) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/ping-test.py b/src/kits/maker-pi-rp2040-robots/ping-bot/ping-test.py deleted file mode 100644 index b3761f864..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/ping-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 0 # Connect the white Grove connector wire next to the 5volt on the ping sensor -ECHO_PIN = 1 # Connect the yellow Grove connector wire next to the GND on the ping sensor - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), " cm") - utime.sleep(.25) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/play-startup-sound.py b/src/kits/maker-pi-rp2040-robots/ping-bot/play-startup-sound.py deleted file mode 100644 index cef3df8f1..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/play-startup-sound.py +++ /dev/null @@ -1,45 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 22 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def sound_off(): - speaker.duty_u16(0) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def playnote(frequency, duration): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(duration) - sound_off() - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -play_startup() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-bot/test-ping-lib.py b/src/kits/maker-pi-rp2040-robots/ping-bot/test-ping-lib.py deleted file mode 100644 index 1032d89fd..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-bot/test-ping-lib.py +++ /dev/null @@ -1,20 +0,0 @@ -from machine import Pin -from utime import sleep -import hcsr04 - -TRIGGER_PIN = 14 # Connect the white Grove connector wire next to the 5volt on the ping sensor -ECHO_PIN = 15 # Connect the yellow Grove connector wire next to the GND on the ping sensor - -ping_sensor = hcsr04.HCSR04(TRIGGER_PIN, ECHO_PIN) - -def avg_dist(num): - total_val = 0 - for i in range(0,num): - total_val += ping_sensor.distance_cm() - sleep(.02) - return round(total_val/num, 3) - -while True: - distance_cm = avg_dist(10) - print(distance_cm) - sleep(.05) diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/README.md b/src/kits/maker-pi-rp2040-robots/ping-display-bot/README.md deleted file mode 100644 index 0fd412d81..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Ping Display Bot - -This robot uses the Cytron Maker Pi RP2040 and has a 128x64 OLED on an SPI port. - -The first four wires of the OLED are on Grove 2 and the Ping Sensor is on Grove 4. -The last three pins of the OLED are on the servo signal ports 13, 14 and 15 (CS, DC and RES) - - -The configuration is as follows: - -```py -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0, sck=spi_sck, mosi=spi_tx) - -CS = machine.Pin(13) -DC = machine.Pin(14) -RES = machine.Pin(15) -oled = SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# pins used on the Grove 4 connector -Trig = Pin(17, Pin.OUT) -Echo = Pin(16, Pin.IN, Pin.PULL_DOWN) -``` - -## Standard Cytron Maker Pi RP2040 Ports - diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-i2c-ssd1306-test.py b/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-i2c-ssd1306-test.py deleted file mode 100644 index 0e3e59263..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-i2c-ssd1306-test.py +++ /dev/null @@ -1,18 +0,0 @@ -import machine -from utime import sleep -from ssd1306 import SSD1306_I2C - -# import config.py -OLED_SDA_PIN=16 -OLED_SCL_PIN=17 - -sda=machine.Pin(OLED_SDA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(OLED_SCL_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("CoderDojo Rocks!", 0, 0) -oled.show() -print('Done') - diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-ping-sensor-graph.py b/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-ping-sensor-graph.py deleted file mode 100644 index 39dacb124..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-ping-sensor-graph.py +++ /dev/null @@ -1,68 +0,0 @@ -from machine import Pin, PWM -from utime import sleep, sleep_us, ticks_us - -from ssd1306 import SSD1306_SPI - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) - -spi=machine.SPI(0, sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(13) -DC = machine.Pin(14) -RES = machine.Pin(15) -oled = SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# pins used on the Grove 4 connector -Trig = Pin(17, Pin.OUT) -Echo = Pin(16, Pin.IN, Pin.PULL_DOWN) - -def CheckDistance(): - SpeedOfSoundInCM = 0.034 - Trig.low() - sleep_us(2) - Trig.high() - sleep_us(10) - Trig.low() - exitLoop = False - loopcount = 0 - while Echo.value() == 0 and exitLoop == False: - loopcount = loopcount + 1 - delay_time = ticks_us() - if loopcount > 3000: - exitLoop == True - while Echo.value() == 1 and exitLoop == False: - loopcount = loopcount + 1 - receive_time = ticks_us() - if loopcount > 3000: - exitLoop == True - if exitLoop == True: - return (0) - else: - return int(( (receive_time - delay_time) * SpeedOfSoundInCM) / 2) - -oled.fill(0) -MAX_VALID_DISTANCE = 63 -max_dist = 0 -min_dist = 63 -x = 0 -while True: - distance = CheckDistance() - - if distance > MAX_VALID_DISTANCE: - distance = MAX_VALID_DISTANCE - if distance > max_dist: - max_dist = distance - if distance < min_dist: - min_dist = distance - # oled.fill(0) - range = max_dist - min_dist - oled.pixel(x, distance, 1) - if x < 126: - x += 1 - if x > 125: - oled.scroll(-1,0) - - # oled.text(str(distance), x*10, 0, 1) - oled.show() - print(distance, min_dist, max_dist, range, x) - sleep(.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-test.py b/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-test.py deleted file mode 100644 index 07f2d2381..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/display-test.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin -from ssd1306 import SSD1306_SPI - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) - -spi=machine.SPI(0, sck=spi_sck, mosi=spi_tx) - -CS = machine.Pin(13) -DC = machine.Pin(14) -RES = machine.Pin(15) -oled = SSD1306_SPI(128, 64, spi, DC, RES, CS) - -oled.text('Hello World!', 0, 0, 1) -oled.show() diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/install-software.sh b/src/kits/maker-pi-rp2040-robots/ping-display-bot/install-software.sh deleted file mode 100644 index e5fadfd50..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/install-software.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# Shell script to install all the relevent micropython libraries on an RP2040 chip -# this script required RSHELL to be installed -# You much shut down Thonny and any other IDEs that use the port before you run this -# use "which rshell" to find the path - -echo "Installing all the relevent micropython libraries on you RP2040" -echo "Using" $RSHELL_PATH "and" $RP2040_PORT -# TODO - create a UNIX shell-scripc test to see if rshell is working -rshell -p $RP2040_PORT - -# Step 1: Setup the HOST Variables -RSHELL_PATH=/Users/dan/opt/miniconda3/envs/mkdocs/bin/rshell -# use "ls -d /dev/cu*" on a Mac to find the port that is being used -RP2040_PORT=/dev/cu.usbmodem14101 -HOST_MICRYPYTHON_LIB_DIR=~/Documents/ws/micropython/src/drivers -HOST_SOUNDS_DIR=~/Documents/ws/robot-media/ - -# Step 2 name the board "pico" and create the lib and sounds directories -# rshell -p /dev/cu.usbmodem14101 echo 'name="pico"' > /pyboard/board.py -# restart rshell -# rshell -p /dev/cu.usbmodem14101 mkdir /pico/lib -# rshell -p /dev/cu.usbmodem14101 mkdir /pico/sounds -# check that lib/ sounds/ board.py all exists - -# Step 3 -# copy the libraries -# cp ~/Documents/ws/micropython/src/drivers/*.py /pico/lib -# rshell -p /dev/cu.usbmodem14101 cp ~/Documents/ws/micropython/src/drivers/*.py /pico/lib - -# Step 4: Copy the media files - -rshell -p $RP2040_PORT cp ~/Documents/ws/robot-media/wav-8k/*.wav /pico/sounds -rshell -p $RP2040_PORT cp ~/Documents/ws/robot-media/img/bytearrays/*py /pico/img \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-display-bot/motor-connections-test.py b/src/kits/maker-pi-rp2040-robots/ping-display-bot/motor-connections-test.py deleted file mode 100644 index e664d9adc..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-display-bot/motor-connections-test.py +++ /dev/null @@ -1,49 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 35000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(1) - pwm.duty_u16(0) - time.sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/main.py b/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/main.py deleted file mode 100644 index f97c18c76..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/main.py +++ /dev/null @@ -1,451 +0,0 @@ -# Demo for Maker Pi RP2040 board using Ping sensor, servo and i2c display - -from machine import Pin, PWM, Timer -import utime -import urandom -from neopixel import Neopixel - -# -# Ping Sensor -# Use the Grove 4 Connector and put trigger on white and echo on yellow -# -PING_TRIGGER_PIN = 7 # GP7 -PING_ECHO_PIN = 28 # GP28 - -# -# i2c OLED 128x32 -# -OLED_SDA_PIN = 26 # GP26 -OLED_SCL_PIN = 27 # GP27 - -# -# Servo -# GND: Brown -# VCC: Orange/Red -# GP15 Yellow: Signal -# -# Time for high level (Radio Shack Micro-servo @ 5V) -# 0.5 ms : 0 degree -# 1.0 ms : 45 degree -# 1.5 ms : 90 degree -# 2.0 ms : 135 degree -# 2.5 ms : 180 degree -SERVO_PIN = 15 - -# IQR Pins -FASTER_PIN = 20 -SLOWER_PIN = 21 - -# built-in Buzzer -BUZZER_PIN = 22 - -# Adjust these parameters to tune the collision avoidance behavior - -POWER_LEL = 35000 -TURN_DISTANCE = 20 # distance we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn - -# startup mode is 0 - motors off and LEDs flashing -# mode 1 is slow -# mode 2 is medium -# mode 3 is fast -mode = 0 - -# Init HC-SR04P pins -trigger = Pin(PING_TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(PING_ECHO_PIN, Pin.IN) # get the delay interval back - -faster_pin = machine.Pin(FASTER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(SLOWER_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -last_time = 0 # the last time we pressed the button - -# -# DISPLAY STUFF -# -# Display Image & text on I2C driven ssd1306 OLED display -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -import framebuf -import math -import utime -WIDTH = 128 # oled display width -HEIGHT = 32 # oled display height - -# Explicit Method -sda=machine.Pin(OLED_SDA_PIN) -scl=machine.Pin(OLED_SCL_PIN) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=40000) # 400k is too fast and has issues -print( 'i2c={:02X}'.format( i2c.scan()[0] ) ) -#print(help(i2c)) -#print(help(i2c.init)) -#print(help(i2c.scan)) -#print(help(i2c.start)) -#print(help(i2c.stop)) -#print(help(i2c.readinto)) -#print(help(i2c.write)) -#print(help(i2c.readfrom)) -#print(help(i2c.readfrom_into)) -#print(help(i2c.writeto)) -#print(help(i2c.writevto)) -#print(help(i2c.readfrom_mem)) -#print(help(i2c.readfrom_mem_into)) -#print(help(i2c.writeto_mem)) -#exit -from ssd1306 import SSD1306_I2C -oled = SSD1306_I2C(128, 32, i2c) - -# Raspberry Pi logo as 32x32 bytearray -buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -fb = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB) - -def blk(): - oled.fill(0) - oled.show() - -def horiz(l,t,r,c): # left, right , top - n = r-l+1 # Horizontal line - for i in range(n): - oled.pixel(l + i, t, c) - -def vert(l,t,b,c): # left, top, bottom - n = b-t+1 # Vertical line - for i in range(n): - oled.pixel(l, t+i,c) - -def box(l,t,r,b,c): # left, top, right, bottom - horiz(l,t,r,c) # Hollow rectangle - horiz(l,b,r,c) - vert(l,t,b,c) - vert(r,t,b,c) - -def ring2(cx,cy,r,c): # Centre (x,y), radius, colour - for angle in range(0, 90, 2): # 0 to 90 degrees in 2s - y3=int(r*math.sin(math.radians(angle))) - x3=int(r*math.cos(math.radians(angle))) - oled.pixel(cx-x3,cy+y3,c) # 4 quadrants - oled.pixel(cx-x3,cy-y3,c) - oled.pixel(cx+x3,cy+y3,c) - oled.pixel(cx+x3,cy-y3,c) - -#print(help(oled.text())) -#print(help()) -#help('modules') -#help(oled) -#help(oled.text) -#help(framebuf.FrameBuffer) -#help(framebuf.FrameBuffer.help()) - -# Clear the oled display in case it has junk on it. -oled.fill(0) # Black - -# Blit the image from the framebuffer to the oled display -oled.blit(fb, 96, 0) - -# Basic stuff -oled.text("Raspberry Pi",5,5) -oled.text("RP2040",5,15) -oled.text("press GP21",5,25) -oled.pixel(10,60,1) - -#ring2(50,43,20,1) # Empty circle -# Finally update the oled display so the image & text is displayed -oled.show() -utime.sleep(1) - - -# -# Back to the motor control stuff. (sorry... i'm soppy today) -# -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '21' in str(pin): - mode +=1 - else: - mode -=1 - # deal with ends - if mode > 4: mode = 2 - if mode < 0: mode = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(BUZZER_PIN)) - -MAX_POWER_LEVEL = 65025 - -MAX_DISTANCE = 100 # ignore anything above this - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 # this must be wired backword? -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# returns distance in cm -def ping(): - #print('in ping') - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - #print('echo is 1') - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - print(distance) - - return int(distance) - -def turn_motor_on(pwm): - #pwm.duty_u16(65025) - pwm.duty_u16(16000) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28] -blue_led_pins.remove(PING_TRIGGER_PIN) -blue_led_pins.remove(PING_ECHO_PIN) -blue_led_pins.remove(OLED_SDA_PIN) -blue_led_pins.remove(OLED_SCL_PIN) - - -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -number_leds = len(blue_led_pins) -led_ports = [] -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def play_no_signal(): - playnote(100, 0.1) - sound_off() - -def play_turn(): - playnote(500, .1) - sound_off() - -def setfreq(frequency): - buzzer.freq(frequency) - -def playnote(frequency, time): - buzzer.duty_u16(1000) - setfreq(frequency) - utime.sleep(time) - -def sound_off(): - buzzer.duty_u16(0) - -def rest(time): - buzzer.duty_u16(0) - utime.sleep(time) - -def play_startup(): - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.05) - playnote(600, .2) - rest(.1) - playnote(800, .4) - sound_off() - -def servo(degrees): - if degrees > 180: degrees=180 - if degrees < 0: degrees=0 - maxDuty=8000 # duty*100 - minDuty=2000 # duty*100 - #maxDuty=2000 # test - #minDuty=8000 # test - newDuty=minDuty+(maxDuty-minDuty)*(degrees/180) - servoPin.duty_u16(int(newDuty)) - -servoPin = PWM(Pin(SERVO_PIN)) -servoPin.freq(50) - -valid_distance = 1 - -def main(): - global valid_distance - print("running main()") - - play_startup() - oled_count=0 # repeat every - oled_count_max=0 # times through loop - servo_count=0 - servo_count_max=0 # when to update - servo_degrees = 0 - servo(servo_degrees) # start in that pos - - # loop forever - while True: - if mode == 0: - stop() - run_lights() - else: - distance = ping() - print('Distance:', distance) - oled_count += 1 - if oled_count > oled_count_max: - oled.fill(0) # Black - oled.text("Distance:",5,5) - oled.text("{:f}".format(distance),5,15) - oled.show() - oled_count = 0 - - servo_count += 1 - if servo_count > servo_count_max: - if distance > MAX_DISTANCE: - servo_degrees = 0 - else: - servo_degrees = 180-distance/MAX_DISTANCE*180 - servo(servo_degrees) - servo_count = 0 - - if distance > MAX_DISTANCE: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - #note=distance*10 - #playnote(note, .025) - - if distance < TURN_DISTANCE: - play_turn() - # back up for a bit - reverse() - utime.sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - else: - turn_left() - utime.sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - utime.sleep(0.05) - -# clean up - -# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -except Exception as e: print(e) -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('shutting motors down') - stop() diff --git a/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/servo-test.py b/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/servo-test.py deleted file mode 100644 index ae35ac987..000000000 --- a/src/kits/maker-pi-rp2040-robots/ping-servo-meter-bot/servo-test.py +++ /dev/null @@ -1,40 +0,0 @@ -# servo -# Brown: GND -# Orange/Red : VCC -# Yellow: Signal -# -# Time for high level (Radio Shack Micro-servo @ 5V) -# 0.5 ms : 0 degree -# 1.0 ms : 45 degree -# 1.5 ms : 90 degree -# 2.0 ms : 135 degree -# 2.5 ms : 180 degree - -from machine import Pin, PWM -from time import sleep - -SERVO_PIN = 15 -servoPin = PWM(Pin(SERVO_PIN)) -servoPin.freq(50) - -def servo(degrees): - if degrees > 180: degrees=180 - if degrees < 0: degrees=0 - maxDuty=8000 # duty*100 - minDuty=2000 # duty*100 - #maxDuty=2000 # test - #minDuty=8000 # test - newDuty=minDuty+(maxDuty-minDuty)*(degrees/180) - servoPin.duty_u16(int(newDuty)) - -while True: - - for degree in range(0,180,1): - servo(degree) - sleep(0.01) - print("increasing -- "+str(degree)) - - for degree in range(180, 0, -1): - servo(degree) - sleep(0.01) - print("decreasing -- "+str(degree)) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/pot-change-speed.py b/src/kits/maker-pi-rp2040-robots/pot-change-speed.py deleted file mode 100644 index ccdf04b67..000000000 --- a/src/kits/maker-pi-rp2040-robots/pot-change-speed.py +++ /dev/null @@ -1,25 +0,0 @@ -from utime import sleep -from machine import Pin, PWM -from time import sleep - -# power is 0 to 65025 -# 3700 just barely moves a DC motor sometimes -MAX_POWER_LEVEL = 30000 -# lower right pins with USB on top -FORWARD_PIN = 8 -REVERSE_PIN = 9 -POT_PIN_1 = 26 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -adc = machine.ADC(POT_PIN_1) - -while True: - pot_value = adc.read_u16() - power = pot_value >> 2 - print(pot_value, power) - forward.duty_u16(power) - reverse.duty_u16(0) - sleep(.1) - \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/pot-forward-reverse.py b/src/kits/maker-pi-rp2040-robots/pot-forward-reverse.py deleted file mode 100644 index c21292593..000000000 --- a/src/kits/maker-pi-rp2040-robots/pot-forward-reverse.py +++ /dev/null @@ -1,47 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# pot init -POT_PIN_1 = 27 -adc = machine.ADC(POT_PIN_1) - - -# motor stuff -HALF_POT = 32768 -FORWARD_PIN = 8 -REVERSE_PIN = 9 -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -counter = 0 -def main(): - global counter - while True: - pot_value = adc.read_u16() - if pot_value > HALF_POT: - # forward - reverse.duty_u16(0) - power = pot_value - HALF_POT - print('forward:', power) - # cut max power by shifting on bit right (div 2) - forward.duty_u16(power >> 1) - else: - forward.duty_u16(0) - power = HALF_POT - pot_value - # cut max power by shifting on bit right (div 2) - reverse.duty_u16(power >> 1) - print('reverse:', power) - - sleep(.1) - counter += 1 - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/print-three-pots.py b/src/kits/maker-pi-rp2040-robots/print-three-pots.py deleted file mode 100644 index 4e3bc0d8a..000000000 --- a/src/kits/maker-pi-rp2040-robots/print-three-pots.py +++ /dev/null @@ -1,19 +0,0 @@ -import machine -from utime import sleep - -POT_PIN_1 = 26 -POT_PIN_2 = 27 -POT_PIN_3 = 28 - -adc_1 = machine.ADC(POT_PIN_1) -adc_2 = machine.ADC(POT_PIN_2) -adc_3 = machine.ADC(POT_PIN_3) - -# return only the top 8 bits by sifting the 16 bit value right 8 bits -def read_pot(adc): - return int(adc.read_u16()) >> 8 - -while True: - print(read_pot(adc_1), read_pot(adc_2), read_pot(adc_3)) - sleep(.5) - \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/switch-bot/main.py b/src/kits/maker-pi-rp2040-robots/switch-bot/main.py deleted file mode 100644 index c571d11ad..000000000 --- a/src/kits/maker-pi-rp2040-robots/switch-bot/main.py +++ /dev/null @@ -1,102 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# GPIO is the internal built-in LED -led0 = Pin(0, Pin.OUT) -led1 = Pin(1, Pin.OUT) -led2 = Pin(2, Pin.OUT) - -# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating -middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) -right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN) -left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN) - -POWER_LEVEL = 30000 -RIGHT_FORWARD_PIN = 10 -RIGHT_REVERSE_PIN = 11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - - -def main(): - distance = ping() - # skip over large numbers - while distance > 100: - distance = ping() - update_display(distance, 'forward') - print(distance) - if distance < TURN_DISTANCE: - print('Reverseing') - reverse() - sleep(BACKUP_TIME) - stop() - sleep(.5) - print('Turning') - if randint(0,2): # 50% chance of being true - turn_right() - else: - turn_left() - sleep(TURN_TIME) - stop() - sleep(.5) - else: - print('Forward') - forward() - sleep(.5) - - print("counter: ", counter) - led_onboard.toggle() - counter += 1 - - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - # sound_off() - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/switch-bot/motor-connection-test.py b/src/kits/maker-pi-rp2040-robots/switch-bot/motor-connection-test.py deleted file mode 100644 index 99283b055..000000000 --- a/src/kits/maker-pi-rp2040-robots/switch-bot/motor-connection-test.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 10 -RIGHT_REVERSE_PIN = 11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(2) - pwm.duty_u16(0) - time.sleep(1) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/switch-bot/stop-all-motors.py b/src/kits/maker-pi-rp2040-robots/switch-bot/stop-all-motors.py deleted file mode 100644 index 32d77e9fd..000000000 --- a/src/kits/maker-pi-rp2040-robots/switch-bot/stop-all-motors.py +++ /dev/null @@ -1,18 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -RIGHT_FORWARD_PIN = 10 -RIGHT_REVERSE_PIN = 11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -right_forward.duty_u16(0) -right_reverse.duty_u16(0) -left_forward.duty_u16(0) -left_reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/switch-bot/switch-test.py b/src/kits/maker-pi-rp2040-robots/switch-bot/switch-test.py deleted file mode 100644 index b7a4a6635..000000000 --- a/src/kits/maker-pi-rp2040-robots/switch-bot/switch-test.py +++ /dev/null @@ -1,30 +0,0 @@ -from machine import Pin -from time import sleep - -# GPIO is the internal built-in LED -led0 = Pin(0, Pin.OUT) -led1 = Pin(1, Pin.OUT) -led2 = Pin(2, Pin.OUT) - -# input on the lower left of the Pico using a built-in pull-down resistor to keep the value from floating -middle_switch = Pin(7, Pin.IN, Pin.PULL_DOWN) -right_switch = Pin(28, Pin.IN, Pin.PULL_DOWN) -left_switch = Pin(27, Pin.IN, Pin.PULL_DOWN) - - -while True: - if middle_switch.value(): # if the value changes - led0.on() - print('middle') - else: led0.off() - - if right_switch.value(): # if the value changes - led1.on() - print('right') - else: led1.off() - - if left_switch.value(): # if the value changes - led2.on() - print('left') - else: led2.off() - sleep(.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/time-of-flight-display-test.py b/src/kits/maker-pi-rp2040-robots/time-of-flight-display-test.py deleted file mode 100644 index f633d990b..000000000 --- a/src/kits/maker-pi-rp2040-robots/time-of-flight-display-test.py +++ /dev/null @@ -1,28 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin, I2C -from ssd1306 import SSD1306_I2C -import VL53L0X - -I2C0_SDA_PIN = 0 -I2C0_SCL_PIN = 1 -I2C1_SDA_PIN = 2 -I2C1_SCL_PIN = 3 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN)) -i2c1=machine.I2C(1,sda=machine.Pin(I2C1_SDA_PIN), scl=machine.Pin(I2C1_SCL_PIN), freq=400000) - -oled = SSD1306_I2C(128, 64, i2c0) -tof = VL53L0X.VL53L0X(i2c1) - -tof.start() -while True: - tof.read() - print(tof.read()) - oled.fill(0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("P1:", 0, 20) - oled.text(str(tof.read()), 40, 20) - oled.show() - time.sleep(0.05) - -# tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-bot/collision-avoidance-tof.py b/src/kits/maker-pi-rp2040-robots/tof-bot/collision-avoidance-tof.py deleted file mode 100644 index f9af07760..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-bot/collision-avoidance-tof.py +++ /dev/null @@ -1,250 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import random -import VL53L0X -from neopixel import Neopixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip.set_pixel(0, green) - strip.set_pixel(1, green) - strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip.set_pixel(0, purple) - strip.set_pixel(1, purple) - strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip.set_pixel(0, red) - strip.set_pixel(1, red) - strip.show() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, blue) - strip.set_pixel(1, blue) - strip.show() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, yellow) - strip.set_pixel(1, yellow) - strip.show() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -#blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -#dist_scale = [4, 8, 16, 24, 50] - -#number_leds = len(blue_led_pins) -#distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -#led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -LED_DELAY = .08 - - - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - sleep(0.05) - -# startup -#run_lights() -#tof.start() -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-bot/tof-test.py b/src/kits/maker-pi-rp2040-robots/tof-bot/tof-test.py deleted file mode 100644 index 1f80a7be6..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-bot/tof-test.py +++ /dev/null @@ -1,17 +0,0 @@ -# Test program for VL53L0X - -from machine import Pin, I2C -import VL53L0X -from utime import sleep - -# Grove Connector 1 -sda=machine.Pin(0) # white Grove wire -scl=machine.Pin(1) # yellow Grove wire -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) - -tof = VL53L0X.VL53L0X(i2c) - -tof.start() -while True: - print(tof.read()) - sleep(.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-2.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-2.py deleted file mode 100644 index 17f8152af..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-2.py +++ /dev/null @@ -1,367 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import neopixel -import ssd1306 -import random -import VL53L0X -from neopixel import NeoPixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -TOF_DATA_PIN = 26 -TOF_CLOCK_PIN = 27 - -sda=machine.Pin(TOF_DATA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(TOF_CLOCK_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip[0] = green - strip[1] = green - strip.write() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip[0] = purple - strip[1] = purple - strip.write() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip[0] = red - strip[1] = red - strip.write() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip[0] = blue - strip[1] = blue - strip.write() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip[0] = yellow - strip[1] = yellow - strip.write() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -#blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -#dist_scale = [4, 8, 16, 24, 50] - -#number_leds = len(blue_led_pins) -#distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -#led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - -def update_display(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def update_splash(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - oled.text("Standby", 0, 44) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -color_cycle = 0 -def cycle_neopixels(): - global color_cycle - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip[i] = wheel(color_cycle) - strip.write() - color_cycle += 5 - color_cycle = color_cycle % 255 - -mode = 0 -# loop forever -def main(): - global valid_distance, mode - while True: - distance = get_distance() - # standby splash until distance is under 3 - if mode == 0: - update_splash(distance) - cycle_neopixels() - # wave your hand in front of the sensor to start driving - if distance < 3: mode = 1 - elif mode == 1: - update_display(distance) - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - -# startup -#run_lights() -#tof.start() -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-eyes.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-eyes.py deleted file mode 100644 index 5cd5e9e0a..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof-eyes.py +++ /dev/null @@ -1,418 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Time of Flight Sensor -# 128X64 OLED Display -# Eye Motion - -from machine import Pin,PWM -from utime import sleep -import neopixel -import ssd1306 -import random -import VL53L0X -from neopixel import NeoPixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 300 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -TOF_DATA_PIN = 26 -TOF_CLOCK_PIN = 27 - -sda=machine.Pin(TOF_DATA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(TOF_CLOCK_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=Pin(2) -SDL=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip[0] = green - strip[1] = green - strip.write() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip[0] = purple - strip[1] = purple - strip.write() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip[0] = red - strip[1] = red - strip.write() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip[0] = blue - strip[1] = blue - strip.write() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip[0] = yellow - strip[1] = yellow - strip.write() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - - -def update_splash(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - oled.text("Standby", 0, 44) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -color_cycle = 0 -def cycle_neopixels(): - global color_cycle - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip[i] = wheel(color_cycle) - strip.write() - color_cycle += 5 - color_cycle = color_cycle % 255 - - -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 -phm = 18 # pupal horizontal movement range -eye_dist_from_top = 21 -eyeWidth = 27 -eyeHeight = 10 -mouth_vpos = 45 -mouth_width = 40 - -x = 0 -def update_distance_chart(distance): - global x - print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - # oled.text(str(distance),0,53) - oled.show() - -def update_distance(i): - oled.fill(0) - - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32+i, eye_dist_from_top, 5, 5, OFF, FILL) - - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94+i, eye_dist_from_top, 5, 5, OFF, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - oled.text(str(i),0,53) - oled.show() - -def no_signal_face(): - oled.fill(0) - - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32, eye_dist_from_top, 5, 5, OFF, FILL) - - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94, eye_dist_from_top, 5, 5, OFF, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - oled.show() - -mode = 0 -# loop forever -def main(): - global valid_distance, mode - while True: - distance = get_distance() - # standby splash until distance is under 3 - if mode == 0: - update_distance_chart(distance) - # update_distance(-5) - # sleep(2) - cycle_neopixels() - # wave your hand in front of the sensor to start driving - if distance < 3: mode = 1 - elif mode == 1: - update_distance(0) - if distance > MAX_DIST: - print('no signal') - no_signal_face() - # play_no_signal() - # we have a valid distance - else: - # print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - stop() - sleep(REVERSE_TIME) - - # turn in a random direction - if random.random() > .5: - print('turning right') - update_distance(-10) - sleep(1) - turn_right() - else: - print('turning left') - update_distance(10) - sleep(1) - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - # print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof.py deleted file mode 100644 index ef6afbe7f..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance-tof.py +++ /dev/null @@ -1,320 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import ssd1306 -import random -import VL53L0X -from neopixel import Neopixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip.set_pixel(0, green) - strip.set_pixel(1, green) - strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip.set_pixel(0, purple) - strip.set_pixel(1, purple) - strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip.set_pixel(0, red) - strip.set_pixel(1, red) - strip.show() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, blue) - strip.set_pixel(1, blue) - strip.show() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, yellow) - strip.set_pixel(1, yellow) - strip.show() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -#blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -#dist_scale = [4, 8, 16, 24, 50] - -#number_leds = len(blue_led_pins) -#distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -#led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - -def update_display(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - update_display(distance) - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - sleep(0.05) - -# startup -#run_lights() -#tof.start() -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance.py deleted file mode 100644 index 9da395309..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/collision-avoidance.py +++ /dev/null @@ -1,357 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import neopixel -import ssd1306 -import random -import VL53L0X -from neopixel import NeoPixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -TOF_DATA_PIN = 26 -TOF_CLOCK_PIN = 27 - -sda=machine.Pin(TOF_DATA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(TOF_CLOCK_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=Pin(2) -SDL=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip[0] = green - strip[1] = green - strip.write() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip[0] = purple - strip[1] = purple - strip.write() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip[0] = red - strip[1] = red - strip.write() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip[0] = blue - strip[1] = blue - strip.write() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip[0] = yellow - strip[1] = yellow - strip.write() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - -def update_display(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def update_splash(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - oled.text("Standby", 0, 44) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -color_cycle = 0 -def cycle_neopixels(): - global color_cycle - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip[i] = wheel(color_cycle) - strip.write() - color_cycle += 5 - color_cycle = color_cycle % 255 - -mode = 0 -# loop forever -def main(): - global valid_distance, mode - while True: - distance = get_distance() - # standby splash until distance is under 3 - if mode == 0: - update_splash(distance) - cycle_neopixels() - # wave your hand in front of the sensor to start driving - if distance < 3: mode = 1 - elif mode == 1: - update_display(distance) - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - -# startup -#run_lights() -#tof.start() -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-i2c-tof.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-i2c-tof.py deleted file mode 100644 index b821e3ca2..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-i2c-tof.py +++ /dev/null @@ -1,42 +0,0 @@ -import machine -import VL53L0X -from time import sleep -from ssd1306 import SSD1306_I2C - -# setup the 1st I2C interface - -# this is the servo data pin in the corner of the Cytron RP2040 -OLED_RESET = machine.Pin(15, machine.Pin.OUT) -# optional set to low -OLED_RESET.low() -# optional delay here to keep it low -sleep(0.01) -OLED_RESET.high() - -i2c_oled = machine.I2C(0, sda=machine.Pin(0), scl=machine.Pin(1)) -print (i2c_oled.scan()) -oled = SSD1306_I2C(128, 64, i2c_oled) -# oled.text('CoderDojo Rocks!', 0, 0) -# oled.text('128x64 i2C', 0, 20) -# oled.show() - -sda=machine.Pin(26) # lower right pin -scl=machine.Pin(27) # one up from lower right pin -i2c_tof=machine.I2C(1, sda=sda, scl=scl, freq=400000) -print(i2c_tof) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -counter = 0 -while True: - oled.fill(0) - oled.text('CoderDojo Rocks!', 0, 0) - oled.text(str(counter), 0, 10) - distance = tof.read() - oled.text(str(distance), 0, 20) - oled.show() - sleep(.1) - counter += 1 - diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-test.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-test.py deleted file mode 100644 index 39f6202c2..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/display-test.py +++ /dev/null @@ -1,26 +0,0 @@ -import machine -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -SCK=machine.Pin(2) -SDL=machine.Pin(3) - -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) - -RES = machine.Pin(14) -DC = machine.Pin(15) -CS = machine.Pin(13) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -while True: - for i in range(HEIGHT - 10): - oled.text('Hello Dan', 0, i, 1) - for j in range(WIDTH): - oled.scroll(1,0) - oled.show() - - - \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/i2c-scanner.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/i2c-scanner.py deleted file mode 100644 index eae087599..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/i2c-scanner.py +++ /dev/null @@ -1,7 +0,0 @@ -# I2C Scanner -import machine -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -print('This should return [41]') -print(i2c.scan()) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/main.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/main.py deleted file mode 100644 index 5cd5e9e0a..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/main.py +++ /dev/null @@ -1,418 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Time of Flight Sensor -# 128X64 OLED Display -# Eye Motion - -from machine import Pin,PWM -from utime import sleep -import neopixel -import ssd1306 -import random -import VL53L0X -from neopixel import NeoPixel -import framebuf - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 300 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -TOF_DATA_PIN = 26 -TOF_CLOCK_PIN = 27 - -sda=machine.Pin(TOF_DATA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(TOF_CLOCK_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=Pin(2) -SDL=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip[0] = green - strip[1] = green - strip.write() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip[0] = purple - strip[1] = purple - strip.write() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip[0] = red - strip[1] = red - strip.write() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip[0] = blue - strip[1] = blue - strip.write() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip[0] = yellow - strip[1] = yellow - strip.write() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - - -def update_splash(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - oled.text("Standby", 0, 44) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -color_cycle = 0 -def cycle_neopixels(): - global color_cycle - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip[i] = wheel(color_cycle) - strip.write() - color_cycle += 5 - color_cycle = color_cycle % 255 - - -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 -phm = 18 # pupal horizontal movement range -eye_dist_from_top = 21 -eyeWidth = 27 -eyeHeight = 10 -mouth_vpos = 45 -mouth_width = 40 - -x = 0 -def update_distance_chart(distance): - global x - print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - # oled.text(str(distance),0,53) - oled.show() - -def update_distance(i): - oled.fill(0) - - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32+i, eye_dist_from_top, 5, 5, OFF, FILL) - - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94+i, eye_dist_from_top, 5, 5, OFF, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - oled.text(str(i),0,53) - oled.show() - -def no_signal_face(): - oled.fill(0) - - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32, eye_dist_from_top, 5, 5, OFF, FILL) - - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94, eye_dist_from_top, 5, 5, OFF, FILL) - - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - oled.show() - -mode = 0 -# loop forever -def main(): - global valid_distance, mode - while True: - distance = get_distance() - # standby splash until distance is under 3 - if mode == 0: - update_distance_chart(distance) - # update_distance(-5) - # sleep(2) - cycle_neopixels() - # wave your hand in front of the sensor to start driving - if distance < 3: mode = 1 - elif mode == 1: - update_distance(0) - if distance > MAX_DIST: - print('no signal') - no_signal_face() - # play_no_signal() - # we have a valid distance - else: - # print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - stop() - sleep(REVERSE_TIME) - - # turn in a random direction - if random.random() > .5: - print('turning right') - update_distance(-10) - sleep(1) - turn_right() - else: - print('turning left') - update_distance(10) - sleep(1) - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - # print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/motor-connection-test.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/motor-connection-test.py deleted file mode 100644 index e349da5fd..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/motor-connection-test.py +++ /dev/null @@ -1,34 +0,0 @@ -from machine import Pin, PWM -import time - -# max is 65025, min is 10000 -POWER_LEVEL = 30000 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-bot/tof-display-test.py b/src/kits/maker-pi-rp2040-robots/tof-display-bot/tof-display-test.py deleted file mode 100644 index a65427ed6..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-bot/tof-display-test.py +++ /dev/null @@ -1,35 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin, I2C -import ssd1306 -import VL53L0X - -sda=machine.Pin(26) -scl=machine.Pin(27) -i2c=machine.I2C(1,sda=sda, scl=scl, freq=400000) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -RES = machine.Pin(13) -DC = machine.Pin(14) -CS = machine.Pin(15) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -tof = VL53L0X.VL53L0X(i2c) - -tof.start() -while True: - tof.read() - print(tof.read()) - oled.fill(0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("P1:", 0, 20) - oled.text(str(tof.read()), 40, 20) - oled.show() - time.sleep(0.05) - -# tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-display-i2c/main.py b/src/kits/maker-pi-rp2040-robots/tof-display-i2c/main.py deleted file mode 100644 index 542df7b05..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-display-i2c/main.py +++ /dev/null @@ -1,306 +0,0 @@ -from machine import Pin,PWM -import VL53L0X -from time import sleep -from ssd1306 import SSD1306_I2C -from neopixel import NeoPixel -import random -import framebuf - -# OLED Display dimentions -HEIGHT = 64 -WIDTH = 128 -# setup the 1st I2C interface - -# this is the servo data pin in the corner of the Cytron RP2040 -OLED_RESET = Pin(15, Pin.OUT) -# optional set to low -OLED_RESET.low() -# optional delay here to keep it low -sleep(0.01) -OLED_RESET.high() - -i2c_oled = machine.I2C(0, sda=Pin(0), scl=Pin(1)) -print (i2c_oled.scan()) -oled = SSD1306_I2C(128, 64, i2c_oled) -# oled.text('CoderDojo Rocks!', 0, 0) -# oled.text('128x64 i2C', 0, 20) -# oled.show() - -sda=Pin(26) # lower right pin -scl=Pin(27) # one up from lower right pin -i2c_tof=machine.I2C(1, sda=sda, scl=scl, freq=400000) -print(i2c_tof) - -POWER_LEVEL = 33000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# key parameters -POWER_LEVEL = 30000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# the two on-board NeoPixels -NUMBER_PIXELS = 2 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# 64, 64, framebuf.MONO_VLSB -coderdojo_logo_byte_array = bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') -fbi = framebuf.FrameBuffer(coderdojo_logo_byte_array, 64, 64, framebuf.MONO_VLSB) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip[0] = green - strip[1] = green - strip.write() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip[0] = purple - strip[1] = purple - strip.write() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip[0] = red - strip[1] = red - strip.write() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip[0] = blue - strip[1] = blue - strip.write() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip[0] = yellow - strip[1] = yellow - strip.write() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -def update_display(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo Robot", 0, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -def update_splash(distance): - oled.fill(0) - oled.blit(fbi, 64, 0) - oled.text("CoderDojo", 0, 0) - oled.text("Robots", 0, 10) - oled.text("Standby", 0, 44) - if distance < MAX_DIST: - oled.text("Dist:", 0, 54) - oled.text(str(distance), 40, 54) - else: - oled.text("No Signal", 0, 54) - oled.show() - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# a list of our prior distance measurements for graphing mode -distances=[] - -# startup -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -valid_distance = 0 -mode = 0 -# loop forever -def main(): - global mode, valid_distance - while True: - distance = get_distance() - # standby splash until distance is under 3 - if mode == 0: - update_splash(distance) - # wave your hand in front of the sensor to start driving - if distance < 3: mode = 1 - elif mode == 1: - update_display(distance) - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - # play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - #led_show_dist(distance) - -# startup -#run_lights() -#tof.start() -#play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/i2c-scanner.py b/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/i2c-scanner.py deleted file mode 100644 index 4a1053dd0..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/i2c-scanner.py +++ /dev/null @@ -1,18 +0,0 @@ -import machine - -I2C0_SDA_PIN = 16 -I2C0_SCL_PIN = 17 -i2c0=machine.I2C(0,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000) - -print('Scanning I2C bus 0.') -devices = i2c0.scan() # this returns a list of devices - -device_count = len(devices) - -if device_count == 0: - print('No i2c device found on bus 0.') -else: - print(device_count, 'devices found.') - -for device in devices: - print('Decimal address:', device, ", Hex address: ", hex(device)) diff --git a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/main.py b/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/main.py deleted file mode 100644 index a708d4bfd..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/main.py +++ /dev/null @@ -1,338 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import random -import VL53L0X -from neopixel import NeoPixel - - -# key parameters -POWER_LEVEL = 35000 # min is 20000 max is 65025 -TURN_DISTANCE = 20 # distnce we decide to turn - try 20 -REVERSE_TIME = 1 # how long we backup -TURN_TIME = .5 # how long we turn -MAX_DIST = 500 # max ToF sensor value that is reasonable without error - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NEOPIXEL_PIN = 2 -NUMBER_PIXELS = 8 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# Grove Connector 1 -sda=machine.Pin(0) # white Grove wire -scl=machine.Pin(1) # yellow Grove wire -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -BLACK = (0, 0, 0) -RED = (255, 0, 0) -LIGHT_RED = (15, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -LIGHT_GREEN = (0, 25, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -LIGHT_BLUE = (0, 0, 25) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -GRAY = (50, 50, 50) -LIGHT_GRAY = (10, 10, 10) -OFF = (0, 0, 0) -COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) -num_colors = len(COLORS) - -# color wheel -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def draw_idle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -def draw_forward(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == NUMBER_PIXELS - pixel_index - 1: - strip[i] = LIGHT_GRAY - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_reverse(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == pixel_index: - strip[i] = LIGHT_BLUE - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_right(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_RED - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_left(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_GREEN - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_all_off(): - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -#blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -#dist_scale = [4, 8, 16, 24, 50] - -#number_leds = len(blue_led_pins) -#distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -#led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 50 # distance measure when an object is about 1/2 cm away -max_dist = 100 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# map the value from old to new range like the arduino map(x, inmin, inmax, outmin, outmax) -def valmap(value, istart, istop, ostart, ostop): - denominator = istop - istart - if denominator == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / denominator)) - -LED_DELAY = .08 - -min_dist = 5 -max_dist = 255 - -# global variables -counter = 0 -state = 0 -old_state = 1 -play_startup() - -# loop forever -def main(): - global counter, state, old_state - while True: - # sleep(1) - distance = get_distance() - print('distance =', distance) - - # wait until we get a hand wave in front of the bot - if distance > TURN_DISTANCE and state == 0: - if state != old_state: - print('new state idel distance > ', distance) - draw_idle(counter, .1) - counter += 1 - if distance < TURN_DISTANCE and state == 0: - state = 1 - # non idle - if state == 1: - # print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - play_turn() - reverse_cycles = round(REVERSE_TIME / .1) - for i in range(0, reverse_cycles): - draw_reverse(counter, .1) - counter += 1 - - # turn in a random direction - turn_direction = random.random() - if turn_direction > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - turn_cycles = round(TURN_TIME / .1) - for i in range(0, turn_cycles): - if turn_direction > .5: - draw_right(counter, .1) - else: - draw_left(counter, .1) - counter += 1 - # now continue going forward - forward() - draw_forward(counter, .01) - counter += 1 - else: - print('going forward', distance) - forward() - draw_forward(counter, .01) - counter += 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - # turn off the LEDs - draw_all_off() - tof.stop() diff --git a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/motor-connections-test.py b/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/motor-connections-test.py deleted file mode 100644 index e664d9adc..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/motor-connections-test.py +++ /dev/null @@ -1,49 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 35000 # MAX is65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(1) - pwm.duty_u16(0) - time.sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off motors') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-neopixel-test.py b/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-neopixel-test.py deleted file mode 100644 index f1efbe210..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-neopixel-test.py +++ /dev/null @@ -1,38 +0,0 @@ -# Test program for VL53L0X - -from machine import Pin, I2C -import VL53L0X -from utime import sleep -from neopixel import NeoPixel - -NEOPIXEL_PIN = 12 -NUMBER_PIXELS = 8 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# Grove Connector 4 -I2C0_SDA_PIN = 26 -I2C0_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C0_SDA_PIN), scl=machine.Pin(I2C0_SCL_PIN), freq=400000) - -tof = VL53L0X.VL53L0X(i2c) - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -MIN_DIST = 30 -MAX_DIST = 300 -tof.start() -while True: - dist = tof.read() - MIN_DIST - if dist > MAX_DIST: - dist = 300 - index = valmap(dist, MIN_DIST, MAX_DIST, 0, NUMBER_PIXELS-1) - print(dist, index) - strip[index] = (255,0,0) - strip.write() - sleep(.05) # below this we get a flicker - strip[index] = (0,0,0) - strip.write() diff --git a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-print-test.py b/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-print-test.py deleted file mode 100644 index 36eacddef..000000000 --- a/src/kits/maker-pi-rp2040-robots/tof-neopiexel-bot/tof-print-test.py +++ /dev/null @@ -1,25 +0,0 @@ -from machine import I2C -from time import sleep -import VL53L0X - -# Grove connector 4 -sda=machine.Pin(26) -scl=machine.Pin(27) -i2c=I2C(1, sda=sda, scl=scl) - -print(i2c) - -# Create a VL53L0X object time of flight distance sensor object -tof = VL53L0X.VL53L0X(i2c) -MAX_RANGE = 1200 - -tof.start() -while True: - tof_value = tof.read() - if tof_value < MAX_RANGE : - dist = (tof_value - 30) * .5 - print('value =', tof_value, ' dist=', dist) - sleep(.5) - else: - print(tof_value, ' out of range') - diff --git a/src/kits/maker-pi-rp2040/01-on-board-neopixel-test.py b/src/kits/maker-pi-rp2040/01-on-board-neopixel-test.py deleted file mode 100644 index 71fd569e4..000000000 --- a/src/kits/maker-pi-rp2040/01-on-board-neopixel-test.py +++ /dev/null @@ -1,30 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NUMBER_PIXELS = 2 -NEOPIXEL_PIN = 18 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -counter = 0 -while True: - - # turn both on red - for i in range(0, NUMBER_PIXELS): - strip[i] = (255,0,0) - strip.write() - sleep(.5) - - # turn both on green - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,255,0) - strip.write() - sleep(.5) - - # turn both on blue - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,255) - strip.write() - sleep(1) - counter += 1 - print(counter) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/01a-blink-lab.py b/src/kits/maker-pi-rp2040/01a-blink-lab.py deleted file mode 100644 index ed45fb238..000000000 --- a/src/kits/maker-pi-rp2040/01a-blink-lab.py +++ /dev/null @@ -1,10 +0,0 @@ -import machine -from utime import sleep - -# setup the first LED as an output signal -first_led = machine.Pin(0, machine.Pin.OUT) - -while True: - first_led.toggle() - # wait for 1/2 second - sleep(.5) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/01b-led-pattern-test.py b/src/kits/maker-pi-rp2040/01b-led-pattern-test.py deleted file mode 100644 index 69199bf10..000000000 --- a/src/kits/maker-pi-rp2040/01b-led-pattern-test.py +++ /dev/null @@ -1,25 +0,0 @@ -# Demo for Maker Pi RP2040 board - -import machine -import time - -blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -while True: - # blue up - for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() diff --git a/src/kits/maker-pi-rp2040/02a-blink-neopixel-lab.py b/src/kits/maker-pi-rp2040/02a-blink-neopixel-lab.py deleted file mode 100644 index 8b2a47796..000000000 --- a/src/kits/maker-pi-rp2040/02a-blink-neopixel-lab.py +++ /dev/null @@ -1,19 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -while True: - # turn on first pixel red for 1/2 second - strip.set_pixel(0, (255, 0, 0)) - strip.show() - sleep(.5) - strip.set_pixel(0, (0, 0, 0)) # turn all colors off - strip.show() - sleep(.5) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/02b-blink-neopixel-lab.py b/src/kits/maker-pi-rp2040/02b-blink-neopixel-lab.py deleted file mode 100644 index ae94e48d6..000000000 --- a/src/kits/maker-pi-rp2040/02b-blink-neopixel-lab.py +++ /dev/null @@ -1,19 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -while True: - # turn on first red for 1/2 second - strip.set_pixel(0, (255, 0, 0)) - strip.show() - sleep(.5) - strip.set_pixel(0, (0, 0, 0)) # all first off - strip.show() - sleep(.5) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/03-neopixel-button-lab.py b/src/kits/maker-pi-rp2040/03-neopixel-button-lab.py deleted file mode 100644 index 89e7c37ca..000000000 --- a/src/kits/maker-pi-rp2040/03-neopixel-button-lab.py +++ /dev/null @@ -1,93 +0,0 @@ -# press buttons to change the color of the NeoPixels -import utime -from machine import Pin -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 -BUTTON_A_PIN = 20 -BUTTON_B_PIN = 21 -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -white = (255, 255, 255) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) - -# color index into colors list -neopixel_a = 0 -neopixel_b = 0 -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_a = machine.Pin(BUTTON_A_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_b = machine.Pin(BUTTON_B_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time, num_colors, neopixel_a, neopixel_b - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - button_presses += 1 - if '20' in str(pin): - neopixel_a +=1 - if neopixel_a > num_colors - 1: - neopixel_a = 0 - else: - neopixel_b +=1 - if neopixel_b > num_colors - 1: - neopixel_b = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -print('Running NeoPixel Button Lab') -strip.set_pixel(0, (4,5,5)) -strip.set_pixel(1, (4,5,5)) -strip.show() - -def main(): - global button_presses, old_presses, colors, neopixel_a, neopixel_b - while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a) - print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b) - strip.set_pixel(0, colors[neopixel_a]) - strip.set_pixel(1, colors[neopixel_b]) - strip.show() - old_presses = button_presses - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Turning off NeoPixels') - strip.set_pixel(0, (0,0,0)) - strip.set_pixel(1, (0,0,0)) - strip.show() diff --git a/src/kits/maker-pi-rp2040/72-pixel-rainbow-bot.py b/src/kits/maker-pi-rp2040/72-pixel-rainbow-bot.py deleted file mode 100644 index af9f388c3..000000000 --- a/src/kits/maker-pi-rp2040/72-pixel-rainbow-bot.py +++ /dev/null @@ -1,172 +0,0 @@ -from machine import Pin, PWM -from time import sleep -from machine import Pin -from machine import I2C -import VL53L0X -from neopixel import NeoPixel - -# Motor Code -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 18 -LEFT_FORWARD_PIN = 20 -LEFT_REVERSE_PIN = 21 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# Sensor Code -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor - -# used to blink the onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# LED Code -NEOPIXEL_PIN = 15 -NUMBER_PIXELS = 72 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# driving parameters -POWER_LEVEL = 30000 # use a value from 20000 to 65025 -TURN_THRESHOLD = 400 # 25 cm -TURN_TIME = .25 # seconds of turning -BACKUP_TIME = .75 # seconds of backing up if obstacle detected - -red = (255, 0, 0) -orange = (255, 165, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, green) - #strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, red) - #strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, blue) - #strip.show() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, yellow) - #strip.show() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - for i in range(numpix): - strip.set_pixel(i, violet) - strip.show() - -def read_sensor_avg(): - total = 0 - for i in range(10): - total = total + tof.read() - sleep(.01) - return int(total/10) - -# offset is the color to start (0 to 6) -# dir is 1 for forward and -1 for reverse -def color_wipe_4(offset, dir): - for i in range(12): - if dir == 1: - this_color = colors[ ((i-offset) %7 )] - else: - this_color = colors[ ((i+offset) %7 )] - strip[i] = this_color - strip[23-i] = this_color - strip[i+24] = this_color - strip[47-i] = this_color - strip[48+i] = this_color - strip[71-i] = this_color - strip.write() - # time.sleep(0.01) - -counter = 0 -while True: - dist = read_sensor_avg() - print(dist) - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - turn_right() - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - else: - forward() - print("going forward") - color_wipe_4(counter % 7, 1) - counter += 1 \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/blue-leds-up-down.py b/src/kits/maker-pi-rp2040/blue-leds-up-down.py deleted file mode 100644 index edcbe3502..000000000 --- a/src/kits/maker-pi-rp2040/blue-leds-up-down.py +++ /dev/null @@ -1,25 +0,0 @@ -import machine -import time - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -unused_blue_led_pins = [2,3,4,6,7,26,27,28] -number_leds = len(unused_blue_led_pins) -led_ports = [] -delay = .05 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(unused_blue_led_pins[i], machine.Pin.OUT)) - -# loop forever -while True: - # blue up - for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/collision-avoidance-ping.py b/src/kits/maker-pi-rp2040/collision-avoidance-ping.py deleted file mode 100644 index 3b85d73f3..000000000 --- a/src/kits/maker-pi-rp2040/collision-avoidance-ping.py +++ /dev/null @@ -1,273 +0,0 @@ -# Demo for Maker Pi RP2040 board using Ping sensor -from machine import Pin, PWM, Timer -import utime -import urandom -from neopixel import Neopixel - -# Adjust these parameters to tune the collision avoidance behavior - -POWER_LEVEL = 35000 -TURN_DISTANCE = 20 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn - -# startup mode is 0 - motors off and LEDs flashing -# mode 1 is slow -# mode 2 is medium -# mode 3 is fast -mode = 0 - -# Use the Grove 4 Connector and put trigger on white and echo on yellow -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -# Init HC-SR04P pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -last_time = 0 # the last time we pressed the button - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global mode, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - mode +=1 - else: - mode -=1 - # deal with ends - if mode > 4: mode = 2 - if mode < 0: mode = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -MAX_POWER_LEVEL = 65025 - -MAX_DISTANCE = 100 # ignore anything above this - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# returns distance in cm -def ping(): - print('in ping') - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - print('echo is 1') - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - print(distance) - return int(distance) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 16 and 17 since the are used for the ping sensor -blue_led_pins = [0, 1, 2, 3, 4, 5, 6, 7, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -number_leds = len(blue_led_pins) -led_ports = [] -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - utime.sleep(LED_DELAY) - led_ports[i].low() - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def play_no_signal(): - playnote(100, 0.1) - sound_off() - -def play_turn(): - playnote(500, .1) - sound_off() - -def setfreq(frequency): - buzzer.freq(frequency) - -def playnote(frequency, time): - buzzer.duty_u16(1000) - setfreq(frequency) - utime.sleep(time) - -def sound_off(): - buzzer.duty_u16(0) - -def rest(time): - buzzer.duty_u16(0) - utime.sleep(time) - -def play_startup(): - #playnote(600, 0.2) - rest(.05) - #playnote(600, 0.2) - rest(.05) - #playnote(600, 0.2) - rest(.1) - #playnote(800, 0.4) - sound_off() - -valid_distance = 1 -# loop forever -def main(): - global valid_distance - print("running main()") - - play_startup() - - while True: - if mode == 0: - stop() - run_lights() - else: - distance = ping() - print('Distance:', distance) - if distance > MAX_DISTANCE: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < TURN_DISTANCE: - play_turn() - # back up for a bit - reverse() - utime.sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - else: - turn_left() - utime.sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - utime.sleep(0.05) - -# clean up - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - print('shutting motors down') - stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/collision-avoidance.py b/src/kits/maker-pi-rp2040/collision-avoidance.py deleted file mode 100644 index 88589bf5f..000000000 --- a/src/kits/maker-pi-rp2040/collision-avoidance.py +++ /dev/null @@ -1,91 +0,0 @@ -# Time of Flight Distance Sensor Test -# Demo for Maker Pi RP2040 board - -from machine import Pin,PWM -import time -import VL53L0X -buzzer=PWM(Pin(22)) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn(): - playtone(500) - time.sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - while True: - global valid_distance - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - - valid_distance = 0 - else: - print(distance) - if distance < 30: - play_turn() - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/collision-avoidence-tof-v3.py b/src/kits/maker-pi-rp2040/collision-avoidence-tof-v3.py deleted file mode 100644 index ce66d63ae..000000000 --- a/src/kits/maker-pi-rp2040/collision-avoidence-tof-v3.py +++ /dev/null @@ -1,276 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import random -import VL53L0X -from neopixel import Neopixel - -# key parameters -POWER_LEVEL = 35000 # min is 20000 max is 65025 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_DIST = 200 - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 11 -RIGHT_REVERSE_PIN = 10 -LEFT_FORWARD_PIN = 8 -LEFT_REVERSE_PIN = 9 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -sda=machine.Pin(2) # lower right pin -scl=machine.Pin(3) # one up from lower right pin -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip.set_pixel(0, green) - strip.set_pixel(1, green) - strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip.set_pixel(0, purple) - strip.set_pixel(1, purple) - strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip.set_pixel(0, red) - strip.set_pixel(1, red) - strip.show() - play_turn_right() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, blue) - strip.set_pixel(1, blue) - strip.show() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, yellow) - strip.set_pixel(1, yellow) - strip.show() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [4, 8, 16, 24, 50] - -number_leds = len(blue_led_pins) -distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds, distance_per_led - for led_index in range(0, number_leds): - val = TURN_DISTANCE + led_index * distance_per_led - if in_distance > val: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -LED_DELAY = .08 -def run_lights(): - for i in range(0, number_leds): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() - # blue down - for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - strip.set_pixel(0, colors[i]) - strip.set_pixel(1, colors[i]) - strip.show() - sleep(LED_DELAY) - led_ports[i].low() -# start our time-of-flight sensor - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > MAX_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - sleep(TURN_TIME) - # continue going forward - forward() - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - sleep(0.05) - -# startup -run_lights() -tof.start() -play_startup() -valid_distance = 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/collision-avoidence-v1.py b/src/kits/maker-pi-rp2040/collision-avoidence-v1.py deleted file mode 100644 index 535523759..000000000 --- a/src/kits/maker-pi-rp2040/collision-avoidence-v1.py +++ /dev/null @@ -1,181 +0,0 @@ -# Demo for Maker Pi RP2040 board - -from machine import Pin,PWM -import time -import VL53L0X - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# max = 65025, min = 20000 -POWER_LEVEL = 20000 - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# Time of flight sensor is on the I2C bus on Grove connector 0 -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn(): - playtone(500) - time.sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < 30: - play_turn() - # back up for 1/2 second - reverse() - time.sleep(0.5) - turn_right() - time.sleep(0.75) - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence version 1.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/collision-avoidence-v2.py b/src/kits/maker-pi-rp2040/collision-avoidence-v2.py deleted file mode 100644 index 962f749ce..000000000 --- a/src/kits/maker-pi-rp2040/collision-avoidence-v2.py +++ /dev/null @@ -1,198 +0,0 @@ -# Collision Avoidance Demo for Maker Pi RP2040 board -# Version 2.0 with random turn direction and different sounds for left and right turns - -from machine import Pin,PWM -import time -import random -import VL53L0X - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# max = 65025, min = 20000 -POWER_LEVEL = 20000 -BACKUP_TIME = 0.5 # time to backup get near an obsticle -TURN_TIME = 0.75 # time to turn if we get near an obsticle - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# Time of flight sensor is on the I2C bus on Grove connector 0 -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn_right(): - playtone(500) - time.sleep(0.1) - bequiet() - -def play_turn_left(): - playtone(700) - time.sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < 30: - - # back up for a bit - reverse() - time.sleep(BACKUP_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - play_turn_right() - turn_right() - else: - print('turning left') - play_turn_left() - turn_left() - time.sleep(TURN_TIME) - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence version 1.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/color-wheel.py b/src/kits/maker-pi-rp2040/color-wheel.py deleted file mode 100644 index 9c380c556..000000000 --- a/src/kits/maker-pi-rp2040/color-wheel.py +++ /dev/null @@ -1,39 +0,0 @@ -from utime import sleep -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 - -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(wait): - for j in range(255): - for i in range(num_pixels): - rc_index = (i * 256 // num_pixels) + j - pixels[i] = wheel(rc_index & 255) - pixels.write() - -counter = 0 -while True: - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip.set_pixel(i, wheel(counter)) - strip.show() - counter += 1 - counter = counter % 255 - sleep(.01) diff --git a/src/kits/maker-pi-rp2040/display-spi-test.py b/src/kits/maker-pi-rp2040/display-spi-test.py deleted file mode 100644 index 039d51521..000000000 --- a/src/kits/maker-pi-rp2040/display-spi-test.py +++ /dev/null @@ -1,22 +0,0 @@ -import machine -from utime import sleep -import ssd1306 - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=200000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -counter = 0; -while True: - oled.fill(0) - oled.show() - oled.text('CoderDojo Rocks!', 0, 0, 1) - oled.text(str(counter), 0, 57, 1) - oled.show() - counter += 1; - sleep(1) - diff --git a/src/kits/maker-pi-rp2040/display-ssd1306-spi-test.py b/src/kits/maker-pi-rp2040/display-ssd1306-spi-test.py deleted file mode 100644 index 039d51521..000000000 --- a/src/kits/maker-pi-rp2040/display-ssd1306-spi-test.py +++ /dev/null @@ -1,22 +0,0 @@ -import machine -from utime import sleep -import ssd1306 - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=200000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -counter = 0; -while True: - oled.fill(0) - oled.show() - oled.text('CoderDojo Rocks!', 0, 0, 1) - oled.text(str(counter), 0, 57, 1) - oled.show() - counter += 1; - sleep(1) - diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-display.py b/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-display.py deleted file mode 100644 index 7690dfe44..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-display.py +++ /dev/null @@ -1,301 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.1 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# Defualt parameters for collision avoidance mode - -DEFAULT_MOTOR_POWER_CODE = 3 # med is 30000 -DEFAULT_TURN_DISTANCE_CODE = 4 # 15 cm -DEFAULT_REVERSE_TIME_CODE = 4 # .5 seconds -DEFAULT_TURN_TIME_CODE = 4 # .5 seconds - -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -mode_value = 0 # the value for the currnt mode -counter = 0 # main loop counter - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) - -# power - -# motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_pairs = [('Off', 0), ('Low', 20000), ('ML', 30000), ('Med', 37000), ('MH', 49000), ('Hi', 55000), ('Max', MAX_POWER_LEVEL)] -motor_power_count = len(motor_power_pairs) -motor_power_code = DEFAULT_MOTOR_POWER_CODE -motor_power_pair = motor_power_pairs[motor_power_code] -motor_power_label = motor_power_pair[0] -motor_power = motor_power_pair[1] - -# turn distance -turn_dist_list = (5, 7, 10, 15, 20, 30, 40) -turn_dist_count = len(turn_dist_list) -turn_dist_code = DEFAULT_TURN_DISTANCE_CODE -turn_distance = turn_dist_list[DEFAULT_TURN_DISTANCE_CODE] - -# rev time -reverse_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -reverse_time_count = len(reverse_time_list) -reverse_time_code = DEFAULT_REVERSE_TIME_CODE -reverse_time = reverse_time_list[DEFAULT_REVERSE_TIME_CODE] - -# turn times -turn_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -turn_time_count = len(turn_time_list) -turn_time_code = DEFAULT_TURN_TIME_CODE -turn_time = turn_time_list[DEFAULT_TURN_TIME_CODE] - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, mode_value, last_time, mode_count, motor_power_code, turn_dist_code, reverse_time_code, turn_time_code - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: - if mode == 3: - motor_power_code += 1 - if motor_power_code >= motor_power_count: - motor_power_code = 0 - if mode == 4: - turn_dist_code += 1 - if turn_dist_code >= turn_dist_count: - turn_dist_code = 0 - if mode == 5: - reverse_time_code += 1 - if reverse_time_code >= reverse_time_count: - reverse_time_code = 0 - if mode == 6: - turn_time_code += 1 - if turn_time_code >= turn_time_count: - turn_time_code = 0 - last_time = new_time - - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - - -# time of flight calibration parameters -TOF_ZERO_VALUE = 60 # subtract this from reading so measurements next to sensor are 0 cm -TOF_MAX_SENSOR_DIST = 1200 # ignore anything above this distance -TOF_SCALE = .25 # multiply this to the raw number to convert to CM - -# get the normalized time-of-flight distance -def get_tof_distance_cm(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - #if tof_distance < TOF_ZERO_VALUE: - # zero_dist = tof_distance - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter, mode_value, motor_power, turn_distance, reverse_time, turn_time - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - - # standby mode - motors are off - if mode == 0: - oled.text('Press button', 0, 10, 1) - oled.text('GP%d to start.' % MODE_BUTTON_PIN, 0, 20, 1) - oled.text('Dist:%d' % dist, 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # collision avoidance motors are on - elif mode == 1: - oled.text('Dist:%d' % dist, 0, 10, 1) - oled.text('Motor Pwr:' + motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # dive in a square - elif mode == 2: - oled.text('Sqr Fwd Time:%d' % SQUARE_FWD_TIME, 0, 10, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 20, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # select power, turn dist, reverse time, turn time - elif mode == 3: - oled.text('Select Power:', 0, 10, 1) - oled.text(motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text(str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - oled.text(str(mode_value), 0, 40, 1) - - # turn dist - elif mode == 4: - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(str(turn_dist_list[turn_dist_code]), 0, 20, 1) - oled.text(str(mode_value), 0, 40, 1) - - # reverse time - elif mode == 5: - oled.text('Reverse Time:', 0, 10, 1) - oled.text(str(reverse_time_list[reverse_time_code]), 0, 20, 1) - - # turn time - elif mode == 6: - oled.text('Turn Time:', 0, 10, 1) - oled.text(str(turn_time_list[turn_time_code]), 0, 20, 1) - oled.text(str(mode_value), 0, 40, 1) - - # summary screen - elif mode == 7: - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 10, 1) - oled.text('Turn Dist:' + str(turn_dist_list[turn_dist_code]), 0, 20, 1) - oled.text('Rev Time:' + str(reverse_time_list[reverse_time_code]), 0, 30, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 40, 1) - - # add to the bottom of the display - br = 54 # bottom row for numbers - oled.text('ct:', 0, br, 1) - oled.text(str(counter), 25, br, 1) - - oled.text('md:', 60, br, 1) - oled.text(str(mode), 75, br, 1) - - oled.text('mv:', 90, br, 1) - oled.text(str(mode_value), 110, br, 1) if (mode != 0 and mode != 1 and mode != 2 and mode != 7) else None - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, mode_value, last_mode, current_mode, motor_power, turn_distance, reverse_time, turn_time - while True: - dist = get_tof_distance_cm() - update_display() - - if mode == 0: # standby - stop() - elif mode == 1: # collision avoidance - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < turn_distance: - # back up for a bit - drive_reverse(motor_power) - sleep(reverse_time) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(turn_time) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - elif mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - - elif mode == 3: # prog power - stop() - motor_power = motor_power_pairs[mode_value][1] - - elif mode == 4: # prog turn dist - turn_distance = turn_dist_list[mode_value] - - elif mode == 5: # prog rev time - reverse_time = reverse_time_list[mode_value] - - elif mode == 6: # prog turn time - turn_time = turn_time_list[mode_value] - - sleep(.1) - counter += 1 - if mode != current_mode: - print(counter, 'mode:', mode, 'mode val:', mode_value) - current_mode = mode - mode_value = 0 - # if (counter % 50) == 0: - # print(counter, 'mode:', mode, 'mode val:', mode_value) - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.1') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options-v2.py b/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options-v2.py deleted file mode 100644 index 474e77f24..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options-v2.py +++ /dev/null @@ -1,288 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.1 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# Defualt parameters for collision avoidance mode - -DEFAULT_MOTOR_POWER_CODE = 3 # med is 30000 -DEFAULT_TURN_DISTANCE_CODE = 4 # 15 cm -DEFAULT_REVERSE_TIME_CODE = 4 # .5 seconds -DEFAULT_TURN_TIME_CODE = 4 # .5 seconds - -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -# counter = 0 # main loop counter for debugging - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) - -# power - -# motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_pairs = [('Off', 0), ('Low', 20000), ('ML', 30000), ('Med', 37000), ('MH', 49000), ('Hi', 55000), ('Max', MAX_POWER_LEVEL)] -motor_power_count = len(motor_power_pairs) -motor_power_code = DEFAULT_MOTOR_POWER_CODE -motor_power_pair = motor_power_pairs[motor_power_code] -motor_power_label = motor_power_pair[0] -motor_power = motor_power_pairs[motor_power_code][1] - -# turn distance -turn_dist_list = (5, 7, 10, 15, 20, 30, 40) -turn_dist_count = len(turn_dist_list) -turn_dist_code = DEFAULT_TURN_DISTANCE_CODE -turn_distance = turn_dist_list[DEFAULT_TURN_DISTANCE_CODE] - -# rev time -reverse_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -reverse_time_count = len(reverse_time_list) -reverse_time_code = DEFAULT_REVERSE_TIME_CODE -reverse_time = reverse_time_list[DEFAULT_REVERSE_TIME_CODE] - -# turn times -turn_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -turn_time_count = len(turn_time_list) -turn_time_code = DEFAULT_TURN_TIME_CODE -turn_time = turn_time_list[DEFAULT_TURN_TIME_CODE] - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, last_time, mode_count, motor_power_code, motor_power, turn_dist_code, turn_dist, reverse_time_code, reverse_time, turn_time_code, turn_time - new_time = ticks_ms() - - # if it has been more that 1/10 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - last_time = new_time - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: # the mode value button has been pressed so we have a mode value that has a value to be set - - if mode == 3: - motor_power_code += 1 - if motor_power_code >= motor_power_count: - motor_power_code = 0 - motor_power = motor_power_pairs[motor_power_code][1] - - if mode == 4: - turn_dist_code += 1 - if turn_dist_code >= turn_dist_count: - turn_dist_code = 0 - turn_dist = turn_dist_list[turn_dist_code] - - if mode == 5: - reverse_time_code += 1 - if reverse_time_code >= reverse_time_count: - reverse_time_code = 0 - reverse_time = reverse_time_list[reverse_time_code] - - if mode == 6: - turn_time_code += 1 - turn_time = turn_time_list[turn_time_code] - if turn_time_code >= turn_time_count: - turn_time_code = 0 - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - -# time of flight calibration parameters -TOF_ZERO_VALUE = 60 # subtract this from reading so measurements next to sensor are 0 cm -TOF_MAX_SENSOR_DIST = 1200 # ignore anything above this distance -TOF_SCALE = .25 # multiply this to the raw number to convert to CM - -# get the normalized time-of-flight distance -def get_tof_distance_cm(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # return the distance in cm - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter, mode_value, motor_power, turn_distance, reverse_time, turn_time - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - - # standby mode - motors are off - if mode == 0: - oled.text('Press button', 0, 10, 1) - oled.text('GP%d to start.' % MODE_BUTTON_PIN, 0, 20, 1) - oled.text('Dist:%d' % dist, 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # collision avoidance motors are on - elif mode == 1: - oled.text('Dist:%d' % dist, 0, 10, 1) - oled.text('Motor Pwr:' + motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # dive in a square - elif mode == 2: - oled.text('Sqr Fwd Time:%d' % SQUARE_FWD_TIME, 0, 10, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 20, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # select power, turn dist, reverse time, turn time - elif mode == 3: - oled.text('Select Power:', 0, 10, 1) - oled.text(motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text(str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - oled.text(str(motor_power), 0, 40, 1) - - # turn dist - elif mode == 4: - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(str(turn_dist_list[turn_dist_code]), 0, 20, 1) - - # reverse time - elif mode == 5: - oled.text('Reverse Time:', 0, 10, 1) - oled.text(str(reverse_time_list[reverse_time_code]), 0, 20, 1) - - # turn time - elif mode == 6: - oled.text('Turn Time:', 0, 10, 1) - oled.text(str(turn_time_list[turn_time_code]), 0, 20, 1) - - # summary screen - elif mode == 7: - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 10, 1) - oled.text('Turn Dist:' + str(turn_dist_list[turn_dist_code]), 0, 20, 1) - oled.text('Rev Time:' + str(reverse_time_list[reverse_time_code]), 0, 30, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 40, 1) - - # add to the bottom of the display - br = 54 # bottom row for numbers - # oled.text('ct:', 0, br, 1) - # oled.text(str(counter), 25, br, 1) - - # oled.text('md:', 0, br, 1) - # oled.text(str(mode), 25, br, 1) - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, last_mode, current_mode, motor_power, turn_distance, reverse_time, turn_time - while True: - dist = get_tof_distance_cm() - update_display() - - if mode == 0: # standby - stop() - elif mode == 1: # collision avoidance - - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < turn_distance: - # back up for a bit - drive_reverse(motor_power) - sleep(reverse_time) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(turn_time) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - elif mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - - elif mode == 3: # prog power - stop() - - sleep(.1) - # counter += 1 - if mode != current_mode: - print('mode:', mode) - current_mode = mode - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.1') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options.py b/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options.py deleted file mode 100644 index c437c2195..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/collision-avoidance-options.py +++ /dev/null @@ -1,265 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.1 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# key parameters -MOTOR_POWER = 20000 # min is 20000 max is 65025 -MOTOR_POWER_CODE = 3 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -REVERSE_TIME = .4 # how long we backup -TURN_TIME = .4 # how long we turn -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -mode_value = 0 # the value for the currnt mode -counter = 0 # main loop counter - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) -# power -motor_power_code = MOTOR_POWER_CODE -# motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_dict = {0: 'Off', 20000: 'Low', 30000: 'ML', 40000: 'Med', 50000: 'MH', 55000: 'Hi', MAX_POWER_LEVEL: 'Max'} -motor_power_count = len(motor_power_dict) -motor_power = 0 -# turn distance -turn_dist_dict = {5: '5cm', 7: '7cm', 10: '10cm', 15: '15cm', 20: '20cm', 30: '30cm', 40: '40cm'} -turn_dist_count = len(turn_dist_dict) -turn_distance = 5 -# rev time -reverse_time_dict= {.2: '.2 sec', .3: '.3 sec', .4: '.4 sec', .5: '.5 sec', .6: '.6 sec', .7: '.7 sec', .8: '.8 sec', .9: '.9 sec', 1.0: '1 sec'} -reverse_time_count = len(reverse_time_dict) -reverse_time = .2 -# turn time -turn_time_dict= {.2: '.2 sec', .3: '.3 sec', .4: '.4 sec', .5: '.5 sec', .6: '.6 sec', .7: '.7 sec', .8: '.8 sec', .9: '.9 sec', 1.0: '1 sec'} -turn_time_count = len(turn_time_dict) -turn_time = .2 - - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, mode_value, last_time, mode_count - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: - mode_value +=1 - # if mode_value > 6: - # mode_value = 0 - last_time = new_time - print(mode) - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - - -# time of flight calibration parameters -# calibration parameters for the Time of Flight Sensor - -TOF_ZERO_VALUE = 60 -TOF_MAX_SENSOR_DIST = 1200 -TOF_SCALE = .25 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - #if tof_distance < TOF_ZERO_VALUE: - # zero_dist = tof_distance - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter, mode_value, motor_power, turn_distance, reverse_time, turn_time - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - if mode == 0: - oled.text('Press button', 0, 10, 1) - oled.text('GP%d to start.' % MODE_BUTTON_PIN, 0, 20, 1) - oled.text('Dist:%d' % dist, 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - elif mode == 1: # collision avoidance - oled.text('Dist:%d' % dist, 0, 10, 1) - oled.text('Motor Pwr:' + motor_power_dict[motor_power], 0, 20, 1) - # oled.text('', 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - elif mode == 2: # square - oled.text('Sqr Fwd Time:%d' % SQUARE_FWD_TIME, 0, 10, 1) - oled.text('Motor Pwr:' + motor_power_dict[motor_power], 0, 20, 1) - oled.text('Turn Time:' + turn_time_dict[turn_time], 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - elif mode == 3: # select power - oled.text('Select level:', 0, 10, 1) - oled.text(motor_power_dict[motor_power], 0, 20, 1) - elif mode == 4: # turn dist - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(turn_dist_dict[turn_distance], 0, 20, 1) - elif mode == 5: # reverse time - oled.text('Reverse Time:', 0, 10, 1) - oled.text(reverse_time_dict[reverse_time], 0, 20, 1) - elif mode == 6: # turn time - oled.text('Turn Time:', 0, 10, 1) - oled.text(turn_time_dict[turn_time], 0, 20, 1) - elif mode == 7: - oled.text('Motor Pwr:' + motor_power_dict[motor_power], 0, 10, 1) - oled.text('Turn Dist:' + turn_dist_dict[turn_distance], 0, 20, 1) - oled.text('Rev Time:' + reverse_time_dict[reverse_time], 0, 30, 1) - oled.text('Turn Time:' + turn_time_dict[turn_time], 0, 40, 1) - - oled.text(str(counter), 0, 54, 1) - oled.text(str(mode), 50, 54, 1) - oled.text(str(mode_value), 80, 54, 1) if (mode != 0 and mode != 1 and mode != 2 and mode != 7) else None - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, mode_value, last_mode, current_mode, motor_power, turn_distance, reverse_time, turn_time - while True: - dist = get_distance() - update_display() - - if mode == 0: # standby - stop() - elif mode == 1: # collision avoidance - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < turn_distance: - # back up for a bit - drive_reverse(motor_power) - sleep(reverse_time) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(turn_time) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - elif mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - - elif mode == 3: # prog power - stop() - mode_value = mode_value % motor_power_count - motor_power = list(motor_power_dict.keys())[mode_value] - # print(mode_value) - - elif mode == 4: # prog turn dist - mode_value = mode_value % turn_dist_count - turn_distance = list(turn_dist_dict.keys())[mode_value] - # print(mode_value) - - elif mode == 5: # prog rev time - mode_value = mode_value % reverse_time_count - reverse_time = list(reverse_time_dict.keys())[mode_value] - # print(mode_value) - - elif mode == 6: # prog turn time - mode_value = mode_value % turn_time_count - turn_time = list(turn_time_dict.keys())[mode_value] - # print(mode_value) - - sleep(.1) - counter += 1 - if mode != current_mode: - print(counter, 'mode:', mode, 'mode val:', mode_value) - current_mode = mode - mode_value = 0 - # if (counter % 50) == 0: - # print(counter, 'mode:', mode, 'mode val:', mode_value) - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.1') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/display-spi-test.py b/src/kits/maker-pi-rp2040/display-tof-bot/display-spi-test.py deleted file mode 100644 index 039d51521..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/display-spi-test.py +++ /dev/null @@ -1,22 +0,0 @@ -import machine -from utime import sleep -import ssd1306 - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=200000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -counter = 0; -while True: - oled.fill(0) - oled.show() - oled.text('CoderDojo Rocks!', 0, 0, 1) - oled.text(str(counter), 0, 57, 1) - oled.show() - counter += 1; - sleep(1) - diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/main.py b/src/kits/maker-pi-rp2040/display-tof-bot/main.py deleted file mode 100644 index 3d19893c3..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/main.py +++ /dev/null @@ -1,288 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.1 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# Defualt parameters for collision avoidance mode - -DEFAULT_MOTOR_POWER_CODE = 3 # med is 30000 -DEFAULT_TURN_DISTANCE_CODE = 4 # 15 cm -DEFAULT_REVERSE_TIME_CODE = 4 # .5 seconds -DEFAULT_TURN_TIME_CODE = 4 # .5 seconds - -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -# counter = 0 # main loop counter for debugging - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) - -# power - -# motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_pairs = [('Off', 0), ('Low', 20000), ('ML', 30000), ('Med', 37000), ('MH', 49000), ('Hi', 55000), ('Max', MAX_POWER_LEVEL)] -motor_power_count = len(motor_power_pairs) -motor_power_code = DEFAULT_MOTOR_POWER_CODE -motor_power_pair = motor_power_pairs[motor_power_code] -motor_power_label = motor_power_pair[0] -motor_power = motor_power_pairs[motor_power_code][1] - -# turn distance -turn_dist_list = (5, 7, 10, 15, 20, 30, 40) -turn_dist_count = len(turn_dist_list) -turn_dist_code = DEFAULT_TURN_DISTANCE_CODE -turn_distance = turn_dist_list[DEFAULT_TURN_DISTANCE_CODE] - -# rev time -reverse_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -reverse_time_count = len(reverse_time_list) -reverse_time_code = DEFAULT_REVERSE_TIME_CODE -reverse_time = reverse_time_list[DEFAULT_REVERSE_TIME_CODE] - -# turn times -turn_time_list= (.3, .4, .5, .6, .7, .8, .9, 1.0, 1.1, 1.2, 1.5) -turn_time_count = len(turn_time_list) -turn_time_code = DEFAULT_TURN_TIME_CODE -turn_time = turn_time_list[DEFAULT_TURN_TIME_CODE] - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, last_time, mode_count, motor_power_code, motor_power, turn_dist_code, turn_dist, reverse_time_code, reverse_time, turn_time_code, turn_time - new_time = ticks_ms() - - # if it has been more that 1/10 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - last_time = new_time - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: # the mode value button has been pressed so we have a mode value that has a value to be set - - if mode == 3: - motor_power_code += 1 - if motor_power_code >= motor_power_count: - motor_power_code = 0 - motor_power = motor_power_pairs[motor_power_code][1] - - if mode == 4: - turn_dist_code += 1 - if turn_dist_code >= turn_dist_count: - turn_dist_code = 0 - turn_dist = turn_dist_list[turn_dist_code] - - if mode == 5: - reverse_time_code += 1 - if reverse_time_code >= reverse_time_count: - reverse_time_code = 0 - reverse_time = reverse_time_list[reverse_time_code] - - if mode == 6: - turn_time_code += 1 - if turn_time_code >= turn_time_count: - turn_time_code = 0 - turn_time = turn_time_list[turn_time_code] - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - -# time of flight calibration parameters -TOF_ZERO_VALUE = 60 # subtract this from reading so measurements next to sensor are 0 cm -TOF_MAX_SENSOR_DIST = 1200 # ignore anything above this distance -TOF_SCALE = .25 # multiply this to the raw number to convert to CM - -# get the normalized time-of-flight distance -def get_tof_distance_cm(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # return the distance in cm - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter, mode_value, motor_power, turn_distance, reverse_time, turn_time - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - - # standby mode - motors are off - if mode == 0: - oled.text('Press button', 0, 10, 1) - oled.text('GP%d to start.' % MODE_BUTTON_PIN, 0, 20, 1) - oled.text('Dist:%d' % dist, 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # collision avoidance motors are on - elif mode == 1: - oled.text('Dist:%d' % dist, 0, 10, 1) - oled.text('Motor Pwr:' + motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # dive in a square - elif mode == 2: - oled.text('Sqr Fwd Time:%d' % SQUARE_FWD_TIME, 0, 10, 1) - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 20, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 30, 1) - action = 'Turn' if dist < turn_distance else 'Forward' - oled.text('Action:' + action, 0, 40, 1) - - # select power, turn dist, reverse time, turn time - elif mode == 3: - oled.text('Select Power:', 0, 10, 1) - oled.text(motor_power_pairs[motor_power_code][0], 0, 20, 1) - oled.text(str(motor_power_pairs[motor_power_code][1]), 0, 30, 1) - oled.text(str(motor_power), 0, 40, 1) - - # turn dist - elif mode == 4: - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(str(turn_dist_list[turn_dist_code]), 0, 20, 1) - - # reverse time - elif mode == 5: - oled.text('Reverse Time:', 0, 10, 1) - oled.text(str(reverse_time_list[reverse_time_code]), 0, 20, 1) - - # turn time - elif mode == 6: - oled.text('Turn Time:', 0, 10, 1) - oled.text(str(turn_time_list[turn_time_code]), 0, 20, 1) - - # summary screen - elif mode == 7: - oled.text('Motor Pwr:' + str(motor_power_pairs[motor_power_code][0]), 0, 10, 1) - oled.text('Turn Dist:' + str(turn_dist_list[turn_dist_code]), 0, 20, 1) - oled.text('Rev Time:' + str(reverse_time_list[reverse_time_code]), 0, 30, 1) - oled.text('Turn Time:' + str(turn_time_list[turn_time_code]), 0, 40, 1) - - # add to the bottom of the display - br = 54 # bottom row for numbers - # oled.text('ct:', 0, br, 1) - # oled.text(str(counter), 25, br, 1) - - # oled.text('md:', 0, br, 1) - # oled.text(str(mode), 25, br, 1) - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, last_mode, current_mode, motor_power, turn_distance, reverse_time, turn_time - while True: - dist = get_tof_distance_cm() - update_display() - - if mode == 0: # standby - stop() - elif mode == 1: # collision avoidance - - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < turn_distance: - # back up for a bit - drive_reverse(motor_power) - sleep(reverse_time) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(turn_time) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - elif mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - - elif mode == 3: # prog power - stop() - - sleep(.1) - # counter += 1 - if mode != current_mode: - print('mode:', mode) - current_mode = mode - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.1') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/neopixel-test.py b/src/kits/maker-pi-rp2040/display-tof-bot/neopixel-test.py deleted file mode 100644 index 2733c86d7..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/neopixel-test.py +++ /dev/null @@ -1,36 +0,0 @@ -import time -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -color_index = 0 -while True: - for color in colors: - for i in range(NUMBER_PIXELS): - print(i, color_names[color_index]) - strip.set_pixel(i, color) - strip.show() - time.sleep(1) - color_index += 1 - if color_index >= num_colors: color_index = 0 diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/robotfunctions.py b/src/kits/maker-pi-rp2040/display-tof-bot/robotfunctions.py deleted file mode 100644 index 086e2307c..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/robotfunctions.py +++ /dev/null @@ -1,138 +0,0 @@ -from machine import Pin,PWM -from neopixel import Neopixel -from utime import sleep, ticks_ms - -# The Piezo Buzzer is on GP22 -BUZZER_PIN = 22 -buzzer=PWM(Pin(BUZZER_PIN)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN =10 -RIGHT_REVERSE_PIN =11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -def turn_motor_on(pwm, motor_power): - pwm.duty_u16(motor_power) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(motor_power): - turn_motor_on(right_forward, motor_power) - turn_motor_on(left_forward, motor_power) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip.set_pixel(0, green) - strip.set_pixel(1, green) - strip.show() - -def drive_reverse(motor_power): - turn_motor_on(right_reverse, motor_power) - turn_motor_on(left_reverse, motor_power) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip.set_pixel(0, purple) - strip.set_pixel(1, purple) - strip.show() - -def turn_right(motor_power): - turn_motor_on(right_forward, motor_power) - turn_motor_on(left_reverse, motor_power) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip.set_pixel(0, red) - strip.set_pixel(1, red) - strip.show() - play_turn_right() - -def turn_left(motor_power): - turn_motor_on(right_reverse, motor_power) - turn_motor_on(left_forward, motor_power) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, blue) - strip.set_pixel(1, blue) - strip.show() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, yellow) - strip.set_pixel(1, yellow) - strip.show() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/tof-display-text.py b/src/kits/maker-pi-rp2040/display-tof-bot/tof-display-text.py deleted file mode 100644 index 0d90177d3..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/tof-display-text.py +++ /dev/null @@ -1,33 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import ssd1306 -import VL53L0X - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -while True: - dist = tof.read() - print(dist) - oled.fill(0) - oled.text(str(dist), 0, 0, 1) - oled.show() - time.sleep(0.2) - -# for cleanup -# tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display-tof-bot/tof-test.py b/src/kits/maker-pi-rp2040/display-tof-bot/tof-test.py deleted file mode 100644 index 16dbcece8..000000000 --- a/src/kits/maker-pi-rp2040/display-tof-bot/tof-test.py +++ /dev/null @@ -1,35 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -while True: - tof.start() - tof.read() - print(tof.read()) - tof.stop() - time.sleep(0.1) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -while True: - tof.start() - tof.read() - print(tof.read()) - tof.stop() - time.sleep(0.1) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/display/main.py b/src/kits/maker-pi-rp2040/display/main.py deleted file mode 100644 index 5fed64776..000000000 --- a/src/kits/maker-pi-rp2040/display/main.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin, Timer -import ssd1306 -from utime import sleep -import framebuf - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(6) -DC = machine.Pin(5) -SCK=machine.Pin(2) -SDA=machine.Pin(3) -RES = machine.Pin(4) - - -spi=machine.SPI(0,sck=SCK, mosi=SDA) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.poweron() -sleep(.1) -oled.init_display() -sleep(.1) - -counter = 0 -while True: - oled.fill(0) - - for i in range(0,63,8): - oled.hline(0, i, WIDTH, 1) - oled.hline(0, 63, WIDTH, 1) - - for i in range(0,127,8): - oled.vline(i, 0, HEIGHT, 1) - - oled.vline(127, 0, HEIGHT, 1) - - # clear the region to draw the counter in - oled.fill_rect(9,9,40,11,0) - oled.text(str(counter), 10, 11, 1) - - oled.show() - sleep(.05) - print(counter) - counter += 1 \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/i2c-scanner.py b/src/kits/maker-pi-rp2040/i2c-scanner.py deleted file mode 100644 index b1203d0b2..000000000 --- a/src/kits/maker-pi-rp2040/i2c-scanner.py +++ /dev/null @@ -1,15 +0,0 @@ -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -device_id = i2c.scan()[0] -print("Device found at decimal", device_id) - -if device_id == 41: - print("TEST PASS") -else: - print("No device found at decimal 41") - print("TEST FAIL") diff --git a/src/kits/maker-pi-rp2040/led-pattern-test.py b/src/kits/maker-pi-rp2040/led-pattern-test.py deleted file mode 100644 index 1e1b6cd69..000000000 --- a/src/kits/maker-pi-rp2040/led-pattern-test.py +++ /dev/null @@ -1,71 +0,0 @@ -# Demo for Maker Pi RP2040 board - -import machine -import time -import VL53L0X - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -# start our time-of-flight sensor -tof.start() -# loop forever -while True: - distance = get_distance() - print(distance) - led_show_dist(distance) - time.sleep(0.05) - -# clean up -tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/led-strip-8-pixels.py b/src/kits/maker-pi-rp2040/led-strip-8-pixels.py deleted file mode 100644 index 72d48e0ba..000000000 --- a/src/kits/maker-pi-rp2040/led-strip-8-pixels.py +++ /dev/null @@ -1,335 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep -import random -import VL53L0X -from neopixel import NeoPixel - - -# key parameters -POWER_LEVEL = 35000 # min is 20000 max is 65025 -TURN_DISTANCE = 20 # distnce we decide to turn - try 20 -REVERSE_TIME = .6 # how long we backup -TURN_TIME = .5 # how long we turn -MAX_DIST = 500 # max ToF sensor value that is reasonable without error - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -NEOPIXEL_PIN = 2 -NUMBER_PIXELS = 8 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# Grove Connector 1 -sda=machine.Pin(0) # white Grove wire -scl=machine.Pin(1) # yellow Grove wire -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -BLACK = (0, 0, 0) -RED = (255, 0, 0) -LIGHT_RED = (15, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -LIGHT_GREEN = (0, 25, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -LIGHT_BLUE = (0, 0, 25) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -GRAY = (50, 50, 50) -LIGHT_GRAY = (10, 10, 10) -OFF = (0, 0, 0) -COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) -num_colors = len(COLORS) - -# color wheel -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def draw_idle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -def draw_forward(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == NUMBER_PIXELS - pixel_index - 1: - strip[i] = LIGHT_GRAY - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_reverse(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == pixel_index: - strip[i] = LIGHT_BLUE - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_right(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_RED - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_left(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_GREEN - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def draw_all_off(): - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -# remove 0, 1, 2 and 3 for the I2C busees and remove 26,27 and 28 for the pots -#blue_led_pins = [4, 5, 6, 7, 16, 17] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -#dist_scale = [4, 8, 16, 24, 50] - -#number_leds = len(blue_led_pins) -#distance_per_led = (MAX_DIST - TURN_DISTANCE) / number_leds -#led_ports = [] -# time for each LED to display -delay = .05 - -# time of flight calibration parameters -zero_dist = 50 # distance measure when an object is about 1/2 cm away -max_dist = 100 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -#for i in range(number_leds): -# led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# map the value from old to new range like the arduino map(x, inmin, inmax, outmin, outmax) -def valmap(value, istart, istop, ostart, ostop): - denominator = istop - istart - if denominator == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / denominator)) - -LED_DELAY = .08 - -min_dist = 5 -max_dist = 255 - -# global variables -counter = 0 -state = 0 -old_state = 1 - -# loop forever -def main(): - global counter, state, old_state - while True: - distance = get_distance() - # print(distance) - - # wait hear until we get a valid distance - if distance > MAX_DIST: - if state != old_state: - print('distance > ', MAX_DIST) - old_state = state - draw_idle(counter, .1) - counter += 1 - else: - state = 1 - # we have a valid distance - else: - # print(distance) - if distance < TURN_DISTANCE: - # back up for a bit - reverse() - reverse_cycles = round(REVERSE_TIME / .1) - for i in range(0, reverse_cycles): - draw_reverse(counter, .1) - counter += 1 - - # turn in a random direction - turn_direction = random.random() - if turn_direction > .5: - print('turning right') - turn_right() - else: - print('turning left') - turn_left() - turn_cycles = round(REVERSE_TIME / .1) - for i in range(0, turn_cycles): - if turn_direction > .5: - draw_right(counter, .1) - else: - draw_left(counter, .1) - counter += 1 - # now continue going forward - forward() - draw_forward(counter, .01) - counter += 1 - else: - print('forward') - forward() - draw_forward(counter, .01) - counter += 1 - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - # turn off the LEDs - draw_all_off() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/main.py b/src/kits/maker-pi-rp2040/main.py deleted file mode 100644 index e5c467f05..000000000 --- a/src/kits/maker-pi-rp2040/main.py +++ /dev/null @@ -1,179 +0,0 @@ -# Demo for Maker Pi RP2040 board - -from machine import Pin,PWM -import time -import VL53L0X - -# Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -# max = 65025, min = 20000 -POWER_LEVEL = 20000 - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -# Time of flight sensor is on the I2C bus on Grove connector 0 -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def play_no_signal(): - playtone(100) - time.sleep(0.1) - bequiet() - -def play_turn(): - playtone(500) - time.sleep(0.1) - bequiet() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 - -# loop forever -def main(): - global valid_distance - while True: - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - if distance < 30: - play_turn() - # back up for 1/2 second - reverse() - time.sleep(0.5) - turn_right() - time.sleep(0.75) - else: - print('forward') - forward() - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrup -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) - stop() - tof.stop() diff --git a/src/kits/maker-pi-rp2040/maker-pi-rp2040-pins.py b/src/kits/maker-pi-rp2040/maker-pi-rp2040-pins.py deleted file mode 100644 index c1b48ba88..000000000 --- a/src/kits/maker-pi-rp2040/maker-pi-rp2040-pins.py +++ /dev/null @@ -1,54 +0,0 @@ -# Pin Definitions for the Cytron Maker Pi RP2040 Board -# just import this file and reference the pins by name, not number - -# Grove Port 1 -I2C_SDA_0 = 0 -I2C_SCL_0 = 1 - -# Grove Port 2 -I2C_SDA_0 = 2 -I2C_SCL_0 = 3 - -# Grove Port 3 -I2C_SDA_0 = 4 -I2C_SCL_0 = 5 - -# Grove Port 4 -I2C_SDA_0 = 16 -I2C_SCL_0 = 17 - -# Grove Port 5 -I2C_SDA_0 = 6 -ADC_0 = 26 - -# Grove Port 6 -ADC_0 = 26 -ADC_1 = 27 - -# Grove Port 7 -ADC_2 = 28 -SCL1 = 7 - -# Motor Pins -MOTOR_1_A = 8 -MOTOR_1_B = 9 -MOTOR_2_A = 10 -MOTOR_2_B = 11 - -# Servo Pins -SERVO_1 = 12 -SERVO_2 = 13 -SERVO_3 = 14 -SERVO_4 = 15 - -# LEDs -NEOPIXEL = 18 -# Blue LEDs GPIO Status Pins -BLUE_LEDS = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] - -# Buttons -BUTTON_1 = 20 -BUTTON_2 = 21 - -# Buzzer -BUZZER = 22 \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/motor-connections-test-interrupt.py b/src/kits/maker-pi-rp2040/motor-connections-test-interrupt.py deleted file mode 100644 index 5181529e5..000000000 --- a/src/kits/maker-pi-rp2040/motor-connections-test-interrupt.py +++ /dev/null @@ -1,51 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 30000 # 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN =10 -RIGHT_REVERSE_PIN =11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -print('Press CTRL-C to stop all motors.') - -try: - while True: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - print('Turning all motors off.') - stop() diff --git a/src/kits/maker-pi-rp2040/motor-connections-test.py b/src/kits/maker-pi-rp2040/motor-connections-test.py deleted file mode 100644 index bdbef28a3..000000000 --- a/src/kits/maker-pi-rp2040/motor-connections-test.py +++ /dev/null @@ -1,34 +0,0 @@ -from machine import Pin, PWM -import time - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/neopixel-button-lab.py b/src/kits/maker-pi-rp2040/neopixel-button-lab.py deleted file mode 100644 index 89e7c37ca..000000000 --- a/src/kits/maker-pi-rp2040/neopixel-button-lab.py +++ /dev/null @@ -1,93 +0,0 @@ -# press buttons to change the color of the NeoPixels -import utime -from machine import Pin -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 -BUTTON_A_PIN = 20 -BUTTON_B_PIN = 21 -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (125, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -white = (255, 255, 255) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) - -# color index into colors list -neopixel_a = 0 -neopixel_b = 0 -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_a = machine.Pin(BUTTON_A_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_b = machine.Pin(BUTTON_B_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time, num_colors, neopixel_a, neopixel_b - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - button_presses += 1 - if '20' in str(pin): - neopixel_a +=1 - if neopixel_a > num_colors - 1: - neopixel_a = 0 - else: - neopixel_b +=1 - if neopixel_b > num_colors - 1: - neopixel_b = 0 - last_time = new_time - -# now we register the handler function when the button is pressed -button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -print('Running NeoPixel Button Lab') -strip.set_pixel(0, (4,5,5)) -strip.set_pixel(1, (4,5,5)) -strip.show() - -def main(): - global button_presses, old_presses, colors, neopixel_a, neopixel_b - while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - print('NeoPixel A:', color_names[neopixel_a], 'index:', neopixel_a) - print('NeoPixel B:', color_names[neopixel_b], 'index:', neopixel_b) - strip.set_pixel(0, colors[neopixel_a]) - strip.set_pixel(1, colors[neopixel_b]) - strip.show() - old_presses = button_presses - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Turning off NeoPixels') - strip.set_pixel(0, (0,0,0)) - strip.set_pixel(1, (0,0,0)) - strip.show() diff --git a/src/kits/maker-pi-rp2040/neopixel-test.py b/src/kits/maker-pi-rp2040/neopixel-test.py deleted file mode 100644 index 2733c86d7..000000000 --- a/src/kits/maker-pi-rp2040/neopixel-test.py +++ /dev/null @@ -1,36 +0,0 @@ -import time -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -LED_PIN = 18 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -color_index = 0 -while True: - for color in colors: - for i in range(NUMBER_PIXELS): - print(i, color_names[color_index]) - strip.set_pixel(i, color) - strip.show() - time.sleep(1) - color_index += 1 - if color_index >= num_colors: color_index = 0 diff --git a/src/kits/maker-pi-rp2040/original-circuitpython-demo-code.py b/src/kits/maker-pi-rp2040/original-circuitpython-demo-code.py deleted file mode 100644 index 39b5fb131..000000000 --- a/src/kits/maker-pi-rp2040/original-circuitpython-demo-code.py +++ /dev/null @@ -1,205 +0,0 @@ -# ************************************************* -# Out-of-the-box Demo for Cytron Maker Pi RP2040 -# -# This demo code is written in CircuitPython and it serves -# as an easy quality check when you first receive the board. -# -# It plays a melody upon power up (slide power switch to ON) -# and shows running lights (blue LEDs) at the same time. -# Then the two RGB LEDs will animate the colors, while the -# program checking push buttons' state, repeatedly. -# -# Press GP20 button to play a short melody, lights up all -# blue LEDs, move servo motors to 0 degree and run DC motors -# at 50% and -50% speeds. -# Press GP21 button to play another melody, turn off all blue -# LEDs, move servo motors to 180 degree & brake DC motors. -# -# Maker Pi RP2040 also has four DC motors quick test buttons -# built-in. You may press the onboard M1A, M1B, M2A or M2B -# push buttons to run your motors without writing any code. -# -# More info: -# http://www.cytron.io/p-maker-pi-rp2040 -# https://circuitpython.org/board/raspberry_pi_pico -# -# Email: support@cytron.io -# ************************************************* -import board -import digitalio -import neopixel -import simpleio -import time -import pwmio -from adafruit_motor import servo, motor - -# Initialize LEDs -# LEDs placement on Maker Pi RP2040 -LED_PINS = [board.GP0, - board.GP1, - board.GP2, - board.GP3, - board.GP4, - board.GP5, - board.GP6, - board.GP7, - board.GP16, - board.GP17, - board.GP26, - board.GP27, - board.GP28] - -LEDS = [] -for pin in LED_PINS: - # Set pins as digital output - digout = digitalio.DigitalInOut(pin) - digout.direction = digitalio.Direction.OUTPUT - LEDS.append(digout) - -# Initialize Neopixel RGB LEDs -pixels = neopixel.NeoPixel(board.GP18, 2) -pixels.fill(0) - -# Melody -MELODY_NOTE = [659, 659, 0, 659, 0, 523, 659, 0, 784] -MELODY_DURATION = [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.2] - -# Define pin connected to piezo buzzer -PIEZO_PIN = board.GP22 - -# Initialize buttons -btn1 = digitalio.DigitalInOut(board.GP20) -btn2 = digitalio.DigitalInOut(board.GP21) -btn1.direction = digitalio.Direction.INPUT -btn2.direction = digitalio.Direction.INPUT -btn1.pull = digitalio.Pull.UP -btn2.pull = digitalio.Pull.UP - -# Initialize servos -# 50% duty cycle: 2**15 = 32768 = 1/2 of 65536 (16-bit) -servo_motors = [] # create an array and add servo objects. -servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP12, duty_cycle=2**15, frequency=50))) -servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP13, duty_cycle=2**15, frequency=50))) -servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP14, duty_cycle=2**15, frequency=50))) -servo_motors.append(servo.Servo(pwmio.PWMOut(board.GP15, duty_cycle=2**15, frequency=50))) - -# Initialize DC motors -m1a = pwmio.PWMOut(board.GP8, frequency=50) -m1b = pwmio.PWMOut(board.GP9, frequency=50) -motor1 = motor.DCMotor(m1a, m1b) -m2a = pwmio.PWMOut(board.GP10, frequency=50) -m2b = pwmio.PWMOut(board.GP11, frequency=50) -motor2 = motor.DCMotor(m2a, m2b) - -# ------------------------------------------------- -# ON START: Show running light and play melody -# ------------------------------------------------- -for i in range(len(LEDS)): - LEDS[i].value = True - - if i < len(MELODY_NOTE): - # Play melody tones - simpleio.tone(PIEZO_PIN, MELODY_NOTE[i], duration=MELODY_DURATION[i]) - else: - # Light up the remainding LEDs - time.sleep(0.15) - -# Turn off LEDs one-by-one very quickly -for i in range(len(LEDS)): - LEDS[i].value = False - time.sleep(0.02) - - -color = 0 -state = 0 - -# ------------------------------------------------- -# FOREVER LOOP: Check buttons & animate RGB LEDs -# ------------------------------------------------- -while True: - - # Check button 1 (GP20) - if not btn1.value: # button 1 pressed - # Light up all LEDs - for i in range(len(LEDS)): - LEDS[i].value = True - - # Move servos to 0 degree - for i in range(len(servo_motors)): - servo_motors[i].angle = 0 - - # Move motors at 50% speed - motor1.throttle = 0.5 # motor1.throttle = 1 or -1 for full speed - motor2.throttle = -0.5 - - # Play tones - simpleio.tone(PIEZO_PIN, 262, duration=0.1) - simpleio.tone(PIEZO_PIN, 659, duration=0.15) - simpleio.tone(PIEZO_PIN, 784, duration=0.2) - - # Check button 2 (GP21) - elif not btn2.value: # button 2 pressed - # Turn off all LEDs - for i in range(len(LEDS)): - LEDS[i].value = False - - # Move servos to 180 degree - for i in range(len(servo_motors)): - servo_motors[i].angle = 180 - - # Brake motors - motor1.throttle = 0 # motor1.throttle = None to spin freely - motor2.throttle = 0 - - # Play tones - simpleio.tone(PIEZO_PIN, 784, duration=0.1) - simpleio.tone(PIEZO_PIN, 659, duration=0.15) - simpleio.tone(PIEZO_PIN, 262, duration=0.2) - - - # Animate RGB LEDs - if state == 0: - if color < 0x101010: - color += 0x010101 # increase rgb colors to 0x10 each - else: - state += 1 - elif state == 1: - if (color & 0x00FF00) > 0: - color -= 0x000100 # decrease green to zero - else: - state += 1 - elif state == 2: - if (color & 0xFF0000) > 0: - color -= 0x010000 # decrease red to zero - else: - state += 1 - elif state == 3: - if (color & 0x00FF00) < 0x1000: - color += 0x000100 # increase green to 0x10 - else: - state += 1 - elif state == 4: - if (color & 0x0000FF) > 0: - color -= 1 # decrease blue to zero - else: - state += 1 - elif state == 5: - if (color & 0xFF0000) < 0x100000: - color += 0x010000 # increase red to 0x10 - else: - state += 1 - elif state == 6: - if (color & 0x00FF00) > 0: - color -= 0x000100 # decrease green to zero - else: - state += 1 - elif state == 7: - if (color & 0x00FFFF) < 0x001010: - color += 0x000101 # increase gb to 0x10 - else: - state = 1 - pixels.fill(color) # fill the color on both RGB LEDs - - - # Sleep to debounce buttons & change the speed of RGB color swipe - time.sleep(0.05) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/ping-sensor-demo.py b/src/kits/maker-pi-rp2040/ping-sensor-demo.py deleted file mode 100644 index da65d2137..000000000 --- a/src/kits/maker-pi-rp2040/ping-sensor-demo.py +++ /dev/null @@ -1,60 +0,0 @@ -# Sample MicroPython program to test a ultrasonic ping sensor using the Maker Pi RP2040 -# This is a polling (non interrupt) version of testing a Ultrasonic Ping sensor -# It is deliberately designed for beginning students to be able to understand -# See https://gist.githubusercontent.com/suadanwar/81ca2b83383310fa170a76bdf56771fb/raw/3ff9ae1cc226734c4d6db8756534fbe5df829c4a/UltrasonicPico.py - -from machine import Pin, PWM -import utime - -# We will pull the trigger down low for 2 microsends and then high for 10 microseconds -# then low to start measurement -Trig = Pin(27, Pin.OUT) -# we will look for a -Echo = Pin(26, Pin.IN, Pin.PULL_DOWN) - -Buzzer = PWM(Pin(18)) - -# returns the distance to a obstacle in cm -def CheckDistance(): - SpeedOfSoundInCM = 0.034 - - # begin the LOW/HIGH/LOW trigger output sequence - Trig.low() - utime.sleep_us(2) - Trig.high() - utime.sleep_us(10) - Trig.low() - exitLoop = False - loopcount = 0 #used as a failsafe if the signal doesn't return - # now we wait for the Echo pin to go high - while Echo.value() == 0 and exitLoop == False: - loopcount = loopcount + 1 - delaytime = utime.ticks_us() - # give up after 3,000 tries - if loopcount > 3000 : exitLoop == True - - # we now a high if we did not timeout - while Echo.value() == 1 and exitLoop == False: - loopcount = loopcount + 1 - receivetime = utime.ticks_us() - # give up after 3,000 tries - if loopcount > 3000 : exitLoop == True - - if exitLoop == True: #We failed somewhere - return 0 - else: - distance = ((receivetime – delaytime) * SpeedOfSoundInCM) / 2 - return distance - -while True: - # why do they call CheckDistance() 3 times and not reference the distance variable? - distance = CheckDistance() - print(distance) - # biz if we find something closer than 10 cm away - if distance < 10: - Buzzer.duty_u16(3000) - Buzzer.freq(1700) - utime.sleep(0.05) - Buzzer.duty_u16(0) - # sleep longer the further away the object is - utime.sleep(distance/1000) \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/play-mario.md b/src/kits/maker-pi-rp2040/play-mario.md deleted file mode 100644 index 9f5eb1456..000000000 --- a/src/kits/maker-pi-rp2040/play-mario.md +++ /dev/null @@ -1,70 +0,0 @@ -# Play Mario on MicroPython - -This program will play the theme music from the Mario video game. - -```python -from machine import Pin, PWM -from utime import sleep -buzzer = PWM(Pin(16)) - -tones = { -"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46, -"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65, -"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98, -"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139, -"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185, -"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311, -"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698, -"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661, -"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520, -"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978 -} - -song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"] -mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6", - 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", - 0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, - "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0] - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def playsong(mysong): - for i in range(len(mysong)): - if (mysong[i] == "P" or mysong[i] == 0 ): - bequiet() - else: - playtone(tones[mysong[i]]) - sleep(0.3) - bequiet() -playsong(mario) -``` - -## Turning off the Sound with an Interrupt -When you stop the program, a sound might still be playing on the RP2040 because the Stop function does not terminate all the PWM loops. You can fix this by putting the main loop in a function and adding a try/except/finally statement at the end of your program. - - -```py -def main(): - global loop_counter - while True: - playsong(mario) - loop_counter=loop_counter+1 - print(loop_counter) - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard interrupt -print('Press Control-C to Terminate') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - buzzer.duty_u16(0) -``` \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/servo-button-lab.py b/src/kits/maker-pi-rp2040/servo-button-lab.py deleted file mode 100644 index 39e2a8a45..000000000 --- a/src/kits/maker-pi-rp2040/servo-button-lab.py +++ /dev/null @@ -1,59 +0,0 @@ -# Maker Pi RP2040 program to check the limits of a 180 degree servo such as a SG90 micro servo -from machine import Pin, PWM -import time - -BUTTON_1_PIN = 20 # increment the angle -BUTTON_2_PIN = 21 # decrement the angle - -SERVO_1_PIN = 12 -SERVO_2_PIN = 13 # MAX=5749@40 -SERVO_3_PIN = 14 -SERVO_4_PIN = 15 -SERVO_MIN_DUTY = 1725 -SERVO_MAX_DUTY = 6378 -# this is ususlly standard across most servos -SERVO_FREQ_HZ = 40 - -pwm = PWM(Pin(SERVO_2_PIN)) - -# the two button on the Maker Pi RP2040 -increment_angle_button_pin = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -decrement_angle_button_pin = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This will take in integers of range in (min and max) return a integer in the output range (min and max) -# Used to convert one range of values into another using a linear function like the Arduino map() function -def convert(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min - -# globals -angle = -90 # change this to be 90 to test the other end -last_time = 0 # the last time we pressed the button - -# if the pin is 20 then increment, else decement -def button_pressed_handler(pin): - global angle, last_time - new_time = time.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - angle +=1 - else: - angle -=1 - last_time = new_time - # now we register the handler function when the button is pressed -increment_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -decrement_angle_button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -pwm.freq(SERVO_FREQ_HZ) -old_angle = -1 -print('Press the GP20 and GP21 buttons on the Maker Pi RP2040 to verify the -90 and 90 angles are correct.') -print('Adjust the SERVO_MIN_DUTY and SERVO_MAX_DUTY values accordingly.') -while True: - # only print on change in the button_presses value - if angle != old_angle: - duty = ServoDuty(angle) - print('new angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle - diff --git a/src/kits/maker-pi-rp2040/servo-sweep-lab.py b/src/kits/maker-pi-rp2040/servo-sweep-lab.py deleted file mode 100644 index 92c62d0b4..000000000 --- a/src/kits/maker-pi-rp2040/servo-sweep-lab.py +++ /dev/null @@ -1,44 +0,0 @@ -from machine import Pin, PWM -import time - -BUTTON_1_PIN = 20 -BUTTON_2_PIN = 21 - -SERVO_1_PIN = 12 -SERVO_2_PIN = 13 -SERVO_3_PIN = 14 -SERVO_4_PIN = 15 -SERVO_FREQ_HZ = 50 -SERVO_MIN_DUTY = 1500 -SERVO_MAX_DUTY = 7200 -# this is ususlly standard across most servos -SERVO_FREQ_HZ = 40 -DELAY = 0.05 # delay to give the servo time to moce -STEP = 5 # number of steps between angles - -pwm = PWM(Pin(SERVO_1_PIN)) - -# globals -angle = 0 - -# Thisw will take in integers of range in (min and max) return a integer in the output range (min and max) -# Used to convert one range of values into another using a linear function like the Arduino map() function -def convert(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min - -old_angle = -1 - -pwm.freq(50) -while True: - for angle in range(-90, 90, STEP): - duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY) - print('angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle - time.sleep(DELAY) - for angle in range(90, -90, -STEP): - duty = convert(angle, -90, 90, SERVO_MIN_DUTY, SERVO_MAX_DUTY) - print('angle:', angle, 'duty: ', duty) - pwm.duty_u16(duty) - old_angle = angle - time.sleep(DELAY) diff --git a/src/kits/maker-pi-rp2040/time-of-flight-lab.py b/src/kits/maker-pi-rp2040/time-of-flight-lab.py deleted file mode 100644 index 5904abd4e..000000000 --- a/src/kits/maker-pi-rp2040/time-of-flight-lab.py +++ /dev/null @@ -1,89 +0,0 @@ -# Demo for Maker Pi RP2040 board using the VL32L0X time of flight distance sensor -# Note the driver I used came from here: https://github.com/CoderDojoTC/micropython/blob/main/src/drivers/VL53L0X.py -# Perhaps derived from here: https://github.com/uceeatz/VL53L0X/blob/master/VL53L0X.py - -# This demo makes the blue LEDs show the distance and prints the distance on the console -import machine -import time -import VL53L0X - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs which we can use 11 -# The distance scale is non linear -# GP0 and GP1 will always be on since they are the I2C Data and Clock -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -dist_scale = [2, 6, 10, 20, 30, 40, 50, 60, 80, 110, 150] -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# initial calibration parameters -ZERO_DIST = 60 -MAX_DIST = 1200 # max raw distance we are able to read -SCALE_DIST = .3 # multiplier for raw to calibrated distance - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - - - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > MAX_DIST: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < ZERO_DIST: - zero_dist = tof_distance - return int((tof_distance - ZERO_DIST) * SCALE_DIST) - -# use the dist_scale to turn on LEDs -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -print('Using', number_leds, ' blue leds to show distance.') - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# start our time-of-flight sensor -tof.start() -# autocalibrate the minimum distance -min_distance = 1000 - - -# loop forever -while True: - raw_distance = get_distance() - # recalibrate if we have a new min distance - if raw_distance < min_distance: - min_distance = raw_distance - calibrated_distance = raw_distance - min_distance - print(raw_distance, calibrated_distance) - led_show_dist(calibrated_distance) - time.sleep(0.05) - -# clean up -tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/tof-distance-measure.py b/src/kits/maker-pi-rp2040/tof-distance-measure.py deleted file mode 100644 index 92622f16d..000000000 --- a/src/kits/maker-pi-rp2040/tof-distance-measure.py +++ /dev/null @@ -1,81 +0,0 @@ -# Demo for Maker Pi RP2040 board - -import machine -import time -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print("Device found at decimal", i2c.scan()) - -# The Maker Pi RP2040 has 13 fantastic blue GPIO status LEDs -blue_led_pins = [2, 3, 4, 5, 6, 7, 16, 17, 26, 27, 28] -# dist_scale = [2, 4, 6, 8, 10, 13, 16, 20, 25, 35, 50, 75, 100] -dist_scale = [2, 4, 6, 8, 10, 15, 20, 25, 50, 100, 150, 200, 300] - -number_leds = len(blue_led_pins) -led_ports = [] -delay = .05 - -# calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# create a list of the ports -for i in range(number_leds): - led_ports.append(machine.Pin(blue_led_pins[i], machine.Pin.OUT)) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -# blue up -for i in range(0, number_leds): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() -# blue down -for i in range(number_leds - 1, 0, -1): - led_ports[i].high() - time.sleep(delay) - led_ports[i].low() - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -def led_show_dist(in_distance): - global number_leds - for led_index in range(0, number_leds): - if in_distance > dist_scale[led_index]: - led_ports[led_index].high() - else: - led_ports[led_index].low() - -# start our time-of-flight sensor -tof.start() -valid_distance = 1 -# loop forever -while True: - distance = get_distance() - if distance > 1000: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - valid_distance = 0 - else: - print(distance) - valid_distance = 1 - led_show_dist(distance) - time.sleep(0.05) - -# clean up -tof.stop() \ No newline at end of file diff --git a/src/kits/maker-pi-rp2040/two-button-press.py b/src/kits/maker-pi-rp2040/two-button-press.py deleted file mode 100644 index 679374925..000000000 --- a/src/kits/maker-pi-rp2040/two-button-press.py +++ /dev/null @@ -1,40 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -faster_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN) -slower_pin = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # this should be pin.id but it does not work - if '20' in str(pin): - button_presses +=1 - else: - button_presses -=1 - last_time = new_time - - -# now we register the handler function when the button is pressed -faster_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -slower_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 - -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/kits/motor-direction-lab/main.py b/src/kits/motor-direction-lab/main.py deleted file mode 100644 index 30b1b3203..000000000 --- a/src/kits/motor-direction-lab/main.py +++ /dev/null @@ -1,73 +0,0 @@ -from machine import Pin, PWM, I2C -from lcd_api import LcdApi -from pico_i2c_lcd import I2cLcd -from time import sleep - -# pot init -POT_PIN_1 = 26 -adc = machine.ADC(POT_PIN_1) - -# Display init -SDA_PIN = 16 -SCL_PIN = 17 -I2C_ADDR = 0x27 -I2C_NUM_ROWS = 2 -I2C_NUM_COLS = 16 -i2c = I2C(0, sda=machine.Pin(SDA_PIN), scl=machine.Pin(SCL_PIN), freq=400000) -lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) - -# motor stuff -HALF_POT = 32768 -FORWARD_PIN = 9 -REVERSE_PIN = 8 -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -counter = 0 -scale = .25 # percent of total to give the motor for a demo that does not use too much battery power -def main(): - global counter, scale - while True: - pot_value = adc.read_u16() - print(pot_value, pot_value >> 6) - if pot_value > HALF_POT: - # forward - reverse.duty_u16(0) - power = pot_value - HALF_POT - scaled_power = int(power * scale) - print('forward:', scaled_power) - forward.duty_u16(scaled_power) - else: - forward.duty_u16(0) - power = HALF_POT - pot_value - scaled_power = int(power * scale) - reverse.duty_u16(scaled_power) - print('reverse:', scaled_power) - - # display code - lcd.clear() - lcd.move_to(0, 0) - lcd.putstr(str(pot_value >> 6)) - - lcd.move_to(8, 0) - lcd.putstr(str(power >> 6)) - - lcd.move_to(0, 1) - if pot_value > HALF_POT: - lcd.putstr('forward') - else: - lcd.putstr('reverse') - - sleep(.1) - counter += 1 - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/motor-dist-pot-display/display-banner-test.py b/src/kits/motor-dist-pot-display/display-banner-test.py deleted file mode 100644 index fa69de9ee..000000000 --- a/src/kits/motor-dist-pot-display/display-banner-test.py +++ /dev/null @@ -1,29 +0,0 @@ -from machine import Pin -import ssd1306 -import utime - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.fill(0) -oled.text("Dan McCreary", 0, 0, 1) -oled.text("MicroPython Robt", 0, 10, 1) -oled.text("264K RAM!", 0, 20, 1) -oled.text("128X64 OLED", 0, 28, 1) -oled.text("ssd1306 SPI", 0, 36, 1) -oled.text("$4 + $17 = $21", 0, 45, 1) -oled.text("Dan McCreary", 0, 54, 1) -oled.show() diff --git a/src/kits/motor-dist-pot-display/draw-tof-chart.py b/src/kits/motor-dist-pot-display/draw-tof-chart.py deleted file mode 100644 index 070b823c8..000000000 --- a/src/kits/motor-dist-pot-display/draw-tof-chart.py +++ /dev/null @@ -1,85 +0,0 @@ -from machine import Pin,PWM -import VL53L0X -from time import sleep -import ssd1306 -from neopixel import NeoPixel - -# OLED Display dimentions -HEIGHT = 64 -WIDTH = 128 -MAX_TOF_VALUE = 1200 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print('i2c:', i2c) - -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -x=0 -def update_display(distance): - global x - print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - oled.show() - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# a list of our prior distance measurements for graphing mode -distances=[] - -valid_distance = 0 -mode = 0 -# loop forever -def main(): - global mode, valid_distance - while True: - distance = get_distance() - if distance < MAX_TOF_VALUE: - update_display(distance) - sleep(.05) - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Chart Time of Flight') - -try: - main() -except KeyboardInterrupt: - print('Got interupt') -finally: - # Optional cleanup code - print('Powering down sound') - tof.stop() diff --git a/src/kits/motor-dist-pot-display/pot-motor-test.py b/src/kits/motor-dist-pot-display/pot-motor-test.py deleted file mode 100644 index 243ede6b9..000000000 --- a/src/kits/motor-dist-pot-display/pot-motor-test.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import Pin, PWM, ADC -from utime import sleep - -# lower right pins with USB on top -FORWARD_PIN = 19 -REVERSE_PIN = 18 - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -POWER_LEVEL = 65025 - -def main(): - while True: - pot_value = pot.read_u16() - print('pot val', pot_value) - forward.duty_u16(pot_value) - sleep(.1) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering motor now.') - forward.duty_u16(0) - reverse.duty_u16(0) diff --git a/src/kits/motor-dist-pot-display/pot-print.py b/src/kits/motor-dist-pot-display/pot-print.py deleted file mode 100644 index aee355cf4..000000000 --- a/src/kits/motor-dist-pot-display/pot-print.py +++ /dev/null @@ -1,22 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -def read_pot_u8(): - return pot.read_u16() >> 8 - -counter = 0 -while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - print(pot_value) - # print("pot_value:", delay) - high_bits = pot_value >> 9 - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/neopixel-jar/07-pot.py b/src/kits/neopixel-jar/07-pot.py deleted file mode 100644 index bc9756cc1..000000000 --- a/src/kits/neopixel-jar/07-pot.py +++ /dev/null @@ -1,8 +0,0 @@ -from machine import ADC -from utime import sleep -pot = ADC(26) -while True: - # shift the reading 8 bits to the right - val = pot.read_u16() >> 8 - print(val) - sleep(.2) \ No newline at end of file diff --git a/src/kits/neopixel-jar/11-candle.py b/src/kits/neopixel-jar/11-candle.py deleted file mode 100644 index d3a9f7a9f..000000000 --- a/src/kits/neopixel-jar/11-candle.py +++ /dev/null @@ -1,24 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep -from urandom import randint -# https://docs.micropython.org/en/latest/library/random.html - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def candle(delay): - for i in range(0, NUMBER_PIXELS): - red = 150 + randint(0,50) - green = 50 + randint(0,25) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -counter = 0 -while True: - candle(.001) - # wrap - counter = counter % (NUMBER_PIXELS-1) - counter += 1 \ No newline at end of file diff --git a/src/kits/neopixel-jar/13-pot-up-and-down.py b/src/kits/neopixel-jar/13-pot-up-and-down.py deleted file mode 100644 index e5ef594fd..000000000 --- a/src/kits/neopixel-jar/13-pot-up-and-down.py +++ /dev/null @@ -1,20 +0,0 @@ -from machine import ADC, Pin -from utime import sleep -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -pot = ADC(26) -while True: - # shift the reading 8 bits to the right to be 0 to 255 - val = pot.read_u16() >> 8 - pixel = round(NUMBER_PIXELS * (val/255)) - print(val, pixel) - for i in range(0, pixel): - strip[i] = (80, 25, 0) - for i in range(pixel, NUMBER_PIXELS): - strip[i] = (0, 0, 50) - strip.write() diff --git a/src/kits/neopixel-jar/14-pot-color-wheel.py b/src/kits/neopixel-jar/14-pot-color-wheel.py deleted file mode 100644 index 86715d698..000000000 --- a/src/kits/neopixel-jar/14-pot-color-wheel.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import ADC, Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -pot = ADC(26) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -while True: - val = pot.read_u16() >> 8 - for i in range(0, NUMBER_PIXELS): - color = wheel(val) - print(color) - strip[i] = color - strip.write() - diff --git a/src/kits/neopixel-jar/15-pot-candle.py b/src/kits/neopixel-jar/15-pot-candle.py deleted file mode 100644 index 1b043e097..000000000 --- a/src/kits/neopixel-jar/15-pot-candle.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin, ADC -from neopixel import NeoPixel -from utime import sleep -from urandom import randint -# https://docs.micropython.org/en/latest/library/random.html -pot = ADC(26) - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def candle(brightness, delay): - for i in range(0, NUMBER_PIXELS): - # we can't get any dimmer than this - if brightness < 4: - red = 1 - green = 0 - blue = 0 - # one step from the lowest setting - elif brightness < 8: - red = 2 + randint(0,2) - green = 1 - blue = 0 - # white hot candle on full bright mode - elif brightness >= 254: - red = 255 - green = 255 - blue = 255 - # somewhere in the middle with red being 4/5 of the color - else: - red = int(brightness * .9) + randint(0,int(brightness/5)) - # keep red from going over max of 255 - if red > 255: red = 255 - green = int(brightness/5) + randint(0,int(brightness/10)) - blue = 0 - print(brightness, red, green, blue) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, blue) - strip.write() - sleep(delay) - -while True: - val = pot.read_u16() >> 8 - candle(val, .001) \ No newline at end of file diff --git a/src/kits/neopixel-jar/21-two-buttons.py b/src/kits/neopixel-jar/21-two-buttons.py deleted file mode 100644 index 66d929cf5..000000000 --- a/src/kits/neopixel-jar/21-two-buttons.py +++ /dev/null @@ -1,46 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -BUTTON_PIN_1 = 17 -BUTTON_PIN_2 = 16 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - button_presses +=1 - else: - button_presses -=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/kits/neopixel/01-blink.py b/src/kits/neopixel/01-blink.py deleted file mode 100644 index 6379b90af..000000000 --- a/src/kits/neopixel/01-blink.py +++ /dev/null @@ -1,16 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - # brightness is a number from 0 of 255 - strip[0] = (25,0,0) # set first pixel to red - strip.write() # write to strip - sleep(.5) # wait 1/5 second - strip[0] = (0,0,0) # turn off first pixel - strip.write() - sleep(.5) # stay off 1/2 second diff --git a/src/kits/neopixel/02-heart-beat.py b/src/kits/neopixel/02-heart-beat.py deleted file mode 100644 index b23bac5a4..000000000 --- a/src/kits/neopixel/02-heart-beat.py +++ /dev/null @@ -1,16 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - # brightness is a number from 0 of 255 - strip[0] = (25,0,0) # set first pixel to red - strip.write() # write to strip - sleep(.1) # wait 1/10 second - strip[0] = (0,0,0) # turn off first pixel - strip.write() - sleep(1) # stay off 1 second diff --git a/src/kits/neopixel/03-neopixel-red-move-test.py b/src/kits/neopixel/03-neopixel-red-move-test.py deleted file mode 100644 index e47491f6a..000000000 --- a/src/kits/neopixel/03-neopixel-red-move-test.py +++ /dev/null @@ -1,15 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - # red is 10 of 255 - strip[i] = (10,0,0) - strip.write() - sleep(.05) - strip[i] = (0,0,0) diff --git a/src/kits/neopixel/03-rgb-blink.py b/src/kits/neopixel/03-rgb-blink.py deleted file mode 100644 index a2205a620..000000000 --- a/src/kits/neopixel/03-rgb-blink.py +++ /dev/null @@ -1,19 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - strip[0] = (25,0,0) # set first pixel to red - strip[1] = (0,25,0) # set first pixel to green - strip[2] = (0,0,25) # set first pixel to blue - strip.write() # write to strip - sleep(.5) # wait 1/10 second - strip[0] = (0,0,0) # turn off first pixel - strip[1] = (0,0,0) - strip[2] = (0,0,0) - strip.write() - sleep(.5) # stay off 1 second diff --git a/src/kits/neopixel/04-rainbow-cycle.py b/src/kits/neopixel/04-rainbow-cycle.py deleted file mode 100644 index 873e9d22f..000000000 --- a/src/kits/neopixel/04-rainbow-cycle.py +++ /dev/null @@ -1,39 +0,0 @@ -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(counter, .2) - counter += 1 diff --git a/src/kits/neopixel/04-rgb-cycle.py b/src/kits/neopixel/04-rgb-cycle.py deleted file mode 100644 index f62efab6a..000000000 --- a/src/kits/neopixel/04-rgb-cycle.py +++ /dev/null @@ -1,26 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - strip[0] = (25,0,0) # set first pixel to red - strip.write() # write to strip - sleep(.5) # wait 1/2 second - strip[0] = (0,0,0) # turn off first pixel - strip.write() - - strip[1] = (0,25,0) # set second pixel to green - strip.write() - sleep(.5) - strip[1] = (0,0,0) # turn off second pixel - strip.write() - - strip[2] = (0,0,25) # set first pixel to green - strip.write() - sleep(.5) - strip[2] = (0,0,0) # turn off first pixel - strip.write() diff --git a/src/kits/neopixel/05-color-wheel.py b/src/kits/neopixel/05-color-wheel.py deleted file mode 100644 index db3596c83..000000000 --- a/src/kits/neopixel/05-color-wheel.py +++ /dev/null @@ -1,29 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -while True: - for i in range(0, 256): - color = wheel(i) - strip[0] = color - strip.write() - sleep(.01) - diff --git a/src/kits/neopixel/06-static-rainbow.py b/src/kits/neopixel/06-static-rainbow.py deleted file mode 100644 index 32aaf72f5..000000000 --- a/src/kits/neopixel/06-static-rainbow.py +++ /dev/null @@ -1,40 +0,0 @@ -# static rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -while True: - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[i] = color - strip.write() - sleep(.1) # time between pixel draws - sleep(1) # time at the end of the rainbow draw - erase() diff --git a/src/kits/neopixel/07-rainbow-cycle.py b/src/kits/neopixel/07-rainbow-cycle.py deleted file mode 100644 index 6cf3f09d6..000000000 --- a/src/kits/neopixel/07-rainbow-cycle.py +++ /dev/null @@ -1,40 +0,0 @@ -# rainbow cycle -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(counter, .2) - counter += 1 diff --git a/src/kits/neopixel/08-mini-static-rainbow.py b/src/kits/neopixel/08-mini-static-rainbow.py deleted file mode 100644 index 394b93967..000000000 --- a/src/kits/neopixel/08-mini-static-rainbow.py +++ /dev/null @@ -1,41 +0,0 @@ -# mini static rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -RAINBOW_LENGTH = 7 -PERCENT_COLOR_WHEEL = round(255/RAINBOW_LENGTH) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -while True: - for i in range(0, RAINBOW_LENGTH): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[i] = color - strip.write() - sleep(.1) # time between pixel draws - sleep(1) # time at the end of the rainbow draw - erase() diff --git a/src/kits/neopixel/09-mini-static-rainbow-reverse.py b/src/kits/neopixel/09-mini-static-rainbow-reverse.py deleted file mode 100644 index 7e40937a8..000000000 --- a/src/kits/neopixel/09-mini-static-rainbow-reverse.py +++ /dev/null @@ -1,42 +0,0 @@ -# mini static rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -RAINBOW_LENGTH = 7 -PERCENT_COLOR_WHEEL = round(255/RAINBOW_LENGTH) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -while True: - for i in range(0, RAINBOW_LENGTH): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards - strip[RAINBOW_LENGTH-1 - i] = color - strip.write() - sleep(.1) - sleep(1) - erase() diff --git a/src/kits/neopixel/10-moving-rainbow.py b/src/kits/neopixel/10-moving-rainbow.py deleted file mode 100644 index ac8b1522c..000000000 --- a/src/kits/neopixel/10-moving-rainbow.py +++ /dev/null @@ -1,55 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -RAINBOW_LENGTH = 7 -PERCENT_COLOR_WHEEL = round(255/RAINBOW_LENGTH) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -counter = 0 -while True: - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - print('off:', counter-1) - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(.05) - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS diff --git a/src/kits/neopixel/20-button-press.py b/src/kits/neopixel/20-button-press.py deleted file mode 100644 index 4f7254b5c..000000000 --- a/src/kits/neopixel/20-button-press.py +++ /dev/null @@ -1,32 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/kits/neopixel/21-two-buttons.py b/src/kits/neopixel/21-two-buttons.py deleted file mode 100644 index 9b44d4603..000000000 --- a/src/kits/neopixel/21-two-buttons.py +++ /dev/null @@ -1,46 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - button_presses +=1 - else: - button_presses -=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/kits/ping-neopixel/hcsr04.py b/src/kits/ping-neopixel/hcsr04.py deleted file mode 100644 index d38aebd1c..000000000 --- a/src/kits/ping-neopixel/hcsr04.py +++ /dev/null @@ -1,82 +0,0 @@ -from machine import Pin, time_pulse_us -from utime import sleep_us - -__version__ = '0.2.1' -__author__ = 'Roberto Sánchez' -__license__ = "Apache License 2.0. https://www.apache.org/licenses/LICENSE-2.0" - -class HCSR04: - """ - Driver to use the untrasonic sensor HC-SR04. - The sensor range is between 2cm and 4m. - - The timeouts received listening to echo pin are converted to OSError('Out of range') - - """ - # echo_timeout_us is based in chip range limit (400cm) - def __init__(self, trigger_pin, echo_pin, echo_timeout_us=500*2*30): - """ - trigger_pin: Output pin to send pulses - echo_pin: Readonly pin to measure the distance. The pin should be protected with 1k resistor - echo_timeout_us: Timeout in microseconds to listen to echo pin. - By default is based in sensor limit range (4m) - """ - self.echo_timeout_us = echo_timeout_us - # Init trigger pin (out) - self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None) - self.trigger.value(0) - - # Init echo pin (in) - self.echo = Pin(echo_pin, mode=Pin.IN, pull=None) - - def _send_pulse_and_wait(self): - """ - Send the pulse to trigger and listen on echo pin. - We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received. - """ - self.trigger.value(0) # Stabilize the sensor - sleep_us(5) - self.trigger.value(1) - # Send a 10us pulse. - sleep_us(10) - self.trigger.value(0) - try: - pulse_time = time_pulse_us(self.echo, 1, self.echo_timeout_us) - # time_pulse_us returns -2 if there was timeout waiting for condition; and -1 if there was timeout during the main measurement. It DOES NOT raise an exception - # ...as of MicroPython 1.17: http://docs.micropython.org/en/v1.17/library/machine.html#machine.time_pulse_us - if pulse_time < 0: - MAX_RANGE_IN_CM = const(500) # it's really ~400 but I've read people say they see it working up to ~460 - pulse_time = int(MAX_RANGE_IN_CM * 29.1) # 1cm each 29.1us - return pulse_time - except OSError as ex: - if ex.args[0] == 110: # 110 = ETIMEDOUT - raise OSError('Out of range') - raise ex - - def distance_mm(self): - """ - Get the distance in milimeters without floating point operations. - """ - pulse_time = self._send_pulse_and_wait() - - # To calculate the distance we get the pulse_time and divide it by 2 - # (the pulse walk the distance twice) and by 29.1 becasue - # the sound speed on air (343.2 m/s), that It's equivalent to - # 0.34320 mm/us that is 1mm each 2.91us - # pulse_time // 2 // 2.91 -> pulse_time // 5.82 -> pulse_time * 100 // 582 - mm = pulse_time * 100 // 582 - return mm - - def distance_cm(self): - """ - Get the distance in centimeters with floating point operations. - It returns a float - """ - pulse_time = self._send_pulse_and_wait() - - # To calculate the distance we get the pulse_time and divide it by 2 - # (the pulse walk the distance twice) and by 29.1 becasue - # the sound speed on air (343.2 m/s), that It's equivalent to - # 0.034320 cm/us that is 1cm each 29.1us - cms = (pulse_time / 2) / 29.1 - return cms \ No newline at end of file diff --git a/src/kits/ping-neopixel/main.py b/src/kits/ping-neopixel/main.py deleted file mode 100644 index 0b1396891..000000000 --- a/src/kits/ping-neopixel/main.py +++ /dev/null @@ -1,51 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -from hcsr04 import HCSR04 - -from utime import sleep, sleep_us, ticks_us -from neopixel import NeoPixel - -NUMBER_PIXELS = 12 -LED_PIN = 0 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -onboard_led = Pin(25, Pin.OUT) - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -MAX_DIST = 50 - -sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN) - -# Will return a integer -def map(x, in_min, in_max, out_min, out_max): - numerator = (x - in_min) * (out_max - out_min) - denom = (in_max - in_min) + out_min - if denom == 0: - denom = .001 - return int(numerator // denom) - -min = MAX_DIST -max = 0 -sleep(.1) - -while True: - dist = sensor.distance_cm() - if dist > MAX_DIST: - dist = MAX_DIST; - if dist > max: - max = dist - if dist < min: - min = dist - print("min: ", min, " max: ", max) - index = map(dist, min, max, 0, 11) - print("Distance:", round(dist, 2), "cm", " index:", index) - strip[index] = (255,0,255) - strip.write() - sleep(.1) - onboard_led.toggle() - strip[index] = (0,0,0) diff --git a/src/kits/ping-neopixel/ping-neopixel.py b/src/kits/ping-neopixel/ping-neopixel.py deleted file mode 100644 index 0b1396891..000000000 --- a/src/kits/ping-neopixel/ping-neopixel.py +++ /dev/null @@ -1,51 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -from hcsr04 import HCSR04 - -from utime import sleep, sleep_us, ticks_us -from neopixel import NeoPixel - -NUMBER_PIXELS = 12 -LED_PIN = 0 -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -onboard_led = Pin(25, Pin.OUT) - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -MAX_DIST = 50 - -sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN) - -# Will return a integer -def map(x, in_min, in_max, out_min, out_max): - numerator = (x - in_min) * (out_max - out_min) - denom = (in_max - in_min) + out_min - if denom == 0: - denom = .001 - return int(numerator // denom) - -min = MAX_DIST -max = 0 -sleep(.1) - -while True: - dist = sensor.distance_cm() - if dist > MAX_DIST: - dist = MAX_DIST; - if dist > max: - max = dist - if dist < min: - min = dist - print("min: ", min, " max: ", max) - index = map(dist, min, max, 0, 11) - print("Distance:", round(dist, 2), "cm", " index:", index) - strip[index] = (255,0,255) - strip.write() - sleep(.1) - onboard_led.toggle() - strip[index] = (0,0,0) diff --git a/src/kits/ping-neopixel/ping-print.py b/src/kits/ping-neopixel/ping-print.py deleted file mode 100644 index b7618184e..000000000 --- a/src/kits/ping-neopixel/ping-print.py +++ /dev/null @@ -1,17 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -from utime import sleep, sleep_us, ticks_us -from hcsr04 import HCSR04 - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -sensor = HCSR04(trigger_pin=TRIGGER_PIN, echo_pin=ECHO_PIN) - - -while True: - print("Distance:", sensor.distance_cm(), "cm") - sleep(.1) diff --git a/src/kits/pot-display/01-blink-led.py b/src/kits/pot-display/01-blink-led.py deleted file mode 100644 index 429bf4c1a..000000000 --- a/src/kits/pot-display/01-blink-led.py +++ /dev/null @@ -1,9 +0,0 @@ -from machine import Pin, Timer - -led = Pin("LED", Pin.OUT) -tim = Timer() -def tick(timer): - global led - led.toggle() - -tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick) \ No newline at end of file diff --git a/src/kits/pot-display/05-display-hello-world.py b/src/kits/pot-display/05-display-hello-world.py deleted file mode 100644 index a7973f84c..000000000 --- a/src/kits/pot-display/05-display-hello-world.py +++ /dev/null @@ -1,28 +0,0 @@ -# Display Test -# Pin order GND, VCC, Clock, Data, Reset, DC, CS -from machine import Pin -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -counter = 0 -while True: - display.fill(0) - display.text('Hello World!', 0, 0) - display.text(str(counter), 0, 10) - display.show() - sleep(.5) - counter += 1 - diff --git a/src/kits/pot-display/07-display-bar.py b/src/kits/pot-display/07-display-bar.py deleted file mode 100644 index f1ded6d70..000000000 --- a/src/kits/pot-display/07-display-bar.py +++ /dev/null @@ -1,86 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico W -led = Pin('LED', Pin.OUT) - -FORWARD_PIN = 18 -REVERSE_PIN = 19 - -MAX_POWER = 65025 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) -# these are often not needed -forward.freq(50) # 50 hertz -reverse.freq(50) # 50 hertz - -# turn both motors off -forward.duty_u16(0) -reverse.duty_u16(0) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -# global variables - -# how often to read the pot and update the display 20 times per second -delay = .05 - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def update_display(counter, pot_value, high_bits): - oled.fill(0) - oled.text('CoderDojo PotLab', 0, 0) - oled.fill_rect(0, 10, high_bits, 20, 1) - - oled.text('ADC Value:', 0, 35) - oled.text(str(pot_value), 80, 35) - - oled.text('Display Val:', 0, 45) - oled.text(str(high_bits), 95, 45) - - oled.text('Counter:', 0, 54) - oled.text(str(counter), 65, 54) - oled.show() - -counter = 0 -def main(): - global counter - while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - forward.duty_u16(pot_value) - print("pot_value:", delay) - high_bits = pot_value >> 9 - # print("delay:", high_bits) - update_display(counter, pot_value, high_bits) - led.toggle() - sleep(delay) - counter += 1 - -# brief startup test -# forward.duty_u16(MAX_POWER) -# sleep(1) -# forward.duty_u16(0) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/kits/pot-display/main.py b/src/kits/pot-display/main.py deleted file mode 100644 index 5248acef5..000000000 --- a/src/kits/pot-display/main.py +++ /dev/null @@ -1,41 +0,0 @@ -# Display Test -# Pin order GND, VCC, Clock, Data, Reset, DC, CS -from machine import Pin, ADC -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -display.fill(0) -display.text('running', 0, 10) -display.show() -sleep(.5) -display.fill(0) -display.show() - -pot = ADC(26) - -x=0 -while True: - # just get the top 6 bits 0-63 - pot_val = pot.read_u16() >> 10 - y = HEIGHT - pot_val - 1 - print(x,y) - display.pixel(x, y, 1) - display.show() - if x > WIDTH - 3: - display.scroll(-1, 0) - # print('scrolling') - else: - x += 1 - sleep(.1) \ No newline at end of file diff --git a/src/kits/pwm-display/01-blink.py b/src/kits/pwm-display/01-blink.py deleted file mode 100644 index cf8a31ea2..000000000 --- a/src/kits/pwm-display/01-blink.py +++ /dev/null @@ -1,6 +0,0 @@ -from machine import Pin -from time import sleep -led_onboard = Pin(25, Pin.OUT) -while True: - led_onboard.toggle() - sleep(.25) \ No newline at end of file diff --git a/src/kits/pwm-display/01-pot-print.py b/src/kits/pwm-display/01-pot-print.py deleted file mode 100644 index 2647365a7..000000000 --- a/src/kits/pwm-display/01-pot-print.py +++ /dev/null @@ -1,7 +0,0 @@ -from machine import Pin, ADC -from utime import sleep -POT_PIN = ADC(26) - -while True: - print(POT_PIN.read_u16()) - sleep(.1) \ No newline at end of file diff --git a/src/kits/pwm-display/02-external-blink.py b/src/kits/pwm-display/02-external-blink.py deleted file mode 100644 index 55b224c10..000000000 --- a/src/kits/pwm-display/02-external-blink.py +++ /dev/null @@ -1,6 +0,0 @@ -from machine import Pin -from time import sleep -led_onboard = Pin(16, Pin.OUT) -while True: - led_onboard.toggle() - sleep(.25) \ No newline at end of file diff --git a/src/kits/pwm-display/03-display-pot-bar.py b/src/kits/pwm-display/03-display-pot-bar.py deleted file mode 100644 index 551d1772b..000000000 --- a/src/kits/pwm-display/03-display-pot-bar.py +++ /dev/null @@ -1,54 +0,0 @@ -# Display a PWM waveform on a 128x64 OLED Display - -from machine import Pin, ADC, SPI -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT // 2 -clock=Pin(2) -data=Pin(3) -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -spi=SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -POT_PIN = ADC(26) -POT_MAX = 65536 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, yPos, barHeight): - oled.fill_rect(0, yPos, inval, barHeight, 1) # fill with 1s - -def update_display(xPos): - oled.fill(0) - oled.text('Display Pot', 0, 0) - # draw a hbar at the top yPos, height - draw_hbar(xPos, 10, 2) - oled.text("X Pos: " + str(xPos), 0, 56) - oled.show() - -counter = 0 -# repeat forever -while True: - potVal = int(POT_PIN.read_u16()) - xPos = map(potVal, 0, POT_MAX, 0, WIDTH) - update_display(xPos) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/pwm-display/03-external-led-fader.py b/src/kits/pwm-display/03-external-led-fader.py deleted file mode 100644 index 2c36c3e87..000000000 --- a/src/kits/pwm-display/03-external-led-fader.py +++ /dev/null @@ -1,14 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -pwm = PWM(Pin(16)) - -pwm.freq(1000) - -while True: - for duty in range(65025): - pwm.duty_u16(duty) - sleep(0.0001) - for duty in range(65025, 0, -1): - pwm.duty_u16(duty) - sleep(0.0001) diff --git a/src/kits/pwm-display/05-pot-led-dimmer.py b/src/kits/pwm-display/05-pot-led-dimmer.py deleted file mode 100644 index 914c3e27c..000000000 --- a/src/kits/pwm-display/05-pot-led-dimmer.py +++ /dev/null @@ -1,18 +0,0 @@ -from machine import ADC, Pin, PWM -from time import sleep - -EXTERNAL_LED_PIN = 18 -ADC_PIN = 26 - -POT_PIN = ADC(ADC_PIN) -pwm = PWM(Pin(EXTERNAL_LED_PIN)) - -pwm.freq(50) - -while True: - potVal = POT_PIN.read_u16() - pwm.duty_u16(potVal) - sleep(0.01) - - - diff --git a/src/kits/pwm-display/10-display-pwm-fade-led.py b/src/kits/pwm-display/10-display-pwm-fade-led.py deleted file mode 100644 index 6ddecacf1..000000000 --- a/src/kits/pwm-display/10-display-pwm-fade-led.py +++ /dev/null @@ -1,86 +0,0 @@ -# Display a PWM waveform on a 128x64 OLED Display - -from machine import ADC, Pin, PWM -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) -EXTERNAL_LED_PIN = 18 -pwm = PWM(Pin(EXTERNAL_LED_PIN)) -# 50% duty cycle -pwm.freq(50) - -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT // 2 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -POT_PIN = machine.ADC(26) -POT_MAX = 65536 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, yPos, barHeight): - oled.fill_rect(0, yPos, inval, barHeight, 1) # fill with 1s - -# draw a square wave -def draw_pulse_wave(dutyCycle, yOffset): - pulses = 5 - square_wave_height = 20 - sq_wave_period = WIDTH // pulses - high_length = int(dutyCycle * sq_wave_period / 100) - # half the square wave period - hswp = sq_wave_period // 2 - - - for i in range(0,pulses+1): - # top bar - oled.hline(i*sq_wave_period, yOffset-square_wave_height, high_length, 1) - # down line - oled.vline(i*sq_wave_period + high_length, yOffset-square_wave_height, square_wave_height, 1) - # up line - oled.vline(i*sq_wave_period + yOffset-square_wave_height-2, yOffset-square_wave_height+1, square_wave_height, 1) - # bottem bar - oled.hline(i*sq_wave_period - (sq_wave_period - high_length), yOffset, sq_wave_period-high_length, 1) - - # oled.text(str(high_length), 64, 56) - -def update_display(counter, xPos, dutyCycle): - oled.fill(0) - oled.text('Pulse Width Modu', 0, 0) - # draw a hbar at the top yPos, height - draw_hbar(xPos, 10, 2) - draw_pulse_wave(dutyCycle, HALF_HEIGHT+15) - # oled.hline(0, HALF_HEIGHT+15, WIDTH, 1) - oled.text("Duty Cycle: " + str(round(dutyCycle)), 0, 56) - oled.show() - -counter = 0 -# repeat forever -while True: - potVal = POT_PIN.read_u16() - # set the duty cycle on the LED for brightness - pwm.duty_u16(potVal) - xPos = map(potVal, 0, POT_MAX, 0, WIDTH) - # duty cycle is a float - dutyCycle = int(xPos / WIDTH * 100) - update_display(counter, xPos, dutyCycle) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/pwm-display/display-pot-bar.py b/src/kits/pwm-display/display-pot-bar.py deleted file mode 100644 index 551d1772b..000000000 --- a/src/kits/pwm-display/display-pot-bar.py +++ /dev/null @@ -1,54 +0,0 @@ -# Display a PWM waveform on a 128x64 OLED Display - -from machine import Pin, ADC, SPI -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT // 2 -clock=Pin(2) -data=Pin(3) -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -spi=SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -POT_PIN = ADC(26) -POT_MAX = 65536 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, yPos, barHeight): - oled.fill_rect(0, yPos, inval, barHeight, 1) # fill with 1s - -def update_display(xPos): - oled.fill(0) - oled.text('Display Pot', 0, 0) - # draw a hbar at the top yPos, height - draw_hbar(xPos, 10, 2) - oled.text("X Pos: " + str(xPos), 0, 56) - oled.show() - -counter = 0 -# repeat forever -while True: - potVal = int(POT_PIN.read_u16()) - xPos = map(potVal, 0, POT_MAX, 0, WIDTH) - update_display(xPos) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/pwm-display/display-pwm.py b/src/kits/pwm-display/display-pwm.py deleted file mode 100644 index f7e3498b7..000000000 --- a/src/kits/pwm-display/display-pwm.py +++ /dev/null @@ -1,80 +0,0 @@ -# Display a PWM waveform on a 128x64 OLED Display - -from machine import Pin, ADC, SPI -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT // 2 -clock=Pin(2) -data=Pin(3) -RES = Pin(4) -DC = Pin(5) -CS = Pin(6) - -spi=SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -POT_PIN = ADC(26) -POT_MAX = 65536 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, yPos, barHeight): - oled.fill_rect(0, yPos, inval, barHeight, 1) # fill with 1s - -# draw a square wave -def draw_pulse_wave(dutyCycle, yOffset): - pulses = 5 - square_wave_height = 20 - sq_wave_period = WIDTH // pulses - high_length = int(dutyCycle * sq_wave_period / 100) - # half the square wave period - hswp = sq_wave_period // 2 - - - for i in range(0,pulses+1): - # top bar - oled.hline(i*sq_wave_period, yOffset-square_wave_height, high_length, 1) - # down line - oled.vline(i*sq_wave_period + high_length, yOffset-square_wave_height, square_wave_height, 1) - # up line - oled.vline(i*sq_wave_period + yOffset-square_wave_height-2, yOffset-square_wave_height+1, square_wave_height, 1) - # bottem bar - oled.hline(i*sq_wave_period - (sq_wave_period - high_length), yOffset, sq_wave_period-high_length, 1) - - # oled.text(str(high_length), 64, 56) - -def update_display(counter, xPos, dutyCycle): - oled.fill(0) - oled.text('Pulse Width Modu', 0, 0) - # draw a hbar at the top yPos, height - draw_hbar(xPos, 10, 2) - draw_pulse_wave(dutyCycle, HALF_HEIGHT+15) - # oled.hline(0, HALF_HEIGHT+15, WIDTH, 1) - oled.text("Duty Cycle: " + str(round(dutyCycle)), 0, 56) - oled.show() - -counter = 0 -# repeat forever -while True: - potVal = int(POT_PIN.read_u16()) - xPos = map(potVal, 0, POT_MAX, 0, WIDTH) - # duty cycle is a float - dutyCycle = int(xPos / WIDTH * 100) - update_display(counter, xPos, dutyCycle) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/pwm-display/display-test-47.py b/src/kits/pwm-display/display-test-47.py deleted file mode 100644 index b5cc88c9d..000000000 --- a/src/kits/pwm-display/display-test-47.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -WIDTH = 128 -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(counter): - oled.fill(0) - oled.text('Running', 0, 0) - oled.text("Dan McCreary's", 0, 10) - oled.text('Robot Lab 47', 0, 20) - oled.text(str(counter), 0, 30) - oled.show() - -counter = 0 -# repeat forever -while True: - update_display(counter) - led.toggle() - sleep(.5) - counter += 1 \ No newline at end of file diff --git a/src/kits/pwm-display/main.py b/src/kits/pwm-display/main.py deleted file mode 100644 index 6ddecacf1..000000000 --- a/src/kits/pwm-display/main.py +++ /dev/null @@ -1,86 +0,0 @@ -# Display a PWM waveform on a 128x64 OLED Display - -from machine import ADC, Pin, PWM -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) -EXTERNAL_LED_PIN = 18 -pwm = PWM(Pin(EXTERNAL_LED_PIN)) -# 50% duty cycle -pwm.freq(50) - -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT // 2 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -POT_PIN = machine.ADC(26) -POT_MAX = 65536 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, yPos, barHeight): - oled.fill_rect(0, yPos, inval, barHeight, 1) # fill with 1s - -# draw a square wave -def draw_pulse_wave(dutyCycle, yOffset): - pulses = 5 - square_wave_height = 20 - sq_wave_period = WIDTH // pulses - high_length = int(dutyCycle * sq_wave_period / 100) - # half the square wave period - hswp = sq_wave_period // 2 - - - for i in range(0,pulses+1): - # top bar - oled.hline(i*sq_wave_period, yOffset-square_wave_height, high_length, 1) - # down line - oled.vline(i*sq_wave_period + high_length, yOffset-square_wave_height, square_wave_height, 1) - # up line - oled.vline(i*sq_wave_period + yOffset-square_wave_height-2, yOffset-square_wave_height+1, square_wave_height, 1) - # bottem bar - oled.hline(i*sq_wave_period - (sq_wave_period - high_length), yOffset, sq_wave_period-high_length, 1) - - # oled.text(str(high_length), 64, 56) - -def update_display(counter, xPos, dutyCycle): - oled.fill(0) - oled.text('Pulse Width Modu', 0, 0) - # draw a hbar at the top yPos, height - draw_hbar(xPos, 10, 2) - draw_pulse_wave(dutyCycle, HALF_HEIGHT+15) - # oled.hline(0, HALF_HEIGHT+15, WIDTH, 1) - oled.text("Duty Cycle: " + str(round(dutyCycle)), 0, 56) - oled.show() - -counter = 0 -# repeat forever -while True: - potVal = POT_PIN.read_u16() - # set the duty cycle on the LED for brightness - pwm.duty_u16(potVal) - xPos = map(potVal, 0, POT_MAX, 0, WIDTH) - # duty cycle is a float - dutyCycle = int(xPos / WIDTH * 100) - update_display(counter, xPos, dutyCycle) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/rfid-rc522/lib/01-print-board-stats.py b/src/kits/rfid-rc522/lib/01-print-board-stats.py deleted file mode 100644 index 90e4b7b76..000000000 --- a/src/kits/rfid-rc522/lib/01-print-board-stats.py +++ /dev/null @@ -1,5 +0,0 @@ -from os import uname - -board = uname()[0] - -print('Board Name:', board) \ No newline at end of file diff --git a/src/kits/rfid-rc522/lib/RfidAccess.py b/src/kits/rfid-rc522/lib/RfidAccess.py deleted file mode 100644 index 43eddce65..000000000 --- a/src/kits/rfid-rc522/lib/RfidAccess.py +++ /dev/null @@ -1,213 +0,0 @@ -class RfidAccess: - NEVER = 0 - KEYA = 1 - KEYB = 2 - KEYAB = 3 - ALLBLOCK = -1 - - def __init__(self): - self.C1 = 0 - self.C2 = 0 - self.C3 = 8 - self.C1_Inv = 15 - self.C2_Inv = 15 - self.C3_Inv = 7 - self.Valid=False - - def findAccessIndex(self,table,mask,accessbits): - for i in range(8): - if table[i] == accessbits: - if (i & 1) == 0 : - self.C2 = self.C2 & ~mask - else: - self.C2 = self.C2 | mask - - if (i & 2) == 0 : - self.C1 = self.C1 & ~mask - else: - self.C1 = self.C1 | mask - - if (i & 4) == 0: - self.C3 = self.C3 & ~mask - else: - self.C3 = self.C3 | mask - - self.C1_Inv = self.C1 ^ 0xf - self.C2_Inv = self.C2 ^ 0xf - self.C3_Inv = self.C3 ^ 0xf - return True - return False - - - - - - def setTrailerAccess(self,keyA_Write=KEYA, access_Read=KEYA,access_Write=KEYA,keyB_Read=KEYA,keyB_Write=KEYA): - #C1 weight 2 , C2 weight 1 , C3 weight 4 - - # Key A Wr Access R Access W KeyB R KEYB W - access_Index = ( (self.KEYA, self.KEYA, self.NEVER, self.KEYA,self.KEYA), - (self.NEVER,self.KEYA,self.NEVER,self.KEYA,self.NEVER), - (self.KEYB, self.KEYAB,self.NEVER,self.NEVER,self.NEVER), - (self.NEVER,self.KEYAB,self.NEVER,self.NEVER,self.NEVER), - (self.KEYA,self.KEYA,self.KEYA,self.KEYA,self.KEYA), - (self.KEYB,self.KEYAB,self.KEYB,self.NEVER,self.KEYB), - (self.NEVER,self.KEYAB,self.KEYB,self.NEVER,self.NEVER), - (self.NEVER,self.KEYAB,self.NEVER,self.NEVER,self.NEVER)) - if self.findAccessIndex(access_Index,8, (keyA_Write,access_Read,access_Write,keyB_Read,keyB_Write)): - return True - else: - print("Access Trailer method not possible") - return False - - - def setBlockAccess(self, blockID, access_Read=KEYAB, access_Write=KEYAB, access_Inc=KEYAB, access_Dec=KEYAB): - # C1 weight 2 , C2 weight 1 , C3 weight 4 - # Key Read Key Write INCREment decrement/transfer/etc - access_Blk_idx=((self.KEYAB, self.KEYAB, self.KEYAB, self.KEYAB,None), - (self.KEYAB, self.NEVER, self.NEVER, self.NEVER,None), - (self.KEYAB, self.KEYB, self.NEVER, self.NEVER,None), - (self.KEYAB, self.KEYB, self.KEYB, self.KEYAB,None), - (self.KEYAB, self.NEVER, self.NEVER, self.KEYAB,None), - (self.KEYB, self.KEYB, self.NEVER, self.NEVER,None), - (self.KEYB, self.NEVER, self.NEVER, self.NEVER,None), - (self.NEVER, self.NEVER, self.NEVER, self.NEVER,None)) - - if(blockID == self.ALLBLOCK): - Mask = 7 - elif (BlockID<0) or (blockID >3): - return false - else: - Mask = 1 << blockID - - if self.findAccessIndex(access_Blk_idx,Mask,( access_Read, access_Write, access_Inc, access_Dec, None)): - return True - else: - print("**** Error Access Block method not possible") - return False - - - def encodeAccess(self): - self.C1 = self.C1 & 0xf - self.C2 = self.C2 & 0xf - self.C3 = self.C3 & 0xf - self.C1_INV = self.C1 ^ 0xf - self.C2_INV = self.C2 ^ 0xf - self.C3_INV = self.C3 ^ 0xf - byte6 = self.C2_INV << 4 | self.C1_INV - byte7 = self.C1 << 4 | self.C3_INV - byte8 = self.C3 << 4 | self.C2 - return (byte6, byte7, byte8) - - - def decodeAccess(self, byte6,byte7,byte8): - self.C1_Inv = byte6 & 0xf - self.C2_Inv = (byte6 & 0xf0) >> 4 - self.C3_Inv = byte7 & 0xf - self.C1 = (byte7 & 0xf0) >> 4 - self.C2 = byte8 & 0xf - self.C3 = (byte8 & 0xf0) >>4 - return ((self.C1 ^ self.C1_Inv) & (self.C2 ^ self.C2_Inv) & (self.C3 ^ self.C3_Inv)) & 0xf == 0xf - - def decodeAccessFromBlock3(self, block3): - if len(block3)!= 16: - return False - return self.decodeAccess(block3[6],block3[7],block3[8]) - - - def showTrailerAccess(self): - KeyAWrite = ['key A', 'never', 'key B', 'never', 'key A', 'key B', 'never', 'never'] - AccessRead = ['key A', 'key A', 'key A|B', 'key A|B', 'key A','key A|B','key A|B','key A|B' ] - AccessWrite = ['never', 'never', 'never', 'never', 'key A', 'key B', 'key B', 'never'] - KeyBRead = ['key A data R/W', 'key A data R', 'never', 'never', 'key A data R/W', 'never', 'never', 'never'] - KeyBWrite = ['key A data R/W', 'never', 'key B', 'never', 'key A data R/W', 'key B', 'never', 'never'] - - index = 0 - - if self.C2 & 0x8 > 0: - index = 1 - if self.C1 & 0x8 > 0: - index = index + 2 - if self.C3 & 0x8 > 0: - index = index + 4 - - - #print("TrailerAccess idx=",index) - print('Access key A read => never') - print('Access key A write =>', KeyAWrite[index]) - print('Access key B read =>', KeyBRead[index]) - print('Access key B write =>', KeyBWrite[index]) - print('Access bits read =>', AccessRead[index]) - print('Access bits write =>', AccessWrite[index]) - - - def showBlockAccess(self,blockID): - BlockRead = ['key A|B','key A|B','key A|B','key A|B','key A|B','key B', 'key B', 'never' ] - BlockWrite = ['key A|B', 'never', 'key B', 'key B', 'never', 'key B','never', 'never'] - BlockIncrement = ['key A|B', 'never', 'never', 'key B', 'never', 'never', 'never', 'never'] - BlockDecrement = ['key A|B', 'never', 'never', 'key A|B', 'key A|B', 'never', 'never', 'never'] - if blockID == 3: - self.showTrailerAccess() - else: - mask = 1 << blockID - index = 0 - if (self.C2 & mask) > 0: - index =1 - if (self.C1 & mask) > 0: - index = index + 2 - if (self.C3 & mask) > 0: - index = index + 4 - - print("Block ", blockID, " read =>", BlockRead[index]) - print("Block ", blockID, " write =>", BlockWrite[index]) - print("Block ", blockID, " Increment =>", BlockIncrement[index]) - print("Block ", blockID, " Decrement+ =>", BlockDecrement[index]) - - def showAccess(self): - print("/--------- SHOW ACCESS ---------\\") - AccessB = self.encodeAccess() - print('Access Bytes (6,7,8)= (',hex(AccessB[0]),', ',hex(AccessB[1]),', ',hex(AccessB[2]),')') - print('(C1, C2, C3) = (',hex(self.C1),', ',hex(self.C2),', ',hex(self.C3),')') - for i in range(4): - self.showBlockAccess(i) - print("\\---------------------------------/") - - - def fillBlock3(self,keyA=None,keyB=None,block=None): - if block is None: - block = 16*[0xff] - if len(block) != 16: - block = 16*[0xff] - - if keyA is not None: - if len(keyA) == 6 : - block[0:6]=keyA - - if keyB is not None: - if len(keyB) == 6 : - block[10:16]=keyB - b6, b7, b8 = self.encodeAccess() - block[6]=b6 - block[7]=b7 - block[8]=b8 - return block - - - -if __name__ == "__main__": - rfid = RfidAccess() - - - print("\nEx: Decode access_bits for [0xff, 0x07, 0x80]") - if rfid.decodeAccess(0xFF,0x07,0x80): - rfid.showAccess() - else: - print('Invalid Access') - - print("\n\nSet block 0 to 3 to be read by KEYA but R/W with KEYB") - rfid.setBlockAccess(rfid.ALLBLOCK, access_Read=rfid.KEYAB, access_Write=rfid.KEYB, access_Inc=rfid.NEVER, access_Dec=rfid.NEVER) - print("Set sector trailer to be only set by Key B"); - rfid.setTrailerAccess(keyA_Write=rfid.KEYB,access_Read=rfid.KEYAB,access_Write=rfid.KEYB,keyB_Read=rfid.NEVER,keyB_Write=rfid.KEYB) - rfid.showAccess() - - diff --git a/src/kits/rfid-rc522/lib/carl.py b/src/kits/rfid-rc522/lib/carl.py deleted file mode 100644 index 2733b072c..000000000 --- a/src/kits/rfid-rc522/lib/carl.py +++ /dev/null @@ -1,33 +0,0 @@ -# data_read.py -from mfrc522 import MFRC522 -import utime -import machine -from time import sleep -# from ssd1306 import SSD1306_I2C - -reader = MFRC522(spi_id=0,sck=6,miso=4,mosi=7,cs=5,rst=22) - -# i2c = machine.I2C(0, sda=machine.Pin(16), scl=machine.Pin(17)) -# setup the display driver using the i2c interface -# oled = SSD1306_I2C(128, 64, i2c) - -print("Bring TAG closer...") -print("") - - -while True: - reader.init() - (stat, tag_type) = reader.request(reader.REQIDL) - print(stat) - if stat == reader.OK: - - (stat, uid) = reader.SelectTagSN() - if stat == reader.OK: - card = int.from_bytes(bytes(uid),"little",False) - print("CARD ID: "+str(card)) -# oled.fill(0) -# oled.show() -# oled.text(str(card), 0, 0) -# oled.text("Line2", 0, 15) -# oled.show() - utime.sleep(1) \ No newline at end of file diff --git a/src/kits/rfid-rc522/lib/config.py b/src/kits/rfid-rc522/lib/config.py deleted file mode 100644 index 5ad83ceef..000000000 --- a/src/kits/rfid-rc522/lib/config.py +++ /dev/null @@ -1,10 +0,0 @@ -# reader = MFRC522(spi_id=0, sck=2, miso=4, mosi=3, cs=1, rst=0) -RESET_PIN = 0 # Green OUT -SDA_PIN = 1 # Yellow OUT but used a Chip Select CS -SCK_PIN = 2 # Orange OUT clock going from Pico to RC522 -MISO_PIN = 3 # Blue -MOSI_PIN = 4 # Purple -IRQ_PIN = 7 # Brown, OUT but not used in the reader demo - -# GND is Black -# Red goes to 3.3v out \ No newline at end of file diff --git a/src/kits/rfid-rc522/lib/mfrc522.py b/src/kits/rfid-rc522/lib/mfrc522.py deleted file mode 100644 index ccb5aa4a4..000000000 --- a/src/kits/rfid-rc522/lib/mfrc522.py +++ /dev/null @@ -1,382 +0,0 @@ -#mfrc522.py - -from machine import Pin, SPI -from os import uname - - -class MFRC522: - - DEBUG = False - OK = 0 - NOTAGERR = 1 - ERR = 2 - - REQIDL = 0x26 - REQALL = 0x52 - AUTHENT1A = 0x60 - AUTHENT1B = 0x61 - - PICC_ANTICOLL1 = 0x93 - PICC_ANTICOLL2 = 0x95 - PICC_ANTICOLL3 = 0x97 - - - def __init__(self, sck, mosi, miso, rst, cs,baudrate=1000000,spi_id=0): - - self.sck = Pin(sck, Pin.OUT) - self.mosi = Pin(mosi, Pin.OUT) - self.miso = Pin(miso) - self.rst = Pin(rst, Pin.OUT) - self.cs = Pin(cs, Pin.OUT) - - self.rst.value(0) - self.cs.value(1) - - board = uname()[0] - - if board == 'WiPy' or board == 'LoPy' or board == 'FiPy': - self.spi = SPI(0) - self.spi.init(SPI.MASTER, baudrate=1000000, pins=(self.sck, self.mosi, self.miso)) - elif (board == 'esp8266') or (board == 'esp32'): - self.spi = SPI(baudrate=100000, polarity=0, phase=0, sck=self.sck, mosi=self.mosi, miso=self.miso) - self.spi.init() - elif board == 'rp2': - self.spi = SPI(spi_id,baudrate=baudrate,sck=self.sck, mosi= self.mosi, miso= self.miso) - else: - raise RuntimeError("Unsupported platform") - - self.rst.value(1) - self.init() - - def _wreg(self, reg, val): - - self.cs.value(0) - self.spi.write(b'%c' % int(0xff & ((reg << 1) & 0x7e))) - self.spi.write(b'%c' % int(0xff & val)) - self.cs.value(1) - - def _rreg(self, reg): - - self.cs.value(0) - self.spi.write(b'%c' % int(0xff & (((reg << 1) & 0x7e) | 0x80))) - val = self.spi.read(1) - self.cs.value(1) - - return val[0] - - def _sflags(self, reg, mask): - self._wreg(reg, self._rreg(reg) | mask) - - def _cflags(self, reg, mask): - self._wreg(reg, self._rreg(reg) & (~mask)) - - def _tocard(self, cmd, send): - - recv = [] - bits = irq_en = wait_irq = n = 0 - stat = self.ERR - - if cmd == 0x0E: - irq_en = 0x12 - wait_irq = 0x10 - elif cmd == 0x0C: - irq_en = 0x77 - wait_irq = 0x30 - - self._wreg(0x02, irq_en | 0x80) - self._cflags(0x04, 0x80) - self._sflags(0x0A, 0x80) - self._wreg(0x01, 0x00) - - for c in send: - self._wreg(0x09, c) - self._wreg(0x01, cmd) - - if cmd == 0x0C: - self._sflags(0x0D, 0x80) - - i = 2000 - while True: - n = self._rreg(0x04) - i -= 1 - if ~((i != 0) and ~(n & 0x01) and ~(n & wait_irq)): - break - - self._cflags(0x0D, 0x80) - - if i: - if (self._rreg(0x06) & 0x1B) == 0x00: - stat = self.OK - - if n & irq_en & 0x01: - stat = self.NOTAGERR - elif cmd == 0x0C: - n = self._rreg(0x0A) - lbits = self._rreg(0x0C) & 0x07 - if lbits != 0: - bits = (n - 1) * 8 + lbits - else: - bits = n * 8 - - if n == 0: - n = 1 - elif n > 16: - n = 16 - - for _ in range(n): - recv.append(self._rreg(0x09)) - else: - stat = self.ERR - - return stat, recv, bits - - def _crc(self, data): - - self._cflags(0x05, 0x04) - self._sflags(0x0A, 0x80) - - for c in data: - self._wreg(0x09, c) - - self._wreg(0x01, 0x03) - - i = 0xFF - while True: - n = self._rreg(0x05) - i -= 1 - if not ((i != 0) and not (n & 0x04)): - break - - return [self._rreg(0x22), self._rreg(0x21)] - - def init(self): - - self.reset() - self._wreg(0x2A, 0x8D) - self._wreg(0x2B, 0x3E) - self._wreg(0x2D, 30) - self._wreg(0x2C, 0) - self._wreg(0x15, 0x40) - self._wreg(0x11, 0x3D) - self.antenna_on() - - def reset(self): - self._wreg(0x01, 0x0F) - - def antenna_on(self, on=True): - - if on and ~(self._rreg(0x14) & 0x03): - self._sflags(0x14, 0x03) - else: - self._cflags(0x14, 0x03) - - def request(self, mode): - - self._wreg(0x0D, 0x07) - (stat, recv, bits) = self._tocard(0x0C, [mode]) - - if (stat != self.OK) | (bits != 0x10): - stat = self.ERR - - return stat, bits - - def anticoll(self,anticolN): - - ser_chk = 0 - ser = [anticolN, 0x20] - - self._wreg(0x0D, 0x00) - (stat, recv, bits) = self._tocard(0x0C, ser) - - if stat == self.OK: - if len(recv) == 5: - for i in range(4): - ser_chk = ser_chk ^ recv[i] - if ser_chk != recv[4]: - stat = self.ERR - else: - stat = self.ERR - - return stat, recv - - - def PcdSelect(self, serNum,anticolN): - backData = [] - buf = [] - buf.append(anticolN) - buf.append(0x70) - #i = 0 - ###xorsum=0; - for i in serNum: - buf.append(i) - #while i<5: - # buf.append(serNum[i]) - # i = i + 1 - pOut = self._crc(buf) - buf.append(pOut[0]) - buf.append(pOut[1]) - (status, backData, backLen) = self._tocard( 0x0C, buf) - if (status == self.OK) and (backLen == 0x18): - return 1 - else: - return 0 - - - def SelectTag(self, uid): - byte5 = 0 - - #(status,puid)= self.anticoll(self.PICC_ANTICOLL1) - #print("uid",uid,"puid",puid) - for i in uid: - byte5 = byte5 ^ i - puid = uid + [byte5] - - if self.PcdSelect(puid,self.PICC_ANTICOLL1) == 0: - return (self.ERR,[]) - return (self.OK , uid) - - def tohexstring(self,v): - s="[" - for i in v: - if i != v[0]: - s = s+ ", " - s=s+ "0x{:02X}".format(i) - s= s+ "]" - return s - - - - - def SelectTagSN(self): - valid_uid=[] - (status,uid)= self.anticoll(self.PICC_ANTICOLL1) - #print("Select Tag 1:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - - if self.DEBUG: print("anticol(1) {}".format(uid)) - if self.PcdSelect(uid,self.PICC_ANTICOLL1) == 0: - return (self.ERR,[]) - if self.DEBUG: print("pcdSelect(1) {}".format(uid)) - - #check if first byte is 0x88 - if uid[0] == 0x88 : - #ok we have another type of card - valid_uid.extend(uid[1:4]) - (status,uid)=self.anticoll(self.PICC_ANTICOLL2) - #print("Select Tag 2:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - if self.DEBUG: print("Anticol(2) {}".format(uid)) - rtn = self.PcdSelect(uid,self.PICC_ANTICOLL2) - if self.DEBUG: print("pcdSelect(2) return={} uid={}".format(rtn,uid)) - if rtn == 0: - return (self.ERR,[]) - if self.DEBUG: print("PcdSelect2() {}".format(uid)) - #now check again if uid[0] is 0x88 - if uid[0] == 0x88 : - valid_uid.extend(uid[1:4]) - (status , uid) = self.anticoll(self.PICC_ANTICOLL3) - #print("Select Tag 3:",self.tohexstring(uid)) - if status != self.OK: - return (self.ERR,[]) - if self.DEBUG: print("Anticol(3) {}".format(uid)) - if self.MFRC522_PcdSelect(uid,self.PICC_ANTICOLL3) == 0: - return (self.ERR,[]) - if self.DEBUG: print("PcdSelect(3) {}".format(uid)) - valid_uid.extend(uid[0:5]) - # if we are here than the uid is ok - # let's remove the last BYTE whic is the XOR sum - - return (self.OK , valid_uid[:len(valid_uid)-1]) - #return (self.OK , valid_uid) - - - - - - - def auth(self, mode, addr, sect, ser): - return self._tocard(0x0E, [mode, addr] + sect + ser[:4])[0] - - def authKeys(self,uid,addr,keyA=None, keyB=None): - status = self.ERR - if keyA is not None: - status = self.auth(self.AUTHENT1A, addr, keyA, uid) - elif keyB is not None: - status = self.auth(self.AUTHENT1B, addr, keyB, uid) - return status - - - def stop_crypto1(self): - self._cflags(0x08, 0x08) - - def read(self, addr): - - data = [0x30, addr] - data += self._crc(data) - (stat, recv, _) = self._tocard(0x0C, data) - return stat, recv - - def write(self, addr, data): - - buf = [0xA0, addr] - buf += self._crc(buf) - (stat, recv, bits) = self._tocard(0x0C, buf) - - if not (stat == self.OK) or not (bits == 4) or not ((recv[0] & 0x0F) == 0x0A): - stat = self.ERR - else: - buf = [] - for i in range(16): - buf.append(data[i]) - buf += self._crc(buf) - (stat, recv, bits) = self._tocard(0x0C, buf) - if not (stat == self.OK) or not (bits == 4) or not ((recv[0] & 0x0F) == 0x0A): - stat = self.ERR - return stat - - - def writeSectorBlock(self,uid, sector, block, data, keyA=None, keyB = None): - absoluteBlock = sector * 4 + (block % 4) - if absoluteBlock > 63 : - return self.ERR - if len(data) != 16: - return self.ERR - if self.authKeys(uid,absoluteBlock,keyA,keyB) != self.ERR : - return self.write(absoluteBlock, data) - return self.ERR - - def readSectorBlock(self,uid ,sector, block, keyA=None, keyB = None): - absoluteBlock = sector * 4 + (block % 4) - if absoluteBlock > 63 : - return self.ERR, None - if self.authKeys(uid,absoluteBlock,keyA,keyB) != self.ERR : - return self.read(absoluteBlock) - return self.ERR, None - - def MFRC522_DumpClassic1K(self,uid, Start=0, End=64, keyA=None, keyB=None): - for absoluteBlock in range(Start,End): - status = self.authKeys(uid,absoluteBlock,keyA,keyB) - # Check if authenticated - print("{:02d} S{:02d} B{:1d}: ".format(absoluteBlock, absoluteBlock//4 , absoluteBlock % 4),end="") - if status == self.OK: - status, block = self.read(absoluteBlock) - if status == self.ERR: - break - else: - for value in block: - print("{:02X} ".format(value),end="") - print(" ",end="") - for value in block: - if (value > 0x20) and (value < 0x7f): - print(chr(value),end="") - else: - print('.',end="") - print("") - else: - break - if status == self.ERR: - print("Authentication error") - return self.ERR - return self.OK \ No newline at end of file diff --git a/src/kits/rfid-rc522/lib/read.py b/src/kits/rfid-rc522/lib/read.py deleted file mode 100644 index 4376975da..000000000 --- a/src/kits/rfid-rc522/lib/read.py +++ /dev/null @@ -1,53 +0,0 @@ -# pico_read.py -# https://github.com/danjperron/micropython-mfrc522/blob/master/Pico_example/Pico_read.py -# rdr = mfrc522.MFRC522(sck=SCK_PIN,mosi=MOSI_PIN,miso=MISO_PIN,rst=RST_PIN,cs=21)from mfrc522 import MFRC522 -from mfrc522 import MFRC522 -import config - -# Implicit read from config file -SCK_PIN = config.SCK_PIN -MISO_PIN = config.MISO_PIN -MOSI_PIN = config.MOSI_PIN -RESET_PIN = config.RESET_PIN - -import utime - -def uidToString(uid): - mystring = "" - for i in uid: - mystring = "%02X" % i + mystring - return mystring - -reader = MFRC522(spi_id=0,sck=2,miso=4,mosi=3,cs=1,rst=0) -# reader = MFRC522(spi_id=0, sck=SCK_PIN, miso=MISO_PIN, mosi=MOSI_PIN, cs=1, rst=RESET_PIN) - -print("") -print("Please place card on reader") -print("") - -PreviousCard = [0] - -try: - while True: - - reader.init() - (stat, tag_type) = reader.request(reader.REQIDL) - #print('request stat:',stat,' tag_type:',tag_type) - if stat == reader.OK: - (stat, uid) = reader.SelectTagSN() - if uid == PreviousCard: - continue - if stat == reader.OK: - print("Card detected {} uid={}".format(hex(int.from_bytes(bytes(uid),"little",False)).upper(),reader.tohexstring(uid))) - defaultKey = [255,255,255,255,255,255] - reader.MFRC522_DumpClassic1K(uid, Start=0, End=64, keyA=defaultKey) - print("Done") - PreviousCard = uid - else: - pass - else: - PreviousCard=[0] - utime.sleep_ms(50) - -except KeyboardInterrupt: - pass \ No newline at end of file diff --git a/src/kits/rfid-rc522/read.py b/src/kits/rfid-rc522/read.py deleted file mode 100644 index f4495b4c6..000000000 --- a/src/kits/rfid-rc522/read.py +++ /dev/null @@ -1,39 +0,0 @@ -import mfrc522 -from os import uname - - -def uidToString(uid): - mystring = "" - for i in uid: - mystring = "%02X" % i + mystring - return mystring - -def do_read(): - - if uname()[0] == 'WiPy': - rdr = mfrc522.MFRC522("GP14", "GP16", "GP15", "GP22", "GP17") - elif uname()[0] == 'esp32': - rdr = mfrc522.MFRC522(sck=18,mosi=23,miso=19,rst=22,cs=21) - else: - raise RuntimeError("Unsupported platform") - - print("") - print("Place card before reader to read from address 0x08") - print("") - - try: - while True: - - (stat, tag_type) = rdr.request(rdr.REQIDL) - - if stat == rdr.OK: - - (stat, uid) = rdr.SelectTagSN() - - if stat == rdr.OK: - print("Card detected %s" % uidToString(uid)) - else: - print("Authentication error") - - except KeyboardInterrupt: - print("Bye") \ No newline at end of file diff --git a/src/kits/rgb-knobs/01-blink.py b/src/kits/rgb-knobs/01-blink.py deleted file mode 100644 index bfb7bb9b3..000000000 --- a/src/kits/rgb-knobs/01-blink.py +++ /dev/null @@ -1,20 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 10 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - # red is 10 of 255 - strip[NUMBER_PIXELS-1] = (255,0,0) - - # turn on for 1/2 second - strip.write() - sleep(.25) - - # turn off for 1/2 second - strip[NUMBER_PIXELS-1] = (0,0,0) - strip.write() - sleep(.25) \ No newline at end of file diff --git a/src/kits/rgb-knobs/main.py b/src/kits/rgb-knobs/main.py deleted file mode 100644 index 66b8953e2..000000000 --- a/src/kits/rgb-knobs/main.py +++ /dev/null @@ -1,37 +0,0 @@ -# this kit assumes we have three POTs hooked to pins 26, 27 and 28 of the Pico -from machine import ADC, Pin -from utime import sleep -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 10 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# this is the built-in LED on the Pico which we toggle on and off to show sampling -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side -pot1 = ADC(28) # red -pot2 = ADC(27) # green -pot3 = ADC(26) # blue - -MAX_DELAY = .5 # seconds - -# global variables -delay = .05 - -# repeat forever -while True: - # we have the POTs wired backwards so we subtract to get the value - pot_value1 = pot1.read_u16() >> 8 # read the value from the pot and shift 6 bits - pot_value2 = pot2.read_u16() >> 8 - pot_value3 = pot3.read_u16() >> 8 - print("rgb", pot_value1, pot_value2, pot_value3) - - # update the strip with our new values - for i in range(NUMBER_PIXELS): - strip[i] = (pot_value3, pot_value2, pot_value1) - strip.write() - - sleep(delay) - led.toggle() \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/01-rotary-test.py b/src/kits/rotary-neopixel-display/01-rotary-test.py deleted file mode 100644 index ee105b63c..000000000 --- a/src/kits/rotary-neopixel-display/01-rotary-test.py +++ /dev/null @@ -1,29 +0,0 @@ -from machine import Pin -from rotary import Rotary -from time import sleep - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) -val = 0 - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('PRESS') - elif change == Rotary.SW_RELEASE: - print('RELEASE') - -rotary.add_handler(rotary_changed) - -while True: - sleep(0.1) \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/02-rotary-neopixel.py b/src/kits/rotary-neopixel-display/02-rotary-neopixel.py deleted file mode 100644 index f41357ca2..000000000 --- a/src/kits/rotary-neopixel-display/02-rotary-neopixel.py +++ /dev/null @@ -1,84 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 2 -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('PRESS') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('RELEASE') - color_index += 1 - color_index = color_index % (color_count - 1) - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -color_index = 0 -color = red -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - if mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - # print('color index', color_index) - color = colors[color_index] - \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/05-rotary-neopixel-five-modes.py b/src/kits/rotary-neopixel-display/05-rotary-neopixel-five-modes.py deleted file mode 100644 index 2fb366400..000000000 --- a/src/kits/rotary-neopixel-display/05-rotary-neopixel-five-modes.py +++ /dev/null @@ -1,115 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -mode_names = ['dot', 'hole', 'compare', 'chase', 'rainbow'] - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 5 - print('mode=', mode, mode_names[mode]) -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) - - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('PRESS') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('RELEASE') - color_index += 1 - color_index = color_index % (color_count - 1) - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -color_index = 0 -color = red -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - elif mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 2: - for i in range(0, NUMBER_PIXELS): - if i > val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 3: - for i in range(0, NUMBER_PIXELS): - if (i-val) % 3: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 4: - # if the val + offset is larger than the number of pixels we need to do a modulo - strip[val % (NUMBER_PIXELS)] = violet - strip[(val+1) % (NUMBER_PIXELS)] = indigo - strip[(val+2) % (NUMBER_PIXELS)] = blue - strip[(val+3) % (NUMBER_PIXELS)] = green - strip[(val+4) % (NUMBER_PIXELS)] = yellow - strip[(val+5) % (NUMBER_PIXELS)] = orange - strip[(val+6) % (NUMBER_PIXELS)] = red - # turn off the rest - strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0) - strip.write() - # print('color index', color_index) - color = colors[color_index] - \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/05-rotary-pattern-display.py b/src/kits/rotary-neopixel-display/05-rotary-pattern-display.py deleted file mode 100644 index 436bccdea..000000000 --- a/src/kits/rotary-neopixel-display/05-rotary-pattern-display.py +++ /dev/null @@ -1,150 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel -import ssd1306 - - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -mode_names = ['moving dot', 'moving hole', 'swipe', 'theater chase', 'moving rainbow'] - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 5 - print('mode=', mode, mode_names[mode]) -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(6) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(5) -RES = machine.Pin(4) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -color_index = 0 -color = red -colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) -color_names = ['red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'indigo', 'violet', 'white'] -color_count = len(colors) - -mode_names = ['dot', 'hole', 'less than', 'theater chase', 'moving rainbow'] - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index, color - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('Rotary knob pressed') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('Rotary knob released') - color_index += 1 - color_index = color_index % color_count - color = colors[color_index] - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -def update_display(color, pattern, index): - oled.fill(0) - oled.text('Color:', 0, 0) - oled.text(str(color), 10, 11) - oled.text('Pattern:', 0, 22) - oled.text(str(pattern), 10, 33) - oled.text('Index:', 0, 44) - oled.text(str(index), 10, 55) - oled.show() - - -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - elif mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 2: - for i in range(0, NUMBER_PIXELS): - if i > val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 3: - for i in range(0, NUMBER_PIXELS): - if (i-val) % 3: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 4: - # if the val + offset is larger than the number of pixels we need to do a modulo - strip[val % (NUMBER_PIXELS)] = violet - strip[(val+1) % (NUMBER_PIXELS)] = indigo - strip[(val+2) % (NUMBER_PIXELS)] = blue - strip[(val+3) % (NUMBER_PIXELS)] = green - strip[(val+4) % (NUMBER_PIXELS)] = yellow - strip[(val+5) % (NUMBER_PIXELS)] = orange - strip[(val+6) % (NUMBER_PIXELS)] = red - # turn off the rest - strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0) - strip.write() - # print('color index', color_index) - color_name = color_names[color_index] - mode_name = mode_names[mode] - update_display(color_name, mode_name, val) - \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/09-display-test.py b/src/kits/rotary-neopixel-display/09-display-test.py deleted file mode 100644 index 8b63d054a..000000000 --- a/src/kits/rotary-neopixel-display/09-display-test.py +++ /dev/null @@ -1,30 +0,0 @@ -# Test display connections - -from machine import Pin, I2C -from utime import sleep -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(6) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(5) -RES = machine.Pin(4) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -counter = 0 -while True: - oled.fill(0) - oled.text(str(counter), 0, 1) - oled.show() - sleep(1) - counter += 1 - - \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/10-display-coder-dojo-logo.py b/src/kits/rotary-neopixel-display/10-display-coder-dojo-logo.py deleted file mode 100644 index 4de5368a6..000000000 --- a/src/kits/rotary-neopixel-display/10-display-coder-dojo-logo.py +++ /dev/null @@ -1,47 +0,0 @@ -# This code displays pi image & text on I2C OLED display, then repeats forever. -# Also print out the OLED's I2C address on serial at program start. -# --- -# Connection: SCL = GP1, SDA = GP0 -# --- -# Hardware: -# 1. Cytron Maker Pi RP2040 (www.cytron.io/p-MAKER-PI-RP2040) -# - Any RP2040 boards should work too. -# 2. Grove OLED Display 0.96 inch (www.cytron.io/p-grove-oled-display-0p96-inch-ssd1315) -# --- -from machine import Pin, I2C -import framebuf -import utime -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(6) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(5) -RES = machine.Pin(4) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -# Raspberry Pi logo as 32x32 bytearray - -my_bytearray = (b'\x00\x00\x00@ \x10\x08\x00\x04\x00\x02\x02\x01\xf1\x19\t\t\xf9\x03\x02\x06\x0e<\xfc\xf8\xf0\xe0\xc0\x80\x00\x00\x00\xf0\x06\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x06\x04\x04\x03\x80\x80\xc0\xe0\xf8\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x0f \x80\x00\x00\x00\x00\x00\xe0\xf8\xfc\xfe\xfe\xff\xef\xef\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x00\x00\x00\x00\x02\x04\x08\x10\x10#\x0f_\x7f\x7f\xff\xf7\xf7\xf0\xf7q\x7f\x7f???\x1f\x0f\x07\x03\x01\x00\x00\x00') -coderdojo_logo = bytearray(my_bytearray) - - -# Load the raspberry pi logo into the framebuffer (the image is 32x32) -# Monochrome Horizontal least significant bit encoding is MONO_HLSB -# https://docs.micropython.org/en/latest/library/framebuf.html#framebuf.framebuf.MONO_VLSB -# fb = framebuf.FrameBuffer(pi_logo, 32, 32, framebuf.MONO_HLSB) -fbi = framebuf.FrameBuffer(coderdojo_logo, 32, 32, framebuf.MONO_VLSB) - -oled.fill(0) -oled.blit(fbi, 0, 1) -oled.show() - - \ No newline at end of file diff --git a/src/kits/rotary-neopixel-display/main.py b/src/kits/rotary-neopixel-display/main.py deleted file mode 100644 index 3761cad5e..000000000 --- a/src/kits/rotary-neopixel-display/main.py +++ /dev/null @@ -1,145 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel -import ssd1306 - - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -mode_names = ['moving dot', 'moving hole', 'swipe', 'theater chase', 'moving rainbow'] - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 5 - print('mode=', mode, mode_names[mode]) -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -CS = machine.Pin(6) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(5) -RES = machine.Pin(4) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) # Init oled display - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -caramel=(255,35,0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0,255,255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -color_index = 0 -color = red -colors = (red, orange, yellow, green, blue, cyan, indigo, caramel, violet, white) -color_names = ['red', 'orange', 'yellow', 'green', 'blue','cyan', 'indigo', 'caramel', 'violet', 'white'] -color_count = len(colors) - -mode_names = ['dot', 'hole', 'less than', 'theater chase', 'moving rainbow'] - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index, color - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('Rotary knob pressed') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('Rotary knob released') - color_index += 1 - color_index = color_index % color_count - color = colors[color_index] - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -def update_display(color, pattern, index): - oled.fill(0) - oled.text('Color:', 0, 0) - oled.text(str(color), 10, 11) - oled.text('Pattern:', 0, 22) - oled.text(str(pattern), 10, 33) - oled.text('Index:', 0, 44) - oled.text(str(index), 10, 55) - oled.show() - - -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - elif mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 2: - for i in range(0, NUMBER_PIXELS): - if i > val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 3: - for i in range(0, NUMBER_PIXELS): - if (i-val) % 3: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 4: - # if the val + offset is larger than the number of pixels we need to do a modulo - for i in range (len(colors)): - strip[(val+i) % (NUMBER_PIXELS)] = colors[i] - - # turn off the rest - for i in range (len(colors),NUMBER_PIXELS): - strip[(val+i) % (NUMBER_PIXELS)] = (0,0,0) - - strip.write() - # print('color index', color_index) - color_name = color_names[color_index] - mode_name = mode_names[mode] - update_display(color_name, mode_name, val) - \ No newline at end of file diff --git a/src/kits/tof-pot-motor-display/01-tof-i2c-scanner-test.py b/src/kits/tof-pot-motor-display/01-tof-i2c-scanner-test.py deleted file mode 100644 index 71155c0a6..000000000 --- a/src/kits/tof-pot-motor-display/01-tof-i2c-scanner-test.py +++ /dev/null @@ -1,20 +0,0 @@ -import machine - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -print('i2c result:', i2c) -address = i2c.scan() -print('Scan result:', address) - -decimal = address[0] -hex = hex(decimal) - -print('The VL53L0X has expected values of decimal 41 and hex 0x29') -print("Device found at decimal: ", i2c.scan(), decimal, hex) - -if (decimal == 41): - print('PASS') -else: - print('FAIL') diff --git a/src/kits/tof-pot-motor-display/03-tof-print-console-test.py b/src/kits/tof-pot-motor-display/03-tof-print-console-test.py deleted file mode 100644 index 66eb24507..000000000 --- a/src/kits/tof-pot-motor-display/03-tof-print-console-test.py +++ /dev/null @@ -1,17 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(0) # lower right pin -scl=machine.Pin(1) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl) -print('Device found at decimal address: ', i2c.scan()[0], 'Hex: ', hex(i2c.scan()[0])) -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -while True: - print(tof.read()) - time.sleep(0.1) diff --git a/src/kits/tof-pot-motor-display/04-display-test.py b/src/kits/tof-pot-motor-display/04-display-test.py deleted file mode 100644 index 1719fa1d0..000000000 --- a/src/kits/tof-pot-motor-display/04-display-test.py +++ /dev/null @@ -1,36 +0,0 @@ -from machine import Pin -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(counter): - oled.fill(0) - oled.text("MicroPython", 0, 0, 1) - oled.text("Rocks!", 0, 10, 1) - oled.text("264K RAM", 0, 20, 1) - oled.text("128X64 OLED", 0, 28, 1) - oled.text("ssd1306 SPI", 0, 36, 1) - oled.text("$4 + $17 = $21", 0, 45, 1) - oled.text(str(counter), 0, 54, 1) - oled.show() - -counter = 0 -while True: - update_display(counter) - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/tof-pot-motor-display/05-display-pot.py b/src/kits/tof-pot-motor-display/05-display-pot.py deleted file mode 100644 index a98bf53b8..000000000 --- a/src/kits/tof-pot-motor-display/05-display-pot.py +++ /dev/null @@ -1,61 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -WIDTH = 128 -HEIGHT = 64 -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -print(spi) - - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def update_display(counter, pot_value, high_bits): - oled.fill(0) - oled.text('CoderDojo PotLab', 0, 0) - oled.fill_rect(0, 10, high_bits, 20, 1) - - oled.text('ADC Value:', 0, 35) - oled.text(str(pot_value), 80, 35) - - oled.text('Display Val:', 0, 45) - oled.text(str(high_bits), 95, 45) - - oled.text('Counter:', 0, 54) - oled.text(str(counter), 65, 54) - oled.show() - -# return the 8 most significant bits of the ADC -def read_pot_u8(): - return pot.read_u16() >> 8 - -counter = 0 -while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - print(pot_value) - # print("pot_value:", delay) - high_bits = pot_value >> 9 - # print("delay:", high_bits) - update_display(counter, pot_value, high_bits) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/kits/tof-pot-motor-display/10-tof-display-vline.py b/src/kits/tof-pot-motor-display/10-tof-display-vline.py deleted file mode 100644 index 81837fb54..000000000 --- a/src/kits/tof-pot-motor-display/10-tof-display-vline.py +++ /dev/null @@ -1,70 +0,0 @@ -# VL53L0X Display Test - -from machine import Pin, I2C -import VL53L0X -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print('i2c:', i2c) - -tof = VL53L0X.VL53L0X(i2c) -TOF_MAX_VALUE = 200 # dist in cm anything beyond this we will ignore -TOF_MIN_OFFSET = 35 # subtract from raw sensor -TOF_SCALE = 0.5 # scale the result - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -def update_display(dist): - oled.fill(0) - if dist < TOF_MAX_VALUE: - print('dist:', dist) - oled.text('Distance:'+ str(round(dist))+'cm', 0, 56, 1) - # convert to a scale of 0 to 127 - tofX = map(dist, 0, TOF_MAX_VALUE, 0, WIDTH) - oled.vline(tofX, 0, HEIGHT, 1) - else: - print('out of range:', dist) - oled.text('Out of range', 0, 0, 1) - oled.show() - -def dist_cm(): - tof_value = tof.read() - # these constants need clibration - dist_in_cm = (tof_value - TOF_MIN_OFFSET) * TOF_SCALE - if dist_in_cm < 0: - return 0 - elif dist_in_cm > TOF_MAX_VALUE: - return TOF_MAX_VALUE - else: - return dist_in_cm - -tof.start() -while True: - # get distace in cm - dist = dist_cm() - update_display(dist) - sleep(.1) - diff --git a/src/kits/tof-pot-motor-display/12-display-pot-tof.py b/src/kits/tof-pot-motor-display/12-display-pot-tof.py deleted file mode 100644 index b873f6ed8..000000000 --- a/src/kits/tof-pot-motor-display/12-display-pot-tof.py +++ /dev/null @@ -1,84 +0,0 @@ -# VL53L0X Display Test - -from machine import ADC, I2C, Pin, PWM -import VL53L0X -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print('i2c:', i2c) - -tof = VL53L0X.VL53L0X(i2c) -TOF_MAX_VALUE = 200 # dist in cm anything beyond this we will ignore -TOF_MIN_OFFSET = 35 # subtract from raw sensor -TOF_SCALE = 0.5 # scale the result - -pot = ADC(26) - -# returns a value from 0 to 127 -def read_pot_128(): - return pot.read_u16() >> 9 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -def vline_dash(x, y, length, dash_length, color): - number_dashes = length // dash_length - for i in range(number_dashes): - oled.vline(x, y + i*dash_length, dash_length // 2, color) - -def update_display(dist, potValue): - oled.fill(0) - if dist < TOF_MAX_VALUE: - print('dist:', dist) - oled.text('Pot:'+ str(potValue), 0, 46, 1) - oled.text('Distance:'+ str(round(dist))+'cm', 0, 56, 1) - # convert to a scale of 0 to 127 - tofX = map(dist, 0, TOF_MAX_VALUE, 0, WIDTH) - oled.vline(tofX, 0, HEIGHT-20, 1) - else: - print('out of range:', dist) - oled.text('Out of range', 0, 0, 1) - vline_dash(potValue, 0, HEIGHT-20, 7, 1) - oled.show() - -def dist_cm(): - tof_value = tof.read() - # these constants need clibration - dist_in_cm = (tof_value - TOF_MIN_OFFSET) * TOF_SCALE - if dist_in_cm < 0: - return 0 - elif dist_in_cm > TOF_MAX_VALUE: - return TOF_MAX_VALUE - else: - return dist_in_cm - -tof.start() -while True: - # get distace in cm - dist = dist_cm() - potValue = read_pot_128() - update_display(dist, potValue) - sleep(.1) - diff --git a/src/kits/tof-pot-motor-display/13-obstacle-warning.py b/src/kits/tof-pot-motor-display/13-obstacle-warning.py deleted file mode 100644 index 25f1fcda2..000000000 --- a/src/kits/tof-pot-motor-display/13-obstacle-warning.py +++ /dev/null @@ -1,109 +0,0 @@ -# VL53L0X Display Test - -from machine import ADC, I2C, Pin, PWM -import VL53L0X -import ssd1306 -from utime import sleep - -# Display Setup -WIDTH = 128 -HEIGHT = 64 -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Tof Setup -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print('i2c:', i2c) -tof = VL53L0X.VL53L0X(i2c) -TOF_MAX_VALUE = 200 # dist in cm anything beyond this we will ignore -TOF_MIN_OFFSET = 35 # subtract from raw sensor -TOF_SCALE = 0.5 # scale the result - -# ADC Setup -pot = ADC(26) - -# Motor Setup -MAX_MOTOR = 65025 -# lower right pins with USB on top -FOR_PIN = 18 -REV_PIN = 19 - -forward = PWM(Pin(FOR_PIN)) -reverse = PWM(Pin(REV_PIN)) -forward.freq(50) -forward.freq(50) -# turn off the both motors -forward.duty_u16(0) -reverse.duty_u16(0) - -# returns a value from 0 to 127 -def read_pot_128(): - return pot.read_u16() >> 9 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -def vline_dash(x, y, length, dash_length, color): - number_dashes = length // dash_length - for i in range(number_dashes): - oled.vline(x, y + i*dash_length, dash_length // 2, color) - -def update_display(dist, potValue): - oled.fill(0) - if dist < TOF_MAX_VALUE: - print('dist:', dist) - #oled.text('Pot:'+ str(potValue), 0, 46, 1) - #oled.text('Distance:'+ str(round(dist))+'cm', 0, 56, 1) - tofX = map(dist, 0, TOF_MAX_VALUE, 0, WIDTH) - oled.vline(tofX, 0, HEIGHT-10, 1) - - if tofX > potValue: - oled.text('Drive Forward!', 0, 56, 1) - forward.duty_u16(MAX_MOTOR) - reverse.duty_u16(0) - else: - oled.text('Backup!', 0, 56, 1) - forward.duty_u16(0) - reverse.duty_u16(MAX_MOTOR) - # convert to a scale of 0 to 127 - - else: - print('out of range:', dist) - oled.text('Out of range', 0, 56, 1) - # draw the vertical line x, y, length, pixels on, color - vline_dash(potValue, 0, HEIGHT-8, 7, 1) - oled.show() - -def dist_cm(): - tof_value = tof.read() - # these constants need clibration - dist_in_cm = (tof_value - TOF_MIN_OFFSET) * TOF_SCALE - if dist_in_cm < 0: - return 0 - elif dist_in_cm > TOF_MAX_VALUE: - return TOF_MAX_VALUE - else: - return dist_in_cm - -tof.start() -while True: - # get distace in cm - dist = dist_cm() - potValue = read_pot_128() - update_display(dist, potValue) - sleep(.1) - diff --git a/src/kits/tof-pot-motor-display/13-wire-animate.py b/src/kits/tof-pot-motor-display/13-wire-animate.py deleted file mode 100644 index a8d27f66d..000000000 --- a/src/kits/tof-pot-motor-display/13-wire-animate.py +++ /dev/null @@ -1,121 +0,0 @@ -from machine import Pin -from utime import sleep -from neopixel import NeoPixel - -NUMBER_PIXELS = 28 -LED_PIN = 12 - -strip = NeoPixel(Pin(LED_PIN), NUMBER_PIXELS) - -# one segment for the 6 parts of the H brige -# lower right, upper right, upper left, lower left, middle right, middle left -segments = [[0,4], [5,9], [10,14], [15,19], [20, 23], [24, 27]] -num_segments = len(segments) -# upper left, middle left, middle right, lower right -foward_segments = [2,4,5,0] -forward_directions = [1,1,1,-1] -forward_list = [] -# upper right, middle right, middle left, lower left -reverse_segments = [1,5,4,3] -reverse_directions = [-1,-1,-1,1] -reverse_list = [] - -color_names = ["red", "orange", "yellow", "green", "indigo", "violet"] -red = (255, 0, 0) -lightred = (25, 0, 0) -off = (0,0,0) -orange = (120, 40, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightgreen = (0, 25, 0) -blue = (0, 0, 255) -lightblue = (0, 0, 25) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -colors = (red, orange, yellow, green, blue, indigo, violet) - -def make_forward_list(): - seg_counter = 0 - for i in foward_segments: - if forward_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - forward_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - forward_list.append(j) - seg_counter += 1 - -def make_reverse_list(): - seg_counter = 0 - for i in reverse_segments: - if reverse_directions[seg_counter] > 0: - for j in range(segments[i][0], segments[i][1]+1): - reverse_list.append(j) - else: - for j in range(segments[i][1], segments[i][0]-1, -1): - reverse_list.append(j) - seg_counter += 1 - -# draw every third pixel on -state = 2 # 0, 1 or 2 -def draw_forward(delay): - global state - #print("fwd:", start) - length = len(forward_list) + 2 - for i in range(0, length): - # print(start, i, forward_list[i+start], not((i) % 3)) - if (i+state) < (length-1) and not((i+state) % 3): - if i < length-2: - strip[forward_list[i]] = lightblue - # print("on: ", forward_list[i]) - else: - if (i+state) < length-1: - strip[forward_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -state = 2 -def draw_reverse(delay): - global state - #print("rev:", start) - length = len(reverse_list)+2 - for i in range(0, length): - #print(i+state) - if not((i+state) % 3) and (i+state) < (length-1): - if i < length-2: - strip[reverse_list[i]] = lightgreen - else: - if (i+state) < length-1: - strip[reverse_list[i]] = off - strip.write() - sleep(delay) - if state == 0: - state = 2 - else: state -= 1 - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = off - strip.write() - -delay = .2 - -make_forward_list() -print(forward_list) -make_reverse_list() -print(reverse_list) - -while True: - for i in range(0, 40): - draw_forward(delay) - clear() - for i in range(0, 40): - draw_reverse(delay) - clear() - - - diff --git a/src/kits/tof-pot-motor-display/main.py b/src/kits/tof-pot-motor-display/main.py deleted file mode 100644 index 25f1fcda2..000000000 --- a/src/kits/tof-pot-motor-display/main.py +++ /dev/null @@ -1,109 +0,0 @@ -# VL53L0X Display Test - -from machine import ADC, I2C, Pin, PWM -import VL53L0X -import ssd1306 -from utime import sleep - -# Display Setup -WIDTH = 128 -HEIGHT = 64 -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Tof Setup -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -# print('i2c:', i2c) -tof = VL53L0X.VL53L0X(i2c) -TOF_MAX_VALUE = 200 # dist in cm anything beyond this we will ignore -TOF_MIN_OFFSET = 35 # subtract from raw sensor -TOF_SCALE = 0.5 # scale the result - -# ADC Setup -pot = ADC(26) - -# Motor Setup -MAX_MOTOR = 65025 -# lower right pins with USB on top -FOR_PIN = 18 -REV_PIN = 19 - -forward = PWM(Pin(FOR_PIN)) -reverse = PWM(Pin(REV_PIN)) -forward.freq(50) -forward.freq(50) -# turn off the both motors -forward.duty_u16(0) -reverse.duty_u16(0) - -# returns a value from 0 to 127 -def read_pot_128(): - return pot.read_u16() >> 9 - -# map a value from one rante into another range -# checks for divide by zero -def map(value, istart, istop, ostart, ostop): - # check ff (istop - istart) - if (istop - istart) == 0: - return ostop - else: - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -def vline_dash(x, y, length, dash_length, color): - number_dashes = length // dash_length - for i in range(number_dashes): - oled.vline(x, y + i*dash_length, dash_length // 2, color) - -def update_display(dist, potValue): - oled.fill(0) - if dist < TOF_MAX_VALUE: - print('dist:', dist) - #oled.text('Pot:'+ str(potValue), 0, 46, 1) - #oled.text('Distance:'+ str(round(dist))+'cm', 0, 56, 1) - tofX = map(dist, 0, TOF_MAX_VALUE, 0, WIDTH) - oled.vline(tofX, 0, HEIGHT-10, 1) - - if tofX > potValue: - oled.text('Drive Forward!', 0, 56, 1) - forward.duty_u16(MAX_MOTOR) - reverse.duty_u16(0) - else: - oled.text('Backup!', 0, 56, 1) - forward.duty_u16(0) - reverse.duty_u16(MAX_MOTOR) - # convert to a scale of 0 to 127 - - else: - print('out of range:', dist) - oled.text('Out of range', 0, 56, 1) - # draw the vertical line x, y, length, pixels on, color - vline_dash(potValue, 0, HEIGHT-8, 7, 1) - oled.show() - -def dist_cm(): - tof_value = tof.read() - # these constants need clibration - dist_in_cm = (tof_value - TOF_MIN_OFFSET) * TOF_SCALE - if dist_in_cm < 0: - return 0 - elif dist_in_cm > TOF_MAX_VALUE: - return TOF_MAX_VALUE - else: - return dist_in_cm - -tof.start() -while True: - # get distace in cm - dist = dist_cm() - potValue = read_pot_128() - update_display(dist, potValue) - sleep(.1) - diff --git a/src/kits/tof-pot-motor-display/stop-motors.py b/src/kits/tof-pot-motor-display/stop-motors.py deleted file mode 100644 index e32815f3e..000000000 --- a/src/kits/tof-pot-motor-display/stop-motors.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -FORWARD_PIN = 18 -REVERSE_PIN = 19 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) -forward.freq(50) -forward.freq(50) - -forward.duty_u16(0) -reverse.duty_u16(0) -print('Motor Stopped') \ No newline at end of file diff --git a/src/led-strip.py b/src/led-strip.py deleted file mode 100644 index c7da523ac..000000000 --- a/src/led-strip.py +++ /dev/null @@ -1,109 +0,0 @@ -import array, time -from machine import Pin -import rp2 - -# Configure the number of WS2812 LEDs. -NUM_LEDS = 24 -PIN_NUM = 0 -brightness = 1.0 -pattern_sleep = .5 # Time to delay on each pattern in seconds - -@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24) -def ws2812(): - T1 = 2 - T2 = 5 - T3 = 3 - wrap_target() - label("bitloop") - out(x, 1) .side(0) [T3 - 1] - jmp(not_x, "do_zero") .side(1) [T1 - 1] - jmp("bitloop") .side(1) [T2 - 1] - label("do_zero") - nop() .side(0) [T2 - 1] - wrap() - - -# Create the StateMachine with the ws2812 program, outputting on pin -sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(PIN_NUM)) - -# Start the StateMachine, it will wait for data on its FIFO. -sm.active(1) - -# Display a pattern on the LEDs via an array of LED RGB values. -ar = array.array("I", [0 for _ in range(NUM_LEDS)]) - -########################################################################## -def pixels_show(): - dimmer_ar = array.array("I", [0 for _ in range(NUM_LEDS)]) - for i,c in enumerate(ar): - r = int(((c >> 8) & 0xFF) * brightness) - g = int(((c >> 16) & 0xFF) * brightness) - b = int((c & 0xFF) * brightness) - dimmer_ar[i] = (g<<16) + (r<<8) + b - sm.put(dimmer_ar, 8) - time.sleep_ms(10) - -def pixels_set(i, color): - ar[i] = (color[1]<<16) + (color[0]<<8) + color[2] - -def pixels_fill(color): - for i in range(len(ar)): - pixels_set(i, color) - -def color_chase(color, pattern_sleep): - for i in range(NUM_LEDS): - pixels_set(i, color) - time.sleep(pattern_sleep) - pixels_show() - time.sleep(pattern_sleep) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - - -def rainbow_cycle(pattern_sleep): - for j in range(255): - for i in range(NUM_LEDS): - rc_index = (i * 256 // NUM_LEDS) + j - pixels_set(i, wheel(rc_index & 255)) - pixels_show() - time.sleep(pattern_sleep) - - -RED = (255, 0, 0) -ORANGE = (255, 180, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -INDIGO = (75, 0, 130) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -BLACK = (0, 0, 0) -COLORS = (RED, ORANGE, YELLOW, GREEN, CYAN, BLUE, INDIGO, PURPLE) - -print("sending data to pin:", PIN_NUM) - -while True: - print("fills") - for color in COLORS: - pixels_fill(color) - pixels_show() - time.sleep(0.2) - - print("chases") - for color in COLORS: - color_chase(color, 0.01) - - print("rainbow") - rainbow_cycle(0) diff --git a/src/lib/glcdfont.py b/src/lib/glcdfont.py deleted file mode 100644 index c76e4d6a1..000000000 --- a/src/lib/glcdfont.py +++ /dev/null @@ -1,294 +0,0 @@ -# Original Adafruit_GFX 5x7 font - -def height(): - return 8 - -def max_width(): - return 6 - -def hmap(): - return False - -def reverse(): - return False - -def monospaced(): - return True - -def min_ch(): - return 0 - -def max_ch(): - return 255 - - -_font = \ - b'\x00\x00\x00\x00\x00'\ - b'\x3E\x5B\x4F\x5B\x3E'\ - b'\x3E\x6B\x4F\x6B\x3E'\ - b'\x1C\x3E\x7C\x3E\x1C'\ - b'\x18\x3C\x7E\x3C\x18'\ - b'\x1C\x57\x7D\x57\x1C'\ - b'\x1C\x5E\x7F\x5E\x1C'\ - b'\x00\x18\x3C\x18\x00'\ - b'\xFF\xE7\xC3\xE7\xFF'\ - b'\x00\x18\x24\x18\x00'\ - b'\xFF\xE7\xDB\xE7\xFF'\ - b'\x30\x48\x3A\x06\x0E'\ - b'\x26\x29\x79\x29\x26'\ - b'\x40\x7F\x05\x05\x07'\ - b'\x40\x7F\x05\x25\x3F'\ - b'\x5A\x3C\xE7\x3C\x5A'\ - b'\x7F\x3E\x1C\x1C\x08'\ - b'\x08\x1C\x1C\x3E\x7F'\ - b'\x14\x22\x7F\x22\x14'\ - b'\x5F\x5F\x00\x5F\x5F'\ - b'\x06\x09\x7F\x01\x7F'\ - b'\x00\x66\x89\x95\x6A'\ - b'\x60\x60\x60\x60\x60'\ - b'\x94\xA2\xFF\xA2\x94'\ - b'\x08\x04\x7E\x04\x08'\ - b'\x10\x20\x7E\x20\x10'\ - b'\x08\x08\x2A\x1C\x08'\ - b'\x08\x1C\x2A\x08\x08'\ - b'\x1E\x10\x10\x10\x10'\ - b'\x0C\x1E\x0C\x1E\x0C'\ - b'\x30\x38\x3E\x38\x30'\ - b'\x06\x0E\x3E\x0E\x06'\ - b'\x00\x00\x00\x00\x00'\ - b'\x00\x00\x5F\x00\x00'\ - b'\x00\x07\x00\x07\x00'\ - b'\x14\x7F\x14\x7F\x14'\ - b'\x24\x2A\x7F\x2A\x12'\ - b'\x23\x13\x08\x64\x62'\ - b'\x36\x49\x56\x20\x50'\ - b'\x00\x08\x07\x03\x00'\ - b'\x00\x1C\x22\x41\x00'\ - b'\x00\x41\x22\x1C\x00'\ - b'\x2A\x1C\x7F\x1C\x2A'\ - b'\x08\x08\x3E\x08\x08'\ - b'\x00\x80\x70\x30\x00'\ - b'\x08\x08\x08\x08\x08'\ - b'\x00\x00\x60\x60\x00'\ - b'\x20\x10\x08\x04\x02'\ - b'\x3E\x51\x49\x45\x3E'\ - b'\x00\x42\x7F\x40\x00'\ - b'\x72\x49\x49\x49\x46'\ - b'\x21\x41\x49\x4D\x33'\ - b'\x18\x14\x12\x7F\x10'\ - b'\x27\x45\x45\x45\x39'\ - b'\x3C\x4A\x49\x49\x31'\ - b'\x41\x21\x11\x09\x07'\ - b'\x36\x49\x49\x49\x36'\ - b'\x46\x49\x49\x29\x1E'\ - b'\x00\x00\x14\x00\x00'\ - b'\x00\x40\x34\x00\x00'\ - b'\x00\x08\x14\x22\x41'\ - b'\x14\x14\x14\x14\x14'\ - b'\x00\x41\x22\x14\x08'\ - b'\x02\x01\x59\x09\x06'\ - b'\x3E\x41\x5D\x59\x4E'\ - b'\x7C\x12\x11\x12\x7C'\ - b'\x7F\x49\x49\x49\x36'\ - b'\x3E\x41\x41\x41\x22'\ - b'\x7F\x41\x41\x41\x3E'\ - b'\x7F\x49\x49\x49\x41'\ - b'\x7F\x09\x09\x09\x01'\ - b'\x3E\x41\x41\x51\x73'\ - b'\x7F\x08\x08\x08\x7F'\ - b'\x00\x41\x7F\x41\x00'\ - b'\x20\x40\x41\x3F\x01'\ - b'\x7F\x08\x14\x22\x41'\ - b'\x7F\x40\x40\x40\x40'\ - b'\x7F\x02\x1C\x02\x7F'\ - b'\x7F\x04\x08\x10\x7F'\ - b'\x3E\x41\x41\x41\x3E'\ - b'\x7F\x09\x09\x09\x06'\ - b'\x3E\x41\x51\x21\x5E'\ - b'\x7F\x09\x19\x29\x46'\ - b'\x26\x49\x49\x49\x32'\ - b'\x03\x01\x7F\x01\x03'\ - b'\x3F\x40\x40\x40\x3F'\ - b'\x1F\x20\x40\x20\x1F'\ - b'\x3F\x40\x38\x40\x3F'\ - b'\x63\x14\x08\x14\x63'\ - b'\x03\x04\x78\x04\x03'\ - b'\x61\x59\x49\x4D\x43'\ - b'\x00\x7F\x41\x41\x41'\ - b'\x02\x04\x08\x10\x20'\ - b'\x00\x41\x41\x41\x7F'\ - b'\x04\x02\x01\x02\x04'\ - b'\x40\x40\x40\x40\x40'\ - b'\x00\x03\x07\x08\x00'\ - b'\x20\x54\x54\x78\x40'\ - b'\x7F\x28\x44\x44\x38'\ - b'\x38\x44\x44\x44\x28'\ - b'\x38\x44\x44\x28\x7F'\ - b'\x38\x54\x54\x54\x18'\ - b'\x00\x08\x7E\x09\x02'\ - b'\x18\xA4\xA4\x9C\x78'\ - b'\x7F\x08\x04\x04\x78'\ - b'\x00\x44\x7D\x40\x00'\ - b'\x20\x40\x40\x3D\x00'\ - b'\x7F\x10\x28\x44\x00'\ - b'\x00\x41\x7F\x40\x00'\ - b'\x7C\x04\x78\x04\x78'\ - b'\x7C\x08\x04\x04\x78'\ - b'\x38\x44\x44\x44\x38'\ - b'\xFC\x18\x24\x24\x18'\ - b'\x18\x24\x24\x18\xFC'\ - b'\x7C\x08\x04\x04\x08'\ - b'\x48\x54\x54\x54\x24'\ - b'\x04\x04\x3F\x44\x24'\ - b'\x3C\x40\x40\x20\x7C'\ - b'\x1C\x20\x40\x20\x1C'\ - b'\x3C\x40\x30\x40\x3C'\ - b'\x44\x28\x10\x28\x44'\ - b'\x4C\x90\x90\x90\x7C'\ - b'\x44\x64\x54\x4C\x44'\ - b'\x00\x08\x36\x41\x00'\ - b'\x00\x00\x77\x00\x00'\ - b'\x00\x41\x36\x08\x00'\ - b'\x02\x01\x02\x04\x02'\ - b'\x3C\x26\x23\x26\x3C'\ - b'\x1E\xA1\xA1\x61\x12'\ - b'\x3A\x40\x40\x20\x7A'\ - b'\x38\x54\x54\x55\x59'\ - b'\x21\x55\x55\x79\x41'\ - b'\x21\x54\x54\x78\x41'\ - b'\x21\x55\x54\x78\x40'\ - b'\x20\x54\x55\x79\x40'\ - b'\x0C\x1E\x52\x72\x12'\ - b'\x39\x55\x55\x55\x59'\ - b'\x39\x54\x54\x54\x59'\ - b'\x39\x55\x54\x54\x58'\ - b'\x00\x00\x45\x7C\x41'\ - b'\x00\x02\x45\x7D\x42'\ - b'\x00\x01\x45\x7C\x40'\ - b'\xF0\x29\x24\x29\xF0'\ - b'\xF0\x28\x25\x28\xF0'\ - b'\x7C\x54\x55\x45\x00'\ - b'\x20\x54\x54\x7C\x54'\ - b'\x7C\x0A\x09\x7F\x49'\ - b'\x32\x49\x49\x49\x32'\ - b'\x32\x48\x48\x48\x32'\ - b'\x32\x4A\x48\x48\x30'\ - b'\x3A\x41\x41\x21\x7A'\ - b'\x3A\x42\x40\x20\x78'\ - b'\x00\x9D\xA0\xA0\x7D'\ - b'\x39\x44\x44\x44\x39'\ - b'\x3D\x40\x40\x40\x3D'\ - b'\x3C\x24\xFF\x24\x24'\ - b'\x48\x7E\x49\x43\x66'\ - b'\x2B\x2F\xFC\x2F\x2B'\ - b'\xFF\x09\x29\xF6\x20'\ - b'\xC0\x88\x7E\x09\x03'\ - b'\x20\x54\x54\x79\x41'\ - b'\x00\x00\x44\x7D\x41'\ - b'\x30\x48\x48\x4A\x32'\ - b'\x38\x40\x40\x22\x7A'\ - b'\x00\x7A\x0A\x0A\x72'\ - b'\x7D\x0D\x19\x31\x7D'\ - b'\x26\x29\x29\x2F\x28'\ - b'\x26\x29\x29\x29\x26'\ - b'\x30\x48\x4D\x40\x20'\ - b'\x38\x08\x08\x08\x08'\ - b'\x08\x08\x08\x08\x38'\ - b'\x2F\x10\xC8\xAC\xBA'\ - b'\x2F\x10\x28\x34\xFA'\ - b'\x00\x00\x7B\x00\x00'\ - b'\x08\x14\x2A\x14\x22'\ - b'\x22\x14\x2A\x14\x08'\ - b'\xAA\x00\x55\x00\xAA'\ - b'\xAA\x55\xAA\x55\xAA'\ - b'\x00\x00\x00\xFF\x00'\ - b'\x10\x10\x10\xFF\x00'\ - b'\x14\x14\x14\xFF\x00'\ - b'\x10\x10\xFF\x00\xFF'\ - b'\x10\x10\xF0\x10\xF0'\ - b'\x14\x14\x14\xFC\x00'\ - b'\x14\x14\xF7\x00\xFF'\ - b'\x00\x00\xFF\x00\xFF'\ - b'\x14\x14\xF4\x04\xFC'\ - b'\x14\x14\x17\x10\x1F'\ - b'\x10\x10\x1F\x10\x1F'\ - b'\x14\x14\x14\x1F\x00'\ - b'\x10\x10\x10\xF0\x00'\ - b'\x00\x00\x00\x1F\x10'\ - b'\x10\x10\x10\x1F\x10'\ - b'\x10\x10\x10\xF0\x10'\ - b'\x00\x00\x00\xFF\x10'\ - b'\x10\x10\x10\x10\x10'\ - b'\x10\x10\x10\xFF\x10'\ - b'\x00\x00\x00\xFF\x14'\ - b'\x00\x00\xFF\x00\xFF'\ - b'\x00\x00\x1F\x10\x17'\ - b'\x00\x00\xFC\x04\xF4'\ - b'\x14\x14\x17\x10\x17'\ - b'\x14\x14\xF4\x04\xF4'\ - b'\x00\x00\xFF\x00\xF7'\ - b'\x14\x14\x14\x14\x14'\ - b'\x14\x14\xF7\x00\xF7'\ - b'\x14\x14\x14\x17\x14'\ - b'\x10\x10\x1F\x10\x1F'\ - b'\x14\x14\x14\xF4\x14'\ - b'\x10\x10\xF0\x10\xF0'\ - b'\x00\x00\x1F\x10\x1F'\ - b'\x00\x00\x00\x1F\x14'\ - b'\x00\x00\x00\xFC\x14'\ - b'\x00\x00\xF0\x10\xF0'\ - b'\x10\x10\xFF\x10\xFF'\ - b'\x14\x14\x14\xFF\x14'\ - b'\x10\x10\x10\x1F\x00'\ - b'\x00\x00\x00\xF0\x10'\ - b'\xFF\xFF\xFF\xFF\xFF'\ - b'\xF0\xF0\xF0\xF0\xF0'\ - b'\xFF\xFF\xFF\x00\x00'\ - b'\x00\x00\x00\xFF\xFF'\ - b'\x0F\x0F\x0F\x0F\x0F'\ - b'\x38\x44\x44\x38\x44'\ - b'\x7C\x2A\x2A\x3E\x14'\ - b'\x7E\x02\x02\x06\x06'\ - b'\x02\x7E\x02\x7E\x02'\ - b'\x63\x55\x49\x41\x63'\ - b'\x38\x44\x44\x3C\x04'\ - b'\x40\x7E\x20\x1E\x20'\ - b'\x06\x02\x7E\x02\x02'\ - b'\x99\xA5\xE7\xA5\x99'\ - b'\x1C\x2A\x49\x2A\x1C'\ - b'\x4C\x72\x01\x72\x4C'\ - b'\x30\x4A\x4D\x4D\x30'\ - b'\x30\x48\x78\x48\x30'\ - b'\xBC\x62\x5A\x46\x3D'\ - b'\x3E\x49\x49\x49\x00'\ - b'\x7E\x01\x01\x01\x7E'\ - b'\x2A\x2A\x2A\x2A\x2A'\ - b'\x44\x44\x5F\x44\x44'\ - b'\x40\x51\x4A\x44\x40'\ - b'\x40\x44\x4A\x51\x40'\ - b'\x00\x00\xFF\x01\x03'\ - b'\xE0\x80\xFF\x00\x00'\ - b'\x08\x08\x6B\x6B\x08'\ - b'\x36\x12\x36\x24\x36'\ - b'\x06\x0F\x09\x0F\x06'\ - b'\x00\x00\x18\x18\x00'\ - b'\x00\x00\x10\x10\x00'\ - b'\x30\x40\xFF\x01\x01'\ - b'\x00\x1F\x01\x01\x1E'\ - b'\x00\x19\x1D\x17\x12'\ - b'\x00\x3C\x3C\x3C\x3C'\ - b'\x00\x00\x00\x00\x00' - -_mvfont = memoryview(_font) - -def get_width(s): - return len(s)*6 - -def get_ch(ch): - ordch = ord(ch) - offset = ordch*5 - buf = bytearray(6) - buf[0] = 0 - buf[1:]=_mvfont[offset:offset+5] - return buf, 6 - diff --git a/src/lib/ssd1306-spi-test.py b/src/lib/ssd1306-spi-test.py deleted file mode 100644 index 9874e91f3..000000000 --- a/src/lib/ssd1306-spi-test.py +++ /dev/null @@ -1,24 +0,0 @@ -from machine import Pin -import ssd1306 -import utime - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 -spi=machine.SPI(0) -print(spi) - -CS = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -while True: - oled.fill(0) - oled.text("Hello World!", 0, 0, 1) - oled.show() - oled.fill(1) - oled.text("Hello World!", 0, 0, 0) - oled.show() \ No newline at end of file diff --git a/src/lib/ssd1306.py b/src/lib/ssd1306.py deleted file mode 100644 index 6359c85ea..000000000 --- a/src/lib/ssd1306.py +++ /dev/null @@ -1,155 +0,0 @@ -# MicroPython SSD1306 OLED driver, I2C and SPI interfaces - -from micropython import const -import framebuf - - -# register definitions -SET_CONTRAST = const(0x81) -SET_ENTIRE_ON = const(0xA4) -SET_NORM_INV = const(0xA6) -SET_DISP = const(0xAE) -SET_MEM_ADDR = const(0x20) -SET_COL_ADDR = const(0x21) -SET_PAGE_ADDR = const(0x22) -SET_DISP_START_LINE = const(0x40) -SET_SEG_REMAP = const(0xA0) -SET_MUX_RATIO = const(0xA8) -SET_COM_OUT_DIR = const(0xC0) -SET_DISP_OFFSET = const(0xD3) -SET_COM_PIN_CFG = const(0xDA) -SET_DISP_CLK_DIV = const(0xD5) -SET_PRECHARGE = const(0xD9) -SET_VCOM_DESEL = const(0xDB) -SET_CHARGE_PUMP = const(0x8D) - -# Subclassing FrameBuffer provides support for graphics primitives -# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html -class SSD1306(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB) - self.init_display() - - def init_display(self): - for cmd in ( - SET_DISP | 0x00, # off - # address setting - SET_MEM_ADDR, - 0x00, # horizontal - # resolution and layout - SET_DISP_START_LINE | 0x00, - SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 - SET_MUX_RATIO, - self.height - 1, - SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0 - SET_DISP_OFFSET, - 0x00, - SET_COM_PIN_CFG, - 0x02 if self.width > 2 * self.height else 0x12, - # timing and driving scheme - SET_DISP_CLK_DIV, - 0x80, - SET_PRECHARGE, - 0x22 if self.external_vcc else 0xF1, - SET_VCOM_DESEL, - 0x30, # 0.83*Vcc - # display - SET_CONTRAST, - 0xFF, # maximum - SET_ENTIRE_ON, # output follows RAM contents - SET_NORM_INV, # not inverted - # charge pump - SET_CHARGE_PUMP, - 0x10 if self.external_vcc else 0x14, - SET_DISP | 0x01, - ): # on - self.write_cmd(cmd) - self.fill(0) - self.show() - - def poweroff(self): - self.write_cmd(SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(SET_DISP | 0x01) - - def contrast(self, contrast): - self.write_cmd(SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(SET_NORM_INV | (invert & 1)) - - def show(self): - x0 = 0 - x1 = self.width - 1 - if self.width == 64: - # displays with width of 64 pixels are shifted by 32 - x0 += 32 - x1 += 32 - self.write_cmd(SET_COL_ADDR) - self.write_cmd(x0) - self.write_cmd(x1) - self.write_cmd(SET_PAGE_ADDR) - self.write_cmd(0) - self.write_cmd(self.pages - 1) - self.write_data(self.buffer) - - -class SSD1306_I2C(SSD1306): - def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.temp = bytearray(2) - self.write_list = [b"\x40", None] # Co=0, D/C#=1 - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.write_list[1] = buf - self.i2c.writevto(self.addr, self.write_list) - - -class SSD1306_SPI(SSD1306): - def __init__(self, width, height, spi, dc, res, cs, external_vcc=False): - self.rate = 10 * 1024 * 1024 - dc.init(dc.OUT, value=0) - res.init(res.OUT, value=0) - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - import time - - self.res(1) - time.sleep_ms(1) - self.res(0) - time.sleep_ms(10) - self.res(1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) diff --git a/src/lib/tt32.py b/src/lib/tt32.py deleted file mode 100644 index e98667e65..000000000 --- a/src/lib/tt32.py +++ /dev/null @@ -1,430 +0,0 @@ -# Code generated by font-to-py.py. -# Font: CM Sans Serif 2012.ttf -version = '0.2' - -def height(): - return 31 - -def max_width(): - return 26 - -def hmap(): - return False - -def reverse(): - return False - -def monospaced(): - return False - -def min_ch(): - return 32 - -def max_ch(): - return 126 - -_font =\ -b'\x0f\x00\x00\x07\x00\x00\xc0\x07\x00\x00\xe0\x07\x00\x00\xe0\x07'\ -b'\x00\x00\xf0\x01\x67\x00\xf0\xc0\xf7\x00\xf0\xe0\xf7\x00\xf0\xe0'\ -b'\x67\x00\xf0\xf1\x01\x00\xe0\xff\x00\x00\xe0\x7f\x00\x00\xc0\x3f'\ -b'\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x08\x00\xf0\xff\xf3\x00\xf0\xff\xf3\x00\xf0\xff'\ -b'\xf3\x00\xf0\xff\x63\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x0a\x00\xf0\x0f\x00\x00\xf0\x0f\x00\x00'\ -b'\xf0\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x0f\x00\x00'\ -b'\xf0\x0f\x00\x00\xf0\x0f\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00'\ -b'\x0f\x00\x00\x00\x0e\x00\x00\x0e\x0e\x00\x00\x0e\x7e\x00\x00\xfe'\ -b'\x7f\x00\xe0\xff\x7f\x00\xe0\xff\x0f\x00\xe0\x0f\x0e\x00\x00\x0e'\ -b'\x0e\x00\x00\x0e\x7f\x00\x00\xfe\x7f\x00\xe0\xff\x7f\x00\xe0\xff'\ -b'\x0f\x00\xe0\x0f\x0e\x00\x00\x0e\x0e\x00\x00\x0e\x00\x00\x0e\x00'\ -b'\x00\x1f\x0e\x00\x80\x3f\x1e\x00\xc0\x3f\x3e\x00\xc0\x79\x3c\x00'\ -b'\xc0\x71\x38\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xc0\xe1\x38\x00'\ -b'\xc0\xe3\x38\x00\xc0\xe7\x3f\x00\x80\xc7\x1f\x00\x00\x86\x0f\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x17\x00\x80\x07\x00\x00\xc0\x0f'\ -b'\x00\x00\xe0\x1f\x00\x00\xf0\x3c\x00\x00\x70\x38\x80\x00\x70\x38'\ -b'\xe0\x00\x70\x38\xf8\x00\xf0\x3c\x7e\x00\xe0\x1f\x1f\x00\xc0\xcf'\ -b'\x0f\x00\x80\xf7\x03\x00\x00\xfc\x00\x00\x00\x3f\x1e\x00\x80\x8f'\ -b'\x7f\x00\xe0\x87\x7f\x00\xf0\xc1\xf3\x00\x70\xc0\xe1\x00\x10\xc0'\ -b'\xe1\x00\x00\xc0\xf3\x00\x00\x80\x7f\x00\x00\x80\x7f\x00\x00\x00'\ -b'\x1e\x00\x00\x00\x00\x00\x13\x00\x00\x00\x0f\x00\x00\x80\x3f\x00'\ -b'\x00\xc0\x3f\x00\x80\xe7\x7f\x00\xe0\x7f\xf8\x00\xe0\x3f\xf8\x00'\ -b'\xf0\x3f\xf0\x00\xf0\x78\xf0\x00\xf0\xf8\xf0\x00\xf0\xff\xf3\x00'\ -b'\xe0\xdf\xff\x00\xe0\x8f\xff\x00\x80\x07\x7e\x00\x00\xc0\xff\x00'\ -b'\x00\xc0\xff\x00\x00\xc0\xff\x00\x00\xc0\xc3\x00\x00\x00\x80\x00'\ -b'\x00\x00\x00\x00\x05\x00\xf0\x0f\x00\x00\xf0\x0f\x00\x00\xf0\x0f'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\xfc\x03\x00'\ -b'\x80\xff\x1f\x00\xe0\xff\x7f\x00\xf8\xff\xff\x01\xfc\x01\xf8\x03'\ -b'\x3e\x00\xc0\x07\x0e\x00\x00\x07\x02\x00\x00\x04\x00\x00\x00\x00'\ -b'\x09\x00\x02\x00\x00\x04\x0e\x00\x00\x07\x3e\x00\xc0\x07\xfc\x01'\ -b'\xf8\x03\xf8\xff\xff\x01\xe0\xff\x7f\x00\x80\xff\x1f\x00\x00\xfc'\ -b'\x03\x00\x00\x00\x00\x00\x0b\x00\x80\x01\x00\x00\xa0\x09\x00\x00'\ -b'\xf0\x1f\x00\x00\xe0\x0f\x00\x00\xc0\x07\x00\x00\xe0\x0f\x00\x00'\ -b'\xf0\x1d\x00\x00\xa0\x09\x00\x00\x80\x01\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x0f\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\xc0'\ -b'\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\xfe\x7f\x00\x00\xfe'\ -b'\x7f\x00\x00\xfe\x7f\x00\x00\xfe\x7f\x00\x00\xc0\x03\x00\x00\xc0'\ -b'\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\x00'\ -b'\x00\x00\x06\x00\x00\x00\x60\x0c\x00\x00\xf0\x0c\x00\x00\xf0\x07'\ -b'\x00\x00\xe0\x03\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\xc0'\ -b'\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\xc0'\ -b'\x03\x00\x00\xc0\x03\x00\x00\xc0\x03\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x06\x00\x00\x00\x60\x00\x00\x00\xf0\x00\x00\x00\xf0\x00'\ -b'\x00\x00\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x00\x00'\ -b'\xe0\x00\x00\x00\xfc\x00\x00\xc0\xff\x00\x00\xf8\xff\x00\x80\xff'\ -b'\x1f\x00\xf8\xff\x03\x00\xfc\x3f\x00\x00\xfc\x07\x00\x00\x7c\x00'\ -b'\x00\x00\x04\x00\x00\x00\x11\x00\x00\xfc\x03\x00\x80\xff\x1f\x00'\ -b'\xc0\xff\x3f\x00\xe0\xff\x7f\x00\xe0\x07\x7e\x00\xf0\x01\xf8\x00'\ -b'\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x01\xf8\x00'\ -b'\xe0\x07\x7e\x00\xe0\xff\x7f\x00\xc0\xff\x3f\x00\x80\xff\x1f\x00'\ -b'\x00\xfc\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x80\x03'\ -b'\x00\x00\x80\x03\x00\x00\xc0\x03\x00\x00\xe0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x10\x00\x00\x07\xf8\x00\xc0\x07\xfc\x00\xc0\x07\xfe\x00'\ -b'\xe0\x07\xff\x00\xf0\x81\xf7\x00\xf0\x80\xf3\x00\xf0\xc0\xf1\x00'\ -b'\xf0\xe0\xf1\x00\xf0\xe0\xf0\x00\xf0\xf1\xf0\x00\xe0\x7f\xf0\x00'\ -b'\xe0\x7f\xf0\x00\xc0\x3f\xf0\x00\x00\x0f\xf0\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x10\x00\x00\x00\x0e\x00\x00\x07\x3e\x00\xc0\x07'\ -b'\x3e\x00\xe0\x07\x7e\x00\xe0\x07\xf8\x00\xf0\x01\xf0\x00\xf0\xf0'\ -b'\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf9\xf0\x00\xf0\xff'\ -b'\xf9\x00\xe0\xff\x7f\x00\xc0\xdf\x7f\x00\x80\x8f\x3f\x00\x00\x00'\ -b'\x0f\x00\x00\x00\x00\x00\x10\x00\x00\x00\x0f\x00\x00\x80\x0f\x00'\ -b'\x00\xe0\x0f\x00\x00\xf8\x0f\x00\x00\x7c\x0f\x00\x00\x3f\x0f\x00'\ -b'\x80\x0f\x0f\x00\xe0\x07\x0f\x00\xf0\x01\x0f\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\x00\x00\x0f\x00'\ -b'\x00\x00\x0f\x00\x00\x00\x00\x00\x0f\x00\x00\x70\x1c\x00\xf0\x7f'\ -b'\x3c\x00\xf0\x7f\x7c\x00\xf0\xff\x7c\x00\xf0\x78\xf8\x00\xf0\x3c'\ -b'\xf0\x00\xf0\x3c\xf0\x00\xf0\x3c\xf0\x00\xf0\x3c\xf0\x00\xf0\x7c'\ -b'\x78\x00\xf0\xf8\x7f\x00\xf0\xf0\x3f\x00\xf0\xe0\x1f\x00\x00\xc0'\ -b'\x0f\x00\x00\x00\x00\x00\x10\x00\x00\xfc\x07\x00\x00\xff\x1f\x00'\ -b'\xc0\xff\x3f\x00\xe0\xff\x7f\x00\xe0\xf3\x78\x00\xf0\x79\xf0\x00'\ -b'\xf0\x78\xf0\x00\xf0\x78\xf0\x00\xf0\x78\xf0\x00\xf0\xf9\xf8\x00'\ -b'\xe0\xf3\x7f\x00\xe0\xf3\x7f\x00\xc0\xe3\x3f\x00\x00\x83\x0f\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\xf0\x00\x00\x00\xf0\x00'\ -b'\x00\x00\xf0\x00\x00\x00\xf0\x00\xf8\x00\xf0\x80\xff\x00\xf0\xe0'\ -b'\xff\x00\xf0\xf8\xff\x00\xf0\xfc\x07\x00\xf0\x7e\x00\x00\xf0\x1f'\ -b'\x00\x00\xf0\x07\x00\x00\xf0\x03\x00\x00\xf0\x01\x00\x00\xf0\x00'\ -b'\x00\x00\x10\x00\x00\x00\x0f\x00\x80\xc7\x3f\x00\xc0\xef\x7f\x00'\ -b'\xe0\xff\x7f\x00\xe0\xff\xf8\x00\xf0\x7d\xf0\x00\xf0\x78\xf0\x00'\ -b'\xf0\x78\xf0\x00\xf0\x78\xf0\x00\xf0\x7d\xf0\x00\xe0\xff\xf8\x00'\ -b'\xe0\xff\x7f\x00\xc0\xef\x7f\x00\x80\xc7\x3f\x00\x00\x00\x0f\x00'\ -b'\x00\x00\x00\x00\x10\x00\x00\x3f\x00\x00\x80\xff\x30\x00\xc0\xff'\ -b'\x71\x00\xe0\xff\x71\x00\xf0\xe1\xf3\x00\xf0\xc1\xf3\x00\xf0\xc0'\ -b'\xf3\x00\xf0\xc0\xf3\x00\xf0\xc0\xf3\x00\xf0\xc1\xf9\x00\xe0\xe1'\ -b'\x7d\x00\xe0\xff\x7f\x00\xc0\xff\x3f\x00\x80\xff\x1f\x00\x00\xfc'\ -b'\x03\x00\x00\x00\x00\x00\x06\x00\x00\x18\x60\x00\x00\x3c\xf0\x00'\ -b'\x00\x3c\xf0\x00\x00\x18\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x06\x00\x00\x18\x60\x0c\x00\x3c\xf0\x0c\x00\x3c\xf0\x07\x00\x18'\ -b'\xe0\x03\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\xc0\x03\x00'\ -b'\x00\xe0\x07\x00\x00\xe0\x07\x00\x00\xf0\x0f\x00\x00\xf0\x0f\x00'\ -b'\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x38\x1c\x00\x00\x3c\x3c\x00'\ -b'\x00\x1c\x38\x00\x00\x1e\x78\x00\x00\x00\x00\x00\x0e\x00\x00\x78'\ -b'\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x78'\ -b'\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x78'\ -b'\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x1e\x78\x00\x00\x3c\x3c\x00'\ -b'\x00\x3c\x3c\x00\x00\x78\x1e\x00\x00\x78\x1e\x00\x00\x70\x0e\x00'\ -b'\x00\xf0\x0f\x00\x00\xe0\x07\x00\x00\xe0\x07\x00\x00\xc0\x07\x00'\ -b'\x00\xc0\x03\x00\x00\x00\x00\x00\x0f\x00\x00\x07\x00\x00\xc0\x07'\ -b'\x00\x00\xe0\x07\x00\x00\xe0\x07\x00\x00\xf0\x01\x67\x00\xf0\xc0'\ -b'\xf7\x00\xf0\xe0\xf7\x00\xf0\xe0\x67\x00\xf0\xf1\x01\x00\xe0\xff'\ -b'\x00\x00\xe0\x7f\x00\x00\xc0\x3f\x00\x00\x00\x1f\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x16\x00\x00\xf8\x01\x00\x00\xfe\x07\x00'\ -b'\x80\xff\x1f\x00\xc0\x0f\x1e\x00\xc0\x03\x3c\x00\xe0\xe1\x79\x00'\ -b'\xe0\xf8\x73\x00\xf0\xfc\xf7\x00\x70\x1c\xe7\x00\x70\x0e\xe7\x00'\ -b'\x70\x8e\xe3\x00\x70\xfe\xe1\x00\x70\xfc\xe3\x00\xf0\xfc\xe7\x00'\ -b'\xe0\x0c\x77\x00\xe0\x01\x77\x00\xc0\xc3\x23\x00\xc0\xff\x43\x00'\ -b'\x00\xff\x01\x00\x00\x7e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x13\x00\x00\x00\xc0\x00\x00\x00\xf8\x00\x00\x00\xfe\x00\x00\xc0'\ -b'\xff\x00\x00\xf8\x3f\x00\x00\xff\x0f\x00\xe0\xff\x0f\x00\xf0\x1f'\ -b'\x0f\x00\xf0\x03\x0f\x00\xf0\x00\x0f\x00\xf0\x07\x0f\x00\xf0\x3f'\ -b'\x0f\x00\xc0\xff\x0f\x00\x00\xfe\x0f\x00\x00\xf0\x7f\x00\x00\x80'\ -b'\xff\x00\x00\x00\xfc\x00\x00\x00\xf0\x00\x00\x00\x80\x00\x12\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00'\ -b'\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf9\xf0\x00'\ -b'\xf0\xff\xf9\x00\xe0\xff\x7f\x00\xc0\xdf\x7f\x00\x80\x8f\x3f\x00'\ -b'\x00\x00\x1f\x00\x00\x00\x00\x00\x14\x00\x00\xf8\x01\x00\x00\xfe'\ -b'\x07\x00\x80\xff\x1f\x00\xc0\xff\x3f\x00\xc0\x0f\x3f\x00\xe0\x03'\ -b'\x7c\x00\xe0\x01\x78\x00\xf0\x01\xf8\x00\xf0\x00\xf0\x00\xf0\x00'\ -b'\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x01\xf8\x00\xe0\x01'\ -b'\x78\x00\xe0\x07\x7e\x00\xc0\x07\x3e\x00\x80\x07\x1e\x00\x00\x03'\ -b'\x0c\x00\x00\x04\x04\x00\x00\x00\x00\x00\x13\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\x00\xf0\x00'\ -b'\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00'\ -b'\xf0\x00\xf8\x00\xe0\x01\x78\x00\xe0\x07\x7e\x00\xc0\xff\x3f\x00'\ -b'\x80\xff\x1f\x00\x00\xff\x0f\x00\x00\xfc\x03\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00\xf0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xf0\xf0\x00\xf0\xf0'\ -b'\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0'\ -b'\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\xf0\xf0\x00\xf0\x00'\ -b'\xf0\x00\xf0\x00\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xf0\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00'\ -b'\xf0\xf0\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00\xf0\xf0\x00\x00'\ -b'\xf0\xf0\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\x00\x00\x00\x00'\ -b'\x15\x00\x00\xf8\x01\x00\x00\xfe\x0f\x00\x80\xff\x1f\x00\xc0\xff'\ -b'\x3f\x00\xc0\x0f\x7f\x00\xe0\x03\x7c\x00\xe0\x01\xf8\x00\xf0\x01'\ -b'\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\xe0\xf1\x00\xf0\xe0'\ -b'\xf1\x00\xf0\xe1\x79\x00\xe0\xe1\x79\x00\xe0\xe3\x3d\x00\xc0\xe7'\ -b'\xff\x00\x80\xe7\xff\x00\x00\xe3\xff\x00\x00\xe4\xff\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x14\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\x00\xf0\x00\x00\x00\xf0\x00\x00'\ -b'\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00'\ -b'\x00\xf0\x00\x00\x00\xf0\x00\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\xf0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x3f\x00'\ -b'\x00\x00\x7f\x00\x00\x00\x7f\x00\x00\x00\xf8\x00\x00\x00\xf0\x00'\ -b'\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf8\x00'\ -b'\xf0\xff\x7f\x00\xf0\xff\x7f\x00\xf0\xff\x3f\x00\xf0\xff\x0f\x00'\ -b'\x00\x00\x00\x00\x12\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\xf0\xff\xff\x00\x00\xf0\x01\x00\x00\xfc\x00\x00\x00\xfe'\ -b'\x00\x00\x00\xff\x01\x00\x80\xff\x07\x00\xc0\xef\x0f\x00\xe0\x87'\ -b'\x3f\x00\xf0\x01\x7f\x00\xf0\x00\xfc\x00\x70\x00\xf8\x00\x30\x00'\ -b'\xf0\x00\x10\x00\xc0\x00\x10\x00\x80\x00\x00\x00\x00\x00\x10\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00'\ -b'\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00'\ -b'\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x18\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\xf0\x07\x00\x00\xf0\x7f\x00\x00\x80\xff\x07\x00\x00\xfc'\ -b'\x3f\x00\x00\xc0\xff\x00\x00\x00\xfe\x00\x00\x00\xfe\x00\x00\xc0'\ -b'\xff\x00\x00\xfc\x3f\x00\x80\xff\x07\x00\xf0\x7f\x00\x00\xf0\x07'\ -b'\x00\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff'\ -b'\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x14\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\x07\x00\x00\xc0\x1f\x00\x00\x00\x3f\x00\x00'\ -b'\x00\xfc\x00\x00\x00\xf0\x03\x00\x00\xc0\x0f\x00\x00\x80\x3f\x00'\ -b'\x00\x00\xfe\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x16\x00\x00\xf8\x01\x00\x00\xfe\x07\x00\x80\xff'\ -b'\x1f\x00\xc0\xff\x3f\x00\xc0\x0f\x3f\x00\xe0\x03\x7c\x00\xe0\x01'\ -b'\x78\x00\xf0\x01\xf8\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00\xf0\x00'\ -b'\xf0\x00\xf0\x00\xf0\x00\xf0\x01\xf8\x00\xe0\x01\x78\x00\xe0\x03'\ -b'\x7c\x00\xc0\x0f\x3f\x00\xc0\xff\x3f\x00\x80\xff\x1f\x00\x00\xfe'\ -b'\x07\x00\x00\xf8\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xe0\x01\x00\xf0\xe0\x01\x00\xf0\xe0\x01\x00\xf0\xe0\x01\x00'\ -b'\xf0\xe0\x01\x00\xf0\xe0\x01\x00\xf0\xf1\x01\x00\xe0\xff\x00\x00'\ -b'\xe0\xff\x00\x00\xc0\x7f\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\xf8\x01\x00\x00\xff'\ -b'\x0f\x00\x80\xff\x1f\x00\xc0\xff\x3f\x00\xe0\x0f\x7e\x00\xe0\x03'\ -b'\x7c\x00\xf0\x01\xf8\x00\xf0\x00\xf0\x00\xf0\x00\xf1\x00\xf0\x80'\ -b'\xf3\x00\xf0\xc0\xf7\x00\xf0\x80\xff\x00\xf0\x01\xff\x00\xe0\x03'\ -b'\x7e\x00\xe0\x0f\x7e\x00\xc0\xff\x7f\x00\x80\xff\xff\x00\x00\xfe'\ -b'\x77\x00\x00\xf8\x21\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xe0\x01\x00\xf0\xe0\x01\x00\xf0\xe0\x01\x00\xf0\xe0\x03\x00'\ -b'\xf0\xe0\x0f\x00\xf0\xe0\x3f\x00\xf0\xf1\x7f\x00\xe0\xff\xfc\x00'\ -b'\xe0\xff\xf0\x00\xc0\x7f\xe0\x00\x00\x1f\x80\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x04\x00\x80\x0f'\ -b'\x1e\x00\xc0\x1f\x3e\x00\xe0\x3f\x7e\x00\xe0\x3f\x7c\x00\xf0\x39'\ -b'\xf8\x00\xf0\x70\xf0\x00\xf0\x70\xf0\x00\xf0\x70\xf0\x00\xf0\x70'\ -b'\xf0\x00\xf0\x60\xf0\x00\xf0\xe1\xf8\x00\xe0\xe3\x78\x00\xe0\xc7'\ -b'\x7f\x00\xc0\xc3\x7f\x00\x80\x83\x3f\x00\x00\x02\x0f\x00\x00\x00'\ -b'\x00\x00\x0f\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00'\ -b'\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf0\xff\xff\x00\xf0\x00\x00\x00\xf0\x00\x00\x00'\ -b'\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\x00\x00\x00\x00'\ -b'\x12\x00\xf0\xff\x07\x00\xf0\xff\x1f\x00\xf0\xff\x3f\x00\xf0\xff'\ -b'\x7f\x00\x00\x00\x7c\x00\x00\x00\xf8\x00\x00\x00\xf0\x00\x00\x00'\ -b'\xf0\x00\x00\x00\xf0\x00\x00\x00\xf0\x00\x00\x00\xf8\x00\x00\x00'\ -b'\x7c\x00\xf0\xff\x7f\x00\xf0\xff\x3f\x00\xf0\xff\x1f\x00\xf0\xff'\ -b'\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x00\x30\x00\x00\x00'\ -b'\xf0\x01\x00\x00\xf0\x0f\x00\x00\xf0\x7f\x00\x00\xc0\xff\x03\x00'\ -b'\x00\xfe\x1f\x00\x00\xe0\xff\x00\x00\x00\xff\x00\x00\x00\xf8\x00'\ -b'\x00\x00\xff\x00\x00\xe0\xff\x00\x00\xfe\x1f\x00\xc0\xff\x03\x00'\ -b'\xf0\x7f\x00\x00\xf0\x0f\x00\x00\xf0\x01\x00\x00\x30\x00\x00\x00'\ -b'\x19\x00\x70\x00\x00\x00\xf0\x03\x00\x00\xf0\x3f\x00\x00\xf0\xff'\ -b'\x01\x00\x80\xff\x1f\x00\x00\xf8\xff\x00\x00\x80\xff\x00\x00\x00'\ -b'\xfc\x00\x00\xe0\xff\x00\x00\xff\xff\x00\xf0\xff\x07\x00\xf0\x3f'\ -b'\x00\x00\xf0\x03\x00\x00\xf0\x1f\x00\x00\xf0\xff\x03\x00\x80\xff'\ -b'\x7f\x00\x00\xf8\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\xf0'\ -b'\xff\x00\x00\xff\x3f\x00\xf0\xff\x07\x00\xf0\x7f\x00\x00\xf0\x07'\ -b'\x00\x00\xf0\x00\x00\x00\x11\x00\x10\x00\x80\x00\x30\x00\xe0\x00'\ -b'\xf0\x00\xf0\x00\xf0\x01\xfc\x00\xf0\x07\xfe\x00\xc0\x9f\x3f\x00'\ -b'\x80\xff\x0f\x00\x00\xfe\x07\x00\x00\xfc\x01\x00\x00\xfe\x07\x00'\ -b'\x80\xff\x0f\x00\xc0\x9f\x3f\x00\xf0\x07\x7f\x00\xf0\x03\xfc\x00'\ -b'\xf0\x00\xf8\x00\x70\x00\xe0\x00\x10\x00\x80\x00\x12\x00\x10\x00'\ -b'\x00\x00\x30\x00\x00\x00\xf0\x00\x00\x00\xf0\x03\x00\x00\xf0\x0f'\ -b'\x00\x00\xc0\x3f\x00\x00\x00\x7f\x00\x00\x00\xfc\xff\x00\x00\xf0'\ -b'\xff\x00\x00\xf0\xff\x00\x00\xfc\xff\x00\x00\x7f\x00\x00\xc0\x3f'\ -b'\x00\x00\xf0\x0f\x00\x00\xf0\x03\x00\x00\xf0\x00\x00\x00\x30\x00'\ -b'\x00\x00\x10\x00\x00\x00\x11\x00\x00\x00\xe0\x00\xf0\x00\xf8\x00'\ -b'\xf0\x00\xfc\x00\xf0\x00\xfe\x00\xf0\x00\xff\x00\xf0\x80\xff\x00'\ -b'\xf0\xc0\xf3\x00\xf0\xf0\xf1\x00\xf0\xf8\xf0\x00\xf0\x7c\xf0\x00'\ -b'\xf0\x3e\xf0\x00\xf0\x0f\xf0\x00\xf0\x07\xf0\x00\xf0\x03\xf0\x00'\ -b'\xf0\x01\xf0\x00\xf0\x00\xf0\x00\x00\x00\x00\x00\x09\x00\xff\xff'\ -b'\xff\x0f\xff\xff\xff\x0f\xff\xff\xff\x0f\xff\xff\xff\x0f\x0f\x00'\ -b'\x00\x0f\x0f\x00\x00\x0f\x0f\x00\x00\x0f\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x0a\x00\x04\x00\x00\x00\x3c\x00\x00\x00\xfc\x03\x00\x00'\ -b'\xfc\x1f\x00\x00\xf8\xff\x01\x00\xc0\xff\x1f\x00\x00\xfc\xff\x00'\ -b'\x00\xe0\xff\x00\x00\x00\xfe\x00\x00\x00\xe0\x00\x09\x00\x0f\x00'\ -b'\x00\x0f\x0f\x00\x00\x0f\x0f\x00\x00\x0f\xff\xff\xff\x0f\xff\xff'\ -b'\xff\x0f\xff\xff\xff\x0f\xff\xff\xff\x0f\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x0f\x00\x00\x80\x01\x00\x00\xf0\x01\x00\x00\xfc\x01\x00'\ -b'\x80\xff\x01\x00\xe0\x3f\x00\x00\xf0\x07\x00\x00\xf0\x01\x00\x00'\ -b'\xf0\x03\x00\x00\xf0\x1f\x00\x00\xc0\xff\x00\x00\x00\xfe\x01\x00'\ -b'\x00\xf8\x01\x00\x00\xc0\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00'\ -b'\x17\x00\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00'\ -b'\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00'\ -b'\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00'\ -b'\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00'\ -b'\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00'\ -b'\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x00\x00\x00\x0f\x0c\x00'\ -b'\x08\x00\x00\x00\x18\x00\x00\x00\x38\x00\x00\x00\x78\x00\x00\x00'\ -b'\x70\x00\x00\x00\x60\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x11\x00\x00\x40\x3c\x00\x00\x30\x7e\x00\x00\x38\x7f\x00\x00\x7c'\ -b'\xff\x00\x00\x3e\xf3\x00\x00\x1e\xf3\x00\x00\x1e\xf3\x00\x00\x1e'\ -b'\xf1\x00\x00\x9e\x71\x00\x00\xbe\x79\x00\x00\xfc\xff\x00\x00\xfc'\ -b'\xff\x00\x00\xf8\xff\x00\x00\xf0\xff\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x12\x00\xfc\xff\xff\x00\xfc\xff\xff\x00'\ -b'\xfc\xff\xff\x00\xfc\xff\xff\x00\x00\x7c\x3c\x00\x00\x3c\x78\x00'\ -b'\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x1e\xf0\x00'\ -b'\x00\x3e\xf8\x00\x00\x7c\x7c\x00\x00\xfc\x7f\x00\x00\xf8\x3f\x00'\ -b'\x00\xf0\x1f\x00\x00\xc0\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x10\x00\x00\xc0\x07\x00\x00\xf0\x1f\x00\x00\xf8\x3f\x00\x00\xfc'\ -b'\x7f\x00\x00\x7c\x7c\x00\x00\x3e\xf8\x00\x00\x1e\xf0\x00\x00\x1e'\ -b'\xf0\x00\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x3c\xf8\x00\x00\x7c'\ -b'\x7c\x00\x00\x78\x38\x00\x00\x30\x18\x00\x00\x20\x08\x00\x00\x00'\ -b'\x00\x00\x12\x00\x00\xc0\x07\x00\x00\xf0\x1f\x00\x00\xf8\x3f\x00'\ -b'\x00\xfc\x7f\x00\x00\x7e\xfc\x00\x00\x3e\xf8\x00\x00\x1e\xf0\x00'\ -b'\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x3c\x78\x00\x00\x7c\x7c\x00'\ -b'\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff\xff\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\xe0'\ -b'\x0f\x00\x00\xf0\x1f\x00\x00\xf8\x3f\x00\x00\xfc\x7f\x00\x00\xdc'\ -b'\x7b\x00\x00\xde\xf3\x00\x00\xde\xf3\x00\x00\xde\xf3\x00\x00\xde'\ -b'\xf3\x00\x00\xde\xfb\x00\x00\xfc\x7b\x00\x00\xfc\x7b\x00\x00\xf8'\ -b'\x33\x00\x00\xf0\x03\x00\x00\x80\x03\x00\x00\x00\x00\x00\x09\x00'\ -b'\x00\x1c\x00\x00\x00\x1c\x00\x00\xc0\xff\xff\x00\xf0\xff\xff\x00'\ -b'\xf0\xff\xff\x00\xf8\xff\xff\x00\x78\x1c\x00\x00\x3c\x1c\x00\x00'\ -b'\x3c\x1c\x00\x00\x11\x00\x00\xc0\x07\x08\x00\xf0\x1f\x1c\x00\xf8'\ -b'\x3f\x3c\x00\xfc\x7f\x3c\x00\x7e\xfc\x7c\x00\x3e\xf8\x78\x00\x1e'\ -b'\xf0\x78\x00\x1e\xf0\x78\x00\x1e\xf0\x78\x00\x3c\x78\x7c\x00\x78'\ -b'\x7c\x3e\x00\xfe\xff\x3f\x00\xfe\xff\x1f\x00\xfe\xff\x0f\x00\xfe'\ -b'\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\xfc\xff\xff\x00'\ -b'\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff\xff\x00\x00\x3c\x00\x00'\ -b'\x00\x1e\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00'\ -b'\x00\x3e\x00\x00\x00\xfc\xff\x00\x00\xfc\xff\x00\x00\xf8\xff\x00'\ -b'\x00\xe0\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x60\xfe'\ -b'\xff\x00\xf0\xfe\xff\x00\xf0\xfe\xff\x00\x60\xfe\xff\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x78'\ -b'\x00\x00\x00\x78\x60\xfe\xff\x7f\xf0\xfe\xff\x3f\xf0\xfe\xff\x3f'\ -b'\x60\xfe\xff\x0f\x10\x00\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff'\ -b'\xff\x00\xfc\xff\xff\x00\x00\xc0\x07\x00\x00\xe0\x03\x00\x00\xf0'\ -b'\x07\x00\x00\xfc\x0f\x00\x00\xfe\x3f\x00\x00\x3e\xff\x00\x00\x1e'\ -b'\xfc\x00\x00\x0e\xf8\x00\x00\x06\xe0\x00\x00\x02\xc0\x00\x00\x00'\ -b'\x80\x00\x00\x00\x00\x00\x07\x00\xfc\xff\xff\x00\xfc\xff\xff\x00'\ -b'\xfc\xff\xff\x00\xfc\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x00\x00\x00\x00\x1a\x00\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\xfe'\ -b'\xff\x00\x00\xfe\xff\x00\x00\x3c\x00\x00\x00\x1e\x00\x00\x00\x1e'\ -b'\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00\x00\x3e\x00\x00\x00\xfc'\ -b'\xff\x00\x00\xfc\xff\x00\x00\xf8\xff\x00\x00\xfc\xff\x00\x00\x3e'\ -b'\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00\x00\x3e'\ -b'\x00\x00\x00\xfc\xff\x00\x00\xfc\xff\x00\x00\xf8\xff\x00\x00\xe0'\ -b'\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00'\ -b'\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\xfe\xff\x00'\ -b'\x00\x3c\x00\x00\x00\x1c\x00\x00\x00\x1e\x00\x00\x00\x1e\x00\x00'\ -b'\x00\x1e\x00\x00\x00\x3e\x00\x00\x00\xfc\xff\x00\x00\xfc\xff\x00'\ -b'\x00\xf8\xff\x00\x00\xe0\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x11\x00\x00\xc0\x07\x00\x00\xf0\x1f\x00\x00\xf8\x3f\x00\x00\xfc'\ -b'\x7f\x00\x00\x7c\x7c\x00\x00\x3e\xf8\x00\x00\x1e\xf0\x00\x00\x1e'\ -b'\xf0\x00\x00\x1e\xf0\x00\x00\x3e\xf8\x00\x00\x7c\x7c\x00\x00\xfc'\ -b'\x7f\x00\x00\xf8\x3f\x00\x00\xf0\x1f\x00\x00\xc0\x07\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x12\x00\x00\xfe\xff\x7f\x00\xfe\xff\x7f'\ -b'\x00\xfe\xff\x7f\x00\xfe\xff\x7f\x00\x7c\x7c\x00\x00\x3c\x78\x00'\ -b'\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x1e\xf0\x00\x00\x1e\xf0\x00'\ -b'\x00\x3e\xf8\x00\x00\x7c\x7c\x00\x00\xfc\x7f\x00\x00\xf8\x3f\x00'\ -b'\x00\xf0\x1f\x00\x00\xc0\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x11\x00\x00\xc0\x07\x00\x00\xf0\x1f\x00\x00\xf8\x3f\x00\x00\xfc'\ -b'\x7f\x00\x00\x7e\xfc\x00\x00\x3e\xf8\x00\x00\x1e\xf0\x00\x00\x1e'\ -b'\xf0\x00\x00\x1e\xf0\x00\x00\x3c\x78\x00\x00\x7c\x7c\x00\x00\xfe'\ -b'\xff\x7f\x00\xfe\xff\x7f\x00\xfe\xff\x7f\x00\xfe\xff\x7f\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x0a\x00\x00\xfe\xff\x00\x00\xfe\xff\x00'\ -b'\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\x3c\x00\x00\x00\x1e\x00\x00'\ -b'\x00\x1e\x00\x00\x00\x0e\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00'\ -b'\x0f\x00\x00\x00\x08\x00\x00\x70\x18\x00\x00\xfc\x38\x00\x00\xfc'\ -b'\x7d\x00\x00\xfe\xf9\x00\x00\x9e\xf1\x00\x00\x9e\xf1\x00\x00\x9e'\ -b'\xf1\x00\x00\x9e\xf3\x00\x00\x3e\xf3\x00\x00\x3c\x7f\x00\x00\x3c'\ -b'\x7f\x00\x00\x38\x3e\x00\x00\x20\x1c\x00\x00\x00\x00\x00\x09\x00'\ -b'\x00\x0e\x00\x00\x00\x0e\x00\x00\xfc\xff\x1f\x00\xfc\xff\x3f\x00'\ -b'\xfc\xff\x7f\x00\xfc\xff\xff\x00\x00\x0e\xf0\x00\x00\x0e\xf0\x00'\ -b'\x00\x0e\xf0\x00\x10\x00\x00\xfe\x0f\x00\x00\xfe\x3f\x00\x00\xfe'\ -b'\x7f\x00\x00\xfe\x7f\x00\x00\x00\xf8\x00\x00\x00\xf0\x00\x00\x00'\ -b'\xf0\x00\x00\x00\xf0\x00\x00\x00\x70\x00\x00\x00\x78\x00\x00\xfe'\ -b'\xff\x00\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\xfe\xff\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x0f\x00\x00\x06\x00\x00\x00\x3e\x00\x00'\ -b'\x00\xfe\x00\x00\x00\xfe\x07\x00\x00\xf8\x3f\x00\x00\xc0\xff\x00'\ -b'\x00\x00\xfe\x00\x00\x00\xf0\x00\x00\x00\xfe\x00\x00\xc0\xff\x00'\ -b'\x00\xf8\x1f\x00\x00\xfe\x07\x00\x00\xfe\x00\x00\x00\x1e\x00\x00'\ -b'\x00\x06\x00\x00\x16\x00\x00\x06\x00\x00\x00\x7e\x00\x00\x00\xfe'\ -b'\x03\x00\x00\xfe\x1f\x00\x00\xf0\xff\x00\x00\x00\xff\x00\x00\x00'\ -b'\xf8\x00\x00\x80\xff\x00\x00\xf8\xff\x00\x00\xfe\x0f\x00\x00\xfe'\ -b'\x00\x00\x00\xfe\x00\x00\x00\xfe\x07\x00\x00\xf8\x7f\x00\x00\x80'\ -b'\xff\x00\x00\x00\xf8\x00\x00\x00\xff\x00\x00\xf0\xff\x00\x00\xfe'\ -b'\x3f\x00\x00\xfe\x03\x00\x00\x7e\x00\x00\x00\x0e\x00\x00\x0f\x00'\ -b'\x00\x02\x80\x00\x00\x06\xe0\x00\x00\x1e\xf0\x00\x00\x3e\xfc\x00'\ -b'\x00\xfe\x7e\x00\x00\xf8\x3f\x00\x00\xe0\x0f\x00\x00\xe0\x07\x00'\ -b'\x00\xf8\x1f\x00\x00\xfc\x7f\x00\x00\x7e\xfc\x00\x00\x1e\xf8\x00'\ -b'\x00\x0e\xe0\x00\x00\x02\xc0\x00\x00\x00\x80\x00\x0f\x00\x00\x06'\ -b'\x00\x00\x00\x3e\x00\x00\x00\xfe\x00\x78\x00\xfe\x07\x78\x00\xf8'\ -b'\x1f\x7c\x00\xc0\xff\x7f\x00\x00\xfe\x3f\x00\x00\xf0\x1f\x00\x00'\ -b'\xfe\x07\x00\xc0\xff\x00\x00\xf8\x1f\x00\x00\xfe\x07\x00\x00\xfe'\ -b'\x00\x00\x00\x1e\x00\x00\x00\x06\x00\x00\x0e\x00\x00\x00\xe0\x00'\ -b'\x00\x1e\xf0\x00\x00\x1e\xf8\x00\x00\x1e\xfc\x00\x00\x1e\xfe\x00'\ -b'\x00\x1e\xff\x00\x00\x9e\xf7\x00\x00\xde\xf3\x00\x00\xfe\xf1\x00'\ -b'\x00\xfe\xf0\x00\x00\x7e\xf0\x00\x00\x3e\xf0\x00\x00\x1e\xf0\x00'\ -b'\x00\x00\x00\x00\x0a\x00\x00\x60\x00\x00\x00\xf0\x00\x00\x00\xf0'\ -b'\x00\x00\xf8\xff\xff\x01\xfc\xff\xff\x03\xfe\x9f\xff\x07\xfe\x0f'\ -b'\xff\x07\x0e\x00\x00\x07\x0e\x00\x00\x07\x00\x00\x00\x00\x08\x00'\ -b'\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff\xff\x00\xfc\xff\xff\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\ -b'\x09\x00\x0e\x00\x00\x07\x0e\x00\x00\x07\xfe\x0f\xff\x07\xfe\x9f'\ -b'\xff\x07\xfc\xff\xff\x03\xf8\xff\xff\x01\x00\xf0\x00\x00\x00\xf0'\ -b'\x00\x00\x00\x60\x00\x00\x0c\x00\x30\x00\x00\x00\x38\x00\x00\x00'\ -b'\x18\x00\x00\x00\x18\x00\x00\x00\x18\x00\x00\x00\x30\x00\x00\x00'\ -b'\x30\x00\x00\x00\x30\x00\x00\x00\x38\x00\x00\x00\x18\x00\x00\x00'\ -b'\x00\x00\x00\x00\x00\x00\x00\x00' - -_index =\ -b'\x00\x00\x3e\x00\x64\x00\x86\x00\xb0\x00\xee\x00\x28\x01\x86\x01'\ -b'\xd4\x01\xea\x01\x10\x02\x36\x02\x64\x02\xa2\x02\xbc\x02\xe2\x02'\ -b'\xfc\x02\x26\x03\x6c\x03\x92\x03\xd4\x03\x16\x04\x58\x04\x96\x04'\ -b'\xd8\x04\x12\x05\x54\x05\x96\x05\xb0\x05\xca\x05\xfc\x05\x36\x06'\ -b'\x68\x06\xa6\x06\x00\x07\x4e\x07\x98\x07\xea\x07\x38\x08\x7e\x08'\ -b'\xc0\x08\x16\x09\x68\x09\x86\x09\xc4\x09\x0e\x0a\x50\x0a\xb2\x0a'\ -b'\x04\x0b\x5e\x0b\xa8\x0b\xfe\x0b\x48\x0c\x92\x0c\xd0\x0c\x1a\x0d'\ -b'\x60\x0d\xc6\x0d\x0c\x0e\x56\x0e\x9c\x0e\xc2\x0e\xec\x0e\x12\x0f'\ -b'\x50\x0f\xae\x0f\xe0\x0f\x26\x10\x70\x10\xb2\x10\xfc\x10\x3e\x11'\ -b'\x64\x11\xaa\x11\xec\x11\x0a\x12\x24\x12\x66\x12\x84\x12\xee\x12'\ -b'\x30\x13\x76\x13\xc0\x13\x06\x14\x30\x14\x6e\x14\x94\x14\xd6\x14'\ -b'\x14\x15\x6e\x15\xac\x15\xea\x15\x24\x16\x4e\x16\x70\x16\x96\x16'\ -b'\xc8\x16' - -_mvfont = memoryview(_font) - -def _chr_addr(ordch): - offset = 2 * (ordch - 32) - return int.from_bytes(_index[offset:offset + 2], 'little') - -def get_width(s): - width = 0 - for ch in s: - ordch = ord(ch) - ordch = ordch + 1 if ordch >= 32 and ordch <= 126 else 32 - offset = _chr_addr(ordch) - width += int.from_bytes(_font[offset:offset + 2], 'little') - return width - -def get_ch(ch): - ordch = ord(ch) - ordch = ordch + 1 if ordch >= 32 and ordch <= 126 else 32 - offset = _chr_addr(ordch) - width = int.from_bytes(_font[offset:offset + 2], 'little') - next_offs = _chr_addr(ordch +1) - return _mvfont[offset + 2:next_offs], width - diff --git a/src/motors/forward-and-reverse.py b/src/motors/forward-and-reverse.py deleted file mode 100644 index b85251a6a..000000000 --- a/src/motors/forward-and-reverse.py +++ /dev/null @@ -1,35 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -pot = machine.ADC(26) -# lower right pins with USB on top -FORWARD_PIN = 16 -REVERSE_PIN = 17 - -MAX_POWER = 65025 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -def main(): - while True: - for i in range(0, MAX_POWER, 1024): - print(i) - forward.duty_u16(i) - sleep(.1) - forward.duty_u16(0) - for i in range(0, MAX_POWER, 1024): - print(i) - reverse.duty_u16(i) - sleep(.1) - reverse.duty_u16(0) -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/motors/motor-drive-test-l293.py b/src/motors/motor-drive-test-l293.py deleted file mode 100644 index 05d90c698..000000000 --- a/src/motors/motor-drive-test-l293.py +++ /dev/null @@ -1,51 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -FORWARD_PIN = 19 -REVERSE_PIN = 18 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -POWER_LEVEL = 65025 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) -# end of main() - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() diff --git a/src/motors/motor-driver-l293d.py b/src/motors/motor-driver-l293d.py deleted file mode 100644 index 7d2e886ec..000000000 --- a/src/motors/motor-driver-l293d.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -pot = machine.ADC(26) -# lower right pins with USB on top -FORWARD_PIN = 16 -REVERSE_PIN = 17 - -MAX_POWER = 65025 -POT_MAX = 65025 -HALF_POT = int(POT_MAX / 2) - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -counter = 0 -def main(): - while True: - global counter - pot_val = pot.read_u16() - if pot_val > HALF_POT: - reverse.duty_u16(0) - speed = (pot_val - HALF_POT)*2 - forward.duty_u16(speed) - print('forward', speed) - else: - forward.duty_u16(0) - speed = (HALF_POT - pot_val)*2 - reverse.duty_u16(speed) - print('reverse', speed) - counter += 1 - sleep(.1) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/motors/spin-forward-reverse.py b/src/motors/spin-forward-reverse.py deleted file mode 100644 index 8ed94e5f2..000000000 --- a/src/motors/spin-forward-reverse.py +++ /dev/null @@ -1,61 +0,0 @@ -# spin foward slow to fast -from machine import Pin, PWM -from time import sleep - -# this is the built-in LED on the Pico W -led = Pin('LED', Pin.OUT) - -FORWARD_PIN = 16 -REVERSE_PIN = 17 - -MAX_POWER = 65025 - -forward = PWM(Pin(FORWARD_PIN)) -reverse = PWM(Pin(REVERSE_PIN)) - -delay = .05 -def main(): - while True: - - # slowly add forward power - for i in range(0, MAX_POWER, 1024): - forward.duty_u16(i) - print(i) - led.toggle() - sleep(delay) - # stay at max forward for one second - sleep(1) - # scale back forward power - for i in range(MAX_POWER, 0, -1024): - forward.duty_u16(i) - print(i) - led.toggle() - sleep(delay) - # keep off for a second - sleep(1) - - # reverse - for i in range(0, MAX_POWER, 1024): - reverse.duty_u16(i) - print(i) - led.toggle() - sleep(delay) - # keep max reverse for one second - sleep(1) - for i in range(MAX_POWER, 0, -1024): - reverse.duty_u16(i) - print(i) - led.toggle() - sleep(delay) - # keep off for a second - sleep(1) -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - reverse.duty_u16(0) \ No newline at end of file diff --git a/src/motors/spin-forward-slow-to-fast.py b/src/motors/spin-forward-slow-to-fast.py deleted file mode 100644 index 21feb24e8..000000000 --- a/src/motors/spin-forward-slow-to-fast.py +++ /dev/null @@ -1,38 +0,0 @@ -# spin foward slow to fast -from machine import Pin, PWM -from time import sleep - -# this is the built-in LED on the Pico W -led = Pin('LED', Pin.OUT) - -FORWARD_PIN = 16 -#REVERSE_PIN = 17 - -MAX_POWER = 65025 - -forward = PWM(Pin(FORWARD_PIN)) -#reverse = PWM(Pin(REVERSE_PIN)) - -delay = .05 -def main(): - while True: - for i in range(0, MAX_POWER, 1024): - forward.duty_u16(i) - print(i) - led.toggle() - sleep(delay) - for i in range(MAX_POWER, 0, -1024): - forward.duty_u16(i) - print(i) - led.toggle() - sleep(delay) -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - forward.duty_u16(0) - #reverse.duty_u16(0) \ No newline at end of file diff --git a/src/motors/spin-one-motor.py b/src/motors/spin-one-motor.py deleted file mode 100644 index 6981c69d5..000000000 --- a/src/motors/spin-one-motor.py +++ /dev/null @@ -1,24 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -FORWARD_PIN = 16 - -MAX_POWER = 65025 - -forward = PWM(Pin(FORWARD_PIN)) - -counter = 0 -def main(): - while True: - for i in range(0, MAX_POWER, 1000): - print(i) - forward.duty_u16(i) - sleep(.1) - -try: - main() -except KeyboardInterrupt: - print('Got an interrupt.') -finally: - print('Powering down the motor.') - forward.duty_u16(0) \ No newline at end of file diff --git a/src/motors/stepper/picoStepper.py b/src/motors/stepper/picoStepper.py deleted file mode 100644 index 13052c52b..000000000 --- a/src/motors/stepper/picoStepper.py +++ /dev/null @@ -1,58 +0,0 @@ -# .';:cc;. -# .,',;lol::c. -# ;';lddddlclo -# lcloxxoddodxdool:,. -# cxdddxdodxdkOkkkkkkkd:. -# .ldxkkOOOOkkOO000Okkxkkkkx:. -# .lddxkkOkOOO0OOO0000Okxxxxkkkk: -# 'ooddkkkxxkO0000KK00Okxdoodxkkkko -# .ooodxkkxxxOO000kkkO0KOxolooxkkxxkl -# lolodxkkxxkOx,. .lkdolodkkxxxO. -# doloodxkkkOk .... .,cxO; -# ddoodddxkkkk: ,oxxxkOdc'..o' -# :kdddxxxxd, ,lolccldxxxkkOOOkkkko, -# lOkxkkk; :xkkkkkkkkOOO000OOkkOOk. -# ;00Ok' 'O000OO0000000000OOOO0Od. -# .l0l.;OOO000000OOOOOO000000x, -# .'OKKKK00000000000000kc. -# .:ox0KKKKKKK0kdc,. -# ... -# -# Author: peppe8o -# Date: Dec 27th, 2021 -# Version: 1.0 -# https://peppe8o.com - -from machine import Pin -from time import sleep - -# define variables -motor_GP = [0,1,2,3] # RPI Pico ports, ordered according to IN1, IN2, IN3 and IN4 of ULN2003 -seq_pointer=[0,1,2,3,4,5,6,7] # Pointer to keep current sequence position -stepper_obj = [] # array including the 4 Pins connected yo - -# sequence map -arrSeq = [[0,0,0,1],\ - [0,0,1,1],\ - [0,0,1,0],\ - [0,1,1,0],\ - [0,1,0,0],\ - [1,1,0,0],\ - [1,0,0,0],\ - [1,0,0,1]] - - -# Set all pins as output -print("Setup pins...") -for gp in motor_GP: stepper_obj.append(Pin(gp, Pin.OUT)) - -def stepper_move(direction): # direction must be +1 or -1 - global seq_pointer - seq_pointer=seq_pointer[direction:]+seq_pointer[:direction] - for a in range(4): stepper_obj[a].value(arrSeq[seq_pointer[0]][a]) - sleep(0.001) - -while True: - stepper_move(1) - - \ No newline at end of file diff --git a/src/neopixels/01-neopixel-red-move-test.py b/src/neopixels/01-neopixel-red-move-test.py deleted file mode 100644 index 3bdf571e1..000000000 --- a/src/neopixels/01-neopixel-red-move-test.py +++ /dev/null @@ -1,15 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - # red is 10 of 255 - strip[i] = (10,0,0) - strip.write() - sleep(.05) - strip[i] = (0,0,0) diff --git a/src/neopixels/02-neopixel-solid-color-test.py b/src/neopixels/02-neopixel-solid-color-test.py deleted file mode 100644 index 68cc9ff8a..000000000 --- a/src/neopixels/02-neopixel-solid-color-test.py +++ /dev/null @@ -1,28 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 10 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def solid_color(color): - for i in range(0, NUMBER_PIXELS): - strip[i] = color - strip.write() - -delay = 4 -while True: - # red - print('red') - solid_color((255,0,0)) - sleep(delay) - print('green') - solid_color((0,255,0)) - sleep(delay) - print('blue') - solid_color((0,0,255)) - sleep(delay) - print('off') - solid_color((0,0,0)) - sleep(delay) diff --git a/src/neopixels/03-move.py b/src/neopixels/03-move.py deleted file mode 100644 index e47491f6a..000000000 --- a/src/neopixels/03-move.py +++ /dev/null @@ -1,15 +0,0 @@ -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - for i in range(0, NUMBER_PIXELS): - # red is 10 of 255 - strip[i] = (10,0,0) - strip.write() - sleep(.05) - strip[i] = (0,0,0) diff --git a/src/neopixels/04-rainbow-cycle.py b/src/neopixels/04-rainbow-cycle.py deleted file mode 100644 index 873e9d22f..000000000 --- a/src/neopixels/04-rainbow-cycle.py +++ /dev/null @@ -1,39 +0,0 @@ -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(counter, .2) - counter += 1 diff --git a/src/neopixels/05-color-wipe.py b/src/neopixels/05-color-wipe.py deleted file mode 100644 index 054e40fa9..000000000 --- a/src/neopixels/05-color-wipe.py +++ /dev/null @@ -1,33 +0,0 @@ -from neopixel import NeoPixel -from time import sleep - -# most people have a heart rate of around 60-70 beats per minute -# If you add a once second deplay between "beats" you can make and LED -# look like a beating heart. - -NUMBER_PIXELS = 60 -LED_PIN = 0 - -strip = NeoPixel(machine.Pin(LED_PIN), NUMBER_PIXELS) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet, white) - -def color_wipe(): - for color in colors: - for i in range(0, NUMBER_PIXELS): - strip[i] = color - strip.write() - sleep(.01) - sleep(1) - -while True: - color_wipe() diff --git a/src/neopixels/05-rainbow-cycle-8-pixel.py b/src/neopixels/05-rainbow-cycle-8-pixel.py deleted file mode 100644 index f843ed848..000000000 --- a/src/neopixels/05-rainbow-cycle-8-pixel.py +++ /dev/null @@ -1,40 +0,0 @@ -import machine, neopixel -from utime import sleep -from neopixel import Neopixel - -NEOPIXEL_PIN = 14 -NUMBER_PIXELS = 8 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB") -strip.brightness(10) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip.set_pixel((i + counter) % NUMBER_PIXELS, color) - strip.show() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(counter, .2) - counter += 1 diff --git a/src/neopixels/06-neopixel-five-drive-patterns.py b/src/neopixels/06-neopixel-five-drive-patterns.py deleted file mode 100644 index e24fd794c..000000000 --- a/src/neopixels/06-neopixel-five-drive-patterns.py +++ /dev/null @@ -1,144 +0,0 @@ -''' -Five drive patterns -1 - idle - rainbow moving -2 - forward - white going front (7) to back (0) -3 - reverse - blue boing back (0) to front (7) -4 - right turn - blink red -5 - left turn - blink green -''' -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 2 -NUMBER_PIXELS = 8 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) -BLACK = (0, 0, 0) -RED = (255, 0, 0) -LIGHT_RED = (15, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -LIGHT_GREEN = (0, 25, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -LIGHT_BLUE = (0, 0, 25) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -GRAY = (50, 50, 50) -LIGHT_GRAY = (10, 10, 10) -OFF = (0, 0, 0) -COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def idle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -def forward(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == NUMBER_PIXELS - pixel_index - 1: - strip[i] = LIGHT_GRAY - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def reverse(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS): - if i == pixel_index: - strip[i] = LIGHT_BLUE - else: - strip[i] = OFF - strip.write() - sleep(wait) - -def right(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_RED - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def left(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - pixel_index = counter % NUMBER_PIXELS - if counter % 2: - for i in range(0, NUMBER_PIXELS): - strip[i] = LIGHT_GREEN - else: - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - sleep(wait) - -def all_off(): - for i in range(0, NUMBER_PIXELS): - strip[i] = OFF - strip.write() - -counter = 0 -between_pattern_delay = 1 -while True: - for i in range(8): - print('Idle', counter) - idle(counter, .4) - counter += 1 - all_off() - sleep(between_pattern_delay) - - for i in range(8): - print('Forward', counter) - forward(counter, .2) - counter += 1 - all_off() - sleep(between_pattern_delay) - - for i in range(8): - print('Reverse', counter) - reverse(counter, .2) - counter += 1 - all_off() - sleep(between_pattern_delay) - - for i in range(8): - print('Right', counter) - right(counter, .4) - counter += 1 - all_off() - sleep(between_pattern_delay) - - for i in range(8): - print('Left', counter) - left(counter, .4) - counter += 1 - all_off() - sleep(between_pattern_delay) \ No newline at end of file diff --git a/src/neopixels/08-random-colors.py b/src/neopixels/08-random-colors.py deleted file mode 100644 index dca10e19d..000000000 --- a/src/neopixels/08-random-colors.py +++ /dev/null @@ -1,57 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep -from urandom import randint -# https://docs.micropython.org/en/latest/library/random.html - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -# cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# offset should be incremented by one for motion -def draw_random_color(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - draw_random_color() - sleep(.1) diff --git a/src/neopixels/10-moving-rainbow.py b/src/neopixels/10-moving-rainbow.py deleted file mode 100644 index ac8b1522c..000000000 --- a/src/neopixels/10-moving-rainbow.py +++ /dev/null @@ -1,55 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -RAINBOW_LENGTH = 7 -PERCENT_COLOR_WHEEL = round(255/RAINBOW_LENGTH) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -counter = 0 -while True: - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - print('off:', counter-1) - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(.05) - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS diff --git a/src/neopixels/11-candle.py b/src/neopixels/11-candle.py deleted file mode 100644 index 38378ac6e..000000000 --- a/src/neopixels/11-candle.py +++ /dev/null @@ -1,24 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep -from urandom import randint -# https://docs.micropython.org/en/latest/library/random.html - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def candle(delay): - for i in range(0, NUMBER_PIXELS): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -counter = 0 -while True: - candle(.01) - # wrap - counter = counter % (NUMBER_PIXELS-1) - counter += 1 \ No newline at end of file diff --git a/src/neopixels/25-modes.py b/src/neopixels/25-modes.py deleted file mode 100644 index 11dbf3ec4..000000000 --- a/src/neopixels/25-modes.py +++ /dev/null @@ -1,217 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixelgrb import NeoPixel2 -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 50 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel2(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle(delay): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -def random_color(delay): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, wait): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -# Global variables -mode = 11 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .05) - elif mode == 2: - move_dot(counter, green, .05) - elif mode == 3: - move_dot(counter, blue, .05) - elif mode == 4: - comet_tail(counter, red, .01) - elif mode == 5: - comet_tail(counter, green, .01) - elif mode == 6: - comet_tail(counter, blue, .01) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .15) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS diff --git a/src/neopixels/4th-of-july-colors.py b/src/neopixels/4th-of-july-colors.py deleted file mode 100644 index b771f9b6b..000000000 --- a/src/neopixels/4th-of-july-colors.py +++ /dev/null @@ -1,286 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = 16 # len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle(delay): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -def random_color(delay): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - sleep(delay) - -def random_red_white_blue(delay): - for i in range(0,10): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 3) - if random_color < 1: - strip[random_offset] = red - elif random_color < 2: - strip[random_offset] = white - elif random_color < 3: - strip[random_offset] = blue - strip.write() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -delay = .05 -while True: - # print only on change - if mode != last_mode: - # print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, delay) - elif mode == 1: - move_dot(counter, red, delay) - elif mode == 2: - move_dot(counter, white, delay) - elif mode == 3: - move_dot(counter, blue, delay) - elif mode == 4: - comet_tail(counter, red, .005) - elif mode == 5: - comet_tail(counter, white, .005) - elif mode == 6: - comet_tail(counter, blue, .005) - elif mode == 8: - random_red_white_blue(.01) - elif mode == 9: - bounce(counter, red, .10) - elif mode == 10: - bounce(counter, white, .10) - elif mode == 11: - bounce(counter, blue, .10) - elif mode == 12: - running_lights(counter, red, 4, .2) - elif mode == 13: - running_lights(counter, white, 4, .2) - elif mode == 14: - running_lights(counter, blue, 4, .2) - elif mode == 15: - rainbow_cycle(counter, .05) - elif mode == 16: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter == NUMBER_PIXELS: - counter = counter % NUMBER_PIXELS - mode += 1 - if mode == 16: - mode = 0 diff --git a/src/neopixels/comet-tail.py b/src/neopixels/comet-tail.py deleted file mode 100644 index a56218365..000000000 --- a/src/neopixels/comet-tail.py +++ /dev/null @@ -1,67 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -# cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# offset should be incremented by one for motion -def draw_comet_tail(offset, color, delay): - offset = offset % NUMBER_PIXELS - for i in range(0, color_count): - target = ((level_count - i - 1) + offset) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - if offset > 0: - strip[offset-1] = (0,0,0) - if offset == NUMBER_PIXELS-1: - strip[offset] = (0,0,0) - strip.write() - sleep(delay) - - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - for color_index in range(0, color_count): - for i in range(0, NUMBER_PIXELS): - draw_comet_tail(counter, colors[color_index], .001) - counter += 1 - print(counter) diff --git a/src/neopixels/main-demo.py b/src/neopixels/main-demo.py deleted file mode 100644 index 6f199b87f..000000000 --- a/src/neopixels/main-demo.py +++ /dev/null @@ -1,276 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle_rnd(): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - -def candle(delay): - for i in range(0, 5): - candle_rnd() - sleep(delay) - -def random_color_pixel(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - - -def random_color(delay): - for i in range(0, 5): - random_color_pixel() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) - -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .03) - elif mode == 2: - move_dot(counter, green, .03) - elif mode == 3: - move_dot(counter, blue, .03) - elif mode == 4: - comet_tail(counter, red, .003) - elif mode == 5: - comet_tail(counter, green, .003) - elif mode == 6: - comet_tail(counter, blue, .003) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .1) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .03) - elif mode == 12: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter > NUMBER_PIXELS -1 : - counter = 0 - mode += 1 - if mode > mode_count - 2: - mode = 0 diff --git a/src/neopixels/main-w.py b/src/neopixels/main-w.py deleted file mode 100644 index 6f199b87f..000000000 --- a/src/neopixels/main-w.py +++ /dev/null @@ -1,276 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle_rnd(): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - -def candle(delay): - for i in range(0, 5): - candle_rnd() - sleep(delay) - -def random_color_pixel(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - - -def random_color(delay): - for i in range(0, 5): - random_color_pixel() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) - -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .03) - elif mode == 2: - move_dot(counter, green, .03) - elif mode == 3: - move_dot(counter, blue, .03) - elif mode == 4: - comet_tail(counter, red, .003) - elif mode == 5: - comet_tail(counter, green, .003) - elif mode == 6: - comet_tail(counter, blue, .003) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .1) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .03) - elif mode == 12: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - if counter > NUMBER_PIXELS -1 : - counter = 0 - mode += 1 - if mode > mode_count - 2: - mode = 0 diff --git a/src/neopixels/main.py b/src/neopixels/main.py deleted file mode 100644 index 2ebc174b9..000000000 --- a/src/neopixels/main.py +++ /dev/null @@ -1,262 +0,0 @@ -# moving rainbow -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -RAINBOW_LENGTH = 7 -PERCENT_SMALL_COLOR_WHEEL = round(255/RAINBOW_LENGTH) -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -BUTTON_PIN_1 = 15 -BUTTON_PIN_2 = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail - -button1 = machine.Pin(BUTTON_PIN_1, machine.Pin.IN, machine.Pin.PULL_DOWN) -button2 = machine.Pin(BUTTON_PIN_2, machine.Pin.IN, machine.Pin.PULL_DOWN) - -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -mode_list = ['moving rainbow', 'moving red dot', 'moving blue dot', 'moving green dot', - 'red commet', 'blue commet', 'green commet', 'candle flicker', 'random dots', 'bounce', - 'running lights', 'rainbow cycle', 'cylon scanner'] -mode_count = len(mode_list) - -# This function gets called every time the button is pressed. The parameter "pin" is used to tell -# which pin is used -def button_pressed_handler(pin): - global mode, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - # this is a hack but I can't get the pin ID parameter without vars() or attr() - pin_num = int(str(pin)[4:6]) - # this works as long as one of the buttons is this one - if pin_num == BUTTON_PIN_1: - mode +=1 - else: - mode -=1 - # wrap around if we get too high - mode = mode % mode_count - last_time = new_time - -# now we register the handler function when the button is pressed -button1.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -button2.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# erase the entire strip -def erase(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def move_dot(counter, color, delay): - strip[counter] = color - strip.write() - sleep(delay) - strip[counter] = (0,0,0) - -def comet_tail(counter, color, delay): - for i in range(0, color_count): - # we start to draw at the head of the commet N levels away from the counter - target = ((level_count - i - 1) + counter) % NUMBER_PIXELS - # number to scale by - scale = (levels[i] / 255) - strip[target] = (int(color[0]*scale), int(color[1]*scale), int(color[2]*scale)) - # erase the tail - if counter > 0: - strip[counter-1] = (0,0,0) - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - strip.write() - sleep(delay) - -def moving_rainbow(counter, delay): - for i in range(0, RAINBOW_LENGTH-1): - color_index = round(i*PERCENT_SMALL_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - # start at the end and subtract to go backwards and add the counter for offset - index = RAINBOW_LENGTH-1 - i + counter - # print(index) - if index < NUMBER_PIXELS: - strip[index] = color - strip.write() - # erase the tail if we are not at the start - if counter > 0: - strip[counter-1] = (0,0,0) - strip.write() - # turn off the last pixel at the top - if counter == NUMBER_PIXELS-1: - strip[counter] = (0,0,0) - sleep(delay) - -def candle(delay): - green = 50 + randint(0,155) - red = green + randint(0,50) - strip[randint(0,NUMBER_PIXELS - 1)] = (red, green, 0) - strip.write() - sleep(delay) - -def random_color(delay): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - sleep(delay) - -HALF_LENGTH = round(NUMBER_PIXELS/2) -def bounce(counter, color, delay): - if counter < HALF_LENGTH: - strip[counter] = color - strip[NUMBER_PIXELS-1 - counter] = color - strip.write() - strip[counter] = (0,0,0) - strip[NUMBER_PIXELS-1 - counter] = (0,0,0) - sleep(delay) - else: - half_counter = counter - HALF_LENGTH - strip[HALF_LENGTH - half_counter] = color - strip[HALF_LENGTH + half_counter] = color - strip.write() - strip[HALF_LENGTH - half_counter] = (0,0,0) - strip[HALF_LENGTH + half_counter] = (0,0,0) - sleep(delay) - -def running_lights(counter, color, spacing, delay): - for i in range(0, NUMBER_PIXELS): - if (counter+i) % spacing: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - sleep(delay) - -def rainbow_cycle(counter, delay): - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(delay) - -# 0=fwd, 1=rev -state = 0 -def cylon_scanner(delay): - global counter, state - if state == 0: - #print('going forward', counter) - strip[counter] = red_light - strip[counter+1] = red_med - strip[counter+2] = red - strip[counter+3] = red_med - strip[counter+4] = red_light - # erase the tail - if counter > 0: strip[counter-1] = off - strip.write() - sleep(delay) - # reverse direction - if counter == NUMBER_PIXELS-5: - state = 1 - counter = 0 - #print('go to reverse', state) - return - else: - i = NUMBER_PIXELS-counter - 5 - #print('in reverse c=', counter, 'i=', i) - strip[i] = red_light - strip[i+1] = red_med - strip[i+2] = red - strip[i+3] = red_med - strip[i+4] = red_light - strip.write() - sleep(delay) - # turn off as we move in reverse - if i < NUMBER_PIXELS-2: - strip[i+4] = off - if i == NUMBER_PIXELS - 6: - strip[NUMBER_PIXELS-1] = off - if i == 0: - state = 0 - counter = 0 - #print('switching to forward', counter) -# Global variables -mode = 0 -counter = 0 -last_mode = 1 -while True: - # print only on change - if mode != last_mode: - print('mode=', mode, 'running program', mode_list[mode]) - last_mode = mode - if mode == 0: - moving_rainbow(counter, .05) - elif mode == 1: - move_dot(counter, red, .05) - elif mode == 2: - move_dot(counter, green, .05) - elif mode == 3: - move_dot(counter, blue, .05) - elif mode == 4: - comet_tail(counter, red, .01) - elif mode == 5: - comet_tail(counter, green, .01) - elif mode == 6: - comet_tail(counter, blue, .01) - elif mode == 7: - candle(.01) - elif mode == 8: - random_color(.01) - elif mode == 9: - bounce(counter, red, .15) - elif mode == 10: - running_lights(counter, blue, 4, .2) - elif mode == 11: - rainbow_cycle(counter, .05) - elif mode == 12: - cylon_scanner(.05) - else: - print('mode', mode, 'not configured') - - counter += 1 - # wrap the counter using modulo - counter = counter % NUMBER_PIXELS diff --git a/src/neopixels/matrix/13-matrix-count.py b/src/neopixels/matrix/13-matrix-count.py deleted file mode 100644 index 4d9ef8018..000000000 --- a/src/neopixels/matrix/13-matrix-count.py +++ /dev/null @@ -1,32 +0,0 @@ -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 256 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) -delay = .05 -brightness = 20 -counter = 0 -while True: - for i in range(0, NUMBER_PIXELS): - strip[i] = (brightness, 0 ,0) - if i > 0: - strip[i-1] = (0, 0 ,0) - strip.write() - sleep(delay) - for i in range(0, NUMBER_PIXELS): - strip[i] = (0, brightness ,0) - if i > 0: - strip[i-1] = (0, 0 ,0) - strip.write() - sleep(delay) - for i in range(0, NUMBER_PIXELS): - strip[i] = (0, 0 ,brightness) - if i > 0: - strip[i-1] = (0, 0 ,0) - strip.write() - sleep(delay) - diff --git a/src/neopixels/matrix/14-matrix-rainbow.py b/src/neopixels/matrix/14-matrix-rainbow.py deleted file mode 100644 index 0ecb3b092..000000000 --- a/src/neopixels/matrix/14-matrix-rainbow.py +++ /dev/null @@ -1,39 +0,0 @@ -import machine -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 256 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(counter, wait): - global NUMBER_PIXELS, PERCENT_COLOR_WHEEL - for i in range(0, NUMBER_PIXELS): - color_index = round(i*PERCENT_COLOR_WHEEL) - color = wheel(color_index) - # print(color_index, color) - strip[(i + counter) % NUMBER_PIXELS] = color - strip.write() - sleep(wait) - -counter = 0 -offset = 0 -while True: - print('Running cycle', counter) - rainbow_cycle(counter, .05) - counter += 1 diff --git a/src/neopixels/matrix/15-bounce-test.py b/src/neopixels/matrix/15-bounce-test.py deleted file mode 100644 index 82a327fd9..000000000 --- a/src/neopixels/matrix/15-bounce-test.py +++ /dev/null @@ -1,58 +0,0 @@ -# Bounce a ball around a NeoPixel Matrix -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# matrix = [[0 for _ in range(cols)] for _ in range(rows)] -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def write_pixel(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - strip[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - strip[x*ROWS + y] = value - -def show(): - strip.write() - -brightness=1 -x=0 -y=0 -dx = 1 -dy = 1 -counter = 0 -while True: - if x <= 0: - dx = 1 - if y <= 0: - dy = 1 - if x >= COLS-1: - dx = -1 - if y >= ROWS-1: - dy = -1 - print(x,y) - if counter < 100: - write_pixel(x, y, (brightness,0,0)) # blue - elif counter < 200: - write_pixel(x, y, (0,brightness,0)) # blue - elif counter < 300: - write_pixel(x, y, (0,0,brightness)) # blue - show() - x += dx - y += dy - counter += 1 - if counter > 300: - counter = 0 - if not counter % 150: - x += 1 - sleep(.1) diff --git a/src/neopixels/matrix/16-rainbow.py b/src/neopixels/matrix/16-rainbow.py deleted file mode 100644 index eb5f70ae7..000000000 --- a/src/neopixels/matrix/16-rainbow.py +++ /dev/null @@ -1,55 +0,0 @@ -# import MatrixBuffer - -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -# how many steps to get through the color wheel of 256 colors -COLOR_WHEEL_STEP = round(256/COLS) - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# matrix = [[0 for _ in range(cols)] for _ in range(rows)] -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -def write_pixel(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - strip[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - strip[x*ROWS + y] = value - -def show(): - strip.write() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -print('Color Wheel Step:', COLOR_WHEEL_STEP) -counter = 0 -while True: - for x in range(0, COLS): - for y in range(0, ROWS): - # * PERCENT_COLOR_WHEEL - write_pixel(x, y, wheel((x*COLOR_WHEEL_STEP + y*COLOR_WHEEL_STEP - counter*8) % 256)) - strip.write() - counter += 1 - - \ No newline at end of file diff --git a/src/neopixels/matrix/16-text-scroll-test.py b/src/neopixels/matrix/16-text-scroll-test.py deleted file mode 100644 index 1bb41c3ad..000000000 --- a/src/neopixels/matrix/16-text-scroll-test.py +++ /dev/null @@ -1,67 +0,0 @@ -# LED Matrix message scroller demo. - -import bitmapfont -import machine -import utime -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -matrix = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def fill(val): - for i in range(0, NUMBER_PIXELS): - matrix[i] = val - -# Configuration: -DISPLAY_WIDTH = 32 # Display width in pixels. -DISPLAY_HEIGHT = 8 # Display height in pixels. -SPEED = 20.0 # Scroll speed in pixels per second. - -def show(): - matrix.write() - -def write_pixel_value(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - matrix[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - matrix[x*ROWS + y] = value - -def write_pixel(x, y): - write_pixel_value(x, y, (1,1,2)) - -def scroll_text(message): - - with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, write_pixel) as bf: - # Global state: - pos = DISPLAY_WIDTH # X position of the message start. - message_width = bf.width(message) # Message width in pixels. - last = utime.ticks_ms() # Last frame millisecond tick time. - speed_ms = SPEED / 1000.0 # Scroll speed in pixels/ms. - # Main loop: - while True: - # Compute the time delta in milliseconds since the last frame. - current = utime.ticks_ms() - delta_ms = utime.ticks_diff(current, last) - last = current - # Compute position using speed and time delta. - pos -= speed_ms*delta_ms - if pos < -message_width: - pos = DISPLAY_WIDTH - # Clear the matrix and draw the text at the current position. - fill((0,0,0)) - bf.text(message, int(pos), 0) - # Update the matrix LEDs. - show() - # Sleep a bit to give USB mass storage some processing time (quirk - # of SAMD21 firmware right now). - utime.sleep_ms(20) - -write_pixel(0,0) -show() -#scroll_text('Dan Loves Ann!') -scroll_text('MicroPython Rocks') \ No newline at end of file diff --git a/src/neopixels/matrix/17-banner-rgb-rainbow.py b/src/neopixels/matrix/17-banner-rgb-rainbow.py deleted file mode 100644 index 2a6c172ef..000000000 --- a/src/neopixels/matrix/17-banner-rgb-rainbow.py +++ /dev/null @@ -1,126 +0,0 @@ -# import MatrixBuffer -import bitmapfont -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, sleep_ms, ticks_ms, ticks_diff - -NEOPIXEL_PIN = 0 -ROWS = 8 -COLS = 32 -NUMBER_PIXELS = ROWS * COLS -# how many steps to get through the color wheel of 256 colors -COLOR_WHEEL_STEP = round(256/COLS) - -matrix = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# Configuration: -DISPLAY_WIDTH = 32 # Display width in pixels. -DISPLAY_HEIGHT = 8 # Display height in pixels. -SPEED = 20.0 # Scroll speed in pixels per second -SPEED_MS = SPEED / 1000.0 # Scroll speed in pixels/ms - -# matrix = [[0 for _ in range(cols)] for _ in range(rows)] -def clear(): - for i in range(0, NUMBER_PIXELS): - matrix[i] = (0,0,0) - matrix.write() - -def write_pixel(x, y, value): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - matrix[(x+1)*ROWS - y - 1] = value - else: # even count rows, 0, 2, 4 the wire goes from the top down up - matrix[x*ROWS + y] = value - -def show(): - matrix.write() - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_index(counter): - for x in range(0, COLS): - for y in range(0, ROWS): - # * PERCENT_COLOR_WHEEL - write_pixel_color_param(x, y, wheel((x*COLOR_WHEEL_STEP + y*COLOR_WHEEL_STEP - counter*8) % 256)) - matrix.write() - -def rainbow_delay(delay): - for i in range(0,DISPLAY_WIDTH): - rainbow_index(i) - sleep(delay/100) - -def write_pixel_color(x, y): - global font_color - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - matrix[(x+1)*ROWS - y - 1] = font_color - else: # even count rows, 0, 2, 4 the wire goes from the top down up - matrix[x*ROWS + y] = font_color - -def write_pixel_color_param(x, y, font_color): - if y >= 0 and y < ROWS and x >=0 and x < COLS: - # odd count rows 1, 3, 5 the wire goes from bottup - if x % 2: - matrix[(x+1)*ROWS - y - 1] = font_color - else: # even count rows, 0, 2, 4 the wire goes from the top down up - matrix[x*ROWS + y] = font_color - -def fill(val): - for i in range(0, NUMBER_PIXELS): - matrix[i] = val - -def scroll_text(message, counter): - - with bitmapfont.BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, write_pixel_color) as bf: - # Global state: - pos = DISPLAY_WIDTH # X position of the message start. - message_width = bf.width(message) # Message width in pixels. - last = ticks_ms() # Last frame millisecond tick time. - - # Main loop: - for i in range(0, message_width): - # Compute the time delta in milliseconds since the last frame. - current = ticks_ms() - delta_ms = ticks_diff(current, last) - last = current - # Compute position using speed and time delta. - pos -= SPEED_MS*delta_ms - if pos < -message_width: - pos = DISPLAY_WIDTH - # Clear the matrix and draw the text at the current position. - fill((0,0,0)) - bf.text(message, int(pos), 0) - # Update the matrix LEDs. - show() - # Sleep a bit to give USB mass storage some processing time (quirk - # of SAMD21 firmware right now). - sleep_ms(20) - -counter = 0 -font_color = (10,10,10) -while True: - font_color = (255,0,0) - #scroll_text('Code Savvy Rocks!', counter) - font_color = (0,255,0) - #scroll_text('Code Savvy Rocks!', counter) - font_color = (0,0,255) - scroll_text('Code Savvy Rocks!', counter) - counter += 1 - rainbow_delay(1) - print(counter) - if counter > DISPLAY_WIDTH: - counter = 0 - \ No newline at end of file diff --git a/src/neopixels/matrix/bitmapfont.py b/src/neopixels/matrix/bitmapfont.py deleted file mode 100644 index 3f10ca1cc..000000000 --- a/src/neopixels/matrix/bitmapfont.py +++ /dev/null @@ -1,69 +0,0 @@ -# MicroPython basic bitmap font renderer. -# Author: Tony DiCola -# License: MIT License (https://opensource.org/licenses/MIT) -try: - import ustruct -except ImportError: - import struct as ustruct - - -class BitmapFont: - - def __init__(self, width, height, pixel, font_name='font5x8.bin'): - # Specify the drawing area width and height, and the pixel function to - # call when drawing pixels (should take an x and y param at least). - # Optionally specify font_name to override the font file to use (default - # is font5x8.bin). The font format is a binary file with the following - # format: - # - 1 unsigned byte: font character width in pixels - # - 1 unsigned byte: font character height in pixels - # - x bytes: font data, in ASCII order covering all 255 characters. - # Each character should have a byte for each pixel column of - # data (i.e. a 5x8 font has 5 bytes per character). - self._width = width - self._height = height - self._pixel = pixel - self._font_name = font_name - - def init(self): - # Open the font file and grab the character width and height values. - # Note that only fonts up to 8 pixels tall are currently supported. - self._font = open(self._font_name, 'rb') - self._font_width, self._font_height = ustruct.unpack('BB', self._font.read(2)) - - def deinit(self): - # Close the font file as cleanup. - self._font.close() - - def __enter__(self): - self.init() - return self - - def __exit__(self, exception_type, exception_value, traceback): - self.deinit() - - def draw_char(self, ch, x, y, *args, **kwargs): - # Don't draw the character if it will be clipped off the visible area. - if x < -self._font_width or x >= self._width or \ - y < -self._font_height or y >= self._height: - return - # Go through each column of the character. - for char_x in range(self._font_width): - # Grab the byte for the current column of font data. - self._font.seek(2 + (ord(ch) * self._font_width) + char_x) - line = ustruct.unpack('B', self._font.read(1))[0] - # Go through each row in the column byte. - for char_y in range(self._font_height): - # Draw a pixel for each bit that's flipped on. - if (line >> char_y) & 0x1: - self._pixel(x + char_x, y + char_y, *args, **kwargs) - - def text(self, text, x, y, *args, **kwargs): - # Draw the specified text at the specified location. - for i in range(len(text)): - self.draw_char(text[i], x + (i * (self._font_width + 1)), y, - *args, **kwargs) - - def width(self, text): - # Return the pixel width of the specified text message. - return len(text) * (self._font_width + 1) \ No newline at end of file diff --git a/src/neopixels/matrix/gfx-to-bin.py b/src/neopixels/matrix/gfx-to-bin.py deleted file mode 100644 index d015e405b..000000000 --- a/src/neopixels/matrix/gfx-to-bin.py +++ /dev/null @@ -1,271 +0,0 @@ -# Quick script to convert Adafruit GFX font into binary file. -# Author: Tony DiCola -# License: MIT (https://opensource.org/licenses/MIT) -# Taken from glcdfont.c from Adafruit GFX Arduino library. -FONT = bytes(( - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, - 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, - 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, - 0x18, 0x3C, 0x7E, 0x3C, 0x18, - 0x1C, 0x57, 0x7D, 0x57, 0x1C, - 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, - 0x00, 0x18, 0x3C, 0x18, 0x00, - 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, - 0x00, 0x18, 0x24, 0x18, 0x00, - 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, - 0x30, 0x48, 0x3A, 0x06, 0x0E, - 0x26, 0x29, 0x79, 0x29, 0x26, - 0x40, 0x7F, 0x05, 0x05, 0x07, - 0x40, 0x7F, 0x05, 0x25, 0x3F, - 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, - 0x7F, 0x3E, 0x1C, 0x1C, 0x08, - 0x08, 0x1C, 0x1C, 0x3E, 0x7F, - 0x14, 0x22, 0x7F, 0x22, 0x14, - 0x5F, 0x5F, 0x00, 0x5F, 0x5F, - 0x06, 0x09, 0x7F, 0x01, 0x7F, - 0x00, 0x66, 0x89, 0x95, 0x6A, - 0x60, 0x60, 0x60, 0x60, 0x60, - 0x94, 0xA2, 0xFF, 0xA2, 0x94, - 0x08, 0x04, 0x7E, 0x04, 0x08, - 0x10, 0x20, 0x7E, 0x20, 0x10, - 0x08, 0x08, 0x2A, 0x1C, 0x08, - 0x08, 0x1C, 0x2A, 0x08, 0x08, - 0x1E, 0x10, 0x10, 0x10, 0x10, - 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, - 0x30, 0x38, 0x3E, 0x38, 0x30, - 0x06, 0x0E, 0x3E, 0x0E, 0x06, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x5F, 0x00, 0x00, - 0x00, 0x07, 0x00, 0x07, 0x00, - 0x14, 0x7F, 0x14, 0x7F, 0x14, - 0x24, 0x2A, 0x7F, 0x2A, 0x12, - 0x23, 0x13, 0x08, 0x64, 0x62, - 0x36, 0x49, 0x56, 0x20, 0x50, - 0x00, 0x08, 0x07, 0x03, 0x00, - 0x00, 0x1C, 0x22, 0x41, 0x00, - 0x00, 0x41, 0x22, 0x1C, 0x00, - 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, - 0x08, 0x08, 0x3E, 0x08, 0x08, - 0x00, 0x80, 0x70, 0x30, 0x00, - 0x08, 0x08, 0x08, 0x08, 0x08, - 0x00, 0x00, 0x60, 0x60, 0x00, - 0x20, 0x10, 0x08, 0x04, 0x02, - 0x3E, 0x51, 0x49, 0x45, 0x3E, - 0x00, 0x42, 0x7F, 0x40, 0x00, - 0x72, 0x49, 0x49, 0x49, 0x46, - 0x21, 0x41, 0x49, 0x4D, 0x33, - 0x18, 0x14, 0x12, 0x7F, 0x10, - 0x27, 0x45, 0x45, 0x45, 0x39, - 0x3C, 0x4A, 0x49, 0x49, 0x31, - 0x41, 0x21, 0x11, 0x09, 0x07, - 0x36, 0x49, 0x49, 0x49, 0x36, - 0x46, 0x49, 0x49, 0x29, 0x1E, - 0x00, 0x00, 0x14, 0x00, 0x00, - 0x00, 0x40, 0x34, 0x00, 0x00, - 0x00, 0x08, 0x14, 0x22, 0x41, - 0x14, 0x14, 0x14, 0x14, 0x14, - 0x00, 0x41, 0x22, 0x14, 0x08, - 0x02, 0x01, 0x59, 0x09, 0x06, - 0x3E, 0x41, 0x5D, 0x59, 0x4E, - 0x7C, 0x12, 0x11, 0x12, 0x7C, - 0x7F, 0x49, 0x49, 0x49, 0x36, - 0x3E, 0x41, 0x41, 0x41, 0x22, - 0x7F, 0x41, 0x41, 0x41, 0x3E, - 0x7F, 0x49, 0x49, 0x49, 0x41, - 0x7F, 0x09, 0x09, 0x09, 0x01, - 0x3E, 0x41, 0x41, 0x51, 0x73, - 0x7F, 0x08, 0x08, 0x08, 0x7F, - 0x00, 0x41, 0x7F, 0x41, 0x00, - 0x20, 0x40, 0x41, 0x3F, 0x01, - 0x7F, 0x08, 0x14, 0x22, 0x41, - 0x7F, 0x40, 0x40, 0x40, 0x40, - 0x7F, 0x02, 0x1C, 0x02, 0x7F, - 0x7F, 0x04, 0x08, 0x10, 0x7F, - 0x3E, 0x41, 0x41, 0x41, 0x3E, - 0x7F, 0x09, 0x09, 0x09, 0x06, - 0x3E, 0x41, 0x51, 0x21, 0x5E, - 0x7F, 0x09, 0x19, 0x29, 0x46, - 0x26, 0x49, 0x49, 0x49, 0x32, - 0x03, 0x01, 0x7F, 0x01, 0x03, - 0x3F, 0x40, 0x40, 0x40, 0x3F, - 0x1F, 0x20, 0x40, 0x20, 0x1F, - 0x3F, 0x40, 0x38, 0x40, 0x3F, - 0x63, 0x14, 0x08, 0x14, 0x63, - 0x03, 0x04, 0x78, 0x04, 0x03, - 0x61, 0x59, 0x49, 0x4D, 0x43, - 0x00, 0x7F, 0x41, 0x41, 0x41, - 0x02, 0x04, 0x08, 0x10, 0x20, - 0x00, 0x41, 0x41, 0x41, 0x7F, - 0x04, 0x02, 0x01, 0x02, 0x04, - 0x40, 0x40, 0x40, 0x40, 0x40, - 0x00, 0x03, 0x07, 0x08, 0x00, - 0x20, 0x54, 0x54, 0x78, 0x40, - 0x7F, 0x28, 0x44, 0x44, 0x38, - 0x38, 0x44, 0x44, 0x44, 0x28, - 0x38, 0x44, 0x44, 0x28, 0x7F, - 0x38, 0x54, 0x54, 0x54, 0x18, - 0x00, 0x08, 0x7E, 0x09, 0x02, - 0x18, 0xA4, 0xA4, 0x9C, 0x78, - 0x7F, 0x08, 0x04, 0x04, 0x78, - 0x00, 0x44, 0x7D, 0x40, 0x00, - 0x20, 0x40, 0x40, 0x3D, 0x00, - 0x7F, 0x10, 0x28, 0x44, 0x00, - 0x00, 0x41, 0x7F, 0x40, 0x00, - 0x7C, 0x04, 0x78, 0x04, 0x78, - 0x7C, 0x08, 0x04, 0x04, 0x78, - 0x38, 0x44, 0x44, 0x44, 0x38, - 0xFC, 0x18, 0x24, 0x24, 0x18, - 0x18, 0x24, 0x24, 0x18, 0xFC, - 0x7C, 0x08, 0x04, 0x04, 0x08, - 0x48, 0x54, 0x54, 0x54, 0x24, - 0x04, 0x04, 0x3F, 0x44, 0x24, - 0x3C, 0x40, 0x40, 0x20, 0x7C, - 0x1C, 0x20, 0x40, 0x20, 0x1C, - 0x3C, 0x40, 0x30, 0x40, 0x3C, - 0x44, 0x28, 0x10, 0x28, 0x44, - 0x4C, 0x90, 0x90, 0x90, 0x7C, - 0x44, 0x64, 0x54, 0x4C, 0x44, - 0x00, 0x08, 0x36, 0x41, 0x00, - 0x00, 0x00, 0x77, 0x00, 0x00, - 0x00, 0x41, 0x36, 0x08, 0x00, - 0x02, 0x01, 0x02, 0x04, 0x02, - 0x3C, 0x26, 0x23, 0x26, 0x3C, - 0x1E, 0xA1, 0xA1, 0x61, 0x12, - 0x3A, 0x40, 0x40, 0x20, 0x7A, - 0x38, 0x54, 0x54, 0x55, 0x59, - 0x21, 0x55, 0x55, 0x79, 0x41, - 0x22, 0x54, 0x54, 0x78, 0x42, # a-umlaut - 0x21, 0x55, 0x54, 0x78, 0x40, - 0x20, 0x54, 0x55, 0x79, 0x40, - 0x0C, 0x1E, 0x52, 0x72, 0x12, - 0x39, 0x55, 0x55, 0x55, 0x59, - 0x39, 0x54, 0x54, 0x54, 0x59, - 0x39, 0x55, 0x54, 0x54, 0x58, - 0x00, 0x00, 0x45, 0x7C, 0x41, - 0x00, 0x02, 0x45, 0x7D, 0x42, - 0x00, 0x01, 0x45, 0x7C, 0x40, - 0x7D, 0x12, 0x11, 0x12, 0x7D, # A-umlaut - 0xF0, 0x28, 0x25, 0x28, 0xF0, - 0x7C, 0x54, 0x55, 0x45, 0x00, - 0x20, 0x54, 0x54, 0x7C, 0x54, - 0x7C, 0x0A, 0x09, 0x7F, 0x49, - 0x32, 0x49, 0x49, 0x49, 0x32, - 0x3A, 0x44, 0x44, 0x44, 0x3A, # o-umlaut - 0x32, 0x4A, 0x48, 0x48, 0x30, - 0x3A, 0x41, 0x41, 0x21, 0x7A, - 0x3A, 0x42, 0x40, 0x20, 0x78, - 0x00, 0x9D, 0xA0, 0xA0, 0x7D, - 0x3D, 0x42, 0x42, 0x42, 0x3D, # O-umlaut - 0x3D, 0x40, 0x40, 0x40, 0x3D, - 0x3C, 0x24, 0xFF, 0x24, 0x24, - 0x48, 0x7E, 0x49, 0x43, 0x66, - 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, - 0xFF, 0x09, 0x29, 0xF6, 0x20, - 0xC0, 0x88, 0x7E, 0x09, 0x03, - 0x20, 0x54, 0x54, 0x79, 0x41, - 0x00, 0x00, 0x44, 0x7D, 0x41, - 0x30, 0x48, 0x48, 0x4A, 0x32, - 0x38, 0x40, 0x40, 0x22, 0x7A, - 0x00, 0x7A, 0x0A, 0x0A, 0x72, - 0x7D, 0x0D, 0x19, 0x31, 0x7D, - 0x26, 0x29, 0x29, 0x2F, 0x28, - 0x26, 0x29, 0x29, 0x29, 0x26, - 0x30, 0x48, 0x4D, 0x40, 0x20, - 0x38, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x38, - 0x2F, 0x10, 0xC8, 0xAC, 0xBA, - 0x2F, 0x10, 0x28, 0x34, 0xFA, - 0x00, 0x00, 0x7B, 0x00, 0x00, - 0x08, 0x14, 0x2A, 0x14, 0x22, - 0x22, 0x14, 0x2A, 0x14, 0x08, - 0x55, 0x00, 0x55, 0x00, 0x55, # #176 (25% block) missing in old code - 0xAA, 0x55, 0xAA, 0x55, 0xAA, # 50% block - 0xFF, 0x55, 0xFF, 0x55, 0xFF, # 75% block - 0x00, 0x00, 0x00, 0xFF, 0x00, - 0x10, 0x10, 0x10, 0xFF, 0x00, - 0x14, 0x14, 0x14, 0xFF, 0x00, - 0x10, 0x10, 0xFF, 0x00, 0xFF, - 0x10, 0x10, 0xF0, 0x10, 0xF0, - 0x14, 0x14, 0x14, 0xFC, 0x00, - 0x14, 0x14, 0xF7, 0x00, 0xFF, - 0x00, 0x00, 0xFF, 0x00, 0xFF, - 0x14, 0x14, 0xF4, 0x04, 0xFC, - 0x14, 0x14, 0x17, 0x10, 0x1F, - 0x10, 0x10, 0x1F, 0x10, 0x1F, - 0x14, 0x14, 0x14, 0x1F, 0x00, - 0x10, 0x10, 0x10, 0xF0, 0x00, - 0x00, 0x00, 0x00, 0x1F, 0x10, - 0x10, 0x10, 0x10, 0x1F, 0x10, - 0x10, 0x10, 0x10, 0xF0, 0x10, - 0x00, 0x00, 0x00, 0xFF, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0xFF, 0x10, - 0x00, 0x00, 0x00, 0xFF, 0x14, - 0x00, 0x00, 0xFF, 0x00, 0xFF, - 0x00, 0x00, 0x1F, 0x10, 0x17, - 0x00, 0x00, 0xFC, 0x04, 0xF4, - 0x14, 0x14, 0x17, 0x10, 0x17, - 0x14, 0x14, 0xF4, 0x04, 0xF4, - 0x00, 0x00, 0xFF, 0x00, 0xF7, - 0x14, 0x14, 0x14, 0x14, 0x14, - 0x14, 0x14, 0xF7, 0x00, 0xF7, - 0x14, 0x14, 0x14, 0x17, 0x14, - 0x10, 0x10, 0x1F, 0x10, 0x1F, - 0x14, 0x14, 0x14, 0xF4, 0x14, - 0x10, 0x10, 0xF0, 0x10, 0xF0, - 0x00, 0x00, 0x1F, 0x10, 0x1F, - 0x00, 0x00, 0x00, 0x1F, 0x14, - 0x00, 0x00, 0x00, 0xFC, 0x14, - 0x00, 0x00, 0xF0, 0x10, 0xF0, - 0x10, 0x10, 0xFF, 0x10, 0xFF, - 0x14, 0x14, 0x14, 0xFF, 0x14, - 0x10, 0x10, 0x10, 0x1F, 0x00, - 0x00, 0x00, 0x00, 0xF0, 0x10, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, - 0xFF, 0xFF, 0xFF, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xFF, 0xFF, - 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, - 0x38, 0x44, 0x44, 0x38, 0x44, - 0xFC, 0x4A, 0x4A, 0x4A, 0x34, # sharp-s or beta - 0x7E, 0x02, 0x02, 0x06, 0x06, - 0x02, 0x7E, 0x02, 0x7E, 0x02, - 0x63, 0x55, 0x49, 0x41, 0x63, - 0x38, 0x44, 0x44, 0x3C, 0x04, - 0x40, 0x7E, 0x20, 0x1E, 0x20, - 0x06, 0x02, 0x7E, 0x02, 0x02, - 0x99, 0xA5, 0xE7, 0xA5, 0x99, - 0x1C, 0x2A, 0x49, 0x2A, 0x1C, - 0x4C, 0x72, 0x01, 0x72, 0x4C, - 0x30, 0x4A, 0x4D, 0x4D, 0x30, - 0x30, 0x48, 0x78, 0x48, 0x30, - 0xBC, 0x62, 0x5A, 0x46, 0x3D, - 0x3E, 0x49, 0x49, 0x49, 0x00, - 0x7E, 0x01, 0x01, 0x01, 0x7E, - 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, - 0x44, 0x44, 0x5F, 0x44, 0x44, - 0x40, 0x51, 0x4A, 0x44, 0x40, - 0x40, 0x44, 0x4A, 0x51, 0x40, - 0x00, 0x00, 0xFF, 0x01, 0x03, - 0xE0, 0x80, 0xFF, 0x00, 0x00, - 0x08, 0x08, 0x6B, 0x6B, 0x08, - 0x36, 0x12, 0x36, 0x24, 0x36, - 0x06, 0x0F, 0x09, 0x0F, 0x06, - 0x00, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x00, 0x10, 0x10, 0x00, - 0x30, 0x40, 0xFF, 0x01, 0x01, - 0x00, 0x1F, 0x01, 0x01, 0x1E, - 0x00, 0x19, 0x1D, 0x17, 0x12, - 0x00, 0x3C, 0x3C, 0x3C, 0x3C, - 0x00, 0x00, 0x00, 0x00, 0x00 # #255 NBSP -)) - - -if __name__ == '__main__': - with open('font5x8.bin', 'wb') as outfile: - # Write a byte each for the character width, character height. - outfile.write(bytes((5, 8))) - # Now write all of the font character bytes. - for font_byte in FONT: - outfile.write(font_byte.to_bytes(1, 'big')) \ No newline at end of file diff --git a/src/neopixels/moving-rainbow.py b/src/neopixels/moving-rainbow.py deleted file mode 100644 index 9d6ee953b..000000000 --- a/src/neopixels/moving-rainbow.py +++ /dev/null @@ -1,61 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -# cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, indigo, violet) -color_count = len(colors) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# offset should be incremented by one for motion -def draw_rainbow(offset, delay): - offset = offset % NUMBER_PIXELS - for i in range(0, color_count): - target = ((color_count - i - 1) + offset) % NUMBER_PIXELS - strip[target] = colors[i] - if offset > 0: - strip[offset-1] = (0,0,0) - if offset == NUMBER_PIXELS-1: - strip[offset] = (0,0,0) - strip.write() - sleep(delay) - - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - draw_rainbow(counter, .001) - counter += 1 - print(counter) diff --git a/src/neopixels/neopixel-raw-demo.py b/src/neopixels/neopixel-raw-demo.py deleted file mode 100644 index 6c0eb2136..000000000 --- a/src/neopixels/neopixel-raw-demo.py +++ /dev/null @@ -1,63 +0,0 @@ -import time -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 8 -np = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def demo(np, delay): - n = np.n - - # cycle - for i in range(4 * n): - for j in range(n): - np[j] = (0, 0, 0) - np[i % n] = (255, 255, 255) - np.write() - time.sleep_ms(delay) - - # bounce - for i in range(4 * n): - for j in range(n): - np[j] = (255, 255, 0) - if (i // n) % 2 == 0: - np[i % n] = (0, 0, 255) - else: - np[n - 1 - (i % n)] = (0, 255, 0) - np.write() - time.sleep_ms(delay*2) - - # fade in/out - for i in range(0, 4 * 256, 8): - for j in range(n): - if (i // 256) % 2 == 0: - val = i & 0xff - else: - val = 255 - (i & 0xff) - np[j] = (val, 0, 0) - time.sleep_ms(delay) - np.write() - - # clear - for i in range(n): - np[i] = (0, 0, 0) - np.write() - -delay = 100 # 100 millseconds between draws -counter = 0 -print('Number of NeoPixels', np.n) -print('Pin Number:', np.pin) -print('Buffer Lenght:', len(np.buf)) -print('Buffer:', np.buf) -for i in range(0, np.n): - j = i * 3 - np.buf[j] = 0 # green byte - np.buf[j+1] = 255 # red byte - np.buf[j+2] = 0 #blue -np.write() -time.sleep(2) -print('Buffer:', np.buf) -while True: - print('running demo', counter) - demo(np, delay) - counter += 1 \ No newline at end of file diff --git a/src/neopixels/neopixel-ring-rotary-spin-colors.py b/src/neopixels/neopixel-ring-rotary-spin-colors.py deleted file mode 100644 index a2c1296d4..000000000 --- a/src/neopixels/neopixel-ring-rotary-spin-colors.py +++ /dev/null @@ -1,118 +0,0 @@ -from machine import Pin -from rotary import Rotary -from neopixel import NeoPixel -from utime import sleep, ticks_ms - -NEOPIXEL_PIN = 22 -NUMBER_PIXELS = 24 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 22 is the button press switch. -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 16 -ENCODER_B = 17 -SWITCH = 18 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -brightness = 255 -red = (brightness, 0, 0) -green = (0, brightness, 0) -blue = (0, 0, brightness) - -# connect to one end of the button to this pin and the other to 3.3V -BUTTON_PIN = 15 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -BLACK = (0, 0, 0) -RED = (255, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -color_list = (RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) -current_color = 0 -color_count = len(color_list) - -last_time = 0 -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global current_color, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - current_color += 1 - current_color = current_color % color_count - draw_bar(val, width, color_list[current_color]) - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - - -# value of the rotery encoder -val = 0 -# width of the color band -width = 5 - -def rotary_changed(change): - global val, width - if change == Rotary.ROT_CW: - val = val + 1 - val = val % NUMBER_PIXELS - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - val = val % NUMBER_PIXELS - print(val) - elif change == Rotary.SW_PRESS: - width += 1 - width = width % 12 - draw_bar(val, width, color_list[current_color]) - print('new width:', width) - elif change == Rotary.SW_RELEASE: - pass - # print('RELEASE') - -rotary.add_handler(rotary_changed) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def draw_bar(start, width, color): - global strip - if start > 0: - strip[start % NUMBER_PIXELS] = (0,0,0) - end = start + width + 1 - for i in range(start+1, end): - strip[i % NUMBER_PIXELS] = color - if end < NUMBER_PIXELS: - strip[end % NUMBER_PIXELS] = (0,0,0) - strip.write() - - -current_val = 0 -draw_bar(0, width, color_list[current_color], ) -while True: - # draw only on a change - if val != current_val: - print('drawing at', val, 'width=', width) - draw_bar(val, width, color_list[current_color]) - current_val = val diff --git a/src/neopixels/neopixel2-grb-test.py b/src/neopixels/neopixel2-grb-test.py deleted file mode 100644 index 3b60bbea0..000000000 --- a/src/neopixels/neopixel2-grb-test.py +++ /dev/null @@ -1,27 +0,0 @@ -# this is the same as the standard NeoPixel library but with the order of the red and green bytes reversed. -# class NeoPixel2: -# G R B W -# ORDER = (0, 1, 2, 3) -from neopixelgrb import NeoPixel2 -from utime import sleep - -NEOPIXEL_PIN = 0 -# guess the number here -NUMBER_PIXELS = 50 - -strip = NeoPixel2(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - - -print('Turning the last pixel red:', NUMBER_PIXELS-1) -print('Drawing orange, yellow, green, blue, indigo and violet') - -strip[NUMBER_PIXELS-1] = (255,0,0) # red -strip[NUMBER_PIXELS-2] = (128,50,0) # orange -strip[NUMBER_PIXELS-3] = (128,128,0) # yellow -strip[NUMBER_PIXELS-4] = (0,255,0) # green -strip[NUMBER_PIXELS-5] = (0,0,255) # blue -strip[NUMBER_PIXELS-6] = (75,0,130) # indigo or pink -strip[NUMBER_PIXELS-7] = (255,0,255) # violet or purple -strip.write() - - diff --git a/src/neopixels/old/02-neopixel-length-test.py b/src/neopixels/old/02-neopixel-length-test.py deleted file mode 100644 index 8347efa77..000000000 --- a/src/neopixels/old/02-neopixel-length-test.py +++ /dev/null @@ -1,35 +0,0 @@ -import machine -from neopixel import Neopixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 72 -strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB") - -delay = .01 -# blink the first pixel red - -while True: - for i in range(0,5): - strip.set_pixel(NUMBER_PIXELS -1 ,(255,0,0)) - strip.show() - sleep(0.1) - strip.set_pixel(NUMBER_PIXELS -1 ,(0,0,0)) - strip.show() - sleep(0.1) - - for i in range(0, NUMBER_PIXELS - 1): - # set pixel 0 to be red - strip.set_pixel(i,(255,0,0)) - strip.show() - sleep(delay) - # turn pixel 0 off - strip.set_pixel(i, (0,0,0)) - for i in range(NUMBER_PIXELS-1, 0, -1): - # set pixel 0 to be red - strip.set_pixel(i,(255,0,0)) - strip.show() - sleep(delay) - # turn pixel 0 off - strip.set_pixel(i, (0,0,0)) - diff --git a/src/neopixels/old/06-pixel-line-gradient.py b/src/neopixels/old/06-pixel-line-gradient.py deleted file mode 100644 index e9eccbcbe..000000000 --- a/src/neopixels/old/06-pixel-line-gradient.py +++ /dev/null @@ -1,86 +0,0 @@ -import machine, neopixel -from utime import sleep -from neopixel import Neopixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 72 -strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB") -left = 0 -max_index = NUMBER_PIXELS - 1 -step = 3 - -delay=.001 -while True: - print('red to green') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (255,0,0), (0,255,0)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (255,0,0), (0,255,0)) - strip.show() - sleep(delay) - - print('green to blue') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,255,0), (0,0,255)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,255,0), (0,0,255)) - strip.show() - sleep(delay) - - print('blue to red') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,0,255), (255,0,0)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,0,255), (255,0,0)) - strip.show() - sleep(delay) - - print('yellow to purple') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (255,125,0), (255,0,255)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (255,125,0), (255,0,255)) - strip.show() - sleep(delay) - - print('orange to blue') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (50,25,0), (0,0,255)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (50,25,0), (0,0,255)) - strip.show() - sleep(delay) - - print('cyan to pink') - for i in range(0, 255, step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,255,255), (50,0,0)) - strip.show() - sleep(delay) - for i in range(255, 0, -step): - strip.brightness(i) - strip.set_pixel_line_gradient(0, max_index, (0,255,255), (50,0,0)) - strip.show() - sleep(delay) - - print('') \ No newline at end of file diff --git a/src/neopixels/old/color-wheel.py b/src/neopixels/old/color-wheel.py deleted file mode 100644 index 5f8c634de..000000000 --- a/src/neopixels/old/color-wheel.py +++ /dev/null @@ -1,38 +0,0 @@ -import machine, neopixel -from utime import sleep -from neopixel import Neopixel - -NEOPIXEL_PIN = 16 -NUMBER_PIXELS = 10 -strip = Neopixel(NUMBER_PIXELS, 0, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_cycle(wait): - for j in range(255): - for i in range(NUMBER_PIXELS): - rc_index = (i * 256 // NUMBER_PIXELS) + j - pixels[i] = wheel(rc_index & 255) - pixels.write() - -counter = 0 -while True: - for i in range(0, NUMBER_PIXELS): - # print(wheel(counter)) - strip.set_pixel(i, wheel(counter)) - strip.show() - counter += 1 - counter = counter % 255 - sleep(.01) diff --git a/src/neopixels/old/neopixel-test.py b/src/neopixels/old/neopixel-test.py deleted file mode 100644 index b908cf7b0..000000000 --- a/src/neopixels/old/neopixel-test.py +++ /dev/null @@ -1,33 +0,0 @@ -import machine, neopixel, time -# Set the pin number and number of pixels -from neopixel import Neopixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 144 -strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB") - -# blink the first pixel red - -while True: - # set pixel 0 to be red - strip.set_pixel(0,(255,0,0)) - strip.show() - time.sleep(0.5) - # turn pixel 0 off - strip.set_pixel(0, (0,0,0)) - - # set pixel 1 to be green - strip.set_pixel(1,(0,255,0)) - strip.show() - time.sleep(0.5) - # turn pixel 0 off - strip.set_pixel(1, (0,0,0)) - - # set pixel 2 to be blue - strip.set_pixel(2,(0,0,255)) - strip.show() - time.sleep(0.5) - # turn pixel 0 off - strip.set_pixel(2, (0,0,0)) - strip.show() - time.sleep(0.5) diff --git a/src/neopixels/old/neopixel.py b/src/neopixels/old/neopixel.py deleted file mode 100644 index 73d1d92c1..000000000 --- a/src/neopixels/old/neopixel.py +++ /dev/null @@ -1,201 +0,0 @@ -import array, time -from machine import Pin -import rp2 - -# from https://raw.githubusercontent.com/blaz-r/pi_pico_neopixel/main/neopixel.py - -# PIO state machine for RGB. Pulls 24 bits (rgb -> 3 * 8bit) automatically -@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24) -def ws2812(): - T1 = 2 - T2 = 5 - T3 = 3 - wrap_target() - label("bitloop") - out(x, 1) .side(0) [T3 - 1] - jmp(not_x, "do_zero") .side(1) [T1 - 1] - jmp("bitloop") .side(1) [T2 - 1] - label("do_zero") - nop().side(0) [T2 - 1] - wrap() - -# PIO state machine for RGBW. Pulls 32 bits (rgbw -> 4 * 8bit) automatically -@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=32) -def sk6812(): - T1 = 2 - T2 = 5 - T3 = 3 - wrap_target() - label("bitloop") - out(x, 1) .side(0) [T3 - 1] - jmp(not_x, "do_zero") .side(1) [T1 - 1] - jmp("bitloop") .side(1) [T2 - 1] - label("do_zero") - nop() .side(0) [T2 - 1] - wrap() - - -# Delay here is the reset time. You need a pause to reset the LED strip back to the initial LED -# however, if you have quite a bit of processing to do before the next time you update the strip -# you could put in delay=0 (or a lower delay) -# -# Class supports different order of individual colors (GRB, RGB, WRGB, GWRB ...). In order to achieve -# this, we need to flip the indexes: in 'RGBW', 'R' is on index 0, but we need to shift it left by 3 * 8bits, -# so in it's inverse, 'WBGR', it has exactly right index. Since micropython doesn't have [::-1] and recursive rev() -# isn't too efficient we simply do that by XORing (operator ^) each index with 3 (0b11) to make this flip. -# When dealing with just 'RGB' (3 letter string), this means same but reduced by 1 after XOR!. -# Example: in 'GRBW' we want final form of 0bGGRRBBWW, meaning G with index 0 needs to be shifted 3 * 8bit -> -# 'G' on index 0: 0b00 ^ 0b11 -> 0b11 (3), just as we wanted. -# Same hold for every other index (and - 1 at the end for 3 letter strings). - -class Neopixel: - def __init__(self, num_leds, state_machine, pin, mode="RGB", delay=0.0001): - self.pixels = array.array("I", [0 for _ in range(num_leds)]) - self.mode = set(mode) # set for better performance - if 'W' in self.mode: - # RGBW uses different PIO state machine configuration - self.sm = rp2.StateMachine(state_machine, sk6812, freq=8000000, sideset_base=Pin(pin)) - # dictionary of values required to shift bit into position (check class desc.) - self.shift = {'R': (mode.index('R') ^ 3) * 8, 'G': (mode.index('G') ^ 3) * 8, - 'B': (mode.index('B') ^ 3) * 8, 'W': (mode.index('W') ^ 3) * 8} - else: - self.sm = rp2.StateMachine(state_machine, ws2812, freq=8000000, sideset_base=Pin(pin)) - self.shift = {'R': ((mode.index('R') ^ 3) - 1) * 8, 'G': ((mode.index('G') ^ 3) - 1) * 8, - 'B': ((mode.index('B') ^ 3) - 1) * 8, 'W': 0} - self.sm.active(1) - self.num_leds = num_leds - self.delay = delay - self.brightnessvalue = 255 - - # Set the overal value to adjust brightness when updating leds - def brightness(self, brightness=None): - if brightness == None: - return self.brightnessvalue - else: - if brightness < 1: - brightness = 1 - if brightness > 255: - brightness = 255 - self.brightnessvalue = brightness - - # Create a gradient with two RGB colors between "pixel1" and "pixel2" (inclusive) - # Function accepts two (r, g, b) / (r, g, b, w) tuples - def set_pixel_line_gradient(self, pixel1, pixel2, left_rgb_w, right_rgb_w): - if pixel2 - pixel1 == 0: - return - right_pixel = max(pixel1, pixel2) - left_pixel = min(pixel1, pixel2) - - for i in range(right_pixel - left_pixel + 1): - fraction = i / (right_pixel - left_pixel) - red = round((right_rgb_w[0] - left_rgb_w[0]) * fraction + left_rgb_w[0]) - green = round((right_rgb_w[1] - left_rgb_w[1]) * fraction + left_rgb_w[1]) - blue = round((right_rgb_w[2] - left_rgb_w[2]) * fraction + left_rgb_w[2]) - # if it's (r, g, b, w) - if len(left_rgb_w) == 4 and 'W' in self.mode: - white = round((right_rgb_w[3] - left_rgb_w[3]) * fraction + left_rgb_w[3]) - self.set_pixel(left_pixel + i, (red, green, blue, white)) - else: - self.set_pixel(left_pixel + i, (red, green, blue)) - - # Set an array of pixels starting from "pixel1" to "pixel2" (inclusive) to the desired color. - # Function accepts (r, g, b) / (r, g, b, w) tuple - def set_pixel_line(self, pixel1, pixel2, rgb_w): - for i in range(pixel1, pixel2 + 1): - self.set_pixel(i, rgb_w) - - # Set red, green and blue value of pixel on position - # Function accepts (r, g, b) / (r, g, b, w) tuple - def set_pixel(self, pixel_num, rgb_w): - pos = self.shift - - red = round(rgb_w[0] * (self.brightness() / 255)) - green = round(rgb_w[1] * (self.brightness() / 255)) - blue = round(rgb_w[2] * (self.brightness() / 255)) - white = 0 - # if it's (r, g, b, w) - if len(rgb_w) == 4 and 'W' in self.mode: - white = round(rgb_w[3] * (self.brightness() / 255)) - - self.pixels[pixel_num] = white << pos['W'] | blue << pos['B'] | red << pos['R'] | green << pos['G'] - - # Converts HSV color to rgb tuple and returns it - # Function accepts integer values for , and - # The logic is almost the same as in Adafruit NeoPixel library: - # https://github.com/adafruit/Adafruit_NeoPixel so all the credits for that - # go directly to them (license: https://github.com/adafruit/Adafruit_NeoPixel/blob/master/COPYING) - def colorHSV(self, hue, sat, val): - if hue >= 65536: - hue %= 65536 - - hue = (hue * 1530 + 32768) // 65536 - if hue < 510: - b = 0 - if hue < 255: - r = 255 - g = hue - else: - r = 510 - hue - g = 255 - elif hue < 1020: - r = 0 - if hue < 765: - g = 255 - b = hue - 510 - else: - g = 1020 - hue - b = 255 - elif hue < 1530: - g = 0 - if hue < 1275: - r = hue - 1020 - b = 255 - else: - r = 255 - b = 1530 - hue - else: - r = 255 - g = 0 - b = 0 - - v1 = 1 + val - s1 = 1 + sat - s2 = 255 - sat - - r = ((((r * s1) >> 8) + s2) * v1) >> 8 - g = ((((g * s1) >> 8) + s2) * v1) >> 8 - b = ((((b * s1) >> 8) + s2) * v1) >> 8 - - return r, g, b - - - # Rotate pixels to the left - def rotate_left(self, num_of_pixels): - if num_of_pixels == None: - num_of_pixels = 1 - self.pixels = self.pixels[num_of_pixels:] + self.pixels[:num_of_pixels] - - # Rotate pixels to the right - def rotate_right(self, num_of_pixels): - if num_of_pixels == None: - num_of_pixels = 1 - num_of_pixels = -1 * num_of_pixels - self.pixels = self.pixels[num_of_pixels:] + self.pixels[:num_of_pixels] - - # Update pixels - def show(self): - # If mode is RGB, we cut 8 bits of, otherwise we keep all 32 - cut = 8 - if 'W' in self.mode: - cut = 0 - for i in range(self.num_leds): - self.sm.put(self.pixels[i], cut) - time.sleep(self.delay) - - # Set all pixels to given rgb values - # Function accepts (r, g, b) / (r, g, b, w) - def fill(self, rgb_w): - for i in range(self.num_leds): - self.set_pixel(i, rgb_w) - time.sleep(self.delay) - diff --git a/src/neopixels/old/power-step-test-2.py b/src/neopixels/old/power-step-test-2.py deleted file mode 100644 index bdee99eb5..000000000 --- a/src/neopixels/old/power-step-test-2.py +++ /dev/null @@ -1,26 +0,0 @@ -import time -from neopixel import Neopixel - -NUMBER_PIXELS = 144 -PIXELS_IN_TEST = 20 -strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB") -strip.brightness(1) - -def off(): - global NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS - 1): - strip.set_pixel(i, (0,0,0)) - strip.show() - -while True: - # turn everything off for a second - off() - time.sleep(1) - for power_level in range(50, 0, -1): - print('Power Level:', power_level) - print('Current in milliamps:', power_level*2) # estimate at 2ma on 10% brightness - for i in range(0, power_level - 1): - strip.set_pixel(i, (255,0,0)) - strip.show() - time.sleep(9) - off() \ No newline at end of file diff --git a/src/neopixels/old/power-step-test.py b/src/neopixels/old/power-step-test.py deleted file mode 100644 index aaa301c33..000000000 --- a/src/neopixels/old/power-step-test.py +++ /dev/null @@ -1,26 +0,0 @@ -import time -from neopixel import Neopixel - -NUMBER_PIXELS = 144 -PIXELS_IN_TEST = 20 -strip = Neopixel(NUMBER_PIXELS, 0, 0, "GRB") -strip.brightness(10) - -def off(): - global NUMBER_PIXELS - for i in range(0, NUMBER_PIXELS - 1): - strip.set_pixel(i, (0,0,0)) - strip.show() - -while True: - # turn everything off for a second - off() - time.sleep(1) - for power_level in range(50, 0, -1): - print('Power Level:', power_level) - print('Current in milliamps:', power_level*2) # estimate at 2ma on 10% brightness - for i in range(0, power_level - 1): - strip.set_pixel(i, (255,255,255)) - strip.show() - time.sleep(5) - off() \ No newline at end of file diff --git a/src/neopixels/old/rainbow-cylon-eye-scanner.py b/src/neopixels/old/rainbow-cylon-eye-scanner.py deleted file mode 100644 index f6ecc2a75..000000000 --- a/src/neopixels/old/rainbow-cylon-eye-scanner.py +++ /dev/null @@ -1,86 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 25 -STATE_MACHINE = 0 -LED_PIN = 0 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -off = (0,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (255, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -def draw_eye_7(r, g, b): - for i in range(6, NUMBER_PIXELS): - strip.set_pixel(i, (r, g, b)) - # step back from the current to 6 back halfing the intensity each time - for j in range(0,7): - strip.set_pixel(i-j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j)))) - if i > 6: strip.set_pixel(i-7, (0,0,0)) - strip.show() - sleep(delay) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-6, 0, -1): - strip.set_pixel(i, (r, g, b)) - for j in range(7,0): - strip.set_pixel(i+j, (int(r/pow(2,j)), int(g/pow(2,j)), int(b/pow(2,j)))) - if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0)) - strip.show() - sleep(delay) - -def draw_rainbow(): - for i in range(0, NUMBER_PIXELS-7): - strip.set_pixel(i, violet) - strip.set_pixel(i+1, indigo) - strip.set_pixel(i+2, blue) - strip.set_pixel(i+3, green) - strip.set_pixel(i+4, yellow) - strip.set_pixel(i+5,orange) - strip.set_pixel(i+6, red) - if i > 6: strip.set_pixel(i-7, (0,0,0)) - strip.show() - sleep(delay) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-7, 1, -1): - strip.set_pixel(i, red) - strip.set_pixel(i+1, orange) - strip.set_pixel(i+2, yellow) - strip.set_pixel(i+3, green) - strip.set_pixel(i+4, blue) - strip.set_pixel(i+5, indigo) - strip.set_pixel(i+6, violet) - if i < NUMBER_PIXELS-7: strip.set_pixel(i+7, (0,0,0)) - strip.show() - sleep(delay) - -# delay = .031 - -delay = .06 -color_index = 0 -while True: - draw_rainbow() - draw_eye_7(255,0,0) - draw_eye_7(255,60,0) - draw_eye_7(255,255,0) - draw_eye_7(0,255,0) - draw_eye_7(0,0,255) - draw_eye_7(0,255,255) - draw_eye_7(75,30,130) - draw_eye_7(255,0,255) - draw_eye_7(255,255,255) \ No newline at end of file diff --git a/src/neopixels/rainbow-slider-60.py b/src/neopixels/rainbow-slider-60.py deleted file mode 100644 index 199e4d937..000000000 --- a/src/neopixels/rainbow-slider-60.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# The Change Rate is how quickly the colors change moving down the strip -def rainbow_slide(counter, change_rate, delay): - for i in range(0, NUMBER_PIXELS): - # the modulo make sure the color is in range of 0 to 255 - strip[i] = wheel((i*change_rate + counter) % 255) - strip.write() - sleep(delay) - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - rainbow_slide(counter, 3, .0001) - counter += 1 - print(counter) diff --git a/src/neopixels/rainbow-slider.py b/src/neopixels/rainbow-slider.py deleted file mode 100644 index 0381ba16b..000000000 --- a/src/neopixels/rainbow-slider.py +++ /dev/null @@ -1,40 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 16 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def rainbow_slide(counter, delay): - for i in range(0, NUMBER_PIXELS): - strip[i] = wheel((i*NUMBER_PIXELS - counter) % 255) - strip.write() - sleep(delay) - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - rainbow_slide(counter, .004) - counter += NUMBER_PIXELS diff --git a/src/neopixels/random-colors.py b/src/neopixels/random-colors.py deleted file mode 100644 index 7a6ce0de6..000000000 --- a/src/neopixels/random-colors.py +++ /dev/null @@ -1,57 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep -from urandom import randint -# https://docs.micropython.org/en/latest/library/random.html - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 60 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -# cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, indigo, violet) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# offset should be incremented by one for motion -def draw_random_color(): - random_offset = randint(0, NUMBER_PIXELS-1) - random_color = randint(0, 255) - strip[random_offset] = wheel(random_color) - strip.write() - -def clear(): - for i in range(0, NUMBER_PIXELS): - strip[i] = (0,0,0) - strip.write() - -# setup -counter = 0 -clear() - -# main loop -while True: - draw_random_color() - sleep(.1) diff --git a/src/neopixels/three-pot-kit/main.py b/src/neopixels/three-pot-kit/main.py deleted file mode 100644 index e505d2c51..000000000 --- a/src/neopixels/three-pot-kit/main.py +++ /dev/null @@ -1,37 +0,0 @@ -% this kit assumes we have three POTs hooked to pins 26, 27 and 28 of the Picl -from machine import ADC, Pin -from utime import sleep -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# this is the built-in LED on the Pico which we toggle on and off to show sampling -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side -pot1 = ADC(26) -pot2 = ADC(27) -pot3 = ADC(28) - -MAX_DELAY = .5 # seconds - -# global variables -delay = .1 - -# repeat forever -while True: - # we have the POTs wired backwards so we subtract to get the value - pot_value1 = 255 - (pot1.read_u16() >> 8) # read the value from the pot and shift 6 bits - pot_value2 = 255 - (pot2.read_u16() >> 8) - pot_value3 = 255 - (pot3.read_u16() >> 8) - print("pot_values:", pot_value1, pot_value2, pot_value3) - - # update the strip with our new values - for i in range(NUMBER_PIXELS): - strip[i] = (pot_value3, pot_value2, pot_value1) - strip.write() - - sleep(delay) - led.toggle() diff --git a/src/network/01-connect-access-point-test.py b/src/network/01-connect-access-point-test.py deleted file mode 100644 index 0cdbb7e2b..000000000 --- a/src/network/01-connect-access-point-test.py +++ /dev/null @@ -1,18 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(.1) - print("Waiting", counter) - counter += 1 - -print('Connected to', secrets.SSID) diff --git a/src/network/01-connect-access-point-timed-test.py b/src/network/01-connect-access-point-timed-test.py deleted file mode 100644 index 72f71a838..000000000 --- a/src/network/01-connect-access-point-timed-test.py +++ /dev/null @@ -1,21 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -start = ticks_ms() # start a millisecond counter - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - counter += 1 - print(counter, '.', sep='', end='') - -print('Connected to', secrets.SSID) -print('Total connect milliseconds:', ticks_diff(ticks_ms(), start)) \ No newline at end of file diff --git a/src/network/01-is-connected-test.py b/src/network/01-is-connected-test.py deleted file mode 100644 index 8dbde7565..000000000 --- a/src/network/01-is-connected-test.py +++ /dev/null @@ -1,12 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -sleep(3) -print(wlan.isconnected()) -print(wlan.status()) -print(wlan.scan()) \ No newline at end of file diff --git a/src/network/01-is-connected-timed-test.py b/src/network/01-is-connected-timed-test.py deleted file mode 100644 index 8dbde7565..000000000 --- a/src/network/01-is-connected-timed-test.py +++ /dev/null @@ -1,12 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -sleep(3) -print(wlan.isconnected()) -print(wlan.status()) -print(wlan.scan()) \ No newline at end of file diff --git a/src/network/01-simple-connnect-test.py b/src/network/01-simple-connnect-test.py deleted file mode 100644 index eb01f8177..000000000 --- a/src/network/01-simple-connnect-test.py +++ /dev/null @@ -1,17 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # power up the WiFi chip -print('Waiting for wifi chip to power up') -sleep(3) # wait three seconds for the chip to power up and initialize -wlan.connect(secrets.SSID, secrets.PASSWORD) -print('Waiting for access point to log us in.') -sleep(2) -if wlan.isconnected(): - print('Success! We have connected to your access point!') - print('Try to ping the device at', wlan.ifconfig()[0]) -else: - print('Failure! We have not connected to your access point! Check your secrets.py file for errors.') \ No newline at end of file diff --git a/src/network/02-http-get-timed.py b/src/network/02-http-get-timed.py deleted file mode 100644 index b9d8dcd1e..000000000 --- a/src/network/02-http-get-timed.py +++ /dev/null @@ -1,21 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff -import urequests - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) - -start = ticks_ms() # start a millisecond counter - -astronauts = urequests.get("http://api.open-notify.org/astros.json").json() - -delta = ticks_diff(ticks_ms(), start) - -number = astronauts['number'] -print('There are', number, 'astronauts in space.') -for i in range(number): - print(i+1, astronauts['people'][i]['name']) - -print("HTTP GET Time in milliseconds:", delta) \ No newline at end of file diff --git a/src/network/02-http-get.py b/src/network/02-http-get.py deleted file mode 100644 index 0f6808f93..000000000 --- a/src/network/02-http-get.py +++ /dev/null @@ -1,13 +0,0 @@ -import network -import secrets -import time -import urequests -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -print(wlan.isconnected()) -astronauts = urequests.get("http://api.open-notify.org/astros.json").json() -number = astronauts['number'] -print('There are', number, 'astronauts in space.') -for i in range(number): - print(astronauts['people'][i]['name']) \ No newline at end of file diff --git a/src/network/02-scan-wifi-networks.py b/src/network/02-scan-wifi-networks.py deleted file mode 100644 index d959d7d63..000000000 --- a/src/network/02-scan-wifi-networks.py +++ /dev/null @@ -1,18 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - while not wlan.isconnected(): - time.sleep(.1) - print("Waiting") - -ac_list = wlan.scan() -for name in ac_list: - print(name) diff --git a/src/network/03-wait-till-connected-timed.py b/src/network/03-wait-till-connected-timed.py deleted file mode 100644 index b95bc241f..000000000 --- a/src/network/03-wait-till-connected-timed.py +++ /dev/null @@ -1,20 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - while not wlan.isconnected(): - sleep(.1) - print("Waiting") - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta) -print(wlan.ifconfig()) \ No newline at end of file diff --git a/src/network/03-wait-till-connected.py b/src/network/03-wait-till-connected.py deleted file mode 100644 index 5e29612e3..000000000 --- a/src/network/03-wait-till-connected.py +++ /dev/null @@ -1,16 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - while not wlan.isconnected(): - time.sleep(.1) - print("Waiting") - -print(wlan.ifconfig()) \ No newline at end of file diff --git a/src/network/03-wait-until-connected.py b/src/network/03-wait-until-connected.py deleted file mode 100644 index c1fc79afa..000000000 --- a/src/network/03-wait-until-connected.py +++ /dev/null @@ -1,22 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - counter += 1 - print(counter, '.', sep='', end='', ) - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta) -print("Ping the following address:", wlan.ifconfig()[0]) \ No newline at end of file diff --git a/src/network/04-socket-test.py b/src/network/04-socket-test.py deleted file mode 100644 index f2c075deb..000000000 --- a/src/network/04-socket-test.py +++ /dev/null @@ -1,24 +0,0 @@ -import network -import secrets -from utime import sleep - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - while not wlan.isconnected(): - time.sleep(.1) - print("Waiting") - -# now use socket as usual -import socket -addr = socket.getaddrinfo('micropython.org', 80)[0][-1] -s = socket.socket() -s.connect(addr) -s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n') -data = s.recv(1000) -print(data) -s.close() \ No newline at end of file diff --git a/src/network/05-get-mac-address-timed.py b/src/network/05-get-mac-address-timed.py deleted file mode 100644 index 627dd02c1..000000000 --- a/src/network/05-get-mac-address-timed.py +++ /dev/null @@ -1,24 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_us, ticks_diff - -print('Getting MAC/Ethernet Address for this device.') - -start = ticks_us() # start a millisecond counter -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # power up the chip - -# This returns a byte array of hex numbers -mac_addess = wlan.config('mac') -print('Time in microseconds:', ticks_diff(ticks_us(), start)) -# each MAC address is 6 bytes or 48 bits -print("Hex byte array:", mac_addess, 'length:', len(mac_addess)) - -# This should be in hex per the Notational Conventions -# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions -# b'(\xcd\xc1\x015X' -# 28:cd:c1:1:35:58 -# format in MAC Notational Convention -for digit in range(0,5): - print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '') -print(str(hex(mac_addess[5]))[2:4] ) \ No newline at end of file diff --git a/src/network/05-get-mac-address.py b/src/network/05-get-mac-address.py deleted file mode 100644 index 627dd02c1..000000000 --- a/src/network/05-get-mac-address.py +++ /dev/null @@ -1,24 +0,0 @@ -import network -import secrets -from utime import sleep, ticks_us, ticks_diff - -print('Getting MAC/Ethernet Address for this device.') - -start = ticks_us() # start a millisecond counter -wlan = network.WLAN(network.STA_IF) -wlan.active(True) # power up the chip - -# This returns a byte array of hex numbers -mac_addess = wlan.config('mac') -print('Time in microseconds:', ticks_diff(ticks_us(), start)) -# each MAC address is 6 bytes or 48 bits -print("Hex byte array:", mac_addess, 'length:', len(mac_addess)) - -# This should be in hex per the Notational Conventions -# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions -# b'(\xcd\xc1\x015X' -# 28:cd:c1:1:35:58 -# format in MAC Notational Convention -for digit in range(0,5): - print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '') -print(str(hex(mac_addess[5]))[2:4] ) \ No newline at end of file diff --git a/src/network/06-get-weather-on-console.py b/src/network/06-get-weather-on-console.py deleted file mode 100644 index 778c023b2..000000000 --- a/src/network/06-get-weather-on-console.py +++ /dev/null @@ -1,46 +0,0 @@ -import network -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta, 'milliseconds') -print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid - -weather = urequests.get(url).json() -print('City:', weather['city']['name']) -print('Timezone:', weather['city']['timezone']) - -# this could be up to 39 values -max_items = 14 -# print a row of dates and hours -for i in range(0, max_items): - print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='') -print() -# print a row of temperatures -for i in range(0, max_items): - print(round(weather['list'][i]['main']['temp']), ' ', end='') - # print('feels like:', weather['list'][i]['main']['feels_like']) - # print(weather['list'][i]['weather'][0]['description']) - # print(weather['list'][i]['dt_txt']) - -# print(weather) \ No newline at end of file diff --git a/src/network/06-get-weather-thonny-plot.py b/src/network/06-get-weather-thonny-plot.py deleted file mode 100644 index 1916d315c..000000000 --- a/src/network/06-get-weather-thonny-plot.py +++ /dev/null @@ -1,47 +0,0 @@ -import network -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -# print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -#print("Connect Time:", delta, 'milliseconds') -#print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid -#print(url) - -weather = urequests.get(url).json() -#print('City:', weather['city']['name']) -#print('Timezone:', weather['city']['timezone']) - -max_times = 39 -# for i in range(0, 39): -#for i in range(0, max_times): -# print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='') -# print() -for i in range(0, max_times): - print(' FeelsLike:', weather['list'][i]['main']['feels_like'], end='') - #print(' Min:', weather['list'][i]['main']['temp_min'], end='') - print(' Max:', weather['list'][i]['main']['temp_max'], end='') - print(' Temp: ', weather['list'][i]['main']['temp']) - # print(weather['list'][i]['weather'][0]['description']) - # print(weather['list'][i]['dt_txt']) - -# print(weather) \ No newline at end of file diff --git a/src/network/06-get-weather.py b/src/network/06-get-weather.py deleted file mode 100644 index 1f66571cd..000000000 --- a/src/network/06-get-weather.py +++ /dev/null @@ -1,45 +0,0 @@ -import network -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - -delta = ticks_diff(ticks_ms(), start) -print("Connect Time:", delta, 'milliseconds') -print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid -print(url) - -weather = urequests.get(url).json() -print('City:', weather['city']['name']) -print('Timezone:', weather['city']['timezone']) - -max_times = 16 -# for i in range(0, 39): -for i in range(0, max_times): - print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='') -print() -for i in range(0, max_times): - print(round(weather['list'][i]['main']['temp']), ' ', end='') - # print('feels like:', weather['list'][i]['main']['feels_like']) - # print(weather['list'][i]['weather'][0]['description']) - # print(weather['list'][i]['dt_txt']) - -# print(weather) \ No newline at end of file diff --git a/src/network/07-get-weather-display-plot.py b/src/network/07-get-weather-display-plot.py deleted file mode 100644 index d629ab61d..000000000 --- a/src/network/07-get-weather-display-plot.py +++ /dev/null @@ -1,127 +0,0 @@ -import network -import ssd1306 -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -# startup - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def display_startup(counter): - oled.fill(0) - oled.text('Running startup', 0, 10, 1) - oled.text('Connecting to', 0, 20, 1) - oled.text(secrets.SSID, 0, 30, 1) - oled.text(str(counter), 0, 40, 1) - oled.show() - -def display_status(counter): - oled.fill(0) - # display the network name - oled.text('n:' + secrets.SSID, 0, 0, 1) - - # display the connection time - oled.text('t:', 0, 10, 1) - oled.text(str(connection_time)+ ' ms', 15, 10, 1) - oled.show() - -def display_weather(): - global weather, city, current_temp - oled.fill(0) - min = 120 - max = -50 - for i in range(0, 39): - temp = round(weather['list'][i]['main']['temp']) - if temp < min: - min = temp - if temp > max: - max = temp - min = round(min) - max = round(max) - temp_range_height = max - min - graph_height = 54 - scale = graph_height/temp_range_height - print('min/max/range/scale:', min, max, temp_range_height, scale) - - # display city name, current temp, min and max - oled.text(city + ': ' + str(current_temp), 0, 0, 1) - oled.text(str(min), 0, 57, 1) # bottom left corner - oled.text(str(max), 0, 10, 1) # under top row - - max_points = 39 - - # graph temps for the next n periods - print('Date Tmp TNx Y Y2 Del') - for i in range(0, max_points): - temp = round(weather['list'][i]['main']['temp']) - x = i * 3 # scaled x - y = 63 - round((temp - min)*scale) - oled.pixel(x, y, 1) - - # now draw the next two points - if i < max_points: - temp_next = round(weather['list'][i+1]['main']['temp']) - y_next = 63 - round((temp_next - min)*scale) - y_delta = -round((y - y_next)/3) # a small positive or negative number - - print(weather['list'][i]['dt_txt'][0:13], - '{: 3.3d}'.format(temp), - '{: 3.3d}'.format(temp_next), - '{: 3.3d}'.format(y), - '{: 3.3d}'.format(y_next), - '{: 3.3d}'.format(y_delta)) - - # should be 1/3 of the way to the next point - oled.pixel(x+1, y + y_delta, 1) - # should be 2/3 of the way to the next point - oled.pixel(x+2, y + 2*y_delta, 1) - oled.show() - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - display_startup(counter) - -delta = ticks_diff(ticks_ms(), start) -#print("Connect Time:", delta, 'milliseconds') -#print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid -#print(url) - -max_times = 39 -#for i in range(0, max_times): - #print(' Temp: ', weather['list'][i]['main']['temp']) - -while True: - # globals: weather, city, current_temp - weather = urequests.get(url).json() - # print(weather) - city = weather['city']['name'] - current_temp = round(weather['list'][0]['main']['temp']) - display_weather() - print('Going to sleep for one hour') - sleep(3600) # sleep one hour \ No newline at end of file diff --git a/src/network/10-web-server.py b/src/network/10-web-server.py deleted file mode 100644 index 2f8391860..000000000 --- a/src/network/10-web-server.py +++ /dev/null @@ -1,88 +0,0 @@ -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -import network -import socket -import time -import secrets - -from machine import Pin - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - -

                                                                                                                                                                                                                                                                                                                                                                                          Pico Wireless Web Server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          %s

                                                                                                                                                                                                                                                                                                                                                                                          - Turn On - Turn Off - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -print('addr:', addr) -s = socket.socket() -#if not addr: -s.bind(addr) -s.listen(1) - -print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - print('client connected from', addr) - request = cl.recv(1024) - print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - print( 'led on = ' + str(led_on)) - print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - print('connection closed') \ No newline at end of file diff --git a/src/network/11-web-server-v2.py b/src/network/11-web-server-v2.py deleted file mode 100644 index 570a096f5..000000000 --- a/src/network/11-web-server-v2.py +++ /dev/null @@ -1,135 +0,0 @@ -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -import network -import socket -from time import sleep -import secrets - -from machine import Pin - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(False) -sleep(1) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - -

                                                                                                                                                                                                                                                                                                                                                                                          Pico Wireless Web Server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          State: %s

                                                                                                                                                                                                                                                                                                                                                                                          - Turn On - Turn Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Red LED On - Red LED Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Green LED On - Green LED Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Blue LED On - Blue LED Off - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -# print('addr:', addr) - -s = socket.socket() -# this prevents the "OSError: [Errno 98] EADDRINUSE" error for repeated tests -s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -print('Got a sockert. s:', s) - -#if not addr: - -print('going to run bind to addr on the socket') -s.bind(addr) - -print('going to run listen(1) on socket') -s.listen(1) - -print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - # print('client connected from', addr) - request = cl.recv(1024) - # print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - - red_on = request.find('/led/red/on') - red_off = request.find('/led/red/off') - - green_on = request.find('/led/green/on') - green_off = request.find('/led/green/off') - - blue_on = request.find('/led/blue/on') - blue_off = request.find('/led/blue/off') - - # print( 'led on = ' + str(led_on)) - # print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - - if red_on == 6: - print("red on") - if red_off == 6: - print("red off") - - if green_on == 6: - print("green on") - if green_off == 6: - print("green off") - - if blue_on == 6: - print("blue on") - if blue_off == 6: - print("blue off") - - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - s.close() - print('connection closed') \ No newline at end of file diff --git a/src/network/11-web-server-v3.py b/src/network/11-web-server-v3.py deleted file mode 100644 index 570a096f5..000000000 --- a/src/network/11-web-server-v3.py +++ /dev/null @@ -1,135 +0,0 @@ -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -import network -import socket -from time import sleep -import secrets - -from machine import Pin - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(False) -sleep(1) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - -

                                                                                                                                                                                                                                                                                                                                                                                          Pico Wireless Web Server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          State: %s

                                                                                                                                                                                                                                                                                                                                                                                          - Turn On - Turn Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Red LED On - Red LED Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Green LED On - Green LED Off
                                                                                                                                                                                                                                                                                                                                                                                          - - Blue LED On - Blue LED Off - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - sleep(1) - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -# print('addr:', addr) - -s = socket.socket() -# this prevents the "OSError: [Errno 98] EADDRINUSE" error for repeated tests -s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -print('Got a sockert. s:', s) - -#if not addr: - -print('going to run bind to addr on the socket') -s.bind(addr) - -print('going to run listen(1) on socket') -s.listen(1) - -print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - # print('client connected from', addr) - request = cl.recv(1024) - # print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - - red_on = request.find('/led/red/on') - red_off = request.find('/led/red/off') - - green_on = request.find('/led/green/on') - green_off = request.find('/led/green/off') - - blue_on = request.find('/led/blue/on') - blue_off = request.find('/led/blue/off') - - # print( 'led on = ' + str(led_on)) - # print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - - if red_on == 6: - print("red on") - if red_off == 6: - print("red off") - - if green_on == 6: - print("green on") - if green_off == 6: - print("green off") - - if blue_on == 6: - print("blue on") - if blue_off == 6: - print("blue off") - - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - s.close() - print('connection closed') \ No newline at end of file diff --git a/src/network/12-stream-sensor-data-to-web.py b/src/network/12-stream-sensor-data-to-web.py deleted file mode 100644 index 27d0edf1e..000000000 --- a/src/network/12-stream-sensor-data-to-web.py +++ /dev/null @@ -1,6 +0,0 @@ -# Stream Sensor Data to a Web Page - -## References - -[Picockpit Demo](https://picockpit.com/raspberry-pi/stream-sensor-data-over-wifi-with-raspberry-pi-pico-w) -[GitHub](https://github.com/pi3g/pico-w/blob/main/MicroPython/II%20Pico%20W%20Sensor%20Server/main.py) diff --git a/src/network/12-web-neopixel-controller.py b/src/network/12-web-neopixel-controller.py deleted file mode 100644 index 2ce0f2948..000000000 --- a/src/network/12-web-neopixel-controller.py +++ /dev/null @@ -1,207 +0,0 @@ -# Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/ -from machine import Pin -from neopixel import NeoPixel -import network -import socket -from time import sleep -import secrets - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 30 -PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS) - -# setup -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255,0,0) -green = (0,255,0) -blue = (0,0,255) -off = (0,0,0) - -def set_color(color): - for i in range(0, NUMBER_PIXELS): - strip[i] = color - strip.write() - -# Select the onboard LED -led = machine.Pin("LED", machine.Pin.OUT) - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -wlan.connect(secrets.SSID, secrets.PASSWORD) -stateis = "LED is OFF" - -html = """ - - - Web Server On Pico W - - - -

                                                                                                                                                                                                                                                                                                                                                                                          Pico Wireless Web Server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          Onboard LED State: %s

                                                                                                                                                                                                                                                                                                                                                                                          - - -
                                                                                                                                                                                                                                                                                                                                                                                          - - - Turn Onboard LED On - Turn Onboard LED Off -
                                                                                                                                                                                                                                                                                                                                                                                          - - - Red LED On - Red LED Off -
                                                                                                                                                                                                                                                                                                                                                                                          - - - - Green LED On - Green LED Off -
                                                                                                                                                                                                                                                                                                                                                                                          - - - Blue LED On - Blue LED Off - - -
                                                                                                                                                                                                                                                                                                                                                                                          - - -""" - -# Wait for connect or fail -max_wait = 10 -while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - sleep(1) - led.toggle() - -# Handle connection error -if wlan.status() != 3: - raise RuntimeError('network connection failed') -else: - print('We are connected to WiFI access point:', secrets.SSID) - status = wlan.ifconfig() - print( 'The IP address of the pico W is:', status[0] ) - -# Open socket -addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] -# print('addr:', addr) - -s = socket.socket() -# this prevents the "OSError: [Errno 98] EADDRINUSE" error for repeated tests -s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -# print('Got a sockert. s:', s) - -#if not addr: - -# print('going to run bind to addr on the socket') -s.bind(addr) - -# print('going to run listen(1) on socket') -s.listen(1) - -# print('listening on', addr) - -# Listen for connections -while True: - try: - cl, addr = s.accept() - # print('client connected from', addr) - request = cl.recv(1024) - # print(request) - request = str(request) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - - red_on = request.find('/led/red/on') - red_off = request.find('/led/red/off') - - green_on = request.find('/led/green/on') - green_off = request.find('/led/green/off') - - blue_on = request.find('/led/blue/on') - blue_off = request.find('/led/blue/off') - - # print( 'led on = ' + str(led_on)) - # print( 'led off = ' + str(led_off)) - - if led_on == 6: - print("led on") - led.on() - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.off() - stateis = "LED is OFF" - - if red_on == 6: - print("red on") - set_color(red) - if red_off == 6: - print("red off") - set_color(off) - - if green_on == 6: - print("green on") - set_color(green) - if green_off == 6: - print("green off") - set_color(off) - - if blue_on == 6: - print("blue on") - set_color(blue) - if blue_off == 6: - print("blue off") - set_color(off) - - # generate the we page with the stateis as a parameter - response = html % stateis - cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - cl.send(response) - cl.close() - - except OSError as e: - cl.close() - s.close() - print('connection closed') \ No newline at end of file diff --git a/src/network/clock/clock-digits-3.py b/src/network/clock/clock-digits-3.py deleted file mode 100644 index 2dd4faf26..000000000 --- a/src/network/clock/clock-digits-3.py +++ /dev/null @@ -1,127 +0,0 @@ -# clock digits -import machine -import utime -import ssd1306 -from utime import sleep, localtime -led = machine.Pin(25, machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA, baudrate=100000) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -segmentMapping = [ - #a, b, c, d, e, f, g - [1, 1, 1, 1, 1, 1, 0], # 0 - [0, 1, 1, 0, 0, 0, 0], # 1 - [1, 1, 0, 1, 1, 0, 1], # 2 - [1, 1, 1, 1, 0, 0, 1], # 3 - [0, 1, 1, 0, 0, 1, 1], # 4 - [1, 0, 1, 1, 0, 1, 1], # 5 - [1, 0, 1, 1, 1, 1, 1], # 6 - [1, 1, 1, 0, 0, 0, 0], # 7 - [1, 1, 1, 1, 1, 1, 1], # 8 - [1, 1, 1, 1, 0, 1, 1] # 9 -]; - - -# x and y are the center of the digit, size is the center to edge -def drawDigit(digit, x, y, size): - - segmentOn = segmentMapping[digit]; - - # Horizontal segments - for i in [0, 3, 6]: - if (segmentOn[i]): - if (i==0): yOffset = 0 # top - if (i==3): yOffset = size*2 # bottom element - if (i==6): yOffset = size # middle - oled.line(x - size, y+yOffset-size, x + size, y+yOffset-size, 1); - - # Vertical segments - for i in [1, 2, 4, 5]: - if (segmentOn[i]) : - if (i==1 or i==5): - startY = y-size - endY = y - if (i==2 or i==4): - startY = y - endY = y + size - if (i==4 or i==5): xOffset = -size - if (i==1 or i==2): xOffset = +size - xpos = x + xOffset - oled.line(xpos, startY, xpos, endY, 1); - -def update_screen(digit_val): - oled.fill(0) - oled.text('Clock Digit Lab', 0, 0, 1) - dr = 10 # digit radius - dch = 26 # digit center hight - lm = 10 # left margin for all 4-digits - dw = 24 # digit width (2*dr + spacing between digits - cm = 8 # colon left margin - - # draw the hour digits - hour = localtime()[3] - if hour > 12: - hour = hour - 12 - am_pm = 'pm' - else: - am_pm = 'am' - if hour < 10: - # just draw the second digit - drawDigit(hour, lm+dw, dch, dr) - else: - # we have 10, 11 or 12 so the first digit is 1 - drawDigit(1, lm, dch, dr) - # subtract 10 from the second digit - drawDigit(hour-10, lm+dw, dch, dr) - - # draw the colon - if localtime()[5] % 2: - draw_colon(lm+dw*2+cm-16,dch-5) - - # draw the minutes - minutes = localtime()[4] - # value, x, y, size - # left minute digit after the colon - drawDigit(minutes // 10, lm+dw*2+cm, dch, dr) - # right minute digit - drawDigit(minutes % 10, lm+dw*3+cm+2, dch, dr) - - # draw the AM/PM - oled.text(am_pm, lm+dw*4+cm-8, dch+3, 1) - - #oled.text(timeStrFmt(), 0, 46, 1) - oled.text(str(localtime()[5]), 0, 54) - #oled.text(str(digit_val), 0, 54, 1) - - oled.show() - -def draw_colon(x,y): - oled.fill_rect(x, y, 2, 2,1) - oled.fill_rect(x, y+8, 2, 2,1) - -def timeStrFmt(): - hour = localtime()[3] - if hour > 12: - hour = hour - 12 - am_pm = ' pm' - else: am_pm = ' am' - # format minutes and seconds with leading zeros - minutes = "{:02d}".format(localtime()[4]) - return str(hour) + ':' + minutes + am_pm - -counter = 0 -while True: - update_screen(counter) - sleep(1) - counter += 1 - if counter > 9: - counter = 0 - diff --git a/src/network/clock/clock-digits-v1.py b/src/network/clock/clock-digits-v1.py deleted file mode 100644 index 9ef350521..000000000 --- a/src/network/clock/clock-digits-v1.py +++ /dev/null @@ -1,74 +0,0 @@ -# clock digits -import machine -import utime -import ssd1306 -from utime import sleep, localtime -led = machine.Pin(25, machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA, baudrate=100000) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -segmentMapping = [ - #a, b, c, d, e, f, g - [1, 1, 1, 1, 1, 1, 0], # 0 - [0, 1, 1, 0, 0, 0, 0], # 1 - [1, 1, 0, 1, 1, 0, 1], # 2 - [1, 1, 1, 1, 0, 0, 1], # 3 - [0, 1, 1, 0, 0, 1, 1], # 4 - [1, 0, 1, 1, 0, 1, 1], # 5 - [1, 0, 1, 1, 1, 1, 1], # 6 - [1, 1, 1, 0, 0, 0, 0], # 7 - [1, 1, 1, 1, 1, 1, 1], # 8 - [1, 1, 1, 1, 0, 1, 1] # 9 -]; - - -# x and y are the center of the digit, size is the center to edge -def drawDigit(digit, x, y, size): - - segmentOn = segmentMapping[digit]; - - # Horizontal segments - for i in [0, 3, 6]: - if (segmentOn[i]): - if (i==0): yOffset = 0 # top - if (i==3): yOffset = size*2 # bottom element - if (i==6): yOffset = size # middle - oled.line(x - size, y+yOffset-size, x + size, y+yOffset-size, 1); - - # Vertical segments - for i in [1, 2, 4, 5]: - if (segmentOn[i]) : - if (i==1 or i==5): - startY = y-size - endY = y - if (i==2 or i==4): - startY = y - endY = y + size - if (i==4 or i==5): xOffset = -size - if (i==1 or i==2): xOffset = +size - xpos = x + xOffset - oled.line(xpos, startY, xpos, endY, 1); - -def update_screen(digit_val): - oled.fill(0) - oled.text('Clock Digit Lab', 0, 0, 1) - drawDigit(digit_val, 64, 32, 20) - oled.text(str(digit_val), 0, 54, 1) - oled.show() - -counter = 0 -while True: - update_screen(counter) - sleep(1) - counter += 1 - if counter > 9: - counter = 0 - diff --git a/src/network/clock/clock-digits-v2.py b/src/network/clock/clock-digits-v2.py deleted file mode 100644 index 41240883b..000000000 --- a/src/network/clock/clock-digits-v2.py +++ /dev/null @@ -1,82 +0,0 @@ -# clock digits -import machine -import utime -import ssd1306 -from utime import sleep, localtime -led = machine.Pin(25, machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA, baudrate=100000) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -segmentMapping = [ - #a, b, c, d, e, f, g - [1, 1, 1, 1, 1, 1, 0], # 0 - [0, 1, 1, 0, 0, 0, 0], # 1 - [1, 1, 0, 1, 1, 0, 1], # 2 - [1, 1, 1, 1, 0, 0, 1], # 3 - [0, 1, 1, 0, 0, 1, 1], # 4 - [1, 0, 1, 1, 0, 1, 1], # 5 - [1, 0, 1, 1, 1, 1, 1], # 6 - [1, 1, 1, 0, 0, 0, 0], # 7 - [1, 1, 1, 1, 1, 1, 1], # 8 - [1, 1, 1, 1, 0, 1, 1] # 9 -]; - - -# x and y are the center of the digit, size is the center to edge -def drawDigit(digit, x, y, size): - - segmentOn = segmentMapping[digit]; - - # Horizontal segments - for i in [0, 3, 6]: - if (segmentOn[i]): - if (i==0): yOffset = 0 # top - if (i==3): yOffset = size*2 # bottom element - if (i==6): yOffset = size # middle - oled.line(x - size, y+yOffset-size, x + size, y+yOffset-size, 1); - - # Vertical segments - for i in [1, 2, 4, 5]: - if (segmentOn[i]) : - if (i==1 or i==5): - startY = y-size - endY = y - if (i==2 or i==4): - startY = y - endY = y + size - if (i==4 or i==5): xOffset = -size - if (i==1 or i==2): xOffset = +size - xpos = x + xOffset - oled.line(xpos, startY, xpos, endY, 1); - -def update_screen(digit_val): - oled.fill(0) - oled.text('Clock Digit Lab', 0, 0, 1) - drawDigit(digit_val, 20, 32, 10) - drawDigit(digit_val, 45, 32, 10) - drawDigit(digit_val, 80, 32, 10) - drawDigit(digit_val, 110, 32, 10) - oled.text(str(digit_val), 0, 54, 1) - draw_colon() - oled.show() - -def draw_colon(): - oled.fill_rect(64, 28, 2, 2,1) - oled.fill_rect(64, 36, 2, 2,1) - -counter = 0 -while True: - update_screen(counter) - sleep(1) - counter += 1 - if counter > 9: - counter = 0 - diff --git a/src/network/clock/clock-digits.py b/src/network/clock/clock-digits.py deleted file mode 100644 index 9ef350521..000000000 --- a/src/network/clock/clock-digits.py +++ /dev/null @@ -1,74 +0,0 @@ -# clock digits -import machine -import utime -import ssd1306 -from utime import sleep, localtime -led = machine.Pin(25, machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA, baudrate=100000) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -segmentMapping = [ - #a, b, c, d, e, f, g - [1, 1, 1, 1, 1, 1, 0], # 0 - [0, 1, 1, 0, 0, 0, 0], # 1 - [1, 1, 0, 1, 1, 0, 1], # 2 - [1, 1, 1, 1, 0, 0, 1], # 3 - [0, 1, 1, 0, 0, 1, 1], # 4 - [1, 0, 1, 1, 0, 1, 1], # 5 - [1, 0, 1, 1, 1, 1, 1], # 6 - [1, 1, 1, 0, 0, 0, 0], # 7 - [1, 1, 1, 1, 1, 1, 1], # 8 - [1, 1, 1, 1, 0, 1, 1] # 9 -]; - - -# x and y are the center of the digit, size is the center to edge -def drawDigit(digit, x, y, size): - - segmentOn = segmentMapping[digit]; - - # Horizontal segments - for i in [0, 3, 6]: - if (segmentOn[i]): - if (i==0): yOffset = 0 # top - if (i==3): yOffset = size*2 # bottom element - if (i==6): yOffset = size # middle - oled.line(x - size, y+yOffset-size, x + size, y+yOffset-size, 1); - - # Vertical segments - for i in [1, 2, 4, 5]: - if (segmentOn[i]) : - if (i==1 or i==5): - startY = y-size - endY = y - if (i==2 or i==4): - startY = y - endY = y + size - if (i==4 or i==5): xOffset = -size - if (i==1 or i==2): xOffset = +size - xpos = x + xOffset - oled.line(xpos, startY, xpos, endY, 1); - -def update_screen(digit_val): - oled.fill(0) - oled.text('Clock Digit Lab', 0, 0, 1) - drawDigit(digit_val, 64, 32, 20) - oled.text(str(digit_val), 0, 54, 1) - oled.show() - -counter = 0 -while True: - update_screen(counter) - sleep(1) - counter += 1 - if counter > 9: - counter = 0 - diff --git a/src/network/clock/clock.py b/src/network/clock/clock.py deleted file mode 100644 index ab36b124b..000000000 --- a/src/network/clock/clock.py +++ /dev/null @@ -1,81 +0,0 @@ -import ntptime, network -from machine import RTC -from utime import sleep, sleep_ms, time, localtime, mktime -import config.py -# wifi_ssid = -# wifi_pass = - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -def setRTC(): - timeset = False - timetries = 0 - maxtries = 5 - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.') - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - # print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - print('ERROR! Unable to update time from server!') - return False - -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -if __name__ == '__main__': - while True: - update() - sleep(60) diff --git a/src/network/clock/config.py b/src/network/clock/config.py deleted file mode 100644 index f30a44911..000000000 --- a/src/network/clock/config.py +++ /dev/null @@ -1,2 +0,0 @@ -wifi_ssid = 'anndan-4.2' -wifi_pass = 'stargate123' \ No newline at end of file diff --git a/src/network/clock/display-localtime.py b/src/network/clock/display-localtime.py deleted file mode 100644 index 77ce33836..000000000 --- a/src/network/clock/display-localtime.py +++ /dev/null @@ -1,45 +0,0 @@ -import machine -import utime -import ssd1306 -from utime import sleep, localtime -led = machine.Pin('LED', machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -def timeStrFmt(): - hour = localtime()[3] - if hour > 12: - hour = hour - 12 - am_pm = ' pm' - else: am_pm = ' am' - # format minutes and seconds with leading zeros - minutes = "{:02d}".format(localtime()[4]) - seconds = "{:02d}".format(localtime()[5]) - return str(hour) + ':' + minutes + ':' + seconds + am_pm - -def dateStrFmt(): - return str(localtime()[1]) + '/' + str(localtime()[2]) + '/' + str(localtime()[0]) - -def update_display(timeStr, dateStr): - oled.fill(0) - oled.text(timeStr, 10, 10, 1) - oled.text(dateStr, 10, 20, 1) - oled.show() - -counter = 0 -while True: - update_display(timeStrFmt(), dateStrFmt()) - print(localtime(), dateStrFmt(), timeStrFmt(), counter) - led.toggle() - counter += 1 - sleep(1) - - diff --git a/src/network/clock/wifi-clock-main-v2.py b/src/network/clock/wifi-clock-main-v2.py deleted file mode 100644 index 598053f2b..000000000 --- a/src/network/clock/wifi-clock-main-v2.py +++ /dev/null @@ -1,211 +0,0 @@ -import ntptime, network -from machine import RTC -from utime import sleep, sleep_ms, time, localtime, mktime -import ssd1306 - -import config -# wifi_ssid = -# wifi_pass = - -led = machine.Pin('LED', machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -# global array of integers for holding the current date and time -# Values are year=[0], month[1], day[2], hour[3], minute[4], second[5] -current_time = [] * 7 -year = 0 -month = 0 -day = 0 -hour = 0 -minute = 0 -second = 0 - -# display a string on the 128x64 OLED screen using 9 pixel height and 16 characters per line -def display_msg(in_str, chunk_size=16): - print(in_str) - oled.fill(0) - if len(in_str) < chunk_size: - oled.text(in_str, 0, 0) - else: - # create an array of the strings for each line - a = [in_str[i:i+chunk_size] for i in range(0, len(in_str), chunk_size)] - for i in range(0,len(a)): - oled.text(a[i], 0, i*9) - oled.show() - -# Connect the the local Wifi access point -# get the wifi network name and password from the config.py file -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - message = 'Connecting to ' + config.wifi_ssid - display_msg(message) - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - message = message + '.' - display_msg(message + str(10-max_wait)) - max_wait -= 1 - print() - if wifi.status() != 3: - display_msg('Error: Could not connect to wifi!') - display_msg('Connected IP: ' + wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -maxtries = 5 -timetries = 0 -timeset = False - -def setRTC(): - global maxtries, current_time, timetries, timeset, year, month, day, hour, minute, second - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - error_msg = 'NTP update attempt' + str(timetries) + ' of ' + str(maxtries) + ' Check config.' - display_msg(error_msg) - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - print('myt: ', myt) - current_time = myt - year = myt[0] - month = myt[1] - day = myt[2] - hour = myt[3] - minute = myt[4] - second = myt[5] - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - print('Seconds in myt[5]', myt[5]) - sleep_ms(200) - dtime = rtc.datetime() - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - display_msg('ERROR! Unable to update time from server:' + ntptime.host) - return False - -# get an update of the time from the Network Time Protocol Server -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -def timeStrFmt(): - hour = current_time[3] - if hour > 12: - hour = hour - 12 - am_pm = ' pm' - else: am_pm = ' am' - # format minutes and seconds with leading zeros - minutes = "{:02d}".format(current_time[4]) - seconds = "{:02d}".format(current_time[5]) - return str(hour) + ':' + minutes + ':' + seconds + am_pm - -def dateStrFmt(): - return str(month) + '/' + str(day) + str(year) - -def update_display(year, month, day, hour, minute, second): - oled.fill(0) - # no 12/24, leadering zero formatting or am/pm formatting - # time_strs = str(hour) + ':' + str(minute) + ':' + str(second) - # with formatting - timestrf = '%2d:%02d:%02d %s' %(12 if hour == 0 else hour if hour < 13 else hour - 12, minute, second, 'am' if hour < 12 else 'pm') - oled.text(timestrf, 10, 20, 1) - - date_str = str(month) + '/' + str(day) + '/' + str(year) - oled.text(date_str, 10, 40, 1) - oled.show() - -def update_wifi_status(): - oled.fill(0) - oled.text('n: ' + config.wifi_ssid , 0, 0, 1) - oled.text('tries: ' + str(timetries), 0, 10, 1) - if timeset: - oled.text('Connection OK', 0, 20, 1) - else: - oled.text('CONNECTION ERROR', 0, 20, 1) - oled.text('host: ' + ntptime.host, 0, 30, 1) - oled.show() - -def break_string_into_chunks(s, chunk_size=12): - """Breaks a string into chunks of a specified size.""" - return [s[i:i+chunk_size] for i in range(0, len(s), chunk_size)] - -led.on() -display_msg('Booting.') -sleep(.5) - -display_msg('Updating from NTP.') -sleep(.5) -update() - -display_msg('Updating from NTP.') -update_wifi_status() -sleep(1) - -update_display(year, month, day, hour, minute, second) - -# run this loop every second -while True: - - print('current time:', year, month, day, hour, minute, second) - update_display(year, month, day, hour, minute, second) - led.toggle() - sleep(1) - second += 1 - - # check the time server every hour - if second > 59: - second = 0 - if minute > 59: - minute = 0 - # get a new time from the network time server at 2:47 am each night - if (hour == 2) and (minute == 24): - display_message('Syncing time server') - update() - if hour > 23: - hour = 0 - else: - hour += 1 - else: - minute += 1 diff --git a/src/network/clock/wifi-clock-main.py b/src/network/clock/wifi-clock-main.py deleted file mode 100644 index b862be753..000000000 --- a/src/network/clock/wifi-clock-main.py +++ /dev/null @@ -1,159 +0,0 @@ -import ntptime, network -from machine import RTC -from utime import sleep, sleep_ms, time, localtime, mktime -import ssd1306 - -import config -# wifi_ssid = -# wifi_pass = - -led = machine.Pin('LED', machine.Pin.OUT) - -SCL=machine.Pin(2) # SPI CLock -SDA=machine.Pin(3) # SPI Data -spi=machine.SPI(0, sck=SCL, mosi=SDA) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -# global variable for holding the current time array year, month, day, hour, minute, second -current_time = [] * 8 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -maxtries = 5 -timetries = 0 -timeset = False - -def setRTC(): - global maxtries, current_time, timetries, timeset - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.') - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - current_time = myt - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - # print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - print('ERROR! Unable to update time from server!') - return False - -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -def timeStrFmt(): - hour = current_time[3] - if hour > 12: - hour = hour - 12 - am_pm = ' pm' - else: am_pm = ' am' - # format minutes and seconds with leading zeros - minutes = "{:02d}".format(current_time[4]) - seconds = "{:02d}".format(current_time[5]) - return str(hour) + ':' + minutes + ':' + seconds + am_pm - -def dateStrFmt(): - return str(current_time[1]) + '/' + str(current_time[2]) + '/' + str(current_time[0]) - -def update_clock(timeStr, dateStr): - oled.fill(0) - oled.text(timeStr, 10, 10, 1) - oled.text(dateStr, 10, 20, 1) - oled.show() - -def update_wifi_status(): - oled.fill(0) - oled.text('n: ' + config.wifi_ssid , 0, 0, 1) - oled.text('tries: ' + str(timetries), 0, 10, 1) - if timeset: - oled.text('Connection OK', 0, 20, 1) - else: - oled.text('CONNECTION ERROR', 0, 20, 1) - oled.text('host: ' + ntptime.host, 0, 30, 1) - oled.show() - -second_counter = 0 -minute_counter = 0 -hour_counter = 0 -update() -update_wifi_status() -sleep(3) - -# run this loop every second -while True: - update_clock(timeStrFmt(), dateStrFmt()) - # print(localtime()) - print(dateStrFmt(), timeStrFmt()) - led.toggle() - sleep(1) - # check the time server every hour - if second_counter > 59: - second_counter = 0 - if minute_counter > 59: - minute_counter = 0 - if hour_counter > 23: - # get a new time from the network time server - update() - hour_counter = 0 - else: - hour_counter += 1 - else: - minute_counter += 1 - else: - second_counter += 1 - current_time[5] += 1 - diff --git a/src/network/display/display-clock.py b/src/network/display/display-clock.py deleted file mode 100644 index ad0ed0d8c..000000000 --- a/src/network/display/display-clock.py +++ /dev/null @@ -1,106 +0,0 @@ -from machine import Pin -import network -import ntptime -import ssd1306 -# where we keep the WiFi password -import secrets -from utime import sleep, ticks_ms, ticks_diff - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(4) -DC = machine.Pin(5) -RES = machine.Pin(6) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -# US Central -timeZone = -6 -# try one of these -ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org' -ntptime.timeout = 10 - -def wifiConnect(): - wifi = network.WLAN(network.STA_IF) - wifi.active(True) - wifi.config(pm = 0xa11140) # disables wifi sleep mode - if not wifi.isconnected(): - wifi.connect(config.wifi_ssid, config.wifi_pass) - print('Connecting..', end='') - max_wait = 10 - while max_wait > 0: - if wifi.status() < 0 or wifi.status() >= 3: break - sleep_ms(1000) - print('.', end='') - max_wait -= 1 - print() - if wifi.status() != 3: print('Could not connect to wifi!') - # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0]) - sleep_ms(100) - return wifi - -# daylight savings time -def dst(): - year, weekday = localtime()[0], localtime()[6] - dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0)) - dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0)) - return dst_start <= time() < dst_end - -timestr = '' -datestr = '' -dtime = [] -def setRTC(): - global timestr, datestr, dtime - timeset = False - timetries = 0 - maxtries = 5 - while not timeset and timetries < maxtries: - timetries += 1 - try: - ntptime.settime() # update time from ntp server - timeset = True - except: - print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.') - if timetries < maxtries: sleep_ms(15000) - if timeset: - sleep_ms(200) - rtc = RTC() - tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600 - #tz_offset = timeZone * 3600 # without daylight savings - myt = localtime(time() + tz_offset) - rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0)) - sleep_ms(200) - dtime = rtc.datetime() - # set globals - # hh:mm in 12hr am/pm format - timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm') - # mm/dd/yy - datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}' - # print('Time set to:', timestr, datestr) - print(timestr, datestr) - return True - print('ERROR! Unable to update time from server!') - return False - -def update(): - success = False - wifi = wifiConnect() - sleep_ms(100) - if wifi.isconnected(): - success = setRTC() - sleep_ms(100) - return wifi, success - -def update_display(): - global timestr, datestr,dtime - oled.fill(0) - oled.text(timestr + ' ' + datestr, 0, 10, 1) - oled.show() - -while True: - update() - update_display() - sleep(60) diff --git a/src/network/display/display-weather-forecast.py b/src/network/display/display-weather-forecast.py deleted file mode 100644 index f3d44ebe5..000000000 --- a/src/network/display/display-weather-forecast.py +++ /dev/null @@ -1,129 +0,0 @@ -import network -import ssd1306 -import secrets -import urequests -from utime import sleep, ticks_ms, ticks_diff - -# startup - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) - - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def display_startup(counter): - oled.fill(0) - oled.text('Running startup', 0, 10, 1) - oled.text('Connecting to', 0, 20, 1) - oled.text(secrets.SSID, 0, 30, 1) - oled.text(str(counter), 0, 40, 1) - oled.show() - -def display_status(counter): - oled.fill(0) - # display the network name - oled.text('n:' + secrets.SSID, 0, 0, 1) - - # display the connection time - oled.text('t:', 0, 10, 1) - oled.text(str(connection_time)+ ' ms', 15, 10, 1) - oled.show() - -def display_weather(): - global weather, city, current_temp - oled.fill(0) - min = 120 - max = -50 - for i in range(0, 39): - temp = round(weather['list'][i]['main']['temp']) - if temp < min: - min = temp - if temp > max: - max = temp - min = round(min) - max = round(max) - temp_range_height = max - min - graph_height = 54 - scale = graph_height/temp_range_height - print('min/max/range/scale:', min, max, temp_range_height, scale) - - # display city name, current temp, min and max - oled.text(city + ': ' + str(current_temp), 0, 0, 1) - oled.text(str(min), 0, 57, 1) # bottom left corner - oled.text(str(max), 0, 10, 1) # under top row - - max_points = 39 - - # graph temps for the next n periods - print('Date Tmp TNx Y Y2 Del') - for i in range(0, max_points): - temp = round(weather['list'][i]['main']['temp']) - x = i * 3 # scaled x - y = 63 - round((temp - min)*scale) - oled.pixel(x, y, 1) - - # now draw the next two points - if i < max_points: - temp_next = round(weather['list'][i+1]['main']['temp']) - y_next = 63 - round((temp_next - min)*scale) - y_delta = -round((y - y_next)/3) # a small positive or negative number - - print(weather['list'][i]['dt_txt'][0:13], - '{: 3.3d}'.format(temp), - '{: 3.3d}'.format(temp_next), - '{: 3.3d}'.format(y), - '{: 3.3d}'.format(y_next), - '{: 3.3d}'.format(y_delta)) - - # should be 1/3 of the way to the next point - oled.pixel(x+1, y + y_delta, 1) - # should be 2/3 of the way to the next point - oled.pixel(x+2, y + 2*y_delta, 1) - oled.show() - -start = ticks_ms() # start a millisecond counter - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - while not wlan.isconnected(): - sleep(1) - print(counter, '.', sep='', end='', ) - counter += 1 - display_startup(counter) - -delta = ticks_diff(ticks_ms(), start) -#print("Connect Time:", delta, 'milliseconds') -#print("IP Address:", wlan.ifconfig()[0]) - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid -#print(url) - -max_times = 39 -#for i in range(0, max_times): - #print(' Temp: ', weather['list'][i]['main']['temp']) - -while True: - # globals: weather, city, current_temp - weather = urequests.get(url).json() - # print(weather) - city = weather['city']['name'] - current_temp = round(weather['list'][0]['main']['temp']) - display_weather() - print('Going to sleep for one hour') - sleep(3600) # sleep one hour \ No newline at end of file diff --git a/src/network/display/main.py b/src/network/display/main.py deleted file mode 100644 index 654d28f6b..000000000 --- a/src/network/display/main.py +++ /dev/null @@ -1,88 +0,0 @@ -# make a number scroll to the right and increment the number and move down one pixel -# this test patten shows the device is working and will not burn any single pixel if it runs a long time -from machine import Pin -import network -import ssd1306 -import secrets -from utime import sleep, ticks_ms, ticks_diff - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def mac_address_fmt(): - mac_addess = wlan.config('mac') - s="" - for digit in range(0,5): - s+=str(hex(mac_addess[digit]))[2:4] + ':' - s+= hex(mac_addess[5])[2:4] - return s - -def display_startup(counter): - oled.fill(0) - oled.text('Running startup', 0, 10, 1) - oled.text('Connecting to', 0, 20, 1) - oled.text(secrets.SSID, 0, 30, 1) - oled.text(str(counter), 0, 40, 1) - oled.show() - -def display_status(counter): - oled.fill(0) - # display the network name - oled.text('n:' + secrets.SSID, 0, 0, 1) - - # display the connection time - oled.text('t:', 0, 10, 1) - oled.text(str(connection_time)+ ' ms', 15, 10, 1) - - # display the MAC address - oled.text(mac_address_fmt(), 0, 20, 1) - - # display the IP address - oled.text('ip:' + wlan.ifconfig()[0], 0, 30, 1) - oled.text('c:' + str(counter), 0, 40, 1) - oled.show() -# startup -led = Pin("LED", Pin.OUT) -led.on() - -start = ticks_ms() # start a millisecond counter - -print('Connecting to WiFi Network Name:', secrets.SSID) -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -if not wlan.isconnected(): - wlan.connect(secrets.SSID, secrets.PASSWORD) - print("Waiting for connection...") - counter = 0 - display_startup(counter) - while not wlan.isconnected(): - sleep(1) - counter += 1 - led.toggle() - display_startup(counter) - print(counter, '.', sep='', end='') - -connection_time = ticks_diff(ticks_ms(), start) -mac_addess = wlan.config('mac') -print('Connected to', secrets.SSID) -print('Total connect milliseconds:', connection_time) - - -counter = 0 -while True: - led.toggle() - counter += 1 - display_status(counter) - sleep(.5) - - - \ No newline at end of file diff --git a/src/network/display/oled-ssd1306-spi-test.py b/src/network/display/oled-ssd1306-spi-test.py deleted file mode 100644 index 0c2d12930..000000000 --- a/src/network/display/oled-ssd1306-spi-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# make a number scroll to the right and increment the number and move down one pixel -# this test patten shows the device is working and will not burn any single pixel if it runs a long time -import machine -import ssd1306 -from time import sleep - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -counter = 0 -print('dispaying text...') -while True: - for i in range(HEIGHT - 10): - oled.text(str(counter), 0, i, 1) - for j in range(WIDTH): - oled.scroll(1,0) - oled.show() - print(counter, '.', sep="", end="") - counter += 1; - - - - - \ No newline at end of file diff --git a/src/network/memory-stats-timer.py b/src/network/memory-stats-timer.py deleted file mode 100644 index 3d3560460..000000000 --- a/src/network/memory-stats-timer.py +++ /dev/null @@ -1,20 +0,0 @@ -import gc -from machine import Timer - -initial_free_memory = gc.mem_free() - -myTimer1 = Timer() -myTimer2 = Timer() -myTimer3 = Timer() -myTimer4 = Timer() -myTimer5 = Timer() -myTimer6 = Timer() -myTimer7 = Timer() -myTimer8 = Timer() -myTimer9 = Timer() -myTimer10 = Timer() - -diff = initial_free_memory - gc.mem_free() - -print(initial_free_memory, diff, diff/10) - diff --git a/src/network/rgb-sliders.html b/src/network/rgb-sliders.html deleted file mode 100644 index a39912b44..000000000 --- a/src/network/rgb-sliders.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - -

                                                                                                                                                                                                                                                                                                                                                                                          Custom Range Slider

                                                                                                                                                                                                                                                                                                                                                                                          - -
                                                                                                                                                                                                                                                                                                                                                                                          - -

                                                                                                                                                                                                                                                                                                                                                                                          Red:

                                                                                                                                                                                                                                                                                                                                                                                          - -
                                                                                                                                                                                                                                                                                                                                                                                          - -

                                                                                                                                                                                                                                                                                                                                                                                          Green:

                                                                                                                                                                                                                                                                                                                                                                                          - - - -

                                                                                                                                                                                                                                                                                                                                                                                          Blue:

                                                                                                                                                                                                                                                                                                                                                                                          - - - - - diff --git a/src/network/test-ssl.py b/src/network/test-ssl.py deleted file mode 100644 index e3254d114..000000000 --- a/src/network/test-ssl.py +++ /dev/null @@ -1,10 +0,0 @@ -import socket -import ssl - -hostname = 'www.python.org' -context = ssl.create_default_context() - -with socket.create_connection((hostname, 443)) as sock: - with context.wrap_socket(sock, server_hostname=hostname) as ssock: - print(ssock.version()) -# returns: TLSv1.3 \ No newline at end of file diff --git a/src/network/web-server-async.py b/src/network/web-server-async.py deleted file mode 100644 index 18e598ef7..000000000 --- a/src/network/web-server-async.py +++ /dev/null @@ -1,97 +0,0 @@ -import network -import socket -import time - -from machine import Pin -import uasyncio as asyncio - -led = Pin(15, Pin.OUT) -onboard = Pin("LED", Pin.OUT, value=0) - -ssid = 'A Network' -password = 'A Password' - -html = """ - - Pico W - -

                                                                                                                                                                                                                                                                                                                                                                                          Pico W Async Web Server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          A non-blocking server

                                                                                                                                                                                                                                                                                                                                                                                          -

                                                                                                                                                                                                                                                                                                                                                                                          %s

                                                                                                                                                                                                                                                                                                                                                                                          - - -""" - -wlan = network.WLAN(network.STA_IF) - -def connect_to_network(): - wlan.active(True) - wlan.config(pm = 0xa11140) # Disable power-save mode - wlan.connect(ssid, password) - - # max number of seconds to wait before we timeout - max_wait = 10 - while max_wait > 0: - if wlan.status() < 0 or wlan.status() >= 3: - break - max_wait -= 1 - print('waiting for connection...') - time.sleep(1) - - if wlan.status() != 3: - raise RuntimeError('network connection failed') - else: - print('connected') - status = wlan.ifconfig() - print('ip = ' + status[0]) - -async def serve_client(reader, writer): - print("Client connected") - request_line = await reader.readline() - print("Request:", request_line) - # We are not interested in HTTP request headers, skip them - while await reader.readline() != b"\r\n": - pass - - request = str(request_line) - led_on = request.find('/light/on') - led_off = request.find('/light/off') - print( 'led on = ' + str(led_on)) - print( 'led off = ' + str(led_off)) - - stateis = "" - if led_on == 6: - print("led on") - led.value(1) - stateis = "LED is ON" - - if led_off == 6: - print("led off") - led.value(0) - stateis = "LED is OFF" - - response = html % stateis - writer.write('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n') - writer.write(response) - - await writer.drain() - await writer.wait_closed() - print("Client disconnected") - -async def main(): - print('Connecting to Network...') - connect_to_network() - - print('Setting up webserver...') - asyncio.create_task(asyncio.start_server(serve_client, "0.0.0.0", 80)) - while True: - onboard.on() - print("heartbeat") - await asyncio.sleep(0.25) - onboard.off() - await asyncio.sleep(5) - -try: - asyncio.run(main()) -finally: - asyncio.new_event_loop() \ No newline at end of file diff --git a/src/oled/VL53L0X-display.py b/src/oled/VL53L0X-display.py deleted file mode 100644 index 7116ea4d3..000000000 --- a/src/oled/VL53L0X-display.py +++ /dev/null @@ -1,41 +0,0 @@ -# VL53L0X Display Test - -import time -from machine import Pin -from machine import I2C -import VL53L0X -import sh1106 - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -display.rotate(1) - - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 18) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 14) - -while True: -# Start ranging - tof.start() - display.fill(0) - display.text('Distance:', 0, 0, 1) - display.text(str(tof.read()), 20, 20, 1) - display.show() - tof.stop() - - - - - - - - #q = tof.set_signal_rate_limit(0.1) - # - # time.sleep(0.1) diff --git a/src/oled/border.py b/src/oled/border.py deleted file mode 100644 index 5f513dff8..000000000 --- a/src/oled/border.py +++ /dev/null @@ -1,17 +0,0 @@ -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -oled = SSD1306_I2C(width, height, i2c) - -oled.hline(0, 0, width - 1, 1) # top edge -oled.hline(0, height - 1, width - 1, 1) # bottom edge -oled.vline(0, 0, height - 1, 1) # left edge -oled.vline(width - 1, 0, height - 1, 1) # right edge -oled.show() \ No newline at end of file diff --git a/src/oled/bounce.py b/src/oled/bounce.py deleted file mode 100644 index 7df787b71..000000000 --- a/src/oled/bounce.py +++ /dev/null @@ -1,66 +0,0 @@ -import machine -import utime -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(0) -scl=machine.Pin(1) -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -# oled = SSD1306_I2C(width, height, i2c) -display = sh1106.SH1106_I2C(width, height, i2c, Pin(4), 0x3c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 1, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# ok, not really a circle - just a square for now -def draw_ball(x,y, size, state): - if size == 1: - oled.pixel(x, y, state) # draw a single pixel - else: - for i in range(0,size): # draw a box of pixels of the right size - for j in range(0,size): - oled.pixel(x + i, y + j, state) - # TODO: for size above 4 round the corners - -border(width, height) - -ball_size = 2 -current_x = int(width / 2) -current_y = int(height / 2) -direction_x = 1 -direction_y = -1 -# delay_time = .0001 - -# Bounce forever -while True: - draw_ball(current_x,current_y, ball_size,1) - oled.show() - # utime.sleep(delay_time) - draw_ball(current_x,current_y,ball_size,0) - # reverse at the edges - # left edge test - if current_x < 2: - direction_x = 1 - # right edge test - if current_x > width - ball_size -2: - direction_x = -1 - # top edge test - if current_y < 2: - direction_y = 1 - # bottom edge test - if current_y > height - ball_size - 2: - direction_y = -1 - # update the ball - current_x = current_x + direction_x - current_y = current_y + direction_y - - -print('done') \ No newline at end of file diff --git a/src/oled/circuit-python/test-ssd1306-i2c.py b/src/oled/circuit-python/test-ssd1306-i2c.py deleted file mode 100644 index 5de6a78a1..000000000 --- a/src/oled/circuit-python/test-ssd1306-i2c.py +++ /dev/null @@ -1,36 +0,0 @@ -# Basic example of clearing and drawing pixels on a SSD1306 OLED display. -# This example and library is meant to work with Adafruit CircuitPython API. -# Author: Tony DiCola -# License: Public Domain - -# Import all board pins. -from board import SCL, SDA -import busio - -# Import the SSD1306 module. -import adafruit_ssd1306 - - -# Create the I2C interface. -i2c = busio.I2C(SCL, SDA) - -# Create the SSD1306 OLED class. -# The first two parameters are the pixel width and pixel height. Change these -# to the right size for your display! -display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c) -# Alternatively you can change the I2C address of the device with an addr parameter: -#display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, addr=0x31) - -# Clear the display. Always call show after changing pixels to make the display -# update visible! -display.fill(0) - -display.show() - -# Set a pixel in the origin 0,0 position. -display.pixel(0, 0, 1) -# Set a pixel in the middle 64, 16 position. -display.pixel(64, 16, 1) -# Set a pixel in the opposite 127, 31 position. -display.pixel(127, 31, 1) -display.show() \ No newline at end of file diff --git a/src/oled/draw-icon.py b/src/oled/draw-icon.py deleted file mode 100644 index 5d29d2cc7..000000000 --- a/src/oled/draw-icon.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -ICON = [ - [ 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 1, 1, 0, 0, 0, 1, 1, 0], - [ 1, 1, 1, 1, 0, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 1, 1, 1, 1, 1, 0, 0], - [ 0, 0, 0, 1, 1, 1, 0, 0, 0], - [ 0, 0, 0, 0, 1, 0, 0, 0, 0], -] - -oled.fill(0) # Clear the display -for y, row in enumerate(ICON): - for x, c in enumerate(row): - oled.pixel(x, y, c) - -#oled.show() - - diff --git a/src/oled/drivers/sh1106.py b/src/oled/drivers/sh1106.py deleted file mode 100644 index 3158eb116..000000000 --- a/src/oled/drivers/sh1106.py +++ /dev/null @@ -1,227 +0,0 @@ -# -# MicroPython SH1106 OLED driver, I2C and SPI interfaces -# -# The MIT License (MIT) -# -# Copyright (c) 2016 Radomir Dopieralski (@deshipu), -# 2017 Robert Hammelrath (@robert-hh) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Sample code sections -# ------------ SPI ------------------ -# Pin Map SPI -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D7 - GPIO 13 - Din / MOSI fixed -# - D5 - GPIO 14 - Clk / Sck fixed -# - D8 - GPIO 4 - CS (optional, if the only connected device) -# - D2 - GPIO 5 - D/C -# - D1 - GPIO 2 - Res -# -# for CS, D/C and Res other ports may be chosen. -# -# from machine import Pin, SPI -# import sh1106 - -# spi = SPI(1, baudrate=1000000) -# display = sh1106.SH1106_SPI(128, 64, spi, Pin(5), Pin(2), Pin(4)) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() -# -# --------------- I2C ------------------ -# -# Pin Map I2C -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D2 - GPIO 5 - SCK / SCL -# - D1 - GPIO 4 - DIN / SDA -# - D0 - GPIO 16 - Res -# - G - xxxxxx CS -# - G - xxxxxx D/C -# -# Pin's for I2C can be set almost arbitrary -# -# from machine import Pin, I2C -# import sh1106 -# -# i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) -# display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() - -from micropython import const -import utime as time -import framebuf - - -# a few register definitions -_SET_CONTRAST = const(0x81) -_SET_NORM_INV = const(0xa6) -_SET_DISP = const(0xae) -_SET_SCAN_DIR = const(0xc0) -_SET_SEG_REMAP = const(0xa0) -_LOW_COLUMN_ADDRESS = const(0x00) -_HIGH_COLUMN_ADDRESS = const(0x10) -_SET_PAGE_ADDRESS = const(0xB0) - - -class SH1106: - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, - framebuf.MVLSB) - self.framebuf = fb -# set shortcuts for the methods of framebuf - self.fill = fb.fill - self.fill_rect = fb.fill_rect - self.hline = fb.hline - self.vline = fb.vline - self.line = fb.line - self.rect = fb.rect - self.pixel = fb.pixel - self.scroll = fb.scroll - self.text = fb.text - self.blit = fb.blit - - self.init_display() - - def init_display(self): - self.reset() - self.fill(0) - self.poweron() - self.show() - - def poweroff(self): - self.write_cmd(_SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(_SET_DISP | 0x01) - - def rotate(self, flag, update=True): - if flag: - self.write_cmd(_SET_SEG_REMAP | 0x01) # mirror display vertically - self.write_cmd(_SET_SCAN_DIR | 0x08) # mirror display hor. - else: - self.write_cmd(_SET_SEG_REMAP | 0x00) - self.write_cmd(_SET_SCAN_DIR | 0x00) - if update: - self.show() - - def sleep(self, value): - self.write_cmd(_SET_DISP | (not value)) - - def contrast(self, contrast): - self.write_cmd(_SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(_SET_NORM_INV | (invert & 1)) - - def show(self): - for page in range(self.height // 8): - self.write_cmd(_SET_PAGE_ADDRESS | page) - self.write_cmd(_LOW_COLUMN_ADDRESS | 2) - self.write_cmd(_HIGH_COLUMN_ADDRESS | 0) - self.write_data(self.buffer[ - self.width * page:self.width * page + self.width - ]) - - def reset(self, res): - if res is not None: - res(1) - time.sleep_ms(1) - res(0) - time.sleep_ms(20) - res(1) - time.sleep_ms(20) - - -class SH1106_I2C(SH1106): - def __init__(self, width, height, i2c, res=None, addr=0x3c, - external_vcc=False): - self.i2c = i2c - self.addr = addr - self.res = res - self.temp = bytearray(2) - if res is not None: - res.init(res.OUT, value=1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.i2c.writeto(self.addr, b'\x40'+buf) - - def reset(self): - super().reset(self.res) - - -class SH1106_SPI(SH1106): - def __init__(self, width, height, spi, dc, res=None, cs=None, - external_vcc=False): - self.rate = 10 * 1000 * 1000 - dc.init(dc.OUT, value=0) - if res is not None: - res.init(res.OUT, value=0) - if cs is not None: - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - else: - self.dc(0) - self.spi.write(bytearray([cmd])) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) - else: - self.dc(1) - self.spi.write(buf) - - def reset(self): - super().reset(self.res) diff --git a/src/oled/drivers/ssd1306.py b/src/oled/drivers/ssd1306.py deleted file mode 100644 index 6359c85ea..000000000 --- a/src/oled/drivers/ssd1306.py +++ /dev/null @@ -1,155 +0,0 @@ -# MicroPython SSD1306 OLED driver, I2C and SPI interfaces - -from micropython import const -import framebuf - - -# register definitions -SET_CONTRAST = const(0x81) -SET_ENTIRE_ON = const(0xA4) -SET_NORM_INV = const(0xA6) -SET_DISP = const(0xAE) -SET_MEM_ADDR = const(0x20) -SET_COL_ADDR = const(0x21) -SET_PAGE_ADDR = const(0x22) -SET_DISP_START_LINE = const(0x40) -SET_SEG_REMAP = const(0xA0) -SET_MUX_RATIO = const(0xA8) -SET_COM_OUT_DIR = const(0xC0) -SET_DISP_OFFSET = const(0xD3) -SET_COM_PIN_CFG = const(0xDA) -SET_DISP_CLK_DIV = const(0xD5) -SET_PRECHARGE = const(0xD9) -SET_VCOM_DESEL = const(0xDB) -SET_CHARGE_PUMP = const(0x8D) - -# Subclassing FrameBuffer provides support for graphics primitives -# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html -class SSD1306(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB) - self.init_display() - - def init_display(self): - for cmd in ( - SET_DISP | 0x00, # off - # address setting - SET_MEM_ADDR, - 0x00, # horizontal - # resolution and layout - SET_DISP_START_LINE | 0x00, - SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 - SET_MUX_RATIO, - self.height - 1, - SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0 - SET_DISP_OFFSET, - 0x00, - SET_COM_PIN_CFG, - 0x02 if self.width > 2 * self.height else 0x12, - # timing and driving scheme - SET_DISP_CLK_DIV, - 0x80, - SET_PRECHARGE, - 0x22 if self.external_vcc else 0xF1, - SET_VCOM_DESEL, - 0x30, # 0.83*Vcc - # display - SET_CONTRAST, - 0xFF, # maximum - SET_ENTIRE_ON, # output follows RAM contents - SET_NORM_INV, # not inverted - # charge pump - SET_CHARGE_PUMP, - 0x10 if self.external_vcc else 0x14, - SET_DISP | 0x01, - ): # on - self.write_cmd(cmd) - self.fill(0) - self.show() - - def poweroff(self): - self.write_cmd(SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(SET_DISP | 0x01) - - def contrast(self, contrast): - self.write_cmd(SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(SET_NORM_INV | (invert & 1)) - - def show(self): - x0 = 0 - x1 = self.width - 1 - if self.width == 64: - # displays with width of 64 pixels are shifted by 32 - x0 += 32 - x1 += 32 - self.write_cmd(SET_COL_ADDR) - self.write_cmd(x0) - self.write_cmd(x1) - self.write_cmd(SET_PAGE_ADDR) - self.write_cmd(0) - self.write_cmd(self.pages - 1) - self.write_data(self.buffer) - - -class SSD1306_I2C(SSD1306): - def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.temp = bytearray(2) - self.write_list = [b"\x40", None] # Co=0, D/C#=1 - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.write_list[1] = buf - self.i2c.writevto(self.addr, self.write_list) - - -class SSD1306_SPI(SSD1306): - def __init__(self, width, height, spi, dc, res, cs, external_vcc=False): - self.rate = 10 * 1024 * 1024 - dc.init(dc.OUT, value=0) - res.init(res.OUT, value=0) - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - import time - - self.res(1) - time.sleep_ms(1) - self.res(0) - time.sleep_ms(10) - self.res(1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) diff --git a/src/oled/game-of-life.py b/src/oled/game-of-life.py deleted file mode 100644 index 14550c265..000000000 --- a/src/oled/game-of-life.py +++ /dev/null @@ -1,142 +0,0 @@ -# Python code to implement Conway's Game Of Life -import argparse -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.animation as animation - -# setting up the values for the grid -ON = 255 -OFF = 0 -vals = [ON, OFF] - -def randomGrid(N): - - """returns a grid of NxN random values""" - return np.random.choice(vals, N*N, p=[0.2, 0.8]).reshape(N, N) - -def addGlider(i, j, grid): - - """adds a glider with top left cell at (i, j)""" - glider = np.array([[0, 0, 255], - [255, 0, 255], - [0, 255, 255]]) - grid[i:i+3, j:j+3] = glider - -def addGosperGliderGun(i, j, grid): - - """adds a Gosper Glider Gun with top left - cell at (i, j)""" - gun = np.zeros(11*38).reshape(11, 38) - - gun[5][1] = gun[5][2] = 255 - gun[6][1] = gun[6][2] = 255 - - gun[3][13] = gun[3][14] = 255 - gun[4][12] = gun[4][16] = 255 - gun[5][11] = gun[5][17] = 255 - gun[6][11] = gun[6][15] = gun[6][17] = gun[6][18] = 255 - gun[7][11] = gun[7][17] = 255 - gun[8][12] = gun[8][16] = 255 - gun[9][13] = gun[9][14] = 255 - - gun[1][25] = 255 - gun[2][23] = gun[2][25] = 255 - gun[3][21] = gun[3][22] = 255 - gun[4][21] = gun[4][22] = 255 - gun[5][21] = gun[5][22] = 255 - gun[6][23] = gun[6][25] = 255 - gun[7][25] = 255 - - gun[3][35] = gun[3][36] = 255 - gun[4][35] = gun[4][36] = 255 - - grid[i:i+11, j:j+38] = gun - -def update(frameNum, img, grid, N): - - # copy grid since we require 8 neighbors - # for calculation and we go line by line - newGrid = grid.copy() - for i in range(N): - for j in range(N): - - # compute 8-neighbor sum - # using toroidal boundary conditions - x and y wrap around - # so that the simulation takes place on a toroidal surface. - total = int((grid[i, (j-1)%N] + grid[i, (j+1)%N] + - grid[(i-1)%N, j] + grid[(i+1)%N, j] + - grid[(i-1)%N, (j-1)%N] + grid[(i-1)%N, (j+1)%N] + - grid[(i+1)%N, (j-1)%N] + grid[(i+1)%N, (j+1)%N])/255) - - # apply Conway's rules - if grid[i, j] == ON: - if (total < 2) or (total > 3): - newGrid[i, j] = OFF - else: - if total == 3: - newGrid[i, j] = ON - - # update data - img.set_data(newGrid) - grid[:] = newGrid[:] - return img, - -# main() function -def main(): - - # Command line args are in sys.argv[1], sys.argv[2] .. - # sys.argv[0] is the script name itself and can be ignored - # parse arguments - parser = argparse.ArgumentParser(description="Runs Conway's Game of Life simulation.") - - # add arguments - parser.add_argument('--grid-size', dest='N', required=False) - parser.add_argument('--mov-file', dest='movfile', required=False) - parser.add_argument('--interval', dest='interval', required=False) - parser.add_argument('--glider', action='store_true', required=False) - parser.add_argument('--gosper', action='store_true', required=False) - args = parser.parse_args() - - # set grid size - N = 64 - if args.N and int(args.N) > 8: - N = int(args.N) - - # set animation update interval - updateInterval = 50 - if args.interval: - updateInterval = int(args.interval) - - # declare grid - grid = np.array([]) - - # check if "glider" demo flag is specified - if args.glider: - grid = np.zeros(N*N).reshape(N, N) - addGlider(1, 1, grid) - elif args.gosper: - grid = np.zeros(N*N).reshape(N, N) - addGosperGliderGun(10, 10, grid) - - else: # populate grid with random on/off - - # more off than on - grid = randomGrid(N) - - # set up animation - fig, ax = plt.subplots() - img = ax.imshow(grid, interpolation='nearest') - ani = animation.FuncAnimation(fig, update, fargs=(img, grid, N, ), - frames = 10, - interval=updateInterval, - save_count=50) - - # # of frames? - # set output file - if args.movfile: - ani.save(args.movfile, fps=30, extra_args=['-vcodec', 'libx264']) - - plt.show() - -# call main -if __name__ == '__main__': - main() diff --git a/src/oled/i2c/00-i2c-scanner.py b/src/oled/i2c/00-i2c-scanner.py deleted file mode 100644 index e80874882..000000000 --- a/src/oled/i2c/00-i2c-scanner.py +++ /dev/null @@ -1,6 +0,0 @@ - -import machine -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -print(i2c.scan()) \ No newline at end of file diff --git a/src/oled/i2c/01-hello-world.py b/src/oled/i2c/01-hello-world.py deleted file mode 100644 index 408867ee8..000000000 --- a/src/oled/i2c/01-hello-world.py +++ /dev/null @@ -1,11 +0,0 @@ -import machine -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -print('Done') \ No newline at end of file diff --git a/src/oled/i2c/01-sh1106-hello-world.py b/src/oled/i2c/01-sh1106-hello-world.py deleted file mode 100644 index 0b698f12e..000000000 --- a/src/oled/i2c/01-sh1106-hello-world.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin, I2C -import sh1106 - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c = I2C(0, scl=scl, sda=sda, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(4), 0x3c) -display.sleep(False) - -display.fill(0) -display.text('CoderDojo', 0, 0, 1) -display.show() - -print('done') \ No newline at end of file diff --git a/src/oled/i2c/01-ssd1306-hello-world.py b/src/oled/i2c/01-ssd1306-hello-world.py deleted file mode 100644 index 408867ee8..000000000 --- a/src/oled/i2c/01-ssd1306-hello-world.py +++ /dev/null @@ -1,11 +0,0 @@ -import machine -from ssd1306 import SSD1306_I2C - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(128, 64, i2c) -oled.fill(0) -oled.text("Hello World!", 0, 0) -oled.show() -print('Done') \ No newline at end of file diff --git a/src/oled/i2c/oled-scanner-test.py b/src/oled/i2c/oled-scanner-test.py deleted file mode 100644 index 1fab82345..000000000 --- a/src/oled/i2c/oled-scanner-test.py +++ /dev/null @@ -1,16 +0,0 @@ -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found -devices = i2c.scan() -print("Device found at decimal", devices) - -first_device = devices[0] -if first_device == 60: - print("TEST PASS") -else: - print("No OLED device found at decimal 60. Check connections.") - print("TEST FAIL") diff --git a/src/oled/invaders.py b/src/oled/invaders.py deleted file mode 100644 index c90f2b68c..000000000 --- a/src/oled/invaders.py +++ /dev/null @@ -1,257 +0,0 @@ -#Pico Invaders! -# https://github.com/printnplay/Pico-MicroPython/blob/main/picoinvaders.py -# TODO : Implement alien shots, Shields, Sound -from machine import Pin, I2C, ADC, PWM -from ssd1306 import SSD1306_I2C -from time import sleep -import framebuf -import random - -WIDTH = 128 # oled display width -HEIGHT = 64 # oled display height - -Pot = ADC(26) -conversion_factor = 3.3 / (65535) # Conversion from Pin read to proper voltage - -speaker = PWM(Pin(18)) - -i2c = I2C(0) # Init I2C using I2C0 defaults, SCL=Pin(GP9), SDA=Pin(GP8), freq=400000 - -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init oled display - -lowres = True - -if lowres == True: - #smaller alien sprites. set spritex to 5 and spritey to 5 - inv1a = bytearray(b"\xd0xPx\xf0") - inv1b = bytearray(b"\xf0xPx\xd0") - inv2a = bytearray(b"\xe0P\xf8P\xe0") - inv2b = bytearray(b"`\xd0x\xd0`") - spritex = 5 #how big are your alien sprites? - spritey = 5 - aliencountx = 4 #How many rows and columns of aliens - aliencounty = 5 - alienspacingx = 5 - alienspacingy = 3 -else: - #sprite definitions for Aliens. set spritex and spritey to 7 - inv1a = bytearray(b"~\xd8\x88\xf8\x88\xd8~") - inv1b = bytearray(b"|\xda\xc8\xf8\xc8\xda|") - inv2a = bytearray(b"\x88\\:\x1e:\\\x88") - inv2b = bytearray(b"\x08\\\xba\x1e\xba\\\x08") - spritex = 7 #how big are your alien sprites? - spritey = 7 - aliencountx = 4 #How many rows and columns of aliens - aliencounty = 4 - alienspacingx = 3 - alienspacingy = 3 -logo = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\x00\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\x00\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\x00\xff\xfc\x00\x00\x00\x01\xff\x80\x00\x07\xbd\xe0\x00\x00\x00\x00\x03\xe0\x00\x00\x00\x01\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x01\x08\x80\x00\x00\x01\xef\x00\x00\x00\x00\xff\xfc\x00\x00\x00\x01\x08\x80\x00\x00\x01\xef\x00\x00\x00\x00\xff\xfc\x07\xff\xe0\x01\x08\x80\x00\x00\x01\xef\x00\x00\x00\x00\xff\xfc\x07\xff\xe0\x01\x08\x80\x00\x00\x01\xef\x00\x00\x00\x00\x00\x00\x07\xff\xe0\x01\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x008\xe0\x00\xf7\x00\x00\x07\xbd\xefx\x1e\x00\x02\xff\x00\x00\x18\xe0\x00\x00\x00\x00\x07\xbd\xefx\x1e\x00?\xff\x00\x00?\xe0\x00\x0c\x00\x00\x07\xbd\xefx\x1e\x00?\xd0\x00\x00\x1f\xc0\x08<\x00\x00\x07\xbd\xefx\x1e\x00<\x00\x00\x00\x0f\x80\x0c\xf0\x00\x00\x00\x00\x00\x00\x00\x00?\xff\x00\x00\x00\x00\x07\xc0\x00\x00\xf0=\xe0{\xc0\x00?\xff\x00\x00\x00\x00\x03\xc0\x00\x00\xf0=\xe0{\xc0\x00\x00\xbf\x00\x00\x00\x00\x00\xf0\x00\x00\xf0=\xe0{\xc0\x00\x00\x00\x00\x00\x00\x00\x00<\x00\x00\xf0=\xe0{\xc0\x00\x00`\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xc0\x07\xff\xe0\x00\x00\x00\x00\xf0=\xefx\x00\x00\x00\x7f\xfe\x07\xff\xe0\x00\x00\x00\x00\xf0=\xefx\x00\x00\x00\x1e\xfe\x07\xff\xe0\x00\x00\x00\x00\xf0=\xefx\x00\x00\x00\x18\x1e\x00\x00\x00\x00\x00\x00\x00\xf0=\xefx\x00\x00\x00?\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xfe\x00\x00\x00\x01\xff\x80\x00\x00=\xefx\x00\x00\x00\x7f\x80\x00\x00\x00\x01\xff\x80\x00\x00=\xefx\x00\x00\x00@\x00\x00\x00\x00\x00\x10\x80\x00\x00=\xefx\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x80\x00\x00=\xefx\x00\x00?\xff\x00\x01\xff\x80\x00\x10\x80\x00\x00\x00\x00\x00\x00\x00?\xff\x00\x03\xff\xc0\x00\x10\x80\x00\xf0=\xefx\x00\x00?\xff\x00\x07\xff\xe0\x00\x1f\x80\x00\xf0=\xefx\x00\x008\x07\x00\x07\x00\xe0\x00\x0f\x00\x00\xf0=\xefx\x00\x000'\x00\x06\x00\xe0\x00\x00\x00\x00\xf0=\xefx\x00\x00?\xff\x00\x07\xe7\xe0\x01\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xfe\x00\x03\xe3\xc0\x01\xfc\x00\x00\xf0=\xe0{\xc0\x00\x0f\xfc\x00\x01\xe3\x80\x00\x04\x00\x00\xf0=\xe0{\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\xf0=\xe0{\xc0\x00\x00\x7f\xfe\x00\x00\x00\x01\xfc\x00\x00\xf0=\xe0{\xc0\x00\x00\x7f\xfe\x00\x00\x00\x01\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xfe\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xefx\x1e\x00\x00q\xce\x01\xff\x80\x00\x00\x00\x00\x07\xbd\xefx\x1e\x00\x00`\xc6\x03\xff\xc0\x01\xff\x80\x00\x07\xbd\xefx\x1e\x00\x00p\x8e\x07\xff\xe0\x01\xff\x80\x00\x07\xbd\xefx\x1e\x00\x00\x00\x00\x07\x00\xe0\x00\x10\x80\x00\x00\x00\x00\x00\x00\x00\xff\xfc\x00\x06\x04\xe0\x00\x10\x80\x00\x00\x01\xef\x00\x00\x00\xff\xfc\x00\x07\xff\xe0\x00\x10\x80\x00\x00\x01\xef\x00\x00\x00\xff\xfc\x00\x03\xff\xc0\x00\x10\x80\x00\x00\x01\xef\x00\x00\x00\x03\x9c\x00\x01\xff\x80\x00\x1f\x80\x00\x00\x01\xef\x00\x00\x00\t\x9c\x00\x00\x00\x00\x00\x0f\x00\x00\x00\x00\x00\x00\x00\x00\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\xfe\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\xfep\x00\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\xbd\xe0\x00\x00\x00\x00\x1cx\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00q\xce\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xde\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\x9c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x18\x00\x00\x00") - -ship = bytearray(b" p\xf8l>//>l\xf8p ") -ufo = bytearray(b"\x0c\x00>\x80\x1d\x80\r\xe0\x1d\xc0\x15\x80>\x80\x0c\x00") - -num0 = bytearray(b"\x7f\x80\xff\xc0\x80@\x80@\xff\xc0\x7f\x80") -num1 = bytearray(b"\x00\x00\x00\x80\x00\x80\xff\xc0\xff\xc0\x00\x00") -num2 = bytearray(b"\xe1\x80\xf1\xc0\x98@\x8c@\x87\xc0\x83\x80") -num3 = bytearray(b"@\x80\xc0\xc0\x84@\x84@\xff\xc0{\x80") -num4 = bytearray(b"0\x00<\x00/\x00#\x80\xff\xc0\xff\xc0") -num5 = bytearray(b"O\xc0\xcf\xc0\x84@\x84@\xfc@x@") -num6 = bytearray(b"\x7f\x80\xff\xc0\x84@\x84@\xfc\xc0x\x80") -num7 = bytearray(b"\x00@\xe0@\xfc@\x1f@\x03\xc0\x00\xc0") -num8 = bytearray(b"{\x80\xff\xc0\x84@\x84@\xff\xc0{\x80") -num9 = bytearray(b"G\x80\xcf\xc0\x88@\x88@\xff\xc0\x7f\x80") - -aliens = [] -class Alien(object): - - def __init__(self, type, x, y): - self.visible = True - self.type = type - self.x = x - self.y = y - self.origx = x - self.origy = y - -def create_alien(type, x, y): - alien = Alien(type, x, y) - return alien - -def define_aliens(): - type = "inv1a" #First row is type 1. - for x in range (1, aliencountx + 1): - for y in range (1, aliencounty + 1): - aliens.append(create_alien(type, (120 - ((x * (spritex + alienspacingx)) - spritex)), (y * (spritey + alienspacingy)) - spritey)) - if type == "inv1a": - type = "inv2a" #Second row is type 2 - else: - type = "inv1a" - -def reset_aliens(visibility): # Used to reset aliens to starting position and, optionally, visibility - x = 1 - y = 1 - for c in aliens: - if visibility: - c.visible = True - - c.x = c.origx - c.y = c.origy - -# Load images into framebuffer -inv1aBuff = framebuf.FrameBuffer(inv1a, 7, 7, framebuf.MONO_HLSB) -inv1bBuff = framebuf.FrameBuffer(inv1b, 7, 7, framebuf.MONO_HLSB) -inv2aBuff = framebuf.FrameBuffer(inv2a, 7, 7, framebuf.MONO_HLSB) -inv2bBuff = framebuf.FrameBuffer(inv2b, 7, 7, framebuf.MONO_HLSB) - -ufoBuff = framebuf.FrameBuffer(ufo, 12, 8, framebuf.MONO_HLSB) - -logoBuff = framebuf.FrameBuffer(logo, 128, 64, framebuf.MONO_HLSB) - -#Dictionary for lookup of digits for score, level, possibly lives -numbers = { - '0': framebuf.FrameBuffer(num0, 10, 6, framebuf.MONO_HLSB), - '1': framebuf.FrameBuffer(num1, 10, 6, framebuf.MONO_HLSB), - '2': framebuf.FrameBuffer(num2, 10, 6, framebuf.MONO_HLSB), - '3': framebuf.FrameBuffer(num3, 10, 6, framebuf.MONO_HLSB), - '4': framebuf.FrameBuffer(num4, 10, 6, framebuf.MONO_HLSB), - '5': framebuf.FrameBuffer(num5, 10, 6, framebuf.MONO_HLSB), - '6': framebuf.FrameBuffer(num6, 10, 6, framebuf.MONO_HLSB), - '7': framebuf.FrameBuffer(num7, 10, 6, framebuf.MONO_HLSB), - '8': framebuf.FrameBuffer(num8, 10, 6, framebuf.MONO_HLSB), - '9': framebuf.FrameBuffer(num9, 10, 6, framebuf.MONO_HLSB)} - -shipBuff = framebuf.FrameBuffer(ship, 8, 12, framebuf.MONO_HLSB) -# Clear the oled display in case it has junk on it. -oled.fill(0) -oled.blit(logoBuff, 0, 0) -# Finally update the oled display so the image & text is displayed -oled.show() - -sleep(2) - -addy = 3 #pixels of movement per turn on aliens - -shotx = 1 -shoty = 1 -loopCount = 0 -define_aliens() -score = 0 -difficulty = 1 -showufo = False -ufoy = 0 -ufoCount = 0 -soundfreq = 160 -while True: - if showufo: - if soundfreq == 1100: soundfreq = 2000 - else: soundfreq = 1100 - speaker.freq(soundfreq) - speaker.duty_u16(2000) - if shotx > 36 and showufo == False: speaker.duty_u16(0) - ufoChance = random.randrange(1, 350, 1) # 1 in 1000 chance of running this loop that UFO will appear - if ufoChance == 123 and showufo == False: - showufo = True - ufoy = 0 - if showufo: - ufoy = ufoy + 1 - if ufoy > 64: - showufo = False - loopCount = loopCount + 1 - oled.fill(0) - if loopCount > 16 - difficulty: - if showufo == False: - if soundfreq == 180: soundfreq = 160 - elif soundfreq == 160: soundfreq = 140 - elif soundfreq == 140: soundfreq = 120 - else: soundfreq = 180 - speaker.freq(soundfreq) - speaker.duty_u16(2000) - - dropdown = False - loopCount = 0 - for c in aliens: - if c.visible == True: #switch between sprites to animate aliens - if c.type == "inv1a": c.type = "inv1b" - elif c.type == "inv1b": c.type = "inv1a" - elif c.type == "inv2a": c.type = "inv2b" - elif c.type =="inv2b": c.type = "inv2a" - if c.y + addy > 56 or c.y + addy < 0: #are any of the visible invaders at the edge of the screen? - if c.x - 3 < 20: #If they're at the bottom, reset their position - reset_aliens(False) - dropdown = False - dropdown = True - if dropdown == True: #move the aliens down if any of the visible ones hit the screen edge - addy = addy * -1 - for c in aliens: - c.x = c.x - 3 - else: - for c in aliens: - c.y = c.y + addy - - shippos = (Pot.read_u16() * conversion_factor) #Read potentiometer to get ship position - shippos = (64 - ((52 / 3.3) * shippos) - 12) - shotx = shotx + 2 - foundVisible = False #By default, assume all the aliens are dead - if showufo: - if shotx > 120: - if shoty >= ufoy: - if shoty < ufoy + 12: - score = score + 50 - showufo = False - ufoy = 0 - shotx = 20 - shoty = int(shippos) + 6 - - for c in aliens: - if shotx >= c.x and c.visible == True: #Collision detection for aliens with the shots - if shotx - 4 <= c.x + 8: - if shoty > c.y: - if shoty <= c.y + 7: #You hit an alien! - c.visible = False - score = score + 10 - shotx = 32 - shoty = int(shippos) + 6 - if c.visible == True: - foundVisible = True - if c.type == "inv1a": #Display aliens - oled.blit(inv1aBuff, c.x, c.y) #display animation frame 1, set to frame 2 for next time - elif c.type == "inv1b": - oled.blit(inv1bBuff, c.x, c.y) #display animation frame 2, set to frame 1 for next time - elif c.type == "inv2a": - oled.blit(inv2aBuff, c.x, c.y) #display animation frame 1, set to frame 2 for next time - elif c.type == "inv2b": - oled.blit(inv2bBuff, c.x, c.y) #display animation frame 2, set to frame 1 for next time - if showufo: - oled.blit(ufoBuff, 120, ufoy) - if shotx > 130: - - shotx = 32 - shoty = int(shippos) + 6 - - if foundVisible == False: # You finish the level! Increase the difficulty and reset the aliens - if difficulty < 10: - difficulty = difficulty + 1 - reset_aliens(True) - - oled.blit(shipBuff, 18, int(shippos)) # draw the ship - oled.line(shotx, shoty, shotx - 4, shoty, 1) #draw the laser - - numcount = 0 #keeps track of the number of times through the loop! - - for c in str(score): - oled.blit(numbers[c], 1, ((numcount * 7) + 2)) #Display the score, 1 digit at a time - numcount = numcount + 1 - - numcount = 0 - - for c in str(difficulty): - oled.blit(numbers[c], 1, 48 + ((numcount * 7) + 2)) #Display the level, 1 digit at a time - numcount = numcount + 1 - - oled.show() - if shotx == 32 and showufo == False: - speaker.duty_u16(0) - speaker.freq(1000) - speaker.duty_u16(2000) - - sleep(0.001) - diff --git a/src/oled/oled-spi-working.py b/src/oled/oled-spi-working.py deleted file mode 100644 index ee6750e20..000000000 --- a/src/oled/oled-spi-working.py +++ /dev/null @@ -1,150 +0,0 @@ -# SCK -> GP6 -# MOSI -> GP7 -# CS -> GP5 -# D/C -> GP9 -# RES -> GP8 - -from machine import Pin, SPI -from micropython import const -import utime as time -import framebuf - - -# a few register definitions -_SET_CONTRAST = const(0x81) -_SET_NORM_INV = const(0xa6) -_SET_DISP = const(0xae) -_SET_SCAN_DIR = const(0xc0) -_SET_SEG_REMAP = const(0xa0) -_LOW_COLUMN_ADDRESS = const(0x00) -_HIGH_COLUMN_ADDRESS = const(0x10) -_SET_PAGE_ADDRESS = const(0xB0) - - -class SH1106: - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, - framebuf.MVLSB) - self.framebuf = fb -# set shortcuts for the methods of framebuf - self.fill = fb.fill - self.fill_rect = fb.fill_rect - self.hline = fb.hline - self.vline = fb.vline - self.line = fb.line - self.rect = fb.rect - self.pixel = fb.pixel - self.scroll = fb.scroll - self.text = fb.text - self.blit = fb.blit - - self.init_display() - - def init_display(self): - self.reset() - self.fill(0) - self.poweron() - self.show() - - def poweroff(self): - self.write_cmd(_SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(_SET_DISP | 0x01) - - def rotate(self, flag, update=True): - if flag: - self.write_cmd(_SET_SEG_REMAP | 0x01) # mirror display vertically - self.write_cmd(_SET_SCAN_DIR | 0x08) # mirror display hor. - else: - self.write_cmd(_SET_SEG_REMAP | 0x00) - self.write_cmd(_SET_SCAN_DIR | 0x00) - if update: - self.show() - - def sleep(self, value): - self.write_cmd(_SET_DISP | (not value)) - - def contrast(self, contrast): - self.write_cmd(_SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(_SET_NORM_INV | (invert & 1)) - - def show(self): - for page in range(self.height // 8): - self.write_cmd(_SET_PAGE_ADDRESS | page) - self.write_cmd(_LOW_COLUMN_ADDRESS | 2) - self.write_cmd(_HIGH_COLUMN_ADDRESS | 0) - self.write_data(self.buffer[ - self.width * page:self.width * page + self.width - ]) - - def reset(self, res): - if res is not None: - res(1) - time.sleep_ms(1) - res(0) - time.sleep_ms(20) - res(1) - time.sleep_ms(20) - - - -class SH1106_SPI(SH1106): - def __init__(self, width, height, spi, dc, res=None, cs=None, - external_vcc=False): - - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - self.spi.init() - dc.init(dc.OUT, value=0) - if res is not None: - res.init(res.OUT, value=0) - if cs is not None: - cs.init(cs.OUT, value=0) - - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - #self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - #self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - else: - self.dc(0) - self.spi.write(bytearray([cmd])) - - def write_data(self, buf): - #self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - #self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) - else: - self.dc(1) - self.spi.write(buf) - - def reset(self): - super().reset(self.res) - -spi = SPI(0, baudrate=1000*1000, mosi=Pin(7)) -display = SH1106_SPI(96, 64, spi, Pin(9), Pin(8), Pin(5)) -display.sleep(False) -display.fill(0) -display.text('Testing 1', 20, 20, 1) -#display.poweroff() -print(spi) diff --git a/src/oled/oled-ssd1306-spi-scroll.py b/src/oled/oled-ssd1306-spi-scroll.py deleted file mode 100644 index 5f098bfe6..000000000 --- a/src/oled/oled-ssd1306-spi-scroll.py +++ /dev/null @@ -1,29 +0,0 @@ -import machine -import ssd1306 -from time import sleep - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -CS = machine.Pin(0) -DC = machine.Pin(1) -RES = machine.Pin(4) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -counter = 0 -print('dispaying text...') -while True: - for i in range(HEIGHT - 10): - oled.text(str(counter), 0, i, 1) - for j in range(WIDTH): - oled.scroll(1,0) - oled.show() - print(counter, '.', sep="", end="") - counter += 1; - - - - - \ No newline at end of file diff --git a/src/oled/oled-test.py b/src/oled/oled-test.py deleted file mode 100644 index e07d86f0a..000000000 --- a/src/oled/oled-test.py +++ /dev/null @@ -1,35 +0,0 @@ -# Display Image I2C driven ssd1306 OLED display -from machine import Pin, I2C -# https://github.com/stlehmann/micropython-ssd1306 -from ssd1306 import SSD1306_I2C -import uos - -print(uos.uname()) -print("Frequency: ", str(machine.freq()), " Hz.") - -WIDTH = 128 # oled display width -HEIGHT = 64 # oled display height - -sda=machine.Pin(0) # bus 0 data -scl=machine.Pin(1) # bus 0 clock - -# should be 400000, 1000 prints some text -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print("I2C Address Decimal:", i2c.scan()) -print("I2C Address Hex: ", hex(i2c.scan()[0]).upper()) # Display device address -print("I2C Configuration: ", str(i2c)) # Display I2C config - -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init oled display -# oled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c) # Init oled display -oled.fill(0) -#oled.fill(1) -#oled.fill(0) -#oled.show() -oled.text("Hello", 0, 0) -oled.text("Hello", 40, 20) -oled.text("Hello", 60, 30) -oled.text("Hello", 80, 40) -oled.text("Hello", 100, 50) -oled.show() - -print("Done ") diff --git a/src/oled/patterns/01-draw-patterns-ssd1306-spi.py b/src/oled/patterns/01-draw-patterns-ssd1306-spi.py deleted file mode 100644 index 94b7f8277..000000000 --- a/src/oled/patterns/01-draw-patterns-ssd1306-spi.py +++ /dev/null @@ -1,36 +0,0 @@ -import machine -import ssd1306 -import time - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -my_function = '((x-128) * 64) % (y-128)' - -start = time.ticks_ms() - -oled.fill(0) # clear display -for x in range(WIDTH): - for y in range(1, HEIGHT): - if eval(my_function): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) - - -end = time.ticks_ms() -duration = str(end - start) -oled.text(my_function, 0, 44, 1) -oled.text('ms:', 0, 54, 1) -oled.text(duration, 30, 54, 1) -oled.show() - -print('done') - \ No newline at end of file diff --git a/src/oled/patterns/02-draw-pattern.py b/src/oled/patterns/02-draw-pattern.py deleted file mode 100644 index bff9fe5c0..000000000 --- a/src/oled/patterns/02-draw-pattern.py +++ /dev/null @@ -1,36 +0,0 @@ -import machine -import ssd1306 -import time - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -my_function = '((x * 64) % (y-128)' - -start = time.ticks_ms() - -oled.fill(0) # clear display -for x in range(WIDTH): - for y in range(1, HEIGHT): - if eval(my_function): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) - -end = time.ticks_ms() -duration = str(end - start) -oled.text(my_function, 0, 44, 1) -oled.text('ms:', 0, 54, 1) -oled.text(duration, 30, 54, 1) -oled.show() - -print(duration, ' milliseconds') -print('done') - \ No newline at end of file diff --git a/src/oled/patterns/02-draw-patterns-functions.py b/src/oled/patterns/02-draw-patterns-functions.py deleted file mode 100644 index 80a9e32f6..000000000 --- a/src/oled/patterns/02-draw-patterns-functions.py +++ /dev/null @@ -1,26 +0,0 @@ -import machine -import ssd1306 -from time import sleep - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def eval_screen(function, x, y): - if eval(function): - oled.pixel(x, y, 0) - else: - oled.pixel(x, y, 1) - -oled.fill(0) - -for x in range(WIDTH): - for y in range(HEIGHT): - eval_screen('pow(x, y) % 2', x, y) -oled.show() \ No newline at end of file diff --git a/src/oled/patterns/02-draw-patterns-ssd1306-spi-eval.py b/src/oled/patterns/02-draw-patterns-ssd1306-spi-eval.py deleted file mode 100644 index 535ccfbd8..000000000 --- a/src/oled/patterns/02-draw-patterns-ssd1306-spi-eval.py +++ /dev/null @@ -1,36 +0,0 @@ -import machine -import ssd1306 -import time - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -my_function = '((x-128) * 64) % (y-128)' - -start = time.ticks_ms() - -oled.fill(0) # clear display -for x in range(WIDTH): - for y in range(1, HEIGHT): - if eval(my_function): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) - -end = time.ticks_ms() -duration = str(end - start) -oled.text(my_function, 0, 44, 1) -oled.text('ms:', 0, 54, 1) -oled.text(duration, 30, 54, 1) -oled.show() - -print(duration, ' milliseconds') -print('done') - \ No newline at end of file diff --git a/src/oled/patterns/03-draw-patterns-functions.py b/src/oled/patterns/03-draw-patterns-functions.py deleted file mode 100644 index e96801d42..000000000 --- a/src/oled/patterns/03-draw-patterns-functions.py +++ /dev/null @@ -1,30 +0,0 @@ -import machine -import ssd1306 -from time import sleep - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -equations = ['(x ** y) & 64'] -save = ['(x * y) & 24', '(x * y) & 47'] - -# '((x * y) ** 4) % 7' grid -def eval_screen(function): - if eval(function): - oled.pixel(x, y, 0) - else: - oled.pixel(x, y, 1) - -oled.fill(0) -for x in range(WIDTH): - for y in range(HEIGHT): - eval_screen('(y + x) & 10') -oled.show() -print('done') \ No newline at end of file diff --git a/src/oled/patterns/04-draw-pattern-list.py b/src/oled/patterns/04-draw-pattern-list.py deleted file mode 100644 index cf923b63c..000000000 --- a/src/oled/patterns/04-draw-pattern-list.py +++ /dev/null @@ -1,42 +0,0 @@ -import machine -import ssd1306 -from utime import sleep, time - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -equations = ['(x * y) & 24', '(x * y) & 47', '(x * y) & 64', 'x & y', 'x % y', '(x % y) % 4', '40 % (x % y+1)'] - -while True: - for eqn in range(0, len(equations)): - start = time() - - oled.fill(0) # clear display - oled.text('calculating', 0, 0, 1) - oled.text(equations[eqn], 0, 10, 1) - oled.show() - for x in range(WIDTH): - for y in range(1, HEIGHT): - if eval(equations[eqn]): - oled.pixel(x,y,0) - else: - oled.pixel(x,y,1) - oled.show() - sleep(5) - - end = time() - duration = str(end - start) - print(equations[eqn]) - print(duration, ' seconds') - -oled.text('done', 0, 0, 1) -oled.show() -print('done') - \ No newline at end of file diff --git a/src/oled/patterns/05-patterns-repeating.py b/src/oled/patterns/05-patterns-repeating.py deleted file mode 100644 index 560c21be3..000000000 --- a/src/oled/patterns/05-patterns-repeating.py +++ /dev/null @@ -1,3 +0,0 @@ -import machine - -for i i \ No newline at end of file diff --git a/src/oled/random-hearts.py b/src/oled/random-hearts.py deleted file mode 100644 index ab75a927e..000000000 --- a/src/oled/random-hearts.py +++ /dev/null @@ -1,46 +0,0 @@ -from machine import Pin, PWM, SPI -import urandom -import ssd1306 -from utime import sleep -import random # random direction for new ball - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -HEART = [ - [ 0, 0, 0, 0, 0, 0, 0, 0, 0], - [ 0, 1, 1, 0, 0, 0, 1, 1, 0], - [ 1, 1, 1, 1, 0, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 1, 1, 1, 1, 1, 1, 1, 1, 1], - [ 0, 1, 1, 1, 1, 1, 1, 1, 0], - [ 0, 0, 1, 1, 1, 1, 1, 0, 0], - [ 0, 0, 0, 1, 1, 1, 0, 0, 0], - [ 0, 0, 0, 0, 1, 0, 0, 0, 0], -] - -def draw_heart(xofs, yofs): - for y, row in enumerate(HEART): - for x, c in enumerate(row): - oled.pixel(x + xofs, y + yofs, c) - -def random_heart(): - xofs = urandom.getrandbits(7) - yofs = urandom.getrandbits(6) - print(xofs, yofs) - draw_heart(xofs, yofs) - - -oled.fill(0) -for n in range(10): - random_heart() - -oled.show() \ No newline at end of file diff --git a/src/oled/sh1106.py b/src/oled/sh1106.py deleted file mode 100644 index 3158eb116..000000000 --- a/src/oled/sh1106.py +++ /dev/null @@ -1,227 +0,0 @@ -# -# MicroPython SH1106 OLED driver, I2C and SPI interfaces -# -# The MIT License (MIT) -# -# Copyright (c) 2016 Radomir Dopieralski (@deshipu), -# 2017 Robert Hammelrath (@robert-hh) -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Sample code sections -# ------------ SPI ------------------ -# Pin Map SPI -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D7 - GPIO 13 - Din / MOSI fixed -# - D5 - GPIO 14 - Clk / Sck fixed -# - D8 - GPIO 4 - CS (optional, if the only connected device) -# - D2 - GPIO 5 - D/C -# - D1 - GPIO 2 - Res -# -# for CS, D/C and Res other ports may be chosen. -# -# from machine import Pin, SPI -# import sh1106 - -# spi = SPI(1, baudrate=1000000) -# display = sh1106.SH1106_SPI(128, 64, spi, Pin(5), Pin(2), Pin(4)) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() -# -# --------------- I2C ------------------ -# -# Pin Map I2C -# - 3v - xxxxxx - Vcc -# - G - xxxxxx - Gnd -# - D2 - GPIO 5 - SCK / SCL -# - D1 - GPIO 4 - DIN / SDA -# - D0 - GPIO 16 - Res -# - G - xxxxxx CS -# - G - xxxxxx D/C -# -# Pin's for I2C can be set almost arbitrary -# -# from machine import Pin, I2C -# import sh1106 -# -# i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) -# display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -# display.sleep(False) -# display.fill(0) -# display.text('Testing 1', 0, 0, 1) -# display.show() - -from micropython import const -import utime as time -import framebuf - - -# a few register definitions -_SET_CONTRAST = const(0x81) -_SET_NORM_INV = const(0xa6) -_SET_DISP = const(0xae) -_SET_SCAN_DIR = const(0xc0) -_SET_SEG_REMAP = const(0xa0) -_LOW_COLUMN_ADDRESS = const(0x00) -_HIGH_COLUMN_ADDRESS = const(0x10) -_SET_PAGE_ADDRESS = const(0xB0) - - -class SH1106: - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, - framebuf.MVLSB) - self.framebuf = fb -# set shortcuts for the methods of framebuf - self.fill = fb.fill - self.fill_rect = fb.fill_rect - self.hline = fb.hline - self.vline = fb.vline - self.line = fb.line - self.rect = fb.rect - self.pixel = fb.pixel - self.scroll = fb.scroll - self.text = fb.text - self.blit = fb.blit - - self.init_display() - - def init_display(self): - self.reset() - self.fill(0) - self.poweron() - self.show() - - def poweroff(self): - self.write_cmd(_SET_DISP | 0x00) - - def poweron(self): - self.write_cmd(_SET_DISP | 0x01) - - def rotate(self, flag, update=True): - if flag: - self.write_cmd(_SET_SEG_REMAP | 0x01) # mirror display vertically - self.write_cmd(_SET_SCAN_DIR | 0x08) # mirror display hor. - else: - self.write_cmd(_SET_SEG_REMAP | 0x00) - self.write_cmd(_SET_SCAN_DIR | 0x00) - if update: - self.show() - - def sleep(self, value): - self.write_cmd(_SET_DISP | (not value)) - - def contrast(self, contrast): - self.write_cmd(_SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(_SET_NORM_INV | (invert & 1)) - - def show(self): - for page in range(self.height // 8): - self.write_cmd(_SET_PAGE_ADDRESS | page) - self.write_cmd(_LOW_COLUMN_ADDRESS | 2) - self.write_cmd(_HIGH_COLUMN_ADDRESS | 0) - self.write_data(self.buffer[ - self.width * page:self.width * page + self.width - ]) - - def reset(self, res): - if res is not None: - res(1) - time.sleep_ms(1) - res(0) - time.sleep_ms(20) - res(1) - time.sleep_ms(20) - - -class SH1106_I2C(SH1106): - def __init__(self, width, height, i2c, res=None, addr=0x3c, - external_vcc=False): - self.i2c = i2c - self.addr = addr - self.res = res - self.temp = bytearray(2) - if res is not None: - res.init(res.OUT, value=1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.i2c.writeto(self.addr, b'\x40'+buf) - - def reset(self): - super().reset(self.res) - - -class SH1106_SPI(SH1106): - def __init__(self, width, height, spi, dc, res=None, cs=None, - external_vcc=False): - self.rate = 10 * 1000 * 1000 - dc.init(dc.OUT, value=0) - if res is not None: - res.init(res.OUT, value=0) - if cs is not None: - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - else: - self.dc(0) - self.spi.write(bytearray([cmd])) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - if self.cs is not None: - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) - else: - self.dc(1) - self.spi.write(buf) - - def reset(self): - super().reset(self.res) diff --git a/src/oled/spi/main.py b/src/oled/spi/main.py deleted file mode 100644 index abe9a6568..000000000 --- a/src/oled/spi/main.py +++ /dev/null @@ -1,33 +0,0 @@ -from machine import Pin -import ssd1306 -import utime - -WIDTH = 128 -HEIGHT = 64 - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.fill(0) -oled.text("CoderDojo Rocks!", 0, 0, 1) -oled.text("MicroPython", 0, 10, 1) -oled.text("128X64 OLED", 0, 20, 1) -oled.text("SPI SSD1306", 0, 30, 1) -oled.text("$4 + $17", 0, 40, 1) -oled.text("Dan McCreary", 0, 50, 1) -oled.show() - -led_onboard = machine.Pin(25, machine.Pin.OUT) - -while True: - led_onboard.high() - utime.sleep(0.5) - led_onboard.low() - utime.sleep(0.5) diff --git a/src/oled/spi/oled-ssd1309-spi.py b/src/oled/spi/oled-ssd1309-spi.py deleted file mode 100644 index e69685ed8..000000000 --- a/src/oled/spi/oled-ssd1309-spi.py +++ /dev/null @@ -1,28 +0,0 @@ -from machine import Pin -import ssd1306 -import utime - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.fill(0) -oled.text("CoderDojo Rocks!", 0, 0, 1) -oled.text("MicroPython", 0, 10, 1) -oled.text("128X64 OLED", 0, 20, 1) -oled.text("SPI Comm", 0, 30, 1) -oled.text("$4 + $18", 0, 40, 1) -oled.text("Dan McCreary", 0, 50, 1) -oled.show() diff --git a/src/os/uname.py b/src/os/uname.py deleted file mode 100644 index c26ea9a35..000000000 --- a/src/os/uname.py +++ /dev/null @@ -1,6 +0,0 @@ -# https://docs.micropython.org/en/latest/library/os.html -import os -uname = os.uname() -print(uname) - -# (sysname='rp2', nodename='rp2', release='1.19.1', version='v1.19.1-88-g74e33e714 on 2022-06-30 (GNU 11.2.0 MinSizeRel)', machine='Raspberry Pi Pico W with RP2040') \ No newline at end of file diff --git a/src/pong/full-game.py b/src/pong/full-game.py deleted file mode 100644 index 383a097d3..000000000 --- a/src/pong/full-game.py +++ /dev/null @@ -1,175 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -sda=machine.Pin(0) -scl=machine.Pin(1) -pot_pin = machine.ADC(26) -WIDTH = 128 -HEIGHT = 64 -i2c=machine.I2C(0,sda=sda, scl=scl) -oled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(27) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# globals variables -# static variables are constants are uppercase variable names - -HALF_WIDTH = int(WIDTH / 2) - -HALF_HEIGHT = HEIGHT -BALL_SIZE = 3 # 2X2 pixels -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 -# continiuous update of the paddle and ball -# play_startup_sound() -# start with the ball in the center -ball_x = int(WIDTH / 2) -ball_y = int(HEIGHT / 2) -# set the initial directinon to down to the right -ball_x_dir = 1 -ball_y_dir = 1 - -def play_startup_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.freq(1200) - sleep(.25) - speaker.duty_u16(0) - -def play_bounce_sound(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.25) - speaker.duty_u16(0) - -def play_score_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.duty_u16(0) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 0 - else: - x = WIDTH - 2 - y = paddle_center - HALF_PAD_HEIGHT - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - -def draw_ball(): - oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now - -# The main event loop -while True: - oled.fill(0) # clear screen - oled.vline(int(WIDTH / 2), 0, HEIGHT, 1) - # border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = pot_pin_1.read_u16() - pot_val_2 = pot_pin_2.read_u16() - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT) - draw_ball() - - #update ball position with the current directions - ball_x = ball_x + ball_x_dir - ball_y = ball_y + ball_y_dir - - # update the ball direction if we are at the top or bottom edge - if ball_y < 0: - ball_y_dir = 1 - #play_bounce_sound() - if ball_y > HEIGHT - 3: - ball_y_dir = -1 - #play_bounce_sound() - - # if it hits the paddle bounce else score - if ball_x < 1: - top_paddle = pot_val_1 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - # we have a hit - ball_x_dir = 1 - ball_x = 2 - play_bounce_sound() - print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle) - else: - # we have a score for the right player - play_score_sound() - r_score += 1 - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - print('score on left edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - if ball_x > WIDTH - 3: - ball_x = WIDTH - 4 - top_paddle = pot_val_2 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - ball_x_dir = -1 - print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle) - else: - l_score += 1 - play_score_sound() - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - play_bounce_sound() - print('score on right edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - oled.text(str(l_score), HALF_WIDTH - 20, 5, 1) - - oled.text(str(r_score), HALF_WIDTH + 5, 5, 1) - - oled.show() \ No newline at end of file diff --git a/src/pong/paddle-sound-test-ssd1306-spi.py b/src/pong/paddle-sound-test-ssd1306-spi.py deleted file mode 100644 index 379d60e31..000000000 --- a/src/pong/paddle-sound-test-ssd1306-spi.py +++ /dev/null @@ -1,176 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(26) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# globals variables -# static variables are constants are uppercase variable names -WIDTH = 128 -HALF_WIDTH = int(WIDTH / 2) -HEIGHT = 64 -HALF_HEIGHT = HEIGHT -BALL_SIZE = 3 # 2X2 pixels -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 -# continiuous update of the paddle and ball -# play_startup_sound() -# start with the ball in the center -ball_x = int(WIDTH / 2) -ball_y = int(HEIGHT / 2) -# set the initial directinon to down to the right -ball_x_dir = 1 -ball_y_dir = 1 - -def play_startup_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.freq(1200) - sleep(.25) - speaker.duty_u16(0) - -def play_bounce_sound(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.25) - speaker.duty_u16(0) - -def play_score_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.duty_u16(0) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) - - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 0 - else: - x = WIDTH - 2 - y = paddle_center - HALF_PAD_HEIGHT - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - -def draw_ball(): - oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now - -# The main event loop -while True: - oled.fill(0) # clear screen - oled.vline(int(WIDTH / 2), 0, HEIGHT, 1) - # border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = pot_pin_1.read_u16() - pot_val_2 = pot_pin_1.read_u16() - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT) - draw_ball() - - #update ball position with the current directions - ball_x = ball_x + ball_x_dir - ball_y = ball_y + ball_y_dir - - # update the ball direction if we are at the top or bottom edge - if ball_y < 0: - ball_y_dir = 1 - #play_bounce_sound() - if ball_y > HEIGHT - 3: - ball_y_dir = -1 - #play_bounce_sound() - - # if it hits the paddle bounce else score - if ball_x < 1: - top_paddle = pot_val_1 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - # we have a hit - ball_x_dir = 1 - ball_x = 2 - play_bounce_sound() - print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle) - else: - # we have a score for the right player - play_score_sound() - r_score += 1 - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - print('score on left edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - if ball_x > WIDTH - 3: - ball_x = WIDTH - 4 - top_paddle = pot_val_2 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - ball_x_dir = -1 - print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle) - else: - l_score += 1 - play_score_sound() - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - play_bounce_sound() - print('score on right edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - oled.text(str(l_score), HALF_WIDTH - 20, 5, 1) - - oled.text(str(r_score), HALF_WIDTH + 5, 5, 1) - - oled.show() \ No newline at end of file diff --git a/src/pong/paddle-test-ssd1306-i2c.py b/src/pong/paddle-test-ssd1306-i2c.py deleted file mode 100644 index 4c4e05863..000000000 --- a/src/pong/paddle-test-ssd1306-i2c.py +++ /dev/null @@ -1,114 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -import machine -import ssd1306 -import utime -import random # random direction for new ball -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(26) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# globals variables -# static variables are constants are uppercase variable names -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT -BALL_RADIUS = 5 -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -ball_pos = [0,0] -ball_vel = [0,0] -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.hline(0, 0, WIDTH - 1, 1) # top edge - oled.hline(0, HEIGHT - 1, WIDTH - 1, 1) # bottom edge - oled.vline(0, 0, HEIGHT - 1, 1) # left edge - oled.vline(WIDTH - 1, 0, HEIGHT - 1, 1) # right edge - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 1 - else: - x = WIDTH - PAD_WIDTH - 1 - y = paddle_center - HALF_PAD_HEIGHT - ## x, y, width, height - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - # utime.sleep(.1) # wait a bit - -def check_edge(): - # update paddle's vertical position, keep paddle on the screen - if paddle1_pos[1] > HALF_PAD_HEIGHT and paddle1_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HALF_PAD_HEIGHT and paddle1_vel > 0: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle1_vel < 0: - paddle1_pos[1] += paddle1_vel - - if paddle2_pos[1] > HALF_PAD_HEIGHT and paddle2_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HALF_PAD_HEIGHT and paddle2_vel > 0: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle2_vel < 0: - paddle2_pos[1] += paddle2_vel - #update ball - ball_pos[0] += int(ball_vel[0]) - ball_pos[1] += int(ball_vel[1]) - -# continiuous update of the paddle and ball -current_pot_val_1 = 0 -print('p=63') -while True: - oled.fill(0) # clear screen - border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = int(pot_pin_1.read_u16()) - pot_val_2 = int(pot_pin_2.read_u16()) - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print only on change of value - if current_pot_val_1 != pot_val_1: - print('p=', pot_val_1) - current_pot_val_1 = pot_val_1 - oled.vline(0, pot_val_1, 10, 1) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_1 + HALF_PAD_HEIGHT) - - oled.text('p1:', 5, HALF_HEIGHT + 5, 1) - oled.text(str(pot_val_1), 30, HALF_HEIGHT + 5, 1) - - oled.text('p2:', 5, HALF_HEIGHT + 15, 1) - oled.text(str(pot_val_2), 60, HALF_HEIGHT + 15, 1) - - oled.show() - -print('Done') \ No newline at end of file diff --git a/src/pong/paddle-test-ssd1306-spi.py b/src/pong/paddle-test-ssd1306-spi.py deleted file mode 100644 index df25a3a84..000000000 --- a/src/pong/paddle-test-ssd1306-spi.py +++ /dev/null @@ -1,133 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(26) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# globals variables -# static variables are constants are uppercase variable names -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT -BALL_RADIUS = 5 -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -ball_pos = [0,0] -ball_vel = [0,0] -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 - -def play_startup_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.freq(1200) - sleep(.25) - speaker.duty_u16(0) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) - - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 1 - else: - x = WIDTH - PAD_WIDTH - 1 - y = paddle_center - HALF_PAD_HEIGHT - ## x, y, width, height - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - # utime.sleep(.1) # wait a bit - -def check_edge(): - # update paddle's vertical position, keep paddle on the screen - if paddle1_pos[1] > HALF_PAD_HEIGHT and paddle1_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HALF_PAD_HEIGHT and paddle1_vel > 0: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle1_vel < 0: - paddle1_pos[1] += paddle1_vel - - if paddle2_pos[1] > HALF_PAD_HEIGHT and paddle2_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HALF_PAD_HEIGHT and paddle2_vel > 0: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle2_vel < 0: - paddle2_pos[1] += paddle2_vel - #update ball - ball_pos[0] += int(ball_vel[0]) - ball_pos[1] += int(ball_vel[1]) - - - - - -# continiuous update of the paddle and ball -play_startup_sound() -current_pot_val_1 = 0 -print('p=63') -while True: - oled.fill(0) # clear screen - border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = pot_pin_1.read_u16() - pot_val_2 = pot_pin_1.read_u16() - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print only on change of value - if current_pot_val_1 != pot_val_1: - print('p=', pot_val_1) - current_pot_val_1 = pot_val_1 - oled.vline(0, pot_val_1, 10, 1) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT) - - oled.text('p1:', 5, HALF_HEIGHT + 5, 1) - oled.text(str(pot_val_1), 30, HALF_HEIGHT + 5, 1) - - oled.text('p2:', 5, HALF_HEIGHT + 15, 1) - oled.text(str(pot_val_2), 60, HALF_HEIGHT + 15, 1) - - oled.show() - -print('Done') \ No newline at end of file diff --git a/src/pong/paddle-test.py b/src/pong/paddle-test.py deleted file mode 100644 index 2b61e4a5c..000000000 --- a/src/pong/paddle-test.py +++ /dev/null @@ -1,120 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -import machine -import utime -import random # random direction for new ball -from ssd1306 import SSD1306_I2C -# import sh1106 - -# connect the OLED SDA (data) on top pin 1 on the left with USP on top -sda=machine.Pin(0) -# connect the OLED SCL (clock) on send from the top pin 1 -scl=machine.Pin(1) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(26) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# globals variables -# static variables are constants are uppercase variable names -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT -BALL_RADIUS = 5 -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -ball_pos = [0,0] -ball_vel = [0,0] -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 - -# initialize the I2C communications interface with the OLED -i2c=machine.I2C(0,sda=sda, scl=scl) - - -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) -# oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.hline(0, 0, WIDTH - 1, 1) # top edge - oled.hline(0, HEIGHT - 1, WIDTH - 1, 1) # bottom edge - oled.vline(0, 0, HEIGHT - 1, 1) # left edge - oled.vline(WIDTH - 1, 0, HEIGHT - 1, 1) # right edge - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 1 - else: - x = WIDTH - PAD_WIDTH - 1 - y = paddle_center - HALF_PAD_HEIGHT - ## x, y, width, height - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - # utime.sleep(.1) # wait a bit - -def check_edge(): - # update paddle's vertical position, keep paddle on the screen - if paddle1_pos[1] > HALF_PAD_HEIGHT and paddle1_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HALF_PAD_HEIGHT and paddle1_vel > 0: - paddle1_pos[1] += paddle1_vel - elif paddle1_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle1_vel < 0: - paddle1_pos[1] += paddle1_vel - - if paddle2_pos[1] > HALF_PAD_HEIGHT and paddle2_pos[1] < HEIGHT - HALF_PAD_HEIGHT: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HALF_PAD_HEIGHT and paddle2_vel > 0: - paddle2_pos[1] += paddle2_vel - elif paddle2_pos[1] == HEIGHT - HALF_PAD_HEIGHT and paddle2_vel < 0: - paddle2_pos[1] += paddle2_vel - #update ball - ball_pos[0] += int(ball_vel[0]) - ball_pos[1] += int(ball_vel[1]) - -# continiuous update of the paddle and ball -current_pot_val_1 = 0 -print('p=63') -while True: - oled.fill(0) # clear screen - border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = int(pot_pin_1.read_u16()) - pot_val_2 = int(pot_pin_2.read_u16()) - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print only on change of value - if current_pot_val_1 != pot_val_1: - print('p=', pot_val_1) - current_pot_val_1 = pot_val_1 - oled.vline(0, pot_val_1, 10, 1) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_1 + HALF_PAD_HEIGHT) - - oled.text('p1:', 5, HALF_HEIGHT + 5, 1) - oled.text(str(pot_val_1), 30, HALF_HEIGHT + 5, 1) - - oled.text('p2:', 5, HALF_HEIGHT + 15, 1) - oled.text(str(pot_val_2), 60, HALF_HEIGHT + 15, 1) - - oled.show() - -print('Done') \ No newline at end of file diff --git a/src/pong/pong-ssd1306-i2c.py b/src/pong/pong-ssd1306-i2c.py deleted file mode 100644 index 383a097d3..000000000 --- a/src/pong/pong-ssd1306-i2c.py +++ /dev/null @@ -1,175 +0,0 @@ -# Pong game on Raspberry Pi Pico with a OLED and two Potentimeters -from machine import Pin, PWM, SPI -import ssd1306 -from utime import sleep -import random # random direction for new ball - -sda=machine.Pin(0) -scl=machine.Pin(1) -pot_pin = machine.ADC(26) -WIDTH = 128 -HEIGHT = 64 -i2c=machine.I2C(0,sda=sda, scl=scl) -oled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c) -# connect the center tops of the potentiometers to ADC0 and ADC1 -pot_pin_1 = machine.ADC(27) -pot_pin_2 = machine.ADC(26) # make them the same for testing - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# globals variables -# static variables are constants are uppercase variable names - -HALF_WIDTH = int(WIDTH / 2) - -HALF_HEIGHT = HEIGHT -BALL_SIZE = 3 # 2X2 pixels -PAD_WIDTH = 2 -PAD_HEIGHT = 8 -HALF_PAD_WIDTH = int(PAD_WIDTH / 2) -HALF_PAD_HEIGHT = int(PAD_HEIGHT / 2) -POT_MIN = 3000 -POT_MAX = 65534 -MAX_ADC_VALUE = 65534 # Maximum value from the Analog to Digital Converter is 2^16 - 1 -# dynamic global variables use lowercase -paddle1_vel = 0 -paddle2_vel = 0 -l_score = 0 -r_score = 0 -# continiuous update of the paddle and ball -# play_startup_sound() -# start with the ball in the center -ball_x = int(WIDTH / 2) -ball_y = int(HEIGHT / 2) -# set the initial directinon to down to the right -ball_x_dir = 1 -ball_y_dir = 1 - -def play_startup_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.freq(1200) - sleep(.25) - speaker.duty_u16(0) - -def play_bounce_sound(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.25) - speaker.duty_u16(0) - -def play_score_sound(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.25) - speaker.freq(800) - sleep(.25) - speaker.duty_u16(0) - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(WIDTH, HEIGHT): - oled.rect(0, 0, WIDTH, HEIGHT, 1) - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a vertical bar -def draw_paddle(paddle_no, paddle_center): - if paddle_no == 1: - x = 0 - else: - x = WIDTH - 2 - y = paddle_center - HALF_PAD_HEIGHT - oled.fill_rect(x, y, PAD_WIDTH, PAD_HEIGHT, 1) # fill with 1s - -def draw_ball(): - oled.fill_rect(ball_x, ball_y, BALL_SIZE, BALL_SIZE, 1) # square balls for now - -# The main event loop -while True: - oled.fill(0) # clear screen - oled.vline(int(WIDTH / 2), 0, HEIGHT, 1) - # border(WIDTH, HEIGHT) - # read both the pot values - pot_val_1 = pot_pin_1.read_u16() - pot_val_2 = pot_pin_2.read_u16() - # print(pot_val_1) - - # scale the values from the max value of the input is a 2^16 or 65536 to 0 to HEIGHT - PAD_HEIGHT - # ideally, it should range from 5 to 58 - pot_val_1 = valmap(pot_val_1, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - pot_val_2 = valmap(pot_val_2, POT_MIN, POT_MAX, HALF_PAD_HEIGHT, HEIGHT - HALF_PAD_HEIGHT - 2) - - # print(pot_val, pot_scaled) - draw_paddle(1, pot_val_1 + HALF_PAD_HEIGHT) - draw_paddle(2, pot_val_2 + HALF_PAD_HEIGHT) - draw_ball() - - #update ball position with the current directions - ball_x = ball_x + ball_x_dir - ball_y = ball_y + ball_y_dir - - # update the ball direction if we are at the top or bottom edge - if ball_y < 0: - ball_y_dir = 1 - #play_bounce_sound() - if ball_y > HEIGHT - 3: - ball_y_dir = -1 - #play_bounce_sound() - - # if it hits the paddle bounce else score - if ball_x < 1: - top_paddle = pot_val_1 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_1 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - # we have a hit - ball_x_dir = 1 - ball_x = 2 - play_bounce_sound() - print('paddle hit on left edge', pot_val_1, top_paddle, bottom_paddle) - else: - # we have a score for the right player - play_score_sound() - r_score += 1 - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - print('score on left edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - if ball_x > WIDTH - 3: - ball_x = WIDTH - 4 - top_paddle = pot_val_2 - HALF_PAD_HEIGHT - bottom_paddle = pot_val_2 + HALF_PAD_HEIGHT - if ball_y > top_paddle and ball_y < bottom_paddle: - ball_x_dir = -1 - print('bounce on right paddle', pot_val_1, top_paddle, bottom_paddle) - else: - l_score += 1 - play_score_sound() - ball_x = int(WIDTH / 2) - ball_y = int(HEIGHT / 2) - ball_x_dir = random.randint(-1, 2) - if ball_x_dir == 0: - ball_x_dir = 1 - ball_y_dir = random.randint(-1, 2) - play_bounce_sound() - print('score on right edge', pot_val_1, top_paddle, bottom_paddle) - sleep(.25) - - oled.text(str(l_score), HALF_WIDTH - 20, 5, 1) - - oled.text(str(r_score), HALF_WIDTH + 5, 5, 1) - - oled.show() \ No newline at end of file diff --git a/src/pong/silence.py b/src/pong/silence.py deleted file mode 100644 index fa55a1345..000000000 --- a/src/pong/silence.py +++ /dev/null @@ -1,6 +0,0 @@ -from machine import Pin, PWM - -SPEAKER_PIN = 16 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/pong/wave-test.py b/src/pong/wave-test.py deleted file mode 100644 index fd4af2342..000000000 --- a/src/pong/wave-test.py +++ /dev/null @@ -1,16 +0,0 @@ -import wave - -filename = '/sounds/cylon-by-your-command.wav' -# use the wave class open function -f = wave.open(filename,'rb') - -# get sample stats of the wave file -rate = f.getframerate() -bytesDepth = f.getsampwidth() -channels = f.getnchannels() -frameCount = f.getnframes() - -print('Rate: ', rate) -print('bytes depth', bytesDepth) -print('channels:', channels) -print('frameCount:', frameCount) \ No newline at end of file diff --git a/src/pot-lab/pot-min-max-percent.py b/src/pot-lab/pot-min-max-percent.py deleted file mode 100644 index d813653ba..000000000 --- a/src/pot-lab/pot-min-max-percent.py +++ /dev/null @@ -1,15 +0,0 @@ -import machine -import utime -pot = machine.ADC(26) -min = 65535 -max = 0 -pot_val = 0 -while True: - pot_val = pot.read_u16() - if pot_val < min: - min = pot_val - if pot_val > max: - max = pot_val - percent = (pot_val - min)/max * 100 - print(pot_val, min, max, round(percent,1)) - utime.sleep(.2) \ No newline at end of file diff --git a/src/pot-lab/pot-oled-ssd1306-i2c.py b/src/pot-lab/pot-oled-ssd1306-i2c.py deleted file mode 100644 index 6f4cf84ba..000000000 --- a/src/pot-lab/pot-oled-ssd1306-i2c.py +++ /dev/null @@ -1,52 +0,0 @@ -import machine -import utime -import ssd1306 -# import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -pot_pin = machine.ADC(26) - -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -half_height = int(height / 2) -oled = ssd1306.SSD1306_I2C(width, height, i2c) -# oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 1, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, bar_height, state): - oled.fill(0) # clear screen - border(width, height) # draw a border - oled.fill_rect(0, 1, inval, bar_height, 1) # fill with 1 - # utime.sleep(.1) # wait a bit - -# continiuous update -while True: - pot_val = int(pot_pin.read_u16()) - # the max value of the input is a 2^16 or 65536 - pot_scaled = valmap(pot_val, 0, 65536, 0, 127) - # print(pot_val, pot_scaled) - draw_hbar(pot_scaled, half_height, 1) - - oled.text('raw:', 0, half_height + 5, 1) - oled.text(str(pot_val), 30, half_height + 5, 1) - - oled.text('scaled:', 0, half_height + 15, 1) - oled.text(str(pot_scaled), 60, half_height + 15, 1) - oled.show() \ No newline at end of file diff --git a/src/pot-lab/pot-oled.py b/src/pot-lab/pot-oled.py deleted file mode 100644 index 886736d40..000000000 --- a/src/pot-lab/pot-oled.py +++ /dev/null @@ -1,52 +0,0 @@ -import machine -import utime -import ssd1306 -# import sh1106 - -sda=machine.Pin(0) -scl=machine.Pin(1) -pot_pin = machine.ADC(26) - -i2c=machine.I2C(0,sda=sda, scl=scl) -# Screen size -width=128 -height=64 -half_height = int(height / 2) -oled = ssd1306.SSD1306_I2C(width, height, i2c) -# oled = sh1106.SH1106_I2C(width, height, i2c, machine.Pin(4), 0x3c) - -oled.fill(0) # clear to black - -# note that OLEDs have problems with screen burn it - don't leave this on too long! -def border(width, height): - oled.hline(0, 0, width - 1, 1) # top edge - oled.hline(0, height - 2, width - 1, 1) # bottom edge - oled.vline(0, 0, height - 1, 1) # left edge - oled.vline(width - 1, 0, height - 1, 1) # right edge - -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return int(ostart + (ostop - ostart) * ((value - istart) / (istop - istart))) - -# draw a horizontal bar -def draw_hbar(inval, height, state): - oled.fill(0) # clear screen - border(width, height) # draw a border - oled.fill_rect(0, 1, inval, height, 1) # fill with 1 - utime.sleep(.1) # wait a bit - -# continiuous update -while True: - pot_val = int(pot_pin.read_u16()) - # the max value of the input is a 2^16 or 65536 - pot_scaled = valmap(pot_val, 0, 65536, 0, 127) - print(pot_val, pot_scaled) - draw_hbar(pot_scaled, half_height, 1) - - oled.text('raw:', 0, half_height + 5, 1) - oled.text(str(pot_val), 30, half_height + 5, 1) - - oled.text('scaled:', 0, half_height + 15, 1) - oled.text(str(pot_scaled), 60, half_height + 15, 1) - oled.show() \ No newline at end of file diff --git a/src/pot-lab/pot-on-adc0.py b/src/pot-lab/pot-on-adc0.py deleted file mode 100644 index d813653ba..000000000 --- a/src/pot-lab/pot-on-adc0.py +++ /dev/null @@ -1,15 +0,0 @@ -import machine -import utime -pot = machine.ADC(26) -min = 65535 -max = 0 -pot_val = 0 -while True: - pot_val = pot.read_u16() - if pot_val < min: - min = pot_val - if pot_val > max: - max = pot_val - percent = (pot_val - min)/max * 100 - print(pot_val, min, max, round(percent,1)) - utime.sleep(.2) \ No newline at end of file diff --git a/src/pot-lab/value-map.py b/src/pot-lab/value-map.py deleted file mode 100644 index fbbc88814..000000000 --- a/src/pot-lab/value-map.py +++ /dev/null @@ -1,9 +0,0 @@ -# Takes an input number vale and a range between high-and-low and returns it scaled to the new range -# This is similar to the Arduino map() function -def valmap(value, istart, istop, ostart, ostop): - return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)) - -print('Map a number from 0 to 100 to the range of 0 to 10') -print('%-8s %-6s' % ('Input', 'Output')) -for x in range(0, 100): - print('%5.2f %6.3f' % (x, valmap(x, 0, 100.0, 0, 10.0))) \ No newline at end of file diff --git a/src/projects/larson-scanner/main.py b/src/projects/larson-scanner/main.py deleted file mode 100644 index 237df39fe..000000000 --- a/src/projects/larson-scanner/main.py +++ /dev/null @@ -1,37 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 27 -STATE_MACHINE = 0 -LED_PIN = 0 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0,0,0) - -delay = .1 -while True: - for i in range(2, NUMBER_PIXELS-2): - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - if i > 0: strip.set_pixel(i-3, off) - strip.show() - sleep(delay) - for i in range(NUMBER_PIXELS-4, 1, -1): - if i < NUMBER_PIXELS-2: strip.set_pixel(i+3, off) - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - strip.show() - sleep(delay) diff --git a/src/projects/larson-scanner/neopixel-rainbow-swipe.py b/src/projects/larson-scanner/neopixel-rainbow-swipe.py deleted file mode 100644 index c474b7f0d..000000000 --- a/src/projects/larson-scanner/neopixel-rainbow-swipe.py +++ /dev/null @@ -1,39 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 12 -STATE_MACHINE = 0 -LED_PIN = 0 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -off = (0,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -color_index = 0 -while True: - for i in range(0, NUMBER_PIXELS-1): - strip.set_pixel(i, red) - strip.show() - sleep(.1) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-1, 0, -1): - strip.set_pixel(i, red) - strip.show() - sleep(.1) - strip.set_pixel(i, off) diff --git a/src/projects/larson-scanner/red-back-and-forth.py b/src/projects/larson-scanner/red-back-and-forth.py deleted file mode 100644 index 64a6ca354..000000000 --- a/src/projects/larson-scanner/red-back-and-forth.py +++ /dev/null @@ -1,51 +0,0 @@ -from utime import sleep -# We are using https://github.com/blaz-r/pi_pico_neopixel -from neopixel import Neopixel - -NUMBER_PIXELS = 27 -STATE_MACHINE = 0 -LED_PIN = 0 - -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, LED_PIN, "GRB") - -# Color RGB values -red = (255, 0, 0) -red_med = (32, 0, 0) -red_light = (8, 0, 0) -off = (0,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -violet = (138, 43, 226) # mostly pink -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet) - -# set to be 1 to 100 for percent brightness -strip.brightness(100) - -delay = .1 -color_index = 0 -while True: - for i in range(2, NUMBER_PIXELS-2): - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - if i > 0: strip.set_pixel(i-3, (0,0,0)) - strip.show() - sleep(delay) - strip.set_pixel(i, off) - for i in range(NUMBER_PIXELS-4, 1, -1): - if i < NUMBER_PIXELS-2: strip.set_pixel(i+3, (0,0,0)) - strip.set_pixel(i-2, red_light) - strip.set_pixel(i-1, red_med) - strip.set_pixel(i, red) - strip.set_pixel(i+1, red_med) - strip.set_pixel(i+2, red_light) - strip.show() - sleep(delay) diff --git a/src/projects/xmas-lights b/src/projects/xmas-lights deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/robots/display-ajusta-bot/ping-test.py b/src/robots/display-ajusta-bot/ping-test.py deleted file mode 100644 index fd9347d5e..000000000 --- a/src/robots/display-ajusta-bot/ping-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 7 -ECHO_PIN = 6 - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), " cm") - utime.sleep(.25) \ No newline at end of file diff --git a/src/robots/display-ajusta-bot/play-startup-tone.py b/src/robots/display-ajusta-bot/play-startup-tone.py deleted file mode 100644 index c91b2e756..000000000 --- a/src/robots/display-ajusta-bot/play-startup-tone.py +++ /dev/null @@ -1,45 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 9 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def sound_off(): - speaker.duty_u16(0) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def playnote(frequency, duration): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(duration) - sound_off() - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -play_startup() \ No newline at end of file diff --git a/src/robots/display-ajusta-bot/rotary-encoder-display-test.py b/src/robots/display-ajusta-bot/rotary-encoder-display-test.py deleted file mode 100644 index 689e3f2d5..000000000 --- a/src/robots/display-ajusta-bot/rotary-encoder-display-test.py +++ /dev/null @@ -1,71 +0,0 @@ -# Rotary Encoder Display Test -# I am getting ocassional errors -# Traceback (most recent call last): -# File "rotary.py", line 35, in rotary_change -# RuntimeError: schedule queue full - -from rotary import Rotary -from utime import sleep -from machine import Pin - -import ssd1306 -# display setup -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0, sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -rotary = Rotary(16, 17, 22) -mode = 0 -button_state = 0 - -def rotary_changed(change): - global mode, button_state - if change == Rotary.ROT_CW: - mode += 1 - elif change == Rotary.ROT_CCW: - mode -= 1 - # note these are reversed since we have the middle pin on 3.3v - elif change == Rotary.SW_PRESS: - button_state = 0 - elif change == Rotary.SW_RELEASE: - button_state = 1 - -rotary.add_handler(rotary_changed) - -def update_display(): - global mode - oled.fill(0) - oled.text('Rotery Encoder', 0, 0, 1) - oled.text('Display Test', 0, 10, 1) - oled.text('Mode:', 0, 30, 1) - oled.text(str(mode), 50, 30, 1) - oled.text('Button State:', 0, 40, 1) - oled.text(str(button_state), 110, 40, 1) - oled.text('Counter: ', 0, 50, 1) - oled.text(str(counter), 70, 50, 1) - oled.show() - -print('Rotary Encoder Display Test') - -current_mode = mode -current_button = button_state -print('mode:', mode) -print('button:', button_state) -counter = 0 -while True: - update_display() - # only print on change - if current_mode != mode: - print('mode:', mode) - current_mode = mode - if current_button != button_state: - print('button:', button_state) - current_button = button_state - sleep(0.1) - counter += 1 \ No newline at end of file diff --git a/src/robots/display-ajusta-bot/ssd1306-spi-test.py b/src/robots/display-ajusta-bot/ssd1306-spi-test.py deleted file mode 100644 index 1462eeafe..000000000 --- a/src/robots/display-ajusta-bot/ssd1306-spi-test.py +++ /dev/null @@ -1,29 +0,0 @@ -import machine -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) - -spi=machine.SPI(0,sck=clock, mosi=data) - -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -i=0 -while True: - oled.fill(0) - oled.text('Hello Dan', 0, 0, 1) - oled.text(str(i), 0, 10, 1) - oled.show() - i += 1 - sleep(1) - - - - \ No newline at end of file diff --git a/src/robots/ir-collison-bot/ir-sensor-test-2.py b/src/robots/ir-collison-bot/ir-sensor-test-2.py deleted file mode 100644 index 2dd13c8fa..000000000 --- a/src/robots/ir-collison-bot/ir-sensor-test-2.py +++ /dev/null @@ -1,18 +0,0 @@ -from machine import Pin -from utime import sleep - -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -while True: - if left.value()==0: - print('Left') - if center.value()==0: - print('Center') - if right.value()==0: - print('Right') - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - sleep(.25) \ No newline at end of file diff --git a/src/robots/ir-collison-bot/ir-sensor-test.py b/src/robots/ir-collison-bot/ir-sensor-test.py deleted file mode 100644 index b80619367..000000000 --- a/src/robots/ir-collison-bot/ir-sensor-test.py +++ /dev/null @@ -1,12 +0,0 @@ -from machine import Pin -from utime import sleep - -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -while True: - print('Left:', left.value(), end='') - print(' Center:', center.value(), end='') - print(' Right:', right.value()) - sleep(.25) \ No newline at end of file diff --git a/src/robots/ir-collison-bot/ir-sensor-tone-test.py b/src/robots/ir-collison-bot/ir-sensor-tone-test.py deleted file mode 100644 index a19193265..000000000 --- a/src/robots/ir-collison-bot/ir-sensor-tone-test.py +++ /dev/null @@ -1,71 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - - -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def sound_off(): - speaker.duty_u16(0) - -def left_tone(): - speaker.duty_u16(1000) - speaker.freq(300) # 1 Kilohertz - sleep(.5) # wait a 1/4 second - sound_off() - -def center_tone(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(800) - sleep(.25) - sound_off() - -def forward_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.1) - speaker.freq(900) - sleep(.1) - speaker.freq(1200) - sleep(.1) - sound_off() - -# 0=stopped, 1=forward, 2=turing right, 3=turning left -drive_state = 0 -while True: - if left.value()==0: - print('Left') - left_tone() - drive_state = 2 - if center.value()==0: - print('Center') - center_tone() - drive_state = 0 - if right.value()==0: - print('Right') - right_tone() - drive_state = 3 - - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - drive_state = 1 - forward_tone() - sleep(.25) \ No newline at end of file diff --git a/src/robots/ir-collison-bot/main.py b/src/robots/ir-collison-bot/main.py deleted file mode 100644 index 569068ce7..000000000 --- a/src/robots/ir-collison-bot/main.py +++ /dev/null @@ -1,155 +0,0 @@ -from machine import Pin, PWM -from utime import sleep -import ssd1306 - -# Motor pins to the L293 H-Bridge -RIGHT_FORWARD_PIN = 17 -RIGHT_REVERSE_PIN = 16 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# connections to the three IR distance sensors -left = Pin(8, Pin.IN, Pin.PULL_DOWN) -center = Pin(7, Pin.IN, Pin.PULL_DOWN) -right = Pin(6, Pin.IN, Pin.PULL_DOWN) - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - -def sound_off(): - speaker.duty_u16(0) - -def left_tone(): - speaker.duty_u16(1000) - speaker.freq(700) # 1 Kilohertz - sleep(.5) # wait a 1/4 second - sound_off() - -def center_tone(): - speaker.duty_u16(1000) - speaker.freq(900) - sleep(.5) - sound_off() - -def right_tone(): - speaker.duty_u16(1000) - speaker.freq(600) - sleep(.5) - sound_off() - -def forward_tone(): - speaker.duty_u16(1000) - speaker.freq(400) - sleep(.1) - speaker.freq(900) - sleep(.1) - speaker.freq(1200) - sleep(.1) - sound_off() - -def update_oled(): - oled.fill(0) - oled.text("CoderDojo Rocks!", 0, 0, 1) - - oled.text("Left:", 0, 10, 1) - oled.text(str(left.value()), 50, 10, 1) - - - oled.text("Center:", 0, 20, 1) - oled.text(str(center.value()), 60, 20, 1) - - oled.text("Right:", 0, 30, 1) - oled.text(str(right.value()), 55, 30, 1) - - BAR_WIDTH = 40 - BAR_HEIGHT = 20 - if left.value(): - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(WIDTH-40, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if center.value(): - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(50, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - if right.value(): - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 0) - else: - oled.fill_rect(0, 50, BAR_WIDTH, BAR_HEIGHT, 1) - - oled.show() - - - -# 0=stopped, 1=forward, 2=turing right, 3=turning left -drive_state = 0 -counter = 0 -while True: - if left.value()==0: - print('Left') - #left_tone() - turn_right() - update_oled() - drive_state = 2 - if center.value()==0: - print('Center') - center_tone() - reverse() - update_oled() - drive_state = 0 - if right.value()==0: - print('Right') - #right_tone() - turn_left() - update_oled() - drive_state = 3 - - # if (left.value()==1) and (center.value()==1) and (right.value()==1): - if left.value() and center.value() and right.value(): - print('Go forward!') - drive_state = 1 - # forward_tone() - forward() - update_oled() - print("counter: ", counter) - counter += 1 - sleep(.25) \ No newline at end of file diff --git a/src/robots/ir-collison-bot/motor-drive-test-l293-v1.py b/src/robots/ir-collison-bot/motor-drive-test-l293-v1.py deleted file mode 100644 index 024d500bc..000000000 --- a/src/robots/ir-collison-bot/motor-drive-test-l293-v1.py +++ /dev/null @@ -1,30 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 17 -RIGHT_REVERSE_PIN = 16 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(65025) - sleep(1) - pwm.duty_u16(0) - sleep(1) - -print('right forward') -spin_wheel(right_forward) -print('right reverse') -spin_wheel(right_reverse) -print('left foward') -spin_wheel(left_forward) -print('left_reverse') - -spin_wheel(left_reverse) \ No newline at end of file diff --git a/src/robots/ir-collison-bot/motor-drive-test-l293.py b/src/robots/ir-collison-bot/motor-drive-test-l293.py deleted file mode 100644 index 4b528faeb..000000000 --- a/src/robots/ir-collison-bot/motor-drive-test-l293.py +++ /dev/null @@ -1,34 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 17 -RIGHT_REVERSE_PIN = 16 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# while True: -def spin_wheel(pwm): - for duty in range(65025): - pwm.duty_u16(duty) - sleep(0.0002) - sleep(1) - for duty in range(65025, 0, -1): - pwm.duty_u16(duty) - sleep(0.0002) - sleep(.5) - -print('right forward') -spin_wheel(right_forward) -print('right reverse') -spin_wheel(right_reverse) -print('left foward') -spin_wheel(left_forward) -print('left_reverse') - -spin_wheel(left_reverse) \ No newline at end of file diff --git a/src/robots/motor-drive-test-l293.py b/src/robots/motor-drive-test-l293.py deleted file mode 100644 index 0c589678b..000000000 --- a/src/robots/motor-drive-test-l293.py +++ /dev/null @@ -1,35 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 18 -LEFT_FORWARD_PIN = 20 -LEFT_REVERSE_PIN = 21 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -POWER_LEVEL = 65025 - -# while True: -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - sleep(2) - pwm.duty_u16(0) - sleep(1) - -while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) diff --git a/src/robots/oled-ssd1309-spi-test.py b/src/robots/oled-ssd1309-spi-test.py deleted file mode 100644 index fc376ccf3..000000000 --- a/src/robots/oled-ssd1309-spi-test.py +++ /dev/null @@ -1,28 +0,0 @@ -from machine import Pin -import ssd1306 -import utime - -WIDTH = 128 -HEIGHT = 64 - -# default is data on GP7 and clock on GP6 - - -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -oled.fill(0) -oled.text("CoderDojo Rocks!", 0, 0, 1) -oled.text("MicroPython Robt", 0, 10, 1) -oled.text("128X64 OLED", 0, 20, 1) -oled.text("L293 Motor Drive", 0, 30, 1) -oled.text("3 IR Dist Sensors", 0, 40, 1) -oled.text("$25", 0, 50, 1) -oled.show() diff --git a/src/robots/param-bot/button-interrupt-test.py b/src/robots/param-bot/button-interrupt-test.py deleted file mode 100644 index 697c4b87c..000000000 --- a/src/robots/param-bot/button-interrupt-test.py +++ /dev/null @@ -1,34 +0,0 @@ -# Use an interrupt function count the number of times a button has been pressed -from machine import Pin -import micropython -import time - -# global value -button_pressed_count = 0 - -# The built-in LED -builtin_led = Pin(25, Pin.OUT) -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) - -# Interrupt Service Routine for Button Pressed Events - with no debounce -def button1_pressed(change): - global button_pressed_count - change.disable_irq() - change.delay(50) - if button1.value(): - button_pressed_count += 1 - change.enable_irq() - -button1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING ) - -# | Pin.IRQ_RISING -# call the handler function when the value drops from 3.3 to 0 volts on the button pin -# button1.irq(handler=button1_pressed, trigger=Pin.IRQ_FALLING ) - -button_pressed_count_old = 0 -while True: - if button_pressed_count_old != button_pressed_count: - print('Button 1 value:', button_pressed_count) - builtin_led.toggle() - button_pressed_count_old = button_pressed_count - \ No newline at end of file diff --git a/src/robots/param-bot/button-irq-debounce-example.py b/src/robots/param-bot/button-irq-debounce-example.py deleted file mode 100644 index 4f6e588bd..000000000 --- a/src/robots/param-bot/button-irq-debounce-example.py +++ /dev/null @@ -1,32 +0,0 @@ -import utime -from machine import Pin - -# Sample Rapsberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# the lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# this function gets called every time the button is pressed -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses \ No newline at end of file diff --git a/src/robots/param-bot/button-irq-example.py b/src/robots/param-bot/button-irq-example.py deleted file mode 100644 index 286791306..000000000 --- a/src/robots/param-bot/button-irq-example.py +++ /dev/null @@ -1,25 +0,0 @@ -import machine, utime - -# globals -button_presses = 0 -last_time = 0 # the last time we pressed the button - -# the lower right coner has a wire that goes throuh -count_input = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# this function gets called every time the button is pressed -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - if (new_time - last_time) > 200: # if it has been more that 1/5 of a second ago we have a new event - button_presses +=1 - last_time = new_time - -count_input.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - old_presses = button_presses \ No newline at end of file diff --git a/src/robots/param-bot/button-rotary-display.py b/src/robots/param-bot/button-rotary-display.py deleted file mode 100644 index 9b4714627..000000000 --- a/src/robots/param-bot/button-rotary-display.py +++ /dev/null @@ -1,54 +0,0 @@ -# This program will print a sequence of numbers in the shell if a button is pressed -# Each momentary button must be connected to the 3.3 volt power rail -# The rotory encoder will only display A or B values -from machine import Pin, Timer -import ssd1306 -import time - -# display setup -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0, sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -led = Pin(15, Pin.OUT) - -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) -button2 = Pin(15, Pin.IN, Pin.PULL_DOWN) -button3 = Pin(22, Pin.IN, Pin.PULL_DOWN) -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -while True: - - if button1.value(): - print('Button 1 ', end='') - oled.fill(0) - oled.text('Button 1', 0, 0, 1) - oled.show() - if button2.value(): - print('2 ', end='') - oled.fill(0) - oled.text('Button 2', 0, 10, 1) - oled.show() - if button3.value(): - print('3 ', end='') - oled.fill(0) - oled.text('Button 3', 0, 20, 1) - oled.show() - if rotaryA.value(): - print('A ', end='') - oled.fill(0) - oled.text('Rot A', 0, 30, 1) - oled.show() - if rotaryB.value(): - print('B ', end='') - oled.fill(0) - oled.text('Rot B', 0, 40, 1) - oled.show() - time.sleep(0.1) \ No newline at end of file diff --git a/src/robots/param-bot/example_simple.py b/src/robots/param-bot/example_simple.py deleted file mode 100644 index ff14e623c..000000000 --- a/src/robots/param-bot/example_simple.py +++ /dev/null @@ -1,37 +0,0 @@ -# The MIT License (MIT) -# Copyright (c) 2021 Mike Teachman -# https://opensource.org/licenses/MIT -# https://raw.githubusercontent.com/miketeachman/micropython-rotary/master/Examples/example_simple.py -# example for MicroPython rotary encoder - -import sys -if sys.platform == 'esp8266' or sys.platform == 'esp32': - from rotary_irq_esp import RotaryIRQ -elif sys.platform == 'pyboard': - from rotary_irq_pyb import RotaryIRQ - print('found pyboard') -elif sys.platform == 'rp2': - from rotary_irq_rp2 import RotaryIRQ - print('found Raspberry Pico') -else: - print('Warning: The Rotary module has not been tested on this platform') - -import time - - -r = RotaryIRQ(pin_num_clk=17, - pin_num_dt=16, - min_val=0, - max_val=10, - reverse=True, - range_mode=RotaryIRQ.RANGE_WRAP) - -val_old = r.value() -while True: - val_new = r.value() - - if val_old != val_new: - val_old = val_new - print('result =', val_new) - - time.sleep_ms(50) diff --git a/src/robots/param-bot/main.py b/src/robots/param-bot/main.py deleted file mode 100644 index b509de363..000000000 --- a/src/robots/param-bot/main.py +++ /dev/null @@ -1,127 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import machine -import ssd1306 -import time -from rotary import Rotary -import micropython - -# for error handlings -micropython.alloc_emergency_exception_buf(100) - -# the builtin LED should be flashing when the main loop is running -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# momentary push buttons in the lower left corner -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) -button2 = Pin(15, Pin.IN, Pin.PULL_DOWN) - -# Init HC-SR04 pins -TRIGGER_PIN = 7 -ECHO_PIN = 6 -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -# display setup -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = 32 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# Rotary Encoder pins for A, B and Press Button -rotary = Rotary(16, 17, 22) - -# Global Variables -# current program running -prog = 0 -x = 0 -val = 0 -param1 = 0 -param2 = 0 - -def rotary_changed(change): - global val, x - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('Button pressed to clear screen') - x = -1 - val = 0 - x += 1 - print('in rotary_changed') - return - -rotary.add_handler(rotary_changed) - -def ping(): - trigger.low() - time.sleep_us(2) # Wait 2 microseconds low - trigger.high() - time.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = time.ticks_us() - while echo.value() == 1: - signalon = time.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -def myMain(): - i = 0 - prog = 0 - while True: - led_onboard.toggle() - oled.fill(0) - dist = round(ping(), 2) - print("Distance:", dist, " cm") - oled.text('Param Bot', 0, 0, 1) - oled.text('d=', 0, 10, 1) - if dist < 100: - oled.text(str(dist), 20, 10, 1) - - oled.text('prog=', 0, 20, 1) - oled.text(str(prog), 45, 20, 1) - - oled.text('val=', 0, 30, 1) - oled.text(str(val), 40, 30, 1) - - oled.text('x=', 0, 40, 1) - oled.text(str(x), 20, 40, 1) - - if button1.value(): - oled.text('b1=', 100, 10, 1) - oled.text(str(button1.value()), 120, 10, 1) - - if button2.value(): - oled.text('b2=', 100, 20, 1) - oled.text(str(button1.value()), 120, 20, 1) - - oled.text(str(i), 0, 53, 1) - oled.show() - time.sleep(.1) - i += 1 - -# this is the main loop that will watch for control-C events -try: - myMain() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('cleaning up') - oled.fill(0) - oled.show() \ No newline at end of file diff --git a/src/robots/param-bot/ping-display-test.py b/src/robots/param-bot/ping-display-test.py deleted file mode 100644 index 007643e6e..000000000 --- a/src/robots/param-bot/ping-display-test.py +++ /dev/null @@ -1,55 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import machine -import ssd1306 -import time - -TRIGGER_PIN = 7 -ECHO_PIN = 6 - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) - -spi=machine.SPI(0,sck=clock, mosi=data) - -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def ping(): - trigger.low() - time.sleep_us(2) # Wait 2 microseconds low - trigger.high() - time.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = time.ticks_us() - while echo.value() == 1: - signalon = time.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -i = 0 -while True: - dist = ping() - print("Distance:", dist, " cm") - time.sleep(.25) - oled.fill(0) - oled.text('Hello Dan', 0, 0, 1) - oled.text(str(dist), 0, 10, 1) - oled.text(str(i), 0, 53, 1) - oled.show() - time.sleep(.1) - i += 1 \ No newline at end of file diff --git a/src/robots/param-bot/ping-test.py b/src/robots/param-bot/ping-test.py deleted file mode 100644 index fd9347d5e..000000000 --- a/src/robots/param-bot/ping-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 7 -ECHO_PIN = 6 - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), " cm") - utime.sleep(.25) \ No newline at end of file diff --git a/src/robots/param-bot/rotary-encoder-display-plot-test.py b/src/robots/param-bot/rotary-encoder-display-plot-test.py deleted file mode 100644 index 6923b9fbc..000000000 --- a/src/robots/param-bot/rotary-encoder-display-plot-test.py +++ /dev/null @@ -1,55 +0,0 @@ -# rotary-encoder-display-plot-test.py -from rotary import Rotary -import utime as time -from machine import Pin - -import ssd1306 -# display setup -WIDTH = 128 -HEIGHT = 64 -HALF_HEIGHT = 32 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0, sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -rotary = Rotary(16, 17, 22) -x = 0 -val = 0 - -def rotary_changed(change): - global val, x - # oled.fill(0) - oled.pixel(x % WIDTH, HALF_HEIGHT -val, 1) - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('Button pressed to clear screen') - oled.fill(0) - x = 0 - val = 0 - oled.pixel(0, HALF_HEIGHT, 1) - oled.show() - x += 1 - -rotary.add_handler(rotary_changed) - -oled.fill(0) -oled.text('Rotery encoder', 0, 0, 1) -oled.text('Plot test', 0, 10, 1) -oled.text('Press to clear', 0, 20, 1) -oled.show() -time.sleep(2) -oled.fill(0) -oled.pixel(0, HALF_HEIGHT, 1) -oled.show() - -while True: - time.sleep(0.1) \ No newline at end of file diff --git a/src/robots/param-bot/rotary-encoder-display-test.py b/src/robots/param-bot/rotary-encoder-display-test.py deleted file mode 100644 index fe205eb48..000000000 --- a/src/robots/param-bot/rotary-encoder-display-test.py +++ /dev/null @@ -1,48 +0,0 @@ -from rotary import Rotary -import utime as time -from machine import Pin - -import ssd1306 -# display setup -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0, sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -rotary = Rotary(16, 17, 22) -val = 0 - -def rotary_changed(change): - global val - oled.fill(0) - oled.text('Rotery Encoder', 0, 0, 1) - oled.text('Display Test', 0, 10, 1) - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - oled.text(str(val), 0, 30, 1) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - oled.text(str(val), 0, 30, 1) - elif change == Rotary.SW_PRESS: - print('PRESS') - oled.text('B3 Press', 0, 50, 1) - elif change == Rotary.SW_RELEASE: - print('RELEASE') - oled.text('B3 Release', 0, 50, 1) - oled.show() -rotary.add_handler(rotary_changed) - -oled.fill(0) -oled.text('Rotery Encoder', 0, 0, 1) -oled.text('Display Test', 0, 10, 1) -oled.show() - -while True: - time.sleep(0.1) \ No newline at end of file diff --git a/src/robots/param-bot/rotary-read-test.py b/src/robots/param-bot/rotary-read-test.py deleted file mode 100644 index dc1dcda11..000000000 --- a/src/robots/param-bot/rotary-read-test.py +++ /dev/null @@ -1,25 +0,0 @@ -import time -from machine import Pin - -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -val = 0 -# we set the old value to zero for both bits being off -old_combined = 0 -while True: - A_val = rotaryA.value() - B_val = rotaryB.value() - # a sifts by one bit and then is ORed with the B calue - new_combined = (A_val << 1) | B_val - if new_combined != old_combined: - #print(A_val, end='') - #print(B_val) - old_combined = new_combined - print(val) - if A_val == 0 and B_val == 1: - val += 1 - elif A_val == 1 and B_val == 0: - val -= 1 - - time.sleep(.05) \ No newline at end of file diff --git a/src/robots/param-bot/rotary-test.py b/src/robots/param-bot/rotary-test.py deleted file mode 100644 index 5237c92ec..000000000 --- a/src/robots/param-bot/rotary-test.py +++ /dev/null @@ -1,27 +0,0 @@ -from rotary import Rotary -import utime as time -from machine import Pin - -config_16 = Pin(16, Pin.IN, Pin.PULL_DOWN) -config_17 = Pin(17, Pin.IN, Pin.PULL_DOWN) - -rotary = Rotary(16,17, 22) -val = 0 - -def rotary_changed(change): - global val - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('PRESS') - elif change == Rotary.SW_RELEASE: - print('RELEASE') - -rotary.add_handler(rotary_changed) - -while True: - time.sleep(0.1) \ No newline at end of file diff --git a/src/robots/param-bot/rotary.py b/src/robots/param-bot/rotary.py deleted file mode 100644 index 834b6640e..000000000 --- a/src/robots/param-bot/rotary.py +++ /dev/null @@ -1,49 +0,0 @@ -import machine -import utime as time -from machine import Pin -import micropython - -class Rotary: - - ROT_CW = 1 - ROT_CCW = 2 - SW_PRESS = 4 - SW_RELEASE = 8 - - def __init__(self,dt,clk,sw): - self.dt_pin = Pin(dt, Pin.IN, Pin.PULL_DOWN) - self.clk_pin = Pin(clk, Pin.IN, Pin.PULL_DOWN) - self.sw_pin = Pin(sw, Pin.IN, Pin.PULL_DOWN) - self.last_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - self.dt_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.clk_pin.irq(handler=self.rotary_change, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.sw_pin.irq(handler=self.switch_detect, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING ) - self.handlers = [] - self.last_button_status = self.sw_pin.value() - - def rotary_change(self, pin): - new_status = (self.dt_pin.value() << 1) | self.clk_pin.value() - if new_status == self.last_status: - return - transition = (self.last_status << 2) | new_status - if transition == 0b1110: - micropython.schedule(self.call_handlers, Rotary.ROT_CW) - elif transition == 0b1101: - micropython.schedule(self.call_handlers, Rotary.ROT_CCW) - self.last_status = new_status - - def switch_detect(self,pin): - if self.last_button_status == self.sw_pin.value(): - return - self.last_button_status = self.sw_pin.value() - if self.sw_pin.value(): - micropython.schedule(self.call_handlers, Rotary.SW_RELEASE) - else: - micropython.schedule(self.call_handlers, Rotary.SW_PRESS) - - def add_handler(self, handler): - self.handlers.append(handler) - - def call_handlers(self, type): - for handler in self.handlers: - handler(type) diff --git a/src/robots/param-bot/rotery-example-working-clockwise.py b/src/robots/param-bot/rotery-example-working-clockwise.py deleted file mode 100644 index ff14e623c..000000000 --- a/src/robots/param-bot/rotery-example-working-clockwise.py +++ /dev/null @@ -1,37 +0,0 @@ -# The MIT License (MIT) -# Copyright (c) 2021 Mike Teachman -# https://opensource.org/licenses/MIT -# https://raw.githubusercontent.com/miketeachman/micropython-rotary/master/Examples/example_simple.py -# example for MicroPython rotary encoder - -import sys -if sys.platform == 'esp8266' or sys.platform == 'esp32': - from rotary_irq_esp import RotaryIRQ -elif sys.platform == 'pyboard': - from rotary_irq_pyb import RotaryIRQ - print('found pyboard') -elif sys.platform == 'rp2': - from rotary_irq_rp2 import RotaryIRQ - print('found Raspberry Pico') -else: - print('Warning: The Rotary module has not been tested on this platform') - -import time - - -r = RotaryIRQ(pin_num_clk=17, - pin_num_dt=16, - min_val=0, - max_val=10, - reverse=True, - range_mode=RotaryIRQ.RANGE_WRAP) - -val_old = r.value() -while True: - val_new = r.value() - - if val_old != val_new: - val_old = val_new - print('result =', val_new) - - time.sleep_ms(50) diff --git a/src/robots/param-bot/ssd1306.py b/src/robots/param-bot/ssd1306.py deleted file mode 100644 index 30e64e789..000000000 --- a/src/robots/param-bot/ssd1306.py +++ /dev/null @@ -1,160 +0,0 @@ -# MicroPython SSD1306 OLED driver, I2C and SPI interfaces -# ssd1306.py - -from micropython import const -import framebuf - - -# register definitions -SET_CONTRAST = const(0x81) -SET_ENTIRE_ON = const(0xA4) -SET_NORM_INV = const(0xA6) -SET_DISP = const(0xAE) -SET_MEM_ADDR = const(0x20) -SET_COL_ADDR = const(0x21) -SET_PAGE_ADDR = const(0x22) -SET_DISP_START_LINE = const(0x40) -SET_SEG_REMAP = const(0xA0) -SET_MUX_RATIO = const(0xA8) -SET_COM_OUT_DIR = const(0xC0) -SET_DISP_OFFSET = const(0xD3) -SET_COM_PIN_CFG = const(0xDA) -SET_DISP_CLK_DIV = const(0xD5) -SET_PRECHARGE = const(0xD9) -SET_VCOM_DESEL = const(0xDB) -SET_CHARGE_PUMP = const(0x8D) - -# Subclassing FrameBuffer provides support for graphics primitives -# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html -class SSD1306(framebuf.FrameBuffer): - def __init__(self, width, height, external_vcc): - self.width = width - self.height = height - self.external_vcc = external_vcc - self.pages = self.height // 8 - self.buffer = bytearray(self.pages * self.width) - super().__init__(self.buffer, self.width, self.height, framebuf.MONO_VLSB) - self.init_display() - - def init_display(self): - for cmd in ( - SET_DISP, # display off - # address setting - SET_MEM_ADDR, - 0x00, # horizontal - # resolution and layout - SET_DISP_START_LINE, # start at line 0 - SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 - SET_MUX_RATIO, - self.height - 1, - SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0 - SET_DISP_OFFSET, - 0x00, - SET_COM_PIN_CFG, - 0x02 if self.width > 2 * self.height else 0x12, - # timing and driving scheme - SET_DISP_CLK_DIV, - 0x80, - SET_PRECHARGE, - 0x22 if self.external_vcc else 0xF1, - SET_VCOM_DESEL, - 0x30, # 0.83*Vcc - # display - SET_CONTRAST, - 0xFF, # maximum - SET_ENTIRE_ON, # output follows RAM contents - SET_NORM_INV, # not inverted - # charge pump - SET_CHARGE_PUMP, - 0x10 if self.external_vcc else 0x14, - SET_DISP | 0x01, # display on - ): # on - self.write_cmd(cmd) - self.fill(0) - self.show() - - def poweroff(self): - self.write_cmd(SET_DISP) - - def poweron(self): - self.write_cmd(SET_DISP | 0x01) - - def contrast(self, contrast): - self.write_cmd(SET_CONTRAST) - self.write_cmd(contrast) - - def invert(self, invert): - self.write_cmd(SET_NORM_INV | (invert & 1)) - - def rotate(self, rotate): - self.write_cmd(SET_COM_OUT_DIR | ((rotate & 1) << 3)) - self.write_cmd(SET_SEG_REMAP | (rotate & 1)) - - def show(self): - x0 = 0 - x1 = self.width - 1 - if self.width == 64: - # displays with width of 64 pixels are shifted by 32 - x0 += 32 - x1 += 32 - self.write_cmd(SET_COL_ADDR) - self.write_cmd(x0) - self.write_cmd(x1) - self.write_cmd(SET_PAGE_ADDR) - self.write_cmd(0) - self.write_cmd(self.pages - 1) - self.write_data(self.buffer) - - -class SSD1306_I2C(SSD1306): - def __init__(self, width, height, i2c, addr=0x3C, external_vcc=False): - self.i2c = i2c - self.addr = addr - self.temp = bytearray(2) - self.write_list = [b"\x40", None] # Co=0, D/C#=1 - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.temp[0] = 0x80 # Co=1, D/C#=0 - self.temp[1] = cmd - self.i2c.writeto(self.addr, self.temp) - - def write_data(self, buf): - self.write_list[1] = buf - self.i2c.writevto(self.addr, self.write_list) - - -class SSD1306_SPI(SSD1306): - def __init__(self, width, height, spi, dc, res, cs, external_vcc=False): - self.rate = 10 * 1024 * 1024 - dc.init(dc.OUT, value=0) - res.init(res.OUT, value=0) - cs.init(cs.OUT, value=1) - self.spi = spi - self.dc = dc - self.res = res - self.cs = cs - import time - - self.res(1) - time.sleep_ms(1) - self.res(0) - time.sleep_ms(10) - self.res(1) - super().__init__(width, height, external_vcc) - - def write_cmd(self, cmd): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(0) - self.cs(0) - self.spi.write(bytearray([cmd])) - self.cs(1) - - def write_data(self, buf): - self.spi.init(baudrate=self.rate, polarity=0, phase=0) - self.cs(1) - self.dc(1) - self.cs(0) - self.spi.write(buf) - self.cs(1) diff --git a/src/robots/ping-bot-oled/main.py b/src/robots/ping-bot-oled/main.py deleted file mode 100644 index a29ac5a93..000000000 --- a/src/robots/ping-bot-oled/main.py +++ /dev/null @@ -1,161 +0,0 @@ -from machine import Pin, PWM -import ssd1306 -from utime import sleep, sleep_us, ticks_us -from urandom import randint - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) - -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) - -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -width=128 -height=64 -oled = ssd1306.SSD1306_SPI(width, height, spi, DC, RES, CS) - -# Motor controller pins -RIGHT_FORWARD_PIN = 18 -RIGHT_REVERSE_PIN = 19 -LEFT_FORWARD_PIN = 21 -LEFT_REVERSE_PIN = 20 - -# Our PWM objects - one for each motor and direction -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) -# onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - - -# DRIVING PARAMETERS -# Distance in CM that we stop, backup and turn. A value from 10 to 30 is a good range. -TURN_DISTANCE = 15 -# Seconds we backup -BACKUP_TIME = .75 -# Seconds we turn -TURN_TIME = .75 -DRIVE_SPEED = 200 # 100 to 255 - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -def turn_motor_on(pwm): - pwm.duty_u16(int(DRIVE_SPEED * 254)) # 0 to 65025 - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - print(' forward ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_forward) - #turn_motor_off(right_reverse) - #turn_motor_off(left_reverse) - -def reverse(): - print(' reverse ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - print(' turning right ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def turn_left(): - print(' turning left ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def stop(): - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - - # test -def test(): - print('runnint forward, reverse, right, left test') - stop() - forward() - sleep(1) - reverse() - sleep(1) - turn_right() - sleep(1) - turn_left() - sleep(1) - -def update_oled(dist, message): - oled.fill(0) - oled.text(str(dist), 0, 0, 1) - oled.text(message, 0, 20, 1) - oled.show() -# while True: -# test() - -update_oled(ping(), 'CoderDojo Rocks!') -sleep(.25) -stop() - -counter = 0 -while True: - distance = ping() - - # skip over large numbers - while distance > 100: - distance = ping() - print(distance) - if distance < TURN_DISTANCE: - print('Reversing') - update_oled(distance, 'Reversing') - reverse() - sleep(BACKUP_TIME) - stop() - sleep(.5) - - if randint(0,2): # 50% chance of being true - turn_right() - update_oled(distance, 'Turning Right') - else: - turn_left() - update_oled(distance, 'Turning Left') - sleep(TURN_TIME) - stop() - sleep(.5) - else: - print('Forward') - update_oled(distance, 'Forward') - forward() - sleep(.1) - - print("counter: ", counter) - led_onboard.toggle() - counter += 1 - # sleep(.5) \ No newline at end of file diff --git a/src/robots/ping-bot-oled/test-ping-oled.py b/src/robots/ping-bot-oled/test-ping-oled.py deleted file mode 100644 index ad1fad6a3..000000000 --- a/src/robots/ping-bot-oled/test-ping-oled.py +++ /dev/null @@ -1,53 +0,0 @@ -# Just test the ping sensor on the OLED display -from machine import Pin, PWM -from utime import sleep, sleep_us, ticks_us -import ssd1306 - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -width=128 -height=64 -oled = ssd1306.SSD1306_SPI(width, height, spi, DC, RES, CS) -led_onboard = machine.Pin(25, machine.Pin.OUT) - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -def update_oled(dist, message): - oled.fill(0) - oled.text(str(dist), 0, 0, 1) - oled.text(message, 0, 20, 1) - oled.show() - -while True: - dist = ping() - - if dist < 15: - update_oled(dist, "Turning") - print(dist, "Turning") - else: - update_oled(dist, "Forward") - print(dist, "Foward") - sleep(.1) - led_onboard.toggle() \ No newline at end of file diff --git a/src/robots/ping-bot/display-logo-ping.py b/src/robots/ping-bot/display-logo-ping.py deleted file mode 100644 index 766f2c961..000000000 --- a/src/robots/ping-bot/display-logo-ping.py +++ /dev/null @@ -1,69 +0,0 @@ -from machine import Pin -import ssd1306 -import framebuf -from utime import sleep, sleep_us, time, ticks_us - -TRIGGER_PIN = 14 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 15 # One up from bottom left corner - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -WIDTH = 128 -HEIGHT = 64 -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -fb = framebuf.FrameBuffer(bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), - 64, 64, framebuf.MONO_VLSB) - -def update_display(distance): - oled.fill(0) - oled.blit(fb, 64, 0) - oled.text('CoderDojo', 0, 0) - oled.text('Robots', 0, 10) - oled.text('Standby', 0, 44) - oled.text('Dist:', 0, 54) - oled.text(str(distance), 40, 54) - oled.show() - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return round(distance, 1) - -while True: - distance = ping() - update_display(distance) - print("Distance:", distance, " cm") - sleep(.1) \ No newline at end of file diff --git a/src/robots/ping-bot/main.py b/src/robots/ping-bot/main.py deleted file mode 100644 index e8afd375d..000000000 --- a/src/robots/ping-bot/main.py +++ /dev/null @@ -1,134 +0,0 @@ -from machine import Pin, PWM -from utime import sleep, sleep_us, ticks_us -from urandom import randint - -# onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 21 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 20 - -# Our PWM objects - one for each motor and direction -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -# DRIVING PARAMETERS -# Distance in CM that we stop, backup and turn. A value from 10 to 30 is a good range. -TURN_DISTANCE = 20 -# Seconds we backup -BACKUP_TIME = .75 -# Seconds we turn -TURN_TIME = .75 -DRIVE_SPEED = 200 # 100 to 255 - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -def turn_motor_on(pwm): - pwm.duty_u16(int(DRIVE_SPEED * 254)) # 0 to 65025 - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - print(' forward ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_forward) - #turn_motor_off(right_reverse) - #turn_motor_off(left_reverse) - -def reverse(): - print(' reverse ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - print(' turning right ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def turn_left(): - print(' turning left ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def stop(): - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - - # test -def test(): - print('runnint forward, reverse, right, left test') - stop() - forward() - sleep(1) - reverse() - sleep(1) - turn_right() - sleep(1) - turn_left() - sleep(1) - -# while True: -# test() - -counter = 0 -while True: - distance = ping() - # skip over large numbers - while distance > 100: - distance = ping() - print(distance) - if distance < TURN_DISTANCE: - print('Reverseing') - reverse() - sleep(BACKUP_TIME) - stop() - sleep(.5) - print('Turning') - if randint(0,2): # 50% chance of being true - turn_right() - else: - turn_left() - sleep(TURN_TIME) - stop() - sleep(.5) - else: - print('Forward') - forward() - sleep(.5) - - print("counter: ", counter) - led_onboard.toggle() - counter += 1 - # sleep(.5) \ No newline at end of file diff --git a/src/robots/ping-bot/stop-motors.py b/src/robots/ping-bot/stop-motors.py deleted file mode 100644 index 1d2da97e8..000000000 --- a/src/robots/ping-bot/stop-motors.py +++ /dev/null @@ -1,23 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 18 -RIGHT_REVERSE_PIN = 19 -LEFT_FORWARD_PIN = 20 -LEFT_REVERSE_PIN = 21 - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -speaker.duty_u16(0) - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -right_forward.duty_u16(0) -right_reverse.duty_u16(0) -left_forward.duty_u16(0) -left_reverse.duty_u16(0) \ No newline at end of file diff --git a/src/robots/ping-bot/test-drive-all.py b/src/robots/ping-bot/test-drive-all.py deleted file mode 100644 index 8b8fa0288..000000000 --- a/src/robots/ping-bot/test-drive-all.py +++ /dev/null @@ -1,99 +0,0 @@ -# drive forward -from machine import Pin, PWM -from time import sleep -import ssd1306 - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -width=128 -height=64 -oled = ssd1306.SSD1306_SPI(width, height, spi, DC, RES, CS) - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 18 -RIGHT_REVERSE_PIN = 19 -LEFT_FORWARD_PIN = 21 -LEFT_REVERSE_PIN = 20 - -DRIVE_SPEED = 255 # 100 to 255 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -TEST_TIME = 2 # seconds per test - -def turn_motor_on(pwm): - pwm.duty_u16(int(DRIVE_SPEED * 254)) # 0 to 65025 - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - print(' forward ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_forward) - #turn_motor_off(right_reverse) - #turn_motor_off(left_reverse) - -def reverse(): - print(' reverse ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - print(' turning right ', sep='') - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def turn_left(): - print(' turning left ', sep='') - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def stop(): - print(' stop ', sep='') - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def test(): - print('runnint forward, reverse, right, left test') - - stop() - forward() - oled.fill(0) - oled.text('Foward', 4, 10, 1) - oled.show() - sleep(TEST_TIME) - reverse() - oled.fill(0) - oled.text('Reverse', 4, 10, 1) - oled.show() - sleep(TEST_TIME) - turn_right() - oled.fill(0) - oled.text('Right', 4, 10, 1) - oled.show() - sleep(TEST_TIME) - turn_left() - oled.fill(0) - oled.text('Left', 4, 10, 1) - oled.show() - sleep(TEST_TIME) - -while True: - test() \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/button-irq-example.py b/src/robots/ping-display-param-bot/button-irq-example.py deleted file mode 100644 index 0922f040b..000000000 --- a/src/robots/ping-display-param-bot/button-irq-example.py +++ /dev/null @@ -1,41 +0,0 @@ -import machine -from utime import sleep, sleep_us, ticks_ms -# Micropython two button press handler lab -# Wire two momentary press buttons from pins 14 and 15 through the 3.3v rail -# The buttons will increment and decrement a function_value variable - -# lower left on pico -UP_BUTTON_PIN = 14 -DOWN_BUTTON_PIN = 15 - -# the lower right coner has a wire that goes throuh 3.3v -up_irq = machine.Pin(UP_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -down_irq = machine.Pin(DOWN_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -function_value = 0 - -last_time = 0 -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global function_value, last_time - new_time = ticks_ms() - # print(pin) - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if '14' in str(pin): - function_value +=1 - else: - function_value -=1 - last_time = new_time - -# now we register the handler function when the button is pressed -up_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -down_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -print('Running two button button press handeler lab') -current_function_value = function_value -while True: - # only print on change - if current_function_value != function_value: - print('function vale:', function_value) - current_function_value = function_value \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/button-test.py b/src/robots/ping-display-param-bot/button-test.py deleted file mode 100644 index 4813eb889..000000000 --- a/src/robots/ping-display-param-bot/button-test.py +++ /dev/null @@ -1,26 +0,0 @@ -# This program will print a sequence of numbers in the shell if a button is pressed -# Each momentary button must be connected to the 3.3 volt power rail -# The rotory encoder will only display A or B values -from machine import Pin -import time - -led = Pin(15, Pin.OUT) - -button1 = Pin(14, Pin.IN, Pin.PULL_DOWN) -button2 = Pin(15, Pin.IN, Pin.PULL_DOWN) -button3 = Pin(22, Pin.IN, Pin.PULL_DOWN) -rotaryA = Pin(16, Pin.IN, Pin.PULL_DOWN) -rotaryB = Pin(17, Pin.IN, Pin.PULL_DOWN) - -while True: - if button1.value(): - print('1 ', end='') - if button2.value(): - print('2 ', end='') - if button3.value(): - print('3 ', end='') - if rotaryA.value(): - print('A ', end='') - if rotaryB.value(): - print('B ', end='') - time.sleep(0.1) \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/collision-avoidance-display-rotary-ping.py b/src/robots/ping-display-param-bot/collision-avoidance-display-rotary-ping.py deleted file mode 100644 index 9ad203ae1..000000000 --- a/src/robots/ping-display-param-bot/collision-avoidance-display-rotary-ping.py +++ /dev/null @@ -1,367 +0,0 @@ -from machine import Pin, PWM -from rotary import Rotary -from utime import sleep, sleep_us, ticks_us, ticks_ms -import urandom -import ssd1306 - -# The Default Parameters -TURN_DIST = 15 -MOTOR_POWER = 30000 -REVERSE_TIME = .5 -TURN_TIME = .5 - -# ignore any ping measurements above this number -MAX_DIST = 200 -POWER_POWER_LEVEL = 65025 - -# static pin assignments -TRIGGER_PIN = 7 -ECHO_PIN = 6 -# row 12 on left -SPEAKER_PIN = 9 -# lower right on pico -ROTARY_A_PIN = 16 -ROTARY_B_PIN = 17 -ROTARY_BUTTON_PIN = 22 -# lower left on pico -UP_BUTTON_PIN = 14 -DOWN_BUTTON_PIN = 15 - -# Motor Pins -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -rotary = Rotary(ROTARY_A_PIN, ROTARY_B_PIN, ROTARY_BUTTON_PIN) - -# our globals -mode = 0 # the program mode -mode_function = 0 # the function to change within a mode -function_value = 0 # the function value (usually a value of 0-to-5) -dist = 0 -motor_power = MOTOR_POWER -motor_power_val = 2 -turn_dist = TURN_DIST -turn_dist_val = 3 -reverse_time = REVERSE_TIME -reverse_time_val = 3 -turn_time = TURN_TIME -turn_time_val = 3 - -mode_menu = ['Standby', 'Run', 'Program', 'Test Motors', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) -# power -power_level_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -power_level_values = [0, 20000, 30000, 40000, 50000, 55000, POWER_POWER_LEVEL] -power_level_count = len(power_level_labels) -# turn distance -turn_dist_labels = ['5cm', '7cm', '10cm', '15cm', '20cm', '30cm', '40cm'] -turn_dist_values = [5, 7, 10, 15, 20, 30, 40] -turn_dist_count = len(turn_dist_labels) -# rev time -reverse_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -reverse_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -reverse_time_count = len(reverse_time_labels) -# turn time -turn_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -turn_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -turn_time_count = len(turn_time_labels) - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return int(distance) - -# note these are reversed since we have the middle pin on 3.3v -#change == Rotary.ROT_CW: -#change == Rotary.ROT_CCW: -def rotary_changed(change): - global mode, mode_function, function_menu_count - if change == Rotary.SW_PRESS: - mode += 1 - mode_function = 0 - if change == Rotary.ROT_CW: - mode_function +=1 - elif change == Rotary.ROT_CCW: - mode_function -= 1 - # wrap the mode and mode function - if mode > mode_count - 1: - mode = 0 - if mode_function > function_menu_count - 1: - mode_function = function_menu_count - 1 - if mode_function < 0: - mode_function = 0 - -rotary.add_handler(rotary_changed) - -# the lower right coner has a wire that goes throuh 3.3v -up_irq = machine.Pin(UP_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -down_irq = machine.Pin(DOWN_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -last_time = 0 -def button_pressed_handler(pin): - global mode_function, function_value, last_time, power_level_count, turn_dist_count, reverse_time_count, turn_time_count - new_time = ticks_ms() - # print(pin) - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if '14' in str(pin): - function_value +=1 - else: - function_value -=1 - # keep the function values at 0 or above - if function_value < 0: - function_value = 0 - # wrap the function values - if mode_function == 0: - if function_value >= power_level_count - 1: - function_value = power_level_count - 1 - power_level = power_level_values[function_value] - elif mode_function == 1: - if function_value >= turn_dist_count - 1: - function_value = turn_dist_count - 1 - turn_dist = turn_dist_values[function_value] - elif mode_function == 2: - if function_value >= reverse_time_count - 1: - function_value = reverse_time_count - 1 - reverse_time = reverse_time_values[function_value] - elif mode_function == 3: - if function_value >= turn_time_count - 1: - function_value = turn_time_count - 1 - turn_time = turn_time_values[function_value] - last_time = new_time - -# now we register the handler function when the button is pressed -up_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -down_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def update_display(): - global mode, dist, motor_power, backup_delay, turn_dist, turn_delay - oled.fill(0) - - # draw current mode in reverse in top 10 rows - oled.fill_rect(0, 0, WIDTH, 10, 1) - oled.text('Mode:', 0, 2, 0) - oled.text(mode_menu[mode], 40, 1, 0) - - # standby mode - if mode == 0: - oled.text(str(mode), 120, 0, 1) - oled.text('Press Knob', 10, 10, 1) - oled.text('To Start', 10, 20, 1) - - # display distance and action in standby and run modes - if mode == 0 or mode == 1: - oled.text('Dist: ', 0, 30, 1) - oled.text(str(dist), 50, 30, 1) - oled.text('Action:', 0, 40, 1) - if dist < TURN_DIST: - oled.text('Turning', 55, 40, 1) - else: - oled.text('Forward', 55, 40, 1) - - # program mode - if mode == 2: - oled.text('Par: ', 0, 20, 1) - oled.text(functions_menu[mode_function], 30, 20, 1) - - # display the modes function labels and values - oled.text('Val: ', 0, 30, 1) - # for each mode function like "Power Level" we use a different list of label/value pairs - if mode_function == 0: - oled.text(power_level_labels[function_value], 30, 30, 1) - oled.text(str(power_level_values[function_value]), 40, 40, 1) - elif mode_function == 1: - oled.text(turn_dist_labels[function_value], 30, 30, 1) - oled.text(str(turn_dist_values[function_value]), 40, 40, 1) - elif mode_function == 2: - oled.text(reverse_time_labels[function_value], 30, 30, 1) - oled.text(str(reverse_time_values[function_value]), 40, 40, 1) - elif mode_function == 3: - oled.text(turn_time_labels[function_value], 30, 30, 1) - oled.text(str(turn_time_values[function_value]), 40, 40, 1) - oled.text('ValN: ', 0, 40, 1) - - # show function - if mode == 4: - oled.text('Funct: ', 0, 30, 1) - oled.text(str(mode_function), 50, 30, 1) - oled.text('Dist: ', 0, 40, 1) - oled.text(str(dist), 50, 40, 1) - - # draw on the bottom row - oled.text('Counter: ', 0, 57, 1) - oled.text(str(counter), 65, 57, 1) - - oled.show() - -def sound_off(): - speaker.duty_u16(0) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def playnote(frequency, duration): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(duration) - sound_off() - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_reverse(): - playnote(400, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -def turn_motor_on(pwm): - pwm.duty_u16(motor_power) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -print('Collision Avoidance Display Rotary Ping with Speaker') -play_startup() - -counter = 0 -current_dist = 0 -# change the defaut mode -mode = 2 -def main(): - global counter, dist, current_dist - current_mode = mode - current_mode_function = mode_function - current_function_value = function_value - print('in main') - while True: - dist = ping() - if dist != current_dist and dist < MAX_DIST and mode != 2: - print("Distance:", dist, " cm") - current_dist = dist - update_display() - - # run mode - if mode == 1: - if dist < TURN_DIST: - play_reverse() - reverse() - sleep(REVERSE_TIME) - # half right and half left turns - if urandom.random() < .5: - turn_right() - play_turn_right() - else: - turn_left() - play_turn_left() - sleep(TURN_TIME) - forward() - else: - print('forward') - forward() - - # program mode - if mode == 2: - stop() - - # only print on change - if current_mode != mode: - print('mode:', mode) - current_mode = mode - if current_mode_function != mode_function: - print('mode function:', mode_function) - current_mode_function = mode_function - sleep(0.2) - counter += 1 - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('cleaning up') - stop() \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/collision-avoidance-tof-display-v1.py b/src/robots/ping-display-param-bot/collision-avoidance-tof-display-v1.py deleted file mode 100644 index dc64c9242..000000000 --- a/src/robots/ping-display-param-bot/collision-avoidance-tof-display-v1.py +++ /dev/null @@ -1,250 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# key parameters -MOTOR_POWER = 20000 # min is 20000 max is 65025 -motor_power = MOTOR_POWER -MOTOR_POWER_CODE = 3 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -turn_distance = TURN_DISTANCE -REVERSE_TIME = .4 # how long we backup -reverse_time = REVERSE_TIME -TURN_TIME = .4 # how long we turn -turn_time = TURN_TIME -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -mode_value = 0 # the value for the currnt mode -counter = 0 # main loop counter - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) -# power -motor_power_code = MOTOR_POWER_CODE -motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_abbr = ['Off', 'Low', 'ML', 'Med', 'MH', 'Hi', 'Max'] -motor_power_values = [0, 20000, 30000, 40000, 50000, 55000, MAX_POWER_LEVEL] -motor_power_count = len(motor_power_labels) -# turn distance -turn_dist_labels = ['5cm', '7cm', '10cm', '15cm', '20cm', '30cm', '40cm'] -turn_dist_values = [5, 7, 10, 15, 20, 30, 40] -turn_dist_count = len(turn_dist_labels) -# rev time -reverse_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -reverse_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -reverse_time_count = len(reverse_time_labels) -# turn time -turn_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -turn_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -turn_time_count = len(turn_time_labels) - - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, mode_value, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: - mode_value +=1 - if mode_value > 6: - mode_value = 0 - last_time = new_time - print(mode) - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - - -# time of flight calibration parameters -# calibration parameters for the Time of Flight Sensor - -TOF_ZERO_VALUE = 60 -TOF_MAX_SENSOR_DIST = 1200 -TOF_SCALE = .25 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - #if tof_distance < TOF_ZERO_VALUE: - # zero_dist = tof_distance - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - if mode == 0: - oled.text('Press button', 0, 11, 1) - oled.text('GP19 to start.', 0, 20, 1) - oled.text('Dist:', 0, 30, 1) - oled.text(str(dist), 40, 30, 1) - oled.text('Action:', 0, 40, 1) - if dist < turn_distance: - oled.text('Turn', 55, 40, 1) - else: - oled.text('Forward', 55, 40, 1) - elif mode == 1: # collision avoidance - oled.text('Dist:', 0, 30, 1) - oled.text(str(dist), 40, 30, 1) - oled.text('Action:', 0, 40, 1) - if dist < turn_distance: - oled.text('Turn', 55, 40, 1) - else: - oled.text('Forward', 55, 40, 1) - elif mode == 2: # square - oled.text('Select level:', 0, 10, 1) - oled.text(motor_power_labels[mode_value], 0, 20, 1) - elif mode == 3: # select power - oled.text('Select level:', 0, 10, 1) - oled.text(motor_power_labels[mode_value], 0, 20, 1) - elif mode == 4: # turn dist - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(turn_dist_labels[mode_value], 0, 20, 1) - elif mode == 5: # reverse time - oled.text('Reverse Time:', 0, 10, 1) - oled.text(reverse_time_labels[mode_value], 0, 20, 1) - elif mode == 6: # reverse time - oled.text('Turn Time:', 0, 10, 1) - oled.text(turn_time_labels[mode_value], 0, 20, 1) - oled.text(str(counter), 0, 54, 1) - oled.text(str(mode), 50, 54, 1) - oled.text(str(mode_value), 80, 54, 1) - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, mode_value, last_mode, current_mode, motor_power - while True: - dist = get_distance() - update_display() - if mode != last_mode: - print('mode', mode, 'Label:', mode_menu[mode]) - last_mode = mode - if mode == 0: # standby - stop() - if mode == 1: # collision avoidance - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < TURN_DISTANCE: - # back up for a bit - drive_reverse(motor_power) - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(TURN_TIME) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - if mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - if mode == 3: # prog power - stop() - motor_power = motor_power_values[mode_value] - print(mode_menu[mode]) - if mode == 4: # prog turn dist - print(mode_menu[mode]) - if mode == 4: # prog turn dist - print(mode_menu[mode]) - sleep(.1) - counter += 1 - if mode != current_mode: - print(counter, 'mode:', mode, 'mode val:', mode_value) - current_mode = mode - #if (counter % 50) == 0: - #print(counter, 'mode:', mode, 'mode val:', mode_value) - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/robots/ping-display-param-bot/collision-avoidance-v1.py b/src/robots/ping-display-param-bot/collision-avoidance-v1.py deleted file mode 100644 index d79355da7..000000000 --- a/src/robots/ping-display-param-bot/collision-avoidance-v1.py +++ /dev/null @@ -1,236 +0,0 @@ -from machine import Pin, PWM -from rotary import Rotary -from utime import sleep, sleep_us, ticks_ms, ticks_us -import ssd1306 - -# Initial Robot Performance Parameters -MOTOR_POWER = 30000 -TURN_DIST = 20 # distance to reverse and turn in cm -REV_TIME = .5 # time to spend in reverse -TURN_TIME = .5 # time we spend turning -TURN_MODE = 2 #random turn left and right -MAX_DIST = 200 # cm - -# adjustable parameter globals -motor_power = MOTOR_POWER -turn_dist = TURN_DIST -rev_time = REV_TIME -turn_time = TURN_TIME -turn_mode = TURN_MODE - -# static pin assignments - change these if you rewire the robot -TRIGGER_PIN = 7 -ECHO_PIN = 6 -# row 12 on left -SPEAKER_PIN = 9 -# lower right on pico -ROTARY_A_PIN = 16 -ROTARY_B_PIN = 17 -ROTARY_BUTTON_PIN = 22 -# lower left on pico -UP_BUTTON_PIN = 14 -DOWN_BUTTON_PIN = 15 -# motor pins -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -# motor PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -rotary = Rotary(ROTARY_A_PIN, ROTARY_B_PIN, ROTARY_BUTTON_PIN) - -# our globals -mode = 0 # the program mode -mode_function = 0 # the function to change within a mode -function_value = 0 # the function value (usually a value of 0-to-5) -dist = 0 - - -# setup the IRQ objects -up_irq = machine.Pin(UP_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -down_irq = machine.Pin(DOWN_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# for the display programming menu options -mode_menu = ['Standby', 'Run', 'Program', 'Test Motors', 'Status'] -mode_count = len(mode_menu) -# the programming parameters -function_menu = ['Motor Power', 'Turn Dist', 'Rev. Time', 'Turn Time', 'Turn Direction'] -function_count = len(function_menu) -motor_power_labels = ['low', 'medium-low', 'medium', 'fast', 'max'] -motor_power_values = [20000, 25000, 30000, 35000, 40000, 50000, 65025] -turn_dist_values = [5, 10, 15, 20, 35, 30, 35, 40, 50] -reverse_time_values = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.2] -turn_time_values = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0, 1.2] -turn_direction_labels = ['left', 'right', 'random'] - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return int(distance) - -# note these are reversed since we have the middle pin on 3.3v -#change == Rotary.ROT_CW: -#change == Rotary.ROT_CCW: -def rotary_changed(change): - global mode, mode_function - if change == Rotary.SW_PRESS: - mode += 1 - mode_function = 0 - if change == Rotary.ROT_CW: - mode_function +=1 - elif change == Rotary.ROT_CCW: - mode_function -= 1 - # wrap the mode and mode function - if mode > mode_count - 1: - mode = 0 - if mode_function > 5: - mode_function = 0 - if mode_function < 0: - mode_function = 5 - -rotary.add_handler(rotary_changed) - -last_time = 0 -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global function_value, last_time - new_time = ticks_ms() - # print(pin) - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - if '14' in str(pin): - function_value +=1 - else: - function_value -=1 - last_time = new_time -# now we register the handler function when the button is pressed -up_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) -down_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - - -def update_display(): - global mode, dist, motor_power, backup_delay, turn_delay - oled.fill(0) - oled.text('Mode:', 0, 0, 1) - oled.text(mode_menu[mode], 40, 0, 1) - if mode == 0: - oled.text(str(mode), 120, 0, 1) - oled.text('Press Knob', 10, 10, 1) - oled.text('To Start', 10, 20, 1) - if mode == 2: # program mode - oled.text('Funct:', 0, 10, 1) - oled.text(function_menu[mode_function], 10, 20, 1) - oled.text('Val:', 0, 30, 1) - oled.text(str(function_value), 40, 30, 1) - # do not show on PROG mode - if (mode != 2): - oled.text('Dist: ', 0, 40, 1) - oled.text(str(dist), 50, 40, 1) - oled.text('Counter: ', 0, 50, 1) - oled.text(str(counter), 70, 50, 1) - oled.show() - -def sound_off(): - speaker.duty_u16(0) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def playnote(frequency, duration): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(duration) - sound_off() - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) - -print('Collision Avoidance Display Rotary Ping Adjustable Robot with Speaker V1') -play_startup() - -counter = 0 -# 1 if there is no signal - -def main(): - global counter, dist - no_signal_status = 0 - last_no_signal_status = 0 - current_mode = mode - current_mode_function = mode_function - current_function_value = function_value - while True: - dist = ping() - if dist > MAX_DIST: - no_signal_status = 1 - update_display() - - if no_signal_status != last_no_signal_status: - print('No signal status:', no_signal_status) - last_no_signal_status = no_signal_status - # only print on change - if current_mode != mode: - print('mode:', mode) - current_mode = mode - if current_mode_function != mode_function: - print('mode function:', mode_function) - current_mode_function = mode_function - sleep(0.2) - counter += 1 - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('cleaning up') \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/drive-square.py b/src/robots/ping-display-param-bot/drive-square.py deleted file mode 100644 index ef9c1a887..000000000 --- a/src/robots/ping-display-param-bot/drive-square.py +++ /dev/null @@ -1,82 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -POWER_LEVEL = 65025 -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -FWD_TIME = 2 -TURN_TIME = .5 -STOP_TIME = 2 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -print('Running Drive Square Lab') -print('Use Control-C to Stop All Motors') - -def main(): - while True: - print('forward') - forward() - sleep(FWD_TIME) - - print('turning right') - turn_right() - sleep(TURN_TIME) - - print('stop') - stop() - sleep(STOP_TIME) - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('Cleaning up') - print('Powering down all motors now.') - stop() \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/main.py b/src/robots/ping-display-param-bot/main.py deleted file mode 100644 index dc64c9242..000000000 --- a/src/robots/ping-display-param-bot/main.py +++ /dev/null @@ -1,250 +0,0 @@ -# Collision Avoidance Demo for Cytron Maker Pi RP2040 board -# Version 3.0 with startup sounds and NeoPixel feedback - -from machine import Pin,PWM -from utime import sleep, ticks_ms -import random -import VL53L0X -from neopixel import Neopixel -import ssd1306 -from robotfunctions import sound_off, stop, forward, turn_right, turn_left, playnote, drive_reverse - -# key parameters -MOTOR_POWER = 20000 # min is 20000 max is 65025 -motor_power = MOTOR_POWER -MOTOR_POWER_CODE = 3 -TURN_DISTANCE = 25 # distnce we decide to turn - try 20 -turn_distance = TURN_DISTANCE -REVERSE_TIME = .4 # how long we backup -reverse_time = REVERSE_TIME -TURN_TIME = .4 # how long we turn -turn_time = TURN_TIME -MAX_POWER_LEVEL = 65025 -SQUARE_FWD_TIME = 2 - - -# lower left on pico -MODE_BUTTON_PIN = 21 -MODE_VALUE_BUTTON_PIN = 20 -# buttons pull down to GND from 3.3v rail -mode_irq = machine.Pin(MODE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode_value_irq = machine.Pin(MODE_VALUE_BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - - - -# Global Variables -mode = 0 # mode of operation. 0=standby, 1=run collision avoidance -current_mode = -1 -dist = 0 # distance to object in front of us -valid_dist = 1 -mode_value = 0 # the value for the currnt mode -counter = 0 # main loop counter - -# Time of flight sensor is on the I2C bus on Grove connector 0 -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -print("Device found at decimal", i2c.scan()) - -mode_menu = ['Mode: Standby', 'Run Col Avoid', 'Run Square', 'Change Power', 'Change Turn Dist', 'Chg Reverse Time', 'Chg Turn Time', 'Status'] -mode_count = len(mode_menu) -functions_menu = ['Motor Power', 'Turn Dist', 'Rev Time', 'Turn Time'] -function_menu_count = len(functions_menu) -# power -motor_power_code = MOTOR_POWER_CODE -motor_power_labels = ['Off', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Max'] -# three letter code due to limited screen area -motor_power_abbr = ['Off', 'Low', 'ML', 'Med', 'MH', 'Hi', 'Max'] -motor_power_values = [0, 20000, 30000, 40000, 50000, 55000, MAX_POWER_LEVEL] -motor_power_count = len(motor_power_labels) -# turn distance -turn_dist_labels = ['5cm', '7cm', '10cm', '15cm', '20cm', '30cm', '40cm'] -turn_dist_values = [5, 7, 10, 15, 20, 30, 40] -turn_dist_count = len(turn_dist_labels) -# rev time -reverse_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -reverse_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -reverse_time_count = len(reverse_time_labels) -# turn time -turn_time_labels = ['.2 sec', '.3 sec', '.4 sec', '.5 sec', '.6 sec', '.7 sec', '.8 sec', '.9 sec', '1 sec'] -turn_time_values = [.2, .3, .4, .5, .6, .7, .8, .9, 1] -turn_time_count = len(turn_time_labels) - - -# display setup -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -WIDTH=128 -HEIGHT=64 -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# This function gets called every time the button is pressed. The parameter "pin" used to determine what pin is pressed. -last_time = 0 -def button_pressed_handler(pin): - global mode, mode_value, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - if '21' in str(pin): - mode +=1 - if mode > mode_count - 1: - mode = 0 - else: - mode_value +=1 - if mode_value > 6: - mode_value = 0 - last_time = new_time - print(mode) - -# call the button_pressed_handler when buttons are pressed - down from 3.3 on open -mode_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) -mode_value_irq.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_pressed_handler) - - -# time of flight calibration parameters -# calibration parameters for the Time of Flight Sensor - -TOF_ZERO_VALUE = 60 -TOF_MAX_SENSOR_DIST = 1200 -TOF_SCALE = .25 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > TOF_MAX_SENSOR_DIST: - return TOF_MAX_SENSOR_DIST - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - #if tof_distance < TOF_ZERO_VALUE: - # zero_dist = tof_distance - return int((tof_distance - TOF_ZERO_VALUE) * TOF_SCALE) - -def update_display(): - global dist, counter - oled.fill(0) - # put the program mode in the first row in reverse text with dark chars on white background - oled.fill_rect(0, 0, WIDTH - 1, 9, 1) - oled.text(mode_menu[mode], 0, 1, 0) - if mode == 0: - oled.text('Press button', 0, 11, 1) - oled.text('GP19 to start.', 0, 20, 1) - oled.text('Dist:', 0, 30, 1) - oled.text(str(dist), 40, 30, 1) - oled.text('Action:', 0, 40, 1) - if dist < turn_distance: - oled.text('Turn', 55, 40, 1) - else: - oled.text('Forward', 55, 40, 1) - elif mode == 1: # collision avoidance - oled.text('Dist:', 0, 30, 1) - oled.text(str(dist), 40, 30, 1) - oled.text('Action:', 0, 40, 1) - if dist < turn_distance: - oled.text('Turn', 55, 40, 1) - else: - oled.text('Forward', 55, 40, 1) - elif mode == 2: # square - oled.text('Select level:', 0, 10, 1) - oled.text(motor_power_labels[mode_value], 0, 20, 1) - elif mode == 3: # select power - oled.text('Select level:', 0, 10, 1) - oled.text(motor_power_labels[mode_value], 0, 20, 1) - elif mode == 4: # turn dist - oled.text('Select Turn Dist', 0, 10, 1) - oled.text(turn_dist_labels[mode_value], 0, 20, 1) - elif mode == 5: # reverse time - oled.text('Reverse Time:', 0, 10, 1) - oled.text(reverse_time_labels[mode_value], 0, 20, 1) - elif mode == 6: # reverse time - oled.text('Turn Time:', 0, 10, 1) - oled.text(turn_time_labels[mode_value], 0, 20, 1) - oled.text(str(counter), 0, 54, 1) - oled.text(str(mode), 50, 54, 1) - oled.text(str(mode_value), 80, 54, 1) - oled.show() - -last_mode = -1 -# loop forever -def main(): - global dist, counter, mode, mode_value, last_mode, current_mode, motor_power - while True: - dist = get_distance() - update_display() - if mode != last_mode: - print('mode', mode, 'Label:', mode_menu[mode]) - last_mode = mode - if mode == 0: # standby - stop() - if mode == 1: # collision avoidance - if dist > TOF_MAX_SENSOR_DIST: - # only print if we used to have a valid distance - if valid_distance == 1: - print('no signal') - play_no_signal() - valid_distance = 0 - # we have a valid distance - else: - print(dist) - if dist < TURN_DISTANCE: - # back up for a bit - drive_reverse(motor_power) - sleep(REVERSE_TIME) - # turn in a random direction - if random.random() > .5: - print('turning right') - turn_right(motor_power) - else: - print('turning left') - turn_left(motor_power) - sleep(TURN_TIME) - # continue going forward - forward(motor_power) - else: - print('forward') - forward(motor_power) - if mode == 2: # drive square - print('mode 2') - forward(motor_power) - sleep(SQUARE_FWD_TIME) - turn_right(motor_power) - sleep(turn_time) - if mode == 3: # prog power - stop() - motor_power = motor_power_values[mode_value] - print(mode_menu[mode]) - if mode == 4: # prog turn dist - print(mode_menu[mode]) - if mode == 4: # prog turn dist - print(mode_menu[mode]) - sleep(.1) - counter += 1 - if mode != current_mode: - print(counter, 'mode:', mode, 'mode val:', mode_value) - current_mode = mode - #if (counter % 50) == 0: - #print(counter, 'mode:', mode, 'mode val:', mode_value) - -# startup -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -# play_startup() - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Collision Avoidence with Time-of-Flight Sensor Version 3.0') - -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - # Optional cleanup code - print('turning off sound') - sound_off() - print('turning off motors') - stop() - tof.stop() diff --git a/src/robots/ping-display-param-bot/oled-display-test.py b/src/robots/ping-display-param-bot/oled-display-test.py deleted file mode 100644 index a1c9c4ed9..000000000 --- a/src/robots/ping-display-param-bot/oled-display-test.py +++ /dev/null @@ -1,29 +0,0 @@ -import machine -import ssd1306 -import time - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) - -spi=machine.SPI(0,sck=clock, mosi=data) - -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -i=0 -while True: - oled.fill(0) - oled.text('Hello Dan', 0, 0, 1) - oled.text(str(i), 0, 10, 1) - oled.show() - time.sleep(1) - i += 1 - - - - \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/ping-test.py b/src/robots/ping-display-param-bot/ping-test.py deleted file mode 100644 index fd9347d5e..000000000 --- a/src/robots/ping-display-param-bot/ping-test.py +++ /dev/null @@ -1,31 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 7 -ECHO_PIN = 6 - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -while True: - print("Distance:", ping(), " cm") - utime.sleep(.25) \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/robotfunctions.py b/src/robots/ping-display-param-bot/robotfunctions.py deleted file mode 100644 index 086e2307c..000000000 --- a/src/robots/ping-display-param-bot/robotfunctions.py +++ /dev/null @@ -1,138 +0,0 @@ -from machine import Pin,PWM -from neopixel import Neopixel -from utime import sleep, ticks_ms - -# The Piezo Buzzer is on GP22 -BUZZER_PIN = 22 -buzzer=PWM(Pin(BUZZER_PIN)) - -# Motor Pins are A: 8,9 and B: 10,11 -RIGHT_FORWARD_PIN =10 -RIGHT_REVERSE_PIN =11 -LEFT_FORWARD_PIN = 9 -LEFT_REVERSE_PIN = 8 - -# our PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -red = (255, 0, 0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, blue, indigo, violet, cyan, lightgreen, white, pink) - -NUMBER_PIXELS = 2 -STATE_MACHINE = 0 -NEOPIXEL_PIN = 18 -# The Neopixels on the Maker Pi RP2040 are the GRB variety, not RGB -strip = Neopixel(NUMBER_PIXELS, STATE_MACHINE, NEOPIXEL_PIN, "GRB") -strip.brightness(100) - -def turn_motor_on(pwm, motor_power): - pwm.duty_u16(motor_power) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(motor_power): - turn_motor_on(right_forward, motor_power) - turn_motor_on(left_forward, motor_power) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - strip.set_pixel(0, green) - strip.set_pixel(1, green) - strip.show() - -def drive_reverse(motor_power): - turn_motor_on(right_reverse, motor_power) - turn_motor_on(left_reverse, motor_power) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - strip.set_pixel(0, purple) - strip.set_pixel(1, purple) - strip.show() - -def turn_right(motor_power): - turn_motor_on(right_forward, motor_power) - turn_motor_on(left_reverse, motor_power) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - strip.set_pixel(0, red) - strip.set_pixel(1, red) - strip.show() - play_turn_right() - -def turn_left(motor_power): - turn_motor_on(right_reverse, motor_power) - turn_motor_on(left_forward, motor_power) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, blue) - strip.set_pixel(1, blue) - strip.show() - play_turn_left() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - strip.set_pixel(0, yellow) - strip.set_pixel(1, yellow) - strip.show() - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -def play_turn_right(): - playnote(500, 0.1) - -def play_turn_left(): - playnote(700, 0.1) \ No newline at end of file diff --git a/src/robots/ping-display-param-bot/tof-calibration-display-lab.py b/src/robots/ping-display-param-bot/tof-calibration-display-lab.py deleted file mode 100644 index 79a6c00e5..000000000 --- a/src/robots/ping-display-param-bot/tof-calibration-display-lab.py +++ /dev/null @@ -1,44 +0,0 @@ -# Program to calibrate the VL53L0X time-of-flight sensor by monitoring minimum distance -from utime import sleep -from machine import Pin -from machine import I2C -import ssd1306 -import VL53L0X - -spi_sck=machine.Pin(2) -spi_tx=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -I2C_SDA_PIN = 26 -I2C_SCL_PIN = 27 -i2c=machine.I2C(1,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -MAX_DIST = 1200 -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -min_dist = MAX_DIST -while True: - dist = tof.read() - # register new min distance? - if dist < min_dist: - min_dist = dist - print('min dist:', min_dist) - print(dist) - oled.fill(0) - oled.text('dist:', 0, 0, 1) - if dist < MAX_DIST: - oled.text(str(dist), 50, 0, 1) - else: - oled.text('MAX', 50, 0, 1) - oled.text('min dist:', 0, 10, 1) - oled.text(str(min_dist), 70, 10, 1) - oled.text('cal dist:', 0, 20, 1) - oled.text(str(dist - min_dist), 70, 20, 1) - oled.show() - sleep(0.2) \ No newline at end of file diff --git a/src/robots/rainbow-bot/main.py b/src/robots/rainbow-bot/main.py deleted file mode 100644 index a13975446..000000000 --- a/src/robots/rainbow-bot/main.py +++ /dev/null @@ -1,171 +0,0 @@ -from machine import Pin, PWM -from time import sleep -from machine import Pin -from machine import I2C -import VL53L0X -from neopixel import Neopixel - -# Motor Code -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 18 -LEFT_FORWARD_PIN = 20 -LEFT_REVERSE_PIN = 21 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -# Sensor Code -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor - -# used to blink the onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# LED Code -numpix = 72 -strip = Neopixel(numpix, 0, 0, "GRB") -# we turn the brightness way down to not oversaturate the brightness in the video -strip.brightness(20) - -# driving parameters -POWER_LEVEL = 30000 # use a value from 20000 to 65025 -TURN_THRESHOLD = 400 # 25 cm -TURN_TIME = .25 # seconds of turning -BACKUP_TIME = .75 # seconds of backing up if obstacle detected - -red = (255, 0, 0) -orange = (255, 165, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -def turn_motor_on(pwm): - pwm.duty_u16(POWER_LEVEL) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, green) - #strip.show() - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, red) - #strip.show() - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - #for i in range(numpix): - # strip.set_pixel(i, blue) - #strip.show() - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - #for i in range(numpix): - # strip.set_pixel(i, yellow) - #strip.show() - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - for i in range(numpix): - strip.set_pixel(i, violet) - strip.show() - -def read_sensor_avg(): - total = 0 - for i in range(10): - total = total + tof.read() - sleep(.01) - return int(total/10) - -# offset is the color to start (0 to 6) -# dir is 1 for forward and -1 for reverse -def color_wipe_4(offset, dir): - for i in range(12): - if dir == 1: - this_color = colors[ ((i-offset) %7 )] - else: - this_color = colors[ ((i+offset) %7 )] - strip.set_pixel(i, this_color) - strip.set_pixel(23-i, this_color) - strip.set_pixel(i+24, this_color) - strip.set_pixel(47-i, this_color) - strip.set_pixel(48+i, this_color) - strip.set_pixel(71-i, this_color) - strip.show() - # time.sleep(0.01) - -counter = 0 -while True: - dist = read_sensor_avg() - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - turn_right() - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - color_wipe_4(counter % 7, -1) - sleep(.1) - counter += 1 - - else: - forward() - color_wipe_4(counter % 7, 1) - counter += 1 \ No newline at end of file diff --git a/src/robots/rainbow-bot/neopixel-test.py b/src/robots/rainbow-bot/neopixel-test.py deleted file mode 100644 index 549834628..000000000 --- a/src/robots/rainbow-bot/neopixel-test.py +++ /dev/null @@ -1,24 +0,0 @@ -import time -from neopixel import Neopixel - -numpix = 12 -strip = Neopixel(numpix, 0, 0, "GRB") - -red = (255, 0, 0) -orange = (255, 165, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -strip.brightness(255) - -while True: - for color in colors: - for i in range(numpix): - strip.set_pixel(i, color) - strip.show() - time.sleep(0.1) - \ No newline at end of file diff --git a/src/robots/rainbow-bot/neopixel-text.py b/src/robots/rainbow-bot/neopixel-text.py deleted file mode 100644 index 492148dd2..000000000 --- a/src/robots/rainbow-bot/neopixel-text.py +++ /dev/null @@ -1,27 +0,0 @@ -import time - -from neopixel import Neopixel -# https://github.com/blaz-r/pi_pico_neopixel - -numpix = 12 -strip = Neopixel(numpix, 0, 0, "GRB") -# strip.brightness(50) - -red = (255, 0, 0) -orange = (255, 165, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -strip.brightness(255) - -while True: - for color in colors: - for i in range(numpix): - strip.set_pixel(i, color) - strip.show() - time.sleep(0.1) - \ No newline at end of file diff --git a/src/robots/rainbow-bot/pattern-test.py b/src/robots/rainbow-bot/pattern-test.py deleted file mode 100644 index 122658e25..000000000 --- a/src/robots/rainbow-bot/pattern-test.py +++ /dev/null @@ -1,70 +0,0 @@ -import time -from neopixel import Neopixel - -numpix = 72 -strip = Neopixel(numpix, 0, 0, "GRB") - -red = (255, 0, 0) -orange = (255, 150, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -colors = (red, orange, yellow, green, blue, indigo, violet) - -strip.brightness(255) - -def color_wipe(): - for color in colors: - for i in range(numpix): - strip.set_pixel(i, color) - strip.show() - time.sleep(0.01) - -def color_wipe_2(): - for color in colors: - for i in range(12): - strip.set_pixel(i, color) - strip.set_pixel(i+12, color) - strip.set_pixel(i+24, color) - strip.set_pixel(i+36, color) - strip.set_pixel(i+48, color) - strip.set_pixel(i+60, color) - strip.show() - time.sleep(0.01) - -def color_wipe_3(): - for color in colors: - for i in range(12): - strip.set_pixel(i, color) - strip.set_pixel(23-i, color) - strip.set_pixel(i+24, color) - strip.set_pixel(47-i, color) - strip.set_pixel(48+i, color) - strip.set_pixel(71-i, color) - strip.show() - time.sleep(0.3) - -# offset is the color to start (0 to 6) -# dir is 1 for forward and -1 for reverse -def color_wipe_4(offset, dir): - for i in range(12): - if dir == 1: - this_color = colors[ ((i-offset) %7 )] - else: - this_color = colors[ ((i+offset) %7 )] - strip.set_pixel(i, this_color) - strip.set_pixel(23-i, this_color) - strip.set_pixel(i+24, this_color) - strip.set_pixel(47-i, this_color) - strip.set_pixel(48+i, this_color) - strip.set_pixel(71-i, this_color) - strip.show() - # time.sleep(0.01) - -while True: - for counter in range(100): - color_wipe_4(counter %7, 1) - for counter in range(100): - color_wipe_4(counter%7, -1) \ No newline at end of file diff --git a/src/robots/rainbow-bot/vl53l0x-test.py b/src/robots/rainbow-bot/vl53l0x-test.py deleted file mode 100644 index 9eb4b5478..000000000 --- a/src/robots/rainbow-bot/vl53l0x-test.py +++ /dev/null @@ -1,26 +0,0 @@ -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor -while True: -# Start ranging - dist = tof.read() - print(dist) - time.sleep(.1) - - - - - - - #q = tof.set_signal_rate_limit(0.1) - # - # time.sleep(0.1) diff --git a/src/robots/stop-motors.py b/src/robots/stop-motors.py deleted file mode 100644 index bd272a769..000000000 --- a/src/robots/stop-motors.py +++ /dev/null @@ -1,23 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 21 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 20 - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -speaker.duty_u16(0) - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -right_forward.duty_u16(0) # 65025 -right_reverse.duty_u16(0) -left_forward.duty_u16(0) -left_reverse.duty_u16(0) \ No newline at end of file diff --git a/src/robots/time-of-flight-bot/main.py b/src/robots/time-of-flight-bot/main.py deleted file mode 100644 index 3f4233bcf..000000000 --- a/src/robots/time-of-flight-bot/main.py +++ /dev/null @@ -1,100 +0,0 @@ -from machine import Pin, PWM -from utime import sleep -import VL53L0X - -# used to blink the onboard LED -led_onboard = machine.Pin(25, machine.Pin.OUT) - -# driving parameters -POWER_LEVEL = 40000 # use a value from 20000 to 65025 -TURN_THRESHOLD = 400 # 25 cm -TURN_TIME = .25 # seconds of turning -BACKUP_TIME = .75 # seconds of backing up if obstacle deteced - -# Motor pins to the L293 H-Bridge -RIGHT_FORWARD_PIN = 21 -RIGHT_REVERSE_PIN = 20 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 19 - -# setup the PWM objects -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -sda=machine.Pin(16) # Lower right corner of the Pico with the USB on top -scl=machine.Pin(17) # One up from the lower right corner of the Pico -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - - - -def turn_motor_on(pwm): - pwm.duty_u16(65025) - -def turn_motor_off(pwm): - pwm.duty_u16(0) - -def forward(): - turn_motor_on(right_forward) - turn_motor_on(left_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_reverse) - -def reverse(): - turn_motor_on(right_reverse) - turn_motor_on(left_reverse) - turn_motor_off(right_forward) - turn_motor_off(left_forward) - -def turn_right(): - turn_motor_on(right_forward) - turn_motor_on(left_reverse) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - -def turn_left(): - turn_motor_on(right_reverse) - turn_motor_on(left_forward) - turn_motor_off(right_forward) - turn_motor_off(left_reverse) - -def stop(): - turn_motor_off(right_forward) - turn_motor_off(right_reverse) - turn_motor_off(left_forward) - turn_motor_off(left_reverse) - -def read_sensor_avg(): - total = 0 - for i in range(10): - total = total + tof.read() - sleep(.01) - return int(total/10) - -tof.start() # startup the sensor - -while True: - dist = read_sensor_avg(); - print(dist) - - if dist < TURN_THRESHOLD: - print('object detected') - reverse() - sleep(BACKUP_TIME) - led_onboard.high() - turn_right() - sleep(TURN_TIME) - else: - if dist > 1300: - print('no signal') - led_onboard.low() - else: - print('Go forward') - led_onboard.high() - forward() - - diff --git a/src/robots/time-of-flight-bot/motor-connection-test.py b/src/robots/time-of-flight-bot/motor-connection-test.py deleted file mode 100644 index a0af2c652..000000000 --- a/src/robots/time-of-flight-bot/motor-connection-test.py +++ /dev/null @@ -1,51 +0,0 @@ -from machine import Pin, PWM -import time # sleep - -POWER_LEVEL = 65025 -# lower right pins with USB on top - -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt -try: - main() -except KeyboardInterrupt: - print('Got Control-c') -finally: - print('shutting motors down') - stop() diff --git a/src/robots/time-of-flight-bot/motor-drive-test.py b/src/robots/time-of-flight-bot/motor-drive-test.py deleted file mode 100644 index 6743380c8..000000000 --- a/src/robots/time-of-flight-bot/motor-drive-test.py +++ /dev/null @@ -1,51 +0,0 @@ -from machine import Pin, PWM -import time # sleep - -POWER_LEVEL = 65025 -# lower right pins with USB on top - -RIGHT_FORWARD_PIN = 8 -RIGHT_REVERSE_PIN = 9 -LEFT_FORWARD_PIN = 11 -LEFT_REVERSE_PIN = 10 - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - - -def spin_wheel(pwm): - pwm.duty_u16(POWER_LEVEL) - time.sleep(3) - pwm.duty_u16(0) - time.sleep(2) - -def stop(): - right_forward.duty_u16(0) - right_reverse.duty_u16(0) - left_forward.duty_u16(0) - left_reverse.duty_u16(0) - -def main(): - while True: - print('right forward') - spin_wheel(right_forward) - - print('right reverse') - spin_wheel(right_reverse) - - print('left foward') - spin_wheel(left_forward) - - print('left_reverse') - spin_wheel(left_reverse) - -# This allows us to stop the sound and motors when we do a Stop or Control-C which is a keyboard interrupt -try: - main() -except KeyboardInterrupt: - print('Got ctrl-c') -finally: - print('shutting motors down') - stop() diff --git a/src/robots/time-of-flight-bot/stop-motors.py b/src/robots/time-of-flight-bot/stop-motors.py deleted file mode 100644 index bd272a769..000000000 --- a/src/robots/time-of-flight-bot/stop-motors.py +++ /dev/null @@ -1,23 +0,0 @@ -from machine import Pin, PWM -from time import sleep - -# lower right pins with USB on top -RIGHT_FORWARD_PIN = 19 -RIGHT_REVERSE_PIN = 21 -LEFT_FORWARD_PIN = 18 -LEFT_REVERSE_PIN = 20 - -SPEAKER_PIN = 21 -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -speaker.duty_u16(0) - -right_forward = PWM(Pin(RIGHT_FORWARD_PIN)) -right_reverse = PWM(Pin(RIGHT_REVERSE_PIN)) -left_forward = PWM(Pin(LEFT_FORWARD_PIN)) -left_reverse = PWM(Pin(LEFT_REVERSE_PIN)) - -right_forward.duty_u16(0) # 65025 -right_reverse.duty_u16(0) -left_forward.duty_u16(0) -left_reverse.duty_u16(0) \ No newline at end of file diff --git a/src/robots/time-of-flight-bot/time-of-flight-distance-sensor-test.py b/src/robots/time-of-flight-bot/time-of-flight-distance-sensor-test.py deleted file mode 100644 index 9eb4b5478..000000000 --- a/src/robots/time-of-flight-bot/time-of-flight-distance-sensor-test.py +++ /dev/null @@ -1,26 +0,0 @@ -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() # startup the sensor -while True: -# Start ranging - dist = tof.read() - print(dist) - time.sleep(.1) - - - - - - - #q = tof.set_signal_rate_limit(0.1) - # - # time.sleep(0.1) diff --git a/src/sensors/VL53LOX-test.py b/src/sensors/VL53LOX-test.py deleted file mode 100644 index 8e23a4c41..000000000 --- a/src/sensors/VL53LOX-test.py +++ /dev/null @@ -1,18 +0,0 @@ -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # lower right pin -scl=machine.Pin(17) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print(i2c) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -while True: - tof.start() - tof.read() - print(tof.read()) - time.sleep(0.1) diff --git a/src/sensors/VL53LOX-test2.py b/src/sensors/VL53LOX-test2.py deleted file mode 100644 index 891656f98..000000000 --- a/src/sensors/VL53LOX-test2.py +++ /dev/null @@ -1,32 +0,0 @@ -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 18) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 14) - - -while True: -# Start ranging - tof.start() - tof.read() - print(tof.read()) - tof.stop() - - - - - - - #q = tof.set_signal_rate_limit(0.1) - # - # time.sleep(0.1) diff --git a/src/sensors/bme280.py b/src/sensors/bme280.py deleted file mode 100644 index 9d5875a23..000000000 --- a/src/sensors/bme280.py +++ /dev/null @@ -1,285 +0,0 @@ -from machine import I2C -import time - -# BME280 default address. -BME280_I2CADDR = 0x76 - -# Operating Modes -BME280_OSAMPLE_1 = 1 -BME280_OSAMPLE_2 = 2 -BME280_OSAMPLE_4 = 3 -BME280_OSAMPLE_8 = 4 -BME280_OSAMPLE_16 = 5 - -# BME280 Registers - -BME280_REGISTER_DIG_T1 = 0x88 # Trimming parameter registers -BME280_REGISTER_DIG_T2 = 0x8A -BME280_REGISTER_DIG_T3 = 0x8C - -BME280_REGISTER_DIG_P1 = 0x8E -BME280_REGISTER_DIG_P2 = 0x90 -BME280_REGISTER_DIG_P3 = 0x92 -BME280_REGISTER_DIG_P4 = 0x94 -BME280_REGISTER_DIG_P5 = 0x96 -BME280_REGISTER_DIG_P6 = 0x98 -BME280_REGISTER_DIG_P7 = 0x9A -BME280_REGISTER_DIG_P8 = 0x9C -BME280_REGISTER_DIG_P9 = 0x9E - -BME280_REGISTER_DIG_H1 = 0xA1 -BME280_REGISTER_DIG_H2 = 0xE1 -BME280_REGISTER_DIG_H3 = 0xE3 -BME280_REGISTER_DIG_H4 = 0xE4 -BME280_REGISTER_DIG_H5 = 0xE5 -BME280_REGISTER_DIG_H6 = 0xE6 -BME280_REGISTER_DIG_H7 = 0xE7 - -BME280_REGISTER_CHIPID = 0xD0 -BME280_REGISTER_VERSION = 0xD1 -BME280_REGISTER_SOFTRESET = 0xE0 - -BME280_REGISTER_CONTROL_HUM = 0xF2 -BME280_REGISTER_CONTROL = 0xF4 -BME280_REGISTER_CONFIG = 0xF5 -BME280_REGISTER_PRESSURE_DATA = 0xF7 -BME280_REGISTER_TEMP_DATA = 0xFA -BME280_REGISTER_HUMIDITY_DATA = 0xFD - - -class Device: - """Class for communicating with an I2C device. - - Allows reading and writing 8-bit, 16-bit, and byte array values to - registers on the device.""" - - def __init__(self, address, i2c): - """Create an instance of the I2C device at the specified address using - the specified I2C interface object.""" - self._address = address - self._i2c = i2c - - def writeRaw8(self, value): - """Write an 8-bit value on the bus (without register).""" - value = value & 0xFF - self._i2c.writeto(self._address, value) - - def write8(self, register, value): - """Write an 8-bit value to the specified register.""" - b=bytearray(1) - b[0]=value & 0xFF - self._i2c.writeto_mem(self._address, register, b) - - def write16(self, register, value): - """Write a 16-bit value to the specified register.""" - value = value & 0xFFFF - b=bytearray(2) - b[0]= value & 0xFF - b[1]= (value>>8) & 0xFF - self.i2c.writeto_mem(self._address, register, value) - - def readRaw8(self): - """Read an 8-bit value on the bus (without register).""" - return int.from_bytes(self._i2c.readfrom(self._address, 1),'little') & 0xFF - - def readU8(self, register): - """Read an unsigned byte from the specified register.""" - return int.from_bytes( - self._i2c.readfrom_mem(self._address, register, 1),'little') & 0xFF - - def readS8(self, register): - """Read a signed byte from the specified register.""" - result = self.readU8(register) - if result > 127: - result -= 256 - return result - - def readU16(self, register, little_endian=True): - """Read an unsigned 16-bit value from the specified register, with the - specified endianness (default little endian, or least significant byte - first).""" - result = int.from_bytes( - self._i2c.readfrom_mem(self._address, register, 2),'little') & 0xFFFF - if not little_endian: - result = ((result << 8) & 0xFF00) + (result >> 8) - return result - - def readS16(self, register, little_endian=True): - """Read a signed 16-bit value from the specified register, with the - specified endianness (default little endian, or least significant byte - first).""" - result = self.readU16(register, little_endian) - if result > 32767: - result -= 65536 - return result - - def readU16LE(self, register): - """Read an unsigned 16-bit value from the specified register, in little - endian byte order.""" - return self.readU16(register, little_endian=True) - - def readU16BE(self, register): - """Read an unsigned 16-bit value from the specified register, in big - endian byte order.""" - return self.readU16(register, little_endian=False) - - def readS16LE(self, register): - """Read a signed 16-bit value from the specified register, in little - endian byte order.""" - return self.readS16(register, little_endian=True) - - def readS16BE(self, register): - """Read a signed 16-bit value from the specified register, in big - endian byte order.""" - return self.readS16(register, little_endian=False) - - -class BME280: - def __init__(self, mode=BME280_OSAMPLE_1, address=BME280_I2CADDR, i2c=None, - **kwargs): - # Check that mode is valid. - if mode not in [BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4, - BME280_OSAMPLE_8, BME280_OSAMPLE_16]: - raise ValueError( - 'Unexpected mode value {0}. Set mode to one of ' - 'BME280_ULTRALOWPOWER, BME280_STANDARD, BME280_HIGHRES, or ' - 'BME280_ULTRAHIGHRES'.format(mode)) - self._mode = mode - # Create I2C device. - if i2c is None: - raise ValueError('An I2C object is required.') - self._device = Device(address, i2c) - # Load calibration values. - self._load_calibration() - self._device.write8(BME280_REGISTER_CONTROL, 0x3F) - self.t_fine = 0 - - def _load_calibration(self): - - self.dig_T1 = self._device.readU16LE(BME280_REGISTER_DIG_T1) - self.dig_T2 = self._device.readS16LE(BME280_REGISTER_DIG_T2) - self.dig_T3 = self._device.readS16LE(BME280_REGISTER_DIG_T3) - - self.dig_P1 = self._device.readU16LE(BME280_REGISTER_DIG_P1) - self.dig_P2 = self._device.readS16LE(BME280_REGISTER_DIG_P2) - self.dig_P3 = self._device.readS16LE(BME280_REGISTER_DIG_P3) - self.dig_P4 = self._device.readS16LE(BME280_REGISTER_DIG_P4) - self.dig_P5 = self._device.readS16LE(BME280_REGISTER_DIG_P5) - self.dig_P6 = self._device.readS16LE(BME280_REGISTER_DIG_P6) - self.dig_P7 = self._device.readS16LE(BME280_REGISTER_DIG_P7) - self.dig_P8 = self._device.readS16LE(BME280_REGISTER_DIG_P8) - self.dig_P9 = self._device.readS16LE(BME280_REGISTER_DIG_P9) - - self.dig_H1 = self._device.readU8(BME280_REGISTER_DIG_H1) - self.dig_H2 = self._device.readS16LE(BME280_REGISTER_DIG_H2) - self.dig_H3 = self._device.readU8(BME280_REGISTER_DIG_H3) - self.dig_H6 = self._device.readS8(BME280_REGISTER_DIG_H7) - - h4 = self._device.readS8(BME280_REGISTER_DIG_H4) - h4 = (h4 << 24) >> 20 - self.dig_H4 = h4 | (self._device.readU8(BME280_REGISTER_DIG_H5) & 0x0F) - - h5 = self._device.readS8(BME280_REGISTER_DIG_H6) - h5 = (h5 << 24) >> 20 - self.dig_H5 = h5 | ( - self._device.readU8(BME280_REGISTER_DIG_H5) >> 4 & 0x0F) - - def read_raw_temp(self): - """Reads the raw (uncompensated) temperature from the sensor.""" - meas = self._mode - self._device.write8(BME280_REGISTER_CONTROL_HUM, meas) - meas = self._mode << 5 | self._mode << 2 | 1 - self._device.write8(BME280_REGISTER_CONTROL, meas) - sleep_time = 1250 + 2300 * (1 << self._mode) - - sleep_time = sleep_time + 2300 * (1 << self._mode) + 575 - sleep_time = sleep_time + 2300 * (1 << self._mode) + 575 - time.sleep_us(sleep_time) # Wait the required time - msb = self._device.readU8(BME280_REGISTER_TEMP_DATA) - lsb = self._device.readU8(BME280_REGISTER_TEMP_DATA + 1) - xlsb = self._device.readU8(BME280_REGISTER_TEMP_DATA + 2) - raw = ((msb << 16) | (lsb << 8) | xlsb) >> 4 - return raw - - def read_raw_pressure(self): - """Reads the raw (uncompensated) pressure level from the sensor.""" - """Assumes that the temperature has already been read """ - """i.e. that enough delay has been provided""" - msb = self._device.readU8(BME280_REGISTER_PRESSURE_DATA) - lsb = self._device.readU8(BME280_REGISTER_PRESSURE_DATA + 1) - xlsb = self._device.readU8(BME280_REGISTER_PRESSURE_DATA + 2) - raw = ((msb << 16) | (lsb << 8) | xlsb) >> 4 - return raw - - def read_raw_humidity(self): - """Assumes that the temperature has already been read """ - """i.e. that enough delay has been provided""" - msb = self._device.readU8(BME280_REGISTER_HUMIDITY_DATA) - lsb = self._device.readU8(BME280_REGISTER_HUMIDITY_DATA + 1) - raw = (msb << 8) | lsb - return raw - - def read_temperature(self): - """Get the compensated temperature in 0.01 of a degree celsius.""" - adc = self.read_raw_temp() - var1 = ((adc >> 3) - (self.dig_T1 << 1)) * (self.dig_T2 >> 11) - var2 = (( - (((adc >> 4) - self.dig_T1) * ((adc >> 4) - self.dig_T1)) >> 12) * - self.dig_T3) >> 14 - self.t_fine = var1 + var2 - return (self.t_fine * 5 + 128) >> 8 - - def read_pressure(self): - """Gets the compensated pressure in Pascals.""" - adc = self.read_raw_pressure() - var1 = self.t_fine - 128000 - var2 = var1 * var1 * self.dig_P6 - var2 = var2 + ((var1 * self.dig_P5) << 17) - var2 = var2 + (self.dig_P4 << 35) - var1 = (((var1 * var1 * self.dig_P3) >> 8) + - ((var1 * self.dig_P2) >> 12)) - var1 = (((1 << 47) + var1) * self.dig_P1) >> 33 - if var1 == 0: - return 0 - p = 1048576 - adc - p = (((p << 31) - var2) * 3125) // var1 - var1 = (self.dig_P9 * (p >> 13) * (p >> 13)) >> 25 - var2 = (self.dig_P8 * p) >> 19 - return ((p + var1 + var2) >> 8) + (self.dig_P7 << 4) - - def read_humidity(self): - adc = self.read_raw_humidity() - # print 'Raw humidity = {0:d}'.format (adc) - h = self.t_fine - 76800 - h = (((((adc << 14) - (self.dig_H4 << 20) - (self.dig_H5 * h)) + - 16384) >> 15) * (((((((h * self.dig_H6) >> 10) * (((h * - self.dig_H3) >> 11) + 32768)) >> 10) + 2097152) * - self.dig_H2 + 8192) >> 14)) - h = h - (((((h >> 15) * (h >> 15)) >> 7) * self.dig_H1) >> 4) - h = 0 if h < 0 else h - h = 419430400 if h > 419430400 else h - return h >> 12 - - @property - def temperature(self): - "Return the temperature in degrees." - t = self.read_temperature() - ti = t // 100 - td = t - ti * 100 - return "{}.{:02d}C".format(ti, td) - - @property - def pressure(self): - "Return the temperature in hPa." - p = self.read_pressure() // 256 - pi = p // 100 - pd = p - pi * 100 - return "{}.{:02d}hPa".format(pi, pd) - - @property - def humidity(self): - "Return the humidity in percent." - h = self.read_humidity() - hi = h // 1024 - hd = h * 100 // 1024 - hi * 100 - return "{}.{:02d}%".format(hi, hd) \ No newline at end of file diff --git a/src/sensors/button/one-button-lab.py b/src/sensors/button/one-button-lab.py deleted file mode 100644 index 8100f2a23..000000000 --- a/src/sensors/button/one-button-lab.py +++ /dev/null @@ -1,34 +0,0 @@ -import utime -from machine import Pin - -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -BUTTON_PIN = 14 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses diff --git a/src/sensors/button/two-button-lab.py b/src/sensors/button/two-button-lab.py deleted file mode 100644 index 8c7ff45cb..000000000 --- a/src/sensors/button/two-button-lab.py +++ /dev/null @@ -1,49 +0,0 @@ -import utime -from machine import Pin - -# Sample two button Raspberry Pi Pico MicroPython example -# with a debounce delay value of 200ms in the interrupt handler -# https://www.coderdojotc.org/micropython/basics/03-button/ - -# these are the pins in the lower-left corner (USB on top) -BUTTON_PIN_A = 14 -BUTTON_PIN_B = 15 - -button_presses = 0 # the count of times the button has been pressed. A is +1, B is -1 -last_time = 0 # the last time we pressed the button - -# we toggle the builtin LED to get visual feedback -builtin_led = machine.Pin(25, Pin.OUT) - -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_a = machine.Pin(BUTTON_PIN_A, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_b = machine.Pin(BUTTON_PIN_B, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# this is the interrupt callback handler -# get in and out quickly -def button_callback(pin): - global button_presses, last_time - new_time = utime.ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - # print(pin) - if '14' in str(pin): - button_presses +=1 - else: - button_presses -= 1 - last_time = new_time - -# now we register the handler functions when either of the buttons is pressed -button_a.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback) -button_b.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_callback) - -# This is for only printing when a new button press count value happens -old_presses = 0 - -print(button_presses) -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - print(button_presses) - builtin_led.toggle() - old_presses = button_presses diff --git a/src/sensors/compass/compass-heading-to-neopixel-ring.py b/src/sensors/compass/compass-heading-to-neopixel-ring.py deleted file mode 100644 index 23c350c56..000000000 --- a/src/sensors/compass/compass-heading-to-neopixel-ring.py +++ /dev/null @@ -1,31 +0,0 @@ -# The heading changes from 0 to 360 as you rotate the sensor around the vertical axis -from machine import I2C, Pin -from hmc5883l import HMC5883L -from time import sleep -from neopixel import NeoPixel - -# Please check that correct PINs are set on hmc5883l library! -sensor = HMC5883L(scl=13, sda=12, declination=(0, 71)) - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 24 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -while True: - x, y, z = sensor.read() - heading = sensor.heading(x, y)[0] - # scale 0 to 360 to be in the 0 to 23 range - # add a few index so we point north - index = round(heading/15) - 10 - # wrap neg and above 360 - index = (NUMBER_PIXELS - index) % NUMBER_PIXELS - print(heading, index) - for i in range(0, NUMBER_PIXELS): - if i == index: - # turn index red pixel on for and delay - strip[i] = (100,70,100) - else: - strip[i] = (0,0,0) - strip.write() - sleep(.5) - \ No newline at end of file diff --git a/src/sensors/compass/h.pymc5883l-test.py b/src/sensors/compass/h.pymc5883l-test.py deleted file mode 100644 index 46e7d7547..000000000 --- a/src/sensors/compass/h.pymc5883l-test.py +++ /dev/null @@ -1,17 +0,0 @@ -from hmc5883l import HMC5883L -# from https://github.com/gvalkov/micropython-esp8266-hmc5883l - -I2C_DATA_PIN = 0 -I2C_CLOCK_PIN = 1 - -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 - -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) - -print(i2c) - -sensor = HMC5883L(scl=I2C_DATA_PIN, sda=I2C_CLOCK_PIN) - -x, y, z = sensor.read() -print(sensor.format_result(x, y, z)) \ No newline at end of file diff --git a/src/sensors/compass/h.pymc5883l.py b/src/sensors/compass/h.pymc5883l.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/sensors/compass/hmc5883l-test-v2.py b/src/sensors/compass/hmc5883l-test-v2.py deleted file mode 100644 index c8ba6e49f..000000000 --- a/src/sensors/compass/hmc5883l-test-v2.py +++ /dev/null @@ -1,15 +0,0 @@ -# turn on the plot function of Thonny -# The "Z" is how much upsidedown the sensor is -# When the sensor is right-side up the values is -660 -# When the sensor is up-side-down the value is 260 -# tilted it goes to 290 -from machine import I2C -from hmc5883l import HMC5883L -from time import sleep - -sensor = HMC5883L(scl=13, sda=12) - -while True: - x, y, z = sensor.read() - print(x, y, z) - sleep(.3) \ No newline at end of file diff --git a/src/sensors/compass/minneapolis-calibration.py b/src/sensors/compass/minneapolis-calibration.py deleted file mode 100644 index 474143481..000000000 --- a/src/sensors/compass/minneapolis-calibration.py +++ /dev/null @@ -1,13 +0,0 @@ -# The heading changes from 0 to 360 as you rotate the sensor around the vertical axis -from machine import I2C -from hmc5883l import HMC5883L -from time import sleep - -# Please check that correct PINs are set on hmc5883l library! -# The declination is based on using Minneapolis as a city -sensor = HMC5883L(scl=13, sda=12, declination=(0, 71)) - -while True: - sleep(.5) - x, y, z = sensor.read() - print(sensor.heading(x, y)[0]) \ No newline at end of file diff --git a/src/sensors/compass/plot-heading.py b/src/sensors/compass/plot-heading.py deleted file mode 100644 index d0c7d1af9..000000000 --- a/src/sensors/compass/plot-heading.py +++ /dev/null @@ -1,12 +0,0 @@ -# The heading changes from 0 to 360 as you rotate the sensor around the vertical axis -from machine import I2C -from hmc5883l import HMC5883L -from time import sleep - -# Please check that correct PINs are set on hmc5883l library! -sensor = HMC5883L(scl=13, sda=12) - -while True: - sleep(.3) - x, y, z = sensor.read() - print(sensor.heading(x, y)[0]) \ No newline at end of file diff --git a/src/sensors/compass/read-raw-compass-values.py b/src/sensors/compass/read-raw-compass-values.py deleted file mode 100644 index 2a88a9874..000000000 --- a/src/sensors/compass/read-raw-compass-values.py +++ /dev/null @@ -1,8 +0,0 @@ -from array import array -I2C_SDA_PIN = 0 -I2C_SCL_PIN = 1 -i2c=machine.I2C(0,sda=machine.Pin(I2C_SDA_PIN), scl=machine.Pin(I2C_SCL_PIN), freq=400000) -data = array('B', [0] * 6) -while True: - i2c.readfrom_mem_into(0x1e, 0x03, data) - print(data) \ No newline at end of file diff --git a/src/sensors/example_asyncio_class.py b/src/sensors/example_asyncio_class.py deleted file mode 100644 index 78db96e1c..000000000 --- a/src/sensors/example_asyncio_class.py +++ /dev/null @@ -1,93 +0,0 @@ -# The MIT License (MIT) -# Copyright (c) 2021 Mike Teachman -# https://opensource.org/licenses/MIT - -# example for MicroPython rotary encoder -# - uasyncio implementation -# - 2 independent rotary encoders -# - register callbacks with the rotary objects -# - shows the use of an Observer pattern in Python - -import sys -if sys.platform == 'esp8266' or sys.platform == 'esp32': - from rotary_irq_esp import RotaryIRQ -elif sys.platform == 'pyboard': - from rotary_irq_pyb import RotaryIRQ -elif sys.platform == 'rp2': - from rotary_irq_rp2 import RotaryIRQ -else: - print('Warning: The Rotary module has not been tested on this platform') - -import uasyncio as asyncio - - -# example of a class that uses one rotary encoder -class Application1(): - def __init__(self, r1): - self.r1 = r1 - self.myevent = asyncio.Event() - asyncio.create_task(self.action()) - r1.add_listener(self.callback) - - def callback(self): - self.myevent.set() - - async def action(self): - while True: - await self.myevent.wait() - print('App 1: rotary 1 = {}'. format(self.r1.value())) - # do something with the encoder result ... - self.myevent.clear() - - -# example of a class that uses two rotary encoders -class Application2(): - def __init__(self, r1, r2): - self.r1 = r1 - self.r2 = r2 - self.myevent = asyncio.Event() - asyncio.create_task(self.action()) - r1.add_listener(self.callback) - r2.add_listener(self.callback) - - def callback(self): - self.myevent.set() - - async def action(self): - while True: - await self.myevent.wait() - print('App 2: rotary 1 = {}, rotary 2 = {}'. format( - self.r1.value(), self.r2.value())) - # do something with the encoder results ... - self.myevent.clear() - - -async def main(): - rotary_encoder_1 = RotaryIRQ(pin_num_clk=13, - pin_num_dt=14, - min_val=0, - max_val=5, - reverse=False, - range_mode=RotaryIRQ.RANGE_WRAP) - - rotary_encoder_2 = RotaryIRQ(pin_num_clk=18, - pin_num_dt=19, - min_val=0, - max_val=20, - reverse=False, - range_mode=RotaryIRQ.RANGE_WRAP) - - # create tasks that use the rotary encoders - app1 = Application1(rotary_encoder_1) - app2 = Application2(rotary_encoder_1, rotary_encoder_2) - - # keep the event loop active - while True: - await asyncio.sleep_ms(10) - -try: - asyncio.run(main()) -except (KeyboardInterrupt, Exception) as e: - print('Exception {} {}\n'.format(type(e).__name__, e)) -finally: - ret = asyncio.new_event_loop() # Clear retained uasyncio state diff --git a/src/sensors/gesture/APDS9960LITE.py b/src/sensors/gesture/APDS9960LITE.py deleted file mode 100644 index 1c2e5074a..000000000 --- a/src/sensors/gesture/APDS9960LITE.py +++ /dev/null @@ -1,457 +0,0 @@ -"""`APDS9960LITE` -==================================================== - -Low memory Driver class for the APDS9960 - - Author: Rune Langøy 2019 - - Licence GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html -""" -from time import sleep -from micropython import const -#APDS9960_ADDR = const(0x39) - -class I2CEX: - """micropython i2c adds functions for reading / writing byte to a register - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - - def __init__(self, - i2c, - address): - self.__i2c=i2c - self.__address=address - - def __regWriteBit(self,reg,bitPos,bitVal): - """Reads a I2C register byte changes a bit and writes the new value - - :param reg: The I2C register that is writen to - :type reg: int - - :param bitPos: The bit position (0 - 7) - :type bitPos: int - - :param value: True = set-bit / False =clear bit - :type value: bool - """ - val=self.__readByte(reg) # read reg - if bitVal == True: - val=val | (1<>8) & 0xff - self.__i2c.writeto_mem(self.__address,reg,b) - - def __read2Byte(self,reg): - """Reads a I2C byte from the address APDS9960_ADDR (0x39) - - :param reg: The I2C register to read - :type reg: int - - :returns: a value in the range (0- 65535) - :rtype: int - """ - val =self.__i2c.readfrom_mem(self.__address,reg, 2) - return int.from_bytes(val, 'little', True) - - - -class ALS(I2CEX): - """APDS9960 Digital Ambient Light Sense (ALS) and Color Sense (RGBC) functionalities - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - def __init__(self, - i2c): - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - def enableSensor(self,on=True): - """Enable/Disable the Light sensor - - :param on: Enables / Disables the Light sensor - (Default True) - :type on: bool - """ - AEN=1 #ALS enable bit 1 (AEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=AEN,bitVal=on) - - @property - def eLightGain(self): - """Sets the receiver gain for light measurements. - - :getter: Returns the reciever gain (0 -3) - :setter: Sets the reciever gain (0 -3) - :type: int - - :: - - eGain Gain - 0 1x - 1 2x - 2 16x - 3 64x - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val= val & 0b00000011 - return val - - @eLightGain.setter - def eLightGain(self, eGain): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - # set bits in register to given value - eGain &= 0b00000011 - val &= 0b11111100 - val |= eGain - - super().__writeByte(0x8f,val) - - - @property - def ambientLightLevel(self): - """Reads the APDS9960 ambient light level (apds9960 clear channel data) - - :getter: Returns the ambient light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x94) #returns CDATAL and CDATAH - - @property - def redLightLevel(self): - """Reads the APDS9960 red light level (apds9960 red channel data) - - :getter: Returns the red light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x96) #returns RDATAL and RDATAH - - @property - def greenLightLevel(self): - """Reads the APDS9960 green light level (apds9960 green channel data) - - :getter: Returns the green light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x98) #returns GDATAL and GDATAH - - @property - def blueLightLevel(self): - """Reads the APDS9960 blue light level (apds9960 blue channel data) - - :getter: Returns the blue light level (0 - 1025 ) - :type: int - """ - return super().__read2Byte(0x9A) #returns BDATAL and BDATAH - - def setInterruptThreshold(self,high=0,low=20,persistance=4): - """Enable/Disable the proimity sensor - - :param high: high level for generating light hardware interrupt (Range 0 - 1025) - :type high: int - - :param low: low level for generating light hardware interrupt (Range 0 - 1025) - :type low: int - - :param persistance: Number of consecutive reads before IRQ is raised (Range 0 - 7) - :type persistance: int - - """ - #ALS low threshold, lower byte - super().__write2Byte(0x84, low); #set ALS low threshold - super().__write2Byte(0x86, high); #set ALS low threshold - - - if (persistance>7) : - persistance=7 - - val=super().__readByte(0x8C) #APDS9960_PERS 0x8C<3:0> Proximity Interrupt Persistence - val=val & 0b11111000 # Clear APERS - val=val | persistance # Set APERS - super().__writeByte(0x8C,val) # Update APDS9960_PERS - - def clearInterrupt(self): - """Crears the proimity interrupt - IRQ HW output goes low (enables triggering of new IRQ) - """ - super().__readByte(0xe6) #All Non-Gesture Interrupt Clear - - def enableInterrupt(self,on=True): - """Enables/Disables IRQ dependent on limits given by setLightInterruptThreshold() - - :param on: Enable / Disable Hardware IRQ - :type on: bool - """ - #ENABLE 0x80<4> ALS Interrupt Enable - AIEN=4 #ALS Interrupt Enable bit 4 (AIEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=AIEN,bitVal=on) - self.clearInterrupt(); - - -class PROX(I2CEX): - """APDS9960 proximity functons - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - def __init__(self, - i2c): - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - def enableSensor(self,on=True): - """Enable/Disable the proimity sensor - - :param on: Enables / Disables the proximity sensor - (Default True) - :type on: bool - """ - # PEN - bit 2 - PEN=2 #Proximity enable bit 2 (PEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=PEN,bitVal=on) - - def setInterruptThreshold(self,high=0,low=20,persistance=4): - """Enable/Disable the proimity sensor - - :param high: high level for generating proximity hardware interrupt (Range 0 - 255) - :type high: int - - :param low: low level for generating proximity hardware interrupt (Range 0 - 255) - :type low: int - - :param persistance: Number of consecutive reads before IRQ is raised (Range 0 - 7) - :type persistance: int - - """ - super().__writeByte(0x89, low); #set low proximity threshold APDS9960_PILT - super().__writeByte(0x8B, high); #set high proximity threshold APDS9960_PIHT - - if (persistance>7) : - persistance=7 - - val=super().__readByte(0x8C) #APDS9960_PERS 0x8C<7:4> Proximity Interrupt Persistence - val=val & 0b00011111 # Clear PERS - val=val | (persistance << 4) # Set PERS - super().__writeByte(0x8C,val) # Update APDS9960_PERS - - def clearInterrupt(self): - """Crears the proimity interrupt - IRQ HW output goes low (enables triggering of new IRQ) - """ - super().__writeByte(0xE7,0) # APDS9960_AICLEAR clear all interrupts - super().__readByte(0xE5)#(APDS9960_PICLEAR) - - def enableInterrupt(self,on=True): - """Enables/Disables IRQ dependent on limits given by setProximityInterruptThreshold() - - :param on: Enable / Disable Hardware IRQ - :type on: bool - """ - PIEN=5 #Proximity interrupt enable bit 5 (PIEN) in reg APDS9960_REG_ENABLE - super().__regWriteBit(reg=0x80,bitPos=PIEN,bitVal=on) - self.clearInterrupt(); - - @property - def eProximityGain(self): - """Sets the receiver gain for proximity detection. - - :getter: Returns the reciever gain (0 -3) - :setter: Sets the reciever gain (0 -3) - :type: int - - :: - - eGain Gain - 0 1x - 1 2x - 2 4x - 3 8x - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val=((val >>2) & 0b00000011) - return val - - @eProximityGain.setter - def eProximityGain(self, eGain): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - # set bits in register to given value - eGain &= 0b00000011 - eGain = eGain << 2 - val &= 0b11110011 - val |= eGain - - #i2c.writeto_mem(APDS9960_ADDR,APDS9960_REG_CONTROL,bytes((val,))) - super().__writeByte(0x8f,val) - - @property - def eLEDCurrent(self): - """ - Sets LED current for proximity and ALS. - - :getter: Returns the LED current (0 -3) - :setter: Sets the LED current(0 -3) - :type: int - - :: - - eCurent LED Current - 0 100 mA - 1 50 mA - 2 25 mA - 3 12.5 mA - """ - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - val=val >>6 - return val - - - @eLEDCurrent.setter - def eLEDCurrent(self, eCurent): - #APDS9960_REG_CONTROL = const(0x8f) - val=super().__readByte(0x8f) - - # set bits in register to given value - eCurent &= 0b00000011 - eCurent = eCurent << 6 - val &= 0b00111111 - val |= eCurent - - super().__writeByte(0x8f,val) - - @property - def proximityLevel(self): - """Reads the APDS9960 proximity level - - :getter: Returns the proximity level (0 - 255 ) - :type: int - """ - return super().__readByte(0x9c) - - -class APDS9960LITE(I2CEX) : - """APDS9960LITE low memory driver for ASDS9960 - - :param i2c: The I2C driver - :type i2C: machine.i2c - - :example: - .. code:: python - - import machine - from uPy_APDS9960.APDS9960LITE import APDS9960LITE - - i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4)) # Creates I2C Driver on Pin 5 / 6 - adps9960=APDS9960LITE(i2c) # Create APDS9960 Driver - """ - def __init__(self, - i2c): - """Construct the APDS9960 driver class - - :param i2c: The I2C driver - :type i2C: machine.i2c - """ - super().__init__(i2c,0x39) # initiate I2CEX with APDS9960_ADDR - - self.powerOn(False) # APDS9960_ENABLE PON=0 - sleep(.05) - self.powerOn(True) # APDS9960_ENABLE PON=1 - self.prox=PROX(i2c) - self.als=ALS(i2c) - - prox = None - """Prvides APDS9960 Proximity functions.See class: :class:`.PROX` - - :type PROX: - - :example: - .. code:: python - - apds9960=APDS9960LITE(i2c) # Enable sensor - apds9960.prox.enableProximity() # Enable Proximit sensing - - """ - als = None - """Prvides APDS9960 Light sensor functions.See class: :class:`.ALS` - - :type PROX: - """ - def powerOn(self,on=True): - """Enable/Disable the apds9960 sensor - - :param on: Enables / Disables the proximity sensor - (Default True) - :type on: bool - """ - - PON=0 - super().__regWriteBit(reg=0x80,bitPos=PON,bitVal=on) - - - @property - def statusRegister(self): - """ - Status Register (0x93) - The read-only Status Register provides the status of the device. The register is set to 0x04 at power-up. - Returns the device status. - - :getter: Status register content byte - - ====== ===== ============================= - Field Bits Description - ====== ===== ============================= - CPSAT 7 Clear Photodiode Saturation. - PGSAT 6 Analog saturation event. - PINT 5 Proximity Interrupt. - AINT 4 ALS Interrupt. - DNC 3 Do not care. - GINT 2 Gesture Interrupt. - PVALID 1 Proximity Valid. - AVALID 0 ALS Valid. - ====== ===== ============================= - - :rtype: int - """ - return super().__readByte(0x93) \ No newline at end of file diff --git a/src/sensors/gesture/README.md b/src/sensors/gesture/README.md deleted file mode 100644 index 02a8b198d..000000000 --- a/src/sensors/gesture/README.md +++ /dev/null @@ -1,104 +0,0 @@ -# Avago APDS-9960 Gesture Sensor - -https://upy-apds9960.readthedocs.io/en/latest/# - -https://www.youtube.com/watch?v=wH9HpP9bKwE - -https://github.com/rlangoy/uPy_APDS9960/blob/master/uPy_APDS9960/apds9960LITE.py - -## Code - -```py -import machine -from time import sleep_ms -from uPy_APDS9960.apds9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c = machine.I2C(0,scl=scl, sda=sda) - -apds9960=APDS9960LITE(i2c) # Enable sensor -apds9960.prox.enableSensor() # Enable Proximit sensing - -while True: - sleep_ms(25) # wait for readout to be ready - print(apds9960.prox.proximityLevel) #Print the proximity value -``` - -Returns - -``` -0 1 1 1 1 1 0 1 1 2 2 1 1 1 1 1 0 -``` - -## Ambient Light - -```py -# from https://github.com/rlangoy/uPy_APDS9960 -import machine -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -apds9960.als.enableSensor() # Enable Light sensor -sleep_ms(25) # Wait for readout to be ready - -#apds9960.powerOn(True) -#print(apds9960.statusRegister()) - -while True: - print(apds9960.als.ambientLightLevel, ' ', end='') - sleep(.1) -``` - -returns - -``` -1 1 0 0 0 0 0 0 0 0 1 1 1 4 8 10 10 10 12 16 17 19 19 20 21 21 22 25 27 30 33 35 36 37 38 33 33 34 34 34 34 34 35 36 36 38 39 40 38 37 38 40 42 45 48 49 55 61 66 73 76 76 82 93 109 132 156 169 171 173 173 171 164 160 169 165 162 162 164 163 159 158 152 148 148 145 141 135 122 106 96 101 108 89 62 48 33 20 10 5 3 1 0 0 0 0 0 0 0 1 2 4 8 14 26 45 65 91 110 121 124 127 132 150 191 225 244 244 254 288 295 243 219 259 299 287 204 99 31 10 2 1 1 1 0 -``` - -## Reading RGB - - - -```py -while True: - print(apds9960.als.ambientLightLevel,'', end='') - print(apds9960.als.redLightLevel,'', end='') - print(apds9960.als.greenLightLevel,'', end='') - print(apds9960.als.blueLightLevel) - sleep(.1) -``` - -``` -1 0 0 0 -2 0 0 1 -4 1 0 1 -8 3 2 2 -17 6 5 5 -28 14 10 8 -38 19 12 11 -37 27 15 12 -38 30 15 12 -43 29 15 14 -35 22 11 11 -26 17 9 7 -18 12 6 5 -13 7 4 3 -9 4 3 2 -``` - -## References - -### Datasheet -https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf - -https://robojax.com/learn/arduino/?vid=robojax-gesture-APDS9960 \ No newline at end of file diff --git a/src/sensors/gesture/prox-test.py b/src/sensors/gesture/prox-test.py deleted file mode 100644 index 9ac94e885..000000000 --- a/src/sensors/gesture/prox-test.py +++ /dev/null @@ -1,25 +0,0 @@ -# from https://github.com/rlangoy/uPy_APDS9960 -import machine -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -print('done crearing the driver') -print(apds9960) -apds9960.prox.enableSensor() # Enable Proximit sensing -print('enable the sensor') - -#apds9960.powerOn(True) -#print(apds9960.statusRegister()) - -while True: - - sleep(.1) # wait for readout to be ready - print(apds9960.prox.proximityLevel) #Print the proximity value \ No newline at end of file diff --git a/src/sensors/gesture/read-rgb-light-test.py b/src/sensors/gesture/read-rgb-light-test.py deleted file mode 100644 index 222bbc705..000000000 --- a/src/sensors/gesture/read-rgb-light-test.py +++ /dev/null @@ -1,25 +0,0 @@ -# from https://github.com/rlangoy/uPy_APDS9960 -import machine -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=machine.Pin(12) -scl=machine.Pin(13) -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -apds9960.als.enableSensor() # Enable Light sensor -sleep_ms(25) # Wait for readout to be ready - -#apds9960.powerOn(True) -#print(apds9960.statusRegister()) - -while True: - print(apds9960.als.ambientLightLevel,'', end='') - print(apds9960.als.redLightLevel,'', end='') - print(apds9960.als.greenLightLevel,'', end='') - print(apds9960.als.blueLightLevel) - sleep(.1) diff --git a/src/sensors/gesture/rgb-display-graph.py b/src/sensors/gesture/rgb-display-graph.py deleted file mode 100644 index 7dacb132c..000000000 --- a/src/sensors/gesture/rgb-display-graph.py +++ /dev/null @@ -1,53 +0,0 @@ -# from https://github.com/rlangoy/uPy_APDS9960 -from machine import Pin, I2C -import ssd1306 -from time import sleep,sleep_ms -from APDS9960LITE import APDS9960LITE - -#Init I2C Buss on RP2040 -sda=Pin(12) -scl=Pin(13) -i2c=I2C(0, sda=sda, scl=scl, freq=400000) - -print(i2c) -# create the driver -apds9960=APDS9960LITE(i2c) -apds9960.als.enableSensor() # Enable Light sensor -sleep_ms(25) # Wait for readout to be ready - -# display -WIDTH = 128 -ONE_THIRD_WIDTH = int(WIDTH/3) -HEIGHT = 64 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -def update_display(red, green, blue): - oled.fill(0) - # scale red, green and blue to the height - red = int(red*4) - green = int(green*4) - blue = int(blue*3) - - oled.fill(0) - # rect_fill(x, y, width, height) - oled.fill_rect(0, HEIGHT - red, ONE_THIRD_WIDTH, red, 1) - oled.fill_rect(ONE_THIRD_WIDTH, HEIGHT - green, ONE_THIRD_WIDTH, green, 1) - oled.fill_rect(ONE_THIRD_WIDTH * 2, HEIGHT - blue, ONE_THIRD_WIDTH, blue, 1) - oled.text(str(red), 0, 56, 0) - oled.text(str(green), ONE_THIRD_WIDTH, 56, 0) - oled.text(str(blue), ONE_THIRD_WIDTH*2, 56, 0) - oled.show() - -while True: - # print(apds9960.als.ambientLightLevel,'', end='') - red = apds9960.als.redLightLevel - green = apds9960.als.greenLightLevel - blue = apds9960.als.blueLightLevel - update_display(red, green, blue) - sleep(.05) \ No newline at end of file diff --git a/src/sensors/keypad b/src/sensors/keypad deleted file mode 100644 index b72e8c8f3..000000000 --- a/src/sensors/keypad +++ /dev/null @@ -1,3 +0,0 @@ -# Forum - -https://forum.micropython.org/viewtopic.php?t=2785 \ No newline at end of file diff --git a/src/sensors/mpu9250-hard-reset-test.py b/src/sensors/mpu9250-hard-reset-test.py deleted file mode 100644 index b7b12711f..000000000 --- a/src/sensors/mpu9250-hard-reset-test.py +++ /dev/null @@ -1,23 +0,0 @@ -import utime -from machine import I2C, Pin -from mpu9250 import MPU9250 -from mpu6500 import MPU6500, SF_G, SF_DEG_S - -# micropython.alloc_emergency_exception_buf(100) - -sda=machine.Pin(16) # second from bottom right -scl=machine.Pin(17) # bottom right corner -i2c=I2C(0, sda=sda, scl=scl, freq=400000) - -mpu6500 = MPU6500(i2c, accel_sf=SF_G, gyro_sf=SF_DEG_S) -sensor = MPU9250(i2c, mpu6500=mpu6500) - -print("MPU9250 id: " + hex(sensor.whoami)) - -while True: - print(sensor.acceleration) - print(sensor.gyro) - print(sensor.magnetic) - print(sensor.temperature) - - utime.sleep_ms(1000) \ No newline at end of file diff --git a/src/sensors/mpu9250-test.py b/src/sensors/mpu9250-test.py deleted file mode 100644 index 549401fae..000000000 --- a/src/sensors/mpu9250-test.py +++ /dev/null @@ -1,21 +0,0 @@ -import utime -from machine import I2C, Pin -from mpu9250 import MPU9250 - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=I2C(0, sda=sda, scl=scl, freq=400000) -print("Found I2C device at decimal", i2c.scan()) -print('Expecting [104, 118]') - -sensor = MPU9250(i2c) - -print("MPU9250 id: " + hex(sensor.whoami)) - -while True: - print(sensor.acceleration) - print(sensor.gyro) - print(sensor.magnetic) - print(sensor.temperature) - - utime.sleep_ms(1000) \ No newline at end of file diff --git a/src/sensors/photoresistor-test.py b/src/sensors/photoresistor-test.py deleted file mode 100644 index 22fe8e98b..000000000 --- a/src/sensors/photoresistor-test.py +++ /dev/null @@ -1,8 +0,0 @@ -import machine -import time -photo_pin = machine.ADC(26) - -while True: - val = photo_pin.read_u16() - print(val) - time.sleep(.2) \ No newline at end of file diff --git a/src/sensors/ping/ping-display-chart.py b/src/sensors/ping/ping-display-chart.py deleted file mode 100644 index 3befc36c8..000000000 --- a/src/sensors/ping/ping-display-chart.py +++ /dev/null @@ -1,64 +0,0 @@ -# display a plot of ping distance vertical and time across the x-axis -# scroll as we get more values -from machine import Pin -from utime import sleep -import hcsr04 -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -TRIGGER_PIN = 14 # Connect the white Grove connector wire next to the 5volt on the ping sensor -ECHO_PIN = 15 # Connect the yellow Grove connector wire next to the GND on the ping sensor -MAX_VALID = 64 - -ping_sensor = hcsr04.HCSR04(TRIGGER_PIN, ECHO_PIN) - -x = 0 -def update_display(distance): - global x - # print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - oled.show() - -def avg_dist(num): - total_val = 0 - for i in range(0,num): - total_val += ping_sensor.distance_cm() - sleep(.01) - return round(total_val/num, 3) - -while True: - distance_cm = avg_dist(10) - print(distance_cm) - if distance_cm < MAX_VALID: - update_display(distance_cm) - else: - print('out of range:', distance_cm) - sleep(.01) diff --git a/src/sensors/ping/ping-sensor-led-test.py b/src/sensors/ping/ping-sensor-led-test.py deleted file mode 100644 index 55ad791b8..000000000 --- a/src/sensors/ping/ping-sensor-led-test.py +++ /dev/null @@ -1,64 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -from neopixel import NeoPixel -from utime import sleep, sleep_us, ticks_us - -NUMBER_PIXELS = 11 -LED_PIN = 0 -red = (50, 0, 0) -green = (0, 255, 0) - -strip = NeoPixel(machine.Pin(LED_PIN), NUMBER_PIXELS) -TRIGGER_PIN = 16 # With USB on the top, this pin is the bottom left corner -ECHO_PIN = 17 # One up from bottom left corner - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - sleep_us(2) # Wait 2 microseconds low - trigger.high() - sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = ticks_us() - while echo.value() == 1: - signalon = ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -def avg_ping(samples): - total = 0 - for i in range(0, samples+1): - total += ping() - return round(total / samples, 2) - -while True: - dist = avg_ping(5) - # handle the no signal case - if dist > 100: - print("No signal") - for i in range(0, NUMBER_PIXELS): - if i == 0: - strip[i] = red - else: - strip[i] = (0,0,0) - strip.write() - else: - index = round(dist/5) # 5 cm per pixel - if index > NUMBER_PIXELS: - index = NUMBER_PIXELS-1 - print("Distance:", dist, " cm Index:", index) - for i in range(0, NUMBER_PIXELS): - if i < index: - strip[i] = green - else: - strip[i] = (0,0,0) - strip.write() - sleep(.05) diff --git a/src/sensors/ping/ping-test.py b/src/sensors/ping/ping-test.py deleted file mode 100644 index 9d7b31bd4..000000000 --- a/src/sensors/ping/ping-test.py +++ /dev/null @@ -1,33 +0,0 @@ -# Sample code to test HC-SR04 Ultrasonice Ping Sensor -# Connect GND to any GND pin on the Pico -# Connnect VCC to VBUS or 5 Volt power - -from machine import Pin, Timer -import utime - -TRIGGER_PIN = 26 # yellow -ECHO_PIN = 6 # white - -# Init HC-SR04 pins -trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor -echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back - -def ping(): - trigger.low() - utime.sleep_us(2) # Wait 2 microseconds low - trigger.high() - utime.sleep_us(5) # Stay high for 5 miroseconds - trigger.low() - while echo.value() == 0: - signaloff = utime.ticks_us() - while echo.value() == 1: - signalon = utime.ticks_us() - timepassed = signalon - signaloff - distance = (timepassed * 0.0343) / 2 - return distance - -counter = 1 -while True: - print(counter, "Distance:", ping(), " cm") - utime.sleep(.25) - counter += 1 \ No newline at end of file diff --git a/src/sensors/pot-display-blink-speed.py b/src/sensors/pot-display-blink-speed.py deleted file mode 100644 index c2a4e608e..000000000 --- a/src/sensors/pot-display-blink-speed.py +++ /dev/null @@ -1,46 +0,0 @@ -from machine import ADC, Pin -from utime import sleep -from ssd1306 import SSD1306_I2C - -WIDTH = 128 # oled display width -HEIGHT = 32 # oled display height - -sda=machine.Pin(16) # bus 0 data -scl=machine.Pin(17) # bus 0 clock - -# should be 400000, 1000 prints some text -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -oled = SSD1306_I2C(WIDTH, HEIGHT, i2c) - -# this is the built-in LED on the Pico -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -def update_display(pot_value, delay): - oled.fill(0) - oled.rect(0, 0, WIDTH, HEIGHT, 1) - oled.fill_rect(1, 1, pot_value, HEIGHT - 1, 1) - oled.text(str(pot_value), 1, 1, 0) - oled.text(str(delay), 1, 10, 1) - oled.text(str(delay), 1, 20, 0) - oled.show() - -# repeat forever -while True: - pot_value = pot.read_u16() >> 9 # read the value from the pot - delay = round(pot_value/128 * MAX_DELAY, 3) - update_display(pot_value, delay) - print("delay:", delay) - if delay > 0: - print("frequency (toggles per second):", 1/delay) - led.high() # turn on the LED - sleep(delay) # leave it on for 1/2 second - led.low() # Turn off the LED - sleep(delay) # leave it off for 1/2 second diff --git a/src/sensors/pot-display.py b/src/sensors/pot-display.py deleted file mode 100644 index e710d578f..000000000 --- a/src/sensors/pot-display.py +++ /dev/null @@ -1,103 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 -import framebuf - -# this is the built-in LED on the Pico -led = Pin(25, Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -fb = framebuf.FrameBuffer(bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), - 64, 64, framebuf.MONO_VLSB) - -def update_display(counter, pot_value, delay): - oled.fill(0) - oled.text('CoderDojo', 0, 0) - oled.fill_rect(0, 10, int((256 - pot_value)/2), 20, 1) - - oled.text('P:', 0, 34) - oled.text(str(pot_value), 20, 34) - - oled.text('D:', 0, 44) - oled.text(str(round(delay, 3)), 20, 44) - - oled.text('C:', 0, 54) - oled.text(str(counter), 20, 54) - oled.show() - -# return the 8 most significant bits of the ADC -def read_pot_u8(): - return pot.read_u16() >> 8 - -def splash_screen(counter, pot_value, delay): - oled.fill(0) - oled.blit(fb, 64, 0) - oled.text('CoderDojo', 0, 0) - oled.text('Robots', 0, 10) - oled.text('& Sound ', 0, 20) - - oled.text('P:', 0, 34) - oled.text(str(pot_value), 20, 34) - - oled.text('D:', 0, 44) - oled.text(str(round(delay, 3)), 20, 44) - - oled.text('C:', 0, 54) - oled.text(str(counter), 20, 54) - oled.show() - -counter = 0 -current_pot = read_pot_u8() -# display spash until we detect a new pot value -while current_pot == read_pot_u8(): - splash_screen(counter, current_pot, delay) - counter += 1 - -# repeat forever -while True: - pot_value = read_pot_u8() # read the value from the pot - print("pot_value:", delay) - # max of 16 bit value is 65025 but max of 2 to 12th is 4096 - # 12 bits is 4096 (shift 4) - # 10 bits is 1024 (shift 6) - # 8 is 256 (shift 8) - delay = pot_value/256 * MAX_DELAY - print("delay:", delay) - #if delay > 0: - # print("frequency (toggles per second):", 1/delay) - update_display(counter, pot_value, delay) - sleep(.05) - counter += 1 \ No newline at end of file diff --git a/src/sensors/pot/display-pot-on-oled-v2.py b/src/sensors/pot/display-pot-on-oled-v2.py deleted file mode 100644 index c0f5bcdb0..000000000 --- a/src/sensors/pot/display-pot-on-oled-v2.py +++ /dev/null @@ -1,60 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -# global variables - -# how often to read the pot and update the display 20 times per second -delay = .05 - -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) - - - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def update_display(counter, pot_value, high_bits): - oled.fill(0) - oled.text('CoderDojo PotLab', 0, 0) - oled.fill_rect(0, 10, high_bits, 20, 1) - - oled.text('ADC Value:', 0, 35) - oled.text(str(pot_value), 80, 35) - - oled.text('Display Val:', 0, 45) - oled.text(str(high_bits), 95, 45) - - oled.text('Counter:', 0, 54) - oled.text(str(counter), 65, 54) - oled.show() - -# return the 8 most significant bits of the ADC -def read_pot_u8(): - return pot.read_u16() >> 8 - - -counter = 0 -while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - print(pot_value) - # print("pot_value:", delay) - high_bits = pot_value >> 9 - # print("delay:", high_bits) - update_display(counter, pot_value, high_bits) - led.toggle() - sleep(delay) - counter += 1 \ No newline at end of file diff --git a/src/sensors/pot/display-pot-on-oled.py b/src/sensors/pot/display-pot-on-oled.py deleted file mode 100644 index 9b2812369..000000000 --- a/src/sensors/pot/display-pot-on-oled.py +++ /dev/null @@ -1,61 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -WIDTH = 128 -HEIGHT = 64 -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) - -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def update_display(counter, pot_value, high_bits): - oled.fill(0) - oled.text('CoderDojo PotLab', 0, 0) - oled.fill_rect(0, 10, high_bits, 20, 1) - - oled.text('ADC Value:', 0, 35) - oled.text(str(pot_value), 80, 35) - - oled.text('Display Val:', 0, 45) - oled.text(str(high_bits), 95, 45) - - oled.text('Counter:', 0, 54) - oled.text(str(counter), 65, 54) - oled.show() - -# return the 8 most significant bits of the ADC -def read_pot_u8(): - return pot.read_u16() >> 8 - - -counter = 0 -while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - print(pot_value) - # print("pot_value:", delay) - high_bits = pot_value >> 9 - # print("delay:", high_bits) - update_display(counter, pot_value, high_bits) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/sensors/pot/display-pot-value.py b/src/sensors/pot/display-pot-value.py deleted file mode 100644 index 8714e4242..000000000 --- a/src/sensors/pot/display-pot-value.py +++ /dev/null @@ -1,62 +0,0 @@ -from machine import Pin, Timer, PWM, ADC -from utime import sleep -import ssd1306 - -# this is the built-in LED on the Pico -led = Pin('LED', Pin.OUT) - -# ADC0 is GPIO 26. Connect to row 10 the right side. -pot = ADC(26) - -MAX_DELAY = .5 # seconds - -# global variables -delay = 0 - -WIDTH = 128 -HEIGHT = 64 -WIDTH = 128 -HEIGHT = 64 -SCK=machine.Pin(2) -SDL=machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) -spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL) -print(spi) - - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) -oled.poweron() - -def update_display(counter, pot_value, high_bits): - oled.fill(0) - oled.text('CoderDojo PotLab', 0, 0) - oled.fill_rect(0, 10, high_bits, 20, 1) - - oled.text('ADC Value:', 0, 35) - oled.text(str(pot_value), 80, 35) - - oled.text('Display Val:', 0, 45) - oled.text(str(high_bits), 95, 45) - - oled.text('Counter:', 0, 54) - oled.text(str(counter), 65, 54) - oled.show() - -# return the 8 most significant bits of the ADC -def read_pot_u8(): - return pot.read_u16() >> 8 - - -counter = 0 -while True: - pot_value = pot.read_u16() # read the 8 bit value from the pot - print(pot_value) - # print("pot_value:", delay) - high_bits = pot_value >> 9 - # print("delay:", high_bits) - update_display(counter, pot_value, high_bits) - led.toggle() - sleep(.1) - counter += 1 \ No newline at end of file diff --git a/src/sensors/read-temp-pressure.py b/src/sensors/read-temp-pressure.py deleted file mode 100644 index 5387d3b58..000000000 --- a/src/sensors/read-temp-pressure.py +++ /dev/null @@ -1,23 +0,0 @@ -from machine import I2C -import bme280 -import time - -sda=machine.Pin(16) -scl=machine.Pin(17) -i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000) -print(i2c.scan()) - -while True: - bme = BME280.BME280(i2c=i2c) - temp = bme.temperature - hum = bme.humidity - pres = bme.pressure - # uncomment for temperature in Fahrenheit - #temp = (bme.read_temperature()/100) * (9/5) + 32 - #temp = str(round(temp, 2)) + 'F' - print('Temperature: ', temp) - print('Humidity: ', hum) - print('Pressure: ', pres) - - sleep(5) - diff --git a/src/sensors/rotary/draw-eye-scanner.py b/src/sensors/rotary/draw-eye-scanner.py deleted file mode 100644 index 4d5ac9366..000000000 --- a/src/sensors/rotary/draw-eye-scanner.py +++ /dev/null @@ -1,101 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# make an fb for an eye -eye = bytearray(QUARTER_WIDTH * 24) -eyeBuf = framebuf.FrameBuffer(eye, 51, 31, framebuf.MONO_HLSB) -fill = 1 # 0 is no fill center -x = 25 -y = 15 -width = 25 -height = 15 -# draw background eye in white -eyeBuf.ellipse(x, y, width, height, ON, fill) -# draw puple in black -#eyeBuf.ellipse(x, y, 5, 5, OFF, fill) - -eye_dist_from_top = 7 -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement - -while True: - for i in range(-phm, phm): - oled.fill(0) - draw_face_grid() - start = ticks_us() - # left eye - oled.blit(eyeBuf, 7, eye_dist_from_top) - oled.ellipse(32+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - # right eye - oled.blit(eyeBuf, 70, eye_dist_from_top) - oled.ellipse(94+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - end = ticks_us() - drawTime = end - start - oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - sleep(.05) - for i in range(phm, -phm, -1): - oled.fill(0) - draw_face_grid() - start = ticks_us() - # left eye - oled.blit(eyeBuf, 7, eye_dist_from_top) - oled.ellipse(32+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - # right eye - oled.blit(eyeBuf, 70, eye_dist_from_top) - oled.ellipse(94+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - end = ticks_us() - drawTime = end - start - oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - sleep(.05) diff --git a/src/sensors/rotary/draw-polygone.py b/src/sensors/rotary/draw-polygone.py deleted file mode 100644 index e16331562..000000000 --- a/src/sensors/rotary/draw-polygone.py +++ /dev/null @@ -1,80 +0,0 @@ -''' -Test of the MicroPython framebuf poly drawing function - - from array import array - - my_array = array('h', [60,10, 50,60, 40,30]) - display.poly(0,0, my_array, ON, FILL) - -''' - -from machine import Pin -from utime import sleep, ticks_us -from array import array -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - - -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement -eye_dist_from_top = 21 -eyeWidth = 27 -eyeHeight = 10 -mouth_vpos = 45 -mouth_width = 40 - -def draw_face(eye_direction): - oled.fill(0) - # draw_face_grid() - start = ticks_us() - # left eye - my_array = array('h', [60,10, 50,60, 40,30]) - oled.poly(0,0, my_array, ON, FILL) - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - end = ticks_us() - drawTime = end - start - # oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - -while True: - for i in range(-phm, phm): - draw_face(i) - sleep(.02) - for i in range(phm, -phm, -1): - draw_face(i) - sleep(.02) - diff --git a/src/sensors/rotary/ellipse-01.py b/src/sensors/rotary/ellipse-01.py deleted file mode 100644 index 44afa07e3..000000000 --- a/src/sensors/rotary/ellipse-01.py +++ /dev/null @@ -1,62 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -HALF_WIDTH = WIDTH >> 1 -QUEATER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# make an fb for an eye -eye = bytearray(QUEATER_WIDTH * 24) -eyeBuf = framebuf.FrameBuffer(eye, 32, 24, framebuf.MONO_HLSB) -fill = 1 -x = 16 -y = 12 -width = 10 -height = 8 -eyeBuf.ellipse(x, y, width, height, 1, fill) - -eye_dist_from_top = 20 -# copy onto display - -for i in range(0, 1): - oled.fill(0) - start = ticks_us() - # left eye - oled.blit(eyeBuf, 32, eye_dist_from_top) - # right eye - oled.blit(eyeBuf, 96, eye_dist_from_top) - end = ticks_us() - drawTime = end - start - oled.text(str(drawTime), i, 54) - oled.show() - diff --git a/src/sensors/rotary/ellipse-02.py b/src/sensors/rotary/ellipse-02.py deleted file mode 100644 index 4d5ac9366..000000000 --- a/src/sensors/rotary/ellipse-02.py +++ /dev/null @@ -1,101 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -# make an fb for an eye -eye = bytearray(QUARTER_WIDTH * 24) -eyeBuf = framebuf.FrameBuffer(eye, 51, 31, framebuf.MONO_HLSB) -fill = 1 # 0 is no fill center -x = 25 -y = 15 -width = 25 -height = 15 -# draw background eye in white -eyeBuf.ellipse(x, y, width, height, ON, fill) -# draw puple in black -#eyeBuf.ellipse(x, y, 5, 5, OFF, fill) - -eye_dist_from_top = 7 -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement - -while True: - for i in range(-phm, phm): - oled.fill(0) - draw_face_grid() - start = ticks_us() - # left eye - oled.blit(eyeBuf, 7, eye_dist_from_top) - oled.ellipse(32+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - # right eye - oled.blit(eyeBuf, 70, eye_dist_from_top) - oled.ellipse(94+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - end = ticks_us() - drawTime = end - start - oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - sleep(.05) - for i in range(phm, -phm, -1): - oled.fill(0) - draw_face_grid() - start = ticks_us() - # left eye - oled.blit(eyeBuf, 7, eye_dist_from_top) - oled.ellipse(32+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - # right eye - oled.blit(eyeBuf, 70, eye_dist_from_top) - oled.ellipse(94+i, eye_dist_from_top + 14, 5, 5, OFF, fill) - end = ticks_us() - drawTime = end - start - oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - sleep(.05) diff --git a/src/sensors/rotary/eye-scanner-v2.py b/src/sensors/rotary/eye-scanner-v2.py deleted file mode 100644 index 8ebc9f25d..000000000 --- a/src/sensors/rotary/eye-scanner-v2.py +++ /dev/null @@ -1,91 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - - -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement -eye_dist_from_top = 21 -eyeWidth = 27 -eyeHeight = 10 -mouth_vpos = 45 -mouth_width = 40 - -def draw_face(eye_direction): - oled.fill(0) - # draw_face_grid() - start = ticks_us() - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32+i, eye_dist_from_top, 5, 5, OFF, FILL) - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94+i, eye_dist_from_top, 5, 5, OFF, FILL) - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - end = ticks_us() - drawTime = end - start - # oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - -while True: - for i in range(-phm, phm): - draw_face(i) - sleep(.02) - for i in range(phm, -phm, -1): - draw_face(i) - sleep(.02) - diff --git a/src/sensors/rotary/eye-scanner.py b/src/sensors/rotary/eye-scanner.py deleted file mode 100644 index 8ebc9f25d..000000000 --- a/src/sensors/rotary/eye-scanner.py +++ /dev/null @@ -1,91 +0,0 @@ -''' - -FrameBuffer.ellipse(x, y, xr, yr, c) - -FrameBuffer.ellipse(x, y, xr, yr, c[, f, m])¶ -Draw an ellipse at the given location. Radii xr and yr define the geometry; equal values cause -a circle to be drawn. The c parameter defines the color. - -The optional f parameter can be set to True to fill the ellipse. Otherwise just a one -pixel outline is drawn. - -The optional m parameter enables drawing to be restricted to certain quadrants of the ellipse. -The LS four bits determine which quadrants are to be drawn, with bit 0 specifying Q1, b1 Q2, b2 Q3 -and b3 Q4. -Quadrants are numbered counterclockwise with Q1 being top right. -''' - -from machine import Pin -from utime import sleep, ticks_us -from math import sqrt -import framebuf -import ssd1306 - -WIDTH = 128 -# bit shifting only works when the numbers are a power of 2 -HALF_WIDTH = WIDTH >> 1 -QUARTER_WIDTH = HALF_WIDTH >> 1 -HEIGHT = 64 -HALF_HEIGHT = HEIGHT >> 1 -QUARTER_HEIGHT = HALF_HEIGHT >> 1 -ONE_THIRD_HEIGHT = int(HEIGHT/3) - -# draw readability -ON = 1 -OFF = 0 -NO_FILL = 0 -FILL = 1 - - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - - -# copy onto display - -bottom_row_text_vpos = 57 - -def draw_face_grid(): - oled.vline(QUARTER_WIDTH, 0, HEIGHT, 1) # x, y, len, color - oled.vline(QUARTER_WIDTH*3, 0, HEIGHT, 1) - oled.hline(0, ONE_THIRD_HEIGHT, WIDTH, 1) - -phm = 18 # puple horizontal movement -eye_dist_from_top = 21 -eyeWidth = 27 -eyeHeight = 10 -mouth_vpos = 45 -mouth_width = 40 - -def draw_face(eye_direction): - oled.fill(0) - # draw_face_grid() - start = ticks_us() - # left eye - oled.ellipse(32, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(32+i, eye_dist_from_top, 5, 5, OFF, FILL) - # right eye - oled.ellipse(94, eye_dist_from_top, eyeWidth, eyeHeight, ON, FILL) - oled.ellipse(94+i, eye_dist_from_top, 5, 5, OFF, FILL) - # draw mouth - # draw bottom half by doing a bitwise and of 8 and 4 - oled.ellipse(HALF_WIDTH, mouth_vpos, mouth_width, 10, ON, NO_FILL, 12) - end = ticks_us() - drawTime = end - start - # oled.text(str(drawTime), 0, bottom_row_text_vpos) - oled.show() - -while True: - for i in range(-phm, phm): - draw_face(i) - sleep(.02) - for i in range(phm, -phm, -1): - draw_face(i) - sleep(.02) - diff --git a/src/sensors/rotary/neopixel-five-modes.py b/src/sensors/rotary/neopixel-five-modes.py deleted file mode 100644 index 2fb366400..000000000 --- a/src/sensors/rotary/neopixel-five-modes.py +++ /dev/null @@ -1,115 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -mode_names = ['dot', 'hole', 'compare', 'chase', 'rainbow'] - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 5 - print('mode=', mode, mode_names[mode]) -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) - - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('PRESS') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('RELEASE') - color_index += 1 - color_index = color_index % (color_count - 1) - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -color_index = 0 -color = red -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - elif mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 2: - for i in range(0, NUMBER_PIXELS): - if i > val: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 3: - for i in range(0, NUMBER_PIXELS): - if (i-val) % 3: - strip[i] = (0,0,0) - else: - strip[i] = color - elif mode == 4: - # if the val + offset is larger than the number of pixels we need to do a modulo - strip[val % (NUMBER_PIXELS)] = violet - strip[(val+1) % (NUMBER_PIXELS)] = indigo - strip[(val+2) % (NUMBER_PIXELS)] = blue - strip[(val+3) % (NUMBER_PIXELS)] = green - strip[(val+4) % (NUMBER_PIXELS)] = yellow - strip[(val+5) % (NUMBER_PIXELS)] = orange - strip[(val+6) % (NUMBER_PIXELS)] = red - # turn off the rest - strip[(val+7) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+8) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+9) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+10) % (NUMBER_PIXELS)] = (0,0,0) - strip[(val+11) % (NUMBER_PIXELS)] = (0,0,0) - strip.write() - # print('color index', color_index) - color = colors[color_index] - \ No newline at end of file diff --git a/src/sensors/rotary/poly.py b/src/sensors/rotary/poly.py deleted file mode 100644 index 37dac14e2..000000000 --- a/src/sensors/rotary/poly.py +++ /dev/null @@ -1,19 +0,0 @@ -from machine import Pin -from array import array -import ssd1306 - -clock=Pin(2) #SCL -data=Pin(3) #SDA -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS) - -oled.fill(0) -my_array = array('h', [30,10, 100,20, 50,60]) -oled.poly(0,0, my_array, 1, 1) -oled.show() - - diff --git a/src/sensors/rotary/rotary-neopixel-box.py b/src/sensors/rotary/rotary-neopixel-box.py deleted file mode 100644 index f41357ca2..000000000 --- a/src/sensors/rotary/rotary-neopixel-box.py +++ /dev/null @@ -1,84 +0,0 @@ -from machine import Pin -from rotary import Rotary -from utime import sleep, ticks_ms -from neopixel import NeoPixel - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 - -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 15 -ENCODER_B = 14 -SWITCH = 17 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -button_pin = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -mode = 0 # mode to display -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button -def button_pressed_handler(pin): - global button_presses, last_time, mode - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - mode +=1 - last_time = new_time - # make mode 0 or 1 - mode = mode % 2 -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -val = 0 # value of the LED strip index set by the rotary know - -red = (255, 0, 0) -orange = (140, 60, 0) -yellow = (255, 255, 0) -green = (0, 255, 0) -blue = (0, 0, 255) -cyan = (0, 255, 255) -indigo = (75, 0, 130) -violet = (138, 43, 226) -white = (128, 128, 128) -colors = (red, orange, yellow, green, blue, cyan, indigo, violet) -color_count = len(colors) - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val, button_press, color_index - if change == Rotary.ROT_CW: - val = val + 1 - elif change == Rotary.ROT_CCW: - val = val - 1 - elif change == Rotary.SW_PRESS: - print('PRESS') - # button_press = 1 - elif change == Rotary.SW_RELEASE: - print('RELEASE') - color_index += 1 - color_index = color_index % (color_count - 1) - val = val % NUMBER_PIXELS - print(val) - -rotary.add_handler(rotary_changed) - -color_index = 0 -color = red -while True: - if mode == 0: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = color - else: - strip[i] = (0,0,0) - if mode == 1: - for i in range(0, NUMBER_PIXELS): - if i == val: - strip[i] = (0,0,0) - else: - strip[i] = color - strip.write() - # print('color index', color_index) - color = colors[color_index] - \ No newline at end of file diff --git a/src/sensors/rotary/rotary-neopixel-ring.py b/src/sensors/rotary/rotary-neopixel-ring.py deleted file mode 100644 index a2c1296d4..000000000 --- a/src/sensors/rotary/rotary-neopixel-ring.py +++ /dev/null @@ -1,118 +0,0 @@ -from machine import Pin -from rotary import Rotary -from neopixel import NeoPixel -from utime import sleep, ticks_ms - -NEOPIXEL_PIN = 22 -NUMBER_PIXELS = 24 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -# GPIO Pins 16 and 17 are for the encoder pins. 22 is the button press switch. -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 16 -ENCODER_B = 17 -SWITCH = 18 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) - -brightness = 255 -red = (brightness, 0, 0) -green = (0, brightness, 0) -blue = (0, 0, brightness) - -# connect to one end of the button to this pin and the other to 3.3V -BUTTON_PIN = 15 - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN) - -BLACK = (0, 0, 0) -RED = (255, 0, 0) -YELLOW = (255, 150, 0) -GREEN = (0, 255, 0) -CYAN = (0, 255, 255) -BLUE = (0, 0, 255) -PURPLE = (180, 0, 255) -WHITE = (255, 255, 255) -color_list = (RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE) -current_color = 0 -color_count = len(color_list) - -last_time = 0 -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global current_color, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 100: - current_color += 1 - current_color = current_color % color_count - draw_bar(val, width, color_list[current_color]) - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - - -# value of the rotery encoder -val = 0 -# width of the color band -width = 5 - -def rotary_changed(change): - global val, width - if change == Rotary.ROT_CW: - val = val + 1 - val = val % NUMBER_PIXELS - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - val = val % NUMBER_PIXELS - print(val) - elif change == Rotary.SW_PRESS: - width += 1 - width = width % 12 - draw_bar(val, width, color_list[current_color]) - print('new width:', width) - elif change == Rotary.SW_RELEASE: - pass - # print('RELEASE') - -rotary.add_handler(rotary_changed) - -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -def draw_bar(start, width, color): - global strip - if start > 0: - strip[start % NUMBER_PIXELS] = (0,0,0) - end = start + width + 1 - for i in range(start+1, end): - strip[i % NUMBER_PIXELS] = color - if end < NUMBER_PIXELS: - strip[end % NUMBER_PIXELS] = (0,0,0) - strip.write() - - -current_val = 0 -draw_bar(0, width, color_list[current_color], ) -while True: - # draw only on a change - if val != current_val: - print('drawing at', val, 'width=', width) - draw_bar(val, width, color_list[current_color]) - current_val = val diff --git a/src/sensors/rotary/rotary-test.py b/src/sensors/rotary/rotary-test.py deleted file mode 100644 index 011f7c88d..000000000 --- a/src/sensors/rotary/rotary-test.py +++ /dev/null @@ -1,29 +0,0 @@ -from machine import Pin -from rotary import Rotary -from time import sleep - -# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch. -ENCODER_A = 14 -ENCODER_B = 15 -SWITCH = 18 -rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH) -val = 0 - -# this function is called whenever the rotory is changed -def rotary_changed(change): - global val - if change == Rotary.ROT_CW: - val = val + 1 - print(val) - elif change == Rotary.ROT_CCW: - val = val - 1 - print(val) - elif change == Rotary.SW_PRESS: - print('PRESS') - elif change == Rotary.SW_RELEASE: - print('RELEASE') - -rotary.add_handler(rotary_changed) - -while True: - sleep(0.1) \ No newline at end of file diff --git a/src/sensors/rotary/rotary_irq_rp2.py b/src/sensors/rotary/rotary_irq_rp2.py deleted file mode 100644 index 8390e3bbe..000000000 --- a/src/sensors/rotary/rotary_irq_rp2.py +++ /dev/null @@ -1,68 +0,0 @@ -# The MIT License (MIT) -# Copyright (c) 2020 Mike Teachman -# Copyright (c) 2021 Eric Moyer -# https://opensource.org/licenses/MIT - -# Platform-specific MicroPython code for the rotary encoder module -# Raspberry Pi Pico implementation - -# Documentation: -# https://github.com/MikeTeachman/micropython-rotary - -from machine import Pin -from rotary import Rotary - -IRQ_RISING_FALLING = Pin.IRQ_RISING | Pin.IRQ_FALLING - - -class RotaryIRQ(Rotary): - def __init__( - self, - pin_num_clk, - pin_num_dt, - min_val=0, - max_val=10, - reverse=False, - range_mode=Rotary.RANGE_UNBOUNDED, - pull_up=False, - half_step=False, - ): - super().__init__(min_val, max_val, reverse, range_mode, half_step) - - if pull_up: - self._pin_clk = Pin(pin_num_clk, Pin.IN, Pin.PULL_UP) - self._pin_dt = Pin(pin_num_dt, Pin.IN, Pin.PULL_UP) - else: - self._pin_clk = Pin(pin_num_clk, Pin.IN) - self._pin_dt = Pin(pin_num_dt, Pin.IN) - - self._hal_enable_irq() - - def _enable_clk_irq(self): - self._pin_clk.irq(self._process_rotary_pins, IRQ_RISING_FALLING) - - def _enable_dt_irq(self): - self._pin_dt.irq(self._process_rotary_pins, IRQ_RISING_FALLING) - - def _disable_clk_irq(self): - self._pin_clk.irq(None, 0) - - def _disable_dt_irq(self): - self._pin_dt.irq(None, 0) - - def _hal_get_clk_value(self): - return self._pin_clk.value() - - def _hal_get_dt_value(self): - return self._pin_dt.value() - - def _hal_enable_irq(self): - self._enable_clk_irq() - self._enable_dt_irq() - - def _hal_disable_irq(self): - self._disable_clk_irq() - self._disable_dt_irq() - - def _hal_close(self): - self._hal_disable_irq() diff --git a/src/sensors/time-of-flight/VL53L0X-display-test.py b/src/sensors/time-of-flight/VL53L0X-display-test.py deleted file mode 100644 index b340aa042..000000000 --- a/src/sensors/time-of-flight/VL53L0X-display-test.py +++ /dev/null @@ -1,32 +0,0 @@ -# VL53L0X Display Test - -import time -from machine import Pin -from machine import I2C -import VL53L0X -import sh1106 - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -display = sh1106.SH1106_I2C(128, 64, i2c, Pin(16), 0x3c) -display.rotate(1) - - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 18) - -#tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 14) - -while True: -# Start ranging - tof.start() - display.fill(0) - display.text('Distance:', 0, 0, 1) - display.text(str(tof.read()), 20, 20, 1) - display.show() - tof.stop() - \ No newline at end of file diff --git a/src/sensors/time-of-flight/distance-to-pitch-display.py b/src/sensors/time-of-flight/distance-to-pitch-display.py deleted file mode 100644 index b29babac5..000000000 --- a/src/sensors/time-of-flight/distance-to-pitch-display.py +++ /dev/null @@ -1,71 +0,0 @@ -# distance-to-pitch-display.py -# As you move your hand closer and further away from a Time-of-Flight distance sensor -# you change the pitch of the sound on the speaker -from utime import sleep -from machine import Pin, PWM -from machine import I2C -import VL53L0X -import ssd1306 - -WIDTH = 128 -HEIGHT = 64 -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -SDA_PIN = 16 -SCL_PIN = 17 -SPEAKER_PIN = 18 -MAX_DIST = 500 # max raw reading that is valid - -sda=machine.Pin(SDA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(SCL_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -speaker = PWM(Pin(SPEAKER_PIN)) -# speaker.duty_u16(1000) # 50% on and off - -# Create a VL53L0X object and start reading -TOF_ZERO_VALUE = 20 -tof = VL53L0X.VL53L0X(i2c) -# the minimum value for zero distance is about 50 -tof.start() - -def main(): - while True: - # Start ranging - distance = tof.read() - TOF_ZERO_VALUE - if distance > MAX_DIST: - print('No Signal') - speaker.duty_u16(0) - oled.fill(0) - oled.text(str(distance), 0, 0, 1) - oled.text("No Signal", 0, 10, 1) - oled.show() - - else: - # change these numbers to get different sounds - freq = distance * 11 - if freq < 0: - freq = 0 - print(distance, freq) - sleep(.1) - speaker.duty_u16(1000) - speaker.freq(freq) - oled.fill(0) - oled.text(str(distance), 0, 0, 1) - oled.text(str(freq), 0, 10, 1) - oled.show() - -try: - main() -except KeyboardInterrupt: - print("Keyboard Interrupt. Shutting Down Speaker PWM") -finally: - # Optional cleanup code - print('turning off sound') - speaker.duty_u16(0) - tof.stop() \ No newline at end of file diff --git a/src/sensors/time-of-flight/distance-to-pitch.py b/src/sensors/time-of-flight/distance-to-pitch.py deleted file mode 100644 index b29a5ed40..000000000 --- a/src/sensors/time-of-flight/distance-to-pitch.py +++ /dev/null @@ -1,45 +0,0 @@ -from utime import sleep -from machine import Pin, PWM -from machine import I2C -import VL53L0X - -SDA_PIN = 16 -SCL_PIN = 17 -SPEAKER_PIN = 18 -MAX_DIST = 500 # max raw reading that is valid - -sda=machine.Pin(SDA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(SCL_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -speaker = PWM(Pin(SPEAKER_PIN)) -# speaker.duty_u16(1000) # 50% on and off - -# Create a VL53L0X object and start reading -tof = VL53L0X.VL53L0X(i2c) -# the minimum value for zero distance is about 50 -tof.start() - -def main(): - while True: - # Start ranging - distance = tof.read() - if distance > MAX_DIST: - print('No Signal') - speaker.duty_u16(0) - else: - # change these numbers to get different sounds - freq = distance * 9 - 250 - print(distance, freq) - sleep(.1) - speaker.duty_u16(1000) - speaker.freq(freq) - -try: - main() -except KeyboardInterrupt: - print("Keyboard Interrupt. Shutting Down Speaker PWM") -finally: - # Optional cleanup code - print('turning off sound') - speaker.duty_u16(0) - tof.stop() \ No newline at end of file diff --git a/src/sensors/time-of-flight/draw-tof-chart-v2.py b/src/sensors/time-of-flight/draw-tof-chart-v2.py deleted file mode 100644 index 070b823c8..000000000 --- a/src/sensors/time-of-flight/draw-tof-chart-v2.py +++ /dev/null @@ -1,85 +0,0 @@ -from machine import Pin,PWM -import VL53L0X -from time import sleep -import ssd1306 -from neopixel import NeoPixel - -# OLED Display dimentions -HEIGHT = 64 -WIDTH = 128 -MAX_TOF_VALUE = 1200 - -SCL = machine.Pin(2) -SDA = machine.Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=SCL, mosi=SDA) -print(spi) - -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print('i2c:', i2c) - -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -x=0 -def update_display(distance): - global x - print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - oled.show() - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# a list of our prior distance measurements for graphing mode -distances=[] - -valid_distance = 0 -mode = 0 -# loop forever -def main(): - global mode, valid_distance - while True: - distance = get_distance() - if distance < MAX_TOF_VALUE: - update_display(distance) - sleep(.05) - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Chart Time of Flight') - -try: - main() -except KeyboardInterrupt: - print('Got interupt') -finally: - # Optional cleanup code - print('Powering down sound') - tof.stop() diff --git a/src/sensors/time-of-flight/draw-tof-chart.py b/src/sensors/time-of-flight/draw-tof-chart.py deleted file mode 100644 index 637a05c95..000000000 --- a/src/sensors/time-of-flight/draw-tof-chart.py +++ /dev/null @@ -1,156 +0,0 @@ -from machine import Pin,PWM -import VL53L0X -from time import sleep -import ssd1306 -from neopixel import NeoPixel - -# OLED Display dimentions -HEIGHT = 64 -WIDTH = 128 -clock=Pin(2) -data=Pin(3) -RES = machine.Pin(4) -DC = machine.Pin(5) -CS = machine.Pin(6) - -spi=machine.SPI(0, sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=Pin(26) # Grove connector 6 -scl=Pin(27) # Colors on ToF sensor are RBYW (red, black, yello white) -i2c_tof=machine.I2C(1, sda=sda, scl=scl, freq=400000) -MAX_DIST = 365 -# print(i2c_tof) - -# the two on-board NeoPixels -NUMBER_PIXELS = 2 -NEOPIXEL_PIN = 18 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) -red = (255, 0, 0) -lightPink = (10,0,0) -orange = (255, 60, 0) # Gamma corrected from G=128 to be less like yellow -yellow = (255, 150, 0) -green = (0, 255, 0) -lightGreen = (0, 25, 0) -blue = (0, 0, 255) -indigo = (75, 0, 130) # purple? -purple = (75, 0, 130) -violet = (138, 43, 226) # mostly pink -cyan = (0, 255, 255) -lightgreen = (100, 255, 100) -white = (128, 128, 128) # not too bright -pink = (255, 128, 128) -color_names = ('red', 'orange', 'yellow', 'green', 'light green', 'blue', 'indigo', 'violet', 'cyan', 'lightgreen', 'white') -num_colors = len(color_names) -colors = (red, orange, yellow, green, lightGreen, blue, indigo, violet, cyan, lightgreen, white, pink) - -# The Piezo Buzzer is on GP22 -buzzer=PWM(Pin(22)) - -def sound_off(): - buzzer.duty_u16(0) - -# play a frequence for a given time and go off -def playnote(frequency, time): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - # time.sleep(time) - sleep(0.1) - sound_off() # always turn off sound after note - -def play_no_signal(): - playnote(100, 0.1) - -def play_turn(): - playnote(500, .1) - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def rest(time): - sound_off() - sleep(time) - -def play_startup(): - playnote(600, 0.2) - rest(0.05) - playnote(600, 0.2) - rest(.05) - playnote(600, 0.2) - rest(0.1) - playnote(800, 0.4) - -def play_no_signal(): - playnote(300, 0.1) - -x=0 -def update_display(distance): - global x - print(x, distance) - if distance > 63: - distance = 63 - oled.pixel(x,HEIGHT - int(distance) - 1, 1) - if x > WIDTH - 3: - oled.scroll(-1,0) - else: - x += 1 - oled.show() - -# time of flight calibration parameters -zero_dist = 65 # distance measure when an object is about 1/2 cm away -max_dist = 350 # max distance we are able to read -scale_factor = .2 - -# get the normalized time-of-flight distance -def get_distance(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > max_dist: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * scale_factor) - -# a list of our prior distance measurements for graphing mode -distances=[] - -# startup -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -valid_distance = 0 -mode = 0 -# loop forever -def main(): - global mode, valid_distance - while True: - distance = get_distance() - if distance < MAX_DIST: - update_display(distance) - strip[0] = lightGreen - strip[1] = lightGreen - strip.write() - else: - strip[0] = lightPink - strip[1] = lightPink - strip.write() - play_no_signal() - sleep(.05) - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Chart Time of Flight') - -try: - main() -except KeyboardInterrupt: - print('Got interupt') -finally: - # Optional cleanup code - print('Powering down sound') - sound_off() - tof.stop() diff --git a/src/sensors/time-of-flight/i2c-0-tof-test.py b/src/sensors/time-of-flight/i2c-0-tof-test.py deleted file mode 100644 index 492e59570..000000000 --- a/src/sensors/time-of-flight/i2c-0-tof-test.py +++ /dev/null @@ -1,20 +0,0 @@ - -from machine import Pin,PWM -from utime import sleep -import VL53L0X - -sda=Pin(0) # Grove connector 6 -scl=Pin(1) # Colors on ToF sensor are RBYW (red, black, yellow white) -i2c_tof=machine.I2C(0, sda=sda, scl=scl) - -print(i2c_tof) -print(i2c_tof.scan()) - -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -while True: - tof_distance = tof.read() - print(tof_distance) - sleep(.2) - \ No newline at end of file diff --git a/src/sensors/time-of-flight/i2c-scanner.py b/src/sensors/time-of-flight/i2c-scanner.py deleted file mode 100644 index ffecaeb08..000000000 --- a/src/sensors/time-of-flight/i2c-scanner.py +++ /dev/null @@ -1,15 +0,0 @@ -import machine -sda=machine.Pin(0) # row one on our standard Pico breadboard -scl=machine.Pin(1) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl) -print('i2c result:', i2c) -address = i2c.scan() -print('Scan result:', address) -decimal = address[0] -hex = hex(decimal) -print('The VL53L0X has expected values of decimal 41 and hex 0x29') -print("Device found at decimal: ", i2c.scan(), decimal, hex) -if (decimal == 41): - print('PASS') -else: - print('FAIL') diff --git a/src/sensors/time-of-flight/i2c-tof-detection-test.py b/src/sensors/time-of-flight/i2c-tof-detection-test.py deleted file mode 100644 index 7d8106458..000000000 --- a/src/sensors/time-of-flight/i2c-tof-detection-test.py +++ /dev/null @@ -1,27 +0,0 @@ -import machine - -# Change these pin number to match your hardware setup -SDA_PIN = 16 -SCL_PIN = 17 -sda=machine.Pin(SDA_PIN) # row one on our standard Pico breadboard -scl=machine.Pin(SCL_PIN) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# i2c.scan() returns a list of devices that have been found -# i2c.scan()[0] is the first device found - -print("Using I2C SDA Pin:", SDA_PIN) -print("Using I2C SCL Pin:", SCL_PIN) -device_id_list = i2c.scan() -for device_id in device_id_list: - print("Found I2C Device at:", device_id) - -print("Device found at decimal", device_id) - -if device_id_list[0] == 41: - print("TEST PASS!") - print("We have found an Time of Flight Sensor using pins 16 and 17 for SDA and SCL.") - print("Your SDA and SCL lines are connected correctly.") -else: - print("No Time of Flight device found at decimal 41 using these SDA and SCL pins.") - print("TEST FAIL") diff --git a/src/sensors/time-of-flight/print-tof-values-i2c-1.py b/src/sensors/time-of-flight/print-tof-values-i2c-1.py deleted file mode 100644 index f212e1262..000000000 --- a/src/sensors/time-of-flight/print-tof-values-i2c-1.py +++ /dev/null @@ -1,20 +0,0 @@ - -from machine import Pin,PWM -from utime import sleep -import VL53L0X - -sda=Pin(26) # Grove connector 6 -scl=Pin(27) # Colors on ToF sensor are RBYW (red, black, yellow white) -i2c_tof=machine.I2C(1, sda=sda, scl=scl) - -print(i2c_tof) -print(i2c_tof.scan()) - -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -while True: - tof_distance = tof.read() - print(tof_distance) - sleep(.2) - \ No newline at end of file diff --git a/src/sensors/time-of-flight/tof-display-test.py b/src/sensors/time-of-flight/tof-display-test.py deleted file mode 100644 index 0afa1d8e0..000000000 --- a/src/sensors/time-of-flight/tof-display-test.py +++ /dev/null @@ -1,44 +0,0 @@ -# VL53L0X Display Test - -from machine import Pin, I2C -import VL53L0X -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(18) # row one on our standard Pico breadboard -scl=machine.Pin(19) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -tof = VL53L0X.VL53L0X(i2c) -MAX_TOF_VALUE = 1200 -MIN_OFFSET = 28 - -tof.start() -while True: - tof_value = tof.read() - display.fill(0) - if tof_value < MAX_TOF_VALUE: - # subtract and take half for CM - dist = (tof_value - MIN_OFFSET) >> 1 - print('dist:', dist) - display.text('Distance:', 0, 0, 1) - display.text(str(dist), 20, 20, 1) - display.text('cm', 0, 30, 1) - - else: - display.text('Out of range', 0, 0, 1) - display.show() - sleep(.1) - diff --git a/src/sensors/time-of-flight/tof-oled-display-test.py b/src/sensors/time-of-flight/tof-oled-display-test.py deleted file mode 100644 index ba043e252..000000000 --- a/src/sensors/time-of-flight/tof-oled-display-test.py +++ /dev/null @@ -1,37 +0,0 @@ -# VL53L0X Display Test - -from machine import Pin, I2C -import VL53L0X -import ssd1306 -from utime import sleep - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -SCL = machine.Pin(2) -SDA = machine.Pin(3) -DC = machine.Pin(4) -RES = machine.Pin(5) -spi=machine.SPI(0, sck=SCL, mosi=SDA) -# print(spi) - -display = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -sda=machine.Pin(18) # row one on our standard Pico breadboard -scl=machine.Pin(19) # row two on our standard Pico breadboard -i2c=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -tof = VL53L0X.VL53L0X(i2c) - - -tof.start() -while True: - dist = tof.read() - dist = (dist - 30) >> 1 - print(dist) - display.fill(0) - display.text('Distance:', 0, 0, 1) - display.text(str(dist), 20, 20, 1) - display.show() - sleep(.1) - \ No newline at end of file diff --git a/src/sensors/time-of-flight/tof-print-console-test.py b/src/sensors/time-of-flight/tof-print-console-test.py deleted file mode 100644 index 7fee6f0dc..000000000 --- a/src/sensors/time-of-flight/tof-print-console-test.py +++ /dev/null @@ -1,22 +0,0 @@ -from machine import I2C -from time import sleep -import VL53L0X - -sda=machine.Pin(16) # row one on our standard Pico breadboard -scl=machine.Pin(17) # row two on our standard Pico breadboard -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object time of flight distance sensor object -tof = VL53L0X.VL53L0X(i2c) -MAX_RANGE = 1200 - -tof.start() -while True: - tof_value = tof.read() - if tof_value < MAX_RANGE : - dist = (tof_value - 30) * .5 - print('value =', tof_value, ' dist=', dist) - sleep(.5) - else: - print(tof_value, ' out of range') - diff --git a/src/sensors/time-of-flight/tof-to-12-element-neopixel.py b/src/sensors/time-of-flight/tof-to-12-element-neopixel.py deleted file mode 100644 index c3b1149ca..000000000 --- a/src/sensors/time-of-flight/tof-to-12-element-neopixel.py +++ /dev/null @@ -1,30 +0,0 @@ -from machine import Pin, I2C -import VL53L0X -from neopixel import NeoPixel -from utime import sleep - -NEOPIXEL_PIN = 0 -NUMBER_PIXELS = 12 -strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -sda=machine.Pin(16) # lower right pin -scl=machine.Pin(17) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) -print(i2c) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -while True: - dist = round((tof.read() - 30) / 2) - print(dist) - index = round(dist / 20) - if index < 0: - index = 0 - if index > 11: - index = 11 - strip[index] = (255,0,255) - strip.write() - sleep(0.1) - strip[index] = (0,0,0) diff --git a/src/sensors/time-of-flight/tof-to-color.py b/src/sensors/time-of-flight/tof-to-color.py deleted file mode 100644 index 89be53c9a..000000000 --- a/src/sensors/time-of-flight/tof-to-color.py +++ /dev/null @@ -1,101 +0,0 @@ -# convert a time-of-flight reading to a color using the wheel() function -# make a game of keeping it in a color range like blue -from machine import Pin,PWM -import VL53L0X -from neopixel import NeoPixel -from time import sleep - -sda=Pin(26) # Grove connector 6 -scl=Pin(27) # Colors on ToF sensor are RBYW (red, black, yello white) -i2c_tof=machine.I2C(1, sda=sda, scl=scl, freq=400000) - -# Time of Flight Parameters as global variables -# You many need to adjust these a bit -ZERO_DIST = 40 -# created dynamically if we get a lower value -zero_dist = ZERO_DIST -min_raw_distance = ZERO_DIST -# this might vary based on the ambient light around the sensor -MAX_DIST = 1000 -max_raw_distance = 1000 -SCALE_FACTOR = .9 - -# the two on-board NeoPixels -NUMBER_PIXELS = 2 -NEOPIXEL_PIN = 18 - -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colors are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return (0, 0, 0) - if pos < 85: - return (255 - pos * 3, pos * 3, 0) - if pos < 170: - pos -= 85 - return (0, 255 - pos * 3, pos * 3) - pos -= 170 - return (pos * 3, 0, 255 - pos * 3) - -# get the normalized time-of-flight distance in centimeters -# Needs to be calibrated with ZERO_DISTANCE and SCALE_FACTOR -def get_distance_cm(): - global zero_dist, scale_factor - tof_distance = tof.read() - if tof_distance > MAX_DIST: - return tof_distance - # if our current time-of-flight distance is lower than our zero distance then reset the zero distance - if tof_distance < zero_dist: - zero_dist = tof_distance - return int((tof_distance - zero_dist) * SCALE_FACTOR) - -# startup -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c_tof) -tof.start() - -valid_distance = 0 - -# loop forever -def main(): - global max_raw_distance, min_raw_distance - while True: - # read a raw distance - distance = tof.read() - # print('raw distance', distance) - if distance < MAX_DIST: - print(distance, end='') - else: print(0, end='') - if distance > max_raw_distance: - max_raw_distance = distance - if distance < min_raw_distance: - min_raw_distance = distance# wrap around 255 using modulo 255 to get the remainder - mod_distance = distance % 255 - - # print('mod distance', distance) - print(', ', mod_distance) - if distance < max_raw_distance: - strip[0] = wheel(mod_distance) - strip[1] = wheel(mod_distance) - strip.write() - else: - strip[0] = (0,0,0) - strip[1] = (0,0,0) - strip.write() - sleep(.1) - - -# This allows us to stop the sound by doing a Stop or Control-C which is a keyboard intrrupt -print('Running Time of Flight To Color') - -try: - main() -except KeyboardInterrupt: - print('Got interupt') -finally: - # Optional cleanup code - print('Powering down time of flight sensor') - tof.stop() - - \ No newline at end of file diff --git a/src/sensors/vl53l0x.py b/src/sensors/vl53l0x.py deleted file mode 100644 index 65cf36441..000000000 --- a/src/sensors/vl53l0x.py +++ /dev/null @@ -1,34 +0,0 @@ -import pycom -import time -from machine import Pin -from machine import I2C -import VL53L0X - -i2c = I2C(0) -i2c = I2C(0, I2C.MASTER) -i2c = I2C(0, pins=('P10','P9')) -i2c.init(I2C.MASTER, baudrate=9600) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) - -tof.set_Vcsel_pulse_period(tof.vcsel_period_type[0], 18) - -tof.set_Vcsel_pulse_period(tof.vcsel_period_type[1], 14) - - -while True: -# Start ranging - tof.start() - tof.read() - print(tof.read()) - tof.stop() - - - - - - - #q = tof.set_signal_rate_limit(0.1) - # - # time.sleep(0.1) diff --git a/src/servos/data.py b/src/servos/data.py deleted file mode 100644 index bef41f683..000000000 --- a/src/servos/data.py +++ /dev/null @@ -1,22 +0,0 @@ -depth = [ -[191, 193, 227, 288, 420, 423, 424, 419, 418, 422, 423, 413, 414, 405, 378, 358, 335, 322, 308, 281, 270, 244, 231, 218, 209, 201, 191, 186, 179, 185], -[409, 384, 380, 370, 372, 370, 380, 379, 398, 394, 389, 403, 402, 365, 360, 354, 336, 325, 306, 295, 274, 248, 233, 213, 206, 200, 191, 193, 195, 193], -[400, 369, 362, 355, 358, 363, 368, 373, 382, 377, 388, 385, 381, 371, 359, 343, 339, 323, 302, 291, 275, 246, 229, 214, 202, 194, 186, 182, 183, 184], -[374, 357, 351, 344, 342, 343, 354, 346, 360, 365, 363, 361, 359, 352, 336, 322, 311, 313, 301, 290, 262, 250, 234, 211, 204, 191, 197, 188, 191, 188], -[355, 347, 336, 337, 336, 337, 342, 340, 342, 347, 347, 352, 346, 332, 321, 303, 291, 288, 287, 280, 258, 246, 228, 210, 203, 189, 190, 189, 189, 190], -[390, 381, 373, 368, 362, 364, 362, 364, 362, 364, 356, 353, 341, 296, 276, 242, 237, 240, 241, 248, 250, 242, 218, 213, 200, 190, 181, 176, 176, 178], -[353, 346, 342, 333, 341, 334, 336, 332, 334, 332, 324, 312, 282, 256, 230, 204, 198, 200, 206, 212, 223, 221, 212, 205, 199, 191, 189, 188, 188, 188], -[320, 322, 322, 324, 319, 322, 315, 316, 322, 316, 307, 294, 246, 225, 208, 189, 186, 187, 192, 199, 203, 207, 208, 200, 199, 189, 185, 189, 187, 187], -[297, 293, 296, 292, 295, 292, 290, 287, 292, 285, 276, 258, 229, 207, 187, 178, 175, 176, 175, 178, 185, 190, 198, 200, 191, 187, 179, 177, 175, 179], -[265, 287, 298, 299, 290, 285, 287, 284, 284, 280, 259, 235, 201, 189, 173, 166, 166, 163, 163, 168, 174, 181, 188, 191, 189, 185, 186, 186, 184, 184], -[259, 284, 296, 293, 293, 286, 286, 282, 277, 255, 239, 202, 190, 180, 169, 163, 156, 156, 156, 161, 166, 178, 185, 186, 186, 187, 183, 183, 184, 182], -[227, 284, 298, 298, 285, 294, 285, 280, 275, 255, 232, 198, 185, 171, 158, 154, 147, 150, 149, 156, 159, 174, 179, 181, 186, 184, 182, 179, 181, 180], -[215, 291, 295, 308, 294, 290, 280, 280, 260, 245, 228, 193, 180, 160, 155, 151, 145, 143, 147, 151, 154, 169, 177, 182, 184, 183, 181, 182, 184, 183], -[188, 288, 297, 300, 298, 299, 287, 280, 257, 246, 229, 197, 184, 165, 160, 150, 145, 143, 146, 153, 162, 167, 174, 180, 186, 183, 182, 184, 183, 180], -[249, 293, 306, 307, 309, 297, 291, 285, 260, 247, 206, 193, 182, 163, 160, 149, 144, 144, 146, 152, 160, 167, 175, 183, 187, 185, 182, 182, 186, 182], -[237, 289, 299, 308, 308, 297, 293, 286, 271, 260, 218, 205, 189, 171, 165, 157, 150, 148, 149, 154, 164, 171, 185, 187, 189, 186, 182, 185, 185, 184], -[243, 288, 314, 313, 307, 307, 296, 287, 278, 265, 228, 211, 185, 176, 170, 161, 158, 158, 156, 160, 170, 174, 190, 192, 191, 189, 185, 183, 185, 182], -[232, 285, 310, 315, 308, 300, 296, 290, 285, 275, 255, 235, 205, 191, 182, 172, 171, 170, 172, 175, 180, 185, 195, 199, 190, 185, 187, 185, 185, 186], -[273, 294, 315, 320, 316, 313, 305, 291, 290, 289, 278, 267, 231, 215, 196, 186, 185, 181, 186, 187, 193, 196, 204, 199, 192, 190, 186, 183, 183, 184], -[287, 298, 313, 321, 313, 310, 306, 292, 297, 288, 289, 278, 266, 246, 218, 209, 200, 195, 193, 196, 201, 210, 206, 204, 188, 183, 186, 184, 187, 184] -] diff --git a/src/servos/depth-array-plot.py b/src/servos/depth-array-plot.py deleted file mode 100644 index 282f1bb41..000000000 --- a/src/servos/depth-array-plot.py +++ /dev/null @@ -1,39 +0,0 @@ -import numpy as np -import plotly.graph_objs as go - -# Create a 2D array of x and y coordinates -x = np.arange(0, 40) -y = np.arange(0, 40) -xx, yy = np.meshgrid(x, y) - -# Create a 2D array of depth values -depth = np.array([ -[65, 105, 125, 178, 214, 255, 282, 313, 330, 345, 356, 362, 369, 373, 370, 360, 335, 311, 250, 206, 180, 159, 148, 140, 138, 142, 152, 161, 171, 180, 191, 194, 197, 205], -[39, 29, 73, 128, 168, 209, 253, 281, 300, 326, 329, 341, 345, 357, 355, 325, 280, 230, 197, 177, 160, 146, 137, 129, 128, 132, 139, 148, 156, 163, 166, 164, 161, 158], -[13, 23, 43, 62, 98, 133, 161, 187, 222, 253, 270, 292, 311, 314, 282, 233, 199, 174, 157, 153, 146, 136, 127, 119, 118, 125, 133, 140, 148, 156, 161, 166, 175, 180], -[27, 37, 72, 99, 146, 186, 234, 266, 301, 329, 341, 344, 348, 335, 280, 220, 182, 163, 151, 147, 138, 132, 128, 123, 122, 125, 127, 134, 140, 145, 149, 154, 161, 170], -[10, 22, 56, 84, 128, 157, 202, 236, 277, 307, 315, 336, 342, 322, 257, 196, 170, 151, 139, 131, 127, 124, 123, 122, 122, 123, 124, 127, 131, 135, 140, 144, 155, 163], -[11, 25, 52, 70, 102, 136, 178, 213, 231, 258, 279, 294, 294, 272, 216, 180, 158, 143, 131, 126, 121, 120, 122, 124, 123, 123, 123, 124, 126, 129, 133, 142, 151, 158], -[10, 11, 18, 44, 59, 89, 109, 135, 186, 214, 221, 249, 250, 246, 210, 178, 160, 143, 129, 122, 120, 119, 120, 122, 122, 123, 123, 122, 124, 128, 136, 145, 152, 155], -[2, 16, 124, 101, 78, 122, 134, 60, 62, 67, 67, 75, 73, 95, 128, 150, 151, 143, 134, 126, 122, 120, 120, 121, 121, 122, 124, 125, 128, 132, 141, 149, 155, 154], -[-6, -1, 2, 17, 24, 33, 46, 45, 55, 67, 71, 79, 111, 317, 380, 299, 200, 161, 146, 138, 131, 126, 122, 119, 120, 123, 126, 129, 136, 143, 150, 159, 158, 146], -[-3, 9, 3, 12, 23, 34, 39, 60, 62, 72, 92, 99, 110, 111, 127, 146, 158, 159, 152, 143, 138, 130, 124, 121, 121, 124, 128, 134, 141, 149, 157, 163, 156, 139], -[-6, 3, 7, 7, 32, 38, 43, 47, 59, 56, 72, 71, 74, 77, 87, 92, 120, 155, 162, 157, 148, 140, 133, 129, 129, 130, 136, 145, 156, 163, 167, 159, 142, 129], -[-7, 0, -3, 7, 21, 31, 38, 52, 63, 60, 65, 75, 77, 75, 78, 83, 103, 141, 161, 161, 153, 144, 138, 134, 133, 136, 141, 150, 161, 168, 165, 150, 130, 126], -[-8, -3, 4, 13, 30, 28, 39, 53, 57, 67, 67, 64, 65, 77, 75, 74, 90, 102, 135, 159, 161, 155, 149, 147, 144, 148, 154, 161, 167, 161, 140, 118, 109, 103], -[-4, -9, 4, 19, 17, 34, 41, 46, 54, 59, 56, 73, 68, 75, 67, 79, 85, 83, 98, 130, 153, 159, 160, 156, 154, 155, 158, 163, 154, 130, 111, 96, 94, 93], -[-5, 3, 5, 12, 21, 35, 45, 49, 54, 69, 64, 73, 72, 72, 74, 81, 75, 82, 80, 102, 120, 144, 156, 158, 155, 154, 155, 145, 118, 102, 89, 84, 80, 93], -[-2, -2, 5, 11, 24, 33, 42, 45, 58, 65, 66, 76, 70, 66, 72, 64, 72, 76, 77, 79, 87, 100, 123, 136, 136, 134, 122, 104, 89, 87, 75, 78, 80, 92], -[0, 0, 12, 18, 23, 33, 41, 51, 61, 61, 65, 72, 76, 70, 68, 70, 69, 74, 69, 70, 78, 86, 85, 97, 98, 99, 88, 82, 80, 77, 75, 79, 86, 93], -[-4, -1, 2, 24, 32, 33, 44, 52, 51, 66, 66, 70, 68, 68, 61, 72, 76, 70, 69, 70, 70, 68, 71, 80, 75, 73, 75, 73, 69, 71, 70, 72, 73, 92], -[8, 4, 10, 16, 26, 30, 43, 51, 49, 60, 64, 65, 75, 72, 74, 74, 71, 70, 65, 65, 69, 68, 67, 75, 64, 74, 73, 71, 72, 67, 80, 73, 81, 97], -[14, 3, 8, 23, 30, 38, 36, 51, 52, 55, 68, 66, 74, 73, 67, 76, 73, 74, 66, 71, 65, 73, 66, 66, 68, 72, 68, 77, 69, 68, 68, 76, 79, 99], -]) - -# Create a 3D plot of depth data -fig = go.Figure(data=[go.Surface(z=depth, x=xx, y=yy)]) -fig.update_layout(title='3D Plot of Depth Data', - scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Distance From ToF Sensor')) - -# Show the plot -fig.show() diff --git a/src/servos/horozontal-sweep.py b/src/servos/horozontal-sweep.py deleted file mode 100644 index 9b94a5828..000000000 --- a/src/servos/horozontal-sweep.py +++ /dev/null @@ -1,18 +0,0 @@ -from time import sleep -from machine import Pin, PWM - -pwm = PWM(Pin(14)) -pwm.freq(50) - -delay = 0.04 -min = 3000 -angle_span = 1000 -max = min + angle_span - -while True: - for position in range(min,max,50): - pwm.duty_u16(position) - sleep(delay) - for position in range(max,min,-50): - pwm.duty_u16(position) - sleep(delay) \ No newline at end of file diff --git a/src/servos/main.py b/src/servos/main.py deleted file mode 100644 index 558ff21b3..000000000 --- a/src/servos/main.py +++ /dev/null @@ -1,43 +0,0 @@ -from machine import Pin,PWM -import utime - -SERVO_PIN=0 - -SERVO_MIN = 500000 -SERVO_MAX = 1500000 - -POT_PIN = 26 - -POT_MIN = 272 -POT_MAX = 65263 - -servo_per_pot = (SERVO_MAX-SERVO_MIN)/(POT_MAX-POT_MIN) - -analog_value = machine.ADC(POT_PIN) - -led = Pin(25,Pin.OUT) - -servo = PWM(Pin(SERVO_PIN)) -servo.freq(50) - -while True: - reading = analog_value.read_u16() - print("ADC: ",reading) - servo.duty_ns(SERVO_MIN+int(reading*servo_per_pot ) ) - utime.sleep(0.2) - - -# graveyard -servo.duty_ns(SERVO_MID) - -while True: - reading = analog_value.read_u16() - print("ADC: ",reading) - servo.duty_ns(SERVO_MIN) - led.value(0) - utime.sleep(1) - servo.duty_ns(SERVO_MID) - led.value(1) - utime.sleep(0.2) - servo.duty_ns(SERVO_MAX) - utime.sleep(1) diff --git a/src/servos/plot-2d-array-v2.py b/src/servos/plot-2d-array-v2.py deleted file mode 100644 index 24cb03d87..000000000 --- a/src/servos/plot-2d-array-v2.py +++ /dev/null @@ -1,48 +0,0 @@ -import plotly.graph_objs as go -import numpy as np -depth = np.array([ -[65, 105, 125, 178, 214, 255, 282, 313, 330, 345, 356, 362, 369, 373, 370, 360, 335, 311, 250, 206, 180, 159, 148, 140, 138, 142, 152, 161, 171, 180, 191, 194, 197, 205], -[39, 29, 73, 128, 168, 209, 253, 281, 300, 326, 329, 341, 345, 357, 355, 325, 280, 230, 197, 177, 160, 146, 137, 129, 128, 132, 139, 148, 156, 163, 166, 164, 161, 158], -[13, 23, 43, 62, 98, 133, 161, 187, 222, 253, 270, 292, 311, 314, 282, 233, 199, 174, 157, 153, 146, 136, 127, 119, 118, 125, 133, 140, 148, 156, 161, 166, 175, 180], -[27, 37, 72, 99, 146, 186, 234, 266, 301, 329, 341, 344, 348, 335, 280, 220, 182, 163, 151, 147, 138, 132, 128, 123, 122, 125, 127, 134, 140, 145, 149, 154, 161, 170], -[10, 22, 56, 84, 128, 157, 202, 236, 277, 307, 315, 336, 342, 322, 257, 196, 170, 151, 139, 131, 127, 124, 123, 122, 122, 123, 124, 127, 131, 135, 140, 144, 155, 163], -[11, 25, 52, 70, 102, 136, 178, 213, 231, 258, 279, 294, 294, 272, 216, 180, 158, 143, 131, 126, 121, 120, 122, 124, 123, 123, 123, 124, 126, 129, 133, 142, 151, 158], -[10, 11, 18, 44, 59, 89, 109, 135, 186, 214, 221, 249, 250, 246, 210, 178, 160, 143, 129, 122, 120, 119, 120, 122, 122, 123, 123, 122, 124, 128, 136, 145, 152, 155], -[2, 16, 124, 101, 78, 122, 134, 60, 62, 67, 67, 75, 73, 95, 128, 150, 151, 143, 134, 126, 122, 120, 120, 121, 121, 122, 124, 125, 128, 132, 141, 149, 155, 154], -[-6, -1, 2, 17, 24, 33, 46, 45, 55, 67, 71, 79, 111, 317, 380, 299, 200, 161, 146, 138, 131, 126, 122, 119, 120, 123, 126, 129, 136, 143, 150, 159, 158, 146], -[-3, 9, 3, 12, 23, 34, 39, 60, 62, 72, 92, 99, 110, 111, 127, 146, 158, 159, 152, 143, 138, 130, 124, 121, 121, 124, 128, 134, 141, 149, 157, 163, 156, 139], -[-6, 3, 7, 7, 32, 38, 43, 47, 59, 56, 72, 71, 74, 77, 87, 92, 120, 155, 162, 157, 148, 140, 133, 129, 129, 130, 136, 145, 156, 163, 167, 159, 142, 129], -[-7, 0, -3, 7, 21, 31, 38, 52, 63, 60, 65, 75, 77, 75, 78, 83, 103, 141, 161, 161, 153, 144, 138, 134, 133, 136, 141, 150, 161, 168, 165, 150, 130, 126], -[-8, -3, 4, 13, 30, 28, 39, 53, 57, 67, 67, 64, 65, 77, 75, 74, 90, 102, 135, 159, 161, 155, 149, 147, 144, 148, 154, 161, 167, 161, 140, 118, 109, 103], -[-4, -9, 4, 19, 17, 34, 41, 46, 54, 59, 56, 73, 68, 75, 67, 79, 85, 83, 98, 130, 153, 159, 160, 156, 154, 155, 158, 163, 154, 130, 111, 96, 94, 93], -[-5, 3, 5, 12, 21, 35, 45, 49, 54, 69, 64, 73, 72, 72, 74, 81, 75, 82, 80, 102, 120, 144, 156, 158, 155, 154, 155, 145, 118, 102, 89, 84, 80, 93], -[-2, -2, 5, 11, 24, 33, 42, 45, 58, 65, 66, 76, 70, 66, 72, 64, 72, 76, 77, 79, 87, 100, 123, 136, 136, 134, 122, 104, 89, 87, 75, 78, 80, 92], -[0, 0, 12, 18, 23, 33, 41, 51, 61, 61, 65, 72, 76, 70, 68, 70, 69, 74, 69, 70, 78, 86, 85, 97, 98, 99, 88, 82, 80, 77, 75, 79, 86, 93], -[-4, -1, 2, 24, 32, 33, 44, 52, 51, 66, 66, 70, 68, 68, 61, 72, 76, 70, 69, 70, 70, 68, 71, 80, 75, 73, 75, 73, 69, 71, 70, 72, 73, 92], -[8, 4, 10, 16, 26, 30, 43, 51, 49, 60, 64, 65, 75, 72, 74, 74, 71, 70, 65, 65, 69, 68, 67, 75, 64, 74, 73, 71, 72, 67, 80, 73, 81, 97], -[14, 3, 8, 23, 841, 38, 36, 51, 52, 55, 68, 66, 74, 73, 67, 76, 73, 74, 66, 71, 65, 73, 66, 66, 68, 72, 68, 77, 69, 68, 68, 76, 79, 99], -]) - -# number of rows -y_len = len(depth) -# length of the first row -x_len = len(depth[0]) - -print(x_len, y_len) - -# Create 2D data -x = np.arange(-5, 5, 0.1) -y = np.arange(-5, 5, 0.1) -X, Y = np.meshgrid(x, y) -Z = np.sin(np.sqrt(X**2 + Y**2)) - -# Create 3D plot -fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)]) - -# Set plot layout -fig.update_layout(title='3D Plot of Highs', autosize=False, - width=500, height=500, - margin=dict(l=65, r=50, b=65, t=90)) - -# Show plot -# fig.show() \ No newline at end of file diff --git a/src/servos/plot-2d-array-v3.py b/src/servos/plot-2d-array-v3.py deleted file mode 100644 index 24cb03d87..000000000 --- a/src/servos/plot-2d-array-v3.py +++ /dev/null @@ -1,48 +0,0 @@ -import plotly.graph_objs as go -import numpy as np -depth = np.array([ -[65, 105, 125, 178, 214, 255, 282, 313, 330, 345, 356, 362, 369, 373, 370, 360, 335, 311, 250, 206, 180, 159, 148, 140, 138, 142, 152, 161, 171, 180, 191, 194, 197, 205], -[39, 29, 73, 128, 168, 209, 253, 281, 300, 326, 329, 341, 345, 357, 355, 325, 280, 230, 197, 177, 160, 146, 137, 129, 128, 132, 139, 148, 156, 163, 166, 164, 161, 158], -[13, 23, 43, 62, 98, 133, 161, 187, 222, 253, 270, 292, 311, 314, 282, 233, 199, 174, 157, 153, 146, 136, 127, 119, 118, 125, 133, 140, 148, 156, 161, 166, 175, 180], -[27, 37, 72, 99, 146, 186, 234, 266, 301, 329, 341, 344, 348, 335, 280, 220, 182, 163, 151, 147, 138, 132, 128, 123, 122, 125, 127, 134, 140, 145, 149, 154, 161, 170], -[10, 22, 56, 84, 128, 157, 202, 236, 277, 307, 315, 336, 342, 322, 257, 196, 170, 151, 139, 131, 127, 124, 123, 122, 122, 123, 124, 127, 131, 135, 140, 144, 155, 163], -[11, 25, 52, 70, 102, 136, 178, 213, 231, 258, 279, 294, 294, 272, 216, 180, 158, 143, 131, 126, 121, 120, 122, 124, 123, 123, 123, 124, 126, 129, 133, 142, 151, 158], -[10, 11, 18, 44, 59, 89, 109, 135, 186, 214, 221, 249, 250, 246, 210, 178, 160, 143, 129, 122, 120, 119, 120, 122, 122, 123, 123, 122, 124, 128, 136, 145, 152, 155], -[2, 16, 124, 101, 78, 122, 134, 60, 62, 67, 67, 75, 73, 95, 128, 150, 151, 143, 134, 126, 122, 120, 120, 121, 121, 122, 124, 125, 128, 132, 141, 149, 155, 154], -[-6, -1, 2, 17, 24, 33, 46, 45, 55, 67, 71, 79, 111, 317, 380, 299, 200, 161, 146, 138, 131, 126, 122, 119, 120, 123, 126, 129, 136, 143, 150, 159, 158, 146], -[-3, 9, 3, 12, 23, 34, 39, 60, 62, 72, 92, 99, 110, 111, 127, 146, 158, 159, 152, 143, 138, 130, 124, 121, 121, 124, 128, 134, 141, 149, 157, 163, 156, 139], -[-6, 3, 7, 7, 32, 38, 43, 47, 59, 56, 72, 71, 74, 77, 87, 92, 120, 155, 162, 157, 148, 140, 133, 129, 129, 130, 136, 145, 156, 163, 167, 159, 142, 129], -[-7, 0, -3, 7, 21, 31, 38, 52, 63, 60, 65, 75, 77, 75, 78, 83, 103, 141, 161, 161, 153, 144, 138, 134, 133, 136, 141, 150, 161, 168, 165, 150, 130, 126], -[-8, -3, 4, 13, 30, 28, 39, 53, 57, 67, 67, 64, 65, 77, 75, 74, 90, 102, 135, 159, 161, 155, 149, 147, 144, 148, 154, 161, 167, 161, 140, 118, 109, 103], -[-4, -9, 4, 19, 17, 34, 41, 46, 54, 59, 56, 73, 68, 75, 67, 79, 85, 83, 98, 130, 153, 159, 160, 156, 154, 155, 158, 163, 154, 130, 111, 96, 94, 93], -[-5, 3, 5, 12, 21, 35, 45, 49, 54, 69, 64, 73, 72, 72, 74, 81, 75, 82, 80, 102, 120, 144, 156, 158, 155, 154, 155, 145, 118, 102, 89, 84, 80, 93], -[-2, -2, 5, 11, 24, 33, 42, 45, 58, 65, 66, 76, 70, 66, 72, 64, 72, 76, 77, 79, 87, 100, 123, 136, 136, 134, 122, 104, 89, 87, 75, 78, 80, 92], -[0, 0, 12, 18, 23, 33, 41, 51, 61, 61, 65, 72, 76, 70, 68, 70, 69, 74, 69, 70, 78, 86, 85, 97, 98, 99, 88, 82, 80, 77, 75, 79, 86, 93], -[-4, -1, 2, 24, 32, 33, 44, 52, 51, 66, 66, 70, 68, 68, 61, 72, 76, 70, 69, 70, 70, 68, 71, 80, 75, 73, 75, 73, 69, 71, 70, 72, 73, 92], -[8, 4, 10, 16, 26, 30, 43, 51, 49, 60, 64, 65, 75, 72, 74, 74, 71, 70, 65, 65, 69, 68, 67, 75, 64, 74, 73, 71, 72, 67, 80, 73, 81, 97], -[14, 3, 8, 23, 841, 38, 36, 51, 52, 55, 68, 66, 74, 73, 67, 76, 73, 74, 66, 71, 65, 73, 66, 66, 68, 72, 68, 77, 69, 68, 68, 76, 79, 99], -]) - -# number of rows -y_len = len(depth) -# length of the first row -x_len = len(depth[0]) - -print(x_len, y_len) - -# Create 2D data -x = np.arange(-5, 5, 0.1) -y = np.arange(-5, 5, 0.1) -X, Y = np.meshgrid(x, y) -Z = np.sin(np.sqrt(X**2 + Y**2)) - -# Create 3D plot -fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)]) - -# Set plot layout -fig.update_layout(title='3D Plot of Highs', autosize=False, - width=500, height=500, - margin=dict(l=65, r=50, b=65, t=90)) - -# Show plot -# fig.show() \ No newline at end of file diff --git a/src/servos/plot-2d-array.py b/src/servos/plot-2d-array.py deleted file mode 100644 index aad9eea2c..000000000 --- a/src/servos/plot-2d-array.py +++ /dev/null @@ -1,19 +0,0 @@ -import plotly.graph_objs as go -import numpy as np - -# Create 2D data -x = np.arange(-5, 5, 0.1) -y = np.arange(-5, 5, 0.1) -X, Y = np.meshgrid(x, y) -Z = np.sin(np.sqrt(X**2 + Y**2)) - -# Create 3D plot -fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)]) - -# Set plot layout -fig.update_layout(title='3D Plot of Highs', autosize=False, - width=500, height=500, - margin=dict(l=65, r=50, b=65, t=90)) - -# Show plot -fig.show() \ No newline at end of file diff --git a/src/servos/test-tof.py b/src/servos/test-tof.py deleted file mode 100644 index d25ab67ac..000000000 --- a/src/servos/test-tof.py +++ /dev/null @@ -1,20 +0,0 @@ -# Test program for VL53L0X -import time -from machine import Pin -from machine import I2C -import VL53L0X - -sda=machine.Pin(0) # lower right pin -scl=machine.Pin(1) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -# Create a VL53L0X object -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -while True: - tof.read() - print(tof.read()) - time.sleep(0.3) - -# tof.stop() diff --git a/src/servos/vertical-sweep.py b/src/servos/vertical-sweep.py deleted file mode 100644 index c20fa4e88..000000000 --- a/src/servos/vertical-sweep.py +++ /dev/null @@ -1,20 +0,0 @@ -from time import sleep -from machine import Pin, PWM - -VERTICAL_PIN = 15 -pwm = PWM(Pin(VERTICAL_PIN)) -pwm.freq(50) - -# sample values are 0.01 to 0.1 -delay = 0.05 -max_angle = 7500 # lower this increase the higher angle -min_angle = 9000 # increase this to lower the bottom angle - -while True: - - for position in range(max_angle,min_angle,50): - pwm.duty_u16(position) - sleep(delay) - for position in range(min_angle,max_angle,-50): - pwm.duty_u16(position) - sleep(delay) \ No newline at end of file diff --git a/src/servos/x-y-scan-tof.py b/src/servos/x-y-scan-tof.py deleted file mode 100644 index 782d0be55..000000000 --- a/src/servos/x-y-scan-tof.py +++ /dev/null @@ -1,63 +0,0 @@ -from time import sleep -from machine import Pin, PWM -import VL53L0X - -sda=machine.Pin(0) # lower right pin -scl=machine.Pin(1) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -VERTICAL_PIN = 15 -HORIZONTAL_PIN = 14 -vpwm = PWM(Pin(VERTICAL_PIN)) -vpwm.freq(50) -hpwm = PWM(Pin(HORIZONTAL_PIN)) -hpwm.freq(50) - -# sample values are 0.01 to 0.1 -# vertical delay moving the scanner down -vdelay = 0.04 - -# return delay moving the scanner back up - no data being collected -updelay = 0.01 -hdelay = 0.05 -max_vangle = 7500 # lower this increase the higher angle -min_vangle = 9000 # increase this to lower the bottom angle -step = 25 - -horz_min = 3000 # this is where we start horizontal scane -angle_span = 1000 # the angle between the min and max -horz_max = horz_min + angle_span -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -def read_tof(): - return tof.read() - 20 - - -print('depth = [') -# for each horizontal position gather a stripe of data -for h_pos in range(horz_min,horz_max,step): - hpwm.duty_u16(h_pos) - sleep(hdelay) - print('[', end='') - for vposition in range(max_vangle,min_vangle,step): - vpwm.duty_u16(vposition) - dist = read_tof() - if vposition < min_vangle - step: - print(dist, ', ', sep='', end='') - else: - if h_pos < horz_max - print(dist, '],', sep='') - else: - print(dist, ']') - sleep(vdelay) - # move the servo back up but don't gather data - for vposition in range(min_vangle,max_vangle,-step): - vpwm.duty_u16(vposition) -# dist = read_tof() -# if vposition > max_vangle: -# print(dist, ', ', sep='', end='') -# else: -# print(dist) - sleep(updelay) -print(']') \ No newline at end of file diff --git a/src/servos/x-y-scan.py b/src/servos/x-y-scan.py deleted file mode 100644 index aa2d9b0ee..000000000 --- a/src/servos/x-y-scan.py +++ /dev/null @@ -1,46 +0,0 @@ -from time import sleep -from machine import Pin, PWM -import VL53L0X - -sda=machine.Pin(0) # lower right pin -scl=machine.Pin(1) # one up from lower right pin -i2c=machine.I2C(0, sda=sda, scl=scl, freq=400000) - -VERTICAL_PIN = 15 -HORIZONTAL_PIN = 14 -vpwm = PWM(Pin(VERTICAL_PIN)) -vpwm.freq(50) -hpwm = PWM(Pin(HORIZONTAL_PIN)) -hpwm.freq(50) - -# sample values are 0.01 to 0.1 -vdelay = 0.01 -hdelay = 0.05 -max_vangle = 7500 # lower this increase the higher angle -min_vangle = 9000 # increase this to lower the bottom angle - -horz_min = 3000 # this is where we start horizontal scane -angle_span = 1000 # the angle between the min and max -horz_max = horz_min + angle_span -tof = VL53L0X.VL53L0X(i2c) -tof.start() - -def read_tof(): - return tof.read() - 50 - -while True: - - for h_pos in range(horz_min,horz_max,50): - hpwm.duty_u16(h_pos) - sleep(hdelay) - for vposition in range(max_vangle,min_vangle,50): - vpwm.duty_u16(vposition) - dist = read_tof() - print(dist) - sleep(vdelay) - for vposition in range(min_vangle,max_vangle,-50): - vpwm.duty_u16(vposition) - dist = read_tof() - print(dist) - sleep(vdelay) - diff --git a/src/sound/TestwavePlayer.py b/src/sound/TestwavePlayer.py deleted file mode 100644 index 310c9d103..000000000 --- a/src/sound/TestwavePlayer.py +++ /dev/null @@ -1,93 +0,0 @@ -''' - (c) 2021 Daniel Perron - MIT License - - example of audio output using PWM and DMA - right now it works only with wave file at - 8000 sample rate , stereo or mono, and 16 bits audio - - GPIO 2 & 3 pin 4 and 5 are the output - You need to use headphones with a 1K resistor in series on - left and right speaker - - The myPWM subclass set the maximum count to 255 at a frequency around 122.5KHz. - - The myDMA class allow to use direct memory access to transfer each frame at the current sample rate - - - You need to install the wave.py and chunk.py from - https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio - - SDCard.py is available in https://github.com/micropython/micropython/tree/master/drivers/sdcard - please be sure to rename it SDCard.py into the pico lib folder - - - *** be sure to increase the SPI clock speed > 5MHz - *** once SDCard is initialize set the spi to an higher clock - - - How it works, - - 1 - We set the PWM to a range of 255, 1023 for 10 bits, at 122Khz - 2 - We read the wave file using the class wave which will set the sample rate and read the audio data by chunk - 3 - Mono files are converted to stereo by duplicating the original audio samples - 4 - Each chunk are converted to 16 bit signed to unsigned char with the middle at 128 - 5 - Wait for the DMA to be completed. On first it will be anyway. - 6 - The converted chunk is then pass to the DMA to be transfer at the sample rate using one of build-in timer - 7 - Go on step 2 until is done. - - P.S. use rshell to transfer wave files to the Pico file system - - For Headphones - - - 2K - PIO2 -/\/\/-----+----- headphone left - | - === 0.1uF - | - PIO4 -----------+----- headphone ground - | - === 0.1uF - 2k | - PIO3 -/\/\/-----+----- headphone right - - - - For amplifier don't use PIO4 and the capacitor should be 2200pF and connected to GND. - - - - -''' -# -#---USES -import os as uos -from wavePlayer import wavePlayer - - -if __name__ == "__main__": - - player = wavePlayer() - waveFolder= "/sounds" - wavelist = [] - - for i in uos.listdir(waveFolder): - if i.find(".wav")>=0: - wavelist.append(waveFolder+"/"+i) - elif i.find(".WAV")>=0: - wavelist.append(waveFolder+"/"+i) - - if not wavelist : - print("Warning NO '.wav' files found in ", waveFolder) - else: - print("Will play these '.wav' files", "/n" ,wavelist) - try: - while True: - for i in wavelist: - print(i) - player.play(i) - except KeyboardInterrupt: - player.stop() - print("wavePlayer terminated") - diff --git a/src/sound/__pycache__/chunk.cpython-36.pyc b/src/sound/__pycache__/chunk.cpython-36.pyc deleted file mode 100644 index 4f5737332..000000000 Binary files a/src/sound/__pycache__/chunk.cpython-36.pyc and /dev/null differ diff --git a/src/sound/__pycache__/wave.cpython-36.pyc b/src/sound/__pycache__/wave.cpython-36.pyc deleted file mode 100644 index 0e9e87c22..000000000 Binary files a/src/sound/__pycache__/wave.cpython-36.pyc and /dev/null differ diff --git a/src/sound/chunk.py b/src/sound/chunk.py deleted file mode 100644 index eed7f2c6a..000000000 --- a/src/sound/chunk.py +++ /dev/null @@ -1,168 +0,0 @@ -"""Simple class to read IFF chunks. - -An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File -Format)) has the following structure: - -+----------------+ -| ID (4 bytes) | -+----------------+ -| size (4 bytes) | -+----------------+ -| data | -| ... | -+----------------+ - -The ID is a 4-byte string which identifies the type of chunk. - -The size field (a 32-bit value, encoded using big-endian byte order) -gives the size of the whole chunk, including the 8-byte header. - -Usually an IFF-type file consists of one or more chunks. The proposed -usage of the Chunk class defined here is to instantiate an instance at -the start of each chunk and read from the instance until it reaches -the end, after which a new instance can be instantiated. At the end -of the file, creating a new instance will fail with a EOFError -exception. - -Usage: -while True: - try: - chunk = Chunk(file) - except EOFError: - break - chunktype = chunk.getname() - while True: - data = chunk.read(nbytes) - if not data: - pass - # do something with data - -The interface is file-like. The implemented methods are: -read, close, seek, tell, isatty. -Extra methods are: skip() (called by close, skips to the end of the chunk), -getname() (returns the name (ID) of the chunk) - -The __init__ method has one required argument, a file-like object -(including a chunk instance), and one optional argument, a flag which -specifies whether or not chunks are aligned on 2-byte boundaries. The -default is 1, i.e. aligned. -""" - -class Chunk: - def __init__(self, file, align=True, bigendian=True, inclheader=False): - import struct - self.closed = False - self.align = align # whether to align to word (2-byte) boundaries - if bigendian: - strflag = '>' - else: - strflag = '<' - self.file = file - self.chunkname = file.read(4) - if len(self.chunkname) < 4: - raise EOFError - try: - data = file.read(4) - self.chunksize = struct.unpack(strflag+'L', data)[0] - except:# struct.error: - raise EOFError - if inclheader: - self.chunksize = self.chunksize - 8 # subtract header - self.size_read = 0 - try: - self.offset = self.file.tell() - except: - self.seekable = False - else: - self.seekable = True - - def getname(self): - """Return the name (ID) of the current chunk.""" - return self.chunkname - - def getsize(self): - """Return the size of the current chunk.""" - return self.chunksize - - def close(self): - if not self.closed: - self.skip() - self.closed = True - - def isatty(self): - if self.closed: - raise ValueError("I/O operation on closed file") - return False - - def seek(self, pos, whence=0): - """Seek to specified position into the chunk. - Default position is 0 (start of chunk). - If the file is not seekable, this will result in an error. - """ - - if self.closed: - raise ValueError("I/O operation on closed file") - if not self.seekable: - raise OSError("cannot seek") - if whence == 1: - pos = pos + self.size_read - elif whence == 2: - pos = pos + self.chunksize - if pos < 0 or pos > self.chunksize: - raise RuntimeError - self.file.seek(self.offset + pos, 0) - self.size_read = pos - - def tell(self): - if self.closed: - raise ValueError("I/O operation on closed file") - return self.size_read - - def read(self, size=-1): - """Read at most size bytes from the chunk. - If size is omitted or negative, read until the end - of the chunk. - """ - - if self.closed: - raise ValueError("I/O operation on closed file") - if self.size_read >= self.chunksize: - return '' - if size < 0: - size = self.chunksize - self.size_read - if size > self.chunksize - self.size_read: - size = self.chunksize - self.size_read - data = self.file.read(size) - self.size_read = self.size_read + len(data) - if self.size_read == self.chunksize and \ - self.align and \ - (self.chunksize & 1): - dummy = self.file.read(1) - self.size_read = self.size_read + len(dummy) - return data - - def skip(self): - """Skip the rest of the chunk. - If you are not interested in the contents of the chunk, - this method should be called so that the file points to - the start of the next chunk. - """ - - if self.closed: - raise ValueError("I/O operation on closed file") - if self.seekable: - try: - n = self.chunksize - self.size_read - # maybe fix alignment - if self.align and (self.chunksize & 1): - n = n + 1 - self.file.seek(n, 1) - self.size_read = self.size_read + n - return - except OSError: - pass - while self.size_read < self.chunksize: - n = min(8192, self.chunksize - self.size_read) - dummy = self.read(n) - if not dummy: - raise EOFError diff --git a/src/sound/convert-mp3-to-wav.py b/src/sound/convert-mp3-to-wav.py deleted file mode 100644 index 17dd66ad0..000000000 --- a/src/sound/convert-mp3-to-wav.py +++ /dev/null @@ -1,5 +0,0 @@ -import pydub -import - -song = pydub.AudioSegment.from_mp3("Excited-R2D2.mp3") -song.export(dst, format="wav") \ No newline at end of file diff --git a/src/sound/display-test-wav.py b/src/sound/display-test-wav.py deleted file mode 100644 index ee0dc1d4a..000000000 --- a/src/sound/display-test-wav.py +++ /dev/null @@ -1,71 +0,0 @@ -from machine import Pin, Timer, PWM -from utime import sleep -import ssd1306 -import framebuf -from wavePlayer import wavePlayer - -LEFT_SPEAKER = 15 -RIGHT_SPEAKER = 16 -waveFolder= "/sounds" -wavelist = [] - -WIDTH = 128 -HEIGHT = 64 -CS = machine.Pin(1) -DC = machine.Pin(4) -RES = machine.Pin(5) -clock=machine.Pin(2) -data=machine.Pin(3) -spi=machine.SPI(0,sck=clock, mosi=data) -oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS) - -fb = framebuf.FrameBuffer(bytearray( - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x04\x00\x00\x02\x00\x00\x80\xc1\xc1\xc0\xc0\xc0' - b'\xc0\xc0\xc1\x81\x01\x01\x02\x02\x06\x0e\x0c\x1c\x38\xf8\xf8\xf0\xe0\xe0\xc0\x80\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x40\x00\x00\x04\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00' - b'\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x1f\xff\xff\xff\xff\xff\xff\xfe\xfc\xf8\xe0\xc0\x00\x00\x00\x00\x00' - b'\x00\x80\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\x1f\x38\x10\x10\x10' - b'\x10\x30\x1f\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf8\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xf8\xc0\x00' - b'\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x80\x80\x80\xc0\xe0\xe0\xf0\xf8\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc' - b'\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc0\xe0\xf0\xf8\xfc\xfc\xfe\xfe\xfe\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f' - b'\x00\x03\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf9\xf9\xf9\xf1' - b'\x01\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x1f\x03\x00' - b'\x00\x00\x00\x00\x00\x02\x00\x10\x20\x40\x80\x00\x00\x00\x00\x00\x0f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x3f\x3f\x3f\x2f' - b'\x00\x3f\x3f\x03\x03\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x3f\x1f\x0f\x03\x01\x00\x00\x00\x00' - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x04\x00\x00\x10\x01\x23\x07\x0f\x5f\x3f\x3f\x7f\xff\xff\xff\xff\xff\xff' - b'\xff\xff\xff\xff\xff\xff\x7f\x7f\x7f\x7f\x3f\x3f\x3f\x1f\x1f\x0f\x0f\x07\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), - 64, 64, framebuf.MONO_VLSB) - -def update_display(counter): - oled.fill(0) - oled.blit(fb, 64, 0) - oled.text('CoderDojo', 0, 0) - oled.text('Robots', 0, 10) - oled.text('and', 0, 20) - oled.text('Sound', 0, 30) - oled.show() - -counter = 0 -update_display(counter) -sleep(1) -# player = wavePlayer(leftPin=Pin(LEFT_SPEAKER),rightPin=Pin(RIGHT_SPEAKER)) - - -def stop_sounds(): - print("Stopping sound.") - player.stop() - -player = wavePlayer(leftPin=Pin(LEFT_SPEAKER),rightPin=Pin(RIGHT_SPEAKER), dma0Channel=0, dma1Channel=1) - -try: - while True: - update_display(counter) - sleep(1) - player.play('/sounds/r2d2-beeping-4.wav') - sleep(1) - -except KeyboardInterrupt: - stop_sounds() - print("wave player terminated") \ No newline at end of file diff --git a/src/sound/mp3-to-wav.py b/src/sound/mp3-to-wav.py deleted file mode 100644 index bda66a961..000000000 --- a/src/sound/mp3-to-wav.py +++ /dev/null @@ -1,11 +0,0 @@ -from os import path -from pydub import AudioSegment - -# files -# src = "/Users/dan/Documents/ws/robot-media/mp3-files/Excited-R2D2.mp3" -src = "Excited-R2D2.mp3" -# dst = "/Users/dan/Documents/ws/robot-media/wav-files/Excited-R2D2.wav" -dst = "Excited-R2D2.wav" -# convert wav to mp3 -sound = AudioSegment.from_mp3(src) -sound.export(dst, format="wav") \ No newline at end of file diff --git a/src/sound/myDMA.py b/src/sound/myDMA.py deleted file mode 100644 index 5dbc15118..000000000 --- a/src/sound/myDMA.py +++ /dev/null @@ -1,127 +0,0 @@ -from machine import mem32 -import uctypes - -class myDMA: - - def __init__(self, channel, timer=None, clock_MUL=None, clock_DIV=None): - self.channel = channel - self.timer = timer - # why this address? - self.DMA_BASE = 0x50_000_000 - self.DMA_CH_BASE = self.DMA_BASE + (0x40 * channel) - self.READ_ADDR = self.DMA_CH_BASE + 0 - self.WRITE_ADDR = self.DMA_CH_BASE + 4 - self.TRANS_COUNT = self.DMA_CH_BASE + 8 - self.ALIAS_TRANS_COUNT = self.DMA_CH_BASE + 0x1C - self.CTRL_TRIG = self.DMA_CH_BASE + 12 - self.MULTI_TRIG = self.DMA_BASE + 0x430 - self.CHAIN_ABORT = self.DMA_BASE + 0x444 - self.ALIAS_CTRL = self.DMA_CH_BASE + 0x10 - self.timer_channel = timer - self.clock_MUL= clock_MUL - self.clock_DIV = clock_DIV - - if self.timer_channel is None: - self.TIMER = None - else: - self.TIMER = self.DMA_BASE + 0x420 + ( 4 * self.timer_channel) - if not( self.clock_DIV is None or self.clock_MUL is None): - mem32[self.TIMER]= self.clock_MUL << 16 | self.clock_DIV - - mem32[self.CTRL_TRIG] = 0 - self.abort() - self.setCtrl(src_inc=True, dst_inc=True,data_size=1,chainTo=None) - - def start(self): - mem32[self.MULTI_TRIG] = 1 << self.channel - - def enable(self): - mem32[self.CTRL_TRIG | 0x2000]= 1 - - def pause(self): - mem32[self.CTRL_TRIG | 0x3000]= 1 - - def setCtrl(self, src_inc=True, dst_inc=True,data_size=1,chainTo=None): - self.data_size=data_size - DATA_SIZE = 0 - if data_size == 2: - DATA_SIZE = 1 - elif data_size == 4: - DATA_SIZE = 2 - #SET EN (DMA Channel Enable) - ctrl = 1 - #SET DATA_SIZE (size of each DMA bus transfer) - ctrl += (DATA_SIZE << 2) - #SET TREQ_SEL (DMA Transfer Request Signal) - if self.timer_channel is None: - ctrl += (0x3f << 15) #- Unpaced Request - else: - ctrl += ((0x3b + self.timer_channel) << 15) #TIMER paced Request - #SET CHAIN_TO (DMA channel completion trigger another channel) - self.chainTo=chainTo - if chainTo is None: - ctrl += (self.channel << 11) #- - else: - ctrl += (chainTo << 11) - #SET INCR_READ (DMA read address incremented after each bus cycle ???) - if src_inc: - ctrl += 0x10 - #SET INCR_WRITE (DMA write address incremented after each bus cycle ???) - if dst_inc: - ctrl += 0x20 - mem32[self.ALIAS_CTRL] = ctrl - - - def move(self, src_add, dst_add, count, start=False): - # mem32[self.CTRL_TRIG] = 0 - # mem32[self.CHAIN_ABORT] = 1 << self.channel - mem32[self.WRITE_ADDR] = dst_add - mem32[self.READ_ADDR] = src_add - - if start: - mem32[self.ALIAS_TRANS_COUNT] = count // self.data_size - else: - mem32[self.TRANS_COUNT] = count // self.data_size - - def abort(self): - mem32[self.CHAIN_ABORT | 0x2000] = 1 << self.channel - while(mem32[self.CHAIN_ABORT] & (1 << self.channel)): - pass - mem32[self.CTRL_TRIG]=0 - - - def isBusy(self): - flag = mem32[self.ALIAS_CTRL] - if (flag & 0x80000000) != 0: - return False - if (flag & ( 1<<24)) == 0: - return False - return True - -if __name__ == "__main__": - import urandom, time - tSize = 96 - src = bytearray(tSize) - dst = bytearray(tSize) - - for i in range(tSize): - src[i]= urandom.randint(1,7) - #src[i]= i % 255 - - # initialize DMA channel 11 , use timer 3 and set clock to 125MHz/15625 = 8000Hz - dma = myDMA(11, timer=3, clock_MUL=1, clock_DIV=15625) - start = time.ticks_us() - # copy from src to dest - dma.move(uctypes.addressof(src), uctypes.addressof(dst), tSize, start=True) - end = time.ticks_us() - - print("src= ", src) - print("\ndst= ", dst) - # test that it worked - for i in range(0, tSize): - if src[i] != dst[i]: - print('Copy error at', i) - - length_us = end - start - if length_us > 0: - print("\ntook {} us rate = {} bytes /sec\n".format(length_us,1_000_000.0 * tSize / length_us)) \ No newline at end of file diff --git a/src/sound/myPWM.py b/src/sound/myPWM.py deleted file mode 100644 index a2f1f8e72..000000000 --- a/src/sound/myPWM.py +++ /dev/null @@ -1,66 +0,0 @@ -from machine import PWM,Pin,mem32 - -class myPWM(PWM): - def __init__(self,pin,divider=8,top=255): - self.id = int(str(pin)[4:-1].split(',')[0]) - self.A_B = self.id & 1 - self.channel = self.id >> 1 - self.divider = divider - self.top = top - - super().__init__(pin) - super().freq(122_000) - super().duty_u16(32768) - # set memory base - self.PWM_BASE = 0x4005_0000 + (self.channel * 0x14) - # set divider base - self.PWM_DIV = self.PWM_BASE + 4 - # set top base - self.PWM_TOP = self.PWM_BASE + 16 - # set cc base - self.PWM_CC = self.PWM_BASE + 12 - - #ok we want frequency around 60KHz and max top at 255 - # 125Mhz / (255 * 60000) => 8.1 - # then 125MHZ / ( 8 * 255) = 61275Hz - - # set divider to 8 - #mem32[self.PWM_DIV] = 8 << 4 - mem32[self.PWM_DIV] = self.divider << 4 - # set top to 255 - mem32[self.PWM_TOP] = self.top - self.duty(self.top // 2) - - - #def deinit(self): - # super().deinit() - # _p = Pin(self.id,Pin.IN) - - def duty(self, value): - if value > self.top: - value = self.top - reg = mem32[self.PWM_CC] - if self.A_B == 0: - # ok change channel A - mem32[self.PWM_CC]= (reg & 0xffff0000) | value - else: - # channel channel B - mem32[self.PWM_CC]= ( reg & 0xffff) | (value << 16) - - -if __name__ == "__main__": - import utime - # change this if you move the speaker - pwm = myPWM(Pin(15)) - try: - value = 0 - increment = 1 - while True: - value = value % 256 - pwm.duty(value) - if value == 0: - increment = increment * (-1) - value += increment - utime.sleep_ms(2) - except KeyboardInterrupt: - pwm.deinit() \ No newline at end of file diff --git a/src/sound/piano-eight.py b/src/sound/piano-eight.py deleted file mode 100644 index 7879a7edf..000000000 --- a/src/sound/piano-eight.py +++ /dev/null @@ -1,47 +0,0 @@ -# play a tone durning button down -from machine import Pin, PWM -from utime import sleep, ticks_ms - -SPEAKER_PIN = 22 # pass through a seaker and tie the other end to GND -speaker = PWM(Pin(SPEAKER_PIN)) - -builtin_led = machine.Pin(25, Pin.OUT) - -# Connect these GP pins through a button to the +3.3 volt rail -button_pin_1 = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_2 = machine.Pin(11, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_3 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_4 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_5 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_6 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_7 = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN) -button_pin_8 = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN) - -def playtone(frequency): - speaker.duty_u16(1000) # turn the PWM duty to 50% - speaker.freq(frequency) - builtin_led.high() # turn builtin LED on - -def bequiet(): - speaker.duty_u16(0) # turn off the speaker PWM - builtin_led.low() # turn builtin LED off - -while True: - if button_pin_1.value() == 1: - playtone(220) # A3 - elif button_pin_2.value() == 1: - playtone(247) # B3 - elif button_pin_3.value() == 1: - playtone(262) # C4 - elif button_pin_4.value() == 1: - playtone(294) # D4 - elif button_pin_5.value() == 1: - playtone(330) # E4 - elif button_pin_6.value() == 1: - playtone(349) # F4 - elif button_pin_7.value() == 1: - playtone(392) # G4 - elif button_pin_8.value() == 1: - playtone(440) # A4 - else: - bequiet() \ No newline at end of file diff --git a/src/sound/play-all-sounds.py b/src/sound/play-all-sounds.py deleted file mode 100644 index caef2f9a6..000000000 --- a/src/sound/play-all-sounds.py +++ /dev/null @@ -1,112 +0,0 @@ -''' - (c) 2021 Daniel Perron - MIT License - - example of audio output using PWM and DMA - right now it works only with wave file at - 8000 sample rate , stereo or mono, and 16 bits audio - - GPIO 2 & 3 pin 4 and 5 are the output - You need to use headphones with a 1K resistor in series on - left and right speaker - - The myPWM subclass set the maximum count to 255 at a frequency around 122.5KHz. - - The myDMA class allow to use direct memory access to transfer each frame at the current sample rate - - - You need to install the wave.py and chunk.py from - https://github.com/joeky888/awesome-micropython-lib/tree/master/Audio - - SDCard.py is available in https://github.com/micropython/micropython/tree/master/drivers/sdcard - please be sure to rename it SDCard.py into the pico lib folder - - - *** be sure to increase the SPI clock speed > 5MHz - *** once SDCard is initialize set the spi to an higher clock - - - How it works, - - 1 - We set the PWM to a range of 255, 1023 for 10 bits, at 122Khz - 2 - We read the wave file using the class wave which will set the sample rate and read the audio data by chunk - 3 - Mono files are converted to stereo by duplicating the original audio samples - 4 - Each chunk are converted to 16 bit signed to unsigned char with the middle at 128 - 5 - Wait for the DMA to be completed. On first it will be anyway. - 6 - The converted chunk is then pass to the DMA to be transfer at the sample rate using one of build-in timer - 7 - Go on step 2 until is done. - - P.S. use rshell to transfer wave files to the Pico file system - - For Headphones - - - 2K - PIO2 -/\/\/-----+----- headphone left - | - === 0.1uF - | - PIO4 -----------+----- headphone ground - | - === 0.1uF - 2k | - PIO3 -/\/\/-----+----- headphone right - - - - For amplifier don't use PIO4 and the capacitor should be 2200pF and connected to GND. - - - - -''' -# -#---USES -import os as uos -from machine import Pin -import wave -from wavePlayer import wavePlayer -from utime import sleep - -def print_sound_metadata(path_to_wave_file): - f = wave.open(path_to_wave_file,'rb') - print("{0:<50}".format(path_to_wave_file), - "{0:>5}".format(f.getframerate()), - "{0:>5}".format(f.getsampwidth()), - "{0:>6}".format(f.getnchannels()), - "{0:>6}".format(f.getnframes()) - ) - -if __name__ == "__main__": - - player = wavePlayer(leftPin=Pin(15),rightPin=Pin(14)) - # player = wavePlayer() - waveFolder= "/sounds" - wavelist = [] - - for i in uos.listdir(waveFolder): - if i.find(".wav")>=0: - wavelist.append(waveFolder+"/"+i) - elif i.find(".WAV")>=0: - wavelist.append(waveFolder+"/"+i) - - if not wavelist: - print("Warning NO '.wav' files") - else: - print("Will play these '.wav' files") - print("{0:<45}".format('File Path'), 'Frame Rate Width Chans Frames') - for file in wavelist: - print_sound_metadata(file) - print('') - try: - for i in wavelist: - # print("about to play:", i) - sleep(1) - player.play(i) - print_sound_metadata(i) - print('') - - except KeyboardInterrupt: - player.stop() - print("wavePlayer terminated") - diff --git a/src/sound/play-happy-birthday.py b/src/sound/play-happy-birthday.py deleted file mode 100644 index 885e68d8d..000000000 --- a/src/sound/play-happy-birthday.py +++ /dev/null @@ -1,104 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# Speaker is on GP18 on the Cytron Maker Pi Pico board -SPEAKER_PIN = 18 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def playnote(frequency, duration): - speaker.duty_u16(1000) - speaker.freq(frequency) - sleep(duration/1000) - speaker.duty_u16(0) - -def rest(duration): - speaker.duty_u16(0) - sleep(duration/1000) - -name = 'Ann' - -print('Ha', end='') -playnote(264, 250) -rest(.25) # quarter second rest -print('ppy ', end='') -playnote(264, 250) -rest(.125) -print('birth', end='') -playnote(297, 1000) -rest(.125) -print('day ', end='') -playnote(264, 1000) -rest(.125) -print('to ', end='') -playnote(352, 1000) -rest(.125) -print('you') -playnote(330, 2000) -rest(.25) - -print('Ha', end='') -playnote(264, 250) -rest(.25) -print('ppy ', end='') -playnote(264, 250) -rest(.125) -print('birth', end='') -playnote(297, 1000) -rest(.125) -print('day ', end='') -playnote(264, 1000) -rest(.125) -print('to ', end='') -playnote(396, 1000) -rest(.125) -print('you') -playnote(352, 2000) -rest(.25) - -print('Ha', end='') -playnote(264, 250) -rest(.125) -print('ppy ', end='') -playnote(264, 500) -rest(250/1000.0) -print('birth', end='') -playnote(440, 1000) -rest(.125) -print('day ', end='') -playnote(352, 1000) -rest(.125) -print('dear ', end='') -playnote(330, 1000) -print(name) -rest(.125) -playnote(297, 1000) - -playnote(440, 1000) -rest(.125) - -rest(.25) -print('Ha', end='') -playnote(466, 250) -rest(.25) -print('ppy ', end='') -playnote(466, 250) -rest(.125) -print('birth', end='') -playnote(440, 1000) -rest(.125) -print('day ', end='') -playnote(352, 1000) -rest(.125) -print('to ', end='') -playnote(396, 1000) -rest(.125) -print('you') -playnote(352, 2000) -rest(.125) - -# turn off -speaker.duty_u16(0) - -print('HAPPY BIRTHDAY ' + name + ' <3') \ No newline at end of file diff --git a/src/sound/play-mario.py b/src/sound/play-mario.py deleted file mode 100644 index ccf004593..000000000 --- a/src/sound/play-mario.py +++ /dev/null @@ -1,37 +0,0 @@ -from machine import Pin, PWM -from utime import sleep -buzzer = PWM(Pin(16)) - -tones = { -"B0": 31,"C1": 33,"CS1": 35,"D1": 37,"DS1": 39,"E1": 41,"F1": 44,"FS1": 46,"G1": 49,"GS1": 52,"A1": 55,"AS1": 58,"B1": 62,"C2": 65, -"CS2": 69,"D2": 73,"DS2": 78,"E2": 82,"F2": 87,"FS2": 93,"G2": 98,"GS2": 104,"A2": 110,"AS2": 117,"B2": 123,"C3": 131,"CS3": 139, -"D3": 147,"DS3": 156,"E3": 165,"F3": 175,"FS3": 185,"G3": 196,"GS3": 208,"A3": 220,"AS3": 233,"B3": 247,"C4": 262,"CS4": 277,"D4": 294,"DS4": 311, -"E4": 330,"F4": 349,"FS4": 370,"G4": 392,"GS4": 415,"A4": 440,"AS4": 466,"B4": 494,"C5": 523,"CS5": 554,"D5": 587,"DS5": 622,"E5": 659,"F5": 698, -"FS5": 740,"G5": 784,"GS5": 831,"A5": 880,"AS5": 932,"B5": 988,"C6": 1047,"CS6": 1109,"D6": 1175,"DS6": 1245,"E6": 1319,"F6": 1397,"FS6": 1480,"G6": 1568,"GS6": 1661, -"A6": 1760,"AS6": 1865,"B6": 1976,"C7": 2093,"CS7": 2217,"D7": 2349,"DS7": 2489,"E7": 2637,"F7": 2794,"FS7": 2960,"G7": 3136,"GS7": 3322,"A7": 3520, -"AS7": 3729,"B7": 3951,"C8": 4186,"CS8": 4435,"D8": 4699,"DS8": 4978 -} - - -song = ["E5","G5","A5","P","E5","G5","B5","A5","P","E5","G5","A5","P","G5","E5"] -mario = ["E7", "E7", 0, "E7", 0, "C7", "E7", 0, "G7", 0, 0, 0, "G6", 0, 0, 0, "C7", 0, 0, "G6", - 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", - 0, "E7", 0,"C7", "D7", "B6", 0, 0, "C7", 0, 0, "G6", 0, 0, "E6", 0, 0, "A6", 0, "B6", 0, - "AS6", "A6", 0, "G6", "E7", 0, "G7", "A7", 0, "F7", "G7", 0, "E7", 0,"C7", "D7", "B6", 0, 0] - -def playtone(frequency): - buzzer.duty_u16(1000) - buzzer.freq(frequency) - -def bequiet(): - buzzer.duty_u16(0) - -def playsong(mysong): - for i in range(len(mysong)): - if (mysong[i] == "P" or mysong[i] == 0 ): - bequiet() - else: - playtone(tones[mysong[i]]) - sleep(0.2) - bequiet() -playsong(mario) \ No newline at end of file diff --git a/src/sound/play-r2d2-beeping.py b/src/sound/play-r2d2-beeping.py deleted file mode 100644 index a04fd4de7..000000000 --- a/src/sound/play-r2d2-beeping.py +++ /dev/null @@ -1,19 +0,0 @@ -import os as uos -from machine import Pin -from utime import sleep -from wavePlayer import wavePlayer -# this works when we send mono to pin 16 (lower right corner) leftPin=Pin(0),rightPin=Pin(16) -# this will not work) leftPin=Pin(0),rightPin=Pin(18) -# this will not work) leftPin=Pin(0),rightPin=Pin(19) -# this will work: wavePlayer(leftPin=Pin(14),rightPin=Pin(15)) -# this will work: wavePlayer(leftPin=Pin(15),rightPin=Pin(14)) -player = wavePlayer(leftPin=Pin(15),rightPin=Pin(14)) - -try: - while True: - player.play('/sounds/r2d2-beeping-8k.wav') - sleep(1) - -except KeyboardInterrupt: - player.stop() - print("wave player terminated") \ No newline at end of file diff --git a/src/sound/play-scale.py b/src/sound/play-scale.py deleted file mode 100644 index 814011e6b..000000000 --- a/src/sound/play-scale.py +++ /dev/null @@ -1,25 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 22 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def bequiet(): - speaker.duty_u16(0) - -freq = 30 - -for i in range(64): - print(freq) - playtone(freq) - sleep(0.3) - freq = int(freq * 1.1) - -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/sound/play-sound-host.py b/src/sound/play-sound-host.py deleted file mode 100644 index 8c85bd5b6..000000000 --- a/src/sound/play-sound-host.py +++ /dev/null @@ -1,12 +0,0 @@ -# import required libraries -from pydub import AudioSegment -from pydub.playback import play - -# Import an audio file -# Format parameter only -# for readability -# /Users/dan/Documents/ws/robot-media/wav-files -wav_file = AudioSegment.from_file(file = "/Users/dan/Documents/ws/robot-media/wav-files/R2D2-yeah.wav", format = "wav") - -# Play the audio file -play(wav_file) \ No newline at end of file diff --git a/src/sound/play-three-tones.py b/src/sound/play-three-tones.py deleted file mode 100644 index 8abb39420..000000000 --- a/src/sound/play-three-tones.py +++ /dev/null @@ -1,32 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 22 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) - -# the time each tone will be on -ON_TIME = .25 -# the time between the tones -OFF_TIME = .1 - -speaker.duty_u16(1000) -speaker.freq(300) -sleep(ON_TIME) -speaker.duty_u16(0) -sleep(OFF_TIME) - -speaker.duty_u16(1000) -speaker.freq(800) -sleep(ON_TIME) -speaker.duty_u16(0) -sleep(OFF_TIME) - -speaker.duty_u16(1000) -speaker.freq(400) -sleep(ON_TIME) - -# turn off the PWM -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/sound/play-tone-on-button-press.py b/src/sound/play-tone-on-button-press.py deleted file mode 100644 index e7cbc6806..000000000 --- a/src/sound/play-tone-on-button-press.py +++ /dev/null @@ -1,45 +0,0 @@ -from machine import Pin, PWM -from utime import sleep, ticks_ms - -SPEAKER_PIN = 22 -speaker = PWM(Pin(SPEAKER_PIN)) -# Sample Raspberry Pi Pico MicroPython button press example with a debounce delay value of 200ms in the interrupt handler - -button_presses = 0 # the count of times the button has been pressed -last_time = 0 # the last time we pressed the button - -builtin_led = machine.Pin(25, Pin.OUT) -# The lower left corner of the Pico has a wire that goes through the buttons upper left and the lower right goes to the 3.3 rail -button_pin = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_DOWN) - -# This function gets called every time the button is pressed. The parameter "pin" is not used. -def button_pressed_handler(pin): - global button_presses, last_time - new_time = ticks_ms() - # if it has been more that 1/5 of a second since the last event, we have a new event - if (new_time - last_time) > 200: - button_presses +=1 - last_time = new_time - -# now we register the handler function when the button is pressed -button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler = button_pressed_handler) - -def playtone(frequency): - speaker.duty_u16(1000) - speaker.freq(frequency) - -def bequiet(): - speaker.duty_u16(0) - -# This is for only printing when a new button press count value happens -old_presses = 0 -while True: - # only print on change in the button_presses value - if button_presses != old_presses: - playtone(1000) - sleep(.1) - print(button_presses) - builtin_led.toggle() - old_presses = button_presses - else: - bequiet() \ No newline at end of file diff --git a/src/sound/play-tone.py b/src/sound/play-tone.py deleted file mode 100644 index fe757deda..000000000 --- a/src/sound/play-tone.py +++ /dev/null @@ -1,15 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -SPEAKER_PIN = 16 - -# create a Pulse Width Modulation Object on this pin -speaker = PWM(Pin(SPEAKER_PIN)) -# set the duty cycle -speaker.duty_u16(1000) -speaker.freq(1000) # 1 Kilohertz -sleep(1) # wait a second -speaker.duty_u16(1000) -# turn off the PWM -speaker.duty_u16(0) \ No newline at end of file diff --git a/src/sound/sdcard.py b/src/sound/sdcard.py deleted file mode 100644 index 0ba3076a3..000000000 --- a/src/sound/sdcard.py +++ /dev/null @@ -1,282 +0,0 @@ -""" -MicroPython driver for SD cards using SPI bus. - -Requires an SPI bus and a CS pin. Provides readblocks and writeblocks -methods so the device can be mounted as a filesystem. - -Example usage on pyboard: - - import pyb, sdcard, os - sd = sdcard.SDCard(pyb.SPI(1), pyb.Pin.board.X5) - pyb.mount(sd, '/sd2') - os.listdir('/') - -Example usage on ESP8266: - - import machine, sdcard, os - sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15)) - os.mount(sd, '/sd') - os.listdir('/') - -""" - -from micropython import const -import time - - -_CMD_TIMEOUT = const(100) - -_R1_IDLE_STATE = const(1 << 0) -# R1_ERASE_RESET = const(1 << 1) -_R1_ILLEGAL_COMMAND = const(1 << 2) -# R1_COM_CRC_ERROR = const(1 << 3) -# R1_ERASE_SEQUENCE_ERROR = const(1 << 4) -# R1_ADDRESS_ERROR = const(1 << 5) -# R1_PARAMETER_ERROR = const(1 << 6) -_TOKEN_CMD25 = const(0xFC) -_TOKEN_STOP_TRAN = const(0xFD) -_TOKEN_DATA = const(0xFE) - - -class SDCard: - def __init__(self, spi, cs): - self.spi = spi - self.cs = cs - - self.cmdbuf = bytearray(6) - self.dummybuf = bytearray(512) - self.tokenbuf = bytearray(1) - for i in range(512): - self.dummybuf[i] = 0xFF - self.dummybuf_memoryview = memoryview(self.dummybuf) - - # initialise the card - self.init_card() - - def init_spi(self, baudrate): - try: - master = self.spi.MASTER - except AttributeError: - # on ESP8266 - self.spi.init(baudrate=baudrate, phase=0, polarity=0) - else: - # on pyboard - self.spi.init(master, baudrate=baudrate, phase=0, polarity=0) - - def init_card(self): - # init CS pin - self.cs.init(self.cs.OUT, value=1) - - # init SPI bus; use low data rate for initialisation - self.init_spi(100000) - - # clock card at least 100 cycles with cs high - for i in range(16): - self.spi.write(b"\xff") - - # CMD0: init card; should return _R1_IDLE_STATE (allow 5 attempts) - for _ in range(5): - if self.cmd(0, 0, 0x95) == _R1_IDLE_STATE: - break - else: - raise OSError("no SD card") - - # CMD8: determine card version - r = self.cmd(8, 0x01AA, 0x87, 4) - if r == _R1_IDLE_STATE: - self.init_card_v2() - elif r == (_R1_IDLE_STATE | _R1_ILLEGAL_COMMAND): - self.init_card_v1() - else: - raise OSError("couldn't determine SD card version") - - # get the number of sectors - # CMD9: response R2 (R1 byte + 16-byte block read) - if self.cmd(9, 0, 0, 0, False) != 0: - raise OSError("no response from SD card") - csd = bytearray(16) - self.readinto(csd) - if csd[0] & 0xC0 == 0x40: # CSD version 2.0 - self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024 - elif csd[0] & 0xC0 == 0x00: # CSD version 1.0 (old, <=2GB) - c_size = csd[6] & 0b11 | csd[7] << 2 | (csd[8] & 0b11000000) << 4 - c_size_mult = ((csd[9] & 0b11) << 1) | csd[10] >> 7 - self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) - else: - raise OSError("SD card CSD format not supported") - # print('sectors', self.sectors) - - # CMD16: set block length to 512 bytes - if self.cmd(16, 512, 0) != 0: - raise OSError("can't set 512 block size") - - # set to high data rate now that it's initialised - self.init_spi(1320000) - - def init_card_v1(self): - for i in range(_CMD_TIMEOUT): - self.cmd(55, 0, 0) - if self.cmd(41, 0, 0) == 0: - self.cdv = 512 - # print("[SDCard] v1 card") - return - raise OSError("timeout waiting for v1 card") - - def init_card_v2(self): - for i in range(_CMD_TIMEOUT): - time.sleep_ms(50) - self.cmd(58, 0, 0, 4) - self.cmd(55, 0, 0) - if self.cmd(41, 0x40000000, 0) == 0: - self.cmd(58, 0, 0, 4) - self.cdv = 1 - # print("[SDCard] v2 card") - return - raise OSError("timeout waiting for v2 card") - - def cmd(self, cmd, arg, crc, final=0, release=True, skip1=False): - self.cs(0) - - # create and send the command - buf = self.cmdbuf - buf[0] = 0x40 | cmd - buf[1] = arg >> 24 - buf[2] = arg >> 16 - buf[3] = arg >> 8 - buf[4] = arg - buf[5] = crc - self.spi.write(buf) - - if skip1: - self.spi.readinto(self.tokenbuf, 0xFF) - - # wait for the response (response[7] == 0) - for i in range(_CMD_TIMEOUT): - self.spi.readinto(self.tokenbuf, 0xFF) - response = self.tokenbuf[0] - if not (response & 0x80): - # this could be a big-endian integer that we are getting here - for j in range(final): - self.spi.write(b"\xff") - if release: - self.cs(1) - self.spi.write(b"\xff") - return response - - # timeout - self.cs(1) - self.spi.write(b"\xff") - return -1 - - def readinto(self, buf): - self.cs(0) - - # read until start byte (0xff) - for i in range(_CMD_TIMEOUT): - self.spi.readinto(self.tokenbuf, 0xFF) - if self.tokenbuf[0] == _TOKEN_DATA: - break - time.sleep_ms(1) - else: - self.cs(1) - raise OSError("timeout waiting for response") - - # read data - mv = self.dummybuf_memoryview - if len(buf) != len(mv): - mv = mv[: len(buf)] - self.spi.write_readinto(mv, buf) - - # read checksum - self.spi.write(b"\xff") - self.spi.write(b"\xff") - - self.cs(1) - self.spi.write(b"\xff") - - def write(self, token, buf): - self.cs(0) - - # send: start of block, data, checksum - self.spi.read(1, token) - self.spi.write(buf) - self.spi.write(b"\xff") - self.spi.write(b"\xff") - - # check the response - if (self.spi.read(1, 0xFF)[0] & 0x1F) != 0x05: - self.cs(1) - self.spi.write(b"\xff") - return - - # wait for write to finish - while self.spi.read(1, 0xFF)[0] == 0: - pass - - self.cs(1) - self.spi.write(b"\xff") - - def write_token(self, token): - self.cs(0) - self.spi.read(1, token) - self.spi.write(b"\xff") - # wait for write to finish - while self.spi.read(1, 0xFF)[0] == 0x00: - pass - - self.cs(1) - self.spi.write(b"\xff") - - def readblocks(self, block_num, buf): - nblocks = len(buf) // 512 - assert nblocks and not len(buf) % 512, "Buffer length is invalid" - if nblocks == 1: - # CMD17: set read address for single block - if self.cmd(17, block_num * self.cdv, 0, release=False) != 0: - # release the card - self.cs(1) - raise OSError(5) # EIO - # receive the data and release card - self.readinto(buf) - else: - # CMD18: set read address for multiple blocks - if self.cmd(18, block_num * self.cdv, 0, release=False) != 0: - # release the card - self.cs(1) - raise OSError(5) # EIO - offset = 0 - mv = memoryview(buf) - while nblocks: - # receive the data and release card - self.readinto(mv[offset : offset + 512]) - offset += 512 - nblocks -= 1 - if self.cmd(12, 0, 0xFF, skip1=True): - raise OSError(5) # EIO - - def writeblocks(self, block_num, buf): - nblocks, err = divmod(len(buf), 512) - assert nblocks and not err, "Buffer length is invalid" - if nblocks == 1: - # CMD24: set write address for single block - if self.cmd(24, block_num * self.cdv, 0) != 0: - raise OSError(5) # EIO - - # send the data - self.write(_TOKEN_DATA, buf) - else: - # CMD25: set write address for first block - if self.cmd(25, block_num * self.cdv, 0) != 0: - raise OSError(5) # EIO - # send the data - offset = 0 - mv = memoryview(buf) - while nblocks: - self.write(_TOKEN_CMD25, mv[offset : offset + 512]) - offset += 512 - nblocks -= 1 - self.write_token(_TOKEN_STOP_TRAN) - - def ioctl(self, op, arg): - if op == 4: # get number of blocks - return self.sectors diff --git a/src/sound/stop-sounds.py b/src/sound/stop-sounds.py deleted file mode 100644 index a0f951bc6..000000000 --- a/src/sound/stop-sounds.py +++ /dev/null @@ -1,5 +0,0 @@ -from machine import Pin, PWM -pwm = PWM(Pin(14)) -pwm.deinit() -pwm = PWM(Pin(15)) -pwm.deinit() diff --git a/src/sound/test-stereo-auto-ports.py b/src/sound/test-stereo-auto-ports.py deleted file mode 100644 index 27e442dd5..000000000 --- a/src/sound/test-stereo-auto-ports.py +++ /dev/null @@ -1,27 +0,0 @@ -from machine import Pin, PWM -from utime import sleep - -# lower right corner with USB connector on top -AUDIO_LEFT_PIN = 18 -AUDIO_RIGHT_PIN = 19 - -# create a Pulse Width Modulation Object on this pin -left_speaker = PWM(Pin(AUDIO_LEFT_PIN)) -# set the duty cycle to be 50% -left_speaker.duty_u16(1000) -left_speaker.freq(1000) # 50% on and off -sleep(1) # wait a second -left_speaker.duty_u16(0) -# turn off the PWM circuits off with a zero duty cycle -left_speaker.duty_u16(0) -sleep(1) - -# create a Pulse Width Modulation Object on this pin -right_speaker = PWM(Pin(AUDIO_RIGHT_PIN)) -# set the duty cycle to be 50% -right_speaker.duty_u16(1000) -right_speaker.freq(1000) # 50% on and off -sleep(1) # wait a second -right_speaker.duty_u16(0) -# turn off the PWM circuits off with a zero duty cycle -right_speaker.duty_u16(0) \ No newline at end of file diff --git a/src/sound/wave.py b/src/sound/wave.py deleted file mode 100644 index a63726229..000000000 --- a/src/sound/wave.py +++ /dev/null @@ -1,503 +0,0 @@ -"""Stuff to parse WAVE files. - -Usage. - -Reading WAVE files: - f = wave.open(file, 'r') -where file is either the name of a file or an open file pointer. -The open file pointer must have methods read(), seek(), and close(). -When the setpos() and rewind() methods are not used, the seek() -method is not necessary. - -This returns an instance of a class with the following public methods: - getnchannels() -- returns number of audio channels (1 for - mono, 2 for stereo) - getsampwidth() -- returns sample width in bytes - getframerate() -- returns sampling frequency - getnframes() -- returns number of audio frames - getcomptype() -- returns compression type ('NONE' for linear samples) - getcompname() -- returns human-readable version of - compression type ('not compressed' linear samples) - getparams() -- returns a namedtuple consisting of all of the - above in the above order - getmarkers() -- returns None (for compatibility with the - aifc module) - getmark(id) -- raises an error since the mark does not - exist (for compatibility with the aifc module) - readframes(n) -- returns at most n frames of audio - rewind() -- rewind to the beginning of the audio stream - setpos(pos) -- seek to the specified position - tell() -- return the current position - close() -- close the instance (make it unusable) -The position returned by tell() and the position given to setpos() -are compatible and have nothing to do with the actual position in the -file. -The close() method is called automatically when the class instance -is destroyed. - -Writing WAVE files: - f = wave.open(file, 'w') -where file is either the name of a file or an open file pointer. -The open file pointer must have methods write(), tell(), seek(), and -close(). - -This returns an instance of a class with the following public methods: - setnchannels(n) -- set the number of channels - setsampwidth(n) -- set the sample width - setframerate(n) -- set the frame rate - setnframes(n) -- set the number of frames - setcomptype(type, name) - -- set the compression type and the - human-readable compression type - setparams(tuple) - -- set all parameters at once - tell() -- return current position in output file - writeframesraw(data) - -- write audio frames without pathing up the - file header - writeframes(data) - -- write audio frames and patch up the file header - close() -- patch up the file header and close the - output file -You should set the parameters before the first writeframesraw or -writeframes. The total number of frames does not need to be set, -but when it is set to the correct value, the header does not have to -be patched up. -It is best to first set all parameters, perhaps possibly the -compression type, and then write audio frames using writeframesraw. -When all frames have been written, either call writeframes('') or -close() to patch up the sizes in the header. -The close() method is called automatically when the class instance -is destroyed. -""" - -import builtins - -__all__ = ["open", "openfp", "Error"] - -class Error(Exception): - pass - -WAVE_FORMAT_PCM = 0x0001 - -_array_fmts = None, 'b', 'h', None, 'i' - -#import audioop -import struct -import sys -from chunk import Chunk -from collections import namedtuple - -_wave_params = namedtuple('_wave_params', - 'nchannels sampwidth framerate nframes comptype compname') - -class Wave_read: - """Variables used in this class: - - These variables are available to the user though appropriate - methods of this class: - _file -- the open file with methods read(), close(), and seek() - set through the __init__() method - _nchannels -- the number of audio channels - available through the getnchannels() method - _nframes -- the number of audio frames - available through the getnframes() method - _sampwidth -- the number of bytes per audio sample - available through the getsampwidth() method - _framerate -- the sampling frequency - available through the getframerate() method - _comptype -- the AIFF-C compression type ('NONE' if AIFF) - available through the getcomptype() method - _compname -- the human-readable AIFF-C compression type - available through the getcomptype() method - _soundpos -- the position in the audio stream - available through the tell() method, set through the - setpos() method - - These variables are used internally only: - _fmt_chunk_read -- 1 iff the FMT chunk has been read - _data_seek_needed -- 1 iff positioned correctly in audio - file for readframes() - _data_chunk -- instantiation of a chunk class for the DATA chunk - _framesize -- size of one frame in the file - """ - - def initfp(self, file): - self._convert = None - self._soundpos = 0 - self._file = Chunk(file, bigendian = 0) - if self._file.getname() != b'RIFF': - raise Error('file does not start with RIFF id') - if self._file.read(4) != b'WAVE': - raise Error('not a WAVE file') - self._fmt_chunk_read = 0 - self._data_chunk = None - while 1: - self._data_seek_needed = 1 - try: - chunk = Chunk(self._file, bigendian = 0) - except EOFError: - break - chunkname = chunk.getname() - if chunkname == b'fmt ': - self._read_fmt_chunk(chunk) - self._fmt_chunk_read = 1 - elif chunkname == b'data': - if not self._fmt_chunk_read: - raise Error('data chunk before fmt chunk') - self._data_chunk = chunk - self._nframes = chunk.chunksize // self._framesize - self._data_seek_needed = 0 - break - chunk.skip() - if not self._fmt_chunk_read or not self._data_chunk: - raise Error('fmt chunk and/or data chunk missing') - - def __init__(self, f): - self._i_opened_the_file = None - if isinstance(f, str): - f = builtins.open(f, 'rb') - self._i_opened_the_file = f - # else, assume it is an open file object already - try: - self.initfp(f) - except: - if self._i_opened_the_file: - f.close() - raise - - def __del__(self): - self.close() - - def __enter__(self): - return self - - def __exit__(self, *args): - self.close() - - # - # User visible methods. - # - def getfp(self): - return self._file - - def rewind(self): - self._data_seek_needed = 1 - self._soundpos = 0 - - def close(self): - if self._i_opened_the_file: - self._i_opened_the_file.close() - self._i_opened_the_file = None - self._file = None - - def tell(self): - return self._soundpos - - def getnchannels(self): - return self._nchannels - - def getnframes(self): - return self._nframes - - def getsampwidth(self): - return self._sampwidth - - def getframerate(self): - return self._framerate - - def getcomptype(self): - return self._comptype - - def getcompname(self): - return self._compname - - def getparams(self): - return _wave_params(self.getnchannels(), self.getsampwidth(), - self.getframerate(), self.getnframes(), - self.getcomptype(), self.getcompname()) - - def getmarkers(self): - return None - - def getmark(self, id): - raise Error('no marks') - - def setpos(self, pos): - if pos < 0 or pos > self._nframes: - raise Error('position not in range') - self._soundpos = pos - self._data_seek_needed = 1 - - def readframes(self, nframes): - if self._data_seek_needed: - self._data_chunk.seek(0, 0) - pos = self._soundpos * self._framesize - if pos: - self._data_chunk.seek(pos, 0) - self._data_seek_needed = 0 - if nframes == 0: - return b'' - data = self._data_chunk.read(nframes * self._framesize) - if self._sampwidth != 1 and sys.byteorder == 'big': - data = audioop.byteswap(data, self._sampwidth) - if self._convert and data: - data = self._convert(data) - self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth) - return data - - # - # Internal methods. - # - - def _read_fmt_chunk(self, chunk): - wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack(' 4: - raise Error('bad sample width') - self._sampwidth = sampwidth - - def getsampwidth(self): - if not self._sampwidth: - raise Error('sample width not set') - return self._sampwidth - - def setframerate(self, framerate): - if self._datawritten: - raise Error('cannot change parameters after starting to write') - if framerate <= 0: - raise Error('bad frame rate') - self._framerate = int(round(framerate)) - - def getframerate(self): - if not self._framerate: - raise Error('frame rate not set') - return self._framerate - - def setnframes(self, nframes): - if self._datawritten: - raise Error('cannot change parameters after starting to write') - self._nframes = nframes - - def getnframes(self): - return self._nframeswritten - - def setcomptype(self, comptype, compname): - if self._datawritten: - raise Error('cannot change parameters after starting to write') - if comptype not in ('NONE',): - raise Error('unsupported compression type') - self._comptype = comptype - self._compname = compname - - def getcomptype(self): - return self._comptype - - def getcompname(self): - return self._compname - - def setparams(self, params): - nchannels, sampwidth, framerate, nframes, comptype, compname = params - if self._datawritten: - raise Error('cannot change parameters after starting to write') - self.setnchannels(nchannels) - self.setsampwidth(sampwidth) - self.setframerate(framerate) - self.setnframes(nframes) - self.setcomptype(comptype, compname) - - def getparams(self): - if not self._nchannels or not self._sampwidth or not self._framerate: - raise Error('not all parameters set') - return _wave_params(self._nchannels, self._sampwidth, self._framerate, - self._nframes, self._comptype, self._compname) - - def setmark(self, id, pos, name): - raise Error('setmark() not supported') - - def getmark(self, id): - raise Error('no marks') - - def getmarkers(self): - return None - - def tell(self): - return self._nframeswritten - - def writeframesraw(self, data): - if not isinstance(data, (bytes, bytearray)): - data = memoryview(data).cast('B') - self._ensure_header_written(len(data)) - nframes = len(data) // (self._sampwidth * self._nchannels) - if self._convert: - data = self._convert(data) - if self._sampwidth != 1 and sys.byteorder == 'big': - data = audioop.byteswap(data, self._sampwidth) - self._file.write(data) - self._datawritten += len(data) - self._nframeswritten = self._nframeswritten + nframes - - def writeframes(self, data): - self.writeframesraw(data) - if self._datalength != self._datawritten: - self._patchheader() - - def close(self): - if self._file: - try: - self._ensure_header_written(0) - if self._datalength != self._datawritten: - self._patchheader() - self._file.flush() - finally: - self._file = None - if self._i_opened_the_file: - self._i_opened_the_file.close() - self._i_opened_the_file = None - - # - # Internal methods. - # - - def _ensure_header_written(self, datasize): - if not self._headerwritten: - if not self._nchannels: - raise Error('# channels not specified') - if not self._sampwidth: - raise Error('sample width not specified') - if not self._framerate: - raise Error('sampling rate not specified') - self._write_header(datasize) - - def _write_header(self, initlength): - assert not self._headerwritten - self._file.write(b'RIFF') - if not self._nframes: - self._nframes = initlength // (self._nchannels * self._sampwidth) - self._datalength = self._nframes * self._nchannels * self._sampwidth - try: - self._form_length_pos = self._file.tell() - except (AttributeError, OSError): - self._form_length_pos = None - self._file.write(struct.pack(' 5MHz - *** once SDCard is initialize set the spi to an higher clock - - - How it works, - - 1 - We set the PWM to a range of 255, 1023 for 10 bits, at 122Khz - 2 - We read the wave file using the class wave which will set the sample rate and read the audio data by chunk - 3 - Mono files are converted to stereo by duplicating the original audio samples - 4 - Each chunk are converted to 16 bit signed to unsigned char with the middle at 128 - 5 - Wait for the DMA to be completed. On first it will be anyway. - 6 - The converted chunk is then passed to the DMA to be transfered at the sample rate using one of built-in timer - 7 - Go on step 2 until is done. - - P.S. use rshell to transfer wave files to the Pico file system - - April 20 - Version 0.1 - --- Add DMA chainning. This removes the glitch betweem DMA transfer - --- assembly function convert2PWM replace the struct pack and compack - since it is not necessary to convert the binary string it is way faster. - Version 0.2 - --- Add mono audio file handling - - For Headphones - - - 2K - PIO2 -/\/\/-----+----- headphone left - | - === 0.1uF - | - PIO4 -----------+----- headphone ground - | - === 0.1uF - 2k | - PIO3 -/\/\/-----+----- headphone right - - - - For amplifier don't use PIO4 and the capacitor should be 2200pF and connected to GND. - - - - -''' -import wave -import uctypes -from myDMA import myDMA -from myPWM import myPWM -from machine import Pin - - - -#r0 buffer address -#r1 number of word to do -#r2 8 or 10 bit PWM -#then r2 hold data reference by r0 -#r3 = 32768 to convert (-32768..32767) to (0..65535) -#r4 hold 255 or 1023 (8 or 10 bits) -#r5 hold /64 or /256 ( 6 or 8 bit shift) -@micropython.asm_thumb -def convert2PWM(r0,r1,r2): - #r3=32768 - mov(r3,1) - mov(r4,15) - lsl(r3,r4) - # 8bits or 10 bit PWM - mov(r4,255) - cmp(r2,10) - bne(PWM8BITS) - #ok we are 10 bits - # set r4 for 1023 - lsl(r4,r4,2) - add(r4,r4,3) - mov(r5,6) - b(loop) - label(PWM8BITS) - #ok then this is 8 bits - #r4 already to 255 - mov(r5,8) - label(loop) - # get 16 bit data - ldrh(r2,[r0,0]) - # add 32768 - add(r2,r2,r3) - # shift right 6 bit or 8 bit - lsr(r2,r5) - # and 255 or 1023 - and_(r2,r4) - # store new data - strh(r2,[r0,0]) - add(r0,2) - sub(r1,1) - bgt(loop) - -pass -@micropython.asm_thumb -def interleavebytes(r0,r1,r2): -#r0 MONO wav audio buffer address -#r1 Stereo wav audio ouput buffer address -#r2 number of halfwords (16 bit audio samples) from MONO buffer to convert - - label(loop) - # get 16 bit data - ldrh(r3,[r0,0]) - # copy over - strh(r3,[r1,0]) - add(r1,2) - # and duplicate for second channel - strh(r3,[r1,0]) - # point to next audio data halfword - add(r1,2) - add(r0,2) - # decrement counter and loop unless zero - sub(r2,1) - bgt(loop) - - -class wavePlayer: - # here are the default pins, but you can override them - def __init__(self,leftPin=Pin(0),rightPin=Pin(1), virtualGndPin=Pin(4), - dma0Channel=10,dma1Channel=11,dmaTimer=3,pwmBits=10): - #left channel Pin needs to be an even GPIO Pin number - #right channel Pin needs to be left channel + 1 - self.pwmBits=pwmBits - self.PWM_DIVIDER = 1 - if self.pwmBits == 10: - self.PWM_TOP = 1023 - self.PWM_HALF = 512 - else: - # 8 bits - self.PWM_TOP = 255 - self.PWM_HALF = 128 - - self.leftPin=leftPin - self.rightPin=rightPin - self.virtualGndPin=virtualGndPin - - # set PWM - self.leftPWM=myPWM(leftPin,divider=self.PWM_DIVIDER,top=self.PWM_TOP) - self.leftPWM.duty(self.PWM_HALF) - self.rightPWM=myPWM(rightPin,divider=self.PWM_DIVIDER,top=self.PWM_TOP) - self.rightPWM.duty(self.PWM_HALF) - if not (self.virtualGndPin is None): - self.virtualGndPWM=myPWM(self.virtualGndPin,divider=self.PWM_DIVIDER,top=self.PWM_TOP) - self.virtualGndPWM.duty(self.PWM_HALF) - - - # set DMA channel - self.dma0Channel = dma0Channel - self.dma1Channel = dma1Channel - self.dmaTimer = dmaTimer - - - def stop(self): - self.dma0.abort() - self.dma1.abort() - - def play(self,filename): - # open Audio file and get information - - f = wave.open(filename,'rb') - - rate = f.getframerate() - bytesDepth = f.getsampwidth() - channels = f.getnchannels() - frameCount = f.getnframes() - - # set number of Frames/chunk and DMAunitSize for Stereo samples - DMAunitSize = 4 - nbFrame = 2048 - # adjust down if 1 channel (mono) - if channels == 1: - nbFrame=1024 - #number of 16bit audio chunks per Frame - nbData = nbFrame*2 - # Set DMA channel and timer rate - # the divider set the rate at 2Khz (125Mhz//62500) - # The multiplier use the sample rate to adjust it correctly - if rate == 44100: - self.dma0 = myDMA(self.dma0Channel,timer=self.dmaTimer,clock_MUL= 15, clock_DIV=42517) - else: - self.dma0 = myDMA(self.dma0Channel,timer=self.dmaTimer,clock_MUL= rate // 2000, clock_DIV=62500) - self.dma1 = myDMA(self.dma1Channel,timer=self.dmaTimer) # don't need to set timer clock - - #setup DMA chain dma0 to dma1 and vice versa - self.dma0.setCtrl(src_inc=True, dst_inc=False,data_size=DMAunitSize,chainTo=self.dma1.channel) - self.dma1.setCtrl(src_inc=True, dst_inc=False,data_size=DMAunitSize,chainTo=self.dma0.channel) - - # need to alternate DMA buffer using a toggle flag - toggle = True - # need to start first frame - First = True - # loop until is done - frameLeft = frameCount - - while frameLeft>0: - # first DMA - if frameLeft < nbFrame: - nbFrame = frameLeft - nbData = nbFrame*2 - if toggle: - t1 = f.readframes(nbFrame) -#--- Duplicate mono audio samples to simulate stereo sound (on both channels) - if channels ==1: - t3 = bytearray(4096) - interleavebytes(uctypes.addressof(t1),uctypes.addressof(t3),nbFrame) - t1=t3 -#--- make t1 stereo data to PWM compatible - convert2PWM(uctypes.addressof(t1), nbData,self.pwmBits) - self.dma1.move(uctypes.addressof(t1),self.leftPWM.PWM_CC,nbFrame*DMAunitSize) - # check if previous DMA is done - while self.dma0.isBusy(): - pass - # start DMA. - # Since they are chained we need to start the first DMA - if First: - self.dma1.start() - First = False - else: - t0 = f.readframes(nbFrame) -#--- Duplicate mono audio samples to simulate stereo sound (on both channels) - if channels == 1: - t3 = bytearray(4096) - interleavebytes(uctypes.addressof(t0),uctypes.addressof(t3),nbFrame) - t0=t3 -#--- make t0 stereo data to PWM compatible - convert2PWM(uctypes.addressof(t0), nbData,self.pwmBits) - self.dma0.move(uctypes.addressof(t0),self.leftPWM.PWM_CC,nbFrame*DMAunitSize) - # check if previous DMA is done - while self.dma1.isBusy(): - pass - toggle = not toggle - frameLeft -= nbFrame - - if toggle: - self.dma1.pause() - while self.dma0.isBusy(): - pass - self.dma0.pause() - else: - self.dma0.pause() - while self.dma1.isBusy(): - pass - self.dma1.pause() - f.close() - self.stop() - -# if you run this class this is the default main -if __name__ == "__main__": - - import uos - from utime import sleep - #import SDCard - - # mount SDCard - #from machine import SPI,Pin - #sd = SDCard.SDCard(SPI(1),Pin(13)) - - #need to pump up the SPI clock rate - # below 3MHz it won't work! - #sd.init_spi(50_000_000) - #uos.mount(sd,"/sd") - - # player = wavePlayer() - player = wavePlayer(leftPin=Pin(15),rightPin=Pin(14)) - waveFolder= "/sounds" - wavelist = [] - - for i in uos.listdir(waveFolder): - if i.find(".wav")>=0: - wavelist.append(waveFolder+"/"+i) - elif i.find(".WAV")>=0: - wavelist.append(waveFolder+"/"+i) - - try: - for i in wavelist: - print(i) - player.play(i) - sleep(1) - except KeyboardInterrupt: - player.stop() diff --git a/src/time/time-functions-test.py b/src/time/time-functions-test.py deleted file mode 100644 index bdcd497ec..000000000 --- a/src/time/time-functions-test.py +++ /dev/null @@ -1,27 +0,0 @@ -from utime import time, gmtime, localtime, sleep - -print('time() in seconds since 1/1/1970:', time()) -print('gmtime():', gmtime()) -print('localtime():', localtime()) - -print('Year:', localtime()[0]) -print('Month:', localtime()[1]) -print('Day:', localtime()[2]) -print('Hour 24:', localtime()[3]) -# print('Hour:', hour, am_pm) -print('Minute:', localtime()[4]) -print('Seconds:', localtime()[5]) - -while True: - hour24 = localtime()[3] - if hour24 > 12: - hour = hour24 - 12 - am_pm = 'pm' - else: - hour = hour24 - am_pm = 'am' - # pad minutes and seconds with leading zeros - minutes = '{:02d}'.format(localtime()[4]) - seconds = '{:02d}'.format(localtime()[5]) - print(localtime()[2], '-', localtime()[1], '-', localtime()[0], ' ', hour, ':', minutes, ':', seconds, ' ', am_pm, sep='') - sleep(1) diff --git a/src/tools/bit-array.py b/src/tools/bit-array.py deleted file mode 100644 index edba28cda..000000000 --- a/src/tools/bit-array.py +++ /dev/null @@ -1,5 +0,0 @@ -b = bytearray(b'\b1111110\b1111101\b1111100\b1111011\b1111010') - -bl=len(b) - -print(bl) \ No newline at end of file diff --git a/src/tools/get-current-time-in-timezone.py b/src/tools/get-current-time-in-timezone.py deleted file mode 100644 index 406639fd3..000000000 --- a/src/tools/get-current-time-in-timezone.py +++ /dev/null @@ -1,27 +0,0 @@ -import requests -import sys -import json -import time -import secrets - -base = 'https://timeapi.io/api/Time/current/zone' -timeZone='America/Chicago' -url = base + '?timeZone=' + timeZone - -print('url: ' + url) - -response = requests.get(url) -if response.status_code != 200: - print('Status:', response.status_code, 'Problem with the request. Exiting.') - print(url) - sys.exit() - -j = response.json() - -#print(j) - -date = j['date'] - -localtime = j['time'] - -print('The time in', timeZone, 'is', localtime , 'on', date) \ No newline at end of file diff --git a/src/tools/get-size-of-test.py b/src/tools/get-size-of-test.py deleted file mode 100644 index bedc9a731..000000000 --- a/src/tools/get-size-of-test.py +++ /dev/null @@ -1,9 +0,0 @@ -import sys - -x = 'a' -# returns 50 bytes - 48 + null + 1 char -print(sys.getsizeof(x)) - -y = 'ab' -# returns 51 bytes -print(sys.getsizeof(y)) \ No newline at end of file diff --git a/src/tools/image-to-byte-array.py b/src/tools/image-to-byte-array.py deleted file mode 100644 index 07a2fbbb4..000000000 --- a/src/tools/image-to-byte-array.py +++ /dev/null @@ -1,4 +0,0 @@ -with open("/tmp/coderdojo-logo.png", "rb") as image: - f = image.read() - b = bytearray(f) - print(b[0]) diff --git a/src/tools/image-to-framebuf.py b/src/tools/image-to-framebuf.py deleted file mode 100644 index 9ed38bf7b..000000000 --- a/src/tools/image-to-framebuf.py +++ /dev/null @@ -1,22 +0,0 @@ -from PIL import Image - -def convert_image_to_framebuffer(image_path): - image = Image.open(image_path).convert('1') # Convert to 1-bit pixels, black and white - image = image.resize((128, 64)) # Resize to 128x64 pixels - pixels = image.load() - - framebuffer = [] - for y in range(64): - byte = 0 - for x in range(128): - if pixels[x, y] == 0: # Black pixel - byte |= (1 << (x % 8)) - if (x % 8) == 7 or x == 127: - framebuffer.append(byte) - byte = 0 - - return framebuffer - -image_path = 'path_to_your_image.png' -framebuffer = convert_image_to_framebuffer(image_path) -print(framebuffer) diff --git a/src/tools/linear-regression-example-with-plot.py b/src/tools/linear-regression-example-with-plot.py deleted file mode 100644 index dd18389e9..000000000 --- a/src/tools/linear-regression-example-with-plot.py +++ /dev/null @@ -1,28 +0,0 @@ -import numpy as np -import plotly.express as px - -# Input data -xplot_values = np.array([(0,0), (.125, 3000), (.25, 11000), (.5, 17000), (.75, 24000), (.8625, 42000), (1.0, 65536)]) -x = xplot_values[:, 0] -y = xplot_values[:, 1] - -# Fit a linear regression model -model = np.polyfit(x, y, 2) - -# Get the slope and intercept of the line -slope, intercept = model - -# Generate a list of x values for the fitted line -x_fit = np.linspace(x.min(), x.max(), 100) - -# Calculate the y values for the fitted line -y_fit = slope * x_fit + intercept - -# Create a Plotly scatter plot of the data -fig = px.scatter(x=x, y=y) - -# Add the fitted line to the plot -fig.add_scatter(x=x_fit, y=y_fit, mode='lines', name='Fit') - -# Show the plot -fig.show() diff --git a/src/tools/linear-regression-example.py b/src/tools/linear-regression-example.py deleted file mode 100644 index c19e59f8a..000000000 --- a/src/tools/linear-regression-example.py +++ /dev/null @@ -1,17 +0,0 @@ -import numpy as np - -# Input data -xplot_values = np.array([(.125, 3000), (.25, 11000), (.5, 17000), (.75, 24000), (.8125, 42000)]) -x = xplot_values[:, 0] -y = xplot_values[:, 1] - -# Fit a linear regression model -model = np.polyfit(x, y, 2) - -print(model) - -# Get the slope and intercept of the line -slope, intercept, sq = model - -# Print the equation of the line -print(f"y = {slope:.2f}x + {intercept:.2f}") diff --git a/src/tools/numpy-polynomual.py b/src/tools/numpy-polynomual.py deleted file mode 100644 index 96ecdda31..000000000 --- a/src/tools/numpy-polynomual.py +++ /dev/null @@ -1,27 +0,0 @@ -import numpy as np -import plotly.express as px - -# Input data -xplot_values = np.array([(0,0), (.125, 3000), (.25, 11000), (.5, 17000), (.75, 24000), (.8625, 42000), (1.0, 65536)]) -x = xplot_values[:, 0] -y = xplot_values[:, 1] - -# Fit a linear regression model -model = np.polynomial(x, y, 2) - -print(model) - -# Generate a list of x values for the fitted line -x_fit = np.linspace(x.min(), x.max(), 100) -y_fit = -# Calculate the y values for the fitted line -#y_fit = slope * x_fit + intercept - -# Create a Plotly scatter plot of the data -#fig = px.scatter(x=x, y=y) - -# Add the fitted line to the plot -#fig.add_scatter(x=x_fit, y=y_fit, mode='lines', name='Fit') - -# Show the plot -#fig.show() diff --git a/src/tools/poly-fit.py b/src/tools/poly-fit.py deleted file mode 100644 index ea2b5438e..000000000 --- a/src/tools/poly-fit.py +++ /dev/null @@ -1,18 +0,0 @@ -#-----POLYNOMIAL FIT---- -x = np.array([1.2,2.5,3.4,4.0,5.4,6.1,7.2,8.1,9.0,10.1,11.2,12.3,13.4,14.1,15.0]) # x coordinates -xplot_values = np.array([(.125, 3000), (.25, 11000), (.5, 17000), (.75, 24000), (.8125, 42000)]) -x = xplot_values[:, 0] -y = xplot_values[:, 1] -fit = np.polyfit(x, y, 2) -a = fit[0] -b = fit[1] -c = fit[2] -fit_equation = a * np.square(x) + b * x + c -#Plotting -fig1 = plt.figure() -ax1 = fig1.subplots() -ax1.plot(x, fit_equation,color = 'r',alpha = 0.5, label = 'Polynomial fit') -ax1.scatter(x, y, s = 5, color = 'b', label = 'Data points') -ax1.set_title('Polynomial fit example') -ax1.legend() -plt.show() \ No newline at end of file diff --git a/src/tools/polyfit-deg-2.py b/src/tools/polyfit-deg-2.py deleted file mode 100644 index a2679a3b1..000000000 --- a/src/tools/polyfit-deg-2.py +++ /dev/null @@ -1,32 +0,0 @@ -import numpy as np -import plotly.express as px - -xplot_values = np.array([(.125, 3000), (.25, 11000), (.5, 17000), (.75, 24000), (.8125, 42000)]) -x = xplot_values[:, 0] -y = xplot_values[:, 1] - -fit = np.polyfit(x, y, 2) - -a = fit[0] -b = fit[1] -c = fit[2] -x_fit = np.linspace(x.min(), x.max(), 100) -y_fit = a * np.square(x) + b * x + c - -# Create a Plotly scatter plot of the data -fig = px.scatter(x=x, y=y) - -# Add the fitted line to the plot -fig.add_scatter(x=x_fit, y=y_fit, mode='lines', name='Fit') - -# Show the plot -fig.show() - -#Plotting -# fig1 = plt.figure() -# ax1 = fig1.subplots() -# ax1.plot(x, fit_equation,color = 'r',alpha = 0.5, label = 'Polynomial fit') -# ax1.scatter(x, y, s = 5, color = 'b', label = 'Data points') -# ax1.set_title('Polynomial fit example') -# ax1.legend() -# plt.show() \ No newline at end of file diff --git a/src/tools/time-test.py b/src/tools/time-test.py deleted file mode 100644 index 78329ea17..000000000 --- a/src/tools/time-test.py +++ /dev/null @@ -1,20 +0,0 @@ -from datetime import datetime -from time import time -current_time = time() - -now = datetime.now() # current date and time - -year = now.strftime("%Y") -print("year:", year) - -month = now.strftime("%m") -print("month:", month) - -day = now.strftime("%d") -print("day:", day) - -time = now.strftime("%H:%M:%S") -print("time:", time) - -date_time = now.strftime("%m/%d/%Y, %H:%M:%S") -print("date and time:",date_time) \ No newline at end of file diff --git a/src/tools/toggle-color.py b/src/tools/toggle-color.py deleted file mode 100644 index 1e42986bc..000000000 --- a/src/tools/toggle-color.py +++ /dev/null @@ -1,17 +0,0 @@ -b = bytearray(b'\x01\x02\x03\x04\x05') - -bl=len(b) - -for i in range(bl): - m = 0x40 # mask the most significant in a an 8 bit byte - print('\\b', end='') - outstr = '' - for bit in range(0,7): - x = b[i] & m # and with one bit mask - if x != 0: - print(0, end='') - - else: - print(1, end='') - m = m >> 1 - print('') \ No newline at end of file diff --git a/src/tools/web-get-tester.py b/src/tools/web-get-tester.py deleted file mode 100644 index 40fcd5ee2..000000000 --- a/src/tools/web-get-tester.py +++ /dev/null @@ -1,46 +0,0 @@ -# create a web get request and test the response -import requests -import sys -import json -import time -import secrets - -base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&' -location = '5037649' # twin cities -url = base + 'id=' + location + '&appid=' + secrets.appid - -print('url: ' + url) - -response = requests.get(url) -if response.status_code != 200: - print('Status:', response.status_code, 'Problem with the request. Exiting.') - print(url) - sys.exit() - -# Our response data in JSON format -jd = response.json() - -date_time_int = int(jd['list'][0]['dt']) -timezone = int(jd['city']['timezone']) -print('date time int', date_time_int, 'timezone:', timezone) - -print('City:', response.json() ['city']['name']) - -""" -for i in range(0, 12): - print('temp:', response.json() ['list'][i]['main']['temp']) - print('feels like:', response.json() ['list'][i]['main']['feels_like']) - print(response.json() ['list'][i]['weather'][0]['description']) - print('DateTime:', response.json() ['list'][i]['dt_txt']) - print() -""" -for i in range(0, 16): - localtime = int(jd['list'][i]['dt']) + timezone - print(time.gmtime(localtime), ' ', sep='', end='') - print() - -for i in range(0, 16): - print(jd['list'][i]['dt_txt'][5:13], ' ', sep='', end='') -print() -for i in range(0, 16): - print(round(jd['list'][i]['main']['temp']), ' ', end='') \ No newline at end of file diff --git a/src/unix-scripts/board.py b/src/unix-scripts/board.py deleted file mode 100644 index 6456887f8..000000000 --- a/src/unix-scripts/board.py +++ /dev/null @@ -1 +0,0 @@ -name="pico" diff --git a/src/unix-scripts/check-usb.sh b/src/unix-scripts/check-usb.sh deleted file mode 100755 index d20258af0..000000000 --- a/src/unix-scripts/check-usb.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# check if the character file exists -if [ -c /dev/cu.usbmodem14101 ]; then - echo /dev/cu.usbmodem14101 exists -else - echo file /dev/cu.usbmodem14101 does not exist -fi diff --git a/src/unix-scripts/init-pico.sh b/src/unix-scripts/init-pico.sh deleted file mode 100755 index 5a3f79273..000000000 --- a/src/unix-scripts/init-pico.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# UNIX shell script to initialize RP2040 files for bots -# write the file to change the name to be /pico -rshell -p /dev/cu.usbmodem14101 echo 'name="pico"' > /pyboard/board.py -rshell -p /dev/cu.usbmodem14101 cp board.py /pyboard diff --git a/src/unix-scripts/load-libs.sh b/src/unix-scripts/load-libs.sh deleted file mode 100755 index 74f39723b..000000000 --- a/src/unix-scripts/load-libs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# UNIX shell script to load drivers into /pico/lib filesystem -DRIVERS=~/Documents/ws/micropython/src/drivers -# copy the driver files -rshell -p /dev/cu.usbmodem14101 mkdir /pico/lib -rshell -p /dev/cu.usbmodem14101 cp $DRIVERS/*.py /pico/lib diff --git a/src/unix-scripts/load-tof-display-libs.sh b/src/unix-scripts/load-tof-display-libs.sh deleted file mode 100755 index 6027b08b2..000000000 --- a/src/unix-scripts/load-tof-display-libs.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# UNIX shell script to load drivers into /pico/lib filesystem -DRIVERS=~/Documents/ws/micropython/src/drivers -# create the /pico lib dir if it does not exist -rshell -p /dev/cu.usbmodem14101 mkdir /pico/lib -# Copy the driver files -# Copy the display driver -rshell -p /dev/cu.usbmodem14101 cp $DRIVERS/ssd1306.py /pico/lib -# Copy tne time of flight distance sensor -rshell -p /dev/cu.usbmodem14101 cp $DRIVERS/VL53L0X.py /pico/lib - diff --git a/src/unix-scripts/load-tof-display.sh b/src/unix-scripts/load-tof-display.sh deleted file mode 100755 index fafb18eab..000000000 --- a/src/unix-scripts/load-tof-display.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# UNIX shell script to initialize RP2040 files for bots -CMD=rshell -p /dev/cu.usbmodem14101 --buffer-size 512 -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp /Documents/ws/micropython/src/kits/maker-pi-rp2040-robots/tof-display-bot/i2c-scanner.py /pico -SOURCE_FILES=~/Documents/ws/micropython/src/kits/maker-pi-rp2040-robots/tof-display-bot -# write the files to the /pico -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp $SOURCE_FILES/i2c-scanner.py /pico -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp $SOURCE_FILES/motor-connection-test.py /pico -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp $SOURCE_FILES/tof-display-test.py /pico -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp $SOURCE_FILES/collision-avoidance-tof.py /pico -rshell -p /dev/cu.usbmodem14101 --buffer-size 512 cp $SOURCE_FILES/collision-avoidance-tof-eyes.py /pico diff --git a/src/unix-scripts/run.sh b/src/unix-scripts/run.sh deleted file mode 100755 index f717ff70c..000000000 --- a/src/unix-scripts/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -echo 'running init' -./init-pico.sh -echo 'running load libraries' -./load-libs.sh -echo 'running programs' -./load-tof-display.py diff --git a/status/index.html b/status/index.html new file mode 100644 index 000000000..7dedf58cf --- /dev/null +++ b/status/index.html @@ -0,0 +1,1368 @@ + + + + + + + + + + + + + + + + + + + + + + + Status of MicroPython Labs - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + Status of MicroPython Labs + + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                            • + + + Project Boxes + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + 10 Element LED Box + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + Time of Flight Distance Sensor Display Box + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + Pot Display Box + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + Compass Lab Box + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                            Status of MicroPython Labs

                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                            Project Boxes

                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                            10 Element LED Box

                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                            1. Box finished
                                                                                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                                                                                            3. Video done
                                                                                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                                                                                            5. +
                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                            Time of Flight Distance Sensor Display Box

                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                            1. Box finished
                                                                                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                                                                                            3. TODO: Video
                                                                                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                            Pot Display Box

                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                            1. Box finsished
                                                                                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                                                                                            3. Video finished
                                                                                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                            Compass Lab Box

                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                            1. Box finished
                                                                                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/test-colors.py b/test-colors.py deleted file mode 100644 index 4d8b51bcf..000000000 --- a/test-colors.py +++ /dev/null @@ -1,37 +0,0 @@ -from machine import Pin -from neopixel import NeoPixel -from utime import sleep, ticks_ms -from urandom import randint - -NEOPIXEL_PIN = 0 -# This is the best number of pixels for most hats -# if you use 160 pixels/meter strips -NUMBER_PIXELS = 36 -strip = NeoPixel(Pin(NEOPIXEL_PIN), NUMBER_PIXELS) - -red = (255,0,0) -orange = (255,70,0) -yellow = (255,255,0) -green = (0, 255, 0) -green_med = (0,32, 0) -green_light = (0, 8, 0) -blue = (0,0,255) -off = (0, 0, 0) -orange = (140, 60, 0) -white = (255, 255, 255) -colors = (red, orange, yellow, green, blue) -color_count = len(colors) -levels = [255, 128, 64, 32, 16, 8, 4, 2, 1] -level_count = len(levels) - -def solid_color(color, delay): - for i in range(0, NUMBER_PIXELS-1): - strip[i] = color; - strip.write() - sleep(delay) - -while True: - solid_color(red, 1) - solid_color(white, 1) - solid_color(blue, 1) - diff --git a/theme/partials/footer.html b/theme/partials/footer.html deleted file mode 100755 index e37a7520c..000000000 --- a/theme/partials/footer.html +++ /dev/null @@ -1,57 +0,0 @@ -{#- - This file is required to override the default MkDocs footer - do not edit - -#} - {% import "partials/language.html" as lang with context %} -
                                                                                                                                                                                                                                                                                                                                                                                            - {% if page.previous_page or page.next_page %} -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - {% if page.previous_page %} - -
                                                                                                                                                                                                                                                                                                                                                                                            - -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - - - {{ lang.t("footer.previous") }} - - {{ page.previous_page.title }} - -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - {% endif %} - {% if page.next_page %} - -
                                                                                                                                                                                                                                                                                                                                                                                            - - - {{ lang.t("footer.next") }} - - {{ page.next_page.title }} - -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - {% endif %} -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - {% endif %} -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            - {% if config.copyright %} -
                                                                                                                                                                                                                                                                                                                                                                                            - {{ config.copyright }} -
                                                                                                                                                                                                                                                                                                                                                                                            - {% endif %} - All content including images are licenses under - Creative Commons - Attribution NonCommercial ShareAlike -
                                                                                                                                                                                                                                                                                                                                                                                            - {% include "partials/social.html" %} -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                                                                                                            diff --git a/wireless/01-intro/index.html b/wireless/01-intro/index.html new file mode 100644 index 000000000..1fc32530d --- /dev/null +++ b/wireless/01-intro/index.html @@ -0,0 +1,1685 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Introduction - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + Introduction + + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Introduction + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Raspberry Pi Pico W + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + ESP32 Wireless + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + Raspberry Pi Pico W + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              • + + + ESP32 Wireless + + + +
                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                              Introduction to Networking with MicroPython

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              These lessons are designed to give our students an understanding of how wireless communications work with MicroPython.

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              Raspberry Pi Pico W

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              Raspberry Pi Pico W

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              One June 30th, 2022 the Raspberry Pi Foundation announced the availability of the Raspberry Pi Pico W. This $6 microprocessor now supports WiFi and with a software upgrade it may soon support Bluetooth.

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              The Pico W supports 2.4 Ghz 802.11n wireless networking. For MicroPython, we can use a MicroPython library built around the lwip TCP/IP stack. This stack is accessible using the MicroPython network functions.

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              The WiFi chip used is the Infineon CYW43439 chip. This chip also uses an ARM architecture and has extensive support for Bluetooth wireless communication.

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              Wireless Block Architecture

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              You can read more about the capabilities of the WiFi/Bluetooth chip by reading the Infineon CYW43439 Datasheet. I found it interesting that the CYW43439 chip has 512KB of SRAM - almost double what the RP2040 chip contains!

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              ESP32 Wireless

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              We have not integrated the ESP32 into our labs. We suggest you try the following links:

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              ESP32 MicroPython: Connecting to a WiFi Network on Tech Tutorials SX

                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                              MicroPython: Wi-Fi Manager with ESP32 (ESP8266 compatible) on Random Nerd Tutorials

                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                              + Converting Audio Files +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                              + Connecting to WiFi +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/wireless/02-connecting-to-wifi/index.html b/wireless/02-connecting-to-wifi/index.html new file mode 100644 index 000000000..ce8f401d7 --- /dev/null +++ b/wireless/02-connecting-to-wifi/index.html @@ -0,0 +1,1878 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Connecting to WiFi - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + Connecting to WiFi + + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + Connecting to WiFi + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Setting Up Your WIFI secrets.py + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Testing Your WiFi Access Point Connection + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Waiting for a Valid Access Point Connection + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Error Handling + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + Setting Up Your WIFI secrets.py + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + Testing Your WiFi Access Point Connection + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + Waiting for a Valid Access Point Connection + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                • + + + Error Handling + + + +
                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                Connecting to a WiFi Network

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Setting Up Your WIFI secrets.py

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                By convention, we put both our SSID and password in a python file called "secrets.py". This file should never be checked into a public source code repository. We can add secrets.py to the .gitignore file to make sure the secrets.py is never checked into GitHub and exposing your passwords to everyone.

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                SSID = "MY_WIFI_NETWORK_NAME"
                                                                                                                                                                                                                                                                                                                                                                                                +PASSWORD = "MY_WIFI_PASSWORD"
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                By importing the secrets.py file you can then reference your network name like this:

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Testing Your WiFi Access Point Connection

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Here is a very simple script to test see if your network name and password are correct. This script may work, but as we will see, it is both slow and potentially unreliable.

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                                                import network
                                                                                                                                                                                                                                                                                                                                                                                                +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                +from utime import sleep
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan.active(True) # power up the WiFi chip
                                                                                                                                                                                                                                                                                                                                                                                                +print('Waiting for wifi chip to power up...')
                                                                                                                                                                                                                                                                                                                                                                                                +sleep(3) # wait three seconds for the chip to power up and initialize
                                                                                                                                                                                                                                                                                                                                                                                                +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                +print('Waiting for access point to log us in.')
                                                                                                                                                                                                                                                                                                                                                                                                +sleep(2)
                                                                                                                                                                                                                                                                                                                                                                                                +if wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                +  print('Success! We have connected to your access point!')
                                                                                                                                                                                                                                                                                                                                                                                                +  print('Try to ping the device at', wlan.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                +else:
                                                                                                                                                                                                                                                                                                                                                                                                +  print('Failure! We have not connected to your access point!  Check your secrets.py file for errors.')
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Returns:

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                                                                                                                Connecting to WiFi Network Name: MY_WIFI_NETWORK_NAME
                                                                                                                                                                                                                                                                                                                                                                                                +Waiting for wifi chip to power up...
                                                                                                                                                                                                                                                                                                                                                                                                +Waiting for access point to log us in...
                                                                                                                                                                                                                                                                                                                                                                                                +Success! We have connected to your access point!
                                                                                                                                                                                                                                                                                                                                                                                                +Try to ping the device at 10.0.0.70
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                If the result is a Failure you should check the name of the network and the password and that you are getting a strong WiFi signal where you are testing.

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Note that we are using the sleep() function to insert delays into our code. However, the results may actually be faster or slower than our sleep times. Our next step is to add logic that will test to see if the networking device is ready and if our local access point allows us to login correctly.

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Waiting for a Valid Access Point Connection

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Sometimes we want to keep checking if our access point is connected before we begin using our connection. To do this we can create a while loop and continue in the loop while we are not connected.

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                                                +20
                                                                                                                                                                                                                                                                                                                                                                                                +21
                                                                                                                                                                                                                                                                                                                                                                                                +22
                                                                                                                                                                                                                                                                                                                                                                                                import network
                                                                                                                                                                                                                                                                                                                                                                                                +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +if not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                +    print("Waiting for connection...")
                                                                                                                                                                                                                                                                                                                                                                                                +    counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                +    while not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                +        sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                +        print(counter, '.', sep='', end='', )
                                                                                                                                                                                                                                                                                                                                                                                                +        counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +delta = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                +print("Connect Time:", delta, 'milliseconds')
                                                                                                                                                                                                                                                                                                                                                                                                +print('IP Address:', wlan.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                This code also supports a timer that will display the number of seconds for the access point to become valid in the console. The first time after you power on, this may take several seconds. After you are connected the connection will be cached and the time will be 0 milliseconds.

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                First run upon power on might take several seconds: +

                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                                                                                                                >>> %Run -c $EDITOR_CONTENT
                                                                                                                                                                                                                                                                                                                                                                                                +Connecting to WiFi Network Name: MY_NETWORK_NAME
                                                                                                                                                                                                                                                                                                                                                                                                +Waiting for connection...
                                                                                                                                                                                                                                                                                                                                                                                                +0.1.2.3.Connect Time: 4640
                                                                                                                                                                                                                                                                                                                                                                                                +IP Address: 10.0.0.70
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                The second and consecutive runs will use a cached connection.

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                                                                                                                >>> %Run -c $EDITOR_CONTENT
                                                                                                                                                                                                                                                                                                                                                                                                +Connecting to WiFi Network Name: MY_NETWORK_NAME
                                                                                                                                                                                                                                                                                                                                                                                                +Connect Time: 0 milliseconds
                                                                                                                                                                                                                                                                                                                                                                                                +IP Address: 10.0.0.70
                                                                                                                                                                                                                                                                                                                                                                                                +>>>
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                Error Handling

                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                                                +20
                                                                                                                                                                                                                                                                                                                                                                                                lan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                +wlan.connect(ssid, password)
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +# Wait for connect or fail
                                                                                                                                                                                                                                                                                                                                                                                                +max_wait = 10
                                                                                                                                                                                                                                                                                                                                                                                                +while max_wait > 0:
                                                                                                                                                                                                                                                                                                                                                                                                +  if wlan.status() < 0 or wlan.status() >= 3:
                                                                                                                                                                                                                                                                                                                                                                                                +    break
                                                                                                                                                                                                                                                                                                                                                                                                +  max_wait -= 1
                                                                                                                                                                                                                                                                                                                                                                                                +  print('waiting for connection...')
                                                                                                                                                                                                                                                                                                                                                                                                +  time.sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +# Handle connection error
                                                                                                                                                                                                                                                                                                                                                                                                +if wlan.status() != 3:
                                                                                                                                                                                                                                                                                                                                                                                                +   raise RuntimeError('network connection failed')
                                                                                                                                                                                                                                                                                                                                                                                                +else:
                                                                                                                                                                                                                                                                                                                                                                                                +  print('connected')
                                                                                                                                                                                                                                                                                                                                                                                                +  status = wlan.ifconfig()
                                                                                                                                                                                                                                                                                                                                                                                                +  print( 'ip = ' + status[0] )
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                The full TCP/IP stack is running on your Pico W. You should be able to ping the pico using the IP address returned by the status[0] of the wlan.ifconfig() function above.

                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                + Introduction +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                + HTTP GET +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/wireless/03-http-get/index.html b/wireless/03-http-get/index.html new file mode 100644 index 000000000..835bc8194 --- /dev/null +++ b/wireless/03-http-get/index.html @@ -0,0 +1,1719 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + HTTP GET - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + HTTP GET + + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + HTTP GET + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Testing HTTP GET + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Testing HTTP GET + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                  HTTP GET

                                                                                                                                                                                                                                                                                                                                                                                                  + +

                                                                                                                                                                                                                                                                                                                                                                                                  Testing HTTP GET

                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                  The following example was taken from Tom's Hardware

                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                                                                                  +13
                                                                                                                                                                                                                                                                                                                                                                                                  +14
                                                                                                                                                                                                                                                                                                                                                                                                  +15
                                                                                                                                                                                                                                                                                                                                                                                                  +16
                                                                                                                                                                                                                                                                                                                                                                                                  +17
                                                                                                                                                                                                                                                                                                                                                                                                  +18
                                                                                                                                                                                                                                                                                                                                                                                                  +19
                                                                                                                                                                                                                                                                                                                                                                                                  +20
                                                                                                                                                                                                                                                                                                                                                                                                  +21
                                                                                                                                                                                                                                                                                                                                                                                                  import network
                                                                                                                                                                                                                                                                                                                                                                                                  +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                  +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                  +import urequests
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                  +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                  +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +astronauts = urequests.get("http://api.open-notify.org/astros.json").json()
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +delta = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +number = astronauts['number']
                                                                                                                                                                                                                                                                                                                                                                                                  +print('There are', number, 'astronauts in space.')
                                                                                                                                                                                                                                                                                                                                                                                                  +for i in range(number):
                                                                                                                                                                                                                                                                                                                                                                                                  +    print(i+1, astronauts['people'][i]['name'])
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +print("HTTP GET Time in milliseconds:", delta)
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                  Returns:

                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                   1
                                                                                                                                                                                                                                                                                                                                                                                                  + 2
                                                                                                                                                                                                                                                                                                                                                                                                  + 3
                                                                                                                                                                                                                                                                                                                                                                                                  + 4
                                                                                                                                                                                                                                                                                                                                                                                                  + 5
                                                                                                                                                                                                                                                                                                                                                                                                  + 6
                                                                                                                                                                                                                                                                                                                                                                                                  + 7
                                                                                                                                                                                                                                                                                                                                                                                                  + 8
                                                                                                                                                                                                                                                                                                                                                                                                  + 9
                                                                                                                                                                                                                                                                                                                                                                                                  +10
                                                                                                                                                                                                                                                                                                                                                                                                  +11
                                                                                                                                                                                                                                                                                                                                                                                                  +12
                                                                                                                                                                                                                                                                                                                                                                                                  There are 10 astronauts in space.
                                                                                                                                                                                                                                                                                                                                                                                                  +1 Oleg Artemyev
                                                                                                                                                                                                                                                                                                                                                                                                  +2 Denis Matveev
                                                                                                                                                                                                                                                                                                                                                                                                  +3 Sergey Korsakov
                                                                                                                                                                                                                                                                                                                                                                                                  +4 Kjell Lindgren
                                                                                                                                                                                                                                                                                                                                                                                                  +5 Bob Hines
                                                                                                                                                                                                                                                                                                                                                                                                  +6 Samantha Cristoforetti
                                                                                                                                                                                                                                                                                                                                                                                                  +7 Jessica Watkins
                                                                                                                                                                                                                                                                                                                                                                                                  +8 Cai Xuzhe
                                                                                                                                                                                                                                                                                                                                                                                                  +9 Chen Dong
                                                                                                                                                                                                                                                                                                                                                                                                  +10 Liu Yang
                                                                                                                                                                                                                                                                                                                                                                                                  +HTTP GET Time in milliseconds: 786
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                  + Connecting to WiFi +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                  + Web Server +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/wireless/04-web-server/index.html b/wireless/04-web-server/index.html new file mode 100644 index 000000000..072f3233d --- /dev/null +++ b/wireless/04-web-server/index.html @@ -0,0 +1,1836 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Web Server - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + Web Server + + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + Web Server + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                    Web Server with MicroPython

                                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                                    This program turns your Pico W into a small web server. The web page has two links on it. One link will turn the on-board LED on and the other link will turn the LED off.

                                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                                    Screen image of Pico W Web Server: +

                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                     1
                                                                                                                                                                                                                                                                                                                                                                                                    + 2
                                                                                                                                                                                                                                                                                                                                                                                                    + 3
                                                                                                                                                                                                                                                                                                                                                                                                    + 4
                                                                                                                                                                                                                                                                                                                                                                                                    + 5
                                                                                                                                                                                                                                                                                                                                                                                                    + 6
                                                                                                                                                                                                                                                                                                                                                                                                    + 7
                                                                                                                                                                                                                                                                                                                                                                                                    + 8
                                                                                                                                                                                                                                                                                                                                                                                                    + 9
                                                                                                                                                                                                                                                                                                                                                                                                    +10
                                                                                                                                                                                                                                                                                                                                                                                                    +11
                                                                                                                                                                                                                                                                                                                                                                                                    +12
                                                                                                                                                                                                                                                                                                                                                                                                    +13
                                                                                                                                                                                                                                                                                                                                                                                                    +14
                                                                                                                                                                                                                                                                                                                                                                                                    +15
                                                                                                                                                                                                                                                                                                                                                                                                    +16
                                                                                                                                                                                                                                                                                                                                                                                                    +17
                                                                                                                                                                                                                                                                                                                                                                                                    +18
                                                                                                                                                                                                                                                                                                                                                                                                    +19
                                                                                                                                                                                                                                                                                                                                                                                                    +20
                                                                                                                                                                                                                                                                                                                                                                                                    +21
                                                                                                                                                                                                                                                                                                                                                                                                    +22
                                                                                                                                                                                                                                                                                                                                                                                                    +23
                                                                                                                                                                                                                                                                                                                                                                                                    +24
                                                                                                                                                                                                                                                                                                                                                                                                    +25
                                                                                                                                                                                                                                                                                                                                                                                                    +26
                                                                                                                                                                                                                                                                                                                                                                                                    +27
                                                                                                                                                                                                                                                                                                                                                                                                    +28
                                                                                                                                                                                                                                                                                                                                                                                                    +29
                                                                                                                                                                                                                                                                                                                                                                                                    +30
                                                                                                                                                                                                                                                                                                                                                                                                    +31
                                                                                                                                                                                                                                                                                                                                                                                                    +32
                                                                                                                                                                                                                                                                                                                                                                                                    +33
                                                                                                                                                                                                                                                                                                                                                                                                    +34
                                                                                                                                                                                                                                                                                                                                                                                                    +35
                                                                                                                                                                                                                                                                                                                                                                                                    +36
                                                                                                                                                                                                                                                                                                                                                                                                    +37
                                                                                                                                                                                                                                                                                                                                                                                                    +38
                                                                                                                                                                                                                                                                                                                                                                                                    +39
                                                                                                                                                                                                                                                                                                                                                                                                    +40
                                                                                                                                                                                                                                                                                                                                                                                                    +41
                                                                                                                                                                                                                                                                                                                                                                                                    +42
                                                                                                                                                                                                                                                                                                                                                                                                    +43
                                                                                                                                                                                                                                                                                                                                                                                                    +44
                                                                                                                                                                                                                                                                                                                                                                                                    +45
                                                                                                                                                                                                                                                                                                                                                                                                    +46
                                                                                                                                                                                                                                                                                                                                                                                                    +47
                                                                                                                                                                                                                                                                                                                                                                                                    +48
                                                                                                                                                                                                                                                                                                                                                                                                    +49
                                                                                                                                                                                                                                                                                                                                                                                                    +50
                                                                                                                                                                                                                                                                                                                                                                                                    +51
                                                                                                                                                                                                                                                                                                                                                                                                    +52
                                                                                                                                                                                                                                                                                                                                                                                                    +53
                                                                                                                                                                                                                                                                                                                                                                                                    +54
                                                                                                                                                                                                                                                                                                                                                                                                    +55
                                                                                                                                                                                                                                                                                                                                                                                                    +56
                                                                                                                                                                                                                                                                                                                                                                                                    +57
                                                                                                                                                                                                                                                                                                                                                                                                    +58
                                                                                                                                                                                                                                                                                                                                                                                                    +59
                                                                                                                                                                                                                                                                                                                                                                                                    +60
                                                                                                                                                                                                                                                                                                                                                                                                    +61
                                                                                                                                                                                                                                                                                                                                                                                                    +62
                                                                                                                                                                                                                                                                                                                                                                                                    +63
                                                                                                                                                                                                                                                                                                                                                                                                    +64
                                                                                                                                                                                                                                                                                                                                                                                                    +65
                                                                                                                                                                                                                                                                                                                                                                                                    +66
                                                                                                                                                                                                                                                                                                                                                                                                    +67
                                                                                                                                                                                                                                                                                                                                                                                                    +68
                                                                                                                                                                                                                                                                                                                                                                                                    +69
                                                                                                                                                                                                                                                                                                                                                                                                    +70
                                                                                                                                                                                                                                                                                                                                                                                                    +71
                                                                                                                                                                                                                                                                                                                                                                                                    +72
                                                                                                                                                                                                                                                                                                                                                                                                    +73
                                                                                                                                                                                                                                                                                                                                                                                                    +74
                                                                                                                                                                                                                                                                                                                                                                                                    +75
                                                                                                                                                                                                                                                                                                                                                                                                    +76
                                                                                                                                                                                                                                                                                                                                                                                                    +77
                                                                                                                                                                                                                                                                                                                                                                                                    +78
                                                                                                                                                                                                                                                                                                                                                                                                    +79
                                                                                                                                                                                                                                                                                                                                                                                                    +80
                                                                                                                                                                                                                                                                                                                                                                                                    +81
                                                                                                                                                                                                                                                                                                                                                                                                    +82
                                                                                                                                                                                                                                                                                                                                                                                                    +83
                                                                                                                                                                                                                                                                                                                                                                                                    +84
                                                                                                                                                                                                                                                                                                                                                                                                    +85
                                                                                                                                                                                                                                                                                                                                                                                                    +86
                                                                                                                                                                                                                                                                                                                                                                                                    +87
                                                                                                                                                                                                                                                                                                                                                                                                    +88
                                                                                                                                                                                                                                                                                                                                                                                                    # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/
                                                                                                                                                                                                                                                                                                                                                                                                    +import network
                                                                                                                                                                                                                                                                                                                                                                                                    +import socket
                                                                                                                                                                                                                                                                                                                                                                                                    +import time
                                                                                                                                                                                                                                                                                                                                                                                                    +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +from machine import Pin
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +# Select the onboard LED
                                                                                                                                                                                                                                                                                                                                                                                                    +led = machine.Pin("LED", machine.Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                    +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                    +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                    +stateis = "LED is OFF"
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +html = """<!DOCTYPE html>
                                                                                                                                                                                                                                                                                                                                                                                                    +<html>
                                                                                                                                                                                                                                                                                                                                                                                                    +   <head>
                                                                                                                                                                                                                                                                                                                                                                                                    +     <title>Web Server On Pico W </title>
                                                                                                                                                                                                                                                                                                                                                                                                    +   </head>
                                                                                                                                                                                                                                                                                                                                                                                                    +  <body>
                                                                                                                                                                                                                                                                                                                                                                                                    +      <h1>Pico Wireless Web Server</h1>
                                                                                                                                                                                                                                                                                                                                                                                                    +      <p>%s</p>
                                                                                                                                                                                                                                                                                                                                                                                                    +      <a href="/light/on">Turn On</a>
                                                                                                                                                                                                                                                                                                                                                                                                    +      <a href="/light/off">Turn Off</a>
                                                                                                                                                                                                                                                                                                                                                                                                    +  </body>
                                                                                                                                                                                                                                                                                                                                                                                                    +</html>
                                                                                                                                                                                                                                                                                                                                                                                                    +"""
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +# Wait for connect or fail
                                                                                                                                                                                                                                                                                                                                                                                                    +max_wait = 10
                                                                                                                                                                                                                                                                                                                                                                                                    +while max_wait > 0:
                                                                                                                                                                                                                                                                                                                                                                                                    +  if wlan.status() < 0 or wlan.status() >= 3:
                                                                                                                                                                                                                                                                                                                                                                                                    +    break
                                                                                                                                                                                                                                                                                                                                                                                                    +  max_wait -= 1
                                                                                                                                                                                                                                                                                                                                                                                                    +  print('waiting for connection...')
                                                                                                                                                                                                                                                                                                                                                                                                    +  time.sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +# Handle connection error
                                                                                                                                                                                                                                                                                                                                                                                                    +if wlan.status() != 3:
                                                                                                                                                                                                                                                                                                                                                                                                    +  raise RuntimeError('network connection failed')
                                                                                                                                                                                                                                                                                                                                                                                                    +else:
                                                                                                                                                                                                                                                                                                                                                                                                    +  print('We are connected to WiFI access point:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                    +  status = wlan.ifconfig()
                                                                                                                                                                                                                                                                                                                                                                                                    +  print( 'The IP address of the pico W is:', status[0] )
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +# Open socket
                                                                                                                                                                                                                                                                                                                                                                                                    +addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
                                                                                                                                                                                                                                                                                                                                                                                                    +print('addr:', addr)
                                                                                                                                                                                                                                                                                                                                                                                                    +s = socket.socket()
                                                                                                                                                                                                                                                                                                                                                                                                    +#if not addr:
                                                                                                                                                                                                                                                                                                                                                                                                    +s.bind(addr)
                                                                                                                                                                                                                                                                                                                                                                                                    +s.listen(1)
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +print('listening on', addr)
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +# Listen for connections
                                                                                                                                                                                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                                                                                                                                                                                    +  try:
                                                                                                                                                                                                                                                                                                                                                                                                    +    cl, addr = s.accept()
                                                                                                                                                                                                                                                                                                                                                                                                    +    print('client connected from', addr)
                                                                                                                                                                                                                                                                                                                                                                                                    +    request = cl.recv(1024)
                                                                                                                                                                                                                                                                                                                                                                                                    +    print(request)
                                                                                                                                                                                                                                                                                                                                                                                                    +    request = str(request)
                                                                                                                                                                                                                                                                                                                                                                                                    +    led_on = request.find('/light/on')
                                                                                                                                                                                                                                                                                                                                                                                                    +    led_off = request.find('/light/off')
                                                                                                                                                                                                                                                                                                                                                                                                    +    print( 'led on = ' + str(led_on))
                                                                                                                                                                                                                                                                                                                                                                                                    +    print( 'led off = ' + str(led_off))
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +    if led_on == 6:
                                                                                                                                                                                                                                                                                                                                                                                                    +      print("led on")
                                                                                                                                                                                                                                                                                                                                                                                                    +      led.value(1)
                                                                                                                                                                                                                                                                                                                                                                                                    +      stateis = "LED is ON"
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +    if led_off == 6:
                                                                                                                                                                                                                                                                                                                                                                                                    +      print("led off")
                                                                                                                                                                                                                                                                                                                                                                                                    +      led.value(0)
                                                                                                                                                                                                                                                                                                                                                                                                    +      stateis = "LED is OFF"
                                                                                                                                                                                                                                                                                                                                                                                                    +    # generate the we page with the stateis as a parameter
                                                                                                                                                                                                                                                                                                                                                                                                    +    response = html % stateis
                                                                                                                                                                                                                                                                                                                                                                                                    +    cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
                                                                                                                                                                                                                                                                                                                                                                                                    +    cl.send(response)
                                                                                                                                                                                                                                                                                                                                                                                                    +    cl.close()
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +  except OSError as e:
                                                                                                                                                                                                                                                                                                                                                                                                    +    cl.close()
                                                                                                                                                                                                                                                                                                                                                                                                    +    print('connection closed')
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                                    References

                                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                    + HTTP GET +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                    + Web Server NeoPixel +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/wireless/05-mac-address/index.html b/wireless/05-mac-address/index.html new file mode 100644 index 000000000..c4c6b84e4 --- /dev/null +++ b/wireless/05-mac-address/index.html @@ -0,0 +1,1785 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + MAC Address - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + MAC Address + + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + MAC Address + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + What is a MAC Address? + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + Getting the MAC/Ethernet Access + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + MAC Addresses and Privacy + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + What is a MAC Address? + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Getting the MAC/Ethernet Access + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + + + MAC Addresses and Privacy + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                      Getting Your MAC Address

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      What is a MAC Address?

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Every device that works with Ethernet and WiFi must have a Wikipedia Page on MAC Address.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      A MAC address (media access control address) is a unique identifier assigned to a network interface controller (NIC) for use as a network address in communications within a network segment. This use is common in most IEEE 802 networking technologies, including Ethernet, Wi-Fi, and Bluetooth.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Note

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      The MAC address has nothing to do with the Apple Macintosh or Mac OS. They just use the same name to mean different things.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Understanding how devices use MAC addresses is essential to understanding how networks work and debugging them.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      The MAC address is six bytes or "octets". The first three octets are assigned to the organization that created the device. The second three octets are assigned by the organization that created the device. See the Wikipedia Page on MAC Address for more information. If you run this on your Pico W the first octets should be similar.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Here are the two MAC addresses for two different Pico W devices that were purchase together. They came on adjacent parts of a "real" of devices.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                                                                                      28:cd:c1:1:35:54
                                                                                                                                                                                                                                                                                                                                                                                                      +28:cd:c1:1:35:58
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Because they were purchased together, their MAC address are very similar and only differ in the last few bits.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      This Pico W came from another distributer.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                                                      28:cd:c1:0:9e:19
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      You can see that the first three octets are the same. A MAC address often can give clues about the origins of packets on your network. They can also be used as "serial numbers" for each device that connects to WiFi or Ethernet since they are usually burned into ROM at device manufacturing time and are designed to be unique.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Getting the MAC/Ethernet Access

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      You can get the device MAC/Ethernet address and test the roundtrip time between the RP2040 and the WiFi chip using the MAC address function.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                                                                                                      import network
                                                                                                                                                                                                                                                                                                                                                                                                      +from utime import sleep, ticks_us, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +print('Getting MAC/Ethernet Address for this device.')
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +start = ticks_us() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                      +wlan.active(True) # this line powers up the chip - it takes about 2.5 seconds
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +# This returns a byte array of hex numbers
                                                                                                                                                                                                                                                                                                                                                                                                      +mac_addess = wlan.config('mac')
                                                                                                                                                                                                                                                                                                                                                                                                      +print('Time in microseconds:', ticks_diff(ticks_us(), start))
                                                                                                                                                                                                                                                                                                                                                                                                      +# each MAC address is 6 bytes or 48 bits
                                                                                                                                                                                                                                                                                                                                                                                                      +print("Hex byte array:", mac_addess, 'length:', len(mac_addess))
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +# This should be in hex per the Notational Conventions
                                                                                                                                                                                                                                                                                                                                                                                                      +# https://en.wikipedia.org/wiki/MAC_address#Notational_conventions
                                                                                                                                                                                                                                                                                                                                                                                                      +# b'(\xcd\xc1\x015X'
                                                                                                                                                                                                                                                                                                                                                                                                      +# 28:cd:c1:1:35:58
                                                                                                                                                                                                                                                                                                                                                                                                      +# format in MAC Notational Convention
                                                                                                                                                                                                                                                                                                                                                                                                      +for digit in range(0,5):
                                                                                                                                                                                                                                                                                                                                                                                                      +    print(str(hex(mac_addess[digit]))[2:4], ':', sep='', end = '')
                                                                                                                                                                                                                                                                                                                                                                                                      +print(str(hex(mac_addess[5]))[2:4] )
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      First Time After Power On Results: +

                                                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                                                                                                                                                                                                      +4
                                                                                                                                                                                                                                                                                                                                                                                                      Getting MAC/Ethernet Address for this device.
                                                                                                                                                                                                                                                                                                                                                                                                      +Time in microseconds: 2584424
                                                                                                                                                                                                                                                                                                                                                                                                      +Hex byte array: b'(\xcd\xc1\x015X' length: 6
                                                                                                                                                                                                                                                                                                                                                                                                      +28:cd:c1:1:35:58
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Note that it takes about 2.5 seconds just to power on the chip before we get the MAC address.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Subsequent Times +

                                                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                                                      +2
                                                                                                                                                                                                                                                                                                                                                                                                      +3
                                                                                                                                                                                                                                                                                                                                                                                                      +4
                                                                                                                                                                                                                                                                                                                                                                                                      Getting MAC/Ethernet Address for this device.
                                                                                                                                                                                                                                                                                                                                                                                                      +Time in microseconds: 211
                                                                                                                                                                                                                                                                                                                                                                                                      +Hex byte array: b'(\xcd\xc1\x015X' length: 6
                                                                                                                                                                                                                                                                                                                                                                                                      +28:cd:c1:1:35:58
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Note

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      We must add the wlan.active(True) line to this code. If we don't do this, the wifi device will not be powered up and we can't get the MAC address. The function will return all zeros.

                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      I ran this program on my Pico W and I got times of between 214 and 222 microseconds. This shows you that it takes about 100 microseconds to send a request from the RP2040 to the CYW43439 WiFi chip and about 100 milliseconds to return the results. This time lag represents some of the key performance limitations in using the Pico W for high-performance networking.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      MAC Addresses and Privacy

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      MAC addresses are never sent to web servers to protect a clinet's privacy, but if you are debugging networks and looking at tools such as WireShark, they become visible to a local LAN administrator. MAC addresses are also visible to WiFi access points, so your local coffee shop that provides free WiFi could keep track of every time repeat customers use their WiFi access points.

                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                      Some computers such as Apple generate a different MAC address for each different access point they connect to. This prevents multiple stores from connecting your profiles together. So Starbucks can't use your MAC address to offer you a free coffee every 10th visit to different stores, but if you visit a local coffee shop they can use their WiFi access logs to see their same-store repeat customers.

                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                      + Web Server NeoPixel +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                      + UPIP +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/wireless/06-upip/index.html b/wireless/06-upip/index.html new file mode 100644 index 000000000..57f603edb --- /dev/null +++ b/wireless/06-upip/index.html @@ -0,0 +1,1833 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + UPIP - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + UPIP + + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                      + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + UPIP + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Install UPIP From Thonny Package Manager + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Install A Package + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Testing Your Newly Installed Library + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Getting UPIP Help + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + Install UPIP From Thonny Package Manager + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + Install A Package + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + Testing Your Newly Installed Library + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + + + Getting UPIP Help + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        • + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                        MicroPython PIP (UPIP)

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        MicroPython also has a package manager called upip that can be run directly on the microcontroller. This means that every time you get a new microcontroller, you can automatically download all the python packages you need directly from the Internet using a single python program after upip has been installed.

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        This also means that you don't need copies of these libraries installed on your local PC.

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Install UPIP From Thonny Package Manager

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Go to the Thonny Tools -> Manage Packages... menu. Type "upip" in the search field and click the Search on PyPL button:

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Thonny UPIP Search

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        The first search result will be for **micropython-upip". Click on that link and you will see the details.

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Thonny UPIP Search

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Install A Package

                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        The following program assumes that you have followed the steps in our Connecting to WiFi and have a secrets.py file that have your WiFi network name (SSID) and password (PASSWORD).

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                                                        +12
                                                                                                                                                                                                                                                                                                                                                                                                        +13
                                                                                                                                                                                                                                                                                                                                                                                                        +14
                                                                                                                                                                                                                                                                                                                                                                                                        +15
                                                                                                                                                                                                                                                                                                                                                                                                        +16
                                                                                                                                                                                                                                                                                                                                                                                                        +17
                                                                                                                                                                                                                                                                                                                                                                                                        +18
                                                                                                                                                                                                                                                                                                                                                                                                        +19
                                                                                                                                                                                                                                                                                                                                                                                                        +20
                                                                                                                                                                                                                                                                                                                                                                                                        +21
                                                                                                                                                                                                                                                                                                                                                                                                        +22
                                                                                                                                                                                                                                                                                                                                                                                                        +23
                                                                                                                                                                                                                                                                                                                                                                                                        +24
                                                                                                                                                                                                                                                                                                                                                                                                        +25
                                                                                                                                                                                                                                                                                                                                                                                                        +26
                                                                                                                                                                                                                                                                                                                                                                                                        +27
                                                                                                                                                                                                                                                                                                                                                                                                        +28
                                                                                                                                                                                                                                                                                                                                                                                                        +29
                                                                                                                                                                                                                                                                                                                                                                                                        +30
                                                                                                                                                                                                                                                                                                                                                                                                        +31
                                                                                                                                                                                                                                                                                                                                                                                                        import upip
                                                                                                                                                                                                                                                                                                                                                                                                        +import network
                                                                                                                                                                                                                                                                                                                                                                                                        +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                        +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                        +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                        +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +if not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                        +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                        +    print("Waiting for connection...")
                                                                                                                                                                                                                                                                                                                                                                                                        +    counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                        +    while not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                        +        sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                        +        counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                        +        print(counter, '.', sep='', end='', )
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +delta = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                        +print("Connect Time:", delta)
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +# This is the line you must modify for each package you want to install
                                                                                                                                                                                                                                                                                                                                                                                                        +# pystone is a CPU performance benchmarking tool that is easy to run to and test installation
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +start = ticks_ms()
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +upip.install("micropython-pystone_lowmem")
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +print("Download Time:", ticks_diff(ticks_ms(), start), milliseconds)
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Results:

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                                                        +3
                                                                                                                                                                                                                                                                                                                                                                                                        +4
                                                                                                                                                                                                                                                                                                                                                                                                        +5
                                                                                                                                                                                                                                                                                                                                                                                                        +6
                                                                                                                                                                                                                                                                                                                                                                                                        +7
                                                                                                                                                                                                                                                                                                                                                                                                        Connecting to WiFi Network Name: MY_NETWORK_NAME
                                                                                                                                                                                                                                                                                                                                                                                                        +Waiting for connection...
                                                                                                                                                                                                                                                                                                                                                                                                        +1.2.3.4.Connect Time: 4641
                                                                                                                                                                                                                                                                                                                                                                                                        +Installing to: /lib/
                                                                                                                                                                                                                                                                                                                                                                                                        +Warning: micropython.org SSL certificate is not validated
                                                                                                                                                                                                                                                                                                                                                                                                        +Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz
                                                                                                                                                                                                                                                                                                                                                                                                        +Download Time: 4918 milliseconds
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Testing Your Newly Installed Library

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                                                        import pystone_lowmem
                                                                                                                                                                                                                                                                                                                                                                                                        +pystone_lowmem.main()
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Results:

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                                                        Pystone(1.2) time for 500 passes = 410ms
                                                                                                                                                                                                                                                                                                                                                                                                        +This machine benchmarks at 1219 pystones/second
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        Getting UPIP Help

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        1
                                                                                                                                                                                                                                                                                                                                                                                                        +2
                                                                                                                                                                                                                                                                                                                                                                                                        import upip
                                                                                                                                                                                                                                                                                                                                                                                                        +upip.help()
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +

                                                                                                                                                                                                                                                                                                                                                                                                        returns:

                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                         1
                                                                                                                                                                                                                                                                                                                                                                                                        + 2
                                                                                                                                                                                                                                                                                                                                                                                                        + 3
                                                                                                                                                                                                                                                                                                                                                                                                        + 4
                                                                                                                                                                                                                                                                                                                                                                                                        + 5
                                                                                                                                                                                                                                                                                                                                                                                                        + 6
                                                                                                                                                                                                                                                                                                                                                                                                        + 7
                                                                                                                                                                                                                                                                                                                                                                                                        + 8
                                                                                                                                                                                                                                                                                                                                                                                                        + 9
                                                                                                                                                                                                                                                                                                                                                                                                        +10
                                                                                                                                                                                                                                                                                                                                                                                                        +11
                                                                                                                                                                                                                                                                                                                                                                                                        upip - Simple PyPI package manager for MicroPython
                                                                                                                                                                                                                                                                                                                                                                                                        +Usage: micropython -m upip install [-p <path>] <package>... | -r <requirements.txt>
                                                                                                                                                                                                                                                                                                                                                                                                        +import upip; upip.install(package_or_list, [<path>])
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +If <path> isn't given, packages will be installed to sys.path[1], or
                                                                                                                                                                                                                                                                                                                                                                                                        +sys.path[2] if the former is .frozen (path can be set from MICROPYPATH
                                                                                                                                                                                                                                                                                                                                                                                                        +environment variable if supported).
                                                                                                                                                                                                                                                                                                                                                                                                        +Default install path: /lib
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +Note: only MicroPython packages (usually, named micropython-*) are supported
                                                                                                                                                                                                                                                                                                                                                                                                        +for installation, upip does not support arbitrary code in setup.py.
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                        + MAC Address +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                        + Get Weather Forecast +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + + + + \ No newline at end of file diff --git a/wireless/07-web-server-rgb-neopixels/index.html b/wireless/07-web-server-rgb-neopixels/index.html new file mode 100644 index 000000000..809cdf136 --- /dev/null +++ b/wireless/07-web-server-rgb-neopixels/index.html @@ -0,0 +1,2150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Web Server NeoPixel - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + Web Server NeoPixel + + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + + +
                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                        + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + Web Server NeoPixel + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + Sample Code with CSS + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + Sample Code with CSS + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          • + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                          Web Server NeoPixel RGB

                                                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                                                          Sample Code with CSS

                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                          +  2
                                                                                                                                                                                                                                                                                                                                                                                                          +  3
                                                                                                                                                                                                                                                                                                                                                                                                          +  4
                                                                                                                                                                                                                                                                                                                                                                                                          +  5
                                                                                                                                                                                                                                                                                                                                                                                                          +  6
                                                                                                                                                                                                                                                                                                                                                                                                          +  7
                                                                                                                                                                                                                                                                                                                                                                                                          +  8
                                                                                                                                                                                                                                                                                                                                                                                                          +  9
                                                                                                                                                                                                                                                                                                                                                                                                          + 10
                                                                                                                                                                                                                                                                                                                                                                                                          + 11
                                                                                                                                                                                                                                                                                                                                                                                                          + 12
                                                                                                                                                                                                                                                                                                                                                                                                          + 13
                                                                                                                                                                                                                                                                                                                                                                                                          + 14
                                                                                                                                                                                                                                                                                                                                                                                                          + 15
                                                                                                                                                                                                                                                                                                                                                                                                          + 16
                                                                                                                                                                                                                                                                                                                                                                                                          + 17
                                                                                                                                                                                                                                                                                                                                                                                                          + 18
                                                                                                                                                                                                                                                                                                                                                                                                          + 19
                                                                                                                                                                                                                                                                                                                                                                                                          + 20
                                                                                                                                                                                                                                                                                                                                                                                                          + 21
                                                                                                                                                                                                                                                                                                                                                                                                          + 22
                                                                                                                                                                                                                                                                                                                                                                                                          + 23
                                                                                                                                                                                                                                                                                                                                                                                                          + 24
                                                                                                                                                                                                                                                                                                                                                                                                          + 25
                                                                                                                                                                                                                                                                                                                                                                                                          + 26
                                                                                                                                                                                                                                                                                                                                                                                                          + 27
                                                                                                                                                                                                                                                                                                                                                                                                          + 28
                                                                                                                                                                                                                                                                                                                                                                                                          + 29
                                                                                                                                                                                                                                                                                                                                                                                                          + 30
                                                                                                                                                                                                                                                                                                                                                                                                          + 31
                                                                                                                                                                                                                                                                                                                                                                                                          + 32
                                                                                                                                                                                                                                                                                                                                                                                                          + 33
                                                                                                                                                                                                                                                                                                                                                                                                          + 34
                                                                                                                                                                                                                                                                                                                                                                                                          + 35
                                                                                                                                                                                                                                                                                                                                                                                                          + 36
                                                                                                                                                                                                                                                                                                                                                                                                          + 37
                                                                                                                                                                                                                                                                                                                                                                                                          + 38
                                                                                                                                                                                                                                                                                                                                                                                                          + 39
                                                                                                                                                                                                                                                                                                                                                                                                          + 40
                                                                                                                                                                                                                                                                                                                                                                                                          + 41
                                                                                                                                                                                                                                                                                                                                                                                                          + 42
                                                                                                                                                                                                                                                                                                                                                                                                          + 43
                                                                                                                                                                                                                                                                                                                                                                                                          + 44
                                                                                                                                                                                                                                                                                                                                                                                                          + 45
                                                                                                                                                                                                                                                                                                                                                                                                          + 46
                                                                                                                                                                                                                                                                                                                                                                                                          + 47
                                                                                                                                                                                                                                                                                                                                                                                                          + 48
                                                                                                                                                                                                                                                                                                                                                                                                          + 49
                                                                                                                                                                                                                                                                                                                                                                                                          + 50
                                                                                                                                                                                                                                                                                                                                                                                                          + 51
                                                                                                                                                                                                                                                                                                                                                                                                          + 52
                                                                                                                                                                                                                                                                                                                                                                                                          + 53
                                                                                                                                                                                                                                                                                                                                                                                                          + 54
                                                                                                                                                                                                                                                                                                                                                                                                          + 55
                                                                                                                                                                                                                                                                                                                                                                                                          + 56
                                                                                                                                                                                                                                                                                                                                                                                                          + 57
                                                                                                                                                                                                                                                                                                                                                                                                          + 58
                                                                                                                                                                                                                                                                                                                                                                                                          + 59
                                                                                                                                                                                                                                                                                                                                                                                                          + 60
                                                                                                                                                                                                                                                                                                                                                                                                          + 61
                                                                                                                                                                                                                                                                                                                                                                                                          + 62
                                                                                                                                                                                                                                                                                                                                                                                                          + 63
                                                                                                                                                                                                                                                                                                                                                                                                          + 64
                                                                                                                                                                                                                                                                                                                                                                                                          + 65
                                                                                                                                                                                                                                                                                                                                                                                                          + 66
                                                                                                                                                                                                                                                                                                                                                                                                          + 67
                                                                                                                                                                                                                                                                                                                                                                                                          + 68
                                                                                                                                                                                                                                                                                                                                                                                                          + 69
                                                                                                                                                                                                                                                                                                                                                                                                          + 70
                                                                                                                                                                                                                                                                                                                                                                                                          + 71
                                                                                                                                                                                                                                                                                                                                                                                                          + 72
                                                                                                                                                                                                                                                                                                                                                                                                          + 73
                                                                                                                                                                                                                                                                                                                                                                                                          + 74
                                                                                                                                                                                                                                                                                                                                                                                                          + 75
                                                                                                                                                                                                                                                                                                                                                                                                          + 76
                                                                                                                                                                                                                                                                                                                                                                                                          + 77
                                                                                                                                                                                                                                                                                                                                                                                                          + 78
                                                                                                                                                                                                                                                                                                                                                                                                          + 79
                                                                                                                                                                                                                                                                                                                                                                                                          + 80
                                                                                                                                                                                                                                                                                                                                                                                                          + 81
                                                                                                                                                                                                                                                                                                                                                                                                          + 82
                                                                                                                                                                                                                                                                                                                                                                                                          + 83
                                                                                                                                                                                                                                                                                                                                                                                                          + 84
                                                                                                                                                                                                                                                                                                                                                                                                          + 85
                                                                                                                                                                                                                                                                                                                                                                                                          + 86
                                                                                                                                                                                                                                                                                                                                                                                                          + 87
                                                                                                                                                                                                                                                                                                                                                                                                          + 88
                                                                                                                                                                                                                                                                                                                                                                                                          + 89
                                                                                                                                                                                                                                                                                                                                                                                                          + 90
                                                                                                                                                                                                                                                                                                                                                                                                          + 91
                                                                                                                                                                                                                                                                                                                                                                                                          + 92
                                                                                                                                                                                                                                                                                                                                                                                                          + 93
                                                                                                                                                                                                                                                                                                                                                                                                          + 94
                                                                                                                                                                                                                                                                                                                                                                                                          + 95
                                                                                                                                                                                                                                                                                                                                                                                                          + 96
                                                                                                                                                                                                                                                                                                                                                                                                          + 97
                                                                                                                                                                                                                                                                                                                                                                                                          + 98
                                                                                                                                                                                                                                                                                                                                                                                                          + 99
                                                                                                                                                                                                                                                                                                                                                                                                          +100
                                                                                                                                                                                                                                                                                                                                                                                                          +101
                                                                                                                                                                                                                                                                                                                                                                                                          +102
                                                                                                                                                                                                                                                                                                                                                                                                          +103
                                                                                                                                                                                                                                                                                                                                                                                                          +104
                                                                                                                                                                                                                                                                                                                                                                                                          +105
                                                                                                                                                                                                                                                                                                                                                                                                          +106
                                                                                                                                                                                                                                                                                                                                                                                                          +107
                                                                                                                                                                                                                                                                                                                                                                                                          +108
                                                                                                                                                                                                                                                                                                                                                                                                          +109
                                                                                                                                                                                                                                                                                                                                                                                                          +110
                                                                                                                                                                                                                                                                                                                                                                                                          +111
                                                                                                                                                                                                                                                                                                                                                                                                          +112
                                                                                                                                                                                                                                                                                                                                                                                                          +113
                                                                                                                                                                                                                                                                                                                                                                                                          +114
                                                                                                                                                                                                                                                                                                                                                                                                          +115
                                                                                                                                                                                                                                                                                                                                                                                                          +116
                                                                                                                                                                                                                                                                                                                                                                                                          +117
                                                                                                                                                                                                                                                                                                                                                                                                          +118
                                                                                                                                                                                                                                                                                                                                                                                                          +119
                                                                                                                                                                                                                                                                                                                                                                                                          +120
                                                                                                                                                                                                                                                                                                                                                                                                          +121
                                                                                                                                                                                                                                                                                                                                                                                                          +122
                                                                                                                                                                                                                                                                                                                                                                                                          +123
                                                                                                                                                                                                                                                                                                                                                                                                          +124
                                                                                                                                                                                                                                                                                                                                                                                                          +125
                                                                                                                                                                                                                                                                                                                                                                                                          +126
                                                                                                                                                                                                                                                                                                                                                                                                          +127
                                                                                                                                                                                                                                                                                                                                                                                                          +128
                                                                                                                                                                                                                                                                                                                                                                                                          +129
                                                                                                                                                                                                                                                                                                                                                                                                          +130
                                                                                                                                                                                                                                                                                                                                                                                                          +131
                                                                                                                                                                                                                                                                                                                                                                                                          +132
                                                                                                                                                                                                                                                                                                                                                                                                          +133
                                                                                                                                                                                                                                                                                                                                                                                                          +134
                                                                                                                                                                                                                                                                                                                                                                                                          +135
                                                                                                                                                                                                                                                                                                                                                                                                          +136
                                                                                                                                                                                                                                                                                                                                                                                                          +137
                                                                                                                                                                                                                                                                                                                                                                                                          +138
                                                                                                                                                                                                                                                                                                                                                                                                          +139
                                                                                                                                                                                                                                                                                                                                                                                                          +140
                                                                                                                                                                                                                                                                                                                                                                                                          +141
                                                                                                                                                                                                                                                                                                                                                                                                          +142
                                                                                                                                                                                                                                                                                                                                                                                                          +143
                                                                                                                                                                                                                                                                                                                                                                                                          +144
                                                                                                                                                                                                                                                                                                                                                                                                          +145
                                                                                                                                                                                                                                                                                                                                                                                                          +146
                                                                                                                                                                                                                                                                                                                                                                                                          +147
                                                                                                                                                                                                                                                                                                                                                                                                          +148
                                                                                                                                                                                                                                                                                                                                                                                                          +149
                                                                                                                                                                                                                                                                                                                                                                                                          +150
                                                                                                                                                                                                                                                                                                                                                                                                          +151
                                                                                                                                                                                                                                                                                                                                                                                                          +152
                                                                                                                                                                                                                                                                                                                                                                                                          +153
                                                                                                                                                                                                                                                                                                                                                                                                          +154
                                                                                                                                                                                                                                                                                                                                                                                                          +155
                                                                                                                                                                                                                                                                                                                                                                                                          +156
                                                                                                                                                                                                                                                                                                                                                                                                          +157
                                                                                                                                                                                                                                                                                                                                                                                                          +158
                                                                                                                                                                                                                                                                                                                                                                                                          +159
                                                                                                                                                                                                                                                                                                                                                                                                          +160
                                                                                                                                                                                                                                                                                                                                                                                                          +161
                                                                                                                                                                                                                                                                                                                                                                                                          +162
                                                                                                                                                                                                                                                                                                                                                                                                          +163
                                                                                                                                                                                                                                                                                                                                                                                                          +164
                                                                                                                                                                                                                                                                                                                                                                                                          +165
                                                                                                                                                                                                                                                                                                                                                                                                          +166
                                                                                                                                                                                                                                                                                                                                                                                                          +167
                                                                                                                                                                                                                                                                                                                                                                                                          +168
                                                                                                                                                                                                                                                                                                                                                                                                          +169
                                                                                                                                                                                                                                                                                                                                                                                                          +170
                                                                                                                                                                                                                                                                                                                                                                                                          +171
                                                                                                                                                                                                                                                                                                                                                                                                          +172
                                                                                                                                                                                                                                                                                                                                                                                                          +173
                                                                                                                                                                                                                                                                                                                                                                                                          +174
                                                                                                                                                                                                                                                                                                                                                                                                          +175
                                                                                                                                                                                                                                                                                                                                                                                                          +176
                                                                                                                                                                                                                                                                                                                                                                                                          +177
                                                                                                                                                                                                                                                                                                                                                                                                          +178
                                                                                                                                                                                                                                                                                                                                                                                                          +179
                                                                                                                                                                                                                                                                                                                                                                                                          +180
                                                                                                                                                                                                                                                                                                                                                                                                          +181
                                                                                                                                                                                                                                                                                                                                                                                                          +182
                                                                                                                                                                                                                                                                                                                                                                                                          +183
                                                                                                                                                                                                                                                                                                                                                                                                          +184
                                                                                                                                                                                                                                                                                                                                                                                                          +185
                                                                                                                                                                                                                                                                                                                                                                                                          +186
                                                                                                                                                                                                                                                                                                                                                                                                          +187
                                                                                                                                                                                                                                                                                                                                                                                                          +188
                                                                                                                                                                                                                                                                                                                                                                                                          +189
                                                                                                                                                                                                                                                                                                                                                                                                          +190
                                                                                                                                                                                                                                                                                                                                                                                                          +191
                                                                                                                                                                                                                                                                                                                                                                                                          +192
                                                                                                                                                                                                                                                                                                                                                                                                          +193
                                                                                                                                                                                                                                                                                                                                                                                                          +194
                                                                                                                                                                                                                                                                                                                                                                                                          +195
                                                                                                                                                                                                                                                                                                                                                                                                          +196
                                                                                                                                                                                                                                                                                                                                                                                                          +197
                                                                                                                                                                                                                                                                                                                                                                                                          +198
                                                                                                                                                                                                                                                                                                                                                                                                          +199
                                                                                                                                                                                                                                                                                                                                                                                                          +200
                                                                                                                                                                                                                                                                                                                                                                                                          +201
                                                                                                                                                                                                                                                                                                                                                                                                          +202
                                                                                                                                                                                                                                                                                                                                                                                                          +203
                                                                                                                                                                                                                                                                                                                                                                                                          +204
                                                                                                                                                                                                                                                                                                                                                                                                          +205
                                                                                                                                                                                                                                                                                                                                                                                                          # Code taken from https://www.cnx-software.com/2022/07/03/getting-started-with-wifi-on-raspberry-pi-pico-w-board/
                                                                                                                                                                                                                                                                                                                                                                                                          +from machine import Pin
                                                                                                                                                                                                                                                                                                                                                                                                          +from neopixel import NeoPixel
                                                                                                                                                                                                                                                                                                                                                                                                          +import network
                                                                                                                                                                                                                                                                                                                                                                                                          +import socket
                                                                                                                                                                                                                                                                                                                                                                                                          +from time import sleep
                                                                                                                                                                                                                                                                                                                                                                                                          +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +NEOPIXEL_PIN = 0
                                                                                                                                                                                                                                                                                                                                                                                                          +NUMBER_PIXELS = 30
                                                                                                                                                                                                                                                                                                                                                                                                          +PERCENT_COLOR_WHEEL = round(255/NUMBER_PIXELS)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# setup
                                                                                                                                                                                                                                                                                                                                                                                                          +strip = NeoPixel(machine.Pin(NEOPIXEL_PIN), NUMBER_PIXELS)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +red = (255,0,0)
                                                                                                                                                                                                                                                                                                                                                                                                          +green = (0,255,0)
                                                                                                                                                                                                                                                                                                                                                                                                          +blue = (0,0,255)
                                                                                                                                                                                                                                                                                                                                                                                                          +off = (0,0,0)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +def set_color(color):
                                                                                                                                                                                                                                                                                                                                                                                                          +    for i in range(0, NUMBER_PIXELS):
                                                                                                                                                                                                                                                                                                                                                                                                          +        strip[i] = color
                                                                                                                                                                                                                                                                                                                                                                                                          +        strip.write()
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# Select the onboard LED
                                                                                                                                                                                                                                                                                                                                                                                                          +led = machine.Pin("LED", machine.Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                          +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                          +wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                          +stateis = "LED is OFF"
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +html = """<!DOCTYPE html>
                                                                                                                                                                                                                                                                                                                                                                                                          +<html>
                                                                                                                                                                                                                                                                                                                                                                                                          +   <head>
                                                                                                                                                                                                                                                                                                                                                                                                          +     <title>Web Server On Pico W </title>
                                                                                                                                                                                                                                                                                                                                                                                                          +     <style>
                                                                                                                                                                                                                                                                                                                                                                                                          +        body {
                                                                                                                                                                                                                                                                                                                                                                                                          +            font-size:24px;
                                                                                                                                                                                                                                                                                                                                                                                                          +            font-family:'Helvetica'
                                                                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +        .button-row {
                                                                                                                                                                                                                                                                                                                                                                                                          +            display: inline-block;
                                                                                                                                                                                                                                                                                                                                                                                                          +            padding: 2px 3px 6px 3px;
                                                                                                                                                                                                                                                                                                                                                                                                          +            margin: 5px;
                                                                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +        a:visited {
                                                                                                                                                                                                                                                                                                                                                                                                          +          color: yellow;
                                                                                                                                                                                                                                                                                                                                                                                                          +          background-color: transparent;
                                                                                                                                                                                                                                                                                                                                                                                                          +          text-decoration: none;
                                                                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +        a:hover {
                                                                                                                                                                                                                                                                                                                                                                                                          +          color: orange;
                                                                                                                                                                                                                                                                                                                                                                                                          +          background-color: transparent;
                                                                                                                                                                                                                                                                                                                                                                                                          +          text-decoration: none;
                                                                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +        .button {
                                                                                                                                                                                                                                                                                                                                                                                                          +          font: bold 16px Arial;
                                                                                                                                                                                                                                                                                                                                                                                                          +          text-decoration: none;
                                                                                                                                                                                                                                                                                                                                                                                                          +          padding: 2px 6px 2px 6px;
                                                                                                                                                                                                                                                                                                                                                                                                          +          border-top: 2px solid #CCCCCC;
                                                                                                                                                                                                                                                                                                                                                                                                          +          border-right: 2px solid #333333;
                                                                                                                                                                                                                                                                                                                                                                                                          +          border-bottom: 2px solid #333333;
                                                                                                                                                                                                                                                                                                                                                                                                          +          border-left: 2px solid #CCCCCC;
                                                                                                                                                                                                                                                                                                                                                                                                          +        }
                                                                                                                                                                                                                                                                                                                                                                                                          +     </style>
                                                                                                                                                                                                                                                                                                                                                                                                          +   </head>
                                                                                                                                                                                                                                                                                                                                                                                                          +  <body>
                                                                                                                                                                                                                                                                                                                                                                                                          +      <h1>Pico Wireless Web Server</h1>
                                                                                                                                                                                                                                                                                                                                                                                                          +      <p>Onboard LED State: %s</p>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +      <div class="buttons">
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +          <span class="button-row" style="background-color:gray">
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/light/on" class="button">Turn Onboard LED On</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/light/off" class="button">Turn Onboard LED Off</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +          </span><br/>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +          <span class="button-row" style="background-color:red">
                                                                                                                                                                                                                                                                                                                                                                                                          +             <a href="/led/red/on" class="button">Red LED On</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +             <a href="/led/red/off" class="button">Red LED Off</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +          </span><br/>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +          <span class="button-row" style="background-color:green">
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/led/green/on" class="button">Green LED On</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/led/green/off" class="button">Green LED Off</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +          </span><br/>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +          <span class="button-row" style="background-color:blue">
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/led/blue/on" class="button">Blue LED On</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +              <a href="/led/blue/off" class="button">Blue LED Off</a>
                                                                                                                                                                                                                                                                                                                                                                                                          +          </span>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +        </div>
                                                                                                                                                                                                                                                                                                                                                                                                          +  </body>
                                                                                                                                                                                                                                                                                                                                                                                                          +</html>
                                                                                                                                                                                                                                                                                                                                                                                                          +"""
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# Wait for connect or fail
                                                                                                                                                                                                                                                                                                                                                                                                          +max_wait = 10
                                                                                                                                                                                                                                                                                                                                                                                                          +while max_wait > 0:
                                                                                                                                                                                                                                                                                                                                                                                                          +  if wlan.status() < 0 or wlan.status() >= 3:
                                                                                                                                                                                                                                                                                                                                                                                                          +    break
                                                                                                                                                                                                                                                                                                                                                                                                          +  max_wait -= 1
                                                                                                                                                                                                                                                                                                                                                                                                          +  print('waiting for connection...')
                                                                                                                                                                                                                                                                                                                                                                                                          +  sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                          +  led.toggle()
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# Handle connection error
                                                                                                                                                                                                                                                                                                                                                                                                          +if wlan.status() != 3:
                                                                                                                                                                                                                                                                                                                                                                                                          +  raise RuntimeError('network connection failed')
                                                                                                                                                                                                                                                                                                                                                                                                          +else:
                                                                                                                                                                                                                                                                                                                                                                                                          +  print('We are connected to WiFI access point:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                          +  status = wlan.ifconfig()
                                                                                                                                                                                                                                                                                                                                                                                                          +  print( 'The IP address of the pico W is:', status[0] )
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# Open socket
                                                                                                                                                                                                                                                                                                                                                                                                          +addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
                                                                                                                                                                                                                                                                                                                                                                                                          +# print('addr:', addr)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +s = socket.socket()
                                                                                                                                                                                                                                                                                                                                                                                                          +# this prevents the "OSError: [Errno 98] EADDRINUSE" error for repeated tests
                                                                                                                                                                                                                                                                                                                                                                                                          +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                                                                                                                                                                                                                                                                                                                                                                                                          +# print('Got a sockert.  s:', s)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +#if not addr:
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# print('going to run bind to addr on the socket')
                                                                                                                                                                                                                                                                                                                                                                                                          +s.bind(addr)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# print('going to run listen(1) on socket')
                                                                                                                                                                                                                                                                                                                                                                                                          +s.listen(1)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# print('listening on', addr)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +# Listen for connections
                                                                                                                                                                                                                                                                                                                                                                                                          +while True:
                                                                                                                                                                                                                                                                                                                                                                                                          +  try:
                                                                                                                                                                                                                                                                                                                                                                                                          +    cl, addr = s.accept()
                                                                                                                                                                                                                                                                                                                                                                                                          +    # print('client connected from', addr)
                                                                                                                                                                                                                                                                                                                                                                                                          +    request = cl.recv(1024)
                                                                                                                                                                                                                                                                                                                                                                                                          +    # print(request)
                                                                                                                                                                                                                                                                                                                                                                                                          +    request = str(request)
                                                                                                                                                                                                                                                                                                                                                                                                          +    led_on = request.find('/light/on')
                                                                                                                                                                                                                                                                                                                                                                                                          +    led_off = request.find('/light/off')
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    red_on = request.find('/led/red/on')
                                                                                                                                                                                                                                                                                                                                                                                                          +    red_off = request.find('/led/red/off')
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    green_on = request.find('/led/green/on')
                                                                                                                                                                                                                                                                                                                                                                                                          +    green_off = request.find('/led/green/off')
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    blue_on = request.find('/led/blue/on')
                                                                                                                                                                                                                                                                                                                                                                                                          +    blue_off = request.find('/led/blue/off')
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    # print( 'led on = ' + str(led_on))
                                                                                                                                                                                                                                                                                                                                                                                                          +    # print( 'led off = ' + str(led_off))
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    if led_on == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +      print("led on")
                                                                                                                                                                                                                                                                                                                                                                                                          +      led.on()
                                                                                                                                                                                                                                                                                                                                                                                                          +      stateis = "LED is ON"
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    if led_off == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("led off")
                                                                                                                                                                                                                                                                                                                                                                                                          +        led.off()
                                                                                                                                                                                                                                                                                                                                                                                                          +        stateis = "LED is OFF"
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    if red_on == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("red on")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(red)
                                                                                                                                                                                                                                                                                                                                                                                                          +    if red_off == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("red off")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(off)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    if green_on == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("green on")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(green)
                                                                                                                                                                                                                                                                                                                                                                                                          +    if green_off == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("green off")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(off)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    if blue_on == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("blue on")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(blue)
                                                                                                                                                                                                                                                                                                                                                                                                          +    if blue_off == 6:
                                                                                                                                                                                                                                                                                                                                                                                                          +        print("blue off")
                                                                                                                                                                                                                                                                                                                                                                                                          +        set_color(off)
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +    # generate the we page with the stateis as a parameter
                                                                                                                                                                                                                                                                                                                                                                                                          +    response = html % stateis
                                                                                                                                                                                                                                                                                                                                                                                                          +    cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
                                                                                                                                                                                                                                                                                                                                                                                                          +    cl.send(response)
                                                                                                                                                                                                                                                                                                                                                                                                          +    cl.close()
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +  except OSError as e:
                                                                                                                                                                                                                                                                                                                                                                                                          +    cl.close()
                                                                                                                                                                                                                                                                                                                                                                                                          +    s.close()
                                                                                                                                                                                                                                                                                                                                                                                                          +    print('connection closed')
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                                                          References

                                                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                                                          Clear Fix Floating Boxes Example

                                                                                                                                                                                                                                                                                                                                                                                                          +

                                                                                                                                                                                                                                                                                                                                                                                                          https://www.w3schools.com/css/tryit.asp?filename=trycss_float_boxes

                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                           1
                                                                                                                                                                                                                                                                                                                                                                                                          + 2
                                                                                                                                                                                                                                                                                                                                                                                                          + 3
                                                                                                                                                                                                                                                                                                                                                                                                          + 4
                                                                                                                                                                                                                                                                                                                                                                                                          + 5
                                                                                                                                                                                                                                                                                                                                                                                                          + 6
                                                                                                                                                                                                                                                                                                                                                                                                          + 7
                                                                                                                                                                                                                                                                                                                                                                                                          + 8
                                                                                                                                                                                                                                                                                                                                                                                                          + 9
                                                                                                                                                                                                                                                                                                                                                                                                          +10
                                                                                                                                                                                                                                                                                                                                                                                                          +11
                                                                                                                                                                                                                                                                                                                                                                                                          +12
                                                                                                                                                                                                                                                                                                                                                                                                          +13
                                                                                                                                                                                                                                                                                                                                                                                                          +14
                                                                                                                                                                                                                                                                                                                                                                                                          +15
                                                                                                                                                                                                                                                                                                                                                                                                          +16
                                                                                                                                                                                                                                                                                                                                                                                                          +17
                                                                                                                                                                                                                                                                                                                                                                                                          +18
                                                                                                                                                                                                                                                                                                                                                                                                          +19
                                                                                                                                                                                                                                                                                                                                                                                                          +20
                                                                                                                                                                                                                                                                                                                                                                                                          +21
                                                                                                                                                                                                                                                                                                                                                                                                          +22
                                                                                                                                                                                                                                                                                                                                                                                                          +23
                                                                                                                                                                                                                                                                                                                                                                                                          +24
                                                                                                                                                                                                                                                                                                                                                                                                          +25
                                                                                                                                                                                                                                                                                                                                                                                                          +26
                                                                                                                                                                                                                                                                                                                                                                                                          +27
                                                                                                                                                                                                                                                                                                                                                                                                          +28
                                                                                                                                                                                                                                                                                                                                                                                                          +29
                                                                                                                                                                                                                                                                                                                                                                                                          +30
                                                                                                                                                                                                                                                                                                                                                                                                          +31
                                                                                                                                                                                                                                                                                                                                                                                                          <style>
                                                                                                                                                                                                                                                                                                                                                                                                          +* {
                                                                                                                                                                                                                                                                                                                                                                                                          +  box-sizing: border-box;
                                                                                                                                                                                                                                                                                                                                                                                                          +}
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +.box {
                                                                                                                                                                                                                                                                                                                                                                                                          +  float: left;
                                                                                                                                                                                                                                                                                                                                                                                                          +  width: 33.33%;
                                                                                                                                                                                                                                                                                                                                                                                                          +  padding: 30px 20px;
                                                                                                                                                                                                                                                                                                                                                                                                          +}
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +.clearfix::after {
                                                                                                                                                                                                                                                                                                                                                                                                          +  content: "";
                                                                                                                                                                                                                                                                                                                                                                                                          +  clear: both;
                                                                                                                                                                                                                                                                                                                                                                                                          +  display: table;
                                                                                                                                                                                                                                                                                                                                                                                                          +}
                                                                                                                                                                                                                                                                                                                                                                                                          +</style>
                                                                                                                                                                                                                                                                                                                                                                                                          +</head>
                                                                                                                                                                                                                                                                                                                                                                                                          +<body>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +  <h2>Grid of Boxes</h2>
                                                                                                                                                                                                                                                                                                                                                                                                          +  <p>Float boxes side by side:</p>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +  <div class="clearfix">
                                                                                                                                                                                                                                                                                                                                                                                                          +    <div class="box" style="background-color:silver">
                                                                                                                                                                                                                                                                                                                                                                                                          +    <p>Some text inside the box.</p>
                                                                                                                                                                                                                                                                                                                                                                                                          +    </div>
                                                                                                                                                                                                                                                                                                                                                                                                          +    <div class="box" style="background-color:gray">
                                                                                                                                                                                                                                                                                                                                                                                                          +    <p>Some text inside the box.</p>
                                                                                                                                                                                                                                                                                                                                                                                                          +    </div>
                                                                                                                                                                                                                                                                                                                                                                                                          +  </div>
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                          + Web Server +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                          + MAC Address +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + + + + \ No newline at end of file diff --git a/wireless/08-get-weather/index.html b/wireless/08-get-weather/index.html new file mode 100644 index 000000000..a6820a0bc --- /dev/null +++ b/wireless/08-get-weather/index.html @@ -0,0 +1,2014 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Get Weather Forecast - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + Get Weather Forecast + + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + + +
                                                                                                                                                                                                                                                                                                                                                                                                          + +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                          + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + Get Weather Forecast + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + How to Use the Open Weather Map API + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Parsing the JSON file + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Sample Output + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Plotting the Forecast with Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Displaying Predicted Temperatures in a Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + How to Use the Open Weather Map API + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Parsing the JSON file + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Sample Output + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Plotting the Forecast with Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + + + Displaying Predicted Temperatures in a Thonny Plot + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            • + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                            Get the Weather Forecast

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            This demo uses the free web service Open Weather Map.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            The Open Weather Map service returns the predicted temperatures and conditions (sun, cloudy, rain etc.) for three-hour intervals for the next 40 intervals at your specified location.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            You can see this using the UNIX curl command:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                                                                                                            +4
                                                                                                                                                                                                                                                                                                                                                                                                            curl 'http://api.openweathermap.org/data/2.5/forecast?\
                                                                                                                                                                                                                                                                                                                                                                                                            +      units=imperial&\
                                                                                                                                                                                                                                                                                                                                                                                                            +      id=5037649&\
                                                                                                                                                                                                                                                                                                                                                                                                            +      appid=f2b1...'
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            In this example, we are asking it to use US standard Fahrenheit (imperial units) for the city with id 5037649 which is Minneapolis, MN in the USA. You can use the Open Weather site to find the id for your city or specify the longitude and latitude of the point you want to get weather forecasts for. You can also use the GeoNames to find your city ID number.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            How to Use the Open Weather Map API

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            To use this service, you must register and get an API key. You then put your key in the secrets.py file:

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Content of secrets.py +

                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            appid='f2b1...'
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            The secrets.py file is then imported into your program. Make sure to put secrets.py into your .gitignore file so it will not be checked into your public GitHub repo.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            The URL for the service is then created by concatenating the base URL, the city location ID and the application id:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                                                                                                            base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'
                                                                                                                                                                                                                                                                                                                                                                                                            +location = '5037649' # GeoNames ID for Minneapolis in Minnesota, USA
                                                                                                                                                                                                                                                                                                                                                                                                            +url = base + 'id=' + location + '&appid=' + secrets.appid
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Parsing the JSON file

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            The service returns a JSON file with the following format:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                             1
                                                                                                                                                                                                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                                                                                                                                                                                                            +17
                                                                                                                                                                                                                                                                                                                                                                                                            +18
                                                                                                                                                                                                                                                                                                                                                                                                            +19
                                                                                                                                                                                                                                                                                                                                                                                                            +20
                                                                                                                                                                                                                                                                                                                                                                                                            +21
                                                                                                                                                                                                                                                                                                                                                                                                            +22
                                                                                                                                                                                                                                                                                                                                                                                                            +23
                                                                                                                                                                                                                                                                                                                                                                                                            +24
                                                                                                                                                                                                                                                                                                                                                                                                            +25
                                                                                                                                                                                                                                                                                                                                                                                                            +26
                                                                                                                                                                                                                                                                                                                                                                                                            +27
                                                                                                                                                                                                                                                                                                                                                                                                            +28
                                                                                                                                                                                                                                                                                                                                                                                                            +29
                                                                                                                                                                                                                                                                                                                                                                                                            +30
                                                                                                                                                                                                                                                                                                                                                                                                            +31
                                                                                                                                                                                                                                                                                                                                                                                                            +32
                                                                                                                                                                                                                                                                                                                                                                                                            +33
                                                                                                                                                                                                                                                                                                                                                                                                            +34
                                                                                                                                                                                                                                                                                                                                                                                                            +35
                                                                                                                                                                                                                                                                                                                                                                                                            +36
                                                                                                                                                                                                                                                                                                                                                                                                            +37
                                                                                                                                                                                                                                                                                                                                                                                                            +38
                                                                                                                                                                                                                                                                                                                                                                                                            +39
                                                                                                                                                                                                                                                                                                                                                                                                            +40
                                                                                                                                                                                                                                                                                                                                                                                                            +41
                                                                                                                                                                                                                                                                                                                                                                                                            +42
                                                                                                                                                                                                                                                                                                                                                                                                            +43
                                                                                                                                                                                                                                                                                                                                                                                                            +44
                                                                                                                                                                                                                                                                                                                                                                                                            +45
                                                                                                                                                                                                                                                                                                                                                                                                            +46
                                                                                                                                                                                                                                                                                                                                                                                                            +47
                                                                                                                                                                                                                                                                                                                                                                                                            +48
                                                                                                                                                                                                                                                                                                                                                                                                            +49
                                                                                                                                                                                                                                                                                                                                                                                                            +50
                                                                                                                                                                                                                                                                                                                                                                                                            +51
                                                                                                                                                                                                                                                                                                                                                                                                            +52
                                                                                                                                                                                                                                                                                                                                                                                                            +53
                                                                                                                                                                                                                                                                                                                                                                                                            +54
                                                                                                                                                                                                                                                                                                                                                                                                            +55
                                                                                                                                                                                                                                                                                                                                                                                                            +56
                                                                                                                                                                                                                                                                                                                                                                                                            +57
                                                                                                                                                                                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                                                                                                                                                            +    "cod": "200",
                                                                                                                                                                                                                                                                                                                                                                                                            +    "message": 0,
                                                                                                                                                                                                                                                                                                                                                                                                            +    "cnt": 40,
                                                                                                                                                                                                                                                                                                                                                                                                            +    "list": [
                                                                                                                                                                                                                                                                                                                                                                                                            +        {
                                                                                                                                                                                                                                                                                                                                                                                                            +            "dt": 1660078800,
                                                                                                                                                                                                                                                                                                                                                                                                            +            "main": {
                                                                                                                                                                                                                                                                                                                                                                                                            +                "temp": 80.83,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "feels_like": 81.23,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "temp_min": 80.83,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "temp_max": 84.67,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "pressure": 1019,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "sea_level": 1019,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "grnd_level": 988,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "humidity": 47,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "temp_kf": -2.13
                                                                                                                                                                                                                                                                                                                                                                                                            +            },
                                                                                                                                                                                                                                                                                                                                                                                                            +            "weather": [
                                                                                                                                                                                                                                                                                                                                                                                                            +                {
                                                                                                                                                                                                                                                                                                                                                                                                            +                    "id": 800,
                                                                                                                                                                                                                                                                                                                                                                                                            +                    "main": "Clear",
                                                                                                                                                                                                                                                                                                                                                                                                            +                    "description": "clear sky",
                                                                                                                                                                                                                                                                                                                                                                                                            +                    "icon": "01d"
                                                                                                                                                                                                                                                                                                                                                                                                            +                }
                                                                                                                                                                                                                                                                                                                                                                                                            +            ],
                                                                                                                                                                                                                                                                                                                                                                                                            +            "clouds": {
                                                                                                                                                                                                                                                                                                                                                                                                            +                "all": 0
                                                                                                                                                                                                                                                                                                                                                                                                            +            },
                                                                                                                                                                                                                                                                                                                                                                                                            +            "wind": {
                                                                                                                                                                                                                                                                                                                                                                                                            +                "speed": 6.08,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "deg": 226,
                                                                                                                                                                                                                                                                                                                                                                                                            +                "gust": 6.38
                                                                                                                                                                                                                                                                                                                                                                                                            +            },
                                                                                                                                                                                                                                                                                                                                                                                                            +            "visibility": 10000,
                                                                                                                                                                                                                                                                                                                                                                                                            +            "pop": 0,
                                                                                                                                                                                                                                                                                                                                                                                                            +            "sys": {
                                                                                                                                                                                                                                                                                                                                                                                                            +                "pod": "d"
                                                                                                                                                                                                                                                                                                                                                                                                            +            },
                                                                                                                                                                                                                                                                                                                                                                                                            +            "dt_txt": "2022-08-09 21:00:00"
                                                                                                                                                                                                                                                                                                                                                                                                            +        }, 
                                                                                                                                                                                                                                                                                                                                                                                                            +        /* ...repeated 40 times */
                                                                                                                                                                                                                                                                                                                                                                                                            +        ,
                                                                                                                                                                                                                                                                                                                                                                                                            +    "city": {
                                                                                                                                                                                                                                                                                                                                                                                                            +        "id": 5037649,
                                                                                                                                                                                                                                                                                                                                                                                                            +        "name": "Minneapolis",
                                                                                                                                                                                                                                                                                                                                                                                                            +        "coord": {
                                                                                                                                                                                                                                                                                                                                                                                                            +            "lat": 44.98,
                                                                                                                                                                                                                                                                                                                                                                                                            +            "lon": -93.2638
                                                                                                                                                                                                                                                                                                                                                                                                            +        },
                                                                                                                                                                                                                                                                                                                                                                                                            +        "country": "US",
                                                                                                                                                                                                                                                                                                                                                                                                            +        "population": 0,
                                                                                                                                                                                                                                                                                                                                                                                                            +        "timezone": -18000,
                                                                                                                                                                                                                                                                                                                                                                                                            +        "sunrise": 1660043269,
                                                                                                                                                                                                                                                                                                                                                                                                            +        "sunset": 1660094963
                                                                                                                                                                                                                                                                                                                                                                                                            +    }
                                                                                                                                                                                                                                                                                                                                                                                                            +}
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            The bulk of the data is in the list structure with 40 items with a small set of data before and after the list. The data about the HTTP status (200) and the count (40) is before the list and the data about the city is after the list.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Each block of data in the list JSON object contains data about the main data (temperature, min, max, pressure, humidity), cloud cover, wind speed and visibility. It is up to you to decide what data you would like to display within this data. Once you decide what data you want to access you can use JSON path statements to pull the right data out. For example, to get the main temperature for each time period you would run:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                                                                                                            +4
                                                                                                                                                                                                                                                                                                                                                                                                            # get the temp and humidity for the next 40 3-hour intervals
                                                                                                                                                                                                                                                                                                                                                                                                            +for i in range(0, 39):
                                                                                                                                                                                                                                                                                                                                                                                                            +    print('temp:', weather['list'][i]['main']['temp'], end='')
                                                                                                                                                                                                                                                                                                                                                                                                            +    print('humidity:', weather['list'][i]['main']['humidity'])
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Sample Output

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Here is the output on the Thonny shell of the first 16 temperature values:

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Network Weather Results

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Plotting the Forecast with Thonny Plot

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Here is a plot of the temp and the "feels like" temp using the Thonny Plotter panel.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Wireless Forecast Thonny Plot

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Each line has:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                            1. a label string
                                                                                                                                                                                                                                                                                                                                                                                                            2. +
                                                                                                                                                                                                                                                                                                                                                                                                            3. a colon
                                                                                                                                                                                                                                                                                                                                                                                                            4. +
                                                                                                                                                                                                                                                                                                                                                                                                            5. the numeric value
                                                                                                                                                                                                                                                                                                                                                                                                            6. +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            for each value plotted. There can be multiple values per line.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Here is that format:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                                                                                                            Temperature: 63 Feels Like:  63.52
                                                                                                                                                                                                                                                                                                                                                                                                            +Temperature: 62 Feels Like:  62.56
                                                                                                                                                                                                                                                                                                                                                                                                            +Temperature: 70 Feels Like:  69.69
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Sample Code

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                             1
                                                                                                                                                                                                                                                                                                                                                                                                            + 2
                                                                                                                                                                                                                                                                                                                                                                                                            + 3
                                                                                                                                                                                                                                                                                                                                                                                                            + 4
                                                                                                                                                                                                                                                                                                                                                                                                            + 5
                                                                                                                                                                                                                                                                                                                                                                                                            + 6
                                                                                                                                                                                                                                                                                                                                                                                                            + 7
                                                                                                                                                                                                                                                                                                                                                                                                            + 8
                                                                                                                                                                                                                                                                                                                                                                                                            + 9
                                                                                                                                                                                                                                                                                                                                                                                                            +10
                                                                                                                                                                                                                                                                                                                                                                                                            +11
                                                                                                                                                                                                                                                                                                                                                                                                            +12
                                                                                                                                                                                                                                                                                                                                                                                                            +13
                                                                                                                                                                                                                                                                                                                                                                                                            +14
                                                                                                                                                                                                                                                                                                                                                                                                            +15
                                                                                                                                                                                                                                                                                                                                                                                                            +16
                                                                                                                                                                                                                                                                                                                                                                                                            +17
                                                                                                                                                                                                                                                                                                                                                                                                            +18
                                                                                                                                                                                                                                                                                                                                                                                                            +19
                                                                                                                                                                                                                                                                                                                                                                                                            +20
                                                                                                                                                                                                                                                                                                                                                                                                            +21
                                                                                                                                                                                                                                                                                                                                                                                                            +22
                                                                                                                                                                                                                                                                                                                                                                                                            +23
                                                                                                                                                                                                                                                                                                                                                                                                            +24
                                                                                                                                                                                                                                                                                                                                                                                                            +25
                                                                                                                                                                                                                                                                                                                                                                                                            +26
                                                                                                                                                                                                                                                                                                                                                                                                            +27
                                                                                                                                                                                                                                                                                                                                                                                                            +28
                                                                                                                                                                                                                                                                                                                                                                                                            +29
                                                                                                                                                                                                                                                                                                                                                                                                            +30
                                                                                                                                                                                                                                                                                                                                                                                                            +31
                                                                                                                                                                                                                                                                                                                                                                                                            +32
                                                                                                                                                                                                                                                                                                                                                                                                            +33
                                                                                                                                                                                                                                                                                                                                                                                                            +34
                                                                                                                                                                                                                                                                                                                                                                                                            +35
                                                                                                                                                                                                                                                                                                                                                                                                            +36
                                                                                                                                                                                                                                                                                                                                                                                                            +37
                                                                                                                                                                                                                                                                                                                                                                                                            +38
                                                                                                                                                                                                                                                                                                                                                                                                            +39
                                                                                                                                                                                                                                                                                                                                                                                                            +40
                                                                                                                                                                                                                                                                                                                                                                                                            +41
                                                                                                                                                                                                                                                                                                                                                                                                            +42
                                                                                                                                                                                                                                                                                                                                                                                                            +43
                                                                                                                                                                                                                                                                                                                                                                                                            +44
                                                                                                                                                                                                                                                                                                                                                                                                            import network
                                                                                                                                                                                                                                                                                                                                                                                                            +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                            +import urequests
                                                                                                                                                                                                                                                                                                                                                                                                            +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                            +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                            +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +if not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                            +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                            +    print("Waiting for connection...")
                                                                                                                                                                                                                                                                                                                                                                                                            +    counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                            +    while not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                            +        sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                            +        print(counter, '.', sep='', end='', )
                                                                                                                                                                                                                                                                                                                                                                                                            +        counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +delta = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                            +print("Connect Time:", delta, 'milliseconds')
                                                                                                                                                                                                                                                                                                                                                                                                            +print("IP Address:", wlan.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'
                                                                                                                                                                                                                                                                                                                                                                                                            +location = '5037649' # twin cities
                                                                                                                                                                                                                                                                                                                                                                                                            +url = base + 'id=' + location + '&appid=' + secrets.appid
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +weather = urequests.get(url).json()
                                                                                                                                                                                                                                                                                                                                                                                                            +print('City:', weather['city']['name'])
                                                                                                                                                                                                                                                                                                                                                                                                            +print('Timezone:', weather['city']['timezone'])
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +max_times = 16
                                                                                                                                                                                                                                                                                                                                                                                                            +# for i in range(0, 39):
                                                                                                                                                                                                                                                                                                                                                                                                            +for i in range(0, max_times):
                                                                                                                                                                                                                                                                                                                                                                                                            +    print(weather['list'][i]['dt_txt'][5:13], ' ', sep='', end='')
                                                                                                                                                                                                                                                                                                                                                                                                            +print()
                                                                                                                                                                                                                                                                                                                                                                                                            +for i in range(0, max_times):    
                                                                                                                                                                                                                                                                                                                                                                                                            +    print(round(weather['list'][i]['main']['temp']), '      ', end='')
                                                                                                                                                                                                                                                                                                                                                                                                            +    # print('feels like:', weather['list'][i]['main']['feels_like'])
                                                                                                                                                                                                                                                                                                                                                                                                            +    # print(weather['list'][i]['weather'][0]['description'])
                                                                                                                                                                                                                                                                                                                                                                                                            +    # print(weather['list'][i]['dt_txt'])
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +# print(weather)
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Displaying Predicted Temperatures in a Thonny Plot

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            Thonny has a Plot object that you can use to display the relative temperature for the next 40 3-hour cycles.

                                                                                                                                                                                                                                                                                                                                                                                                            +

                                                                                                                                                                                                                                                                                                                                                                                                            To do this, we only need to print out the temperatures each on a separate line:

                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            1
                                                                                                                                                                                                                                                                                                                                                                                                            +2
                                                                                                                                                                                                                                                                                                                                                                                                            +3
                                                                                                                                                                                                                                                                                                                                                                                                            print()
                                                                                                                                                                                                                                                                                                                                                                                                            +for i in range(0, max_times):    
                                                                                                                                                                                                                                                                                                                                                                                                            +    print(round(weather['list'][i]['main']['temp']))
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                            + UPIP +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                            + Display Forecast on OLED +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + + + + \ No newline at end of file diff --git a/wireless/09-get-weather-display/index.html b/wireless/09-get-weather-display/index.html new file mode 100644 index 000000000..84595fb93 --- /dev/null +++ b/wireless/09-get-weather-display/index.html @@ -0,0 +1,2188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Display Forecast on OLED - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + Display Forecast on OLED + + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + + +
                                                                                                                                                                                                                                                                                                                                                                                                            + +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                            + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + Display Forecast on OLED + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Calling the Weather API + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + The Main Loop + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Full Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Sample Debugging + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + Calling the Weather API + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + The Main Loop + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + Full Sample Code + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + + + Sample Debugging + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              • + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                              Get Weather on an OLED Display

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              Network Weather Display

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              In this lesson we will use the Pico W to get a weather forecast from a web service and display the current and forecasted temperatures on a 128x64 OLED display. The display above shows the city and current temperature on the top row of the display and then a plot of the predicted temperatures for the next 120 hours. The max temperature is 87 degrees and the minimum is 60 degrees Fahrenheit.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              Calling the Weather API

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              We will use the same method as in the previous lesson to get the weather forecast. However, in this lesson we will not just plot the temperature on the Thonny plot screen, we will use a OLED screen.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              To do this we will need to write a function that will display the temperature data. The function will display the current location city name, the current temperature, and then draw a plot of the next 40 3-hour intervals. This lesson is a bit harder because we have to manually do all the work of scaling and plotting our data. This is all done for us in the prior Thonny plotting lab.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              To achieve this we will need to scale the data to fit the display grid. We will reserve the top 10 pixels for the city and current temp and then draw the plot on the remaining 54 pixel high and 128 pixel wide plot region.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              To scale the data we will need to find the min and max temperatures. These will also be displayed on the screen. The scale is then the ratio of the graph height over the temperature range. For example if the range of temperatures is 27 degrees and the height of the display is 54 we will need to scale the temperature vertically by 2.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              The horizontal axis will go from 0 to 120. Since we have 40 points, each point will occur every 3rd pixel. We can then look at the difference between the current point and the next point to interpolate the dots between the two points.

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              The math can be a little confusing since higher temperatures are closer to the top of the display, so they have a lower Y coordinate value. Note the y_delta is subtracted from the next value:

                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                                                                  y_delta = -round((y - y_next)/3) # a small positive or negative number for interpolation
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                                                                                                                                              +18
                                                                                                                                                                                                                                                                                                                                                                                                              +19
                                                                                                                                                                                                                                                                                                                                                                                                              +20
                                                                                                                                                                                                                                                                                                                                                                                                              +21
                                                                                                                                                                                                                                                                                                                                                                                                              +22
                                                                                                                                                                                                                                                                                                                                                                                                              +23
                                                                                                                                                                                                                                                                                                                                                                                                              +24
                                                                                                                                                                                                                                                                                                                                                                                                              +25
                                                                                                                                                                                                                                                                                                                                                                                                              +26
                                                                                                                                                                                                                                                                                                                                                                                                              +27
                                                                                                                                                                                                                                                                                                                                                                                                              +28
                                                                                                                                                                                                                                                                                                                                                                                                              +29
                                                                                                                                                                                                                                                                                                                                                                                                              +30
                                                                                                                                                                                                                                                                                                                                                                                                              +31
                                                                                                                                                                                                                                                                                                                                                                                                              +32
                                                                                                                                                                                                                                                                                                                                                                                                              +33
                                                                                                                                                                                                                                                                                                                                                                                                              +34
                                                                                                                                                                                                                                                                                                                                                                                                              +35
                                                                                                                                                                                                                                                                                                                                                                                                              +36
                                                                                                                                                                                                                                                                                                                                                                                                              +37
                                                                                                                                                                                                                                                                                                                                                                                                              +38
                                                                                                                                                                                                                                                                                                                                                                                                              +39
                                                                                                                                                                                                                                                                                                                                                                                                              +40
                                                                                                                                                                                                                                                                                                                                                                                                              +41
                                                                                                                                                                                                                                                                                                                                                                                                              +42
                                                                                                                                                                                                                                                                                                                                                                                                              +43
                                                                                                                                                                                                                                                                                                                                                                                                              +44
                                                                                                                                                                                                                                                                                                                                                                                                              +45
                                                                                                                                                                                                                                                                                                                                                                                                              +46
                                                                                                                                                                                                                                                                                                                                                                                                              +47
                                                                                                                                                                                                                                                                                                                                                                                                              +48
                                                                                                                                                                                                                                                                                                                                                                                                              +49
                                                                                                                                                                                                                                                                                                                                                                                                              +50
                                                                                                                                                                                                                                                                                                                                                                                                              +51
                                                                                                                                                                                                                                                                                                                                                                                                              +52
                                                                                                                                                                                                                                                                                                                                                                                                              def display_weather():
                                                                                                                                                                                                                                                                                                                                                                                                              +    global weather, city, current_temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                              +    min = 120
                                                                                                                                                                                                                                                                                                                                                                                                              +    max = -50
                                                                                                                                                                                                                                                                                                                                                                                                              +    for i in range(0, 39):
                                                                                                                                                                                                                                                                                                                                                                                                              +        temp = round(weather['list'][i]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +        if temp < min:
                                                                                                                                                                                                                                                                                                                                                                                                              +            min = temp
                                                                                                                                                                                                                                                                                                                                                                                                              +        if temp > max:
                                                                                                                                                                                                                                                                                                                                                                                                              +            max = temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    min = round(min)
                                                                                                                                                                                                                                                                                                                                                                                                              +    max = round(max)
                                                                                                                                                                                                                                                                                                                                                                                                              +    temp_range_height = max - min
                                                                                                                                                                                                                                                                                                                                                                                                              +    graph_height = 54
                                                                                                                                                                                                                                                                                                                                                                                                              +    scale = graph_height/temp_range_height
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('min/max/range/scale:', min, max, temp_range_height, scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    # display city name, current temp, min and max
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(city + ': ' + str(current_temp), 0, 0, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(min), 0, 57, 1) # bottom left corner
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(max), 0, 10, 1) # under top row
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    max_points = 39
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    # graph temps for the next n periods
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('Date          Tmp TNx   Y  Y2  Del')
                                                                                                                                                                                                                                                                                                                                                                                                              +    for i in range(0, max_points):
                                                                                                                                                                                                                                                                                                                                                                                                              +        temp = round(weather['list'][i]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +        x = i * 3 # scaled x
                                                                                                                                                                                                                                                                                                                                                                                                              +        y = 63 - round((temp - min)*scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x, y, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        # now draw the next two points
                                                                                                                                                                                                                                                                                                                                                                                                              +        if i < max_points:
                                                                                                                                                                                                                                                                                                                                                                                                              +            temp_next = round(weather['list'][i+1]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +            y_next = 63 - round((temp_next - min)*scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +        y_delta = -round((y - y_next)/3) # a small positive or negative number
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        # for debugging - fixed with columns with leading spaces
                                                                                                                                                                                                                                                                                                                                                                                                              +        print(weather['list'][i]['dt_txt'][0:13],
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(temp),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(temp_next),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y_next),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y_delta))
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        # should be 1/3 of the way to the next point
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x+1, y + y_delta, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +        # should be 2/3 of the way to the next point
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x+2, y + 2*y_delta, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              The Main Loop

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              The main loop repeats forever, pausing every hour between updates. It gets first calls the rest service, +extracts the city name and current temperature and then calls the display_weather() function using global variables for the JSON file, city and current temperature.

                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              1
                                                                                                                                                                                                                                                                                                                                                                                                              +2
                                                                                                                                                                                                                                                                                                                                                                                                              +3
                                                                                                                                                                                                                                                                                                                                                                                                              +4
                                                                                                                                                                                                                                                                                                                                                                                                              +5
                                                                                                                                                                                                                                                                                                                                                                                                              +6
                                                                                                                                                                                                                                                                                                                                                                                                              +7
                                                                                                                                                                                                                                                                                                                                                                                                              +8
                                                                                                                                                                                                                                                                                                                                                                                                              +9
                                                                                                                                                                                                                                                                                                                                                                                                              while True:
                                                                                                                                                                                                                                                                                                                                                                                                              +    # globals: weather, city, current_temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    weather = urequests.get(url).json()
                                                                                                                                                                                                                                                                                                                                                                                                              +    # print(weather)
                                                                                                                                                                                                                                                                                                                                                                                                              +    city = weather['city']['name']
                                                                                                                                                                                                                                                                                                                                                                                                              +    current_temp = round(weather['list'][0]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +    display_weather()
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('Going to sleep for one hour')
                                                                                                                                                                                                                                                                                                                                                                                                              +    sleep(3600) # sleep one hour
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              Full Sample Code

                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                              +  2
                                                                                                                                                                                                                                                                                                                                                                                                              +  3
                                                                                                                                                                                                                                                                                                                                                                                                              +  4
                                                                                                                                                                                                                                                                                                                                                                                                              +  5
                                                                                                                                                                                                                                                                                                                                                                                                              +  6
                                                                                                                                                                                                                                                                                                                                                                                                              +  7
                                                                                                                                                                                                                                                                                                                                                                                                              +  8
                                                                                                                                                                                                                                                                                                                                                                                                              +  9
                                                                                                                                                                                                                                                                                                                                                                                                              + 10
                                                                                                                                                                                                                                                                                                                                                                                                              + 11
                                                                                                                                                                                                                                                                                                                                                                                                              + 12
                                                                                                                                                                                                                                                                                                                                                                                                              + 13
                                                                                                                                                                                                                                                                                                                                                                                                              + 14
                                                                                                                                                                                                                                                                                                                                                                                                              + 15
                                                                                                                                                                                                                                                                                                                                                                                                              + 16
                                                                                                                                                                                                                                                                                                                                                                                                              + 17
                                                                                                                                                                                                                                                                                                                                                                                                              + 18
                                                                                                                                                                                                                                                                                                                                                                                                              + 19
                                                                                                                                                                                                                                                                                                                                                                                                              + 20
                                                                                                                                                                                                                                                                                                                                                                                                              + 21
                                                                                                                                                                                                                                                                                                                                                                                                              + 22
                                                                                                                                                                                                                                                                                                                                                                                                              + 23
                                                                                                                                                                                                                                                                                                                                                                                                              + 24
                                                                                                                                                                                                                                                                                                                                                                                                              + 25
                                                                                                                                                                                                                                                                                                                                                                                                              + 26
                                                                                                                                                                                                                                                                                                                                                                                                              + 27
                                                                                                                                                                                                                                                                                                                                                                                                              + 28
                                                                                                                                                                                                                                                                                                                                                                                                              + 29
                                                                                                                                                                                                                                                                                                                                                                                                              + 30
                                                                                                                                                                                                                                                                                                                                                                                                              + 31
                                                                                                                                                                                                                                                                                                                                                                                                              + 32
                                                                                                                                                                                                                                                                                                                                                                                                              + 33
                                                                                                                                                                                                                                                                                                                                                                                                              + 34
                                                                                                                                                                                                                                                                                                                                                                                                              + 35
                                                                                                                                                                                                                                                                                                                                                                                                              + 36
                                                                                                                                                                                                                                                                                                                                                                                                              + 37
                                                                                                                                                                                                                                                                                                                                                                                                              + 38
                                                                                                                                                                                                                                                                                                                                                                                                              + 39
                                                                                                                                                                                                                                                                                                                                                                                                              + 40
                                                                                                                                                                                                                                                                                                                                                                                                              + 41
                                                                                                                                                                                                                                                                                                                                                                                                              + 42
                                                                                                                                                                                                                                                                                                                                                                                                              + 43
                                                                                                                                                                                                                                                                                                                                                                                                              + 44
                                                                                                                                                                                                                                                                                                                                                                                                              + 45
                                                                                                                                                                                                                                                                                                                                                                                                              + 46
                                                                                                                                                                                                                                                                                                                                                                                                              + 47
                                                                                                                                                                                                                                                                                                                                                                                                              + 48
                                                                                                                                                                                                                                                                                                                                                                                                              + 49
                                                                                                                                                                                                                                                                                                                                                                                                              + 50
                                                                                                                                                                                                                                                                                                                                                                                                              + 51
                                                                                                                                                                                                                                                                                                                                                                                                              + 52
                                                                                                                                                                                                                                                                                                                                                                                                              + 53
                                                                                                                                                                                                                                                                                                                                                                                                              + 54
                                                                                                                                                                                                                                                                                                                                                                                                              + 55
                                                                                                                                                                                                                                                                                                                                                                                                              + 56
                                                                                                                                                                                                                                                                                                                                                                                                              + 57
                                                                                                                                                                                                                                                                                                                                                                                                              + 58
                                                                                                                                                                                                                                                                                                                                                                                                              + 59
                                                                                                                                                                                                                                                                                                                                                                                                              + 60
                                                                                                                                                                                                                                                                                                                                                                                                              + 61
                                                                                                                                                                                                                                                                                                                                                                                                              + 62
                                                                                                                                                                                                                                                                                                                                                                                                              + 63
                                                                                                                                                                                                                                                                                                                                                                                                              + 64
                                                                                                                                                                                                                                                                                                                                                                                                              + 65
                                                                                                                                                                                                                                                                                                                                                                                                              + 66
                                                                                                                                                                                                                                                                                                                                                                                                              + 67
                                                                                                                                                                                                                                                                                                                                                                                                              + 68
                                                                                                                                                                                                                                                                                                                                                                                                              + 69
                                                                                                                                                                                                                                                                                                                                                                                                              + 70
                                                                                                                                                                                                                                                                                                                                                                                                              + 71
                                                                                                                                                                                                                                                                                                                                                                                                              + 72
                                                                                                                                                                                                                                                                                                                                                                                                              + 73
                                                                                                                                                                                                                                                                                                                                                                                                              + 74
                                                                                                                                                                                                                                                                                                                                                                                                              + 75
                                                                                                                                                                                                                                                                                                                                                                                                              + 76
                                                                                                                                                                                                                                                                                                                                                                                                              + 77
                                                                                                                                                                                                                                                                                                                                                                                                              + 78
                                                                                                                                                                                                                                                                                                                                                                                                              + 79
                                                                                                                                                                                                                                                                                                                                                                                                              + 80
                                                                                                                                                                                                                                                                                                                                                                                                              + 81
                                                                                                                                                                                                                                                                                                                                                                                                              + 82
                                                                                                                                                                                                                                                                                                                                                                                                              + 83
                                                                                                                                                                                                                                                                                                                                                                                                              + 84
                                                                                                                                                                                                                                                                                                                                                                                                              + 85
                                                                                                                                                                                                                                                                                                                                                                                                              + 86
                                                                                                                                                                                                                                                                                                                                                                                                              + 87
                                                                                                                                                                                                                                                                                                                                                                                                              + 88
                                                                                                                                                                                                                                                                                                                                                                                                              + 89
                                                                                                                                                                                                                                                                                                                                                                                                              + 90
                                                                                                                                                                                                                                                                                                                                                                                                              + 91
                                                                                                                                                                                                                                                                                                                                                                                                              + 92
                                                                                                                                                                                                                                                                                                                                                                                                              + 93
                                                                                                                                                                                                                                                                                                                                                                                                              + 94
                                                                                                                                                                                                                                                                                                                                                                                                              + 95
                                                                                                                                                                                                                                                                                                                                                                                                              + 96
                                                                                                                                                                                                                                                                                                                                                                                                              + 97
                                                                                                                                                                                                                                                                                                                                                                                                              + 98
                                                                                                                                                                                                                                                                                                                                                                                                              + 99
                                                                                                                                                                                                                                                                                                                                                                                                              +100
                                                                                                                                                                                                                                                                                                                                                                                                              +101
                                                                                                                                                                                                                                                                                                                                                                                                              +102
                                                                                                                                                                                                                                                                                                                                                                                                              +103
                                                                                                                                                                                                                                                                                                                                                                                                              +104
                                                                                                                                                                                                                                                                                                                                                                                                              +105
                                                                                                                                                                                                                                                                                                                                                                                                              +106
                                                                                                                                                                                                                                                                                                                                                                                                              +107
                                                                                                                                                                                                                                                                                                                                                                                                              +108
                                                                                                                                                                                                                                                                                                                                                                                                              +109
                                                                                                                                                                                                                                                                                                                                                                                                              +110
                                                                                                                                                                                                                                                                                                                                                                                                              +111
                                                                                                                                                                                                                                                                                                                                                                                                              +112
                                                                                                                                                                                                                                                                                                                                                                                                              +113
                                                                                                                                                                                                                                                                                                                                                                                                              +114
                                                                                                                                                                                                                                                                                                                                                                                                              +115
                                                                                                                                                                                                                                                                                                                                                                                                              +116
                                                                                                                                                                                                                                                                                                                                                                                                              +117
                                                                                                                                                                                                                                                                                                                                                                                                              +118
                                                                                                                                                                                                                                                                                                                                                                                                              +119
                                                                                                                                                                                                                                                                                                                                                                                                              +120
                                                                                                                                                                                                                                                                                                                                                                                                              +121
                                                                                                                                                                                                                                                                                                                                                                                                              +122
                                                                                                                                                                                                                                                                                                                                                                                                              +123
                                                                                                                                                                                                                                                                                                                                                                                                              +124
                                                                                                                                                                                                                                                                                                                                                                                                              +125
                                                                                                                                                                                                                                                                                                                                                                                                              +126
                                                                                                                                                                                                                                                                                                                                                                                                              +127
                                                                                                                                                                                                                                                                                                                                                                                                              import network
                                                                                                                                                                                                                                                                                                                                                                                                              +import ssd1306
                                                                                                                                                                                                                                                                                                                                                                                                              +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                              +import urequests
                                                                                                                                                                                                                                                                                                                                                                                                              +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +# startup
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                              +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                              +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +WIDTH = 128
                                                                                                                                                                                                                                                                                                                                                                                                              +HEIGHT = 64
                                                                                                                                                                                                                                                                                                                                                                                                              +SCK=machine.Pin(2)
                                                                                                                                                                                                                                                                                                                                                                                                              +SDL=machine.Pin(3)
                                                                                                                                                                                                                                                                                                                                                                                                              +spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)
                                                                                                                                                                                                                                                                                                                                                                                                              +CS = machine.Pin(0)
                                                                                                                                                                                                                                                                                                                                                                                                              +DC = machine.Pin(1)
                                                                                                                                                                                                                                                                                                                                                                                                              +RES = machine.Pin(4)
                                                                                                                                                                                                                                                                                                                                                                                                              +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                                                                                                                                                                                                                                                                                                              +oled.poweron()
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +def display_startup(counter):
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text('Running startup', 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text('Connecting to', 0, 20, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(secrets.SSID, 0, 30, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(counter), 0, 40, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +def display_status(counter):
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                              +    # display the network name
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text('n:' + secrets.SSID, 0, 0, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    # display the connection time
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text('t:', 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(connection_time)+ ' ms', 15, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +def display_weather():
                                                                                                                                                                                                                                                                                                                                                                                                              +    global weather, city, current_temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                              +    min = 120
                                                                                                                                                                                                                                                                                                                                                                                                              +    max = -50
                                                                                                                                                                                                                                                                                                                                                                                                              +    for i in range(0, 39):
                                                                                                                                                                                                                                                                                                                                                                                                              +        temp = round(weather['list'][i]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +        if temp < min:
                                                                                                                                                                                                                                                                                                                                                                                                              +            min = temp
                                                                                                                                                                                                                                                                                                                                                                                                              +        if temp > max:
                                                                                                                                                                                                                                                                                                                                                                                                              +            max = temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    min = round(min)
                                                                                                                                                                                                                                                                                                                                                                                                              +    max = round(max)
                                                                                                                                                                                                                                                                                                                                                                                                              +    temp_range_height = max - min
                                                                                                                                                                                                                                                                                                                                                                                                              +    graph_height = 54
                                                                                                                                                                                                                                                                                                                                                                                                              +    scale = graph_height/temp_range_height
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('min/max/range/scale:', min, max, temp_range_height, scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    # display city name, current temp, min and max
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(city + ': ' + str(current_temp), 0, 0, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(min), 0, 57, 1) # bottom left corner
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.text(str(max), 0, 10, 1) # under top row
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    max_points = 39
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +    # graph temps for the next n periods
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('Date          Tmp TNx   Y  Y2  Del')
                                                                                                                                                                                                                                                                                                                                                                                                              +    for i in range(0, max_points):
                                                                                                                                                                                                                                                                                                                                                                                                              +        temp = round(weather['list'][i]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +        x = i * 3 # scaled x
                                                                                                                                                                                                                                                                                                                                                                                                              +        y = 63 - round((temp - min)*scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x, y, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        # now draw the next two points
                                                                                                                                                                                                                                                                                                                                                                                                              +        if i < max_points:
                                                                                                                                                                                                                                                                                                                                                                                                              +            temp_next = round(weather['list'][i+1]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +            y_next = 63 - round((temp_next - min)*scale)
                                                                                                                                                                                                                                                                                                                                                                                                              +        y_delta = -round((y - y_next)/3) # a small positive or negative number
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        print(weather['list'][i]['dt_txt'][0:13],
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(temp),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(temp_next),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y_next),
                                                                                                                                                                                                                                                                                                                                                                                                              +              '{: 3.3d}'.format(y_delta))
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +        # should be 1/3 of the way to the next point
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x+1, y + y_delta, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +        # should be 2/3 of the way to the next point
                                                                                                                                                                                                                                                                                                                                                                                                              +        oled.pixel(x+2, y + 2*y_delta, 1)
                                                                                                                                                                                                                                                                                                                                                                                                              +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +if not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                              +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                              +    print("Waiting for connection...")
                                                                                                                                                                                                                                                                                                                                                                                                              +    counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                              +    while not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                              +        sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                              +        print(counter, '.', sep='', end='', )
                                                                                                                                                                                                                                                                                                                                                                                                              +        counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                              +        display_startup(counter)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +delta = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                              +#print("Connect Time:", delta, 'milliseconds')
                                                                                                                                                                                                                                                                                                                                                                                                              +#print("IP Address:", wlan.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +base = 'http://api.openweathermap.org/data/2.5/forecast?units=imperial&'
                                                                                                                                                                                                                                                                                                                                                                                                              +location = '5037649' # Minneapolis, MN USA
                                                                                                                                                                                                                                                                                                                                                                                                              +url = base + 'id=' + location + '&appid=' + secrets.appid
                                                                                                                                                                                                                                                                                                                                                                                                              +#print(url)
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +max_times = 39
                                                                                                                                                                                                                                                                                                                                                                                                              +#for i in range(0, max_times):    
                                                                                                                                                                                                                                                                                                                                                                                                              +    #print(' Temp: ', weather['list'][i]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +while True:
                                                                                                                                                                                                                                                                                                                                                                                                              +    # globals: weather, city, current_temp
                                                                                                                                                                                                                                                                                                                                                                                                              +    weather = urequests.get(url).json()
                                                                                                                                                                                                                                                                                                                                                                                                              +    # print(weather)
                                                                                                                                                                                                                                                                                                                                                                                                              +    city = weather['city']['name']
                                                                                                                                                                                                                                                                                                                                                                                                              +    current_temp = round(weather['list'][0]['main']['temp'])
                                                                                                                                                                                                                                                                                                                                                                                                              +    display_weather()
                                                                                                                                                                                                                                                                                                                                                                                                              +    print('Going to sleep for one hour.')
                                                                                                                                                                                                                                                                                                                                                                                                              +    sleep(3600) # sleep one hour
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              Sample Debugging

                                                                                                                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                                                                                                                              To allow you to see the math for the plotting and interpolation we have added a print that prints the temperatures and y coordinates in fixed with format. Here is an example of this output:

                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                               1
                                                                                                                                                                                                                                                                                                                                                                                                              + 2
                                                                                                                                                                                                                                                                                                                                                                                                              + 3
                                                                                                                                                                                                                                                                                                                                                                                                              + 4
                                                                                                                                                                                                                                                                                                                                                                                                              + 5
                                                                                                                                                                                                                                                                                                                                                                                                              + 6
                                                                                                                                                                                                                                                                                                                                                                                                              + 7
                                                                                                                                                                                                                                                                                                                                                                                                              + 8
                                                                                                                                                                                                                                                                                                                                                                                                              + 9
                                                                                                                                                                                                                                                                                                                                                                                                              +10
                                                                                                                                                                                                                                                                                                                                                                                                              +11
                                                                                                                                                                                                                                                                                                                                                                                                              +12
                                                                                                                                                                                                                                                                                                                                                                                                              +13
                                                                                                                                                                                                                                                                                                                                                                                                              +14
                                                                                                                                                                                                                                                                                                                                                                                                              +15
                                                                                                                                                                                                                                                                                                                                                                                                              +16
                                                                                                                                                                                                                                                                                                                                                                                                              +17
                                                                                                                                                                                                                                                                                                                                                                                                              +18
                                                                                                                                                                                                                                                                                                                                                                                                              +19
                                                                                                                                                                                                                                                                                                                                                                                                              +20
                                                                                                                                                                                                                                                                                                                                                                                                              +21
                                                                                                                                                                                                                                                                                                                                                                                                              +22
                                                                                                                                                                                                                                                                                                                                                                                                              +23
                                                                                                                                                                                                                                                                                                                                                                                                              +24
                                                                                                                                                                                                                                                                                                                                                                                                              +25
                                                                                                                                                                                                                                                                                                                                                                                                              +26
                                                                                                                                                                                                                                                                                                                                                                                                              +27
                                                                                                                                                                                                                                                                                                                                                                                                              +28
                                                                                                                                                                                                                                                                                                                                                                                                              +29
                                                                                                                                                                                                                                                                                                                                                                                                              +30
                                                                                                                                                                                                                                                                                                                                                                                                              +31
                                                                                                                                                                                                                                                                                                                                                                                                              +32
                                                                                                                                                                                                                                                                                                                                                                                                              +33
                                                                                                                                                                                                                                                                                                                                                                                                              +34
                                                                                                                                                                                                                                                                                                                                                                                                              +35
                                                                                                                                                                                                                                                                                                                                                                                                              +36
                                                                                                                                                                                                                                                                                                                                                                                                              +37
                                                                                                                                                                                                                                                                                                                                                                                                              +38
                                                                                                                                                                                                                                                                                                                                                                                                              +39
                                                                                                                                                                                                                                                                                                                                                                                                              +40
                                                                                                                                                                                                                                                                                                                                                                                                              +41
                                                                                                                                                                                                                                                                                                                                                                                                              +42
                                                                                                                                                                                                                                                                                                                                                                                                              +43
                                                                                                                                                                                                                                                                                                                                                                                                              Connecting to WiFi Network Name: anndan-2.4
                                                                                                                                                                                                                                                                                                                                                                                                              +min/max/range/scale: 60 87 27 2.0
                                                                                                                                                                                                                                                                                                                                                                                                              +Date           Tmp Tnx  Y  Y2  Del
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 03  68  68  47  47   0
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 06  68  68  47  47   0
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 09  68  65  47  53   2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 12  65  72  53  39  -5
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 15  72  83  39  17  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 18  83  87  17   9  -3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-13 21  87  82   9  19   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 00  82  71  19  41   7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 03  71  66  41  51   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 06  66  62  51  59   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 09  62  60  59  63   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 12  60  71  63  41  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 15  71  82  41  19  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 18  82  85  19  13  -2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-14 21  85  82  13  19   2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 00  82  73  19  37   6
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 03  73  69  37  45   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 06  69  66  45  51   2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 09  66  64  51  55   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 12  64  74  55  35  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 15  74  83  35  17  -6
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 18  83  85  17  13  -1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-15 21  85  81  13  21   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 00  81  75  21  33   4
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 03  75  70  33  43   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 06  70  69  43  45   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 09  69  66  45  51   2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 12  66  66  51  51   0
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 15  66  79  51  25  -9
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 18  79  80  25  23  -1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-16 21  80  70  23  43   7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 00  70  65  43  53   3
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 03  65  64  53  55   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 06  64  63  55  57   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 09  63  61  57  61   1
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 12  61  72  61  39  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 15  72  82  39  19  -7
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 18  82  85  19  13  -2
                                                                                                                                                                                                                                                                                                                                                                                                              +2022-08-17 21  85  81  13  21   3
                                                                                                                                                                                                                                                                                                                                                                                                              +Going to sleep for one hour
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                              + Get Weather Forecast +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                              + WiFi Clock +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + + + + \ No newline at end of file diff --git a/wireless/10-wifi-clock/index.html b/wireless/10-wifi-clock/index.html new file mode 100644 index 000000000..8a02e7fd9 --- /dev/null +++ b/wireless/10-wifi-clock/index.html @@ -0,0 +1,1910 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + WiFi Clock - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + WiFi Clock + + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + + +
                                                                                                                                                                                                                                                                                                                                                                                                              + +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                              + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + WiFi Clock + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + The Config File + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + Sample Output: + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + The Config File + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Full Program + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + Sample Output: + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + + + References + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                • + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                                WiFi Clock

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                In the US, we can access a service called the "Network Time Protocol" or NTP. +This service allows you to get the precise time using your WiFi network.

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                Calling the NTP service in MicroPython is simple once you have +connected to your local wireless access point:

                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                                                                import ntptime
                                                                                                                                                                                                                                                                                                                                                                                                                +ntptime.host = 'us.pool.ntp.org'
                                                                                                                                                                                                                                                                                                                                                                                                                +ntptime.timeout = 10
                                                                                                                                                                                                                                                                                                                                                                                                                +ntptime.settime()
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                After running this code (and checking for errors) your internal Real-time Clock (RTC) will be synced to the NTP server.

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                The rest of this code does the work of adjusting the clock to your local timezone and correcting for any changes in daylight savings time in your area.

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                The Config File

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                We always put local credentials in a separate file so it does not get checked into GitHub.

                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                                wifi_ssid = 'mywifinetworkname'
                                                                                                                                                                                                                                                                                                                                                                                                                +wifi_pass = 'mypassword'
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                Full Program

                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                 1
                                                                                                                                                                                                                                                                                                                                                                                                                + 2
                                                                                                                                                                                                                                                                                                                                                                                                                + 3
                                                                                                                                                                                                                                                                                                                                                                                                                + 4
                                                                                                                                                                                                                                                                                                                                                                                                                + 5
                                                                                                                                                                                                                                                                                                                                                                                                                + 6
                                                                                                                                                                                                                                                                                                                                                                                                                + 7
                                                                                                                                                                                                                                                                                                                                                                                                                + 8
                                                                                                                                                                                                                                                                                                                                                                                                                + 9
                                                                                                                                                                                                                                                                                                                                                                                                                +10
                                                                                                                                                                                                                                                                                                                                                                                                                +11
                                                                                                                                                                                                                                                                                                                                                                                                                +12
                                                                                                                                                                                                                                                                                                                                                                                                                +13
                                                                                                                                                                                                                                                                                                                                                                                                                +14
                                                                                                                                                                                                                                                                                                                                                                                                                +15
                                                                                                                                                                                                                                                                                                                                                                                                                +16
                                                                                                                                                                                                                                                                                                                                                                                                                +17
                                                                                                                                                                                                                                                                                                                                                                                                                +18
                                                                                                                                                                                                                                                                                                                                                                                                                +19
                                                                                                                                                                                                                                                                                                                                                                                                                +20
                                                                                                                                                                                                                                                                                                                                                                                                                +21
                                                                                                                                                                                                                                                                                                                                                                                                                +22
                                                                                                                                                                                                                                                                                                                                                                                                                +23
                                                                                                                                                                                                                                                                                                                                                                                                                +24
                                                                                                                                                                                                                                                                                                                                                                                                                +25
                                                                                                                                                                                                                                                                                                                                                                                                                +26
                                                                                                                                                                                                                                                                                                                                                                                                                +27
                                                                                                                                                                                                                                                                                                                                                                                                                +28
                                                                                                                                                                                                                                                                                                                                                                                                                +29
                                                                                                                                                                                                                                                                                                                                                                                                                +30
                                                                                                                                                                                                                                                                                                                                                                                                                +31
                                                                                                                                                                                                                                                                                                                                                                                                                +32
                                                                                                                                                                                                                                                                                                                                                                                                                +33
                                                                                                                                                                                                                                                                                                                                                                                                                +34
                                                                                                                                                                                                                                                                                                                                                                                                                +35
                                                                                                                                                                                                                                                                                                                                                                                                                +36
                                                                                                                                                                                                                                                                                                                                                                                                                +37
                                                                                                                                                                                                                                                                                                                                                                                                                +38
                                                                                                                                                                                                                                                                                                                                                                                                                +39
                                                                                                                                                                                                                                                                                                                                                                                                                +40
                                                                                                                                                                                                                                                                                                                                                                                                                +41
                                                                                                                                                                                                                                                                                                                                                                                                                +42
                                                                                                                                                                                                                                                                                                                                                                                                                +43
                                                                                                                                                                                                                                                                                                                                                                                                                +44
                                                                                                                                                                                                                                                                                                                                                                                                                +45
                                                                                                                                                                                                                                                                                                                                                                                                                +46
                                                                                                                                                                                                                                                                                                                                                                                                                +47
                                                                                                                                                                                                                                                                                                                                                                                                                +48
                                                                                                                                                                                                                                                                                                                                                                                                                +49
                                                                                                                                                                                                                                                                                                                                                                                                                +50
                                                                                                                                                                                                                                                                                                                                                                                                                +51
                                                                                                                                                                                                                                                                                                                                                                                                                +52
                                                                                                                                                                                                                                                                                                                                                                                                                +53
                                                                                                                                                                                                                                                                                                                                                                                                                +54
                                                                                                                                                                                                                                                                                                                                                                                                                +55
                                                                                                                                                                                                                                                                                                                                                                                                                +56
                                                                                                                                                                                                                                                                                                                                                                                                                +57
                                                                                                                                                                                                                                                                                                                                                                                                                +58
                                                                                                                                                                                                                                                                                                                                                                                                                +59
                                                                                                                                                                                                                                                                                                                                                                                                                +60
                                                                                                                                                                                                                                                                                                                                                                                                                +61
                                                                                                                                                                                                                                                                                                                                                                                                                +62
                                                                                                                                                                                                                                                                                                                                                                                                                +63
                                                                                                                                                                                                                                                                                                                                                                                                                +64
                                                                                                                                                                                                                                                                                                                                                                                                                +65
                                                                                                                                                                                                                                                                                                                                                                                                                +66
                                                                                                                                                                                                                                                                                                                                                                                                                +67
                                                                                                                                                                                                                                                                                                                                                                                                                +68
                                                                                                                                                                                                                                                                                                                                                                                                                +69
                                                                                                                                                                                                                                                                                                                                                                                                                +70
                                                                                                                                                                                                                                                                                                                                                                                                                +71
                                                                                                                                                                                                                                                                                                                                                                                                                +72
                                                                                                                                                                                                                                                                                                                                                                                                                +73
                                                                                                                                                                                                                                                                                                                                                                                                                +74
                                                                                                                                                                                                                                                                                                                                                                                                                +75
                                                                                                                                                                                                                                                                                                                                                                                                                +76
                                                                                                                                                                                                                                                                                                                                                                                                                +77
                                                                                                                                                                                                                                                                                                                                                                                                                +78
                                                                                                                                                                                                                                                                                                                                                                                                                +79
                                                                                                                                                                                                                                                                                                                                                                                                                import ntptime, network
                                                                                                                                                                                                                                                                                                                                                                                                                +from machine import RTC
                                                                                                                                                                                                                                                                                                                                                                                                                +from utime import sleep, sleep_ms, time, localtime, mktime
                                                                                                                                                                                                                                                                                                                                                                                                                +import config
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +# US Central
                                                                                                                                                                                                                                                                                                                                                                                                                +timeZone = -6
                                                                                                                                                                                                                                                                                                                                                                                                                +# try one of these
                                                                                                                                                                                                                                                                                                                                                                                                                +ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org'
                                                                                                                                                                                                                                                                                                                                                                                                                +ntptime.timeout = 10
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +def wifiConnect():
                                                                                                                                                                                                                                                                                                                                                                                                                +    wifi = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                                +    wifi.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                                +    wifi.config(pm = 0xa11140) # disables wifi sleep mode
                                                                                                                                                                                                                                                                                                                                                                                                                +    if not wifi.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                +        wifi.connect(config.wifi_ssid, config.wifi_pass)
                                                                                                                                                                                                                                                                                                                                                                                                                +        print('Connecting..', end='')
                                                                                                                                                                                                                                                                                                                                                                                                                +        max_wait = 10
                                                                                                                                                                                                                                                                                                                                                                                                                +        while max_wait > 0:
                                                                                                                                                                                                                                                                                                                                                                                                                +            if wifi.status() < 0 or wifi.status() >= 3: break
                                                                                                                                                                                                                                                                                                                                                                                                                +            sleep_ms(1000)
                                                                                                                                                                                                                                                                                                                                                                                                                +            print('.', end='')
                                                                                                                                                                                                                                                                                                                                                                                                                +            max_wait -= 1
                                                                                                                                                                                                                                                                                                                                                                                                                +        print()
                                                                                                                                                                                                                                                                                                                                                                                                                +        if wifi.status() != 3: print('Could not connect to wifi!')
                                                                                                                                                                                                                                                                                                                                                                                                                +    # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                                +    sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                +    return wifi
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +# daylight savings time
                                                                                                                                                                                                                                                                                                                                                                                                                +def dst():
                                                                                                                                                                                                                                                                                                                                                                                                                +    year, weekday = localtime()[0], localtime()[6]
                                                                                                                                                                                                                                                                                                                                                                                                                +    dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0))
                                                                                                                                                                                                                                                                                                                                                                                                                +    dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0))
                                                                                                                                                                                                                                                                                                                                                                                                                +    return dst_start <= time() < dst_end
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +def setRTC():
                                                                                                                                                                                                                                                                                                                                                                                                                +    timeset = False
                                                                                                                                                                                                                                                                                                                                                                                                                +    timetries = 0
                                                                                                                                                                                                                                                                                                                                                                                                                +    maxtries = 5
                                                                                                                                                                                                                                                                                                                                                                                                                +    while not timeset and timetries < maxtries:
                                                                                                                                                                                                                                                                                                                                                                                                                +        timetries += 1
                                                                                                                                                                                                                                                                                                                                                                                                                +        try:
                                                                                                                                                                                                                                                                                                                                                                                                                +            ntptime.settime() # update time from ntp server
                                                                                                                                                                                                                                                                                                                                                                                                                +            timeset = True
                                                                                                                                                                                                                                                                                                                                                                                                                +        except:
                                                                                                                                                                                                                                                                                                                                                                                                                +            print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.')
                                                                                                                                                                                                                                                                                                                                                                                                                +            if timetries < maxtries: sleep_ms(15000)
                                                                                                                                                                                                                                                                                                                                                                                                                +        if timeset:
                                                                                                                                                                                                                                                                                                                                                                                                                +            sleep_ms(200)
                                                                                                                                                                                                                                                                                                                                                                                                                +            rtc = RTC()
                                                                                                                                                                                                                                                                                                                                                                                                                +            tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600
                                                                                                                                                                                                                                                                                                                                                                                                                +            #tz_offset = timeZone * 3600 # without daylight savings
                                                                                                                                                                                                                                                                                                                                                                                                                +            myt = localtime(time() + tz_offset)
                                                                                                                                                                                                                                                                                                                                                                                                                +            rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0))
                                                                                                                                                                                                                                                                                                                                                                                                                +            sleep_ms(200)
                                                                                                                                                                                                                                                                                                                                                                                                                +            dtime = rtc.datetime()
                                                                                                                                                                                                                                                                                                                                                                                                                +            timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm')
                                                                                                                                                                                                                                                                                                                                                                                                                +            datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}'
                                                                                                                                                                                                                                                                                                                                                                                                                +            # print('Time set to:', timestr, datestr)
                                                                                                                                                                                                                                                                                                                                                                                                                +            print(timestr, datestr)
                                                                                                                                                                                                                                                                                                                                                                                                                +            return True
                                                                                                                                                                                                                                                                                                                                                                                                                +    print('ERROR! Unable to update time from server!')
                                                                                                                                                                                                                                                                                                                                                                                                                +    return False
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +def update():
                                                                                                                                                                                                                                                                                                                                                                                                                +    success = False
                                                                                                                                                                                                                                                                                                                                                                                                                +    wifi = wifiConnect()
                                                                                                                                                                                                                                                                                                                                                                                                                +    sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                +    if wifi.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                +        success = setRTC()
                                                                                                                                                                                                                                                                                                                                                                                                                +        sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                +    return wifi, success
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +if __name__ == '__main__':
                                                                                                                                                                                                                                                                                                                                                                                                                +    while True:
                                                                                                                                                                                                                                                                                                                                                                                                                +        update()
                                                                                                                                                                                                                                                                                                                                                                                                                +        sleep(60)
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                Sample Output:

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                The console will display the following:

                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                1
                                                                                                                                                                                                                                                                                                                                                                                                                +2
                                                                                                                                                                                                                                                                                                                                                                                                                +3
                                                                                                                                                                                                                                                                                                                                                                                                                +4
                                                                                                                                                                                                                                                                                                                                                                                                                +5
                                                                                                                                                                                                                                                                                                                                                                                                                +6
                                                                                                                                                                                                                                                                                                                                                                                                                +7
                                                                                                                                                                                                                                                                                                                                                                                                                +8
                                                                                                                                                                                                                                                                                                                                                                                                                Connecting.........
                                                                                                                                                                                                                                                                                                                                                                                                                +Connected:  True 
                                                                                                                                                                                                                                                                                                                                                                                                                +IP:  10.0.0.118
                                                                                                                                                                                                                                                                                                                                                                                                                +NTP update attempt # 1 of 5 failed! Retrying in 15 seconds..
                                                                                                                                                                                                                                                                                                                                                                                                                +...
                                                                                                                                                                                                                                                                                                                                                                                                                +7:41pm 9/10/23
                                                                                                                                                                                                                                                                                                                                                                                                                +7:42pm 9/10/23
                                                                                                                                                                                                                                                                                                                                                                                                                +7:43pm 9/10/23
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                Note that connecting to the NTP server failed the first time but worked on the second attempt.

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                This program assumes you have a config.py file in the same folder that the clock.py program runs.

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                References

                                                                                                                                                                                                                                                                                                                                                                                                                +

                                                                                                                                                                                                                                                                                                                                                                                                                NikoKun

                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                                + Display Forecast on OLED +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                                + Advanced Labs +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + + + + \ No newline at end of file diff --git a/wireless/11-advanced-labs/index.html b/wireless/11-advanced-labs/index.html new file mode 100644 index 000000000..65ed41809 --- /dev/null +++ b/wireless/11-advanced-labs/index.html @@ -0,0 +1,1773 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Advanced Labs - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + Advanced Labs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + + +
                                                                                                                                                                                                                                                                                                                                                                                                                + +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + Advanced Labs + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Secure Communications with HTTPS + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Testing SSL/TLS on Standard Python + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Performance Monitoring with uiperf3 + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + UPIP Install + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + Testing Client Performance + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + With Display + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Secure Communications with HTTPS + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Testing SSL/TLS on Standard Python + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Performance Monitoring with uiperf3 + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + UPIP Install + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + + + Testing Client Performance + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  • + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                                  Advanced Wireless Labs

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  Secure Communications with HTTPS

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  In our documentation we frequently refer to secure communications as using a "Secure Sockets Layer". Although the term "SSL" is common, we are actually using a protocol called Transport Layer Security (TLS).

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  TLS replaces SSL. It is an Internet Engineering Task Force (IETF) standard protocol that provides authentication, privacy and data integrity between two communicating computer applications.

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  Note

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  The standard Python request library does not yet support HTTPS on urequest on the Pico W. This is because there are additional tools that require us to use keys and certificates to validate data on an encrypted SSL stream.

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  See the MicroPython SSL/TLS Library

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  Testing SSL/TLS on Standard Python

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                                                                                                                                  +3
                                                                                                                                                                                                                                                                                                                                                                                                                  +4
                                                                                                                                                                                                                                                                                                                                                                                                                  +5
                                                                                                                                                                                                                                                                                                                                                                                                                  +6
                                                                                                                                                                                                                                                                                                                                                                                                                  +7
                                                                                                                                                                                                                                                                                                                                                                                                                  +8
                                                                                                                                                                                                                                                                                                                                                                                                                  +9
                                                                                                                                                                                                                                                                                                                                                                                                                  import socket
                                                                                                                                                                                                                                                                                                                                                                                                                  +import ssl
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +hostname = 'www.python.org'
                                                                                                                                                                                                                                                                                                                                                                                                                  +context = ssl.create_default_context()
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +with socket.create_connection((hostname, 443)) as sock:
                                                                                                                                                                                                                                                                                                                                                                                                                  +    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
                                                                                                                                                                                                                                                                                                                                                                                                                  +        print(ssock.version())
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  returns: TLSv1.3

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  This tells you that the standard Python socket libraries use the TLS v1.3 protocol.

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  Performance Monitoring with uiperf3

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  iperf3 is a standard Python program for internet performance testing. For micropython, we have our own stripped down version called uiperf3.

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  IPerf3 uses a client-server testing model and measures networking performance between two system using various protocoos such as

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                  • UDP - User Datagram Protocol
                                                                                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                                                                                  • TCP - Transmission Control Protocol
                                                                                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                                                                                  • Streaming
                                                                                                                                                                                                                                                                                                                                                                                                                  • +
                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  It can also be used to measure total wireless throughput.

                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  UPIP Install

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                                                                                                                  upip.install("uiperf3")
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +

                                                                                                                                                                                                                                                                                                                                                                                                                  Testing Client Performance

                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  1
                                                                                                                                                                                                                                                                                                                                                                                                                  +2
                                                                                                                                                                                                                                                                                                                                                                                                                  import uiperf3
                                                                                                                                                                                                                                                                                                                                                                                                                  + uiperf3.client('MY_IP_ADDRESS')
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + WiFi Clock +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + With Display +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + + + + \ No newline at end of file diff --git a/wireless/12-display-clock/index.html b/wireless/12-display-clock/index.html new file mode 100644 index 000000000..1a16995bc --- /dev/null +++ b/wireless/12-display-clock/index.html @@ -0,0 +1,1502 @@ + + + + + + + + + + + + + + + + + + + + + + + Display Clock - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + Display Clock + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + + +
                                                                                                                                                                                                                                                                                                                                                                                                                  + +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                  + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Wireless + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                                    Display Clock

                                                                                                                                                                                                                                                                                                                                                                                                                    +

                                                                                                                                                                                                                                                                                                                                                                                                                    This is similar to the WiFi Clock but it uses an OLED display to +show the time and date.

                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                      1
                                                                                                                                                                                                                                                                                                                                                                                                                    +  2
                                                                                                                                                                                                                                                                                                                                                                                                                    +  3
                                                                                                                                                                                                                                                                                                                                                                                                                    +  4
                                                                                                                                                                                                                                                                                                                                                                                                                    +  5
                                                                                                                                                                                                                                                                                                                                                                                                                    +  6
                                                                                                                                                                                                                                                                                                                                                                                                                    +  7
                                                                                                                                                                                                                                                                                                                                                                                                                    +  8
                                                                                                                                                                                                                                                                                                                                                                                                                    +  9
                                                                                                                                                                                                                                                                                                                                                                                                                    + 10
                                                                                                                                                                                                                                                                                                                                                                                                                    + 11
                                                                                                                                                                                                                                                                                                                                                                                                                    + 12
                                                                                                                                                                                                                                                                                                                                                                                                                    + 13
                                                                                                                                                                                                                                                                                                                                                                                                                    + 14
                                                                                                                                                                                                                                                                                                                                                                                                                    + 15
                                                                                                                                                                                                                                                                                                                                                                                                                    + 16
                                                                                                                                                                                                                                                                                                                                                                                                                    + 17
                                                                                                                                                                                                                                                                                                                                                                                                                    + 18
                                                                                                                                                                                                                                                                                                                                                                                                                    + 19
                                                                                                                                                                                                                                                                                                                                                                                                                    + 20
                                                                                                                                                                                                                                                                                                                                                                                                                    + 21
                                                                                                                                                                                                                                                                                                                                                                                                                    + 22
                                                                                                                                                                                                                                                                                                                                                                                                                    + 23
                                                                                                                                                                                                                                                                                                                                                                                                                    + 24
                                                                                                                                                                                                                                                                                                                                                                                                                    + 25
                                                                                                                                                                                                                                                                                                                                                                                                                    + 26
                                                                                                                                                                                                                                                                                                                                                                                                                    + 27
                                                                                                                                                                                                                                                                                                                                                                                                                    + 28
                                                                                                                                                                                                                                                                                                                                                                                                                    + 29
                                                                                                                                                                                                                                                                                                                                                                                                                    + 30
                                                                                                                                                                                                                                                                                                                                                                                                                    + 31
                                                                                                                                                                                                                                                                                                                                                                                                                    + 32
                                                                                                                                                                                                                                                                                                                                                                                                                    + 33
                                                                                                                                                                                                                                                                                                                                                                                                                    + 34
                                                                                                                                                                                                                                                                                                                                                                                                                    + 35
                                                                                                                                                                                                                                                                                                                                                                                                                    + 36
                                                                                                                                                                                                                                                                                                                                                                                                                    + 37
                                                                                                                                                                                                                                                                                                                                                                                                                    + 38
                                                                                                                                                                                                                                                                                                                                                                                                                    + 39
                                                                                                                                                                                                                                                                                                                                                                                                                    + 40
                                                                                                                                                                                                                                                                                                                                                                                                                    + 41
                                                                                                                                                                                                                                                                                                                                                                                                                    + 42
                                                                                                                                                                                                                                                                                                                                                                                                                    + 43
                                                                                                                                                                                                                                                                                                                                                                                                                    + 44
                                                                                                                                                                                                                                                                                                                                                                                                                    + 45
                                                                                                                                                                                                                                                                                                                                                                                                                    + 46
                                                                                                                                                                                                                                                                                                                                                                                                                    + 47
                                                                                                                                                                                                                                                                                                                                                                                                                    + 48
                                                                                                                                                                                                                                                                                                                                                                                                                    + 49
                                                                                                                                                                                                                                                                                                                                                                                                                    + 50
                                                                                                                                                                                                                                                                                                                                                                                                                    + 51
                                                                                                                                                                                                                                                                                                                                                                                                                    + 52
                                                                                                                                                                                                                                                                                                                                                                                                                    + 53
                                                                                                                                                                                                                                                                                                                                                                                                                    + 54
                                                                                                                                                                                                                                                                                                                                                                                                                    + 55
                                                                                                                                                                                                                                                                                                                                                                                                                    + 56
                                                                                                                                                                                                                                                                                                                                                                                                                    + 57
                                                                                                                                                                                                                                                                                                                                                                                                                    + 58
                                                                                                                                                                                                                                                                                                                                                                                                                    + 59
                                                                                                                                                                                                                                                                                                                                                                                                                    + 60
                                                                                                                                                                                                                                                                                                                                                                                                                    + 61
                                                                                                                                                                                                                                                                                                                                                                                                                    + 62
                                                                                                                                                                                                                                                                                                                                                                                                                    + 63
                                                                                                                                                                                                                                                                                                                                                                                                                    + 64
                                                                                                                                                                                                                                                                                                                                                                                                                    + 65
                                                                                                                                                                                                                                                                                                                                                                                                                    + 66
                                                                                                                                                                                                                                                                                                                                                                                                                    + 67
                                                                                                                                                                                                                                                                                                                                                                                                                    + 68
                                                                                                                                                                                                                                                                                                                                                                                                                    + 69
                                                                                                                                                                                                                                                                                                                                                                                                                    + 70
                                                                                                                                                                                                                                                                                                                                                                                                                    + 71
                                                                                                                                                                                                                                                                                                                                                                                                                    + 72
                                                                                                                                                                                                                                                                                                                                                                                                                    + 73
                                                                                                                                                                                                                                                                                                                                                                                                                    + 74
                                                                                                                                                                                                                                                                                                                                                                                                                    + 75
                                                                                                                                                                                                                                                                                                                                                                                                                    + 76
                                                                                                                                                                                                                                                                                                                                                                                                                    + 77
                                                                                                                                                                                                                                                                                                                                                                                                                    + 78
                                                                                                                                                                                                                                                                                                                                                                                                                    + 79
                                                                                                                                                                                                                                                                                                                                                                                                                    + 80
                                                                                                                                                                                                                                                                                                                                                                                                                    + 81
                                                                                                                                                                                                                                                                                                                                                                                                                    + 82
                                                                                                                                                                                                                                                                                                                                                                                                                    + 83
                                                                                                                                                                                                                                                                                                                                                                                                                    + 84
                                                                                                                                                                                                                                                                                                                                                                                                                    + 85
                                                                                                                                                                                                                                                                                                                                                                                                                    + 86
                                                                                                                                                                                                                                                                                                                                                                                                                    + 87
                                                                                                                                                                                                                                                                                                                                                                                                                    + 88
                                                                                                                                                                                                                                                                                                                                                                                                                    + 89
                                                                                                                                                                                                                                                                                                                                                                                                                    + 90
                                                                                                                                                                                                                                                                                                                                                                                                                    + 91
                                                                                                                                                                                                                                                                                                                                                                                                                    + 92
                                                                                                                                                                                                                                                                                                                                                                                                                    + 93
                                                                                                                                                                                                                                                                                                                                                                                                                    + 94
                                                                                                                                                                                                                                                                                                                                                                                                                    + 95
                                                                                                                                                                                                                                                                                                                                                                                                                    + 96
                                                                                                                                                                                                                                                                                                                                                                                                                    + 97
                                                                                                                                                                                                                                                                                                                                                                                                                    + 98
                                                                                                                                                                                                                                                                                                                                                                                                                    + 99
                                                                                                                                                                                                                                                                                                                                                                                                                    +100
                                                                                                                                                                                                                                                                                                                                                                                                                    +101
                                                                                                                                                                                                                                                                                                                                                                                                                    +102
                                                                                                                                                                                                                                                                                                                                                                                                                    +103
                                                                                                                                                                                                                                                                                                                                                                                                                    +104
                                                                                                                                                                                                                                                                                                                                                                                                                    +105
                                                                                                                                                                                                                                                                                                                                                                                                                    +106
                                                                                                                                                                                                                                                                                                                                                                                                                    from machine import Pin
                                                                                                                                                                                                                                                                                                                                                                                                                    +import network
                                                                                                                                                                                                                                                                                                                                                                                                                    +import ntptime
                                                                                                                                                                                                                                                                                                                                                                                                                    +import ssd1306
                                                                                                                                                                                                                                                                                                                                                                                                                    +# where we keep the WiFi password
                                                                                                                                                                                                                                                                                                                                                                                                                    +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                                    +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +WIDTH = 128
                                                                                                                                                                                                                                                                                                                                                                                                                    +HEIGHT = 64
                                                                                                                                                                                                                                                                                                                                                                                                                    +SCK=machine.Pin(2)
                                                                                                                                                                                                                                                                                                                                                                                                                    +SDL=machine.Pin(3)
                                                                                                                                                                                                                                                                                                                                                                                                                    +spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)
                                                                                                                                                                                                                                                                                                                                                                                                                    +CS = machine.Pin(4)
                                                                                                                                                                                                                                                                                                                                                                                                                    +DC = machine.Pin(5)
                                                                                                                                                                                                                                                                                                                                                                                                                    +RES = machine.Pin(6)
                                                                                                                                                                                                                                                                                                                                                                                                                    +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                                                                                                                                                                                                                                                                                                                    +oled.poweron()
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +# US Central
                                                                                                                                                                                                                                                                                                                                                                                                                    +timeZone = -6
                                                                                                                                                                                                                                                                                                                                                                                                                    +# try one of these
                                                                                                                                                                                                                                                                                                                                                                                                                    +ntptime.host = 'us.pool.ntp.org' #'time.nist.gov' #'pool.ntp.org'
                                                                                                                                                                                                                                                                                                                                                                                                                    +ntptime.timeout = 10
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +def wifiConnect():
                                                                                                                                                                                                                                                                                                                                                                                                                    +    wifi = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    wifi.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    wifi.config(pm = 0xa11140) # disables wifi sleep mode
                                                                                                                                                                                                                                                                                                                                                                                                                    +    if not wifi.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                    +        wifi.connect(config.wifi_ssid, config.wifi_pass)
                                                                                                                                                                                                                                                                                                                                                                                                                    +        print('Connecting..', end='')
                                                                                                                                                                                                                                                                                                                                                                                                                    +        max_wait = 10
                                                                                                                                                                                                                                                                                                                                                                                                                    +        while max_wait > 0:
                                                                                                                                                                                                                                                                                                                                                                                                                    +            if wifi.status() < 0 or wifi.status() >= 3: break
                                                                                                                                                                                                                                                                                                                                                                                                                    +            sleep_ms(1000)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            print('.', end='')
                                                                                                                                                                                                                                                                                                                                                                                                                    +            max_wait -= 1
                                                                                                                                                                                                                                                                                                                                                                                                                    +        print()
                                                                                                                                                                                                                                                                                                                                                                                                                    +        if wifi.status() != 3: print('Could not connect to wifi!')
                                                                                                                                                                                                                                                                                                                                                                                                                    +    # print('Connected: ',wifi.isconnected(),'\nIP: ',wifi.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                                    +    sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    return wifi
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +# daylight savings time
                                                                                                                                                                                                                                                                                                                                                                                                                    +def dst():
                                                                                                                                                                                                                                                                                                                                                                                                                    +    year, weekday = localtime()[0], localtime()[6]
                                                                                                                                                                                                                                                                                                                                                                                                                    +    dst_start = mktime((year, 3, (8 - weekday) % 7 + 8, 2, 0, 0, 0, 0))
                                                                                                                                                                                                                                                                                                                                                                                                                    +    dst_end = mktime((year, 11, (1 - weekday) % 7 + 1, 2, 0, 0, 0, 0))
                                                                                                                                                                                                                                                                                                                                                                                                                    +    return dst_start <= time() < dst_end
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +timestr = ''
                                                                                                                                                                                                                                                                                                                                                                                                                    +datestr = ''
                                                                                                                                                                                                                                                                                                                                                                                                                    +dtime = []
                                                                                                                                                                                                                                                                                                                                                                                                                    +def setRTC():
                                                                                                                                                                                                                                                                                                                                                                                                                    +    global timestr, datestr, dtime
                                                                                                                                                                                                                                                                                                                                                                                                                    +    timeset = False
                                                                                                                                                                                                                                                                                                                                                                                                                    +    timetries = 0
                                                                                                                                                                                                                                                                                                                                                                                                                    +    maxtries = 5
                                                                                                                                                                                                                                                                                                                                                                                                                    +    while not timeset and timetries < maxtries:
                                                                                                                                                                                                                                                                                                                                                                                                                    +        timetries += 1
                                                                                                                                                                                                                                                                                                                                                                                                                    +        try:
                                                                                                                                                                                                                                                                                                                                                                                                                    +            ntptime.settime() # update time from ntp server
                                                                                                                                                                                                                                                                                                                                                                                                                    +            timeset = True
                                                                                                                                                                                                                                                                                                                                                                                                                    +        except:
                                                                                                                                                                                                                                                                                                                                                                                                                    +            print(f'NTP update attempt # {timetries} of {maxtries} failed!', 'Retrying in 15 seconds..' if timetries < maxtries else 'Check connection/config.')
                                                                                                                                                                                                                                                                                                                                                                                                                    +            if timetries < maxtries: sleep_ms(15000)
                                                                                                                                                                                                                                                                                                                                                                                                                    +        if timeset:
                                                                                                                                                                                                                                                                                                                                                                                                                    +            sleep_ms(200)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            rtc = RTC()
                                                                                                                                                                                                                                                                                                                                                                                                                    +            tz_offset = (timeZone + 1) * 3600 if dst() else timeZone * 3600
                                                                                                                                                                                                                                                                                                                                                                                                                    +            #tz_offset = timeZone * 3600 # without daylight savings
                                                                                                                                                                                                                                                                                                                                                                                                                    +            myt = localtime(time() + tz_offset)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            rtc.datetime((myt[0], myt[1], myt[2], myt[6], myt[3], myt[4], myt[5], 0))
                                                                                                                                                                                                                                                                                                                                                                                                                    +            sleep_ms(200)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            dtime = rtc.datetime()
                                                                                                                                                                                                                                                                                                                                                                                                                    +            # set globals
                                                                                                                                                                                                                                                                                                                                                                                                                    +            # hh:mm in 12hr am/pm format
                                                                                                                                                                                                                                                                                                                                                                                                                    +            timestr = '%2d:%02d%s' %(12 if dtime[4] == 0 else dtime[4] if dtime[4] < 13 else dtime[4] - 12, dtime[5], 'am' if dtime[4] < 12 else 'pm')
                                                                                                                                                                                                                                                                                                                                                                                                                    +            # mm/dd/yy
                                                                                                                                                                                                                                                                                                                                                                                                                    +            datestr = f'{dtime[1]}/{dtime[2]}/{dtime[0] % 100}'
                                                                                                                                                                                                                                                                                                                                                                                                                    +            # print('Time set to:', timestr, datestr)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            print(timestr, datestr)
                                                                                                                                                                                                                                                                                                                                                                                                                    +            return True
                                                                                                                                                                                                                                                                                                                                                                                                                    +    print('ERROR! Unable to update time from server!')
                                                                                                                                                                                                                                                                                                                                                                                                                    +    return False
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +def update():
                                                                                                                                                                                                                                                                                                                                                                                                                    +    success = False
                                                                                                                                                                                                                                                                                                                                                                                                                    +    wifi = wifiConnect()
                                                                                                                                                                                                                                                                                                                                                                                                                    +    sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    if wifi.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                    +        success = setRTC()
                                                                                                                                                                                                                                                                                                                                                                                                                    +        sleep_ms(100)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    return wifi, success
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +def update_display():
                                                                                                                                                                                                                                                                                                                                                                                                                    +    global timestr, datestr,dtime
                                                                                                                                                                                                                                                                                                                                                                                                                    +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    oled.text(timestr + ' ' + datestr, 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                    +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +while True:
                                                                                                                                                                                                                                                                                                                                                                                                                    +    update()
                                                                                                                                                                                                                                                                                                                                                                                                                    +    update_display()
                                                                                                                                                                                                                                                                                                                                                                                                                    +    sleep(60)
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + + + + \ No newline at end of file diff --git a/wireless/20-display/index.html b/wireless/20-display/index.html new file mode 100644 index 000000000..090b4baec --- /dev/null +++ b/wireless/20-display/index.html @@ -0,0 +1,1774 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + With Display - MicroPython for Kids + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + Skip to content + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + logo + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + MicroPython for Kids + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + With Display + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + + +
                                                                                                                                                                                                                                                                                                                                                                                                                    + +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                    + Initializing search +
                                                                                                                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + GitHub Repo +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                        + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + CoderDojo Mentor Resources + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + MicroPython Home + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Introduction + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Getting Started + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Basic Examples + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sensors + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Motors and Servos + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays - Non-Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Displays Graphical + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sound and Music + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                                          + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Introduction + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Connecting to WiFi + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + HTTP GET + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Web Server + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Web Server NeoPixel + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + MAC Address + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + UPIP + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Get Weather Forecast + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Display Forecast on OLED + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + WiFi Clock + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + Advanced Labs + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + + + + + + + + + With Display + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        • + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                                                                                                                                        + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Robots + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Advanced Labs + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Project Kits + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + Sims + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Glossary + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + References + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contributing + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Contact + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + + + Colophon + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      • + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + +

                                                                                                                                                                                                                                                                                                                                                                                                                      Wireless With Display

                                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                                      Wireless Display

                                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                                      In this lesson, we will add a 128x64 OLED display to our Pico "W" to display network information.

                                                                                                                                                                                                                                                                                                                                                                                                                      +

                                                                                                                                                                                                                                                                                                                                                                                                                      The display we are using is a 2.42" Diymore OLED display as describe in the Display Graphics.

                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                       1
                                                                                                                                                                                                                                                                                                                                                                                                                      + 2
                                                                                                                                                                                                                                                                                                                                                                                                                      + 3
                                                                                                                                                                                                                                                                                                                                                                                                                      + 4
                                                                                                                                                                                                                                                                                                                                                                                                                      + 5
                                                                                                                                                                                                                                                                                                                                                                                                                      + 6
                                                                                                                                                                                                                                                                                                                                                                                                                      + 7
                                                                                                                                                                                                                                                                                                                                                                                                                      + 8
                                                                                                                                                                                                                                                                                                                                                                                                                      + 9
                                                                                                                                                                                                                                                                                                                                                                                                                      +10
                                                                                                                                                                                                                                                                                                                                                                                                                      +11
                                                                                                                                                                                                                                                                                                                                                                                                                      +12
                                                                                                                                                                                                                                                                                                                                                                                                                      +13
                                                                                                                                                                                                                                                                                                                                                                                                                      +14
                                                                                                                                                                                                                                                                                                                                                                                                                      +15
                                                                                                                                                                                                                                                                                                                                                                                                                      +16
                                                                                                                                                                                                                                                                                                                                                                                                                      +17
                                                                                                                                                                                                                                                                                                                                                                                                                      +18
                                                                                                                                                                                                                                                                                                                                                                                                                      +19
                                                                                                                                                                                                                                                                                                                                                                                                                      +20
                                                                                                                                                                                                                                                                                                                                                                                                                      +21
                                                                                                                                                                                                                                                                                                                                                                                                                      +22
                                                                                                                                                                                                                                                                                                                                                                                                                      +23
                                                                                                                                                                                                                                                                                                                                                                                                                      +24
                                                                                                                                                                                                                                                                                                                                                                                                                      +25
                                                                                                                                                                                                                                                                                                                                                                                                                      +26
                                                                                                                                                                                                                                                                                                                                                                                                                      +27
                                                                                                                                                                                                                                                                                                                                                                                                                      +28
                                                                                                                                                                                                                                                                                                                                                                                                                      +29
                                                                                                                                                                                                                                                                                                                                                                                                                      +30
                                                                                                                                                                                                                                                                                                                                                                                                                      +31
                                                                                                                                                                                                                                                                                                                                                                                                                      +32
                                                                                                                                                                                                                                                                                                                                                                                                                      +33
                                                                                                                                                                                                                                                                                                                                                                                                                      +34
                                                                                                                                                                                                                                                                                                                                                                                                                      +35
                                                                                                                                                                                                                                                                                                                                                                                                                      +36
                                                                                                                                                                                                                                                                                                                                                                                                                      +37
                                                                                                                                                                                                                                                                                                                                                                                                                      +38
                                                                                                                                                                                                                                                                                                                                                                                                                      +39
                                                                                                                                                                                                                                                                                                                                                                                                                      +40
                                                                                                                                                                                                                                                                                                                                                                                                                      +41
                                                                                                                                                                                                                                                                                                                                                                                                                      +42
                                                                                                                                                                                                                                                                                                                                                                                                                      +43
                                                                                                                                                                                                                                                                                                                                                                                                                      +44
                                                                                                                                                                                                                                                                                                                                                                                                                      +45
                                                                                                                                                                                                                                                                                                                                                                                                                      +46
                                                                                                                                                                                                                                                                                                                                                                                                                      +47
                                                                                                                                                                                                                                                                                                                                                                                                                      +48
                                                                                                                                                                                                                                                                                                                                                                                                                      +49
                                                                                                                                                                                                                                                                                                                                                                                                                      +50
                                                                                                                                                                                                                                                                                                                                                                                                                      +51
                                                                                                                                                                                                                                                                                                                                                                                                                      +52
                                                                                                                                                                                                                                                                                                                                                                                                                      +53
                                                                                                                                                                                                                                                                                                                                                                                                                      +54
                                                                                                                                                                                                                                                                                                                                                                                                                      +55
                                                                                                                                                                                                                                                                                                                                                                                                                      +56
                                                                                                                                                                                                                                                                                                                                                                                                                      +57
                                                                                                                                                                                                                                                                                                                                                                                                                      +58
                                                                                                                                                                                                                                                                                                                                                                                                                      +59
                                                                                                                                                                                                                                                                                                                                                                                                                      +60
                                                                                                                                                                                                                                                                                                                                                                                                                      +61
                                                                                                                                                                                                                                                                                                                                                                                                                      +62
                                                                                                                                                                                                                                                                                                                                                                                                                      +63
                                                                                                                                                                                                                                                                                                                                                                                                                      +64
                                                                                                                                                                                                                                                                                                                                                                                                                      +65
                                                                                                                                                                                                                                                                                                                                                                                                                      +66
                                                                                                                                                                                                                                                                                                                                                                                                                      +67
                                                                                                                                                                                                                                                                                                                                                                                                                      +68
                                                                                                                                                                                                                                                                                                                                                                                                                      +69
                                                                                                                                                                                                                                                                                                                                                                                                                      +70
                                                                                                                                                                                                                                                                                                                                                                                                                      +71
                                                                                                                                                                                                                                                                                                                                                                                                                      +72
                                                                                                                                                                                                                                                                                                                                                                                                                      +73
                                                                                                                                                                                                                                                                                                                                                                                                                      +74
                                                                                                                                                                                                                                                                                                                                                                                                                      +75
                                                                                                                                                                                                                                                                                                                                                                                                                      +76
                                                                                                                                                                                                                                                                                                                                                                                                                      +77
                                                                                                                                                                                                                                                                                                                                                                                                                      +78
                                                                                                                                                                                                                                                                                                                                                                                                                      +79
                                                                                                                                                                                                                                                                                                                                                                                                                      +80
                                                                                                                                                                                                                                                                                                                                                                                                                      +81
                                                                                                                                                                                                                                                                                                                                                                                                                      +82
                                                                                                                                                                                                                                                                                                                                                                                                                      +83
                                                                                                                                                                                                                                                                                                                                                                                                                      +84
                                                                                                                                                                                                                                                                                                                                                                                                                      +85
                                                                                                                                                                                                                                                                                                                                                                                                                      +86
                                                                                                                                                                                                                                                                                                                                                                                                                      # make a number scroll to the right and increment the number and move down one pixel
                                                                                                                                                                                                                                                                                                                                                                                                                      +# this test patten shows the device is working and will not burn any single pixel if it runs a long time
                                                                                                                                                                                                                                                                                                                                                                                                                      +from machine import Pin
                                                                                                                                                                                                                                                                                                                                                                                                                      +import network
                                                                                                                                                                                                                                                                                                                                                                                                                      +import ssd1306
                                                                                                                                                                                                                                                                                                                                                                                                                      +import secrets
                                                                                                                                                                                                                                                                                                                                                                                                                      +from utime import sleep, ticks_ms, ticks_diff
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +WIDTH = 128
                                                                                                                                                                                                                                                                                                                                                                                                                      +HEIGHT = 64
                                                                                                                                                                                                                                                                                                                                                                                                                      +SCK=machine.Pin(2)
                                                                                                                                                                                                                                                                                                                                                                                                                      +SDL=machine.Pin(3)
                                                                                                                                                                                                                                                                                                                                                                                                                      +spi=machine.SPI(0,baudrate=100000,sck=SCK, mosi=SDL)
                                                                                                                                                                                                                                                                                                                                                                                                                      +CS = machine.Pin(0)
                                                                                                                                                                                                                                                                                                                                                                                                                      +DC = machine.Pin(1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +RES = machine.Pin(4)
                                                                                                                                                                                                                                                                                                                                                                                                                      +oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)
                                                                                                                                                                                                                                                                                                                                                                                                                      +oled.poweron()
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +def mac_address_fmt():
                                                                                                                                                                                                                                                                                                                                                                                                                      +    mac_addess = wlan.config('mac')
                                                                                                                                                                                                                                                                                                                                                                                                                      +    s=""
                                                                                                                                                                                                                                                                                                                                                                                                                      +    for digit in range(0,5):
                                                                                                                                                                                                                                                                                                                                                                                                                      +        s+=str(hex(mac_addess[digit]))[2:4] + ':'
                                                                                                                                                                                                                                                                                                                                                                                                                      +    s+= hex(mac_addess[5])[2:4]
                                                                                                                                                                                                                                                                                                                                                                                                                      +    return s
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +def display_startup(counter):
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('Running startup', 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('Connecting to', 0, 20, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text(secrets.SSID, 0, 30, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text(str(counter), 0, 40, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +def display_status(counter):
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.fill(0)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    # display the network name
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('n:' + secrets.SSID, 0, 0, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +    # display the connection time
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('t:', 0, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text(str(connection_time)+ ' ms', 15, 10, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +    # display the MAC address
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text(mac_address_fmt(), 0, 20, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +    # display the IP address
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('ip:' + wlan.ifconfig()[0], 0, 30, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.text('c:' + str(counter), 0, 40, 1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    oled.show()
                                                                                                                                                                                                                                                                                                                                                                                                                      +# startup
                                                                                                                                                                                                                                                                                                                                                                                                                      +led = Pin("LED", Pin.OUT)
                                                                                                                                                                                                                                                                                                                                                                                                                      +led.on()
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +start = ticks_ms() # start a millisecond counter
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +print('Connecting to WiFi Network Name:', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                                      +wlan = network.WLAN(network.STA_IF)
                                                                                                                                                                                                                                                                                                                                                                                                                      +wlan.active(True)
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +if not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                      +    # this should normally take 3-5 seconds...
                                                                                                                                                                                                                                                                                                                                                                                                                      +    wlan.connect(secrets.SSID, secrets.PASSWORD)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    print("Waiting for connection...")
                                                                                                                                                                                                                                                                                                                                                                                                                      +    counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                                      +    display_startup(counter)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    while not wlan.isconnected():
                                                                                                                                                                                                                                                                                                                                                                                                                      +        sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +        counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                                      +        led.toggle()
                                                                                                                                                                                                                                                                                                                                                                                                                      +        display_startup(counter)
                                                                                                                                                                                                                                                                                                                                                                                                                      +        print(counter, '.', sep='', end='')
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +connection_time = ticks_diff(ticks_ms(), start)
                                                                                                                                                                                                                                                                                                                                                                                                                      +mac_addess = wlan.config('mac')
                                                                                                                                                                                                                                                                                                                                                                                                                      +print('Connected to', secrets.SSID)
                                                                                                                                                                                                                                                                                                                                                                                                                      +print('Total connect milliseconds:', connection_time)
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +counter = 0
                                                                                                                                                                                                                                                                                                                                                                                                                      +while True:
                                                                                                                                                                                                                                                                                                                                                                                                                      +    led.toggle()
                                                                                                                                                                                                                                                                                                                                                                                                                      +    counter += 1
                                                                                                                                                                                                                                                                                                                                                                                                                      +    display_status(counter)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    sleep(1)
                                                                                                                                                                                                                                                                                                                                                                                                                      +    print(counter, 'listening on', wlan.ifconfig()[0])
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + Advanced Labs +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + Introduction +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + + + + + + + \ No newline at end of file diff --git a/docs/wireless/rgb-sliders.html b/wireless/rgb-sliders.html similarity index 100% rename from docs/wireless/rgb-sliders.html rename to wireless/rgb-sliders.html
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + Previous + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + Buttons +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + Next + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + Motor +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      + + + Made with + + Material for MkDocs + + +
                                                                                                                                                                                                                                                                                                                                                                                                                      + +
                                                                                                                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                                                                                                                      +